| Line 15... |
Line 15... |
| 15 |
import com.spice.profitmandi.dao.entity.catalog.SchemeRegion;
|
15 |
import com.spice.profitmandi.dao.entity.catalog.SchemeRegion;
|
| 16 |
import com.spice.profitmandi.dao.entity.catalog.SchemesImeisModel;
|
16 |
import com.spice.profitmandi.dao.entity.catalog.SchemesImeisModel;
|
| 17 |
import com.spice.profitmandi.dao.entity.fofo.*;
|
17 |
import com.spice.profitmandi.dao.entity.fofo.*;
|
| 18 |
import com.spice.profitmandi.dao.entity.inventory.PartnerAgeingModel;
|
18 |
import com.spice.profitmandi.dao.entity.inventory.PartnerAgeingModel;
|
| 19 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
19 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| - |
|
20 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
| 20 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
21 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
| 21 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
22 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
| 22 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
23 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 23 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
24 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 24 |
import com.spice.profitmandi.dao.enumuration.transaction.SchemePayoutStatus;
|
25 |
import com.spice.profitmandi.dao.enumuration.transaction.SchemePayoutStatus;
|
| Line 27... |
Line 28... |
| 27 |
import com.spice.profitmandi.dao.repository.catalog.*;
|
28 |
import com.spice.profitmandi.dao.repository.catalog.*;
|
| 28 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
29 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 29 |
import com.spice.profitmandi.dao.repository.fofo.*;
|
30 |
import com.spice.profitmandi.dao.repository.fofo.*;
|
| 30 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
31 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 31 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
32 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
| - |
|
33 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 32 |
import com.spice.profitmandi.service.NotificationService;
|
34 |
import com.spice.profitmandi.service.NotificationService;
|
| 33 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
35 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 34 |
import com.spice.profitmandi.service.inventory.AgeingService;
|
36 |
import com.spice.profitmandi.service.inventory.AgeingService;
|
| 35 |
import com.spice.profitmandi.service.inventory.PurchaseService;
|
37 |
import com.spice.profitmandi.service.inventory.PurchaseService;
|
| 36 |
import com.spice.profitmandi.service.pricecircular.CatalogSummaryModel;
|
38 |
import com.spice.profitmandi.service.pricecircular.CatalogSummaryModel;
|
| Line 991... |
Line 993... |
| 991 |
}
|
993 |
}
|
| 992 |
}
|
994 |
}
|
| 993 |
}
|
995 |
}
|
| 994 |
|
996 |
|
| 995 |
@Autowired
|
997 |
@Autowired
|
| - |
|
998 |
UserWalletRepository userWalletRepository;
|
| - |
|
999 |
@Autowired
|
| 996 |
UserWalletHistoryRepository userWalletHistoryRepository;
|
1000 |
UserWalletHistoryRepository userWalletHistoryRepository;
|
| 997 |
|
1001 |
|
| 998 |
@Override
|
1002 |
@Override
|
| 999 |
// Always being called from cancel order/bad return means no SCHEME IN is considered
|
1003 |
// Always being called from cancel order/bad return means no SCHEME IN is considered
|
| 1000 |
public void reverseSchemes(List<InventoryItem> inventoryItems, int reversalReference, String reversalReason,
|
1004 |
public void reverseSchemes(List<InventoryItem> inventoryItems, int reversalReference, String reversalReason,
|
| Line 1004... |
Line 1008... |
| 1004 |
LOGGER.info("inventoryItems" + inventoryItems);
|
1008 |
LOGGER.info("inventoryItems" + inventoryItems);
|
| 1005 |
|
1009 |
|
| 1006 |
Map<SchemeType, SchemeInOut> schemeTypeMap = new HashMap<>();
|
1010 |
Map<SchemeType, SchemeInOut> schemeTypeMap = new HashMap<>();
|
| 1007 |
|
1011 |
|
| 1008 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectByInventoryItemIds(inventoryItemsMap.keySet());
|
1012 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectByInventoryItemIds(inventoryItemsMap.keySet());
|
| 1009 |
LOGGER.info("schemeInOuts" + schemeInOuts);
|
1013 |
List<SchemeInOut> rolledBacks = schemeInOuts.stream().filter(x -> x.getStatusDescription().equals(reversalReason)).collect(Collectors.toList());
|
| 1010 |
float amountToRollback = 0;
|
1014 |
float amountToRollback = 0;
|
| 1011 |
|
1015 |
|
| 1012 |
if (!schemeInOuts.isEmpty()) {
|
1016 |
if (!schemeInOuts.isEmpty()) {
|
| 1013 |
List<Integer> schemeIds = schemeInOuts.stream().map(x -> x.getSchemeId()).collect(Collectors.toList());
|
1017 |
List<Integer> schemeIds = schemeInOuts.stream().map(x -> x.getSchemeId()).collect(Collectors.toList());
|
| 1014 |
LOGGER.info("schemeIds" + schemeIds);
|
1018 |
LOGGER.info("schemeIds" + schemeIds);
|
| 1015 |
|
1019 |
|
| 1016 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIds, 0, schemeIds.size())
|
1020 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIds, 0, schemeIds.size())
|
| 1017 |
.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
1021 |
.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| - |
|
1022 |
if (rolledBacks.size() > 0) {
|
| 1018 |
for (SchemeInOut schemeInOut : schemeInOuts) {
|
1023 |
for (SchemeInOut schemeInOut : rolledBacks) {
|
| 1019 |
Scheme scheme = schemesMap.get(schemeInOut.getSchemeId());
|
1024 |
Scheme scheme = schemesMap.get(schemeInOut.getSchemeId());
|
| 1020 |
if (schemeTypes.contains(scheme.getType())) {
|
1025 |
if (schemeTypes.contains(scheme.getType())) {
|
| 1021 |
schemeTypeMap.put(scheme.getType(), schemeInOut);
|
1026 |
schemeTypeMap.put(scheme.getType(), schemeInOut);
|
| 1022 |
if (schemeInOut.getRolledBackTimestamp() == null) {
|
1027 |
if (schemeInOut.getCreditTimestamp() != null) {
|
| 1023 |
schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
|
- |
|
| 1024 |
if (schemeInOut.getCreditTimestamp() != null || schemeInOut.getStatus().equals(SchemePayoutStatus.CREDITED)) {
|
- |
|
| 1025 |
amountToRollback += schemeInOut.getAmount();
|
1028 |
amountToRollback += schemeInOut.getAmount();
|
| 1026 |
}
|
1029 |
}
|
| - |
|
1030 |
}
|
| - |
|
1031 |
}
|
| - |
|
1032 |
} else {
|
| - |
|
1033 |
for (SchemeInOut schemeInOut : schemeInOuts) {
|
| - |
|
1034 |
Scheme scheme = schemesMap.get(schemeInOut.getSchemeId());
|
| - |
|
1035 |
if (schemeTypes.contains(scheme.getType())) {
|
| - |
|
1036 |
if (schemeInOut.getRolledBackTimestamp() == null) {
|
| - |
|
1037 |
schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
|
| - |
|
1038 |
if (schemeInOut.getStatus().equals(SchemePayoutStatus.CREDITED)) {
|
| - |
|
1039 |
amountToRollback += schemeInOut.getAmount();
|
| - |
|
1040 |
}
|
| 1027 |
schemeInOut.setStatus(SchemePayoutStatus.REJECTED);
|
1041 |
schemeInOut.setStatus(SchemePayoutStatus.REJECTED);
|
| 1028 |
schemeInOut.setStatusDescription(reversalReason);
|
1042 |
schemeInOut.setStatusDescription(reversalReason);
|
| - |
|
1043 |
}
|
| 1029 |
}
|
1044 |
}
|
| 1030 |
}
|
1045 |
}
|
| 1031 |
}
|
1046 |
}
|
| 1032 |
}
|
1047 |
}
|
| - |
|
1048 |
|
| 1033 |
int fofoId = inventoryItems.get(0).getFofoId();
|
1049 |
int fofoId = inventoryItems.get(0).getFofoId();
|
| 1034 |
WalletReferenceType walletReferenceType = schemeTypes.containsAll(SchemeService.OUT_SCHEME_TYPES) ? WalletReferenceType.SCHEME_OUT
|
1050 |
WalletReferenceType walletReferenceType = schemeTypes.containsAll(SchemeService.OUT_SCHEME_TYPES) ? WalletReferenceType.SCHEME_OUT
|
| 1035 |
: schemeTypes.contains(SchemeType.ACTIVATION) ? WalletReferenceType.ACTIVATION_SCHEME
|
1051 |
: schemeTypes.contains(SchemeType.ACTIVATION) ? WalletReferenceType.ACTIVATION_SCHEME
|
| 1036 |
: schemeTypes.contains(SchemeType.SPECIAL_SUPPORT) ? WalletReferenceType.SPECIAL_SUPPORT
|
1052 |
: schemeTypes.contains(SchemeType.SPECIAL_SUPPORT) ? WalletReferenceType.SPECIAL_SUPPORT
|
| 1037 |
: schemeTypes.contains(SchemeType.INVESTMENT) ? WalletReferenceType.INVESTMENT_PAYOUT : null;
|
1053 |
: schemeTypes.contains(SchemeType.INVESTMENT) ? WalletReferenceType.SCHEME_OUT : null;
|
| 1038 |
|
- |
|
| - |
|
1054 |
List<UserWalletHistory> userWalletHistoryList = null;
|
| 1039 |
if (amountToRollback > 0 && walletReferenceType != null) {
|
1055 |
if (amountToRollback > 0 && walletReferenceType != null) {
|
| 1040 |
// Mark appropriate reference of rollback investment margin
|
1056 |
// Mark appropriate reference of rollback investment margin
|
| 1041 |
if (schemeTypes.contains(SchemeType.INVESTMENT)) {
|
1057 |
if (schemeTypes.contains(SchemeType.INVESTMENT) && schemeTypeMap.containsKey(SchemeType.INVESTMENT)) {
|
| - |
|
1058 |
LocalDateTime creditTime = schemeTypeMap.get(SchemeType.INVESTMENT).getCreditTimestamp();
|
| - |
|
1059 |
if (creditTime == null) return;
|
| - |
|
1060 |
int investmentReversalReference = Integer.parseInt(FormattingUtils.getYearMonth(creditTime.minusMonths(1)));
|
| - |
|
1061 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(fofoId);
|
| - |
|
1062 |
userWalletHistoryList = userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(userWallet.getUserId(), investmentReversalReference, WalletReferenceType.INVESTMENT_PAYOUT);
|
| - |
|
1063 |
if (userWalletHistoryList.size() > 0) {
|
| - |
|
1064 |
walletReferenceType = WalletReferenceType.INVESTMENT_PAYOUT;
|
| - |
|
1065 |
} else {
|
| - |
|
1066 |
userWalletHistoryList = null;
|
| - |
|
1067 |
}
|
| - |
|
1068 |
}
|
| - |
|
1069 |
if (userWalletHistoryList == null) {
|
| 1042 |
List<UserWalletHistory> userWalletHistoryList = userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(reversalReference, walletReferenceType);
|
1070 |
userWalletHistoryList = userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(reversalReference, walletReferenceType);
|
| - |
|
1071 |
}
|
| 1043 |
if (userWalletHistoryList.size() == 0) {
|
1072 |
if (userWalletHistoryList.size() > 0) {
|
| - |
|
1073 |
int maxDeductible = userWalletHistoryList.stream().collect(Collectors.summingInt(x -> x.getAmount()));
|
| 1044 |
reversalReference = Integer
|
1074 |
if (maxDeductible > 0) {
|
| - |
|
1075 |
LOGGER.info("----------> maxDeductible {}, amountToRollback {}, reversalReference {}, walletReferenceType {} ",maxDeductible, amountToRollback, reversalReference, walletReferenceType);
|
| 1045 |
.parseInt(FormattingUtils.getYearMonth(schemeTypeMap.get(SchemeType.INVESTMENT).getCreditTimestamp().minusMonths(1)));
|
1076 |
walletService.rollbackAmountFromWallet(fofoId, Math.min(maxDeductible, amountToRollback), reversalReference, walletReferenceType,
|
| - |
|
1077 |
reversalReason, LocalDateTime.now());
|
| 1046 |
}
|
1078 |
}
|
| 1047 |
|
1079 |
|
| 1048 |
}
|
1080 |
}
|
| 1049 |
walletService.rollbackAmountFromWallet(fofoId, amountToRollback, reversalReference, walletReferenceType,
|
- |
|
| 1050 |
reversalReason, LocalDateTime.now());
|
- |
|
| 1051 |
}
|
1081 |
}
|
| 1052 |
}
|
1082 |
}
|
| 1053 |
|
1083 |
|
| - |
|
1084 |
|
| 1054 |
@Override
|
1085 |
@Override
|
| 1055 |
public double getTotalMargin(int itemId, PartnerType partnerType, LocalDateTime dateTime) {
|
1086 |
public double getTotalMargin(int itemId, PartnerType partnerType, LocalDateTime dateTime) {
|
| 1056 |
Session session = sessionFactory.getCurrentSession();
|
1087 |
Session session = sessionFactory.getCurrentSession();
|
| 1057 |
CriteriaBuilder cb = session.getCriteriaBuilder();
|
1088 |
CriteriaBuilder cb = session.getCriteriaBuilder();
|
| 1058 |
CriteriaQuery<Double> criteriaQuery = cb.createQuery(Double.class);
|
1089 |
CriteriaQuery<Double> criteriaQuery = cb.createQuery(Double.class);
|