| Line 770... |
Line 770... |
| 770 |
offerRowModel.setEligibleSale(eligibleSale);
|
770 |
offerRowModel.setEligibleSale(eligibleSale);
|
| 771 |
float eligiblePayoutValue = 0;
|
771 |
float eligiblePayoutValue = 0;
|
| 772 |
double finalPayout = 0;
|
772 |
double finalPayout = 0;
|
| 773 |
for (PayoutSlab payoutSlab : itemCriteriaPayout.getPayoutSlabs()) {
|
773 |
for (PayoutSlab payoutSlab : itemCriteriaPayout.getPayoutSlabs()) {
|
| 774 |
if (payoutSlab.getOnwardsAmount() <= eligibleSale) {
|
774 |
if (payoutSlab.getOnwardsAmount() <= eligibleSale) {
|
| - |
|
775 |
LOGGER.info("Eligible Sale {}", eligibleSale);
|
| 775 |
offerRowModel.setPayoutTargetAchieved(payoutSlab.getOnwardsAmount());
|
776 |
offerRowModel.setPayoutTargetAchieved(payoutSlab.getOnwardsAmount());
|
| 776 |
eligiblePayoutValue = payoutSlab.getPayoutAmount();
|
777 |
eligiblePayoutValue = payoutSlab.getPayoutAmount();
|
| 777 |
offerRowModel.setPayoutValue(eligiblePayoutValue);
|
778 |
offerRowModel.setPayoutValue(eligiblePayoutValue);
|
| 778 |
}
|
779 |
}
|
| 779 |
}
|
780 |
}
|
| 780 |
if (AmountType.PERCENTAGE.equals(itemCriteriaPayout.getAmountType())) {
|
781 |
if (AmountType.PERCENTAGE.equals(itemCriteriaPayout.getAmountType())) {
|
| 781 |
finalPayout = (eligiblePayoutValue * eligibleCriteriaSaleDp) / 100;
|
782 |
finalPayout = (eligiblePayoutValue * eligibleCriteriaSaleDp) / 100;
|
| 782 |
} else if (AmountType.FIXED.equals(itemCriteriaPayout.getAmountType())) {
|
783 |
} else if (AmountType.FIXED.equals(itemCriteriaPayout.getAmountType())) {
|
| 783 |
finalPayout = eligiblePayoutValue * eligibleCriteriaSale;
|
784 |
finalPayout = eligiblePayoutValue * eligibleCriteriaSale;
|
| 784 |
} else {
|
785 |
} else {
|
| 785 |
finalPayout = eligiblePayoutValue;
|
- |
|
| 786 |
Map<Integer, Double> fofoCriteriaMap = fixedSlabCriteriaPartnerMap.get(criteriaId);
|
786 |
Map<Integer, Double> fofoCriteriaMap = fixedSlabCriteriaPartnerMap.get(criteriaId);
|
| - |
|
787 |
LOGGER.info("fofoCriteriaMap {}", fofoCriteriaMap);
|
| - |
|
788 |
finalPayout = eligiblePayoutValue;
|
| 787 |
if (fofoCriteriaMap != null) {
|
789 |
if (fofoCriteriaMap != null) {
|
| 788 |
if (fofoCriteriaMap.containsKey(fofoId)) {
|
790 |
if (fofoCriteriaMap.containsKey(fofoId)) {
|
| 789 |
double totalPayout = fofoCriteriaMap.get(fofoId);
|
791 |
double totalPayout = fofoCriteriaMap.get(fofoId);
|
| - |
|
792 |
finalPayout = eligiblePayoutValue - totalPayout;
|
| 790 |
if (Math.abs(totalPayout - finalPayout) < Utils.DOUBLE_EPSILON)
|
793 |
if (Math.abs(finalPayout) < Utils.DOUBLE_EPSILON) {
|
| 791 |
finalPayout = 0;
|
794 |
finalPayout = 0;
|
| - |
|
795 |
}
|
| 792 |
}
|
796 |
}
|
| 793 |
}
|
797 |
}
|
| 794 |
}
|
798 |
}
|
| 795 |
|
799 |
|
| - |
|
800 |
LOGGER.info("Final Payout - {}", finalPayout);
|
| - |
|
801 |
|
| 796 |
if (finalPayout > 0) {
|
802 |
if (finalPayout > 0) {
|
| 797 |
List<Integer> inventoryItemIds = lineItemValueMap.keySet().stream().map(x -> x.getInventoryItemId()).collect(Collectors.toList());
|
803 |
List<Integer> inventoryItemIds = lineItemValueMap.keySet().stream().map(x -> x.getInventoryItemId()).collect(Collectors.toList());
|
| 798 |
Map<Integer, InventoryItem> inventoryItemsMap = inventoryItemRepository.selectAllByIds(inventoryItemIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
804 |
Map<Integer, InventoryItem> inventoryItemsMap = inventoryItemRepository.selectAllByIds(inventoryItemIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 799 |
int totalDpValue = lineItemValueMap.values().stream().collect(Collectors.summingInt(x -> x));
|
- |
|
| 800 |
for (Map.Entry<FofoLineItem, Integer> lineItemValueEntry : lineItemValueMap.entrySet()) {
|
805 |
for (Map.Entry<FofoLineItem, Integer> lineItemValueEntry : lineItemValueMap.entrySet()) {
|
| 801 |
double amount = 0;
|
806 |
double amount = 0;
|
| - |
|
807 |
int totalDpValue = lineItemValueMap.values().stream().collect(Collectors.summingInt(x -> x));
|
| - |
|
808 |
LOGGER.info("Total DP Value {}", totalDpValue);
|
| 802 |
if (AmountType.SLAB_FIXED.equals(itemCriteriaPayout.getAmountType())) {
|
809 |
if (AmountType.SLAB_FIXED.equals(itemCriteriaPayout.getAmountType())) {
|
| 803 |
amount = eligiblePayoutValue * (lineItemValueEntry.getValue() / totalDpValue);
|
810 |
amount = (eligiblePayoutValue * lineItemValueEntry.getValue()) / totalDpValue;
|
| - |
|
811 |
LOGGER.info("Amount - {}", amount);
|
| 804 |
//Fixed slab should be treated as fixed after payout
|
812 |
//Fixed slab should be treated as fixed after payout
|
| 805 |
} else {
|
813 |
} else {
|
| 806 |
amount = eligiblePayoutValue;
|
814 |
amount = eligiblePayoutValue;
|
| - |
|
815 |
//Fixed slab has already taken care of that amount;
|
| - |
|
816 |
if (serialNumberPaid.containsKey(lineItemValueEntry.getKey().getSerialNumber())) {
|
| - |
|
817 |
amount = amount - serialNumberPaid.get(lineItemValueEntry.getKey().getSerialNumber());
|
| - |
|
818 |
}
|
| 807 |
}
|
819 |
}
|
| 808 |
if (serialNumberPaid.containsKey(lineItemValueEntry.getKey().getSerialNumber())) {
|
- |
|
| 809 |
amount = amount - serialNumberPaid.get(lineItemValueEntry.getKey().getSerialNumber());
|
- |
|
| 810 |
}
|
820 |
LOGGER.info("Amount - {}", amount);
|
| 811 |
//ignore reasonably small
|
821 |
//ignore reasonably small
|
| 812 |
if (amount < Utils.DOUBLE_EPSILON) continue;
|
822 |
if (amount < Utils.DOUBLE_EPSILON) continue;
|
| 813 |
AmountModel amountModel = new AmountModel();
|
823 |
AmountModel amountModel = new AmountModel();
|
| 814 |
amountModel.setAmountType(itemCriteriaPayout.getAmountType());
|
824 |
amountModel.setAmountType(itemCriteriaPayout.getAmountType());
|
| 815 |
amountModel.setAmount(amount);
|
825 |
amountModel.setAmount(amount);
|
| Line 820... |
Line 830... |
| 820 |
|
830 |
|
| 821 |
OfferPayout offerPayout = new OfferPayout(fofoId, createOfferRequest.getId(), criteriaId, amount, lineItemValueEntry.getKey().getSerialNumber(), rolloutAmount, SchemePayoutStatus.CREDITED, createOfferRequest.getDescription(), LocalDateTime.now());
|
831 |
OfferPayout offerPayout = new OfferPayout(fofoId, createOfferRequest.getId(), criteriaId, amount, lineItemValueEntry.getKey().getSerialNumber(), rolloutAmount, SchemePayoutStatus.CREDITED, createOfferRequest.getDescription(), LocalDateTime.now());
|
| 822 |
//offerPayout.setInventoryItemId(inventoryItemSaleModelsMap.get(lineItemValueEntry.getKey().getInventoryItemId()));
|
832 |
//offerPayout.setInventoryItemId(inventoryItemSaleModelsMap.get(lineItemValueEntry.getKey().getInventoryItemId()));
|
| 823 |
offerPayoutRepository.persist(offerPayout);
|
833 |
offerPayoutRepository.persist(offerPayout);
|
| 824 |
}
|
834 |
}
|
| - |
|
835 |
walletService.addAmountToWallet((int) fofoId, createOfferRequest.getId(), WalletReferenceType.ADDITIONAL_SCHEME, createOfferRequest.getDescription(), (float) totalRolloutAmount, LocalDateTime.now());
|
| 825 |
}
|
836 |
}
|
| 826 |
walletService.addAmountToWallet((int) fofoId, createOfferRequest.getId(), WalletReferenceType.ADDITIONAL_SCHEME, createOfferRequest.getDescription(), (float) totalRolloutAmount, LocalDateTime.now());
|
- |
|
| 827 |
}
|
837 |
}
|
| 828 |
}
|
838 |
}
|
| 829 |
Offer offer = offerRepository.selectById(createOfferRequest.getId());
|
839 |
Offer offer = offerRepository.selectById(createOfferRequest.getId());
|
| 830 |
offer.setProcessedTimestamp(LocalDateTime.now());
|
840 |
offer.setProcessedTimestamp(LocalDateTime.now());
|
| 831 |
}
|
841 |
}
|