| Line 86... |
Line 86... |
| 86 |
public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|
86 |
public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|
| 87 |
String description, float amount, LocalDateTime businessTime) throws ProfitMandiBusinessException {
|
87 |
String description, float amount, LocalDateTime businessTime) throws ProfitMandiBusinessException {
|
| 88 |
if (Math.round(amount) == 0)
|
88 |
if (Math.round(amount) == 0)
|
| 89 |
return;
|
89 |
return;
|
| 90 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
90 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
| 91 |
int walletAmount = this.getWalletAmount(retailerId);
|
- |
|
| 92 |
userWallet.setAmount(walletAmount + Math.round(amount));
|
91 |
userWallet.setAmount(userWallet.getAmount() + Math.round(amount));
|
| 93 |
this.createUserWalletHistory(Math.round(amount), userWallet.getId(), referenceId, referenceType, description, businessTime);
|
92 |
this.createUserWalletHistory(Math.round(amount), userWallet.getId(), referenceId, referenceType, description, businessTime);
|
| 94 |
}
|
93 |
}
|
| 95 |
|
94 |
|
| 96 |
@Override
|
95 |
@Override
|
| 97 |
public void consumeAmountFromWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|
96 |
public void consumeAmountFromWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|
| Line 102... |
Line 101... |
| 102 |
throw inactivepbse;
|
101 |
throw inactivepbse;
|
| 103 |
}
|
102 |
}
|
| 104 |
if (amount == 0)
|
103 |
if (amount == 0)
|
| 105 |
return;
|
104 |
return;
|
| 106 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
105 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
| 107 |
int walletAmount = this.getWalletAmount(retailerId);
|
106 |
int walletAmount = userWallet.getAmount();
|
| 108 |
// userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
|
- |
|
| 109 |
if (!WalletReferenceType.DAMAGE_PROTECTION.equals(referenceType) && amount > ProfitMandiConstants.MAX_NEGATIVE_WALLET_VALUE && Math.floor(amount) > walletAmount) {
|
107 |
if (!WalletReferenceType.DAMAGE_PROTECTION.equals(referenceType) && amount > ProfitMandiConstants.MAX_NEGATIVE_WALLET_VALUE && Math.floor(amount) > walletAmount) {
|
| 110 |
LOGGER.error("Wallet Balance is insufficient!, needed - {}, wallet has - {}, for retailer - {}", Math.floor(amount), walletAmount, retailerId);
|
108 |
LOGGER.error("Wallet Balance is insufficient!, needed - {}, wallet has - {}, for retailer - {}", Math.floor(amount), walletAmount, retailerId);
|
| 111 |
User user = userRepository.selectById(retailerId);
|
109 |
User user = userRepository.selectById(retailerId);
|
| 112 |
throw new ProfitMandiBusinessException(user.getName(), walletAmount, "WLT_1000");
|
110 |
throw new ProfitMandiBusinessException(user.getName(), walletAmount, "WLT_1000");
|
| 113 |
}
|
111 |
}
|
| Line 124... |
Line 122... |
| 124 |
throw inactivepbse;
|
122 |
throw inactivepbse;
|
| 125 |
}
|
123 |
}
|
| 126 |
if (amount == 0)
|
124 |
if (amount == 0)
|
| 127 |
return;
|
125 |
return;
|
| 128 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
126 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
| 129 |
int walletAmount = this.getWalletAmount(retailerId);
|
127 |
int walletAmount = userWallet.getAmount();
|
| 130 |
// userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
|
- |
|
| 131 |
if (!forced && amount > 2 && amount > walletAmount) {
|
128 |
if (!forced && amount > 2 && amount > walletAmount) {
|
| 132 |
LOGGER.error("Wallet Balance is insufficient!");
|
129 |
LOGGER.error("Wallet Balance is insufficient!");
|
| 133 |
throw new ProfitMandiBusinessException("balance", walletAmount, "WLT_1000");
|
130 |
throw new ProfitMandiBusinessException("balance", walletAmount, "WLT_1000");
|
| 134 |
}
|
131 |
}
|
| 135 |
userWallet.setAmount(walletAmount - Math.round(amount));
|
132 |
userWallet.setAmount(walletAmount - Math.round(amount));
|
| Line 140... |
Line 137... |
| 140 |
public void rollbackAmountFromWallet(int retailerId, float amountToRollback, int rollbackReference,
|
137 |
public void rollbackAmountFromWallet(int retailerId, float amountToRollback, int rollbackReference,
|
| 141 |
WalletReferenceType walletReferenceType, String rollbackReason, LocalDateTime businessTime) throws ProfitMandiBusinessException {
|
138 |
WalletReferenceType walletReferenceType, String rollbackReason, LocalDateTime businessTime) throws ProfitMandiBusinessException {
|
| 142 |
|
139 |
|
| 143 |
if (amountToRollback == 0)
|
140 |
if (amountToRollback == 0)
|
| 144 |
return;
|
141 |
return;
|
| 145 |
int walletAmount = this.getWalletAmount(retailerId);
|
- |
|
| 146 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
142 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
| - |
|
143 |
int walletAmount = userWallet.getAmount();
|
| 147 |
List<UserWalletHistory> uwh = userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(rollbackReference, walletReferenceType)
|
144 |
List<UserWalletHistory> uwh = userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(rollbackReference, walletReferenceType)
|
| 148 |
.stream().filter(x -> x.getWalletId() == userWallet.getId()).collect(Collectors.toList());
|
145 |
.stream().filter(x -> x.getWalletId() == userWallet.getId()).collect(Collectors.toList());
|
| 149 |
if (uwh.size() == 0) {
|
146 |
if (uwh.size() == 0) {
|
| 150 |
LOGGER.info("Retailer with id {} dont have valid reference {} and reference type {}",
|
147 |
LOGGER.info("Retailer with id {} dont have valid reference {} and reference type {}",
|
| 151 |
retailerId, rollbackReference, walletReferenceType);
|
148 |
retailerId, rollbackReference, walletReferenceType);
|
| Line 303... |
Line 300... |
| 303 |
|
300 |
|
| 304 |
List<UserWalletHistory> all_entries = userWalletHistoryRepository
|
301 |
List<UserWalletHistory> all_entries = userWalletHistoryRepository
|
| 305 |
.selectAllByreferenceIdandreferenceType(transactionId, walletReferenceType);
|
302 |
.selectAllByreferenceIdandreferenceType(transactionId, walletReferenceType);
|
| 306 |
|
303 |
|
| 307 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
304 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
| 308 |
int walletAmount = this.getWalletAmount(retailerId);
|
305 |
int walletAmount = userWallet.getAmount();
|
| 309 |
LOGGER.info("userWallet" + userWallet);
|
306 |
LOGGER.info("userWallet" + userWallet);
|
| 310 |
int max_eligible_credit_amount = 0;
|
307 |
int max_eligible_credit_amount = 0;
|
| 311 |
|
308 |
|
| 312 |
LOGGER.info("all_entries {}", all_entries);
|
309 |
LOGGER.info("all_entries {}", all_entries);
|
| 313 |
for (UserWalletHistory history : all_entries) {
|
310 |
for (UserWalletHistory history : all_entries) {
|
| Line 342... |
Line 339... |
| 342 |
if (userWallet == null) {
|
339 |
if (userWallet == null) {
|
| 343 |
userWallet = new UserWallet();
|
340 |
userWallet = new UserWallet();
|
| 344 |
userWallet.setUserId(retailerId);
|
341 |
userWallet.setUserId(retailerId);
|
| 345 |
userWalletRepository.persist(userWallet);
|
342 |
userWalletRepository.persist(userWallet);
|
| 346 |
}
|
343 |
}
|
| 347 |
return (int) userWalletHistoryRepository.selectSumByWallet(userWallet.getId());
|
344 |
int sum = (int) userWalletHistoryRepository.selectSumByWallet(userWallet.getId());
|
| - |
|
345 |
userWallet.setAmount(sum);
|
| - |
|
346 |
return sum;
|
| 348 |
}
|
347 |
}
|
| 349 |
|
348 |
|
| 350 |
@Override
|
349 |
@Override
|
| 351 |
public List<UserWalletHistory> getAllByReference(int fofoId, int reference, WalletReferenceType walletReferenceType)
|
350 |
public List<UserWalletHistory> getAllByReference(int fofoId, int reference, WalletReferenceType walletReferenceType)
|
| 352 |
throws ProfitMandiBusinessException {
|
351 |
throws ProfitMandiBusinessException {
|