Subversion Repositories SmartDukaan

Rev

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

Rev 34738 Rev 34741
Line 446... Line 446...
446
    }
446
    }
447
 
447
 
448
 
448
 
449
    public void generateBiReportExcel() throws Exception {
449
    public void generateBiReportExcel() throws Exception {
450
 
450
 
-
 
451
        LocalDateTime startOfToday;
-
 
452
        LocalDateTime previousDay;
-
 
453
 
-
 
454
        if (LocalDate.now().getDayOfMonth() == 1) {
-
 
455
            // If today is 1st, go to yesterday (i.e., last day of previous month)
-
 
456
            startOfToday = LocalDate.now().minusDays(1).atStartOfDay();
-
 
457
            previousDay = startOfToday.with(LocalTime.MAX);
-
 
458
 
-
 
459
        } else {
-
 
460
            // Otherwise, use today
451
        LocalDateTime startOfToday = LocalDate.now().atStartOfDay();
461
            startOfToday = LocalDate.now().atStartOfDay();
-
 
462
            previousDay = startOfToday.with(LocalTime.MAX).minusDays(1);
-
 
463
        }
452
 
464
 
453
        /*Map<Integer, CustomRetailer> customRetailers = retailerService.getAllFofoRetailersInternalFalse();
465
        /*Map<Integer, CustomRetailer> customRetailers = retailerService.getAllFofoRetailersInternalFalse();
454
 
466
 
455
        List<Integer> retailerIds = customRetailers.values().stream().map(CustomRetailer::getPartnerId).collect(Collectors.toList());*/
467
        List<Integer> retailerIds = customRetailers.values().stream().map(CustomRetailer::getPartnerId).collect(Collectors.toList());*/
456
 
468
 
457
        List<Integer> retailerIds = Arrays.asList(175138886,175139660,175139584,175139235,175138843,175139356,175139662,168094765,175139684,175135707,175139335,175139270,175139305,175139262,175139241,175139560,175139732,175138871,175138875,175139323,175139564,166900459,175139261,175139337,175138836,175139551,175139498,175139685,175127215,175139712,175138969,175139408,175139711,175136389,175139019,175139589,175139424,175139094,175138908,175139180,175139648,175138951,175139220,175139508,175138854,175139726,175138897,175139671,175139721,175139681);
469
        List<Integer> retailerIds = Arrays.asList(175139400, 175139727, 175138674, 175139476, 175139409, 175139260, 175139650, 175139742, 175139715, 175139154, 175139135, 175139550, 175139733, 175139722, 175138842, 175139309, 175138859, 175139438, 175139718, 175139320, 175139047, 175138408, 175139590, 175139494, 175139670, 175139730, 175139295, 175139188, 175139487, 175139422, 175139488, 175139279, 175139724, 175139687, 175139161, 175138934, 175139013, 175139633, 175139383, 175139432, 175139089, 175139561, 175135227, 175139412, 175139018, 175139088, 175139616, 175139294, 175139649, 175139129, 175139366, 175139699, 175139557, 175138174, 175139620, 175139514, 175139079, 175139521, 175139015, 175138982, 175139683, 175139676, 175139562, 175139675, 175138989, 175139114, 175139526, 175139729, 175139394, 175138864, 175135923, 175139415, 175139459, 175139395, 175139731, 175139401, 175139481, 175139623, 175139563, 175139692, 175139345);
458
        Map<Integer,CustomRetailer> customRetailers = retailerService.getFofoRetailers(retailerIds);
470
        Map<Integer,CustomRetailer> customRetailers = retailerService.getFofoRetailers(retailerIds);
459
 
471
 
460
        //partner daily investment
472
        //partner daily investment
461
        List<Loan> defaultLoans = sdCreditService.getDefaultLoans();
473
        List<Loan> defaultLoans = sdCreditService.getDefaultLoans();
462
        Map<Integer,List<Loan>> defaultLoanMap = defaultLoans.stream().collect(Collectors.groupingBy(Loan::getFofoId));
474
        Map<Integer,List<Loan>> defaultLoanMap = defaultLoans.stream().collect(Collectors.groupingBy(Loan::getFofoId));
463
 
475
 
464
        Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = new HashMap<>();
476
        Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = new HashMap<>();
465
        List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
477
        List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
466
                .selectAll(new ArrayList<>(retailerIds), LocalDate.now().minusDays(1));
478
                .selectAll(new ArrayList<>(retailerIds), previousDay.toLocalDate());
467
        if (!partnerDailyInvestments.isEmpty()) {
479
        if (!partnerDailyInvestments.isEmpty()) {
468
            partnerDailyInvestmentMap = partnerDailyInvestments.stream()
480
            partnerDailyInvestmentMap = partnerDailyInvestments.stream()
469
                    .collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
481
                    .collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
470
        }
482
        }
471
 
483
 
-
 
484
 
-
 
485
 
472
    //  this month return data
486
    //  this month return data
-
 
487
 
-
 
488
        YearMonth currentMonth;
-
 
489
        LocalDateTime currentMonthStartDate;
-
 
490
        LocalDateTime currentMonthEndDate;
-
 
491
 
-
 
492
        if (LocalDate.now().getDayOfMonth() == 1) {
-
 
493
            // If today is the 1st, use previous month
-
 
494
            currentMonth = YearMonth.now().minusMonths(1);
-
 
495
            currentMonthStartDate = currentMonth.atDay(1).atStartOfDay();
-
 
496
            currentMonthEndDate = currentMonth.atEndOfMonth().atTime(23, 59, 59);
-
 
497
        } else {
-
 
498
            // Otherwise, use this month up to yesterday
473
        YearMonth currentMonth = YearMonth.now();
499
            currentMonth = YearMonth.now();
-
 
500
            currentMonthStartDate = currentMonth.atDay(1).atStartOfDay();
-
 
501
            currentMonthEndDate = LocalDate.now().minusDays(1).atTime(23, 59, 59);
-
 
502
        }
-
 
503
 
474
        String currentMonthStringValue = String.valueOf(currentMonth);
504
        String currentMonthStringValue = String.valueOf(currentMonth);
475
        LocalDateTime currentMonthStartDate = YearMonth.now().atDay(1).atStartOfDay();
-
 
476
        LocalDateTime currentMonthEndDate = LocalDateTime.now().minusDays(1).toLocalDate().atTime(23, 59, 59);
-
 
477
 
505
 
478
        List<ReturnOrderInfoModel> currentMonthReturnOrderInfoModels = returnOrderInfoRepository.selectAllByBetweenDate(currentMonthStartDate, currentMonthEndDate);
506
        List<ReturnOrderInfoModel> currentMonthReturnOrderInfoModels = returnOrderInfoRepository.selectAllByBetweenDate(currentMonthStartDate, currentMonthEndDate);
479
        Map<Integer, Long> currentMonthPartnerReturnOrderInfoModelMap = currentMonthReturnOrderInfoModels.stream().collect(Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingLong(x -> Math.round(x.getRefundAmount()))));
507
        Map<Integer, Long> currentMonthPartnerReturnOrderInfoModelMap = currentMonthReturnOrderInfoModels.stream().collect(Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingLong(x -> Math.round(x.getRefundAmount()))));
480
 
508
 
481
        List<Order> currentMonthRtoRefundOrders = orderRepository.selectAllOrderDatesBetweenByStatus(currentMonthStartDate, currentMonthEndDate, OrderStatus.RTO_REFUNDED);
509
        List<Order> currentMonthRtoRefundOrders = orderRepository.selectAllOrderDatesBetweenByStatus(currentMonthStartDate, currentMonthEndDate, OrderStatus.RTO_REFUNDED);
482
        Map<Integer, Long> currentMonthRtoRefundOrderMap = currentMonthRtoRefundOrders.stream().collect(Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingLong(x -> Math.round(x.getTotalAmount()))));
510
        Map<Integer, Long> currentMonthRtoRefundOrderMap = currentMonthRtoRefundOrders.stream().collect(Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingLong(x -> Math.round(x.getTotalAmount()))));
483
 
511
 
484
//  last month return data
512
    //  last month return data
485
        YearMonth lastMonth = YearMonth.now().minusMonths(1);
513
        YearMonth lastMonth = currentMonth.minusMonths(1);
486
        String lastMonthStringValue = String.valueOf(lastMonth);
514
        String lastMonthStringValue = String.valueOf(lastMonth);
487
        LocalDateTime lastMontStartDate = lastMonth.atDay(1).atStartOfDay();
515
        LocalDateTime lastMontStartDate = lastMonth.atDay(1).atStartOfDay();
488
        LocalDateTime lastMonthEndDate = lastMonth.atEndOfMonth().atTime(23, 59, 59);
516
        LocalDateTime lastMonthEndDate = lastMonth.atEndOfMonth().atTime(23, 59, 59);
489
 
517
 
490
        List<ReturnOrderInfoModel> lastMonthReturnOrderInfoModels = returnOrderInfoRepository.selectAllByBetweenDate(lastMontStartDate, lastMonthEndDate);
518
        List<ReturnOrderInfoModel> lastMonthReturnOrderInfoModels = returnOrderInfoRepository.selectAllByBetweenDate(lastMontStartDate, lastMonthEndDate);
Line 492... Line 520...
492
 
520
 
493
        List<Order> lastMonthRtoRefundOrders = orderRepository.selectAllOrderDatesBetweenByStatus(lastMontStartDate, lastMonthEndDate, OrderStatus.RTO_REFUNDED);
521
        List<Order> lastMonthRtoRefundOrders = orderRepository.selectAllOrderDatesBetweenByStatus(lastMontStartDate, lastMonthEndDate, OrderStatus.RTO_REFUNDED);
494
        Map<Integer, Long> lastMonthRtoRefundOrderMap = lastMonthRtoRefundOrders.stream().collect(Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingLong(x -> Math.round(x.getTotalAmount()))));
522
        Map<Integer, Long> lastMonthRtoRefundOrderMap = lastMonthRtoRefundOrders.stream().collect(Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingLong(x -> Math.round(x.getTotalAmount()))));
495
 
523
 
496
 
524
 
497
//  twoMonthsAgo return data
525
    //  twoMonthsAgo return data
498
        YearMonth twoMonthsAgo = YearMonth.now().minusMonths(2);
526
        YearMonth twoMonthsAgo = currentMonth.minusMonths(2);
499
        String twoMonthAgoStringValue = String.valueOf(twoMonthsAgo);
527
        String twoMonthAgoStringValue = String.valueOf(twoMonthsAgo);
500
        LocalDateTime twoMonthsAgoStartDate = twoMonthsAgo.atDay(1).atStartOfDay();
528
        LocalDateTime twoMonthsAgoStartDate = twoMonthsAgo.atDay(1).atStartOfDay();
501
        LocalDateTime twoMonthsAgoEndDate = twoMonthsAgo.atEndOfMonth().atTime(23, 59, 59);
529
        LocalDateTime twoMonthsAgoEndDate = twoMonthsAgo.atEndOfMonth().atTime(23, 59, 59);
502
 
530
 
503
        List<ReturnOrderInfoModel> twoMonthAgoReturnOrderInfoModels = returnOrderInfoRepository.selectAllByBetweenDate(twoMonthsAgoStartDate, twoMonthsAgoEndDate);
531
        List<ReturnOrderInfoModel> twoMonthAgoReturnOrderInfoModels = returnOrderInfoRepository.selectAllByBetweenDate(twoMonthsAgoStartDate, twoMonthsAgoEndDate);
Line 556... Line 584...
556
                managerName = bmName;
584
                managerName = bmName;
557
            }
585
            }
558
 
586
 
559
            AST ast = astRepository.selectById(customRetailers.get(fofoId).getAstId());
587
            AST ast = astRepository.selectById(customRetailers.get(fofoId).getAstId());
560
 
588
 
561
            PartnerType partnerTypeThisMonth = partnerTypeChangeService.getTypeOnMonth(fofoId, YearMonth.now());
589
            PartnerType partnerTypeThisMonth = partnerTypeChangeService.getTypeOnMonth(fofoId, currentMonth);
562
 
590
 
563
//            generate retaile detail
591
//            generate retaile detail
564
 
592
 
565
            BIRetailerModel biRetailerModel = new BIRetailerModel();
593
            BIRetailerModel biRetailerModel = new BIRetailerModel();
566
            biRetailerModel.setBmName(bmName);
594
            biRetailerModel.setBmName(bmName);
Line 592... Line 620...
592
            List<PartnerWiseActivatedNotBilledTotal> partnerWiseActivatedNotBilledMonthlyTotals = activatedImeiRepository.getTotalMonthlyActivatedNotBilled(fofoId,twoMonthsAgoStartDate);
620
            List<PartnerWiseActivatedNotBilledTotal> partnerWiseActivatedNotBilledMonthlyTotals = activatedImeiRepository.getTotalMonthlyActivatedNotBilled(fofoId,twoMonthsAgoStartDate);
593
            Map<YearMonth , PartnerWiseActivatedNotBilledTotal> partnerWiseActivatedNotBilledTotalMap = partnerWiseActivatedNotBilledMonthlyTotals.stream().collect(Collectors.toMap(x-> YearMonth.parse(x.getYearMonth()),x->x));
621
            Map<YearMonth , PartnerWiseActivatedNotBilledTotal> partnerWiseActivatedNotBilledTotalMap = partnerWiseActivatedNotBilledMonthlyTotals.stream().collect(Collectors.toMap(x-> YearMonth.parse(x.getYearMonth()),x->x));
594
 
622
 
595
//            this month secondary target
623
//            this month secondary target
596
 
624
 
597
            double currentSecondaryTarget =  monthlyTargetRepository.selectByDateAndFofoId(YearMonth.now(), fofoId) != null ? monthlyTargetRepository.selectByDateAndFofoId(YearMonth.now(), fofoId).getPurchaseTarget() : 0;
625
            double currentSecondaryTarget =  monthlyTargetRepository.selectByDateAndFofoId(currentMonth, fofoId) != null ? monthlyTargetRepository.selectByDateAndFofoId(currentMonth, fofoId).getPurchaseTarget() : 0;
598
 
626
 
599
 
627
 
600
            long currentMonthReturn = currentMonthPartnerReturnOrderInfoModelMap.getOrDefault(fofoId, 0L) + currentMonthRtoRefundOrderMap.getOrDefault(fofoId, 0L);
628
            long currentMonthReturn = currentMonthPartnerReturnOrderInfoModelMap.getOrDefault(fofoId, 0L) + currentMonthRtoRefundOrderMap.getOrDefault(fofoId, 0L);
601
 
629
 
602
 
630
 
603
            Map<Integer, Double> secondaryMtd = orderRepository.selectOrderValueBetweenBillingDatesGroupByFofoId(Arrays.asList(fofoId),
631
            Map<Integer, Double> secondaryMtd = orderRepository.selectOrderValueBetweenBillingDatesGroupByFofoId(Arrays.asList(fofoId),
604
                    startOfToday.withDayOfMonth(1), startOfToday.with(LocalTime.MAX).minusDays(1)).stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getAmount()));
632
                    startOfToday.withDayOfMonth(1), previousDay).stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getAmount()));
605
 
633
 
606
            double secondaryAchievedMtd = secondaryMtd.getOrDefault(fofoId, 0.0);
634
            double secondaryAchievedMtd = secondaryMtd.getOrDefault(fofoId, 0.0);
607
 
635
 
608
            double currentMonthNetSecondary = secondaryAchievedMtd - currentMonthReturn;
636
            double currentMonthNetSecondary = secondaryAchievedMtd - currentMonthReturn;
609
 
637
 
Line 613... Line 641...
613
 
641
 
614
//          this month tertiary----------
642
//          this month tertiary----------
615
 
643
 
616
            LocalDateTime now = LocalDateTime.now();
644
            LocalDateTime now = LocalDateTime.now();
617
            double todaySale = fofoOrderItemRepository.selectSumMopGroupByRetailer(startOfToday, now, fofoId, false).get(fofoId);
645
            double todaySale = fofoOrderItemRepository.selectSumMopGroupByRetailer(startOfToday, now, fofoId, false).get(fofoId);
618
            double mtdSaleTillYesterDay = fofoOrderItemRepository.selectSumMopGroupByRetailer(startOfToday.withDayOfMonth(1), startOfToday, fofoId, false).get(fofoId);
646
            double mtdSaleTillYesterDay = fofoOrderItemRepository.selectSumMopGroupByRetailer(startOfToday.withDayOfMonth(1), previousDay, fofoId, false).get(fofoId);
619
            double mtdSale = mtdSaleTillYesterDay;
647
            double mtdSale = mtdSaleTillYesterDay;
620
 
648
 
621
 
649
 
622
//            last month secondary target
650
//            last month secondary target
623
 
651
 
Line 722... Line 750...
722
            fofoTotalMtdTertiaryMap.put(fofoId,totalMtdTertiaryAmount);
750
            fofoTotalMtdTertiaryMap.put(fofoId,totalMtdTertiaryAmount);
723
 
751
 
724
            LOGGER.info("fofoBrandMtdTertiaryMap- {}",fofoBrandMtdTertiaryMap);
752
            LOGGER.info("fofoBrandMtdTertiaryMap- {}",fofoBrandMtdTertiaryMap);
725
 
753
 
726
 
754
 
727
            List<BrandWiseModel> brandWiseMtdSecondary = orderRepository.selectAllBilledByCategoryOrderGroupByBrandFofoId(fofoId, currentMonthStartDate,Arrays.asList(10006,10009,10010));
755
            List<BrandWiseModel> brandWiseMtdSecondary = orderRepository.selectAllBilledByCategoryOrderGroupByBrandFofoId(fofoId, currentMonthStartDate,Arrays.asList(10006,10001));
728
            Map<String,Long> brandWiseMtdSecondaryMap = brandWiseMtdSecondary.stream().collect(Collectors.toMap(BrandWiseModel::getBrand,BrandWiseModel::getAmount));
756
            Map<String,Long> brandWiseMtdSecondaryMap = brandWiseMtdSecondary.stream().collect(Collectors.toMap(BrandWiseModel::getBrand,BrandWiseModel::getAmount));
729
 
757
 
730
            //retrunInfo
758
            //retrunInfo
731
            List<BrandWiseReturnInfo> brandWiseReturnInfos = returnOrderInfoRepository.selectAllBrandWiseByBetweenDate(currentMonthStartDate,currentMonthEndDate.plusDays(1),fofoId);
759
            List<BrandWiseReturnInfo> brandWiseReturnInfos = returnOrderInfoRepository.selectAllBrandWiseByBetweenDate(currentMonthStartDate,currentMonthEndDate.plusDays(1),fofoId);
732
            Map<String,Double> brandWiseReturnInfoMap = brandWiseReturnInfos.stream().collect(Collectors.toMap(BrandWiseReturnInfo::getBrand, x->x.getReturnAmount()));
760
            Map<String,Double> brandWiseReturnInfoMap = brandWiseReturnInfos.stream().collect(Collectors.toMap(BrandWiseReturnInfo::getBrand, x->x.getReturnAmount()));
Line 795... Line 823...
795
 
823
 
796
            float poValue = partnerDailyInvestmentMap.get(fofoId) != null ?  partnerDailyInvestmentMap.get(fofoId).getUnbilledAmount() : 0f;
824
            float poValue = partnerDailyInvestmentMap.get(fofoId) != null ?  partnerDailyInvestmentMap.get(fofoId).getUnbilledAmount() : 0f;
797
 
825
 
798
            float poAndBilledValue = (float) (currentMonthNetSecondary + poValue);
826
            float poAndBilledValue = (float) (currentMonthNetSecondary + poValue);
799
 
827
 
800
            double todayRequiredDrr = rbmTargetService.calculateFofoIdTodayTarget(fofoId, currentMonthNetSecondary,LocalDate.now());
828
            double todayRequiredDrr = rbmTargetService.calculateFofoIdTodayTarget(fofoId, currentMonthNetSecondary,startOfToday.toLocalDate());
801
 
829
 
802
            double monthDay1Drr = rbmTargetService.calculateFofoIdTodayTarget(fofoId,0d,YearMonth.now().atDay(1));
830
            double monthDay1Drr = rbmTargetService.calculateFofoIdTodayTarget(fofoId,0d,currentMonth.atDay(1));
803
 
831
 
804
 
832
 
805
            double gotDrrPercent = (todayRequiredDrr / monthDay1Drr) * 100;
833
            double gotDrrPercent = (todayRequiredDrr / monthDay1Drr) * 100;
806
 
834
 
807
            long drrPercentDisplay = Math.round(Math.abs(gotDrrPercent));
835
            long drrPercentDisplay = Math.round(Math.abs(gotDrrPercent));
Line 936... Line 964...
936
            LocalDateTime walletCreationDate = userWalletHistoryRepository.selectFirstCreatedDate(fofoId);
964
            LocalDateTime walletCreationDate = userWalletHistoryRepository.selectFirstCreatedDate(fofoId);
937
            BIRetailerModel retailer = entry.getValue();
965
            BIRetailerModel retailer = entry.getValue();
938
 
966
 
939
            Map<YearMonth, BiSecondaryModel> monthlyData = allRetailerMonthlyData.get(fofoId);
967
            Map<YearMonth, BiSecondaryModel> monthlyData = allRetailerMonthlyData.get(fofoId);
940
 
968
 
941
            BiSecondaryModel current = monthlyData.getOrDefault(YearMonth.now(), new BiSecondaryModel(0,0,0,0,0,0,0));
969
            BiSecondaryModel current = monthlyData.getOrDefault(currentMonth, new BiSecondaryModel(0,0,0,0,0,0,0));
942
            BiSecondaryModel last = monthlyData.getOrDefault(YearMonth.now().minusMonths(1), new BiSecondaryModel(0,0,0,0,0,0,0));
970
            BiSecondaryModel last = monthlyData.getOrDefault(currentMonth.minusMonths(1), new BiSecondaryModel(0,0,0,0,0,0,0));
943
            BiSecondaryModel twoAgo = monthlyData.getOrDefault(YearMonth.now().minusMonths(2), new BiSecondaryModel(0,0,0,0,0,0,0));
971
            BiSecondaryModel twoAgo = monthlyData.getOrDefault(currentMonth.minusMonths(2), new BiSecondaryModel(0,0,0,0,0,0,0));
944
 
972
 
945
            List<Object> row = new ArrayList<>();
973
            List<Object> row = new ArrayList<>();
946
            row.addAll(Arrays.asList(
974
            row.addAll(Arrays.asList(
947
                    assessmentMap.get(fofoId),zeroBillingMap.get(fofoId),billingNeededMap.get(fofoId),countAMap.get(fofoId),
975
                    assessmentMap.get(fofoId),zeroBillingMap.get(fofoId),billingNeededMap.get(fofoId),countAMap.get(fofoId),
948
                    retailer.getBmName(),fofoId ,"https://partners.smartdukaan.com/partnerPerformance?fofoId="+fofoId,walletCreationDate,user.getCreateTimestamp(), retailer.getCode(), retailer.getArea(), retailer.getCity(),  retailer.getStoreName(), retailer.getStatus(),
976
                    retailer.getBmName(),fofoId ,"https://partners.smartdukaan.com/partnerPerformance?fofoId="+fofoId,walletCreationDate,user.getCreateTimestamp(), retailer.getCode(), retailer.getArea(), retailer.getCity(),  retailer.getStoreName(), retailer.getStatus(),