Subversion Repositories SmartDukaan

Rev

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

Rev 34504 Rev 34510
Line 1029... Line 1029...
1029
    PurSaleService purSaleService;
1029
    PurSaleService purSaleService;
1030
 
1030
 
1031
    @Autowired
1031
    @Autowired
1032
    CatalogRepository catalogRepository;
1032
    CatalogRepository catalogRepository;
1033
 
1033
 
1034
    private void reverseOppoPayout() throws Exception {
1034
    private void rolloutOppoPayout() throws Exception {
1035
        //List<Integer> schemeIds = Arrays.asList(5540, 5542, 5544,5918, 5919, 5920, 5921, 5922);
1035
        //List<Integer> schemeIds = Arrays.asList(5540, 5542, 5544,5918, 5919, 5920, 5921, 5922);
1036
        List<Integer> schemeIds = Arrays.asList(5540, 5542, 5544, 5545, 5550, 5555, 5556, 5557, 5564, 5565, 5566, 5567, 5569, 5570, 5582, 5590, 5592, 5593, 5594,
1036
        List<Integer> schemeIds = Arrays.asList(5540, 5542, 5544, 5545, 5550, 5555, 5556, 5557, 5564, 5565, 5566, 5567, 5569, 5570, 5582, 5590, 5592, 5593, 5594,
1037
                5595, 5598, 5602, 5604, 5605, 5606, 5607, 5608, 5611, 5618, 5620, 5621, 5622, 5623, 5624, 5625, 5626, 5629, 5631,
1037
                5595, 5598, 5602, 5604, 5605, 5606, 5607, 5608, 5611, 5618, 5620, 5621, 5622, 5623, 5624, 5625, 5626, 5629, 5631,
1038
                5633, 5634, 5635, 5637, 5644, 5649, 5655, 5659, 5662, 5668, 5672, 5674, 5679, 5683, 5684, 5685, 5688, 5689, 5690,
1038
                5633, 5634, 5635, 5637, 5644, 5649, 5655, 5659, 5662, 5668, 5672, 5674, 5679, 5683, 5684, 5685, 5688, 5689, 5690,
1039
                5692, 5694, 5697, 5699, 5700, 5706, 5718, 5729, 5730, 5754, 5756, 5758, 5759, 5761, 5762, 5766, 5769, 5771, 5772,
1039
                5692, 5694, 5697, 5699, 5700, 5706, 5718, 5729, 5730, 5754, 5756, 5758, 5759, 5761, 5762, 5766, 5769, 5771, 5772,
Line 1053... Line 1053...
1053
                6093, 6094, 6095, 6098, 6102);
1053
                6093, 6094, 6095, 6098, 6102);
1054
        Map<Integer, List<SchemeInOut>> inventoryItemSiosMap = schemeInOutRepository.selectBySchemeIds(new HashSet<>(schemeIds)).stream().collect(Collectors.groupingBy(x -> x.getInventoryItemId()));
1054
        Map<Integer, List<SchemeInOut>> inventoryItemSiosMap = schemeInOutRepository.selectBySchemeIds(new HashSet<>(schemeIds)).stream().collect(Collectors.groupingBy(x -> x.getInventoryItemId()));
1055
        Map<Integer, InventoryItem> inventoryItemMap = inventoryItemRepository.selectByIds(inventoryItemSiosMap.keySet()).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
1055
        Map<Integer, InventoryItem> inventoryItemMap = inventoryItemRepository.selectByIds(inventoryItemSiosMap.keySet()).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
1056
        Set<Integer> itemIds = itemRepository.selectAllByBrand("Oppo", 10006).stream().map(x -> x.getId()).collect(toSet());
1056
        Set<Integer> itemIds = itemRepository.selectAllByBrand("Oppo", 10006).stream().map(x -> x.getId()).collect(toSet());
1057
        List<InventoryItem> filteredInventoryItems = inventoryItemMap.values().stream().filter(x -> itemIds.contains(x.getItemId())).collect(Collectors.toList());
1057
        List<InventoryItem> filteredInventoryItems = inventoryItemMap.values().stream().filter(x -> itemIds.contains(x.getItemId())).collect(Collectors.toList());
-
 
1058
 
-
 
1059
        Map<Integer, List<InventoryItem>> purchaseInventoryItemsMap = filteredInventoryItems.stream().filter(x -> x.getCreateTimestamp().isAfter(YearMonth.now().atDay(1).atStartOfDay())).collect(Collectors.groupingBy(x -> x.getPurchaseId()));
-
 
1060
        List<Purchase> purchases = purchaseRepository.selectAllByIds(new ArrayList<>(purchaseInventoryItemsMap.keySet()));
-
 
1061
        for (Purchase purchase : purchases) {
-
 
1062
            String invoiceNumber = purchase.getPurchaseReference();
-
 
1063
            LocalDateTime billingTime = orderRepository.selectByInvoiceNumber(invoiceNumber).get(0).getBillingTimestamp();
-
 
1064
            if (billingTime.isAfter(YearMonth.now().atDay(1).atStartOfDay())) {
-
 
1065
                schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
-
 
1066
            }
-
 
1067
        }
-
 
1068
 
1058
        for (InventoryItem filteredInventoryItem : filteredInventoryItems) {
1069
        for (InventoryItem filteredInventoryItem : filteredInventoryItems) {
1059
            //System.out.println("Serial Number is - " + filteredInventoryItem.getSerialNumber());
1070
            //System.out.println("Serial Number is - " + filteredInventoryItem.getSerialNumber());
1060
            List<ScanRecord> scanRecords = scanRecordRepository.selectByInventoryItemId(filteredInventoryItem.getId());
1071
            List<ScanRecord> scanRecords = scanRecordRepository.selectByInventoryItemId(filteredInventoryItem.getId());
1061
            ScanRecord scanRecord = scanRecords.stream().filter(x -> x.getType().equals(ScanType.SALE)).findFirst().orElse(null);
1072
            ScanRecord scanRecord = scanRecords.stream().filter(x -> x.getType().equals(ScanType.SALE)).findFirst().orElse(null);
1062
            if (scanRecord == null) {
1073
            if (scanRecord == null) {
1063
                continue;
1074
                continue;
1064
                //schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason, Arrays.asList(SchemeType.INVESTMENT));
-
 
1065
            }
-
 
1066
            int orderId = scanRecord.getOrderId();
-
 
1067
            schemeService.reverseSchemes(Arrays.asList(filteredInventoryItem), orderId, "Reissuing margins as incorrect margin disbursed", SchemeType.OUT_SCHEME_TYPES);
-
 
1068
            schemeService.reverseSchemes(Arrays.asList(filteredInventoryItem), orderId, "Reissuing margins as incorrect margin disbursed", Arrays.asList(SchemeType.SPECIAL_SUPPORT));
-
 
1069
            System.out.println("Out\t" + filteredInventoryItem.getId() + "\t" + filteredInventoryItem.getSerialNumber());
-
 
1070
        }
-
 
1071
        Map<Integer, List<InventoryItem>> purchaseInventoryItemsMap = filteredInventoryItems.stream().filter(x -> x.getCreateTimestamp().isAfter(YearMonth.now().atDay(1).atStartOfDay())).collect(Collectors.groupingBy(x -> x.getPurchaseId()));
-
 
1072
        List<Purchase> purchases = purchaseRepository.selectAllByIds(new ArrayList<>(purchaseInventoryItemsMap.keySet()));
-
 
1073
        for (Purchase purchase : purchases) {
-
 
1074
            String invoiceNumber = purchase.getPurchaseReference();
-
 
1075
            LocalDateTime billingTime =  orderRepository.selectByInvoiceNumber(invoiceNumber).get(0).getBillingTimestamp();
-
 
1076
            if(billingTime.isAfter(YearMonth.now().atDay(1).atStartOfDay()) ) {
-
 
1077
                List<InventoryItem> inventoryItems = purchaseInventoryItemsMap.get(purchase.getId());
-
 
1078
                List<Integer> inventoryItemIds =  inventoryItems.stream().map(x -> x.getId()).collect(toList());
-
 
1079
                schemeService.rollbackSchemes(inventoryItemIds, "Reissuing margins as incorrect margin disbursed");
-
 
1080
                for (InventoryItem inventoryItem : inventoryItems) {
-
 
1081
                    System.out.println("In\t" + inventoryItem.getId() + "\t" + inventoryItem.getSerialNumber());
-
 
1082
                }
-
 
1083
            }
1075
            }
-
 
1076
            schemeService.processSchemeOut(scanRecord.getOrderId(), scanRecord.getFofoId());
1084
        }
1077
        }
1085
    }
1078
    }
1086
 
1079
 
-
 
1080
 
1087
    public void test() throws Exception {
1081
    public void test() throws Exception {
1088
        this.reverseOppoPayout();
1082
        //this.reverseOppoPayout();
-
 
1083
        //this.rolloutOppoPayout();
-
 
1084
        this.debitLoanAmountFromWallet();
1089
        //List<TotalLoanAmountDueModel> totalLoanAmountDueModels = loanRepository.getDueLoansByFofoId(175139438);
1085
        //List<TotalLoanAmountDueModel> totalLoanAmountDueModels = loanRepository.getDueLoansByFofoId(175139438);
1090
        //System.out.println(totalLoanAmountDueModels);
1086
        //System.out.println(totalLoanAmountDueModels);
1091
        //runOnceTasks.findCNDiff();
1087
        //runOnceTasks.findCNDiff();
1092
        /*this.updatePartnerLimit();
1088
        /*this.updatePartnerLimit();
1093
        System.out.println(getSuggestedLimit(300000d));
1089
        System.out.println(getSuggestedLimit(300000d));
Line 1099... Line 1095...
1099
        System.out.println(getSuggestedLimit(2000000d));
1095
        System.out.println(getSuggestedLimit(2000000d));
1100
        System.out.println(getSuggestedLimit(2500000d));*/
1096
        System.out.println(getSuggestedLimit(2500000d));*/
1101
        //Utils.sendMailWithAttachments(googleMailSender, new String[]{"amit.gupta@smartdukaan.com"}, null, "DTDC AWb", "PFA");
1097
        //Utils.sendMailWithAttachments(googleMailSender, new String[]{"amit.gupta@smartdukaan.com"}, null, "DTDC AWb", "PFA");
1102
    }
1098
    }
1103
 
1099
 
-
 
1100
    private void debitLoanAmountFromWallet() {
-
 
1101
        List l1 = Arrays.asList(1234, 1420, 2694, 8129, 12182, 12880, 16289, 16462, 16551, 16625, 16819, 17606, 18902, 19152, 19663, 22409, 22410, 23924, 24058, 24206, 24215, 24220, 24459, 25977, 30585, 31590);
-
 
1102
        l1.addAll(Arrays.asList(11849, 12702, 14554, 14643, 19166, 19638, 32824, 33467, 33954, 34017, 34514, 35128, 35229, 35355, 36007, 36351, 36435, 36586, 36608, 36612, 36665, 37076, 37495, 37678, 38519, 38563, 38638, 38690, 38815, 38840, 39015, 39084, 39142, 39379, 39384, 39586, 39636, 39657, 39755, 39788, 39908, 40054, 40220, 40534, 41731, 41962, 42692));
-
 
1103
        l1.addAll(Arrays.asList());
-
 
1104
    }
-
 
1105
 
1104
    public void test4() throws Exception {
1106
    public void test4() throws Exception {
1105
        List<Integer> offerIds = Arrays.asList(2882, 2881, 2880, 2879, 2878, 2877, 2876, 2875, 2874, 2873, 2872, 2871, 2870, 2869, 2868, 2867, 2866, 2865, 2864, 2863, 2862, 2861, 2860, 2859, 2858, 2857, 2856, 2855, 2854, 2853, 2852, 2851, 2850, 2849, 2847, 2846, 2845, 2844, 2843, 2842, 2841, 2840, 2839, 2838, 2837, 2836, 2835, 2834, 2833, 2832, 2831, 2830, 2829, 2828, 2827, 2826, 2825, 2824, 2823, 2822, 2821, 2820, 2819, 2818, 2817, 2816, 2815, 2814, 2813, 2812, 2811, 2810, 2809, 2808, 2807, 2806, 2805, 2804, 2803, 2802, 2801, 2800, 2799, 2798, 2797, 2796, 2795, 2794, 2793, 2792, 2791, 2790, 2789, 2788, 2787, 2786, 2785, 2784, 2783, 2782, 2781, 2780, 2777, 2776, 2775, 2774, 2773, 2772, 2771, 2770, 2769, 2768, 2767, 2766, 2765, 2764, 2763, 2762, 2761, 2760, 2759, 2758, 2757, 2756, 2755, 2754, 2753, 2752, 2751, 2750, 2749, 2748, 2747, 2746, 2745, 2744, 2723, 2722, 2721, 2720, 2719, 2718, 2717, 2716, 2715, 2714, 2713, 2712, 2711, 2710, 2709, 2708, 2707, 2706, 2705, 2704, 2703, 2702, 2701, 2700, 2699, 2698, 2697, 2696, 2695, 2694, 2693, 2692, 2691, 2690, 2494, 2493, 2492, 2491, 2490, 2489, 2488, 2487, 2486, 2485, 2484, 2483, 2482, 2481, 2480, 2479, 2478, 2477, 2476, 2475, 2474, 2473, 2472, 2471, 2470, 2469, 2466, 2465, 2464, 2463, 2462, 2461, 2460, 2459, 2458, 2457, 2456, 2455, 2454, 2453, 2452, 2451, 2450, 2449, 2448, 2447, 2446, 2445, 2444, 2443, 2442, 2441, 2440, 2439, 2407, 2406, 2405, 2404, 2403, 2402, 2401, 2400, 2399, 2398, 2397, 2396, 2395, 2394, 2393, 2392, 2391, 2390, 2389, 2388, 2387, 2386, 2385, 2384, 2383, 2382, 2381, 2117, 2116, 2115, 2114, 2113, 2112, 2111, 2110, 2109, 2108, 2107, 2106, 2105, 2104, 2103, 2102, 2101, 2100, 2099, 2098, 2077);
1107
        List<Integer> offerIds = Arrays.asList(2882, 2881, 2880, 2879, 2878, 2877, 2876, 2875, 2874, 2873, 2872, 2871, 2870, 2869, 2868, 2867, 2866, 2865, 2864, 2863, 2862, 2861, 2860, 2859, 2858, 2857, 2856, 2855, 2854, 2853, 2852, 2851, 2850, 2849, 2847, 2846, 2845, 2844, 2843, 2842, 2841, 2840, 2839, 2838, 2837, 2836, 2835, 2834, 2833, 2832, 2831, 2830, 2829, 2828, 2827, 2826, 2825, 2824, 2823, 2822, 2821, 2820, 2819, 2818, 2817, 2816, 2815, 2814, 2813, 2812, 2811, 2810, 2809, 2808, 2807, 2806, 2805, 2804, 2803, 2802, 2801, 2800, 2799, 2798, 2797, 2796, 2795, 2794, 2793, 2792, 2791, 2790, 2789, 2788, 2787, 2786, 2785, 2784, 2783, 2782, 2781, 2780, 2777, 2776, 2775, 2774, 2773, 2772, 2771, 2770, 2769, 2768, 2767, 2766, 2765, 2764, 2763, 2762, 2761, 2760, 2759, 2758, 2757, 2756, 2755, 2754, 2753, 2752, 2751, 2750, 2749, 2748, 2747, 2746, 2745, 2744, 2723, 2722, 2721, 2720, 2719, 2718, 2717, 2716, 2715, 2714, 2713, 2712, 2711, 2710, 2709, 2708, 2707, 2706, 2705, 2704, 2703, 2702, 2701, 2700, 2699, 2698, 2697, 2696, 2695, 2694, 2693, 2692, 2691, 2690, 2494, 2493, 2492, 2491, 2490, 2489, 2488, 2487, 2486, 2485, 2484, 2483, 2482, 2481, 2480, 2479, 2478, 2477, 2476, 2475, 2474, 2473, 2472, 2471, 2470, 2469, 2466, 2465, 2464, 2463, 2462, 2461, 2460, 2459, 2458, 2457, 2456, 2455, 2454, 2453, 2452, 2451, 2450, 2449, 2448, 2447, 2446, 2445, 2444, 2443, 2442, 2441, 2440, 2439, 2407, 2406, 2405, 2404, 2403, 2402, 2401, 2400, 2399, 2398, 2397, 2396, 2395, 2394, 2393, 2392, 2391, 2390, 2389, 2388, 2387, 2386, 2385, 2384, 2383, 2382, 2381, 2117, 2116, 2115, 2114, 2113, 2112, 2111, 2110, 2109, 2108, 2107, 2106, 2105, 2104, 2103, 2102, 2101, 2100, 2099, 2098, 2077);
1106
        for (Integer offerId : offerIds) {
1108
        for (Integer offerId : offerIds) {
1107
            Offer fromOffer = offerRepository.selectById(offerId);
1109
            Offer fromOffer = offerRepository.selectById(offerId);
1108
            CreateOfferRequest createOfferRequest = offerService.getCreateOfferRequest(fromOffer);
1110
            CreateOfferRequest createOfferRequest = offerService.getCreateOfferRequest(fromOffer);
Line 3666... Line 3668...
3666
 
3668
 
3667
    static {
3669
    static {
3668
        discountMap.put(4 * ProfitMandiConstants.ONE_LAC - 1, 0.2);   // Up to 6 -> 20%
3670
        discountMap.put(4 * ProfitMandiConstants.ONE_LAC - 1, 0.2);   // Up to 6 -> 20%
3669
        discountMap.put(10 * ProfitMandiConstants.ONE_LAC - 1, 0.25);  // 6-10 -> 25%
3671
        discountMap.put(10 * ProfitMandiConstants.ONE_LAC - 1, 0.25);  // 6-10 -> 25%
3670
        discountMap.put(20 * ProfitMandiConstants.ONE_LAC - 1, 0.3); // Above 10 -> 30%
3672
        discountMap.put(20 * ProfitMandiConstants.ONE_LAC - 1, 0.3); // Above 10 -> 30%
3671
        discountMap.put(Double.MAX_VALUE, 0.4); // Above 10 -> 30%
3673
        discountMap.put(Double.MAX_VALUE, 0.4); // Above 10 -> 40%
3672
    }
3674
    }
3673
 
3675
 
3674
    public BigDecimal getSuggestedLimit(double investmentValue) {
3676
    public BigDecimal getSuggestedLimit(double investmentValue) {
3675
        double percentageValue = discountMap.ceilingEntry(investmentValue).getValue();
3677
        double percentageValue = discountMap.ceilingEntry(investmentValue).getValue();
-
 
3678
        return this.getSuggestedAmount(investmentValue, percentageValue);
-
 
3679
 
-
 
3680
    }
-
 
3681
 
-
 
3682
    private BigDecimal getSuggestedAmount(double investmentValue, double percentageValue) {
3676
        return BigDecimal.valueOf(investmentValue * percentageValue);
3683
        return BigDecimal.valueOf(investmentValue * percentageValue);
3677
    }
3684
    }
3678
 
3685
 
-
 
3686
    private static List<Integer> hundredPercentLimitPartnerIds = Arrays.asList(175139630,
-
 
3687
            175139815,
-
 
3688
            175139844,
-
 
3689
            175140101
-
 
3690
    );
-
 
3691
 
3679
    private BigDecimal getSuggestedAmount(CreditAccount creditAccount, CurrentPartnerDailyInvestment
3692
    private BigDecimal getSuggestedAmount(CreditAccount creditAccount, CurrentPartnerDailyInvestment
3680
            currentPartnerDailyInvestment, long utilizationAmount, BigDecimal sidbiLimit) {
3693
            currentPartnerDailyInvestment, long utilizationAmount, BigDecimal sidbiLimit) {
3681
        BigDecimal suggestedAmount = BigDecimal.ZERO;
3694
        BigDecimal suggestedAmount = BigDecimal.ZERO;
3682
        //1 LAC
3695
        //1 LAC
3683
        if (creditAccount == null || creditAccount.getGateway().equals(Gateway.SDDIRECT)) {
3696
        if (creditAccount == null || creditAccount.getGateway().equals(Gateway.SDDIRECT)) {
3684
 
3697
 
3685
            if (currentPartnerDailyInvestment != null) {
3698
            if (currentPartnerDailyInvestment != null) {
-
 
3699
                if (hundredPercentLimitPartnerIds.contains(creditAccount.getFofoId())) {
-
 
3700
                    suggestedAmount = getSuggestedAmount(currentPartnerDailyInvestment.getTotalInvestment() - utilizationAmount, 1);
-
 
3701
                } else {
3686
                suggestedAmount = getSuggestedLimit(currentPartnerDailyInvestment.getTotalInvestment() - utilizationAmount);
3702
                    suggestedAmount = getSuggestedLimit(currentPartnerDailyInvestment.getTotalInvestment() - utilizationAmount);
-
 
3703
                }
3687
            }
3704
            }
3688
            if (suggestedAmount.doubleValue() < 0) {
3705
            if (suggestedAmount.doubleValue() < 0) {
3689
                suggestedAmount = BigDecimal.ZERO;
3706
                suggestedAmount = BigDecimal.ZERO;
3690
            }
3707
            }
3691
        } else if (creditAccount.getGateway().equals(Gateway.SIDBI) && sidbiLimit != null) {
3708
        } else if (creditAccount.getGateway().equals(Gateway.SIDBI) && sidbiLimit != null) {