/** * Method returns how much discount is already offered * * @param lineItems * @return */ private Double getTotalDiscountOffered(Set<LineItem> lineItems) { LOGGER.info("Calculating Total Discount Offered"); Double totalDiscountOffrd = 0D; Map<String, String> qualifyngTypeLI = proposalService.getQualifyingLineItems(); for (LineItem lineItem : lineItems) { if (qualifyngTypeLI.containsKey(lineItem.getPriceType()) || LineItemPriceTypeEnum.ADDEDVALUE.getOptionValue().equals(lineItem.getPriceType())) { if (lineItem.getPriceType().equals(LineItemPriceTypeEnum.ADDEDVALUE.getOptionValue())) { if (lineItem.getRateCardPrice() != null) { totalDiscountOffrd = totalDiscountOffrd + ((lineItem.getRateCardPrice() * lineItem.getImpressionTotal()) / 1000); } } else { if (lineItem.getRateCardPrice() > lineItem.getRate()) { totalDiscountOffrd = totalDiscountOffrd + ((lineItem.getRateCardPrice() - NumberUtil.round(lineItem.getRate(), 2)) * lineItem.getImpressionTotal()) / 1000; } } } } return totalDiscountOffrd; }
/* (non-Javadoc) * @see com.nyt.mpt.service.IPricingStatusCalculatorService#getInvstmntOfQulfyngLI(java.util.Set) */ @Override public Double getInvstmntOfQulfyngLI(Set<LineItem> lineitems, boolean isThresholdCheck) { Double totalInvestment = 0D; LOGGER.info("Calculating Total Investment of Qualifying Line Items"); Map<String, String> qualifyngTypeLI = proposalService.getQualifyingLineItems(); if (isThresholdCheck) { qualifyngTypeLI.put( LineItemPriceTypeEnum.PREEMPTIBLE.getOptionValue(), LineItemPriceTypeEnum.PREEMPTIBLE.getOptionValue()); } for (LineItem lineItem : lineitems) { if (qualifyngTypeLI.containsKey(lineItem.getPriceType())) { if (lineItem.getPriceType().equals(LineItemPriceTypeEnum.ADDEDVALUE.getOptionValue())) { if (lineItem.getRateCardPrice() != null) { totalInvestment = totalInvestment + ((lineItem.getRateCardPrice() * lineItem.getImpressionTotal()) / 1000); } } else { totalInvestment = totalInvestment + lineItem.getTotalInvestment(); } } } return totalInvestment; }
/* (non-Javadoc) * @see com.nyt.mpt.service.IPricingStatusCalculatorService#addAddedValueCheckForOption(com.nyt.mpt.domain.ProposalOption) */ @Override public void addAddedValueCheckForOption(ProposalOption option) { Set<LineItem> lineItems = option.getLatestVersion().getProposalLineItemSet(); if (lineItems != null && !lineItems.isEmpty()) { Double totalInvestment = getInvstmntOfQulfyngLI(lineItems, false); Double allowedPercentage = getAddedValueAllowed( totalInvestment, option.getProposal().getPriceType(), option.getProposal().getAgencyMargin()); Double allowedDiscount = (totalInvestment * allowedPercentage) / 100; Double totalDiscountOffrd = getTotalDiscountOffered(lineItems); for (LineItem lineItem : lineItems) { if (!PricingStatus.PRICING_APPROVED.equals(lineItem.getPricingStatus()) && lineItem.getPriceType().equals(LineItemPriceTypeEnum.ADDEDVALUE.getOptionValue()) && lineItem.getViewabilityLevel() != LineItemViewableCriteriaEnum.VEIWABLE.getViewableValue()) { lineItem.setPricingStatus( (allowedDiscount < totalDiscountOffrd) ? getPricingStatus(lineItem, option.getProposal().isSpecialAdvertiser()) : PricingStatus.SYSTEM_APPROVED); proposalDao.editLineItemsOfProposal(lineItem); } } } }