| Line 921... |
Line 921... |
| 921 |
if (amountToCredit > 0) {
|
921 |
if (amountToCredit > 0) {
|
| 922 |
walletService.addAmountToWallet(fofoId, reversalReference, WalletReferenceType.PRICE_DROP, reversalReason,
|
922 |
walletService.addAmountToWallet(fofoId, reversalReference, WalletReferenceType.PRICE_DROP, reversalReason,
|
| 923 |
amountToCredit);
|
923 |
amountToCredit);
|
| 924 |
}
|
924 |
}
|
| 925 |
}
|
925 |
}
|
| - |
|
926 |
@Override
|
| - |
|
927 |
public void reverseSchemes(List<InventoryItem> inventoryItems, int reversalReference, String reversalReason, SchemeType schemeType) throws ProfitMandiBusinessException{
|
| - |
|
928 |
Map<Integer, InventoryItem> inventoryItemsMap = inventoryItems.stream()
|
| - |
|
929 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| - |
|
930 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectByInventoryItemIds(inventoryItemsMap.keySet());
|
| - |
|
931 |
List<Integer> schemeIds = schemeInOuts.stream().map(x -> x.getSchemeId()).collect(Collectors.toList());
|
| - |
|
932 |
float amount = 0;
|
| - |
|
933 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIds, 0, schemeIds.size()).stream()
|
| - |
|
934 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| - |
|
935 |
for (SchemeInOut schemeInOut : schemeInOuts) {
|
| - |
|
936 |
Scheme scheme = schemesMap.get(schemeInOut.getSchemeId());
|
| - |
|
937 |
if(scheme.getType().equals(schemeType)) {
|
| - |
|
938 |
if(schemeInOut.getRolledBackTimestamp() == null) {
|
| - |
|
939 |
schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
|
| - |
|
940 |
schemeInOutRepository.persist(schemeInOut);
|
| - |
|
941 |
amount += schemeInOut.getAmount();
|
| - |
|
942 |
}
|
| - |
|
943 |
}
|
| - |
|
944 |
}
|
| - |
|
945 |
int fofoId = inventoryItems.get(0).getFofoId();
|
| - |
|
946 |
WalletReferenceType walletReferenceType = schemeType.equals(SchemeType.OUT)?WalletReferenceType.SCHEME_OUT:WalletReferenceType.SCHEME_IN;
|
| - |
|
947 |
walletService.rollbackAmountFromWallet(fofoId, amount, reversalReference, walletReferenceType, reversalReason);
|
| - |
|
948 |
}
|
| 926 |
|
949 |
|
| 927 |
}
|
950 |
}
|