| Line 292... |
Line 292... |
| 292 |
}
|
292 |
}
|
| 293 |
|
293 |
|
| 294 |
// Lets work it up for The Mobile Planet
|
294 |
// Lets work it up for The Mobile Planet
|
| 295 |
// HRFB002 - 157112773
|
295 |
// HRFB002 - 157112773
|
| 296 |
public void dailyReconciliation() throws Exception {
|
296 |
public void dailyReconciliation() throws Exception {
|
| - |
|
297 |
Map<Integer, String> stores = fofoStoreRepository.getStoresMap();
|
| 297 |
List<List<?>> rows = new ArrayList<>();
|
298 |
List<List<?>> rows = new ArrayList<>();
|
| - |
|
299 |
Map<Integer, String> retailerNameMap = retailerService.getAllFofoRetailerIdNameMap(new ArrayList<>(stores.keySet()));
|
| - |
|
300 |
for (int partnerId : stores.keySet()) {
|
| 298 |
UserWallet uw = userWalletRepository.selectByRetailerId(157112773);
|
301 |
UserWallet uw = userWalletRepository.selectByRetailerId(partnerId);
|
| 299 |
List<UserWalletHistory> walletHistory = userWalletHistoryRepository.selectByWalletId(uw.getId());
|
302 |
List<UserWalletHistory> walletHistory = userWalletHistoryRepository.selectByWalletId(uw.getId());
|
| 300 |
Map<LocalDate, List<UserWalletHistory>> dateWiseWalletHistory = walletHistory.stream()
|
303 |
Map<LocalDate, List<UserWalletHistory>> dateWiseWalletHistory = walletHistory.stream()
|
| 301 |
.collect(Collectors.groupingBy(x -> x.getTimestamp().toLocalDate(), Collectors.toList()));
|
304 |
.collect(Collectors.groupingBy(x -> x.getTimestamp().toLocalDate(), Collectors.toList()));
|
| 302 |
for (Map.Entry<LocalDate, List<UserWalletHistory>> entry : dateWiseWalletHistory.entrySet()) {
|
305 |
for (Map.Entry<LocalDate, List<UserWalletHistory>> entry : dateWiseWalletHistory.entrySet()) {
|
| 303 |
LocalDate dateToReconcile = entry.getKey();
|
306 |
LocalDate dateToReconcile = entry.getKey();
|
| 304 |
List<UserWalletHistory> history = entry.getValue();
|
307 |
List<UserWalletHistory> history = entry.getValue();
|
| 305 |
rows.add(reconcileOrdersAndWallet(uw.getUserId(), dateToReconcile, history));
|
308 |
rows.add(reconcileOrdersAndWallet(uw.getUserId(), retailerNameMap.get(partnerId), dateToReconcile, history));
|
| - |
|
309 |
}
|
| 306 |
}
|
310 |
}
|
| 307 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
311 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
| 308 |
Arrays.asList("Date", "Wallet amount", "Ordered Total", "Cancelled Total", "Refunded Total"), rows);
|
312 |
Arrays.asList("Store Code", "Date", "Wallet amount consumed", "Ordered Total", "Cancelled Total", "Refunded Total"), rows);
|
| 309 |
|
313 |
|
| 310 |
Utils.sendMailWithAttachment(mailSender, new String[] { "amit.gupta@shop2020.in" }, new String[] {}, "Test",
|
314 |
Utils.sendMailWithAttachment(mailSender, new String[] { "amit.gupta@shop2020.in" }, new String[] {}, "Test",
|
| 311 |
"test", "File.csv", new ByteArrayResource(baos.toByteArray()));
|
315 |
"test", "File.csv", new ByteArrayResource(baos.toByteArray()));
|
| 312 |
}
|
316 |
}
|
| 313 |
|
317 |
|
| 314 |
private List<?> reconcileOrdersAndWallet(int fofoId, LocalDate localDate, List<UserWalletHistory> history)
|
318 |
private List<?> reconcileOrdersAndWallet(int fofoId, String storeName, LocalDate localDate, List<UserWalletHistory> history)
|
| 315 |
throws Exception {
|
319 |
throws Exception {
|
| 316 |
Map<Integer, Integer> transactionsOnThatDate = history.stream()
|
320 |
Map<Integer, Integer> transactionsOnThatDate = history.stream()
|
| 317 |
.filter(x -> x.getReferenceType().equals(WalletReferenceType.PURCHASE))
|
321 |
.filter(x -> x.getReferenceType().equals(WalletReferenceType.PURCHASE))
|
| 318 |
.collect(Collectors.groupingBy(x -> x.getReference(), Collectors.summingInt(x -> x.getAmount())));
|
322 |
.collect(Collectors.groupingBy(x -> x.getReference(), Collectors.summingInt(x -> x.getAmount())));
|
| 319 |
|
323 |
|
| Line 336... |
Line 340... |
| 336 |
} else {
|
340 |
} else {
|
| 337 |
returnedAmount += returnedOrder.getTotalPrice();
|
341 |
returnedAmount += returnedOrder.getTotalPrice();
|
| 338 |
}
|
342 |
}
|
| 339 |
}
|
343 |
}
|
| 340 |
totalDeductedAmount += o.getWalletAmount();
|
344 |
totalDeductedAmount += o.getWalletAmount();
|
| 341 |
|
345 |
|
| 342 |
} else if (o.getRefundTimestamp() != null && o.getRefundTimestamp().toLocalDate().equals(localDate)) {
|
346 |
} else if (o.getRefundTimestamp() != null && o.getRefundTimestamp().toLocalDate().equals(localDate)) {
|
| 343 |
ReturnOrder returnedOrder = returnOrderRepository.selectByOrderId(o.getId());
|
347 |
ReturnOrder returnedOrder = returnOrderRepository.selectByOrderId(o.getId());
|
| 344 |
if (returnedOrder == null) {
|
348 |
if (returnedOrder == null) {
|
| 345 |
cancelledAmount += o.getWalletAmount();
|
349 |
cancelledAmount += o.getWalletAmount();
|
| 346 |
} else {
|
350 |
} else {
|
| Line 350... |
Line 354... |
| 350 |
}
|
354 |
}
|
| 351 |
totalWalletConsumed -= transactionsOnThatDate.get(transactionId);
|
355 |
totalWalletConsumed -= transactionsOnThatDate.get(transactionId);
|
| 352 |
|
356 |
|
| 353 |
}
|
357 |
}
|
| 354 |
|
358 |
|
| 355 |
return Arrays.asList(localDate, totalWalletConsumed, totalDeductedAmount, cancelledAmount, returnedAmount);
|
359 |
return Arrays.asList(localDate, storeName, totalWalletConsumed, totalDeductedAmount, cancelledAmount, returnedAmount);
|
| 356 |
|
360 |
|
| 357 |
}
|
361 |
}
|
| 358 |
|
362 |
|
| 359 |
private void reconcileDailySchemeIn() {
|
363 |
private void reconcileDailySchemeIn() {
|
| 360 |
|
364 |
|