| 22550 |
ashik.ali |
1 |
package com.spice.profitmandi.service.wallet;
|
|
|
2 |
|
| 30066 |
amit.gupta |
3 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 22550 |
ashik.ali |
4 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 34261 |
tejus.loha |
5 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 30740 |
amit.gupta |
6 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 34261 |
tejus.loha |
7 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 30025 |
amit.gupta |
8 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 23269 |
ashik.ali |
9 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| 25542 |
amit.gupta |
10 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 34261 |
tejus.loha |
11 |
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
|
| 32494 |
amit.gupta |
12 |
import com.spice.profitmandi.dao.entity.transaction.ManualPaymentType;
|
| 22550 |
ashik.ali |
13 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
|
|
14 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
|
|
15 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
| 34261 |
tejus.loha |
16 |
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
|
|
|
17 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
| 32494 |
amit.gupta |
18 |
import com.spice.profitmandi.dao.repository.catalog.ManualPaymentRequestRepository;
|
| 25542 |
amit.gupta |
19 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 33845 |
tejus.loha |
20 |
import com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository;
|
| 33172 |
tejus.loha |
21 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 22550 |
ashik.ali |
22 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
23 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
|
|
24 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 33845 |
tejus.loha |
25 |
import com.spice.profitmandi.dao.repository.user.StoreTimelinetbRepository;
|
| 30025 |
amit.gupta |
26 |
import com.spice.profitmandi.service.NotificationService;
|
| 30740 |
amit.gupta |
27 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
| 34261 |
tejus.loha |
28 |
import com.spice.profitmandi.service.order.OrderService;
|
|
|
29 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 33845 |
tejus.loha |
30 |
import com.spice.profitmandi.service.user.StoreTimelineTatService;
|
| 22857 |
ashik.ali |
31 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| 30025 |
amit.gupta |
32 |
import org.apache.logging.log4j.LogManager;
|
|
|
33 |
import org.apache.logging.log4j.Logger;
|
|
|
34 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 34261 |
tejus.loha |
35 |
import org.springframework.http.ResponseEntity;
|
| 30025 |
amit.gupta |
36 |
import org.springframework.stereotype.Component;
|
| 22857 |
ashik.ali |
37 |
|
| 30025 |
amit.gupta |
38 |
import java.time.LocalDateTime;
|
|
|
39 |
import java.util.*;
|
|
|
40 |
import java.util.stream.Collectors;
|
|
|
41 |
|
| 22550 |
ashik.ali |
42 |
@Component
|
|
|
43 |
public class WalletServiceImpl implements WalletService {
|
|
|
44 |
|
| 32494 |
amit.gupta |
45 |
private static final Logger LOGGER = LogManager.getLogger(WalletServiceImpl.class);
|
| 25395 |
tejbeer |
46 |
|
| 32494 |
amit.gupta |
47 |
@Autowired
|
|
|
48 |
ManualPaymentRequestRepository manualPaymentRequestRepository;
|
| 34261 |
tejus.loha |
49 |
@Autowired
|
|
|
50 |
AddWalletRequestRepository addWalletRequestRepository;
|
|
|
51 |
@Autowired
|
|
|
52 |
OrderService orderService;
|
|
|
53 |
@Autowired
|
|
|
54 |
RetailerService retailerService;
|
| 33194 |
amit.gupta |
55 |
ProfitMandiBusinessException pbse = new ProfitMandiBusinessException("Wallet", "Wallet", "Wallet is under maintainance, please try after some time");
|
|
|
56 |
ProfitMandiBusinessException inactivepbse = new ProfitMandiBusinessException("Wallet", "Wallet", "Investment is incomplete, please add amount to wallet to complete the investment");
|
|
|
57 |
|
| 32494 |
amit.gupta |
58 |
@Autowired
|
|
|
59 |
PartnerInvestmentService partnerInvestmentService;
|
|
|
60 |
private boolean underMaintainance = false;
|
|
|
61 |
@Autowired
|
|
|
62 |
private UserAccountRepository userAccountRepository;
|
| 33172 |
tejus.loha |
63 |
|
| 32494 |
amit.gupta |
64 |
@Autowired
|
|
|
65 |
private UserWalletRepository userWalletRepository;
|
|
|
66 |
@Autowired
|
|
|
67 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
68 |
@Autowired
|
|
|
69 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
|
|
70 |
@Autowired
|
|
|
71 |
private NotificationService notificationService;
|
| 24739 |
tejbeer |
72 |
|
| 33172 |
tejus.loha |
73 |
@Autowired
|
|
|
74 |
RetailerRepository retailerRepository;
|
| 33845 |
tejus.loha |
75 |
@Autowired
|
|
|
76 |
PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
|
|
|
77 |
@Autowired
|
|
|
78 |
StoreTimelineTatService storeTimelineTatService;
|
|
|
79 |
@Autowired
|
|
|
80 |
StoreTimelinetbRepository storeTimelinetbRepository;
|
| 33172 |
tejus.loha |
81 |
|
| 32494 |
amit.gupta |
82 |
@Override
|
|
|
83 |
public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|
|
|
84 |
String description, float amount, LocalDateTime businessTime) throws ProfitMandiBusinessException {
|
|
|
85 |
if (Math.round(amount) == 0)
|
|
|
86 |
return;
|
|
|
87 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
| 33172 |
tejus.loha |
88 |
int walletAmount = this.getWalletAmount(retailerId);
|
| 32494 |
amit.gupta |
89 |
userWallet.setAmount(walletAmount + Math.round(amount));
|
|
|
90 |
if (amount > 0) {
|
|
|
91 |
notificationService.sendNotification(retailerId, "walletcredit", MessageType.wallet, "Rs." + FormattingUtils.formatDecimal(amount) + " credited in SD Wallet", description);
|
|
|
92 |
}
|
|
|
93 |
this.createUserWalletHistory(Math.round(amount), userWallet.getId(), referenceId, referenceType, description, businessTime);
|
|
|
94 |
}
|
| 25609 |
amit.gupta |
95 |
|
| 32494 |
amit.gupta |
96 |
@Override
|
|
|
97 |
public void consumeAmountFromWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|
|
|
98 |
String description, float amount, LocalDateTime businessTime) throws ProfitMandiBusinessException {
|
|
|
99 |
if (underMaintainance) {
|
|
|
100 |
throw pbse;
|
|
|
101 |
} else if (WalletReferenceType.RECHARGE.equals(referenceType) && !isActive(retailerId)) {
|
|
|
102 |
throw inactivepbse;
|
|
|
103 |
}
|
|
|
104 |
if (amount == 0)
|
|
|
105 |
return;
|
|
|
106 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
| 33172 |
tejus.loha |
107 |
int walletAmount = this.getWalletAmount(retailerId);
|
| 32494 |
amit.gupta |
108 |
// userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
|
| 33547 |
tejus.loha |
109 |
if (!WalletReferenceType.DAMAGE_PROTECTION.equals(referenceType) && amount > ProfitMandiConstants.MAX_NEGATIVE_WALLET_VALUE && Math.floor(amount) > walletAmount) {
|
| 34575 |
vikas.jang |
110 |
LOGGER.error("Wallet Balance is insufficient!, needed - {}, wallet has - {}, for retailer - {}", Math.floor(amount), walletAmount, retailerId);
|
| 32494 |
amit.gupta |
111 |
throw new ProfitMandiBusinessException("balance", walletAmount, "WLT_1000");
|
|
|
112 |
}
|
|
|
113 |
userWallet.setAmount(walletAmount - Math.round(amount));
|
|
|
114 |
userWalletRepository.persist(userWallet);
|
|
|
115 |
this.createUserWalletHistory(-Math.round(amount), userWallet.getId(), referenceId, referenceType, description, businessTime);
|
|
|
116 |
}
|
| 24739 |
tejbeer |
117 |
|
| 32494 |
amit.gupta |
118 |
@Override
|
|
|
119 |
public void consumeAmountFromWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|
|
|
120 |
String description, float amount, LocalDateTime businessTime, boolean forced) throws ProfitMandiBusinessException {
|
|
|
121 |
if (underMaintainance) {
|
|
|
122 |
throw pbse;
|
|
|
123 |
} else if (WalletReferenceType.RECHARGE.equals(referenceType) && !isActive(retailerId)) {
|
|
|
124 |
throw inactivepbse;
|
|
|
125 |
}
|
|
|
126 |
if (amount == 0)
|
|
|
127 |
return;
|
|
|
128 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
| 33172 |
tejus.loha |
129 |
int walletAmount = this.getWalletAmount(retailerId);
|
| 32494 |
amit.gupta |
130 |
// userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
|
|
|
131 |
if (!forced && amount > 2 && amount > walletAmount) {
|
|
|
132 |
LOGGER.error("Wallet Balance is insufficient!");
|
|
|
133 |
throw new ProfitMandiBusinessException("balance", walletAmount, "WLT_1000");
|
|
|
134 |
}
|
|
|
135 |
userWallet.setAmount(walletAmount - Math.round(amount));
|
|
|
136 |
this.createUserWalletHistory(-Math.round(amount), userWallet.getId(), referenceId, referenceType, description, businessTime);
|
|
|
137 |
}
|
| 24739 |
tejbeer |
138 |
|
| 32494 |
amit.gupta |
139 |
@Override
|
|
|
140 |
public void rollbackAmountFromWallet(int retailerId, float amountToRollback, int rollbackReference,
|
|
|
141 |
WalletReferenceType walletReferenceType, String rollbackReason, LocalDateTime businessTime) throws ProfitMandiBusinessException {
|
| 25542 |
amit.gupta |
142 |
|
| 32494 |
amit.gupta |
143 |
if (amountToRollback == 0)
|
|
|
144 |
return;
|
| 33172 |
tejus.loha |
145 |
int walletAmount = this.getWalletAmount(retailerId);
|
| 32494 |
amit.gupta |
146 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
|
|
147 |
List<UserWalletHistory> uwh = userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(rollbackReference, walletReferenceType)
|
|
|
148 |
.stream().filter(x -> x.getWalletId() == userWallet.getId()).collect(Collectors.toList());
|
|
|
149 |
if (uwh.size() == 0) {
|
|
|
150 |
LOGGER.info("Retailer with id {} dont have valid reference {} and reference type {}",
|
|
|
151 |
retailerId, rollbackReference, walletReferenceType);
|
|
|
152 |
throw new ProfitMandiBusinessException("Retailer specific wallet entries doesn't exist", retailerId, "Nothing to rollback");
|
|
|
153 |
}
|
|
|
154 |
// userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
|
|
|
155 |
userWallet.setAmount(walletAmount - Math.round(amountToRollback));
|
|
|
156 |
this.createUserWalletHistory(-Math.round(amountToRollback), userWallet.getId(), rollbackReference,
|
|
|
157 |
walletReferenceType, rollbackReason, businessTime);
|
|
|
158 |
userWalletRepository.persist(userWallet);
|
| 24739 |
tejbeer |
159 |
|
| 32494 |
amit.gupta |
160 |
}
|
| 30025 |
amit.gupta |
161 |
|
| 32494 |
amit.gupta |
162 |
private void createUserWalletHistory(float amount, int walletId, int referenceId, WalletReferenceType referenceType,
|
|
|
163 |
String description, LocalDateTime businessTimestamp) {
|
|
|
164 |
if (amount == 0)
|
|
|
165 |
return;
|
|
|
166 |
UserWalletHistory userWalletHistory = new UserWalletHistory();
|
|
|
167 |
userWalletHistory.setWalletId(walletId);
|
|
|
168 |
userWalletHistory.setAmount(Math.round(amount));
|
|
|
169 |
userWalletHistory.setReference(referenceId);
|
|
|
170 |
userWalletHistory.setReferenceType(referenceType);
|
|
|
171 |
userWalletHistory.setTimestamp(LocalDateTime.now());
|
|
|
172 |
userWalletHistory.setDescription(description);
|
|
|
173 |
userWalletHistory.setBusinessTimestamp(businessTimestamp);
|
|
|
174 |
userWalletHistoryRepository.persist(userWalletHistory);
|
|
|
175 |
}
|
| 24739 |
tejbeer |
176 |
|
| 32494 |
amit.gupta |
177 |
@Override
|
|
|
178 |
public UserWallet getUserWalletByUserId(int userId) throws ProfitMandiBusinessException {
|
|
|
179 |
UserAccount userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);
|
| 23509 |
amit.gupta |
180 |
|
| 32494 |
amit.gupta |
181 |
if (underMaintainance) {
|
|
|
182 |
throw pbse;
|
|
|
183 |
}
|
|
|
184 |
return userWalletRepository.selectByRetailerId(Integer.valueOf(userAccount.getAccountKey()));
|
|
|
185 |
}
|
| 30889 |
amit.gupta |
186 |
|
| 32494 |
amit.gupta |
187 |
@Override
|
|
|
188 |
public List<UserWalletHistory> getUserWalletHistoryByUserId(int userId) throws ProfitMandiBusinessException {
|
|
|
189 |
if (underMaintainance || !isActive(userId)) {
|
|
|
190 |
throw pbse;
|
|
|
191 |
}
|
|
|
192 |
UserWallet userWallet = this.getUserWalletByUserId(userId);
|
|
|
193 |
List<UserWalletHistory> userWalletHistories = userWalletHistoryRepository.selectByWalletId(userWallet.getId());
|
|
|
194 |
return userWalletHistories;
|
|
|
195 |
}
|
| 25395 |
tejbeer |
196 |
|
| 32494 |
amit.gupta |
197 |
//Definition is now changed, active also means valid investment should be ok
|
|
|
198 |
private boolean isActive(int userId) {
|
|
|
199 |
boolean active = true;
|
|
|
200 |
try {
|
|
|
201 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(userId);
|
|
|
202 |
active = fs.isActive() && partnerInvestmentService.isInvestmentOk(userId, ProfitMandiConstants.MIN_INVESTMENT_PERCENTAGE, ProfitMandiConstants.CUTOFF_INVESTMENT);
|
|
|
203 |
} catch (Exception e) {
|
| 24739 |
tejbeer |
204 |
|
| 32494 |
amit.gupta |
205 |
}
|
|
|
206 |
return active;
|
|
|
207 |
}
|
| 24739 |
tejbeer |
208 |
|
| 32494 |
amit.gupta |
209 |
@Override
|
|
|
210 |
public List<UserWalletHistory> getUserWalletHistoryByRetailerId(int retailerId)
|
|
|
211 |
throws ProfitMandiBusinessException {
|
|
|
212 |
if (underMaintainance) {
|
|
|
213 |
throw pbse;
|
|
|
214 |
}
|
|
|
215 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
|
|
216 |
return userWalletHistoryRepository.selectByWalletId(userWallet.getId());
|
|
|
217 |
}
|
| 24739 |
tejbeer |
218 |
|
| 32494 |
amit.gupta |
219 |
@Override
|
|
|
220 |
public long getSizeByRetailerId(int retailerId, LocalDateTime startDateTime, LocalDateTime endDateTime)
|
|
|
221 |
throws ProfitMandiBusinessException {
|
|
|
222 |
if (underMaintainance) {
|
|
|
223 |
throw pbse;
|
|
|
224 |
}
|
|
|
225 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
|
|
226 |
return userWalletHistoryRepository.selectCountByWalletId(userWallet.getId(), startDateTime, endDateTime);
|
|
|
227 |
}
|
| 25542 |
amit.gupta |
228 |
|
| 32494 |
amit.gupta |
229 |
@Override
|
|
|
230 |
public List<UserWalletHistory> getPaginatedUserWalletHistoryByRetailerId(int retailerId,
|
|
|
231 |
LocalDateTime startDateTime, LocalDateTime endDateTime, int offset, int limit)
|
|
|
232 |
throws ProfitMandiBusinessException {
|
|
|
233 |
if (underMaintainance) {
|
|
|
234 |
throw pbse;
|
|
|
235 |
}
|
|
|
236 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
|
|
237 |
return userWalletHistoryRepository.selectPaginatedByWalletId(userWallet.getId(), startDateTime, endDateTime,
|
|
|
238 |
offset, limit);
|
|
|
239 |
}
|
| 22550 |
ashik.ali |
240 |
|
| 32494 |
amit.gupta |
241 |
@Override
|
| 33247 |
ranu |
242 |
public Map<Integer, UserWallet> getRetailerIdUserWalletMap(Set<Integer> retailerIds) throws ProfitMandiBusinessException {
|
| 32494 |
amit.gupta |
243 |
List<UserWallet> userWallets = userWalletRepository.selectByRetailerIds(retailerIds);
|
|
|
244 |
Map<Integer, UserWallet> retailerIdUserWalletMap = new HashMap<>();
|
|
|
245 |
for (UserWallet userWallet : userWallets) {
|
|
|
246 |
retailerIdUserWalletMap.put(userWallet.getUserId(), userWallet);
|
|
|
247 |
}
|
|
|
248 |
return retailerIdUserWalletMap;
|
|
|
249 |
}
|
| 24739 |
tejbeer |
250 |
|
| 32494 |
amit.gupta |
251 |
@Override
|
| 33247 |
ranu |
252 |
public Map<Integer, Integer> getWaleltRetailerMap(Set<Integer> walletIds) throws ProfitMandiBusinessException {
|
| 32494 |
amit.gupta |
253 |
List<UserWallet> userWallets = userWalletRepository.selectAllById(walletIds);
|
|
|
254 |
Map<Integer, Integer> walletRetailerMap = new HashMap<>();
|
|
|
255 |
for (UserWallet userWallet : userWallets) {
|
|
|
256 |
walletRetailerMap.put(userWallet.getId(), userWallet.getUserId());
|
|
|
257 |
}
|
|
|
258 |
return walletRetailerMap;
|
|
|
259 |
}
|
| 30740 |
amit.gupta |
260 |
|
| 32494 |
amit.gupta |
261 |
@Override
|
|
|
262 |
public boolean isExistWalletHistory(int retailerId, int referenceId, WalletReferenceType referenceType)
|
|
|
263 |
throws ProfitMandiBusinessException {
|
|
|
264 |
if (underMaintainance) {
|
|
|
265 |
throw pbse;
|
|
|
266 |
}
|
|
|
267 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
|
|
268 |
return userWalletHistoryRepository.isExist(userWallet.getId(), referenceType, referenceId);
|
|
|
269 |
}
|
| 25542 |
amit.gupta |
270 |
|
| 32494 |
amit.gupta |
271 |
@Override
|
|
|
272 |
public UserWallet getUserWallet(int retailerId) throws ProfitMandiBusinessException {
|
|
|
273 |
if (underMaintainance) {
|
|
|
274 |
throw pbse;
|
|
|
275 |
}
|
|
|
276 |
try {
|
|
|
277 |
return userWalletRepository.selectByRetailerId(retailerId);
|
|
|
278 |
} catch (Exception e) {
|
|
|
279 |
UserWallet uw = new UserWallet();
|
|
|
280 |
uw.setAmount(0);
|
|
|
281 |
uw.setRefundableAmount(0);
|
|
|
282 |
uw.setUserId(retailerId);
|
|
|
283 |
userWalletRepository.persist(uw);
|
|
|
284 |
return uw;
|
|
|
285 |
}
|
|
|
286 |
}
|
| 25542 |
amit.gupta |
287 |
|
| 32494 |
amit.gupta |
288 |
@Override
|
|
|
289 |
public float getOpeningTill(int fofoId, LocalDateTime date) throws ProfitMandiBusinessException {
|
|
|
290 |
UserWallet wallet = userWalletRepository.selectByRetailerId(fofoId);
|
|
|
291 |
return userWalletHistoryRepository.getSumTillDate(wallet.getId(), date);
|
|
|
292 |
}
|
| 24739 |
tejbeer |
293 |
|
| 32494 |
amit.gupta |
294 |
@Override
|
|
|
295 |
public float getOpeningTillExcludingPurchase(int fofoId, LocalDateTime date) throws ProfitMandiBusinessException {
|
|
|
296 |
UserWallet wallet = userWalletRepository.selectByRetailerId(fofoId);
|
|
|
297 |
return userWalletHistoryRepository.getSumTillDate(wallet.getId(), date) - userWalletHistoryRepository.getSumTillDate(wallet.getId(), date, WalletReferenceType.PURCHASE);
|
|
|
298 |
}
|
| 24739 |
tejbeer |
299 |
|
| 32494 |
amit.gupta |
300 |
@Override
|
|
|
301 |
public boolean refundToWallet(int retailerId, float amountToRefund, int transactionId,
|
|
|
302 |
WalletReferenceType walletReferenceType, String description) throws ProfitMandiBusinessException {
|
| 24739 |
tejbeer |
303 |
|
| 32494 |
amit.gupta |
304 |
List<UserWalletHistory> all_entries = userWalletHistoryRepository
|
|
|
305 |
.selectAllByreferenceIdandreferenceType(transactionId, walletReferenceType);
|
| 30449 |
amit.gupta |
306 |
|
| 32494 |
amit.gupta |
307 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
| 33172 |
tejus.loha |
308 |
int walletAmount = this.getWalletAmount(retailerId);
|
| 32494 |
amit.gupta |
309 |
LOGGER.info("userWallet" + userWallet);
|
|
|
310 |
int max_eligible_credit_amount = 0;
|
| 24739 |
tejbeer |
311 |
|
| 32494 |
amit.gupta |
312 |
LOGGER.info("all_entries {}", all_entries);
|
|
|
313 |
for (UserWalletHistory history : all_entries) {
|
|
|
314 |
max_eligible_credit_amount -= history.getAmount();
|
|
|
315 |
}
|
|
|
316 |
if (max_eligible_credit_amount < amountToRefund) {
|
|
|
317 |
LOGGER.info("Cant be credited back to wallet as most of it has been already credited");
|
|
|
318 |
return false;
|
|
|
319 |
}
|
| 22550 |
ashik.ali |
320 |
|
| 32494 |
amit.gupta |
321 |
userWallet.setAmount(walletAmount + Math.round(amountToRefund));
|
| 23509 |
amit.gupta |
322 |
|
| 32494 |
amit.gupta |
323 |
LOGGER.info("userWallet" + userWallet);
|
| 30449 |
amit.gupta |
324 |
|
| 32494 |
amit.gupta |
325 |
UserWalletHistory userWalletHistory = new UserWalletHistory();
|
|
|
326 |
userWalletHistory.setAmount(Math.round(amountToRefund));
|
|
|
327 |
userWalletHistory.setReference(transactionId);
|
|
|
328 |
userWalletHistory.setReferenceType(walletReferenceType);
|
|
|
329 |
userWalletHistory.setWalletId(userWallet.getId());
|
|
|
330 |
userWalletHistory.setTimestamp(LocalDateTime.now());
|
|
|
331 |
userWalletHistory.setDescription(description);
|
|
|
332 |
userWalletHistory.setBusinessTimestamp(all_entries.get(0).getBusinessTimestamp());
|
| 30449 |
amit.gupta |
333 |
|
| 32494 |
amit.gupta |
334 |
userWalletHistoryRepository.persist(userWalletHistory);
|
|
|
335 |
return true;
|
| 24739 |
tejbeer |
336 |
|
| 32494 |
amit.gupta |
337 |
}
|
| 26254 |
amit.gupta |
338 |
|
| 32494 |
amit.gupta |
339 |
@Override
|
|
|
340 |
public int getWalletAmount(int retailerId) throws ProfitMandiBusinessException {
|
|
|
341 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
|
|
342 |
if (userWallet == null) {
|
| 33421 |
amit.gupta |
343 |
userWallet = new UserWallet();
|
|
|
344 |
userWallet.setUserId(retailerId);
|
|
|
345 |
userWalletRepository.persist(userWallet);
|
| 32494 |
amit.gupta |
346 |
}
|
|
|
347 |
return (int) userWalletHistoryRepository.selectSumByWallet(userWallet.getId());
|
|
|
348 |
}
|
| 24739 |
tejbeer |
349 |
|
| 32494 |
amit.gupta |
350 |
@Override
|
|
|
351 |
public List<UserWalletHistory> getAllByReference(int fofoId, int reference, WalletReferenceType walletReferenceType)
|
|
|
352 |
throws ProfitMandiBusinessException {
|
|
|
353 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(fofoId);
|
|
|
354 |
if (userWallet == null) {
|
|
|
355 |
return new ArrayList<UserWalletHistory>();
|
|
|
356 |
}
|
|
|
357 |
return userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(userWallet.getId(), reference,
|
|
|
358 |
walletReferenceType);
|
|
|
359 |
}
|
| 30449 |
amit.gupta |
360 |
|
| 32494 |
amit.gupta |
361 |
@Override
|
|
|
362 |
public void resetWallet() throws ProfitMandiBusinessException {
|
|
|
363 |
List<UserWallet> userWallets = userWalletRepository.selectAll();
|
|
|
364 |
for (UserWallet userWallet : userWallets) {
|
|
|
365 |
userWallet.setAmount(this.getWalletAmount(userWallet.getUserId()));
|
| 24739 |
tejbeer |
366 |
|
| 32494 |
amit.gupta |
367 |
}
|
|
|
368 |
}
|
| 25395 |
tejbeer |
369 |
|
| 32494 |
amit.gupta |
370 |
@Override
|
|
|
371 |
public int getManualReference(WalletReferenceType referenceType) {
|
|
|
372 |
ManualPaymentType paymentType = manualPaymentRequestRepository.selectByReferenceType(referenceType);
|
| 24739 |
tejbeer |
373 |
|
| 32494 |
amit.gupta |
374 |
if (paymentType == null) {
|
|
|
375 |
paymentType = new ManualPaymentType();
|
|
|
376 |
paymentType.setReferenceType(referenceType);
|
|
|
377 |
manualPaymentRequestRepository.persist(paymentType);
|
|
|
378 |
}
|
|
|
379 |
paymentType.setCounter(paymentType.getCounter() + 1);
|
|
|
380 |
return paymentType.getCounter();
|
| 24739 |
tejbeer |
381 |
|
| 32494 |
amit.gupta |
382 |
}
|
| 34261 |
tejus.loha |
383 |
|
|
|
384 |
@Override
|
|
|
385 |
public ResponseEntity<?> createAddWalletRequestReport(LocalDateTime startDate, LocalDateTime endDate, AddWalletRequestStatus status) throws Exception {
|
|
|
386 |
List<List<?>> rows = new ArrayList<>();
|
|
|
387 |
List<String> header = Arrays.asList(
|
|
|
388 |
"Retailer Id",
|
|
|
389 |
"Retailer Name",
|
|
|
390 |
"Email",
|
|
|
391 |
"City",
|
|
|
392 |
"State",
|
|
|
393 |
"Transaction Reference",
|
|
|
394 |
"Bank Name",
|
|
|
395 |
"Reference Date",
|
|
|
396 |
"Amount",
|
|
|
397 |
"status",
|
|
|
398 |
"Created On",
|
|
|
399 |
"Updated On"
|
|
|
400 |
);
|
|
|
401 |
|
|
|
402 |
List<AddWalletRequest> addWalletRequests = addWalletRequestRepository.selectAllRetailerIdByDateAndStatus(startDate, endDate, status);
|
|
|
403 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
404 |
for (AddWalletRequest addWalletRequest : addWalletRequests) {
|
|
|
405 |
CustomRetailer customRetailer = customRetailerMap.get(addWalletRequest.getRetailerId());
|
|
|
406 |
rows.add(Arrays
|
|
|
407 |
.asList(
|
|
|
408 |
addWalletRequest.getRetailerId(),
|
|
|
409 |
customRetailer.getBusinessName(),
|
|
|
410 |
customRetailer.getEmail(),
|
|
|
411 |
customRetailer.getAddress().getCity(),
|
|
|
412 |
customRetailer.getAddress().getState(),
|
|
|
413 |
addWalletRequest.getTransaction_reference(),
|
|
|
414 |
addWalletRequest.getBank_name(),
|
|
|
415 |
addWalletRequest.getReference_date(),
|
|
|
416 |
addWalletRequest.getAmount(),
|
|
|
417 |
addWalletRequest.getStatus(),
|
|
|
418 |
addWalletRequest.getCreateTimestamp(),
|
|
|
419 |
addWalletRequest.getUpdateTimestamp()
|
|
|
420 |
)
|
|
|
421 |
);
|
|
|
422 |
}
|
|
|
423 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(header, rows);
|
|
|
424 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Add-wallet-request-"+status+"-Reort-" + startDate.toLocalDate() + "-To-" + endDate.toLocalDate());
|
|
|
425 |
return responseEntity;
|
|
|
426 |
}
|
| 32494 |
amit.gupta |
427 |
}
|
| 24739 |
tejbeer |
428 |
|