| Line 656... |
Line 656... |
| 656 |
return rollout;
|
656 |
return rollout;
|
| 657 |
}
|
657 |
}
|
| 658 |
|
658 |
|
| 659 |
@Override
|
659 |
@Override
|
| 660 |
public Map<Integer, QtyAmountModel> getCriteriaQtyAmounModelMap(CreateOfferRequest createOfferRequest, int fofoId) throws ProfitMandiBusinessException {
|
660 |
public Map<Integer, QtyAmountModel> getCriteriaQtyAmounModelMap(CreateOfferRequest createOfferRequest, int fofoId) throws ProfitMandiBusinessException {
|
| 661 |
final Map<String, LocalDateTime> activatedImeisActivationDateMap;
|
- |
|
| 662 |
Map<Integer, QtyAmountModel> qtyAmountMap;
|
661 |
Map<Integer, QtyAmountModel> qtyAmountMap;
|
| 663 |
if (createOfferRequest.getSchemeType().equals(OfferSchemeType.SELLIN)) {
|
662 |
if (createOfferRequest.getSchemeType().equals(OfferSchemeType.SELLIN)) {
|
| 664 |
qtyAmountMap = getCriteriaQtyAmountModelMapForSellin(createOfferRequest, fofoId);
|
663 |
qtyAmountMap = getCriteriaQtyAmountModelMapForSellin(createOfferRequest, fofoId);
|
| 665 |
} else {
|
664 |
} else {
|
| 666 |
qtyAmountMap = getCriteriaQtyAmountModelMapForSelloutAndActivation(createOfferRequest, fofoId);
|
665 |
qtyAmountMap = getCriteriaQtyAmountModelMapForSelloutAndActivation(createOfferRequest, fofoId);
|
| 667 |
}
|
666 |
}
|
| 668 |
LOGGER.info("Qty Amount Map {}", qtyAmountMap);
|
667 |
LOGGER.info("Qty Amount Map {}", qtyAmountMap);
|
| 669 |
return qtyAmountMap;
|
668 |
return qtyAmountMap;
|
| 670 |
}
|
669 |
}
|
| 671 |
|
670 |
|
| 672 |
private Map<Integer, QtyAmountModel> getCriteriaQtyAmountModelMapForSellin(CreateOfferRequest createOfferRequest, int fofoId) throws ProfitMandiBusinessException {
|
671 |
private PayoutSlab findEligibleSlab(List<PayoutSlab> slabs, int achievedValue) {
|
| 673 |
Map<Integer, QtyAmountModel> criteriaQtyAmountMap = new HashMap<>();
|
672 |
PayoutSlab eligibleSlab = null;
|
| 674 |
List<ItemCriteriaPayout> itemCriteriaPayouts = createOfferRequest.getTargetSlabs().get(0).getItemCriteriaPayouts();
|
673 |
for (PayoutSlab slab : slabs) {
|
| 675 |
Map<Integer, ItemCriteriaPayout> itemCriteriaPayoutMap = itemCriteriaPayouts.stream().collect(Collectors.toMap(x -> x.getItemCriteria().getId(), x -> x));
|
674 |
if (slab.getOnwardsAmount() <= achievedValue) {
|
| - |
|
675 |
eligibleSlab = slab;
|
| - |
|
676 |
} else {
|
| - |
|
677 |
break;
|
| - |
|
678 |
}
|
| - |
|
679 |
}
|
| - |
|
680 |
return eligibleSlab;
|
| - |
|
681 |
}
|
| 676 |
|
682 |
|
| 677 |
Map<Integer, List<Order>> criteriaOrdersMap = offerRepository.getPartnerWiseSellin(fofoId, createOfferRequest, true);
|
683 |
private double calculateFinalPayout(PayoutSlab eligibleSlab, AmountType amountType,
|
| - |
|
684 |
int valueForPercentage, int valueForFixed) {
|
| - |
|
685 |
if (eligibleSlab == null) return 0;
|
| - |
|
686 |
eligibleSlab.setSelected(true);
|
| - |
|
687 |
float payoutRate = eligibleSlab.getPayoutAmount();
|
| - |
|
688 |
if (AmountType.PERCENTAGE.equals(amountType)) {
|
| - |
|
689 |
return (payoutRate * valueForPercentage) / 100;
|
| - |
|
690 |
} else if (AmountType.FIXED.equals(amountType)) {
|
| - |
|
691 |
return payoutRate * valueForFixed;
|
| - |
|
692 |
} else {
|
| - |
|
693 |
return payoutRate;
|
| - |
|
694 |
}
|
| - |
|
695 |
}
|
| 678 |
|
696 |
|
| - |
|
697 |
private QtyAmountModel calculateSellinQtyAndValue(List<Order> orders) {
|
| - |
|
698 |
int qty = orders.stream().collect(Collectors.summingInt(x ->
|
| - |
|
699 |
x.getLineItem().getQuantity() - x.getLineItem().getReturnQty()));
|
| - |
|
700 |
int value = orders.stream().collect(Collectors.summingInt(x ->
|
| - |
|
701 |
Math.round(x.getLineItem().getUnitPrice() *
|
| - |
|
702 |
(x.getLineItem().getQuantity() - x.getLineItem().getReturnQty()))));
|
| - |
|
703 |
return new QtyAmountModel(qty, value);
|
| - |
|
704 |
}
|
| 679 |
|
705 |
|
| 680 |
List<Order> baseCriteriaOrders = null;
|
- |
|
| 681 |
if (criteriaOrdersMap.get(0) != null && criteriaOrdersMap.get(0).size() > 0) {
|
706 |
private Map<Integer, QtyAmountModel> getCriteriaQtyAmountModelMapForSellin(CreateOfferRequest createOfferRequest, int fofoId) throws ProfitMandiBusinessException {
|
| 682 |
baseCriteriaOrders = criteriaOrdersMap.get(0);
|
707 |
Map<Integer, QtyAmountModel> criteriaQtyAmountMap = new HashMap<>();
|
| 683 |
}
|
- |
|
| 684 |
|
708 |
|
| - |
|
709 |
Map<Integer, List<Order>> criteriaOrdersMap = offerRepository.getPartnerWiseSellin(fofoId, createOfferRequest, true);
|
| 685 |
|
710 |
|
| - |
|
711 |
List<Order> baseCriteriaOrders = criteriaOrdersMap.get(0);
|
| 686 |
Integer userBaseQty = null;
|
712 |
Integer userBaseQty = null;
|
| 687 |
Integer userBaseValue = null;
|
713 |
Integer userBaseValue = null;
|
| 688 |
if (baseCriteriaOrders != null) {
|
714 |
if (baseCriteriaOrders != null && baseCriteriaOrders.size() > 0) {
|
| 689 |
userBaseQty = baseCriteriaOrders.stream().collect(Collectors.summingInt(x -> (x.getLineItem().getQuantity() - x.getLineItem().getReturnQty())));
|
715 |
QtyAmountModel baseModel = calculateSellinQtyAndValue(baseCriteriaOrders);
|
| - |
|
716 |
userBaseQty = baseModel.getQty();
|
| 690 |
userBaseValue = baseCriteriaOrders.stream().collect(Collectors.summingInt(x ->
|
717 |
userBaseValue = (int) baseModel.getAmount();
|
| 691 |
Math.round(x.getLineItem().getUnitPrice() * (x.getLineItem().getQuantity() - x.getLineItem().getReturnQty()))
|
718 |
criteriaQtyAmountMap.put(0, baseModel);
|
| 692 |
));
|
719 |
} else {
|
| 693 |
criteriaQtyAmountMap.put(0, new QtyAmountModel(userBaseQty, userBaseValue));
|
720 |
criteriaQtyAmountMap.put(0, new QtyAmountModel(0, 0));
|
| 694 |
|
- |
|
| 695 |
}
|
721 |
}
|
| 696 |
|
722 |
|
| 697 |
LOGGER.info("Processing sellin");
|
723 |
LOGGER.info("Processing sellin");
|
| 698 |
for (ItemCriteriaPayout itemCriteriaPayout : createOfferRequest.getTargetSlabs().get(0).getItemCriteriaPayouts()) {
|
724 |
for (ItemCriteriaPayout itemCriteriaPayout : createOfferRequest.getTargetSlabs().get(0).getItemCriteriaPayouts()) {
|
| 699 |
int criteriaId = itemCriteriaPayout.getItemCriteria().getId();
|
725 |
int criteriaId = itemCriteriaPayout.getItemCriteria().getId();
|
| 700 |
|
726 |
|
| 701 |
QtyAmountModel qtyAmountModel = new QtyAmountModel(0, 0);
|
727 |
QtyAmountModel qtyAmountModel = new QtyAmountModel(0, 0);
|
| 702 |
criteriaQtyAmountMap.put(itemCriteriaPayout.getItemCriteria().getId(), qtyAmountModel);
|
728 |
criteriaQtyAmountMap.put(criteriaId, qtyAmountModel);
|
| 703 |
|
729 |
|
| 704 |
List<Order> orders = criteriaOrdersMap.get(criteriaId);
|
730 |
List<Order> orders = criteriaOrdersMap.get(criteriaId);
|
| 705 |
int totalQty = orders.stream().collect(Collectors.summingInt(x -> (x.getLineItem().getQuantity() - x.getLineItem().getReturnQty())));
|
- |
|
| 706 |
int totalValue = orders.stream().collect(Collectors.summingInt(x -> Math.round(x.getLineItem().
|
731 |
if (orders == null || orders.isEmpty()) continue;
|
| - |
|
732 |
|
| 707 |
getUnitPrice() * (x.getLineItem().getQuantity() - x.getLineItem().getReturnQty()))));
|
733 |
QtyAmountModel criteriaModel = calculateSellinQtyAndValue(orders);
|
| 708 |
int totalBaseQty = totalQty;
|
734 |
int totalBaseQty = criteriaModel.getQty();
|
| 709 |
int totalBaseValue = totalValue;
|
735 |
int totalBaseValue = (int) criteriaModel.getAmount();
|
| 710 |
criteriaQtyAmountMap.put(0, new QtyAmountModel(userBaseQty==null? 0 : userBaseQty, userBaseValue==null?0 : userBaseValue));
|
- |
|
| 711 |
if (userBaseQty != null) {
|
736 |
if (userBaseQty != null) {
|
| 712 |
totalBaseQty = userBaseQty;
|
737 |
totalBaseQty = userBaseQty;
|
| 713 |
totalBaseValue = userBaseValue;
|
738 |
totalBaseValue = userBaseValue;
|
| 714 |
}
|
739 |
}
|
| 715 |
|
740 |
|
| Line 720... |
Line 745... |
| 720 |
purchasedValue = totalBaseQty;
|
745 |
purchasedValue = totalBaseQty;
|
| 721 |
}
|
746 |
}
|
| 722 |
qtyAmountModel.setQty(totalBaseQty);
|
747 |
qtyAmountModel.setQty(totalBaseQty);
|
| 723 |
qtyAmountModel.setAmount(totalBaseValue);
|
748 |
qtyAmountModel.setAmount(totalBaseValue);
|
| 724 |
|
749 |
|
| 725 |
PayoutSlab eligibleSlab = null;
|
- |
|
| 726 |
|
- |
|
| 727 |
for (PayoutSlab payoutSlab : itemCriteriaPayout.getPayoutSlabs()) {
|
750 |
PayoutSlab eligibleSlab = findEligibleSlab(itemCriteriaPayout.getPayoutSlabs(), purchasedValue);
|
| 728 |
if (payoutSlab.getOnwardsAmount() <= purchasedValue) {
|
- |
|
| 729 |
eligibleSlab = payoutSlab;
|
- |
|
| 730 |
} else {
|
- |
|
| 731 |
break;
|
- |
|
| 732 |
}
|
- |
|
| 733 |
}
|
- |
|
| 734 |
double finalPayout = 0;
|
- |
|
| 735 |
if(eligibleSlab != null) {
|
- |
|
| 736 |
eligibleSlab.setSelected(true);
|
- |
|
| 737 |
float eligiblePayoutValue = eligibleSlab.getPayoutAmount();
|
- |
|
| 738 |
if (AmountType.PERCENTAGE.equals(itemCriteriaPayout.getAmountType())) {
|
- |
|
| 739 |
finalPayout = (eligiblePayoutValue * purchasedValue) / 100;
|
- |
|
| 740 |
} else if (AmountType.FIXED.equals(itemCriteriaPayout.getAmountType())) {
|
751 |
double finalPayout = calculateFinalPayout(eligibleSlab, itemCriteriaPayout.getAmountType(),
|
| 741 |
finalPayout = eligiblePayoutValue * purchasedValue;
|
752 |
purchasedValue, purchasedValue);
|
| 742 |
} else {
|
- |
|
| 743 |
finalPayout = eligiblePayoutValue;
|
- |
|
| 744 |
}
|
- |
|
| 745 |
}
|
- |
|
| 746 |
qtyAmountModel.setFinalPayout(finalPayout);
|
753 |
qtyAmountModel.setFinalPayout(finalPayout);
|
| 747 |
createOfferRequest.setCriteriaQtyAmountModel(criteriaQtyAmountMap);
|
- |
|
| 748 |
}
|
754 |
}
|
| 749 |
return criteriaQtyAmountMap;
|
755 |
return criteriaQtyAmountMap;
|
| 750 |
}
|
756 |
}
|
| 751 |
|
757 |
|
| 752 |
private Map<Integer, QtyAmountModel> getCriteriaQtyAmountModelMapForSelloutAndActivation(CreateOfferRequest createOfferRequest, int fofoId) {
|
758 |
private Map<Integer, QtyAmountModel> getCriteriaQtyAmountModelMapForSelloutAndActivation(CreateOfferRequest createOfferRequest, int fofoId) {
|
| Line 773... |
Line 779... |
| 773 |
activatedImeisActivationDateMap = null;
|
779 |
activatedImeisActivationDateMap = null;
|
| 774 |
}
|
780 |
}
|
| 775 |
|
781 |
|
| 776 |
QtyAmountModel qtyAmountModel = null;
|
782 |
QtyAmountModel qtyAmountModel = null;
|
| 777 |
if (createOfferRequest.isBaseCriteria()) {
|
783 |
if (createOfferRequest.isBaseCriteria()) {
|
| - |
|
784 |
Map<Integer, List<FofoOrderItem>> baseCriteriaMap = criteriaPartnerwiseTertiary.get(0);
|
| 778 |
List<FofoOrderItem> fofoOrderItems = criteriaPartnerwiseTertiary.get(0).get(fofoId);
|
785 |
List<FofoOrderItem> fofoOrderItems = baseCriteriaMap == null ? null : baseCriteriaMap.get(fofoId);
|
| 779 |
int totalBaseQty = fofoOrderItems == null ? 0 : fofoOrderItems.stream().filter(x->createOfferRequest.isWithinRange(x.getCreateTimestamp())).collect(Collectors.summingInt(x -> (x.getQuantity())));
|
786 |
int totalBaseQty = fofoOrderItems == null ? 0 : fofoOrderItems.stream().filter(x->createOfferRequest.isWithinRange(x.getCreateTimestamp())).collect(Collectors.summingInt(x -> (x.getQuantity())));
|
| 780 |
int totalBaseValue = fofoOrderItems == null ? 0 : fofoOrderItems.stream().filter(x->createOfferRequest.isWithinRange(x.getCreateTimestamp())).mapToInt(x -> (Math.round(x.getDp())) * x.getQuantity()).sum();
|
787 |
int totalBaseValue = fofoOrderItems == null ? 0 : fofoOrderItems.stream().filter(x->createOfferRequest.isWithinRange(x.getCreateTimestamp())).mapToInt(x -> (Math.round(x.getDp())) * x.getQuantity()).sum();
|
| 781 |
qtyAmountModel = new QtyAmountModel(totalBaseQty, totalBaseValue);
|
788 |
qtyAmountModel = new QtyAmountModel(totalBaseQty, totalBaseValue);
|
| 782 |
if (createOfferRequest.getSchemeType().equals(OfferSchemeType.ACTIVATION)) {
|
789 |
if (createOfferRequest.getSchemeType().equals(OfferSchemeType.ACTIVATION)) {
|
| 783 |
Map<Integer, Integer> inventoryItemValueMap = new HashMap<>();
|
790 |
Map<Integer, Integer> inventoryItemValueMap = new HashMap<>();
|
| - |
|
791 |
if (fofoOrderItems != null) {
|
| 784 |
for (FofoOrderItem fofoOrderItem : fofoOrderItems) {
|
792 |
for (FofoOrderItem fofoOrderItem : fofoOrderItems) {
|
| 785 |
fofoOrderItem.getFofoLineItems().stream().filter(x -> x.getSerialNumber() != null).forEach(
|
793 |
fofoOrderItem.getFofoLineItems().stream().filter(x -> x.getSerialNumber() != null).forEach(
|
| 786 |
lineItem -> {
|
794 |
lineItem -> {
|
| 787 |
if (activatedImeisActivationDateMap == null || activatedImeisActivationDateMap.containsKey(lineItem.getSerialNumber())) {
|
795 |
if (activatedImeisActivationDateMap == null || activatedImeisActivationDateMap.containsKey(lineItem.getSerialNumber())) {
|
| 788 |
inventoryItemValueMap.put(lineItem.getInventoryItemId(), (int) fofoOrderItem.getDp());
|
796 |
inventoryItemValueMap.put(lineItem.getInventoryItemId(), (int) fofoOrderItem.getDp());
|
| - |
|
797 |
}
|
| 789 |
}
|
798 |
}
|
| 790 |
}
|
799 |
);
|
| 791 |
);
|
800 |
}
|
| 792 |
}
|
801 |
}
|
| 793 |
qtyAmountModel.setActivationQty(inventoryItemValueMap.size());
|
802 |
qtyAmountModel.setActivationQty(inventoryItemValueMap.size());
|
| 794 |
qtyAmountModel.setActivationAmount(inventoryItemValueMap.entrySet().stream().collect(Collectors.summingInt(x -> x.getValue())));
|
803 |
qtyAmountModel.setActivationAmount(inventoryItemValueMap.entrySet().stream().collect(Collectors.summingInt(x -> x.getValue())));
|
| 795 |
qtyAmountMap.put(0, qtyAmountModel);
|
804 |
qtyAmountMap.put(0, qtyAmountModel);
|
| 796 |
}
|
805 |
}
|
| 797 |
}
|
806 |
}
|
| 798 |
|
807 |
|
| 799 |
//As of now eligible sale is considered to be without special criteria like brand/
|
- |
|
| 800 |
//CriteriaPayoutWise
|
808 |
//CriteriaPayoutWise
|
| 801 |
for (ItemCriteriaPayout itemCriteriaPayout : createOfferRequest.getTargetSlabs().get(0).getItemCriteriaPayouts()) {
|
809 |
for (ItemCriteriaPayout itemCriteriaPayout : createOfferRequest.getTargetSlabs().get(0).getItemCriteriaPayouts()) {
|
| 802 |
int criteriaId = itemCriteriaPayout.getItemCriteria().getId();
|
810 |
int criteriaId = itemCriteriaPayout.getItemCriteria().getId();
|
| 803 |
Map<Integer, List<FofoOrderItem>> ordersMap = criteriaPartnerwiseTertiary.get(criteriaId);
|
811 |
Map<Integer, List<FofoOrderItem>> ordersMap = criteriaPartnerwiseTertiary.get(criteriaId);
|
| 804 |
//Partywise iteration
|
- |
|
| 805 |
QtyAmountModel qtyAmountModel1 = new QtyAmountModel(0, 0);
|
- |
|
| 806 |
qtyAmountMap.put(criteriaId, qtyAmountModel1);
|
- |
|
| 807 |
List<FofoOrderItem> fofoOrderItems = ordersMap.get(fofoId) == null ? null : ordersMap.get(fofoId);
|
- |
|
| 808 |
if (fofoOrderItems != null && fofoOrderItems.size() > 0) {
|
- |
|
| 809 |
int totalQty = fofoOrderItems.stream().collect(Collectors.summingInt(x -> (x.getQuantity())));
|
- |
|
| 810 |
int totalValue = fofoOrderItems.stream().collect(Collectors.summingInt(x -> Math.round(x.getDp()) * (x.getQuantity())));
|
- |
|
| 811 |
int eligibleQty = totalQty;
|
- |
|
| 812 |
int eligibleValue = totalValue;
|
- |
|
| 813 |
qtyAmountModel1.setQty(totalQty);
|
- |
|
| 814 |
qtyAmountModel1.setAmount(totalValue);
|
- |
|
| 815 |
Map<FofoLineItem, Integer> lineItemValueMap = new HashMap<>();
|
- |
|
| 816 |
if (createOfferRequest.getSchemeType().equals(OfferSchemeType.ACTIVATION)) {
|
- |
|
| 817 |
for (FofoOrderItem fofoOrderItem : fofoOrderItems) {
|
- |
|
| 818 |
fofoOrderItem.getFofoLineItems().stream().filter(x -> x.getSerialNumber() != null).forEach(
|
- |
|
| 819 |
lineItem -> {
|
- |
|
| 820 |
if (activatedImeisActivationDateMap == null) {
|
- |
|
| 821 |
lineItemValueMap.put(lineItem, (int) fofoOrderItem.getDp());
|
- |
|
| 822 |
|
- |
|
| 823 |
} else if (activatedImeisActivationDateMap.containsKey(lineItem.getSerialNumber())) {
|
- |
|
| 824 |
if (itemCriteriaPayout.isWithinRange(activatedImeisActivationDateMap.get(lineItem.getSerialNumber()))) {
|
- |
|
| 825 |
lineItemValueMap.put(lineItem, (int) fofoOrderItem.getDp());
|
- |
|
| 826 |
}
|
- |
|
| 827 |
}
|
- |
|
| 828 |
}
|
- |
|
| 829 |
);
|
- |
|
| 830 |
}
|
- |
|
| 831 |
eligibleQty = lineItemValueMap.size();
|
- |
|
| 832 |
eligibleValue = lineItemValueMap.entrySet().stream().collect(Collectors.summingInt(x -> x.getValue()));
|
- |
|
| 833 |
qtyAmountModel1.setActivationQty(eligibleQty);
|
- |
|
| 834 |
qtyAmountModel1.setActivationAmount(eligibleValue);
|
- |
|
| 835 |
}
|
- |
|
| 836 |
qtyAmountMap.put(criteriaId, qtyAmountModel1);
|
- |
|
| 837 |
|
812 |
|
| 838 |
int eligibleBaseQty = eligibleQty;
|
- |
|
| 839 |
int eligibleBaseValue = eligibleValue;
|
- |
|
| 840 |
if (createOfferRequest.isBaseCriteria()) {
|
- |
|
| 841 |
eligibleBaseQty = qtyAmountModel.getActivationQty();
|
813 |
QtyAmountModel criteriaQtyAmountModel = new QtyAmountModel(0, 0);
|
| 842 |
eligibleBaseValue = (int) qtyAmountModel.getActivationAmount();
|
814 |
qtyAmountMap.put(criteriaId, criteriaQtyAmountModel);
|
| 843 |
}
|
- |
|
| 844 |
|
815 |
|
| - |
|
816 |
if (ordersMap == null) continue;
|
| 845 |
|
817 |
|
| 846 |
int eligibleSale = eligibleBaseValue;
|
- |
|
| 847 |
int eligibleCriteriaSale = eligibleValue;
|
- |
|
| 848 |
int eligibleCriteriaSaleDp = eligibleValue;
|
818 |
List<FofoOrderItem> fofoOrderItems = ordersMap.get(fofoId);
|
| 849 |
|
- |
|
| 850 |
if (createOfferRequest.getTargetType().equals(AchievementType.QUANTITY)) {
|
819 |
if (fofoOrderItems == null || fofoOrderItems.isEmpty()) continue;
|
| 851 |
eligibleSale = eligibleBaseQty;
|
- |
|
| 852 |
eligibleCriteriaSale = eligibleQty;
|
- |
|
| 853 |
}
|
- |
|
| 854 |
|
820 |
|
| - |
|
821 |
int totalQty = fofoOrderItems.stream().collect(Collectors.summingInt(x -> (x.getQuantity())));
|
| - |
|
822 |
int totalValue = fofoOrderItems.stream().collect(Collectors.summingInt(x -> Math.round(x.getDp()) * (x.getQuantity())));
|
| 855 |
float eligiblePayoutValue = 0;
|
823 |
int eligibleQty = totalQty;
|
| 856 |
double finalPayout = 0;
|
824 |
int eligibleValue = totalValue;
|
| - |
|
825 |
criteriaQtyAmountModel.setQty(totalQty);
|
| - |
|
826 |
criteriaQtyAmountModel.setAmount(totalValue);
|
| 857 |
|
827 |
|
| 858 |
PayoutSlab eligibleSlab = null;
|
828 |
Map<FofoLineItem, Integer> lineItemValueMap = new HashMap<>();
|
| 859 |
for (PayoutSlab slab : itemCriteriaPayout.getPayoutSlabs()) {
|
829 |
if (createOfferRequest.getSchemeType().equals(OfferSchemeType.ACTIVATION)) {
|
| 860 |
if (slab.getOnwardsAmount() <= eligibleSale) {
|
830 |
for (FofoOrderItem fofoOrderItem : fofoOrderItems) {
|
| 861 |
eligibleSlab = slab;
|
831 |
fofoOrderItem.getFofoLineItems().stream().filter(x -> x.getSerialNumber() != null).forEach(
|
| 862 |
} else {
|
832 |
lineItem -> {
|
| 863 |
break; // slabs beyond this don't qualify
|
833 |
if (activatedImeisActivationDateMap == null) {
|
| - |
|
834 |
lineItemValueMap.put(lineItem, (int) fofoOrderItem.getDp());
|
| - |
|
835 |
} else if (activatedImeisActivationDateMap.containsKey(lineItem.getSerialNumber())) {
|
| - |
|
836 |
if (itemCriteriaPayout.isWithinRange(activatedImeisActivationDateMap.get(lineItem.getSerialNumber()))) {
|
| - |
|
837 |
lineItemValueMap.put(lineItem, (int) fofoOrderItem.getDp());
|
| 864 |
}
|
838 |
}
|
| 865 |
}
|
839 |
}
|
| 866 |
if(eligibleSlab != null) {
|
840 |
}
|
| 867 |
eligibleSlab.setSelected(true);
|
841 |
);
|
| 868 |
LOGGER.info("Eligible Slab {}", eligibleSlab);
|
- |
|
| 869 |
}
|
842 |
}
|
| - |
|
843 |
eligibleQty = lineItemValueMap.size();
|
| - |
|
844 |
eligibleValue = lineItemValueMap.entrySet().stream().collect(Collectors.summingInt(x -> x.getValue()));
|
| - |
|
845 |
criteriaQtyAmountModel.setActivationQty(eligibleQty);
|
| - |
|
846 |
criteriaQtyAmountModel.setActivationAmount(eligibleValue);
|
| - |
|
847 |
}
|
| 870 |
|
848 |
|
| 871 |
if (AmountType.PERCENTAGE.equals(itemCriteriaPayout.getAmountType())) {
|
- |
|
| 872 |
finalPayout = (eligiblePayoutValue * eligibleCriteriaSaleDp) / 100;
|
849 |
int eligibleBaseQty = eligibleQty;
|
| 873 |
} else if (AmountType.FIXED.equals(itemCriteriaPayout.getAmountType())) {
|
- |
|
| 874 |
finalPayout = eligiblePayoutValue * eligibleCriteriaSale;
|
850 |
int eligibleBaseValue = eligibleValue;
|
| 875 |
} else {
|
- |
|
| 876 |
finalPayout = eligiblePayoutValue;
|
851 |
if (createOfferRequest.isBaseCriteria()) {
|
| 877 |
}
|
- |
|
| 878 |
qtyAmountModel1.setFinalPayout(finalPayout);
|
852 |
eligibleBaseQty = qtyAmountModel.getActivationQty();
|
| 879 |
LOGGER.info("Final Payout - {}", finalPayout);
|
853 |
eligibleBaseValue = (int) qtyAmountModel.getActivationAmount();
|
| 880 |
}
|
854 |
}
|
| 881 |
|
855 |
|
| - |
|
856 |
int eligibleSale = eligibleBaseValue;
|
| - |
|
857 |
int eligibleCriteriaSale = eligibleValue;
|
| - |
|
858 |
int eligibleCriteriaSaleDp = eligibleValue;
|
| 882 |
|
859 |
|
| - |
|
860 |
if (createOfferRequest.getTargetType().equals(AchievementType.QUANTITY)) {
|
| - |
|
861 |
eligibleSale = eligibleBaseQty;
|
| - |
|
862 |
eligibleCriteriaSale = eligibleQty;
|
| - |
|
863 |
}
|
| - |
|
864 |
|
| - |
|
865 |
PayoutSlab eligibleSlab = findEligibleSlab(itemCriteriaPayout.getPayoutSlabs(), eligibleSale);
|
| - |
|
866 |
double finalPayout = calculateFinalPayout(eligibleSlab, itemCriteriaPayout.getAmountType(),
|
| - |
|
867 |
eligibleCriteriaSaleDp, eligibleCriteriaSale);
|
| - |
|
868 |
if (eligibleSlab != null) {
|
| - |
|
869 |
LOGGER.info("Eligible Slab {}", eligibleSlab);
|
| - |
|
870 |
}
|
| - |
|
871 |
criteriaQtyAmountModel.setFinalPayout(finalPayout);
|
| - |
|
872 |
LOGGER.info("Final Payout - {}", finalPayout);
|
| 883 |
}
|
873 |
}
|
| 884 |
return qtyAmountMap;
|
874 |
return qtyAmountMap;
|
| 885 |
}
|
875 |
}
|
| 886 |
|
876 |
|
| 887 |
@Override
|
877 |
@Override
|