Subversion Repositories SmartDukaan

Rev

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

Rev 34700 Rev 34701
Line 450... Line 450...
450
 
450
 
451
    public void generateBiReportExcel() throws Exception {
451
    public void generateBiReportExcel() throws Exception {
452
 
452
 
453
        LocalDateTime startOfToday = LocalDate.now().atStartOfDay();
453
        LocalDateTime startOfToday = LocalDate.now().atStartOfDay();
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(175139494,175139676,175139769);
459
        List<Integer> retailerIds = Arrays.asList(175139615,175139391,175135707);
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));
465
 
465
 
Line 594... Line 594...
594
 
594
 
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),
600
                    startOfToday.withDayOfMonth(1), startOfToday.with(LocalTime.MAX).minusDays(1)).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
 
606
            double currentMonthSecondaryPercent = currentSecondaryTarget == 0 ? 0.0 : (secondaryAchievedMtd / currentSecondaryTarget) * 100;
606
            double currentMonthSecondaryPercent = currentSecondaryTarget == 0 ? 0.0 : Math.round(Math.abs((secondaryAchievedMtd / currentSecondaryTarget) * 100));
607
 
607
 
608
            double currentMonthUnbilled = partnerWiseActivatedNotBilledTotalMap.get(currentMonth) != null ? partnerWiseActivatedNotBilledTotalMap.get(currentMonth).getTotalUnbilledAmount() : 0d;
608
            double currentMonthUnbilled = partnerWiseActivatedNotBilledTotalMap.get(currentMonth) != null ? partnerWiseActivatedNotBilledTotalMap.get(currentMonth).getTotalUnbilledAmount() : 0d;
609
 
609
 
610
//          this month tertiary----------
610
//          this month tertiary----------
611
 
611
 
Line 627... Line 627...
627
 
627
 
628
            double lastMonthSecondaryAchieved = lastMonthSecondary.getOrDefault(fofoId, 0.0);
628
            double lastMonthSecondaryAchieved = lastMonthSecondary.getOrDefault(fofoId, 0.0);
629
 
629
 
630
            double lastMonthNetSecondary = lastMonthSecondaryAchieved - lastMonthReturn;
630
            double lastMonthNetSecondary = lastMonthSecondaryAchieved - lastMonthReturn;
631
 
631
 
632
            double lastMonthSecondaryPercent = lastMonthSecondaryTarget == 0 ? 0.0 : (lastMonthSecondaryAchieved / lastMonthSecondaryTarget) * 100;
632
            double lastMonthSecondaryPercent = lastMonthSecondaryTarget == 0 ? 0.0 : Math.round(Math.abs((lastMonthSecondaryAchieved / lastMonthSecondaryTarget) * 100));
633
 
633
 
634
            double lastMonthUnbilled = partnerWiseActivatedNotBilledTotalMap.get(lastMonth) != null ? partnerWiseActivatedNotBilledTotalMap.get(lastMonth).getTotalUnbilledAmount() : 0d;
634
            double lastMonthUnbilled = partnerWiseActivatedNotBilledTotalMap.get(lastMonth) != null ? partnerWiseActivatedNotBilledTotalMap.get(lastMonth).getTotalUnbilledAmount() : 0d;
635
 
635
 
636
//           last month tertiary
636
//           last month tertiary
637
            Double lastMonthSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
637
            Double lastMonthSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
Line 650... Line 650...
650
 
650
 
651
            double twoMonthAgoSecondaryAchieved = twoMonthAgoSecondary.getOrDefault(fofoId, 0.0);
651
            double twoMonthAgoSecondaryAchieved = twoMonthAgoSecondary.getOrDefault(fofoId, 0.0);
652
 
652
 
653
            double twoMonthAgoNetSecondary = twoMonthAgoSecondaryAchieved - twoMonthAgoReturn;
653
            double twoMonthAgoNetSecondary = twoMonthAgoSecondaryAchieved - twoMonthAgoReturn;
654
 
654
 
655
            double twoMonthAgoSecondaryPercent = twoMonthAgoSecondaryTarget == 0 ? 0.0 : (twoMonthAgoSecondaryAchieved / twoMonthAgoSecondaryTarget) * 100;
655
            double twoMonthAgoSecondaryPercent = twoMonthAgoSecondaryTarget == 0 ? 0.0 : Math.round(Math.abs((twoMonthAgoSecondaryAchieved / twoMonthAgoSecondaryTarget) * 100));
656
 
656
 
657
            double twoMonthAgoUnbilled = partnerWiseActivatedNotBilledTotalMap.get(twoMonthsAgo) != null ? partnerWiseActivatedNotBilledTotalMap.get(twoMonthsAgo).getTotalUnbilledAmount() : 0d;
657
            double twoMonthAgoUnbilled = partnerWiseActivatedNotBilledTotalMap.get(twoMonthsAgo) != null ? partnerWiseActivatedNotBilledTotalMap.get(twoMonthsAgo).getTotalUnbilledAmount() : 0d;
658
 
658
 
659
//          second Month Tertiary
659
//          second Month Tertiary
660
            double twoMonthAgoSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
660
            double twoMonthAgoSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
Line 763... Line 763...
763
            double monthDay1Drr = rbmTargetService.calculateFofoIdTodayTarget(fofoId,0d,YearMonth.now().atDay(1));
763
            double monthDay1Drr = rbmTargetService.calculateFofoIdTodayTarget(fofoId,0d,YearMonth.now().atDay(1));
764
 
764
 
765
 
765
 
766
            double gotDrrPercent = (todayRequiredDrr / monthDay1Drr) * 100;
766
            double gotDrrPercent = (todayRequiredDrr / monthDay1Drr) * 100;
767
 
767
 
-
 
768
            long drrPercentDisplay = Math.round(Math.abs(gotDrrPercent));
-
 
769
 
-
 
770
 
768
            int orderId = orderRepository.getLastOrderByFofoId(fofoId);
771
            int orderId = orderRepository.getLastOrderByFofoId(fofoId);
769
 
772
 
770
            // Determine alert level
773
            // Determine alert level
771
            String alertLevel = "-";
774
            String alertLevel = "-";
772
            int lastPurchaseDays = 0;
775
            int lastPurchaseDays = 0;
Line 801... Line 804...
801
            fofoInvestmentModel.setPoAndBilled(poAndBilledValue);
804
            fofoInvestmentModel.setPoAndBilled(poAndBilledValue);
802
            fofoInvestmentModel.setAgreedInvestment(agreedInvestment);
805
            fofoInvestmentModel.setAgreedInvestment(agreedInvestment);
803
            fofoInvestmentModel.setWallet(partnerDailyInvestmentMap.get(fofoId) != null ? partnerDailyInvestmentMap.get(fofoId).getWalletAmount() : 0);
806
            fofoInvestmentModel.setWallet(partnerDailyInvestmentMap.get(fofoId) != null ? partnerDailyInvestmentMap.get(fofoId).getWalletAmount() : 0);
804
            fofoInvestmentModel.setMonthBeginingDrr(monthDay1Drr);
807
            fofoInvestmentModel.setMonthBeginingDrr(monthDay1Drr);
805
            fofoInvestmentModel.setRequiredDrr(todayRequiredDrr);
808
            fofoInvestmentModel.setRequiredDrr(todayRequiredDrr);
806
            fofoInvestmentModel.setDrrPercent(gotDrrPercent);
809
            fofoInvestmentModel.setDrrPercent(drrPercentDisplay);
807
            fofoInvestmentModel.setLastBillingDone(lastPurchaseDays);
810
            fofoInvestmentModel.setLastBillingDone(lastPurchaseDays);
808
            fofoInvestmentModel.setSlab(alertLevel);
811
            fofoInvestmentModel.setSlab(alertLevel);
809
 
812
 
810
            biInvestmentModelMap.put(fofoId, fofoInvestmentModel);
813
            biInvestmentModelMap.put(fofoId, fofoInvestmentModel);
811
                String assessment = "";
814
                String assessment = "";
Line 825... Line 828...
825
                    zeroBilling = "-";
828
                    zeroBilling = "-";
826
                }
829
                }
827
                zeroBillingMap.put(fofoId,zeroBilling);
830
                zeroBillingMap.put(fofoId,zeroBilling);
828
 
831
 
829
                float billingNeeded = 0f;
832
                float billingNeeded = 0f;
830
                if(gotDrrPercent >= 110 ){
833
                if(drrPercentDisplay >= 110 ){
831
                    billingNeeded = (float) todayRequiredDrr;
834
                    billingNeeded = (float) todayRequiredDrr;
832
                }else {
835
                }else {
833
                    billingNeeded = 0f;
836
                    billingNeeded = 0f;
834
                }
837
                }
835
                billingNeededMap.put(fofoId,billingNeeded);
838
                billingNeededMap.put(fofoId,billingNeeded);
836
 
839
 
837
                int counta = 0;
840
                int counta = 0;
838
                if(defaultLoanAmount > 0 || investmentLevel <= 75 || currentMonthNetSecondary <= 100000 || gotDrrPercent >= 110 ){
841
                if(defaultLoanAmount > 0 || investmentLevel <= 75 || currentMonthNetSecondary <= 100000 || drrPercentDisplay >= 110 ){
839
                    counta = 1;
842
                    counta = 1;
840
                }else {
843
                }else {
841
                    counta = 0;
844
                    counta = 0;
842
                }
845
                }
843
                countAMap.put(fofoId,counta);
846
                countAMap.put(fofoId,counta);
Line 1020... Line 1023...
1020
 
1023
 
1021
        // Send to email
1024
        // Send to email
1022
//        ByteArrayOutputStream csvStream = FileUtil.getCSVByteStreamWithMultiHeaders(headerGroup, rows);
1025
//        ByteArrayOutputStream csvStream = FileUtil.getCSVByteStreamWithMultiHeaders(headerGroup, rows);
1023
        ByteArrayOutputStream csvStream = getExcelStreamWithMultiHeaders(headerGroup, rows);
1026
        ByteArrayOutputStream csvStream = getExcelStreamWithMultiHeaders(headerGroup, rows);
1024
        String fileName = "BI-Retailer-Monthly-Report-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".xlsx";
1027
        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"};
1028
//        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"};
1029
        String[] sendToArray = new String[]{"ranu.rajput@smartdukaan.com"};
1027
 
1030
 
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()));
1031
        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()));
1029
 
1032
 
1030
 
1033
 
1031
    }
1034
    }