Subversion Repositories SmartDukaan

Rev

Rev 34903 | Rev 34912 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34903 Rev 34911
Line 165... Line 165...
165
        System.out.println("test end");
165
        System.out.println("test end");
166
 
166
 
167
    }
167
    }
168
 
168
 
169
    public void generateBiReport() throws Exception {
169
    public void generateBiReport() throws Exception {
170
        System.out.println("bi report started");
170
        this.generateBiReportHierarchyWise();
171
        this.generateBiReportExcel();
171
        this.generateBiReportForAllPartner();
172
        System.out.println("bi report ended {-----}");
-
 
173
    }
172
    }
174
 
173
 
175
    public void createLoanForBillingByTransactionIdAndInvoiceNumber(int transactionId, double invoiceAmount, String invoiceNumber) throws Exception {
174
    public void createLoanForBillingByTransactionIdAndInvoiceNumber(int transactionId, double invoiceAmount, String invoiceNumber) throws Exception {
176
        sdCreditService.createLoanForBilling(transactionId, invoiceAmount, invoiceNumber);
175
        sdCreditService.createLoanForBilling(transactionId, invoiceAmount, invoiceNumber);
177
 
176
 
Line 453... Line 452...
453
        this.sendMailHtmlFormat(emailRecipients, emailContent.toString(), null, bcc, subject);
452
        this.sendMailHtmlFormat(emailRecipients, emailContent.toString(), null, bcc, subject);
454
 
453
 
455
        LOGGER.info("Consolidated Sales L1 feedback summary email sent.");
454
        LOGGER.info("Consolidated Sales L1 feedback summary email sent.");
456
    }
455
    }
457
 
456
 
-
 
457
    public void generateBiReportHierarchyWise() throws Exception{
-
 
458
        List<Integer> categoryIds = Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_RBM, ProfitMandiConstants.TICKET_CATEGORY_SALES,ProfitMandiConstants.TICKET_CATEGORY_ABM);
458
 
459
 
-
 
460
        for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMappingByCategoryIds(categoryIds, false).entrySet()) {
-
 
461
            String storeGuyEmail = storeGuyEntry.getKey();
-
 
462
            Set<Integer> fofoIds = storeGuyEntry.getValue();
-
 
463
            List<Integer> fofoIdList = new ArrayList<>(fofoIds);
-
 
464
            Map<Integer,CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(fofoIdList);
-
 
465
            String[] sendToArray = new String[]{storeGuyEmail};
-
 
466
            this.generateBiReportExcel(customRetailerMap,sendToArray);
-
 
467
 
-
 
468
        }
-
 
469
    }
-
 
470
 
459
    public void generateBiReportExcel() throws Exception {
471
    public void generateBiReportForAllPartner() throws Exception{
-
 
472
        Map<Integer, CustomRetailer> customRetailers = retailerService.getAllFofoRetailersInternalFalse();
-
 
473
        String[] sendToArray = new String[]{"ranu.rajput@smartdukaan.com","ashutosh.verma@smartdukaan.com","sm@smartdukaan.com","raj.singh@smartdukaan.com"};
-
 
474
        this.generateBiReportExcel(customRetailers,sendToArray);
-
 
475
    }
-
 
476
 
-
 
477
 
-
 
478
 
-
 
479
    public void generateBiReportExcel( Map<Integer,CustomRetailer> customRetailers,String[] sendToArray) throws Exception {
460
 
480
 
461
        LocalDateTime startOfToday;
481
        LocalDateTime startOfToday;
462
        LocalDateTime previousDay;
482
        LocalDateTime previousDay;
463
 
483
 
464
        if (LocalDate.now().getDayOfMonth() == 1) {
484
        if (LocalDate.now().getDayOfMonth() == 1) {
Line 470... Line 490...
470
            // Otherwise, use today
490
            // Otherwise, use today
471
            startOfToday = LocalDate.now().atStartOfDay();
491
            startOfToday = LocalDate.now().atStartOfDay();
472
            previousDay = startOfToday.with(LocalTime.MAX).minusDays(1);
492
            previousDay = startOfToday.with(LocalTime.MAX).minusDays(1);
473
        }
493
        }
474
 
494
 
475
        Map<Integer, CustomRetailer> customRetailers = retailerService.getAllFofoRetailersInternalFalse();
-
 
476
 
-
 
477
        List<Integer> retailerIds = customRetailers.values().stream()
495
        List<Integer> retailerIds = customRetailers.values().stream()
478
                .filter(retailer -> {
496
                .filter(retailer -> {
479
                    String storeCode = retailer.getCode(); // adjust method name if different
497
                    String storeCode = retailer.getCode(); // adjust method name if different
480
                    return !storeCode.equalsIgnoreCase("UPGBN640") && !storeCode.equalsIgnoreCase("HRYN039");
498
                    return !storeCode.equalsIgnoreCase("UPGBN640") && !storeCode.equalsIgnoreCase("HRYN039");
481
                })
499
                })
Line 1181... Line 1199...
1181
            ));
1199
            ));
1182
            rows.add(row);
1200
            rows.add(row);
1183
        }
1201
        }
1184
 
1202
 
1185
 
1203
 
-
 
1204
        this.sendMailToUser(headerGroup,rows,sendToArray);
-
 
1205
 
-
 
1206
    }
-
 
1207
 
-
 
1208
    private  void sendMailToUser(List<List<String>> headerGroup,List<List<?>> rows, String[] sendToArray ) throws Exception {
1186
        // Send to email
1209
        // Send to email
1187
//        ByteArrayOutputStream csvStream = FileUtil.getCSVByteStreamWithMultiHeaders(headerGroup, rows);
1210
//        ByteArrayOutputStream csvStream = FileUtil.getCSVByteStreamWithMultiHeaders(headerGroup, rows);
1188
        ByteArrayOutputStream csvStream = getExcelStreamWithMultiHeaders(headerGroup, rows);
1211
        ByteArrayOutputStream csvStream = getExcelStreamWithMultiHeaders(headerGroup, rows);
1189
        String fileName = "BI-Retailer-Monthly-Report-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".xlsx";
1212
        String fileName = "BI-Retailer-Monthly-Report-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".xlsx";
1190
        String[] sendToArray = new String[]{"ranu.rajput@smartdukaan.com","ashutosh.verma@smartdukaan.com","sm@smartdukaan.com","raj.singh@smartdukaan.com"};
-
 
1191
//        String[] sendToArray = new String[]{"ranu.rajput@smartdukaan.com"};
-
 
1192
 
-
 
1193
        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()));
1213
        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()));
1194
 
-
 
1195
 
-
 
1196
    }
1214
    }
1197
 
1215
 
-
 
1216
 
1198
    public static ByteArrayOutputStream getExcelStreamWithMultiHeaders(List<List<String>> headerGroup, List<List<?>> rows) {
1217
    public static ByteArrayOutputStream getExcelStreamWithMultiHeaders(List<List<String>> headerGroup, List<List<?>> rows) {
1199
        Workbook workbook = new XSSFWorkbook();
1218
        Workbook workbook = new XSSFWorkbook();
1200
        Sheet sheet = workbook.createSheet("BI Report");
1219
        Sheet sheet = workbook.createSheet("BI Report");
1201
        CreationHelper creationHelper = workbook.getCreationHelper();
1220
        CreationHelper creationHelper = workbook.getCreationHelper();
1202
        int rowIndex = 0;
1221
        int rowIndex = 0;