| Line 31... |
Line 31... |
| 31 |
import com.spice.profitmandi.dao.repository.catalog.*;
|
31 |
import com.spice.profitmandi.dao.repository.catalog.*;
|
| 32 |
import com.spice.profitmandi.dao.repository.fofo.ActivatedImeiRepository;
|
32 |
import com.spice.profitmandi.dao.repository.fofo.ActivatedImeiRepository;
|
| 33 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
33 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 34 |
import com.spice.profitmandi.dao.repository.fofo.OfferPayoutRepository;
|
34 |
import com.spice.profitmandi.dao.repository.fofo.OfferPayoutRepository;
|
| 35 |
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
|
35 |
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
|
| - |
|
36 |
import com.spice.profitmandi.dao.repository.warehouse.AgeingSummaryModel;
|
| 36 |
import com.spice.profitmandi.dao.repository.warehouse.WarehouseInventoryItemRepository;
|
37 |
import com.spice.profitmandi.dao.repository.warehouse.WarehouseInventoryItemRepository;
|
| 37 |
import com.spice.profitmandi.dao.repository.warehouse.WarehouseScanRepository;
|
38 |
import com.spice.profitmandi.dao.repository.warehouse.WarehouseScanRepository;
|
| 38 |
import com.spice.profitmandi.service.pricecircular.PriceCircularService;
|
39 |
import com.spice.profitmandi.service.pricecircular.PriceCircularService;
|
| 39 |
import com.spice.profitmandi.service.scheme.InventoryPayoutModel;
|
40 |
import com.spice.profitmandi.service.scheme.InventoryPayoutModel;
|
| 40 |
import com.spice.profitmandi.service.user.RetailerService;
|
41 |
import com.spice.profitmandi.service.user.RetailerService;
|
| Line 642... |
Line 643... |
| 642 |
|
643 |
|
| 643 |
|
644 |
|
| 644 |
Map<String, Double> serialNumberPaid = offerPayouts.stream().filter(x -> x.getRejectTimestamp() == null).collect(Collectors.groupingBy(x -> x.getSerialNumber(), Collectors.summingDouble(x -> x.getSlabAmount())));
|
645 |
Map<String, Double> serialNumberPaid = offerPayouts.stream().filter(x -> x.getRejectTimestamp() == null).collect(Collectors.groupingBy(x -> x.getSerialNumber(), Collectors.summingDouble(x -> x.getSlabAmount())));
|
| 645 |
Map<Integer, Map<Integer, List<FofoOrderItem>>> criteriaPartnerwiseTertiary = offerRepository.getCriteriaWisePartnerTertiary(createOfferRequest);
|
646 |
Map<Integer, Map<Integer, List<FofoOrderItem>>> criteriaPartnerwiseTertiary = offerRepository.getCriteriaWisePartnerTertiary(createOfferRequest);
|
| 646 |
|
647 |
|
| 647 |
|
- |
|
| - |
|
648 |
Map<String, AgeingSummaryModel> ageingSummaryModelsMap = null;
|
| 648 |
final Set<String> activatedImeis;
|
649 |
final Set<String> activatedImeis;
|
| 649 |
if (createOfferRequest.getSchemeType().equals(OfferSchemeType.ACTIVATION)) {
|
650 |
if (createOfferRequest.getSchemeType().equals(OfferSchemeType.ACTIVATION)) {
|
| 650 |
//All Serialnumbers for all eligible retailers
|
651 |
//All Serialnumbers for all eligible retailers
|
| 651 |
List<String> serialNumbers = criteriaPartnerwiseTertiary.entrySet().stream().flatMap(x -> x.getValue().entrySet().stream().flatMap(foiList -> foiList.getValue().stream()))
|
652 |
List<String> serialNumbers = criteriaPartnerwiseTertiary.entrySet().stream().flatMap(x -> x.getValue().entrySet().stream().flatMap(foiList -> foiList.getValue().stream()))
|
| 652 |
.flatMap(y -> y.getFofoLineItems().stream()).filter(fli -> fli.getSerialNumber() != null)
|
653 |
.flatMap(y -> y.getFofoLineItems().stream()).filter(fli -> fli.getSerialNumber() != null)
|
| 653 |
.map(x -> x.getSerialNumber()).collect(Collectors.toList());
|
654 |
.map(x -> x.getSerialNumber()).collect(Collectors.toList());
|
| 654 |
if (serialNumbers.size() > 0) {
|
655 |
if (serialNumbers.size() > 0) {
|
| 655 |
activatedImeis = activatedImeiRepository.selectBySerialNumbers(serialNumbers).stream()
|
656 |
activatedImeis = activatedImeiRepository.selectBySerialNumbers(serialNumbers).stream()
|
| 656 |
.filter(x -> createOfferRequest.isWithinRange(x.getActivationTimestamp()))
|
657 |
.filter(x -> createOfferRequest.isWithinRange(x.getActivationTimestamp()))
|
| 657 |
.map(x -> x.getSerialNumber()).collect(Collectors.toSet());
|
658 |
.map(x -> x.getSerialNumber()).collect(Collectors.toSet());
|
| - |
|
659 |
ageingSummaryModelsMap = warehouseInventoryItemRepository.findStockAgeingByFofoIdSerialNumbers(0, serialNumbers).stream().collect(Collectors.toMap(x->x.getSerialNumber(), x->x));
|
| 658 |
} else {
|
660 |
} else {
|
| 659 |
activatedImeis = null;
|
661 |
activatedImeis = null;
|
| 660 |
}
|
662 |
}
|
| 661 |
} else {
|
663 |
} else {
|
| 662 |
activatedImeis = null;
|
664 |
activatedImeis = null;
|
| Line 787... |
Line 789... |
| 787 |
|
789 |
|
| 788 |
if (finalPayout > 0) {
|
790 |
if (finalPayout > 0) {
|
| 789 |
List<Integer> inventoryItemIds = lineItemValueMap.keySet().stream().map(x -> x.getInventoryItemId()).collect(Collectors.toList());
|
791 |
List<Integer> inventoryItemIds = lineItemValueMap.keySet().stream().map(x -> x.getInventoryItemId()).collect(Collectors.toList());
|
| 790 |
Map<Integer, InventoryItem> inventoryItemsMap = inventoryItemRepository.selectAllByIds(inventoryItemIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
792 |
Map<Integer, InventoryItem> inventoryItemsMap = inventoryItemRepository.selectAllByIds(inventoryItemIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 791 |
for (Map.Entry<FofoLineItem, Integer> lineItemValueEntry : lineItemValueMap.entrySet()) {
|
793 |
for (Map.Entry<FofoLineItem, Integer> lineItemValueEntry : lineItemValueMap.entrySet()) {
|
| - |
|
794 |
FofoLineItem fofoLineItem = lineItemValueEntry.getKey();
|
| - |
|
795 |
if(ageingSummaryModelsMap.containsKey(fofoLineItem.getSerialNumber())) {
|
| - |
|
796 |
if(ageingSummaryModelsMap.get(fofoLineItem.getSerialNumber()).isAgedAbove(90)) {
|
| - |
|
797 |
continue;
|
| - |
|
798 |
}
|
| - |
|
799 |
}
|
| 792 |
double amount = 0;
|
800 |
double amount = 0;
|
| 793 |
int totalDpValue = lineItemValueMap.values().stream().collect(Collectors.summingInt(x -> x));
|
801 |
int totalDpValue = lineItemValueMap.values().stream().collect(Collectors.summingInt(x -> x));
|
| 794 |
LOGGER.info("Total DP Value {}", totalDpValue);
|
802 |
LOGGER.info("Total DP Value {}", totalDpValue);
|
| 795 |
if (AmountType.SLAB_FIXED.equals(itemCriteriaPayout.getAmountType())) {
|
803 |
if (AmountType.SLAB_FIXED.equals(itemCriteriaPayout.getAmountType())) {
|
| 796 |
amount = (eligiblePayoutValue * lineItemValueEntry.getValue()) / totalDpValue;
|
804 |
amount = (eligiblePayoutValue * lineItemValueEntry.getValue()) / totalDpValue;
|
| 797 |
LOGGER.info("Amount - {}", amount);
|
805 |
LOGGER.info("Amount - {}", amount);
|
| 798 |
//Fixed slab should be treated as fixed after payout
|
806 |
//Fixed slab should be treated as fixed after payout
|
| 799 |
} else {
|
807 |
} else {
|
| 800 |
amount = eligiblePayoutValue;
|
808 |
amount = eligiblePayoutValue;
|
| 801 |
//Fixed slab has already taken care of that amount;
|
809 |
//Fixed slab has already taken care of that amount;
|
| 802 |
if (serialNumberPaid.containsKey(lineItemValueEntry.getKey().getSerialNumber())) {
|
810 |
if (serialNumberPaid.containsKey(fofoLineItem.getSerialNumber())) {
|
| 803 |
amount = amount - serialNumberPaid.get(lineItemValueEntry.getKey().getSerialNumber());
|
811 |
amount = amount - serialNumberPaid.get(fofoLineItem.getSerialNumber());
|
| 804 |
}
|
812 |
}
|
| 805 |
}
|
813 |
}
|
| 806 |
LOGGER.info("Amount - {}", amount);
|
814 |
LOGGER.info("Amount - {}", amount);
|
| 807 |
//ignore reasonably small
|
815 |
//ignore reasonably small
|
| 808 |
if (amount < Utils.DOUBLE_EPSILON) continue;
|
816 |
if (amount < Utils.DOUBLE_EPSILON) continue;
|
| 809 |
AmountModel amountModel = new AmountModel();
|
817 |
AmountModel amountModel = new AmountModel();
|
| 810 |
amountModel.setAmountType(itemCriteriaPayout.getAmountType());
|
818 |
amountModel.setAmountType(itemCriteriaPayout.getAmountType());
|
| 811 |
amountModel.setAmount(amount);
|
819 |
amountModel.setAmount(amount);
|
| 812 |
amountModel.setDiscount(createOfferRequest.isDiscount());
|
820 |
amountModel.setDiscount(createOfferRequest.isDiscount());
|
| 813 |
InventoryPayoutModel inventoryPayoutModel = priceCircularService.getPayouts(inventoryItemsMap.get(lineItemValueEntry.getKey().getInventoryItemId()));
|
821 |
InventoryPayoutModel inventoryPayoutModel = priceCircularService.getPayouts(inventoryItemsMap.get(fofoLineItem.getInventoryItemId()));
|
| 814 |
double rolloutAmount = inventoryPayoutModel.getRolloutAmount(amountModel);
|
822 |
double rolloutAmount = inventoryPayoutModel.getRolloutAmount(amountModel);
|
| 815 |
totalRolloutAmount += rolloutAmount;
|
823 |
totalRolloutAmount += rolloutAmount;
|
| 816 |
|
824 |
|
| 817 |
OfferPayout offerPayout = new OfferPayout(fofoId, createOfferRequest.getId(), criteriaId, amount, lineItemValueEntry.getKey().getSerialNumber(), rolloutAmount, SchemePayoutStatus.CREDITED, createOfferRequest.getDescription(), LocalDateTime.now());
|
825 |
OfferPayout offerPayout = new OfferPayout(fofoId, createOfferRequest.getId(), criteriaId, amount, fofoLineItem.getSerialNumber(), rolloutAmount, SchemePayoutStatus.CREDITED, createOfferRequest.getDescription(), LocalDateTime.now());
|
| 818 |
//offerPayout.setInventoryItemId(inventoryItemSaleModelsMap.get(lineItemValueEntry.getKey().getInventoryItemId()));
|
826 |
//offerPayout.setInventoryItemId(inventoryItemSaleModelsMap.get(lineItemValueEntry.getKey().getInventoryItemId()));
|
| 819 |
offerPayoutRepository.persist(offerPayout);
|
827 |
offerPayoutRepository.persist(offerPayout);
|
| 820 |
}
|
828 |
}
|
| 821 |
walletService.addAmountToWallet((int) fofoId, createOfferRequest.getId(), WalletReferenceType.ADDITIONAL_SCHEME, createOfferRequest.getDescription(), (float) totalRolloutAmount, LocalDateTime.now());
|
829 |
walletService.addAmountToWallet((int) fofoId, createOfferRequest.getId(), WalletReferenceType.ADDITIONAL_SCHEME, createOfferRequest.getDescription(), (float) totalRolloutAmount, LocalDateTime.now());
|
| 822 |
}
|
830 |
}
|
| Line 824... |
Line 832... |
| 824 |
}
|
832 |
}
|
| 825 |
Offer offer = offerRepository.selectById(createOfferRequest.getId());
|
833 |
Offer offer = offerRepository.selectById(createOfferRequest.getId());
|
| 826 |
offer.setProcessedTimestamp(LocalDateTime.now());
|
834 |
offer.setProcessedTimestamp(LocalDateTime.now());
|
| 827 |
}
|
835 |
}
|
| 828 |
|
836 |
|
| 829 |
private void extracted(CreateOfferRequest createOfferRequest, Map<String, Double> serialNumberPaid, ItemCriteriaPayout itemCriteriaPayout, int criteriaId, double totalRolloutAmount, int fofoId, Map<FofoLineItem, Integer> lineItemValueMap, float eligiblePayoutValue) throws ProfitMandiBusinessException {
|
- |
|
| 830 |
List<Integer> inventoryItemIds = lineItemValueMap.keySet().stream().map(x -> x.getInventoryItemId()).collect(Collectors.toList());
|
- |
|
| 831 |
Map<Integer, InventoryItem> inventoryItemsMap = inventoryItemRepository.selectAllByIds(inventoryItemIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
- |
|
| 832 |
for (Map.Entry<FofoLineItem, Integer> lineItemValueEntry : lineItemValueMap.entrySet()) {
|
- |
|
| 833 |
double amount = 0;
|
- |
|
| 834 |
int totalDpValue = lineItemValueMap.values().stream().collect(Collectors.summingInt(x -> x));
|
- |
|
| 835 |
LOGGER.info("Total DP Value {}", totalDpValue);
|
- |
|
| 836 |
if (AmountType.SLAB_FIXED.equals(itemCriteriaPayout.getAmountType())) {
|
- |
|
| 837 |
amount = (eligiblePayoutValue * lineItemValueEntry.getValue()) / totalDpValue;
|
- |
|
| 838 |
LOGGER.info("Amount - {}", amount);
|
- |
|
| 839 |
//Fixed slab should be treated as fixed after payout
|
- |
|
| 840 |
} else {
|
- |
|
| 841 |
amount = eligiblePayoutValue;
|
- |
|
| 842 |
//Fixed slab has already taken care of that amount;
|
- |
|
| 843 |
if (serialNumberPaid.containsKey(lineItemValueEntry.getKey().getSerialNumber())) {
|
- |
|
| 844 |
amount = amount - serialNumberPaid.get(lineItemValueEntry.getKey().getSerialNumber());
|
- |
|
| 845 |
}
|
- |
|
| 846 |
}
|
- |
|
| 847 |
LOGGER.info("Amount - {}", amount);
|
- |
|
| 848 |
//ignore reasonably small
|
- |
|
| 849 |
if (amount < Utils.DOUBLE_EPSILON) continue;
|
- |
|
| 850 |
AmountModel amountModel = new AmountModel();
|
- |
|
| 851 |
amountModel.setAmountType(itemCriteriaPayout.getAmountType());
|
- |
|
| 852 |
amountModel.setAmount(amount);
|
- |
|
| 853 |
amountModel.setDiscount(createOfferRequest.isDiscount());
|
- |
|
| 854 |
InventoryPayoutModel inventoryPayoutModel = priceCircularService.getPayouts(inventoryItemsMap.get(lineItemValueEntry.getKey().getInventoryItemId()));
|
- |
|
| 855 |
double rolloutAmount = inventoryPayoutModel.getRolloutAmount(amountModel);
|
- |
|
| 856 |
totalRolloutAmount += rolloutAmount;
|
- |
|
| 857 |
|
- |
|
| 858 |
OfferPayout offerPayout = new OfferPayout(fofoId, createOfferRequest.getId(), criteriaId, amount, lineItemValueEntry.getKey().getSerialNumber(), rolloutAmount, SchemePayoutStatus.CREDITED, createOfferRequest.getDescription(), LocalDateTime.now());
|
- |
|
| 859 |
//offerPayout.setInventoryItemId(inventoryItemSaleModelsMap.get(lineItemValueEntry.getKey().getInventoryItemId()));
|
- |
|
| 860 |
offerPayoutRepository.persist(offerPayout);
|
- |
|
| 861 |
}
|
- |
|
| 862 |
walletService.addAmountToWallet((int) fofoId, createOfferRequest.getId(), WalletReferenceType.ADDITIONAL_SCHEME, createOfferRequest.getDescription(), (float) totalRolloutAmount, LocalDateTime.now());
|
- |
|
| 863 |
}
|
- |
|
| 864 |
|
- |
|
| 865 |
@Override
|
837 |
@Override
|
| 866 |
public void processSellin(CreateOfferRequest createOfferRequest) throws Exception {
|
838 |
public void processSellin(CreateOfferRequest createOfferRequest) throws Exception {
|
| 867 |
|
839 |
|
| 868 |
//List<OfferRowModel> offerRowModels = new ArrayList<>();
|
840 |
//List<OfferRowModel> offerRowModels = new ArrayList<>();
|
| 869 |
List<OfferPayout> offerPayouts = offerPayoutRepository.selectAllByOfferId(createOfferRequest.getId());
|
841 |
List<OfferPayout> offerPayouts = offerPayoutRepository.selectAllByOfferId(createOfferRequest.getId());
|