| Line 6... |
Line 6... |
| 6 |
import java.text.MessageFormat;
|
6 |
import java.text.MessageFormat;
|
| 7 |
import java.time.LocalDate;
|
7 |
import java.time.LocalDate;
|
| 8 |
import java.time.LocalDateTime;
|
8 |
import java.time.LocalDateTime;
|
| 9 |
import java.time.LocalTime;
|
9 |
import java.time.LocalTime;
|
| 10 |
import java.time.temporal.ChronoUnit;
|
10 |
import java.time.temporal.ChronoUnit;
|
| 11 |
import java.time.temporal.TemporalAmount;
|
- |
|
| 12 |
import java.time.temporal.TemporalUnit;
|
- |
|
| 13 |
import java.util.ArrayList;
|
11 |
import java.util.ArrayList;
|
| 14 |
import java.util.Arrays;
|
12 |
import java.util.Arrays;
|
| 15 |
import java.util.HashMap;
|
13 |
import java.util.HashMap;
|
| 16 |
import java.util.HashSet;
|
14 |
import java.util.HashSet;
|
| 17 |
import java.util.List;
|
15 |
import java.util.List;
|
| Line 74... |
Line 72... |
| 74 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
72 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 75 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
73 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
| 76 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
74 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 77 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
75 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 78 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
76 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| - |
|
77 |
import com.spice.profitmandi.service.order.OrderService;
|
| 79 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
78 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
| 80 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
79 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
| 81 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
80 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 82 |
import com.spice.profitmandi.service.slab.TargetSlabService;
|
81 |
import com.spice.profitmandi.service.slab.TargetSlabService;
|
| 83 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
82 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| Line 131... |
Line 130... |
| 131 |
|
130 |
|
| 132 |
@Autowired
|
131 |
@Autowired
|
| 133 |
private SchemeService schemeService;
|
132 |
private SchemeService schemeService;
|
| 134 |
|
133 |
|
| 135 |
@Autowired
|
134 |
@Autowired
|
| - |
|
135 |
private OrderService orderService;
|
| - |
|
136 |
|
| - |
|
137 |
@Autowired
|
| 136 |
private SchemeInOutRepository schemeInOutRepository;
|
138 |
private SchemeInOutRepository schemeInOutRepository;
|
| 137 |
|
139 |
|
| 138 |
@Autowired
|
140 |
@Autowired
|
| 139 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
141 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
| 140 |
|
142 |
|
| Line 343... |
Line 345... |
| 343 |
public void evaluateExcessSchemeOut() throws Exception {
|
345 |
public void evaluateExcessSchemeOut() throws Exception {
|
| 344 |
Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
|
346 |
Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
|
| 345 |
Map<Integer, Float> userAmountMap = new HashMap<>();
|
347 |
Map<Integer, Float> userAmountMap = new HashMap<>();
|
| 346 |
|
348 |
|
| 347 |
List<List<Object>> rows = new ArrayList<>();
|
349 |
List<List<Object>> rows = new ArrayList<>();
|
| 348 |
List<String> headers = Arrays.asList("Scheme", "Item","Partner", "Amount", "Credited On",
|
350 |
List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
|
| 349 |
"Invoice Number", "Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
|
351 |
"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
|
| 350 |
schemeRepository.selectAll().stream().forEach(x -> {
|
352 |
schemeRepository.selectAll().stream().forEach(x -> {
|
| 351 |
if (x.getType().equals(SchemeType.OUT)) {
|
353 |
if (x.getType().equals(SchemeType.OUT)) {
|
| 352 |
List<SchemeInOut> sioList = schemeInOutRepository
|
354 |
List<SchemeInOut> sioList = schemeInOutRepository
|
| 353 |
.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
|
355 |
.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
|
| 354 |
if (x.getActiveTimestamp() != null) {
|
356 |
if (x.getActiveTimestamp() != null) {
|
| Line 357... |
Line 359... |
| 357 |
endDateTime = x.getExpireTimestamp();
|
359 |
endDateTime = x.getExpireTimestamp();
|
| 358 |
}
|
360 |
}
|
| 359 |
for (SchemeInOut sio : sioList) {
|
361 |
for (SchemeInOut sio : sioList) {
|
| 360 |
InventoryItem inventoryItem = null;
|
362 |
InventoryItem inventoryItem = null;
|
| 361 |
inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
363 |
inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
| 362 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndSerialNumber(inventoryItem.getFofoId(), inventoryItem.getSerialNumber(),
|
364 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndSerialNumber(
|
| 363 |
null, null, 0, 1).get(0);
|
365 |
inventoryItem.getFofoId(), inventoryItem.getSerialNumber(), null, null, 0, 1).get(0);
|
| 364 |
Optional<ScanRecord> record = scanRecordRepository
|
366 |
Optional<ScanRecord> record = scanRecordRepository
|
| 365 |
.selectByInventoryItemId(sio.getInventoryItemId()).stream()
|
367 |
.selectByInventoryItemId(sio.getInventoryItemId()).stream()
|
| 366 |
.filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
|
368 |
.filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
|
| 367 |
if (record.isPresent()) {
|
369 |
if (record.isPresent()) {
|
| 368 |
int fofoId = record.get().getFofoId();
|
370 |
int fofoId = record.get().getFofoId();
|
| Line 395... |
Line 397... |
| 395 |
userAmountMap.entrySet().stream()
|
397 |
userAmountMap.entrySet().stream()
|
| 396 |
.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
|
398 |
.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
|
| 397 |
x.getValue(), userNameMap.get(x.getKey())));
|
399 |
x.getValue(), userNameMap.get(x.getKey())));
|
| 398 |
|
400 |
|
| 399 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
401 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| 400 |
Utils.sendMailWithAttachment(googleMailSender, "adeel.yazdani@smartdukaan.com",
|
402 |
Utils.sendMailWithAttachment(googleMailSender,
|
| 401 |
new String[] { "amit.gupta@shop2020.in" }, "Partner Excess Amount", "PFA"
|
403 |
new String[] { "amit.gupta@shop2020.in", "adeel.yazdani@smartdukaan.com" }, null,
|
| 402 |
, "ListofSchemes.csv", new ByteArrayResource(baos.toByteArray()));
|
404 |
"Partner Excess Amount", "PFA", "ListofSchemes.csv", new ByteArrayResource(baos.toByteArray()));
|
| 403 |
|
405 |
|
| 404 |
}
|
406 |
}
|
| 405 |
|
407 |
|
| 406 |
public void processScheme(int offset) throws Exception {
|
408 |
public void processScheme(int offset) throws Exception {
|
| 407 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(30*offset);
|
409 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(30 * offset);
|
| 408 |
LocalDateTime endDate = startDate.plusDays(30);
|
410 |
LocalDateTime endDate = startDate.plusDays(30);
|
| 409 |
processScheme(startDate, endDate);
|
411 |
processScheme(startDate, endDate);
|
| 410 |
}
|
412 |
}
|
| 411 |
|
413 |
|
| 412 |
public void processScheme() throws Exception {
|
414 |
public void processScheme() throws Exception {
|
| 413 |
LocalDateTime fromDate = LocalDateTime.now().minusDays(30);
|
415 |
LocalDateTime fromDate = LocalDateTime.now().minusDays(30);
|
| 414 |
processScheme(fromDate, LocalDateTime.now());
|
416 |
processScheme(fromDate, LocalDateTime.now());
|
| 415 |
}
|
417 |
}
|
| 416 |
|
418 |
|
| 417 |
public void processScheme(LocalDateTime startDate, LocalDateTime endDate) throws Exception {
|
419 |
public void processScheme(LocalDateTime startDate, LocalDateTime endDate) throws Exception {
|
| 418 |
LOGGER.info("Started execution at {}", LocalDateTime.now());
|
420 |
LOGGER.info("Started execution at {}", LocalDateTime.now());
|
| 419 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
421 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
| 420 |
for (Purchase purchase : purchases) {
|
422 |
for (Purchase purchase : purchases) {
|
| 421 |
try {
|
423 |
try {
|
| 422 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
424 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
| 423 |
} catch (Exception e) {
|
425 |
} catch (Exception e) {
|
| 424 |
LOGGER.error("Error while processing purchase {} for scheme In ", purchase.getId());
|
426 |
LOGGER.error("Error while processing purchase {} for scheme In ", purchase.getId());
|
| 425 |
e.printStackTrace();
|
427 |
e.printStackTrace();
|
| 426 |
|
428 |
|
| 427 |
}
|
429 |
}
|
| 428 |
}
|
430 |
}
|
| 429 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
431 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
| 430 |
for (FofoOrder fofoOrder : fofoOrders) {
|
432 |
for (FofoOrder fofoOrder : fofoOrders) {
|
| 431 |
try {
|
433 |
try {
|
| Line 458... |
Line 460... |
| 458 |
rechargeTransactionRepository.persist(rt);
|
460 |
rechargeTransactionRepository.persist(rt);
|
| 459 |
}
|
461 |
}
|
| 460 |
LOGGER.info("Cashbacks for Recharge processed Successfully");
|
462 |
LOGGER.info("Cashbacks for Recharge processed Successfully");
|
| 461 |
}
|
463 |
}
|
| 462 |
|
464 |
|
| 463 |
public void sendPartnerInvestmentDetails() throws Exception {
|
465 |
public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
|
| 464 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
- |
|
| 465 |
|
- |
|
| 466 |
List<FofoStore> fofoStores = fofoStoreRepository.selectAll();
|
466 |
List<FofoStore> fofoStores = fofoStoreRepository.selectAll();
|
| 467 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
467 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
| 468 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
468 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| 469 |
|
469 |
|
| 470 |
List<String> headers = Arrays.asList("Code", "StoreName", "Email", "Mobile", "WalletAmount", "InStockAmount",
|
470 |
List<String> headers = Arrays.asList("Code", "StoreName", "Email", "Mobile", "Wallet Amount",
|
| - |
|
471 |
"Yesterday's Sale", "In Stock Amount", "Return In Transit Stock", "Unbilled Amount",
|
| 471 |
"UnbilledStockAmount", "GrnPendingStockAmount", "MinimumInvestment", "TotalInvested", "ShortAmount");
|
472 |
"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short");
|
| 472 |
List<List<Object>> rows = new ArrayList<>();
|
473 |
List<List<Object>> rows = new ArrayList<>();
|
| 473 |
for (FofoStore fofoStore : fofoStores) {
|
474 |
for (FofoStore fofoStore : fofoStores) {
|
| 474 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
475 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
| 475 |
if (retailer == null) {
|
476 |
if (retailer == null) {
|
| 476 |
LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
|
477 |
LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
|
| 477 |
continue;
|
478 |
continue;
|
| 478 |
}
|
479 |
}
|
| 479 |
float walletAmount = walletService.getUserWallet(fofoStore.getId()).getAmount();
|
480 |
float walletAmount = walletService.getUserWallet(fofoStore.getId()).getAmount();
|
| 480 |
float inStockAmount = inventoryService.getTotalAmountInStock(fofoStore.getId());
|
481 |
float inStockAmount = inventoryService.getTotalAmountInStock(fofoStore.getId());
|
| - |
|
482 |
float salesAmount = orderService.getSales(fofoStore.getId(), LocalDate.now().minusDays(1));
|
| 481 |
|
483 |
|
| 482 |
float unbilledStockAmount = 0;
|
484 |
float unbilledStockAmount = 0;
|
| 483 |
List<Order> unbilledOrders = transactionService.getInTransitOrders(fofoStore.getId());
|
485 |
List<Order> unbilledOrders = transactionService.getInTransitOrders(fofoStore.getId());
|
| 484 |
for (Order unBilledOrder : unbilledOrders) {
|
486 |
for (Order unBilledOrder : unbilledOrders) {
|
| 485 |
unbilledStockAmount += unBilledOrder.getTotalAmount();
|
487 |
unbilledStockAmount += unBilledOrder.getTotalAmount();
|
| Line 492... |
Line 494... |
| 492 |
grnPendingOrder.getRetailerEmailId());
|
494 |
grnPendingOrder.getRetailerEmailId());
|
| 493 |
grnPendingStockAmount += grnPendingOrder.getTotalAmount();
|
495 |
grnPendingStockAmount += grnPendingOrder.getTotalAmount();
|
| 494 |
}
|
496 |
}
|
| 495 |
float totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
|
497 |
float totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
|
| 496 |
List<Object> row = Arrays.asList(fofoStore.getCode(), retailer.getBusinessName(), retailer.getEmail(),
|
498 |
List<Object> row = Arrays.asList(fofoStore.getCode(), retailer.getBusinessName(), retailer.getEmail(),
|
| 497 |
retailer.getMobileNumber(), walletAmount, inStockAmount, unbilledStockAmount, grnPendingStockAmount,
|
499 |
retailer.getMobileNumber(), salesAmount, walletAmount, inStockAmount, 0, unbilledStockAmount,
|
| 498 |
fofoStore.getMinimumInvestment(), totalInvestedAmount,
|
500 |
grnPendingStockAmount, fofoStore.getMinimumInvestment(), totalInvestedAmount,
|
| 499 |
fofoStore.getMinimumInvestment() - totalInvestedAmount);
|
501 |
fofoStore.getMinimumInvestment() - totalInvestedAmount);
|
| 500 |
rows.add(row);
|
502 |
rows.add(row);
|
| 501 |
|
503 |
|
| 502 |
}
|
504 |
}
|
| - |
|
505 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 503 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
506 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| - |
|
507 |
String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
|
| - |
|
508 |
|
| 504 |
Utils.sendMailWithAttachment(googleMailSender, "adeel.yazdani@smartdukaan.com",
|
509 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Partner Investment Summary", "PFA", fileName,
|
| - |
|
510 |
new ByteArrayResource(baos.toByteArray()));
|
| - |
|
511 |
|
| - |
|
512 |
}
|
| - |
|
513 |
|
| - |
|
514 |
public void sendPartnerInvestmentDetails() throws Exception {
|
| 505 |
new String[] { "amandeep.singh@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
515 |
List<String> sendTo = Arrays.asList("adeel.yazdani@smartdukaan.com", "amandeep.singh@smartdukaan.com",
|
| 506 |
"kamini.sharma@smartdukaan.com", "dhruv.kathpal@smartdukaan.com" },
|
516 |
"tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "dhruv.kathpal@smartdukaan.com",
|
| - |
|
517 |
"neeraj.gupta@smartdukaan.com");
|
| 507 |
"Partner Investment Summary", "PFA", fileName, new ByteArrayResource(baos.toByteArray()));
|
518 |
this.sendPartnerInvestmentDetails(sendTo);
|
| - |
|
519 |
|
| 508 |
}
|
520 |
}
|
| 509 |
|
521 |
|
| 510 |
private void sendMailWithAttachments(String[] email, String[] ccEmails, String body, String subject,
|
522 |
private void sendMailWithAttachments(String[] email, String[] ccEmails, String body, String subject,
|
| 511 |
Map<String, InputStream> inputStreams)
|
523 |
Map<String, InputStream> inputStreams)
|
| 512 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
524 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
| Line 552... |
Line 564... |
| 552 |
|
564 |
|
| 553 |
inputStreams.put(partnerTargetDetail.getTargetName(), is);
|
565 |
inputStreams.put(partnerTargetDetail.getTargetName(), is);
|
| 554 |
|
566 |
|
| 555 |
}
|
567 |
}
|
| 556 |
// String[] ccEmails = null;
|
568 |
// String[] ccEmails = null;
|
| 557 |
if (partnerTargetDetails.size()>0) {
|
569 |
if (partnerTargetDetails.size() > 0) {
|
| 558 |
String[] ccEmails = { "Tarun.verma@smartdukaan.com", "Kamini.sharma@smartdukaan.com",
|
570 |
String[] ccEmails = { "Tarun.verma@smartdukaan.com", "Kamini.sharma@smartdukaan.com",
|
| 559 |
"chaitnaya.vats@smartdukaan.com", "dhruv.kathpal@smartdukaan.com" };
|
571 |
"chaitnaya.vats@smartdukaan.com", "dhruv.kathpal@smartdukaan.com" };
|
| 560 |
String subject = "Daily Sales Report ";
|
572 |
String subject = "Daily Sales Report ";
|
| 561 |
String message = MessageFormat.format("Sale Target summary for {0}", LocalDate.now());
|
573 |
String message = MessageFormat.format("Sale Target summary for {0}", LocalDate.now());
|
| 562 |
LOGGER.info("message" + message);
|
574 |
LOGGER.info("message" + message);
|
| 563 |
if (salesHeadDetail.getName().equals("Kamal")) {
|
575 |
if (salesHeadDetail.getName().equals("Kamal")) {
|
| 564 |
LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
|
576 |
LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
|
| 565 |
String[] to = { salesHeadDetail.getEmail(), "mohinder.mutreja@smartdukaan.com" };
|
577 |
String[] to = { salesHeadDetail.getEmail(), "mohinder.mutreja@smartdukaan.com" };
|
| 566 |
|
578 |
|
| 567 |
this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
|
579 |
this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
|
| 568 |
|
580 |
|
| 569 |
} else {
|
581 |
} else {
|
| 570 |
LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
|
582 |
LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
|
| 571 |
String[] to = { salesHeadDetail.getEmail() };
|
583 |
String[] to = { salesHeadDetail.getEmail() };
|
| 572 |
this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
|
584 |
this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
|
| 573 |
}
|
585 |
}
|
| 574 |
}
|
586 |
}
|
| 575 |
}
|
587 |
}
|
| 576 |
|
588 |
|
| 577 |
public void sendMailToPartnerAboutTargetAndSales() throws ProfitMandiBusinessException, MessagingException,
|
589 |
public void sendMailToPartnerAboutTargetAndSales() throws ProfitMandiBusinessException, MessagingException,
|
| 578 |
IOException, EncryptedDocumentException, InvalidFormatException {
|
590 |
IOException, EncryptedDocumentException, InvalidFormatException {
|