| Line 43... |
Line 43... |
| 43 |
@Override
|
43 |
@Override
|
| 44 |
public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|
44 |
public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|
| 45 |
String description, float amount) throws ProfitMandiBusinessException {
|
45 |
String description, float amount) throws ProfitMandiBusinessException {
|
| 46 |
if (amount == 0)
|
46 |
if (amount == 0)
|
| 47 |
return;
|
47 |
return;
|
| 48 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
48 |
UserWallet userWallet = userWalletRepository.selectById(retailerId);
|
| - |
|
49 |
//userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
|
| 49 |
userWallet.setAmount(userWallet.getAmount() + Math.round(amount));
|
50 |
userWallet.setAmount(userWallet.getAmount() + Math.round(amount));
|
| 50 |
userWalletRepository.persist(userWallet);
|
51 |
userWalletRepository.persist(userWallet);
|
| 51 |
this.createUserWalletHistory(Math.round(amount), userWallet.getId(), referenceId, referenceType, description);
|
52 |
this.createUserWalletHistory(Math.round(amount), userWallet.getId(), referenceId, referenceType, description);
|
| 52 |
}
|
53 |
}
|
| 53 |
|
54 |
|
| Line 58... |
Line 59... |
| 58 |
throw pbse;
|
59 |
throw pbse;
|
| 59 |
}
|
60 |
}
|
| 60 |
if (amount == 0)
|
61 |
if (amount == 0)
|
| 61 |
return;
|
62 |
return;
|
| 62 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
63 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
| - |
|
64 |
//userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
|
| 63 |
if (amount > userWallet.getAmount()) {
|
65 |
if (amount > userWallet.getAmount()) {
|
| 64 |
LOGGER.error("Wallet Balance is insufficient!");
|
66 |
LOGGER.error("Wallet Balance is insufficient!");
|
| 65 |
throw new ProfitMandiBusinessException("balance", userWallet.getAmount(), "WLT_1000");
|
67 |
throw new ProfitMandiBusinessException("balance", userWallet.getAmount(), "WLT_1000");
|
| 66 |
}
|
68 |
}
|
| 67 |
userWallet.setAmount(userWallet.getAmount() - Math.round(amount));
|
69 |
userWallet.setAmount(userWallet.getAmount() - Math.round(amount));
|
| Line 74... |
Line 76... |
| 74 |
WalletReferenceType walletReferenceType, String rollbackReason) {
|
76 |
WalletReferenceType walletReferenceType, String rollbackReason) {
|
| 75 |
|
77 |
|
| 76 |
if (amountToRollback == 0)
|
78 |
if (amountToRollback == 0)
|
| 77 |
return;
|
79 |
return;
|
| 78 |
UserWallet userWallet = userWalletRepository.selectById(retailerId);
|
80 |
UserWallet userWallet = userWalletRepository.selectById(retailerId);
|
| - |
|
81 |
//userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
|
| 79 |
userWallet.setAmount(userWallet.getAmount() - Math.round(amountToRollback));
|
82 |
userWallet.setAmount(userWallet.getAmount() - Math.round(amountToRollback));
|
| 80 |
userWalletRepository.persist(userWallet);
|
83 |
userWalletRepository.persist(userWallet);
|
| 81 |
this.createUserWalletHistory(-Math.round(amountToRollback), userWallet.getId(), rollbackReference,
|
84 |
this.createUserWalletHistory(-Math.round(amountToRollback), userWallet.getId(), rollbackReference,
|
| 82 |
walletReferenceType, rollbackReason);
|
85 |
walletReferenceType, rollbackReason);
|
| 83 |
|
86 |
|