| Line 505... |
Line 505... |
| 505 |
return amount;
|
505 |
return amount;
|
| 506 |
}
|
506 |
}
|
| 507 |
|
507 |
|
| 508 |
//Only in and activation margins are allowed to be rolled out more than twice
|
508 |
//Only in and activation margins are allowed to be rolled out more than twice
|
| 509 |
private float createSchemeInOut(List<SchemeSummaryModel> schemeSummaryModels, InventoryItem inventoryItem) throws ProfitMandiBusinessException {
|
509 |
private float createSchemeInOut(List<SchemeSummaryModel> schemeSummaryModels, InventoryItem inventoryItem) throws ProfitMandiBusinessException {
|
| 510 |
|
- |
|
| - |
|
510 |
LOGGER.info("schemeSummaryModels - {}", schemeSummaryModels);
|
| 511 |
InventoryPayoutModel inventoryPayoutModel = priceCircularService.getPayouts(inventoryItem);
|
511 |
InventoryPayoutModel inventoryPayoutModel = priceCircularService.getPayouts(inventoryItem);
|
| 512 |
//Get all schemes
|
512 |
//Get all schemes
|
| 513 |
List<SchemeSummaryModel> inventoryPayoutModelToProcess = schemeSummaryModels.stream().filter(x -> x.isProcess()).collect(Collectors.toList());
|
513 |
List<SchemeSummaryModel> inventoryPayoutModelToProcess = schemeSummaryModels.stream().filter(x -> x.isProcess()).collect(Collectors.toList());
|
| 514 |
|
514 |
|
| 515 |
List<SchemeInOut> paidSios = inventoryPayoutModel.getPaidSios();
|
515 |
List<SchemeInOut> paidSios = inventoryPayoutModel.getPaidSios();
|
| Line 751... |
Line 751... |
| 751 |
float amountToCredit = supportAmount * (1 - (totalMargin / (100 + taxRate)));
|
751 |
float amountToCredit = supportAmount * (1 - (totalMargin / (100 + taxRate)));
|
| 752 |
return amountToCredit;
|
752 |
return amountToCredit;
|
| 753 |
}
|
753 |
}
|
| 754 |
|
754 |
|
| 755 |
@Override
|
755 |
@Override
|
| 756 |
public void rollbackSchemes(List<Integer> inventoryItemIds, int rollbackReference, String rollbackReason)
|
756 |
public void rollbackSchemes(List<Integer> inventoryItemIds, String rollbackReason)
|
| 757 |
throws Exception {
|
757 |
throws Exception {
|
| - |
|
758 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectAllByIds(inventoryItemIds);
|
| - |
|
759 |
Map<Integer, InventoryItem> inventoryItemMap = inventoryItems.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| - |
|
760 |
Map<Integer, Integer> purchasePartnerMap = inventoryItems.stream().collect(Collectors.toMap(x -> x.getPurchaseId(), x -> x.getFofoId(), (u, v) -> u));
|
| - |
|
761 |
|
| 758 |
Set<Integer> inventoryItemIdSet = new HashSet<>(inventoryItemIds);
|
762 |
LOGGER.info("inventoryItemIds - {}", inventoryItemIds);
|
| - |
|
763 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectByInventoryItemIds(new HashSet<>(inventoryItemIds));
|
| - |
|
764 |
List<Integer> schemeIds = schemeInOuts.stream().map(x -> x.getSchemeId()).distinct().collect(Collectors.toList());
|
| 759 |
float amountToRollback = 0;
|
765 |
if(schemeIds.size() == 0) return;
|
| 760 |
List<SchemeInOut> schemes = schemeInOutRepository.selectByInventoryItemIds(inventoryItemIdSet);
|
766 |
List<Scheme> schemes = schemeRepository.selectBySchemeIds(schemeIds);
|
| - |
|
767 |
Map<Integer, Float> inSchemesMap = new HashMap<>();
|
| - |
|
768 |
Map<Integer, Float> outSchemesMap = new HashMap<>();
|
| - |
|
769 |
Map<Integer, Scheme> schemesMap = schemes.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 761 |
for (SchemeInOut schemeInOut : schemes) {
|
770 |
for (SchemeInOut schemeInOut : schemeInOuts) {
|
| - |
|
771 |
Map<Integer, Float> schemePayoutMap;
|
| - |
|
772 |
int inventoryItemId = schemeInOut.getInventoryItemId();
|
| 762 |
if (schemeInOut.getRolledBackTimestamp() == null) {
|
773 |
if (schemeInOut.getRolledBackTimestamp() == null) {
|
| 763 |
schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
|
774 |
schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
|
| 764 |
if (schemeInOut.getStatus() == null || schemeInOut.getStatus().equals(SchemePayoutStatus.CREDITED)) {
|
775 |
if (schemeInOut.getStatus() == null || schemeInOut.getStatus().equals(SchemePayoutStatus.CREDITED)) {
|
| 765 |
amountToRollback += schemeInOut.getAmount();
|
776 |
Scheme scheme = schemesMap.get(schemeInOut.getSchemeId());
|
| - |
|
777 |
if (scheme.getType().equals(SchemeType.IN)) {
|
| - |
|
778 |
schemePayoutMap = inSchemesMap;
|
| - |
|
779 |
} else {
|
| - |
|
780 |
schemePayoutMap = outSchemesMap;
|
| - |
|
781 |
}
|
| - |
|
782 |
if (!schemePayoutMap.containsKey(inventoryItemId)) {
|
| - |
|
783 |
schemePayoutMap.put(inventoryItemId, 0f);
|
| - |
|
784 |
}
|
| - |
|
785 |
schemePayoutMap.put(inventoryItemId, inSchemesMap.get(inventoryItemId) + schemeInOut.getAmount());
|
| 766 |
}
|
786 |
}
|
| 767 |
schemeInOut.setStatus(SchemePayoutStatus.REJECTED);
|
787 |
schemeInOut.setStatus(SchemePayoutStatus.REJECTED);
|
| 768 |
schemeInOut.setStatusDescription(rollbackReason);
|
788 |
schemeInOut.setStatusDescription(rollbackReason);
|
| 769 |
}
|
789 |
}
|
| 770 |
}
|
790 |
}
|
| 771 |
if (amountToRollback > 0) {
|
- |
|
| 772 |
int inventoryItemId = inventoryItemIds.get(0);
|
791 |
Map<Integer, Double> purchaseRollbackAmountMap = inSchemesMap.entrySet().stream().collect(Collectors.groupingBy(x -> inventoryItemMap.get(x.getKey()).getPurchaseId(), Collectors.summingDouble(x -> x.getValue())));
|
| - |
|
792 |
|
| 773 |
InventoryItem ii = inventoryItemRepository.selectById(inventoryItemId);
|
793 |
for (Map.Entry<Integer, Double> purchaseRollbackAmountEntry : purchaseRollbackAmountMap.entrySet()) {
|
| 774 |
Integer fofoId = ii.getFofoId();
|
794 |
int purchaseId = purchaseRollbackAmountEntry.getKey();
|
| 775 |
// Purchase p = purchaseRepository.selectById(ii.getPurchaseId());
|
795 |
Double amountToRollback = purchaseRollbackAmountEntry.getValue();
|
| 776 |
// TODO//
|
796 |
if (amountToRollback != null && amountToRollback > 0) {
|
| 777 |
walletService.rollbackAmountFromWallet(fofoId, amountToRollback, ii.getPurchaseId(),
|
797 |
walletService.rollbackAmountFromWallet(purchasePartnerMap.get(purchaseId), amountToRollback.floatValue(), purchaseId,
|
| 778 |
WalletReferenceType.SCHEME_IN, rollbackReason, LocalDateTime.now());
|
798 |
WalletReferenceType.SCHEME_IN, rollbackReason, LocalDateTime.now());
|
| - |
|
799 |
}
|
| 779 |
}
|
800 |
}
|
| 780 |
}
|
801 |
}
|
| 781 |
|
802 |
|
| 782 |
@Override
|
803 |
@Override
|
| 783 |
public Map<String, Object> getSchemes(Set<Integer> roleIds, int offset, int limit)
|
804 |
public Map<String, Object> getSchemes(Set<Integer> roleIds, int offset, int limit)
|
| Line 975... |
Line 996... |
| 975 |
|
996 |
|
| 976 |
}
|
997 |
}
|
| 977 |
|
998 |
|
| 978 |
|
999 |
|
| 979 |
@Override
|
1000 |
@Override
|
| 980 |
public Map<Integer, Float> getCatalogSchemeCashBack(int fofoId, List<Integer> catalogIds) throws ProfitMandiBusinessException {
|
1001 |
public Map<Integer, Float> getCatalogSchemeCashBack(int fofoId, List<Integer> catalogIds) throws
|
| - |
|
1002 |
ProfitMandiBusinessException {
|
| 981 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
|
1003 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
|
| 982 |
Map<CatalogSummaryModel, List<SchemeSummaryModel>> catalogModelMap = tagListingRepository.getModelSchemesByCatalogIdsAndType(fofoId, partnerType, catalogIds, LocalDate.now().atStartOfDay());
|
1004 |
Map<CatalogSummaryModel, List<SchemeSummaryModel>> catalogModelMap = tagListingRepository.getModelSchemesByCatalogIdsAndType(fofoId, partnerType, catalogIds, LocalDate.now().atStartOfDay());
|
| 983 |
|
1005 |
|
| 984 |
Map<Integer, Float> catalogCashbackMap = new HashMap<>();
|
1006 |
Map<Integer, Float> catalogCashbackMap = new HashMap<>();
|
| 985 |
for (Map.Entry<CatalogSummaryModel, List<SchemeSummaryModel>> catalogSummaryModelListEntry : catalogModelMap.entrySet()) {
|
1007 |
for (Map.Entry<CatalogSummaryModel, List<SchemeSummaryModel>> catalogSummaryModelListEntry : catalogModelMap.entrySet()) {
|