| Line 151... |
Line 151... |
| 151 |
@Autowired
|
151 |
@Autowired
|
| 152 |
PartnerStatsService partnerStatsService;
|
152 |
PartnerStatsService partnerStatsService;
|
| 153 |
|
153 |
|
| 154 |
public void test() throws Exception {
|
154 |
public void test() throws Exception {
|
| 155 |
System.out.println("test start");
|
155 |
System.out.println("test start");
|
| 156 |
partnerStatsService.getAllPartnerStats();
|
156 |
//partnerStatsService.getAllPartnerStats();
|
| 157 |
//this.generateBiReportExcel();
|
157 |
this.generateBiReportExcel();
|
| 158 |
System.out.println("test end");
|
158 |
System.out.println("test end");
|
| 159 |
|
159 |
|
| 160 |
}
|
160 |
}
|
| 161 |
|
161 |
|
| 162 |
public void generateBiReport() throws Exception {
|
162 |
public void generateBiReport() throws Exception {
|
| Line 454... |
Line 454... |
| 454 |
|
454 |
|
| 455 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getAllFofoRetailersInternalFalse();
|
455 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getAllFofoRetailersInternalFalse();
|
| 456 |
|
456 |
|
| 457 |
List<Integer> retailerIds = customRetailers.values().stream().map(CustomRetailer::getPartnerId).collect(Collectors.toList());
|
457 |
List<Integer> retailerIds = customRetailers.values().stream().map(CustomRetailer::getPartnerId).collect(Collectors.toList());
|
| 458 |
|
458 |
|
| 459 |
/* List<Integer> retailerIds = Arrays.asList(175139401,175139400,175139381,175139667,175139662,175139661,175130896,175139323,175139452);
|
459 |
/* List<Integer> retailerIds = Arrays.asList(175139494,175139676,175139769);
|
| 460 |
Map<Integer,CustomRetailer> customRetailers = retailerService.getFofoRetailers(retailerIds);*/
|
460 |
Map<Integer,CustomRetailer> customRetailers = retailerService.getFofoRetailers(retailerIds);*/
|
| 461 |
|
461 |
|
| 462 |
//partner daily investment
|
462 |
//partner daily investment
|
| 463 |
List<Loan> defaultLoans = sdCreditService.getDefaultLoan();
|
463 |
List<Loan> defaultLoans = sdCreditService.getDefaultLoan();
|
| 464 |
Map<Integer,List<Loan>> defaultLoanMap = defaultLoans.stream().collect(Collectors.groupingBy(Loan::getFofoId));
|
464 |
Map<Integer,List<Loan>> defaultLoanMap = defaultLoans.stream().collect(Collectors.groupingBy(Loan::getFofoId));
|
| Line 473... |
Line 473... |
| 473 |
|
473 |
|
| 474 |
// this month return data
|
474 |
// this month return data
|
| 475 |
YearMonth currentMonth = YearMonth.now();
|
475 |
YearMonth currentMonth = YearMonth.now();
|
| 476 |
String currentMonthStringValue = String.valueOf(currentMonth);
|
476 |
String currentMonthStringValue = String.valueOf(currentMonth);
|
| 477 |
LocalDateTime currentMonthStartDate = YearMonth.now().atDay(1).atStartOfDay();
|
477 |
LocalDateTime currentMonthStartDate = YearMonth.now().atDay(1).atStartOfDay();
|
| 478 |
LocalDateTime currentMonthEndDate = LocalDateTime.now();
|
478 |
LocalDateTime currentMonthEndDate = LocalDateTime.now().minusDays(1);
|
| 479 |
|
479 |
|
| 480 |
List<ReturnOrderInfoModel> currentMonthReturnOrderInfoModels = returnOrderInfoRepository.selectAllByBetweenDate(currentMonthStartDate, currentMonthEndDate);
|
480 |
List<ReturnOrderInfoModel> currentMonthReturnOrderInfoModels = returnOrderInfoRepository.selectAllByBetweenDate(currentMonthStartDate, currentMonthEndDate);
|
| 481 |
Map<Integer, Long> currentMonthPartnerReturnOrderInfoModelMap = currentMonthReturnOrderInfoModels.stream().collect(Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingLong(x -> Math.round(x.getRefundAmount()))));
|
481 |
Map<Integer, Long> currentMonthPartnerReturnOrderInfoModelMap = currentMonthReturnOrderInfoModels.stream().collect(Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingLong(x -> Math.round(x.getRefundAmount()))));
|
| 482 |
|
482 |
|
| 483 |
List<Order> currentMonthRtoRefundOrders = orderRepository.selectAllOrderDatesBetweenByStatus(currentMonthStartDate, currentMonthEndDate, OrderStatus.RTO_REFUNDED);
|
483 |
List<Order> currentMonthRtoRefundOrders = orderRepository.selectAllOrderDatesBetweenByStatus(currentMonthStartDate, currentMonthEndDate, OrderStatus.RTO_REFUNDED);
|
| Line 595... |
Line 595... |
| 595 |
long currentMonthReturn = currentMonthPartnerReturnOrderInfoModelMap.getOrDefault(fofoId, 0L) + currentMonthRtoRefundOrderMap.getOrDefault(fofoId, 0L);
|
595 |
long currentMonthReturn = currentMonthPartnerReturnOrderInfoModelMap.getOrDefault(fofoId, 0L) + currentMonthRtoRefundOrderMap.getOrDefault(fofoId, 0L);
|
| 596 |
|
596 |
|
| 597 |
|
597 |
|
| 598 |
Map<Integer, Double> secondaryMtd = orderRepository.selectOrderValueBetweenDatesGroupByFofoId(Arrays.asList(fofoId),
|
598 |
Map<Integer, Double> secondaryMtd = orderRepository.selectOrderValueBetweenDatesGroupByFofoId(Arrays.asList(fofoId),
|
| 599 |
Arrays.asList(OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.DELIVERY_SUCCESS, OrderStatus.ACCEPTED, OrderStatus.SUBMITTED_FOR_PROCESSING),
|
599 |
Arrays.asList(OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.DELIVERY_SUCCESS, OrderStatus.ACCEPTED, OrderStatus.SUBMITTED_FOR_PROCESSING),
|
| 600 |
startOfToday.withDayOfMonth(1), startOfToday.with(LocalTime.MAX)).stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getAmount()));
|
600 |
startOfToday.withDayOfMonth(1), startOfToday.with(LocalTime.MAX).minusDays(1)).stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getAmount()));
|
| 601 |
|
601 |
|
| 602 |
double secondaryAchievedMtd = secondaryMtd.getOrDefault(fofoId, 0.0);
|
602 |
double secondaryAchievedMtd = secondaryMtd.getOrDefault(fofoId, 0.0);
|
| 603 |
|
603 |
|
| 604 |
double currentMonthNetSecondary = secondaryAchievedMtd - currentMonthReturn;
|
604 |
double currentMonthNetSecondary = secondaryAchievedMtd - currentMonthReturn;
|
| 605 |
|
605 |
|
| Line 849... |
Line 849... |
| 849 |
//generate excel and sent to mail
|
849 |
//generate excel and sent to mail
|
| 850 |
List<List<String>> headerGroup = new ArrayList<>();
|
850 |
List<List<String>> headerGroup = new ArrayList<>();
|
| 851 |
|
851 |
|
| 852 |
List<String> headers1 = Arrays.asList(
|
852 |
List<String> headers1 = Arrays.asList(
|
| 853 |
"","","","",
|
853 |
"","","","",
|
| 854 |
"Retailer Detail", "","", "", "", "", "", "", "", "",
|
854 |
"Retailer Detail", "","", "", "", "", "", "", "", "","",
|
| 855 |
|
855 |
|
| 856 |
twoMonthAgoStringValue, "", "", "", "", "", "",
|
856 |
twoMonthAgoStringValue, "", "", "", "", "", "",
|
| 857 |
lastMonthStringValue, "", "", "", "", "", "",
|
857 |
lastMonthStringValue, "", "", "", "", "", "",
|
| 858 |
currentMonthStringValue, "", "", "", "", "", "",
|
858 |
currentMonthStringValue, "", "", "", "", "", "",
|
| 859 |
|
859 |
|
| Line 864... |
Line 864... |
| 864 |
|
864 |
|
| 865 |
);
|
865 |
);
|
| 866 |
|
866 |
|
| 867 |
List<String> headers2 = Arrays.asList(
|
867 |
List<String> headers2 = Arrays.asList(
|
| 868 |
"Assessment","Zero billing","Billing needed","Counta",
|
868 |
"Assessment","Zero billing","Billing needed","Counta",
|
| 869 |
"BM","Partner Id","Code","Area", "City", "Store Name", "Status","Category","Sales Manager", "RBM",
|
869 |
"BM","Partner Id","Link","Code","Area", "City", "Store Name", "Status","Category","Sales Manager", "RBM",
|
| 870 |
"Secondary Target", "Secondary Achieved", "Returns", "Net Secondary", "Secondary %",
|
870 |
"Secondary Target", "Secondary Achieved", "Returns", "Net Secondary", "Secondary %",
|
| 871 |
"Tertiary Sale", "Unbilled",
|
871 |
"Tertiary Sale", "Unbilled",
|
| 872 |
"Secondary Target", "Secondary Achieved", "Returns", "Net Secondary", "Secondary %",
|
872 |
"Secondary Target", "Secondary Achieved", "Returns", "Net Secondary", "Secondary %",
|
| 873 |
"Tertiary Sale", "Unbilled",
|
873 |
"Tertiary Sale", "Unbilled",
|
| 874 |
"Secondary Target", "Secondary Achieved", "Returns", "Net Secondary", "Secondary %",
|
874 |
"Secondary Target", "Secondary Achieved", "Returns", "Net Secondary", "Secondary %",
|
| Line 897... |
Line 897... |
| 897 |
BiSecondaryModel twoAgo = monthlyData.getOrDefault(YearMonth.now().minusMonths(2), new BiSecondaryModel(0,0,0,0,0,0,0));
|
897 |
BiSecondaryModel twoAgo = monthlyData.getOrDefault(YearMonth.now().minusMonths(2), new BiSecondaryModel(0,0,0,0,0,0,0));
|
| 898 |
|
898 |
|
| 899 |
List<Object> row = new ArrayList<>();
|
899 |
List<Object> row = new ArrayList<>();
|
| 900 |
row.addAll(Arrays.asList(
|
900 |
row.addAll(Arrays.asList(
|
| 901 |
assessmentMap.get(fofoId),zeroBillingMap.get(fofoId),billingNeededMap.get(fofoId),countAMap.get(fofoId),
|
901 |
assessmentMap.get(fofoId),zeroBillingMap.get(fofoId),billingNeededMap.get(fofoId),countAMap.get(fofoId),
|
| 902 |
retailer.getBmName(),fofoId , retailer.getCode(), retailer.getArea(), retailer.getCity(), retailer.getStoreName(), retailer.getStatus(),
|
902 |
retailer.getBmName(),fofoId ,"https://partners.smartdukaan.com/partnerPerformance?fofoId="+fofoId, retailer.getCode(), retailer.getArea(), retailer.getCity(), retailer.getStoreName(), retailer.getStatus(),
|
| 903 |
retailer.getCategory(), retailer.getSalesManager(), retailer.getRbm()
|
903 |
retailer.getCategory(), retailer.getSalesManager(), retailer.getRbm()
|
| 904 |
|
904 |
|
| 905 |
));
|
905 |
));
|
| 906 |
|
906 |
|
| 907 |
|
907 |
|
| Line 1020... |
Line 1020... |
| 1020 |
|
1020 |
|
| 1021 |
// Send to email
|
1021 |
// Send to email
|
| 1022 |
// ByteArrayOutputStream csvStream = FileUtil.getCSVByteStreamWithMultiHeaders(headerGroup, rows);
|
1022 |
// ByteArrayOutputStream csvStream = FileUtil.getCSVByteStreamWithMultiHeaders(headerGroup, rows);
|
| 1023 |
ByteArrayOutputStream csvStream = getExcelStreamWithMultiHeaders(headerGroup, rows);
|
1023 |
ByteArrayOutputStream csvStream = getExcelStreamWithMultiHeaders(headerGroup, rows);
|
| 1024 |
String fileName = "BI-Retailer-Monthly-Report-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".xlsx";
|
1024 |
String fileName = "BI-Retailer-Monthly-Report-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".xlsx";
|
| 1025 |
String[] sendToArray = new String[]{"ranu.rajput@smartdukaan.com","ashutosh.verma@smartdukaan.com","sm@smartdukaan.com","raj.singh@smartdukaan.com"};
|
1025 |
// String[] sendToArray = new String[]{"ranu.rajput@smartdukaan.com","ashutosh.verma@smartdukaan.com","sm@smartdukaan.com","raj.singh@smartdukaan.com"};
|
| - |
|
1026 |
String[] sendToArray = new String[]{"ranu.rajput@smartdukaan.com"};
|
| 1026 |
|
1027 |
|
| 1027 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, new String[]{}, "BI Retailer Monthly Report", "Please find attached the BI retailer secondary/tertiary monthly report.", fileName, new ByteArrayResource(csvStream.toByteArray()));
|
1028 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, new String[]{}, "BI Retailer Monthly Report", "Please find attached the BI retailer secondary/tertiary monthly report.", fileName, new ByteArrayResource(csvStream.toByteArray()));
|
| 1028 |
|
1029 |
|
| 1029 |
|
1030 |
|
| 1030 |
}
|
1031 |
}
|