Subversion Repositories SmartDukaan

Rev

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

Rev 33554 Rev 33665
Line 584... Line 584...
584
        this.processScratchOffer(fofoOrder);
584
        this.processScratchOffer(fofoOrder);
585
 
585
 
586
        return fofoOrder.getId();
586
        return fofoOrder.getId();
587
    }
587
    }
588
 
588
 
589
    @Override
-
 
590
    public void processScratchOffer(FofoOrder fofoOrder) throws ProfitMandiBusinessException {
-
 
591
        boolean isSmartPhonePurchased = false;
-
 
592
        float maxPurchaseValue = 0;
-
 
593
        List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
-
 
594
        for (FofoOrderItem fofoOrderItem : fofoOrderItems) {
-
 
595
            Item item = itemRepository.selectById(fofoOrderItem.getItemId());
-
 
596
 
-
 
597
            if (item.isSmartPhone()) {
-
 
598
                LOGGER.info("fofoItem {}", fofoOrderItem);
-
 
599
                isSmartPhonePurchased = true;
-
 
600
                maxPurchaseValue = Math.max(fofoOrderItem.getSellingPrice(), maxPurchaseValue);
-
 
601
 
-
 
602
            }
-
 
603
        }
-
 
604
        LocalDate startDate = ProfitMandiConstants.SCRATCH_OFFER_START_DATE;
-
 
605
        LocalDate endDate = ProfitMandiConstants.SCRATCH_OFFER_END_DATE;
-
 
606
        boolean specificPriceOffer = ProfitMandiConstants.SPECIFIC_PRICE_OFFER;
-
 
607
        boolean randomOffer = ProfitMandiConstants.RANDOM_OFFER;
-
 
608
 
-
 
609
        if (isSmartPhonePurchased) {
-
 
610
            if (LocalDateTime.now().isAfter(startDate.atStartOfDay()) && LocalDateTime.now().isBefore(endDate.atTime(Utils.MAX_TIME))) {
-
 
611
                Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
589
    static Map<Double, List<ScratchedGift>> GIFT_SERIES = new TreeMap<>(Comparator.reverseOrder());
612
                try {
-
 
613
                    this.sendAppDownloadBillingOffer(customer.getMobileNumber());
-
 
614
                } catch (Exception e) {
-
 
615
                    // TODO Auto-generated catch block
-
 
616
                    e.printStackTrace();
-
 
617
                }
-
 
618
                if (specificPriceOffer) {
-
 
619
                    this.createSpecificPriceScratchOffer(fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId(), maxPurchaseValue);
-
 
620
                } else if (randomOffer) {
-
 
621
                    this.createRandomScratchOffer(fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
-
 
622
                    LOGGER.info("randomOffer {}", randomOffer);
-
 
623
                } else {
-
 
624
                    this.createScratchOffer(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
-
 
625
                }
-
 
626
 
-
 
627
            }
-
 
628
        }
-
 
629
    }
-
 
630
 
590
 
631
    private void persistNonSerializedWithCustomSerialNumber(CustomFofoOrderItem customFofoOrderItem, int orderItemId) {
591
    private void persistNonSerializedWithCustomSerialNumber(CustomFofoOrderItem customFofoOrderItem, int orderItemId) {
632
        // Create a new instance of FofoNonSerializeSerial
592
        // Create a new instance of FofoNonSerializeSerial
633
        for (String accSerialNumber : customFofoOrderItem.getCustomSerialNumbers()) {
593
        for (String accSerialNumber : customFofoOrderItem.getCustomSerialNumbers()) {
634
            if (!accSerialNumber.isEmpty()) {
594
            if (!accSerialNumber.isEmpty()) {
Line 702... Line 662...
702
                so2.setUnlockedAt(today9PM);
662
                so2.setUnlockedAt(today9PM);
703
            }
663
            }
704
            scratchOfferRepository.persist(so2);
664
            scratchOfferRepository.persist(so2);
705
        }
665
        }
706
    }
666
    }
-
 
667
    private static Map<ScratchedGift, Integer> GIFT_QUANTITIES = new HashMap<>();
707
 
668
 
-
 
669
    static {
-
 
670
        GIFT_QUANTITIES.put(ScratchedGift.MINI_LUNCH_BOX, 500);
708
    static Map<Double, RandomCollection<ScratchedGift>> GIFT_SERIES = new TreeMap<>(Comparator.reverseOrder());
671
        GIFT_QUANTITIES.put(ScratchedGift.THREE_SET_CONTAINER, 250);
-
 
672
        GIFT_QUANTITIES.put(ScratchedGift.CASSROLE, 250);
-
 
673
        GIFT_QUANTITIES.put(ScratchedGift.INSULATED_FLASK, 250);
-
 
674
        GIFT_QUANTITIES.put(ScratchedGift.JUICE_JUG, 250);
-
 
675
        GIFT_QUANTITIES.put(ScratchedGift.JUICER, 11);
-
 
676
        GIFT_QUANTITIES.put(ScratchedGift.HAIR_DRYER, 16);
-
 
677
        GIFT_QUANTITIES.put(ScratchedGift.CHOPPER, 20);
-
 
678
        GIFT_QUANTITIES.put(ScratchedGift.BOTTLE, 12);
-
 
679
        GIFT_QUANTITIES.put(ScratchedGift.ELECTRIC_KETTLE, 137);
-
 
680
        GIFT_QUANTITIES.put(ScratchedGift.BOWL_SET, 134);
-
 
681
        GIFT_QUANTITIES.put(ScratchedGift.BOTTLE_MUG, 28);
-
 
682
        GIFT_QUANTITIES.put(ScratchedGift.EW, 1000);
-
 
683
    }
709
 
684
 
710
    static {
685
    static {
-
 
686
        GIFT_SERIES.put(0.0, Arrays.asList(ScratchedGift.MINI_LUNCH_BOX, ScratchedGift.BOWL_SET, ScratchedGift.THREE_SET_CONTAINER, ScratchedGift.BOTTLE, ScratchedGift.BOTTLE_MUG));
-
 
687
        GIFT_SERIES.put(20001.0, Arrays.asList(ScratchedGift.CASSROLE, ScratchedGift.INSULATED_FLASK, ScratchedGift.JUICE_JUG));
-
 
688
        GIFT_SERIES.put(25001.0, Arrays.asList(ScratchedGift.ELECTRIC_KETTLE));
-
 
689
        GIFT_SERIES.put(35001.0, Arrays.asList(ScratchedGift.JUICER, ScratchedGift.HAIR_DRYER, ScratchedGift.CHOPPER));
-
 
690
    }
-
 
691
 
-
 
692
    List<Double> PRICE_RANGE = Arrays.asList(0.0, 20001.0, 25001.0, 35001.0);
-
 
693
 
-
 
694
    @Override
-
 
695
    public void processScratchOffer(FofoOrder fofoOrder) throws ProfitMandiBusinessException {
-
 
696
        boolean isSmartPhonePurchased = false;
-
 
697
        float maxPurchaseValue = 0;
-
 
698
        List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
-
 
699
        for (FofoOrderItem fofoOrderItem : fofoOrderItems) {
-
 
700
            Item item = itemRepository.selectById(fofoOrderItem.getItemId());
-
 
701
 
-
 
702
            if (item.isSmartPhone()) {
-
 
703
                LOGGER.info("fofoItem {}", fofoOrderItem);
-
 
704
                isSmartPhonePurchased = true;
-
 
705
                maxPurchaseValue = Math.max(fofoOrderItem.getSellingPrice(), maxPurchaseValue);
-
 
706
 
-
 
707
            }
-
 
708
        }
-
 
709
        LocalDate startDate = ProfitMandiConstants.SCRATCH_OFFER_START_DATE;
-
 
710
        LocalDate endDate = ProfitMandiConstants.SCRATCH_OFFER_END_DATE;
-
 
711
        boolean specificPriceOffer = ProfitMandiConstants.SPECIFIC_PRICE_OFFER;
-
 
712
        boolean randomOffer = ProfitMandiConstants.RANDOM_OFFER;
-
 
713
 
-
 
714
        if (isSmartPhonePurchased) {
-
 
715
 
-
 
716
            if (LocalDateTime.now().isAfter(startDate.atStartOfDay()) && LocalDateTime.now().isBefore(endDate.atTime(Utils.MAX_TIME))) {
-
 
717
                Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
-
 
718
                try {
-
 
719
                    this.sendAppDownloadBillingOffer(customer.getMobileNumber());
-
 
720
                } catch (Exception e) {
-
 
721
                    // TODO Auto-generated catch block
-
 
722
                    e.printStackTrace();
-
 
723
                }
-
 
724
                if (specificPriceOffer) {
-
 
725
                    this.createSpecificPriceScratchOffer(fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId(), maxPurchaseValue);
-
 
726
                } else if (randomOffer) {
-
 
727
                    this.createRandomScratchOffer(fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
-
 
728
                    LOGGER.info("randomOffer {}", randomOffer);
-
 
729
                } else {
-
 
730
                    this.createScratchOffer(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
-
 
731
                }
-
 
732
 
-
 
733
            }
-
 
734
        }
-
 
735
    }
-
 
736
 
-
 
737
    @Override
-
 
738
    public ScratchedGift getSelectedGift(double purchaseAmount) {
-
 
739
        //Iterating map in reverse order of values
-
 
740
        Map<ScratchedGift, Long> scratchOfferCountMap = scratchOfferRepository.countOffersByDateRange(ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
-
 
741
 
-
 
742
        RandomCollection<ScratchedGift> giftRandomCollection = createDynamicGiftSeries(scratchOfferCountMap, purchaseAmount);
-
 
743
        if (giftRandomCollection.size() > 0) {
-
 
744
            return giftRandomCollection.next();
-
 
745
        } else {
-
 
746
            // Default gift if no match found
-
 
747
            return ScratchedGift.EW;
-
 
748
        }
-
 
749
    }
-
 
750
 
-
 
751
    public RandomCollection<ScratchedGift> createDynamicGiftSeries(Map<ScratchedGift, Long> soldGiftContMap, Double sellingPrice) {
-
 
752
        int index = 0;
-
 
753
        RandomCollection<ScratchedGift> randomCollection = new RandomCollection<>();
-
 
754
        for (Double price : PRICE_RANGE) {
-
 
755
            if (sellingPrice >= price) {
-
 
756
                int divisor = PRICE_RANGE.size() - index;
-
 
757
                for (ScratchedGift gift : GIFT_SERIES.get(price)) {
-
 
758
                    int remainingQty = GIFT_QUANTITIES.get(gift) - soldGiftContMap.getOrDefault(gift, 0l).intValue();
-
 
759
                    if (remainingQty == 0) {
-
 
760
                        continue;
-
 
761
                    }
-
 
762
                    if (remainingQty > divisor) {
-
 
763
                        randomCollection.add(remainingQty / divisor, gift);
-
 
764
                    } else {
-
 
765
                        randomCollection.add(remainingQty, gift);
-
 
766
                    }
-
 
767
 
-
 
768
                }
-
 
769
                index++;
-
 
770
            }
-
 
771
        }
-
 
772
        return randomCollection;
-
 
773
    }
-
 
774
 
-
 
775
    /*static {
711
        RandomCollection<ScratchedGift> map1 = new RandomCollection<ScratchedGift>().
776
        RandomCollection<ScratchedGift> map1 = new RandomCollection<ScratchedGift>().
712
                add(100d, ScratchedGift.GIFT_BOWL);
777
                add(100d, ScratchedGift.GIFT_BOWL);
713
        GIFT_SERIES.put(0.0, map1);
778
        GIFT_SERIES.put(0.0, map1);
714
        //Map<ScratchedGift, Double> map2 = new HashMap<>();
779
        //Map<ScratchedGift, Double> map2 = new HashMap<>();
715
        RandomCollection<ScratchedGift> map2 = new RandomCollection<ScratchedGift>()
780
        RandomCollection<ScratchedGift> map2 = new RandomCollection<ScratchedGift>()
Line 734... Line 799...
734
        RandomCollection<ScratchedGift> map5 = new RandomCollection<ScratchedGift>()
799
        RandomCollection<ScratchedGift> map5 = new RandomCollection<ScratchedGift>()
735
                .add(40d, ScratchedGift.SPEAKER)
800
                .add(40d, ScratchedGift.SPEAKER)
736
                .add(60d, ScratchedGift.SMART_WATCH);
801
                .add(60d, ScratchedGift.SMART_WATCH);
737
 
802
 
738
        GIFT_SERIES.put(50001.0, map5);
803
        GIFT_SERIES.put(50001.0, map5);
739
    }
804
    }*/
740
 
805
 
741
 
806
 
742
    private void createSpecificPriceScratchOffer(String invoiceNumber, int customerId, float purchaseAmount) {
807
    private void createSpecificPriceScratchOffer(String invoiceNumber, int customerId, float purchaseAmount) {
743
        ScratchedGift selectedGift = getSelectedGift(purchaseAmount);
808
        ScratchedGift selectedGift = getSelectedGift(purchaseAmount);
744
        List<ScratchOffer> scratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(customerId, ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
809
        List<ScratchOffer> scratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(customerId, ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
Line 769... Line 834...
769
            so2.setUnlockedAt(LocalDateTime.now());
834
            so2.setUnlockedAt(LocalDateTime.now());
770
            scratchOfferRepository.persist(so2);
835
            scratchOfferRepository.persist(so2);
771
        }
836
        }
772
    }
837
    }
773
 
838
 
774
    @Override
-
 
775
    public ScratchedGift getSelectedGift(double purchaseAmount) {
-
 
776
        //Iterating map in reverse order of values
-
 
777
        for (Map.Entry<Double, RandomCollection<ScratchedGift>> entry : GIFT_SERIES.entrySet()) {
-
 
778
            if (purchaseAmount >= entry.getKey()) {
-
 
779
                return entry.getValue().next();
-
 
780
            }
-
 
781
        }
-
 
782
        return ScratchedGift.BLNT; // Default gift if no match found
-
 
783
    }
-
 
784
 
-
 
785
    private ScratchedGift getScratchedGiftRandom(int fofoId, int customerId) throws ProfitMandiBusinessException {
839
    private ScratchedGift getScratchedGiftRandom(int fofoId, int customerId) throws ProfitMandiBusinessException {
786
        Map<Integer, ScratchedGift> giftSeries = new HashMap<>();
840
        Map<Integer, ScratchedGift> giftSeries = new HashMap<>();
787
        giftSeries.put(1, ScratchedGift.MINI_CHOPPER);
841
        giftSeries.put(1, ScratchedGift.MINI_CHOPPER);
788
        giftSeries.put(2, ScratchedGift.FRUIT_JUICER);
842
        giftSeries.put(2, ScratchedGift.FRUIT_JUICER);
789
        giftSeries.put(3, ScratchedGift.STEAM_IRON);
843
        giftSeries.put(3, ScratchedGift.STEAM_IRON);
Line 871... Line 925...
871
                .add(100d, ScratchedGift.BLUETOOTH_SPEAKER)
925
                .add(100d, ScratchedGift.BLUETOOTH_SPEAKER)
872
                .add(150d, ScratchedGift.RED_WATER_BOTTLE)
926
                .add(150d, ScratchedGift.RED_WATER_BOTTLE)
873
                .add(200d, ScratchedGift.GIFT_BOWL)
927
                .add(200d, ScratchedGift.GIFT_BOWL)
874
                .add(100d, ScratchedGift.EARBUDS);
928
                .add(100d, ScratchedGift.EARBUDS);
875
 
929
 
876
        ScratchedGift gift = ScratchedGift.RED_WATER_BOTTLE;
-
 
877
 
-
 
878
        Random random = new Random();
-
 
879
        int rand;
930
        ScratchedGift gift;
880
        while (true) {
-
 
881
            rand = random.nextInt(6);
-
 
882
            if (rand != 0) break;
-
 
883
        }
-
 
884
 
931
 
885
        List<ScratchOffer> lastScratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(customerId, ProfitMandiConstants.LAST_SCRATCH_OFFER_START_DATE, ProfitMandiConstants.LAST_SCRATCH_OFFER_END_DATE);
932
        List<ScratchOffer> lastScratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(customerId, ProfitMandiConstants.LAST_SCRATCH_OFFER_START_DATE, ProfitMandiConstants.LAST_SCRATCH_OFFER_END_DATE);
886
//
933
 
887
//        if (lastScratchOffers.isEmpty()) {
934
        if (lastScratchOffers.isEmpty()) {
888
//            gift = map1.next();
935
            gift = map1.next();
889
//        } else {
936
        } else {
890
//            gift = ScratchedGift.RED_WATER_BOTTLE;
937
            gift = ScratchedGift.RED_WATER_BOTTLE;
891
//            LOGGER.info("RED_WATER_BOTTLE {}", gift);
938
            LOGGER.info("RED_WATER_BOTTLE {}", gift);
892
//        }
939
        }
893
        return gift;
940
        return gift;
894
    }
941
    }
895
 
942
 
896
    private HygieneData createAndGetHygieneData(int id, int fofoId) {
943
    private HygieneData createAndGetHygieneData(int id, int fofoId) {
897
        HygieneData hygieneData = new HygieneData();
944
        HygieneData hygieneData = new HygieneData();
Line 901... Line 948...
901
        hygieneDataRepository.persist(hygieneData);
948
        hygieneDataRepository.persist(hygieneData);
902
 
949
 
903
        return hygieneData;
950
        return hygieneData;
904
    }
951
    }
905
 
952
 
-
 
953
 
906
    @Override
954
    @Override
907
    public String getInvoiceNumber(int fofoId, String fofoStoreCode) {
955
    public String getInvoiceNumber(int fofoId, String fofoStoreCode) {
908
        InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = null;
956
        InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = null;
909
        try {
957
        try {
910
            invoiceNumberGenerationSequence = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoId);
958
            invoiceNumberGenerationSequence = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoId);
Line 1012... Line 1060...
1012
        } else {
1060
        } else {
1013
            throw new ProfitMandiBusinessException("Serial Number", serialNumber, "Serial Number does not exist in our warehouse");
1061
            throw new ProfitMandiBusinessException("Serial Number", serialNumber, "Serial Number does not exist in our warehouse");
1014
        }
1062
        }
1015
    }
1063
    }
1016
 
1064
 
1017
    void modifyDummyModel(FofoOrder fofoOrder, InvoicePdfModel pdfModel, int itemId, String serialNumber) throws ProfitMandiBusinessException {
1065
    void modifyDummyModel(FofoOrder fofoOrder, InvoicePdfModel pdfModel, int itemId, String serialNumber) throws
-
 
1066
            ProfitMandiBusinessException {
1018
 
1067
 
1019
        int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(fofoOrder.getFofoId());
1068
        int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(fofoOrder.getFofoId());
1020
 
1069
 
1021
        Address retailerAddress = addressRepository.selectById(retailerAddressId);
1070
        Address retailerAddress = addressRepository.selectById(retailerAddressId);
1022
        Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
1071
        Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
Line 1224... Line 1273...
1224
        pdfModel.setTncs(tncs);
1273
        pdfModel.setTncs(tncs);
1225
        return pdfModel;
1274
        return pdfModel;
1226
 
1275
 
1227
    }
1276
    }
1228
 
1277
 
1229
    private CustomCustomer getCustomCustomer(FofoOrder fofoOrder, CustomAddress retailerAddress) throws ProfitMandiBusinessException {
1278
    private CustomCustomer getCustomCustomer(FofoOrder fofoOrder, CustomAddress retailerAddress) throws
-
 
1279
            ProfitMandiBusinessException {
1230
        Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
1280
        Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
1231
        CustomCustomer customCustomer = new CustomCustomer();
1281
        CustomCustomer customCustomer = new CustomCustomer();
1232
        customCustomer.setFirstName(customer.getFirstName());
1282
        customCustomer.setFirstName(customer.getFirstName());
1233
        customCustomer.setLastName(customer.getLastName());
1283
        customCustomer.setLastName(customer.getLastName());
1234
        customCustomer.setEmailId(customer.getEmailId());
1284
        customCustomer.setEmailId(customer.getEmailId());
Line 1335... Line 1385...
1335
            throw new ProfitMandiBusinessException("cartData", cartJson, "FFORDR_1006");
1385
            throw new ProfitMandiBusinessException("cartData", cartJson, "FFORDR_1006");
1336
        }
1386
        }
1337
    }
1387
    }
1338
 
1388
 
1339
    @Override
1389
    @Override
1340
    public Map<String, Object> getSaleHistory(int fofoId, SearchType searchType, String searchValue, LocalDateTime startDate, LocalDateTime endDate, int offset, int limit) throws ProfitMandiBusinessException {
1390
    public Map<String, Object> getSaleHistory(int fofoId, SearchType searchType, String searchValue, LocalDateTime
-
 
1391
            startDate, LocalDateTime endDate, int offset, int limit) throws ProfitMandiBusinessException {
1341
        long countItems = 0;
1392
        long countItems = 0;
1342
        List<FofoOrder> fofoOrders = new ArrayList<>();
1393
        List<FofoOrder> fofoOrders = new ArrayList<>();
1343
 
1394
 
1344
        if (searchType == SearchType.CUSTOMER_MOBILE_NUMBER && !searchValue.isEmpty()) {
1395
        if (searchType == SearchType.CUSTOMER_MOBILE_NUMBER && !searchValue.isEmpty()) {
1345
            fofoOrders = fofoOrderRepository.selectByFofoIdAndCustomerMobileNumber(fofoId, searchValue, null, null, offset, limit);
1396
            fofoOrders = fofoOrderRepository.selectByFofoIdAndCustomerMobileNumber(fofoId, searchValue, null, null, offset, limit);
Line 1376... Line 1427...
1376
            map.put("end", offset + limit);
1427
            map.put("end", offset + limit);
1377
        }
1428
        }
1378
        return map;
1429
        return map;
1379
    }
1430
    }
1380
 
1431
 
1381
    public ResponseEntity<?> downloadReportInCsv(org.apache.commons.io.output.ByteArrayOutputStream baos, List<List<?>> rows, String fileName) {
1432
    public ResponseEntity<?> downloadReportInCsv(org.apache.commons.io.output.ByteArrayOutputStream
-
 
1433
                                                         baos, List<List<?>> rows, String fileName) {
1382
        final HttpHeaders headers = new HttpHeaders();
1434
        final HttpHeaders headers = new HttpHeaders();
1383
        headers.set("Content-Type", "text/csv");
1435
        headers.set("Content-Type", "text/csv");
1384
 
1436
 
1385
        headers.set("Content-disposition", "inline; filename=" + fileName + ".csv");
1437
        headers.set("Content-disposition", "inline; filename=" + fileName + ".csv");
1386
        headers.setContentLength(baos.toByteArray().length);
1438
        headers.setContentLength(baos.toByteArray().length);
Line 1390... Line 1442...
1390
 
1442
 
1391
        return new ResponseEntity<>(inputStreamResource, headers, HttpStatus.OK);
1443
        return new ResponseEntity<>(inputStreamResource, headers, HttpStatus.OK);
1392
    }
1444
    }
1393
 
1445
 
1394
    @Override
1446
    @Override
-
 
1447
    public Map<String, Object> getSaleHistoryPaginated(int fofoId, SearchType searchType, String
1395
    public Map<String, Object> getSaleHistoryPaginated(int fofoId, SearchType searchType, String searchValue, LocalDateTime startDate, LocalDateTime endDate, int offset, int limit) throws ProfitMandiBusinessException {
1448
            searchValue, LocalDateTime startDate, LocalDateTime endDate, int offset, int limit) throws
-
 
1449
            ProfitMandiBusinessException {
1396
        List<FofoOrder> fofoOrders = new ArrayList<>();
1450
        List<FofoOrder> fofoOrders = new ArrayList<>();
1397
 
1451
 
1398
        if (searchType == SearchType.CUSTOMER_MOBILE_NUMBER && !searchValue.isEmpty()) {
1452
        if (searchType == SearchType.CUSTOMER_MOBILE_NUMBER && !searchValue.isEmpty()) {
1399
            fofoOrders = fofoOrderRepository.selectByFofoIdAndCustomerMobileNumber(fofoId, searchValue, startDate, endDate, offset, limit);
1453
            fofoOrders = fofoOrderRepository.selectByFofoIdAndCustomerMobileNumber(fofoId, searchValue, startDate, endDate, offset, limit);
1400
        } else if (searchType == SearchType.CUSTOMER_NAME && !searchValue.isEmpty()) {
1454
        } else if (searchType == SearchType.CUSTOMER_NAME && !searchValue.isEmpty()) {
Line 1436... Line 1490...
1436
        return serialNumbers;
1490
        return serialNumbers;
1437
    }
1491
    }
1438
 
1492
 
1439
    static final List<String> MOP_VOILATED_BRANDS = Arrays.asList("Live Demo", "Almost New");
1493
    static final List<String> MOP_VOILATED_BRANDS = Arrays.asList("Live Demo", "Almost New");
1440
 
1494
 
-
 
1495
    private void validateDpPrice(int fofoId, Map<
1441
    private void validateDpPrice(int fofoId, Map<Integer, PriceModel> itemIdMopPriceMap, Map<Integer, CustomFofoOrderItem> itemIdCustomFofoLineItemMap) throws ProfitMandiBusinessException {
1496
            Integer, PriceModel> itemIdMopPriceMap, Map<Integer, CustomFofoOrderItem> itemIdCustomFofoLineItemMap) throws
-
 
1497
            ProfitMandiBusinessException {
1442
        if (pricingService.getMopVoilatedRetailerIds().contains(fofoId)) return;
1498
        if (pricingService.getMopVoilatedRetailerIds().contains(fofoId)) return;
1443
        for (Map.Entry<Integer, CustomFofoOrderItem> entry : itemIdCustomFofoLineItemMap.entrySet()) {
1499
        for (Map.Entry<Integer, CustomFofoOrderItem> entry : itemIdCustomFofoLineItemMap.entrySet()) {
1444
            int itemId = entry.getKey();
1500
            int itemId = entry.getKey();
1445
            CustomFofoOrderItem customFofoOrderItem = entry.getValue();
1501
            CustomFofoOrderItem customFofoOrderItem = entry.getValue();
1446
            LOGGER.info("CustomFofoOrderItem -- {}", customFofoOrderItem);
1502
            LOGGER.info("CustomFofoOrderItem -- {}", customFofoOrderItem);
Line 1456... Line 1512...
1456
                }
1512
                }
1457
            }
1513
            }
1458
        }
1514
        }
1459
    }
1515
    }
1460
 
1516
 
-
 
1517
    private void validateMopPrice(int fofoId, Map<
1461
    private void validateMopPrice(int fofoId, Map<Integer, PriceModel> itemIdMopPriceMap, Map<Integer, CustomFofoOrderItem> itemIdCustomFofoLineItemMap) throws ProfitMandiBusinessException {
1518
            Integer, PriceModel> itemIdMopPriceMap, Map<Integer, CustomFofoOrderItem> itemIdCustomFofoLineItemMap) throws
-
 
1519
            ProfitMandiBusinessException {
1462
        if (pricingService.getMopVoilatedRetailerIds().contains(fofoId)) return;
1520
        if (pricingService.getMopVoilatedRetailerIds().contains(fofoId)) return;
1463
        Map<Integer, Float> invalidMopItemIdPriceMap = new HashMap<>();
1521
        Map<Integer, Float> invalidMopItemIdPriceMap = new HashMap<>();
1464
        for (Map.Entry<Integer, PriceModel> entry : itemIdMopPriceMap.entrySet()) {
1522
        for (Map.Entry<Integer, PriceModel> entry : itemIdMopPriceMap.entrySet()) {
1465
            CustomFofoOrderItem customFofoOrderItem = itemIdCustomFofoLineItemMap.get(entry.getKey());
1523
            CustomFofoOrderItem customFofoOrderItem = itemIdCustomFofoLineItemMap.get(entry.getKey());
1466
            Item item = itemRepository.selectById(customFofoOrderItem.getItemId());
1524
            Item item = itemRepository.selectById(customFofoOrderItem.getItemId());
Line 1474... Line 1532...
1474
            throw new ProfitMandiBusinessException("invalidMopItemIdPrice", invalidMopItemIdPriceMap, "FFORDR_1010");
1532
            throw new ProfitMandiBusinessException("invalidMopItemIdPrice", invalidMopItemIdPriceMap, "FFORDR_1010");
1475
        }
1533
        }
1476
 
1534
 
1477
    }
1535
    }
1478
 
1536
 
1479
    private void updateInventoryItemsAndScanRecord(Set<InventoryItem> inventoryItems, int fofoId, Map<Integer, Integer> inventoryItemQuantityUsed, int fofoOrderId) {
1537
    private void updateInventoryItemsAndScanRecord(Set<InventoryItem> inventoryItems, int fofoId, Map<
-
 
1538
            Integer, Integer> inventoryItemQuantityUsed, int fofoOrderId) {
1480
        for (InventoryItem inventoryItem : inventoryItems) {
1539
        for (InventoryItem inventoryItem : inventoryItems) {
1481
            inventoryItem.setLastScanType(ScanType.SALE);
1540
            inventoryItem.setLastScanType(ScanType.SALE);
1482
            inventoryItem.setUpdateTimestamp(LocalDateTime.now());
1541
            inventoryItem.setUpdateTimestamp(LocalDateTime.now());
1483
            ScanRecord scanRecord = new ScanRecord();
1542
            ScanRecord scanRecord = new ScanRecord();
1484
            scanRecord.setInventoryItemId(inventoryItem.getId());
1543
            scanRecord.setInventoryItemId(inventoryItem.getId());
Line 1491... Line 1550...
1491
            purchaseReturnItemRepository.deleteById(inventoryItem.getId());
1550
            purchaseReturnItemRepository.deleteById(inventoryItem.getId());
1492
 
1551
 
1493
        }
1552
        }
1494
    }
1553
    }
1495
 
1554
 
-
 
1555
    private void createFofoLineItem(int fofoOrderItemId, Set<
1496
    private void createFofoLineItem(int fofoOrderItemId, Set<InventoryItem> inventoryItems, Map<Integer, Integer> inventoryItemIdQuantityUsed) {
1556
            InventoryItem> inventoryItems, Map<Integer, Integer> inventoryItemIdQuantityUsed) {
1497
        for (InventoryItem inventoryItem : inventoryItems) {
1557
        for (InventoryItem inventoryItem : inventoryItems) {
1498
            FofoLineItem fofoLineItem = new FofoLineItem();
1558
            FofoLineItem fofoLineItem = new FofoLineItem();
1499
            fofoLineItem.setFofoOrderItemId(fofoOrderItemId);
1559
            fofoLineItem.setFofoOrderItemId(fofoOrderItemId);
1500
            fofoLineItem.setSerialNumber(inventoryItem.getSerialNumber());
1560
            fofoLineItem.setSerialNumber(inventoryItem.getSerialNumber());
1501
            fofoLineItem.setInventoryItemId(inventoryItem.getId());
1561
            fofoLineItem.setInventoryItemId(inventoryItem.getId());
1502
            fofoLineItem.setQuantity(inventoryItemIdQuantityUsed.get(inventoryItem.getId()));
1562
            fofoLineItem.setQuantity(inventoryItemIdQuantityUsed.get(inventoryItem.getId()));
1503
            fofoLineItemRepository.persist(fofoLineItem);
1563
            fofoLineItemRepository.persist(fofoLineItem);
1504
        }
1564
        }
1505
    }
1565
    }
1506
 
1566
 
1507
    private FofoOrderItem createAndGetFofoOrderItem(CustomFofoOrderItem customFofoOrderItem, int fofoOrderId, Map<Integer, Item> itemMap, Set<InventoryItem> inventoryItems, Integer stateId) throws ProfitMandiBusinessException {
1567
    private FofoOrderItem createAndGetFofoOrderItem(CustomFofoOrderItem customFofoOrderItem, int fofoOrderId, Map<
-
 
1568
            Integer, Item> itemMap, Set<InventoryItem> inventoryItems, Integer stateId) throws
-
 
1569
            ProfitMandiBusinessException {
1508
        FofoOrderItem fofoOrderItem = new FofoOrderItem();
1570
        FofoOrderItem fofoOrderItem = new FofoOrderItem();
1509
        fofoOrderItem.setItemId(customFofoOrderItem.getItemId());
1571
        fofoOrderItem.setItemId(customFofoOrderItem.getItemId());
1510
        fofoOrderItem.setQuantity(customFofoOrderItem.getQuantity());
1572
        fofoOrderItem.setQuantity(customFofoOrderItem.getQuantity());
1511
        fofoOrderItem.setSellingPrice(customFofoOrderItem.getSellingPrice());
1573
        fofoOrderItem.setSellingPrice(customFofoOrderItem.getSellingPrice());
1512
        fofoOrderItem.setOrderId(fofoOrderId);
1574
        fofoOrderItem.setOrderId(fofoOrderId);
Line 1545... Line 1607...
1545
        fofoOrderItem.setColor(item.getColor());
1607
        fofoOrderItem.setColor(item.getColor());
1546
        fofoOrderItemRepository.persist(fofoOrderItem);
1608
        fofoOrderItemRepository.persist(fofoOrderItem);
1547
        return fofoOrderItem;
1609
        return fofoOrderItem;
1548
    }
1610
    }
1549
 
1611
 
1550
    private FofoOrderItem getDummyFofoOrderItem(int itemId, int fofoOrderId, String serialNumber, Integer stateId) throws ProfitMandiBusinessException {
1612
    private FofoOrderItem getDummyFofoOrderItem(int itemId, int fofoOrderId, String serialNumber, Integer stateId) throws
-
 
1613
            ProfitMandiBusinessException {
1551
        Item item = itemRepository.selectById(itemId);
1614
        Item item = itemRepository.selectById(itemId);
1552
        TagListing tl = tagListingRepository.selectByItemId(itemId);
1615
        TagListing tl = tagListingRepository.selectByItemId(itemId);
1553
        FofoOrderItem fofoOrderItem = new FofoOrderItem();
1616
        FofoOrderItem fofoOrderItem = new FofoOrderItem();
1554
        fofoOrderItem.setItemId(itemId);
1617
        fofoOrderItem.setItemId(itemId);
1555
        fofoOrderItem.setQuantity(1);
1618
        fofoOrderItem.setQuantity(1);
Line 1587... Line 1650...
1587
        fofoOrderItem.setFofoLineItems(fofoLineItems);
1650
        fofoOrderItem.setFofoLineItems(fofoLineItems);
1588
 
1651
 
1589
        return fofoOrderItem;
1652
        return fofoOrderItem;
1590
    }
1653
    }
1591
 
1654
 
1592
    private void updateCurrentInventorySnapshot(List<CurrentInventorySnapshot> currentInventorySnapshots, int fofoId, int itemId, int quantity) throws ProfitMandiBusinessException {
1655
    private void updateCurrentInventorySnapshot(List<CurrentInventorySnapshot> currentInventorySnapshots,
-
 
1656
                                                int fofoId, int itemId, int quantity) throws ProfitMandiBusinessException {
1593
        for (CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots) {
1657
        for (CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots) {
1594
            if (currentInventorySnapshot.getItemId() == itemId && currentInventorySnapshot.getFofoId() == fofoId) {
1658
            if (currentInventorySnapshot.getItemId() == itemId && currentInventorySnapshot.getFofoId() == fofoId) {
1595
                currentInventorySnapshotRepository.updateAvailabilityByItemIdAndFofoId(itemId, fofoId, currentInventorySnapshot.getAvailability() - quantity);
1659
                currentInventorySnapshotRepository.updateAvailabilityByItemIdAndFofoId(itemId, fofoId, currentInventorySnapshot.getAvailability() - quantity);
1596
            }
1660
            }
1597
        }
1661
        }
1598
    }
1662
    }
1599
 
1663
 
1600
    private void createPaymentOptions(FofoOrder fofoOrder, Set<CustomPaymentOption> customPaymentOptions) throws ProfitMandiBusinessException {
1664
    private void createPaymentOptions(FofoOrder fofoOrder, Set<CustomPaymentOption> customPaymentOptions) throws
-
 
1665
            ProfitMandiBusinessException {
1601
        for (CustomPaymentOption customPaymentOption : customPaymentOptions) {
1666
        for (CustomPaymentOption customPaymentOption : customPaymentOptions) {
1602
            if (customPaymentOption.getAmount() > 0) {
1667
            if (customPaymentOption.getAmount() > 0) {
1603
                PaymentOptionTransaction paymentOptionTransaction = new PaymentOptionTransaction();
1668
                PaymentOptionTransaction paymentOptionTransaction = new PaymentOptionTransaction();
1604
                LOGGER.error("error", fofoOrder.getId());
1669
                LOGGER.error("error", fofoOrder.getId());
1605
                paymentOptionTransaction.setReferenceId(fofoOrder.getId());
1670
                paymentOptionTransaction.setReferenceId(fofoOrder.getId());
Line 1610... Line 1675...
1610
                paymentOptionTransactionRepository.persist(paymentOptionTransaction);
1675
                paymentOptionTransactionRepository.persist(paymentOptionTransaction);
1611
            }
1676
            }
1612
        }
1677
        }
1613
    }
1678
    }
1614
 
1679
 
1615
    private FofoOrder createAndGetFofoOrder(int customerId, String customerGstNumber, int fofoId, String documentNumber, float totalAmount, int customerAddressId) {
1680
    private FofoOrder createAndGetFofoOrder(int customerId, String customerGstNumber, int fofoId, String
-
 
1681
            documentNumber, float totalAmount, int customerAddressId) {
1616
        FofoOrder fofoOrder = new FofoOrder();
1682
        FofoOrder fofoOrder = new FofoOrder();
1617
        fofoOrder.setCustomerGstNumber(customerGstNumber);
1683
        fofoOrder.setCustomerGstNumber(customerGstNumber);
1618
        fofoOrder.setCustomerId(customerId);
1684
        fofoOrder.setCustomerId(customerId);
1619
        fofoOrder.setFofoId(fofoId);
1685
        fofoOrder.setFofoId(fofoId);
1620
        fofoOrder.setInvoiceNumber(documentNumber);
1686
        fofoOrder.setInvoiceNumber(documentNumber);
Line 1622... Line 1688...
1622
        fofoOrder.setCustomerAddressId(customerAddressId);
1688
        fofoOrder.setCustomerAddressId(customerAddressId);
1623
        fofoOrderRepository.persist(fofoOrder);
1689
        fofoOrderRepository.persist(fofoOrder);
1624
        return fofoOrder;
1690
        return fofoOrder;
1625
    }
1691
    }
1626
 
1692
 
-
 
1693
    private void validateItemsSerializedNonSerialized
1627
    private void validateItemsSerializedNonSerialized(List<Item> items, Map<Integer, CustomFofoOrderItem> customFofoOrderItemMap) throws ProfitMandiBusinessException {
1694
            (List<Item> items, Map<Integer, CustomFofoOrderItem> customFofoOrderItemMap) throws
-
 
1695
            ProfitMandiBusinessException {
1628
        List<Integer> invalidItemIdSerialNumbers = new ArrayList<Integer>();
1696
        List<Integer> invalidItemIdSerialNumbers = new ArrayList<Integer>();
1629
        List<Integer> itemIdNonSerializedSerialNumbers = new ArrayList<Integer>();
1697
        List<Integer> itemIdNonSerializedSerialNumbers = new ArrayList<Integer>();
1630
        for (Item i : items) {
1698
        for (Item i : items) {
1631
            CustomFofoOrderItem customFofoOrderItem = customFofoOrderItemMap.get(i.getId());
1699
            CustomFofoOrderItem customFofoOrderItem = customFofoOrderItemMap.get(i.getId());
1632
            if (i.getType().equals(ItemType.SERIALIZED)) {
1700
            if (i.getType().equals(ItemType.SERIALIZED)) {
Line 1652... Line 1720...
1652
            // itemId's are non serialized you are saying these are serialized
1720
            // itemId's are non serialized you are saying these are serialized
1653
            throw new ProfitMandiBusinessException("itemIdNonSerializedSerialNumbers", itemIdNonSerializedSerialNumbers, "FFORDR_1014");
1721
            throw new ProfitMandiBusinessException("itemIdNonSerializedSerialNumbers", itemIdNonSerializedSerialNumbers, "FFORDR_1014");
1654
        }
1722
        }
1655
    }
1723
    }
1656
 
1724
 
-
 
1725
    private void validateCurrentInventorySnapshotQuantities
1657
    private void validateCurrentInventorySnapshotQuantities(List<CurrentInventorySnapshot> currentInventorySnapshots, Map<Integer, CustomFofoOrderItem> itemIdCustomFofoOrderItemMap) throws ProfitMandiBusinessException {
1726
            (List<CurrentInventorySnapshot> currentInventorySnapshots, Map<Integer, CustomFofoOrderItem> itemIdCustomFofoOrderItemMap) throws
-
 
1727
            ProfitMandiBusinessException {
1658
        if (itemIdCustomFofoOrderItemMap.keySet().size() != currentInventorySnapshots.size()) {
1728
        if (itemIdCustomFofoOrderItemMap.keySet().size() != currentInventorySnapshots.size()) {
1659
            throw new ProfitMandiBusinessException("quantiiesSize", currentInventorySnapshots.size(), "");
1729
            throw new ProfitMandiBusinessException("quantiiesSize", currentInventorySnapshots.size(), "");
1660
        }
1730
        }
1661
        List<ItemIdQuantityAvailability> itemIdQuantityAvailabilities = new ArrayList<>(); // this is for error
1731
        List<ItemIdQuantityAvailability> itemIdQuantityAvailabilities = new ArrayList<>(); // this is for error
1662
        LOGGER.info("currentInventorySnapshots " + currentInventorySnapshots);
1732
        LOGGER.info("currentInventorySnapshots " + currentInventorySnapshots);
Line 1680... Line 1750...
1680
            LOGGER.error("Requested quantities should not be greater than currently available quantities {}", itemIdQuantityAvailabilities);
1750
            LOGGER.error("Requested quantities should not be greater than currently available quantities {}", itemIdQuantityAvailabilities);
1681
            throw new ProfitMandiBusinessException("itemIdQuantityAvailabilities", itemIdQuantityAvailabilities, "FFORDR_1015");
1751
            throw new ProfitMandiBusinessException("itemIdQuantityAvailabilities", itemIdQuantityAvailabilities, "FFORDR_1015");
1682
        }
1752
        }
1683
    }
1753
    }
1684
 
1754
 
1685
    private int getItemIdFromSerialNumber(Map<Integer, CustomFofoOrderItem> itemIdCustomFofoOrderItemMap, String serialNumber) {
1755
    private int getItemIdFromSerialNumber(Map<Integer, CustomFofoOrderItem> itemIdCustomFofoOrderItemMap, String
-
 
1756
            serialNumber) {
1686
        int itemId = 0;
1757
        int itemId = 0;
1687
        for (Map.Entry<Integer, CustomFofoOrderItem> entry : itemIdCustomFofoOrderItemMap.entrySet()) {
1758
        for (Map.Entry<Integer, CustomFofoOrderItem> entry : itemIdCustomFofoOrderItemMap.entrySet()) {
1688
            Set<SerialNumberDetail> serialNumberDetails = entry.getValue().getSerialNumberDetails();
1759
            Set<SerialNumberDetail> serialNumberDetails = entry.getValue().getSerialNumberDetails();
1689
            for (SerialNumberDetail serialNumberDetail : serialNumberDetails) {
1760
            for (SerialNumberDetail serialNumberDetail : serialNumberDetails) {
1690
                if (serialNumberDetail.getSerialNumber().equals(serialNumber)) {
1761
                if (serialNumberDetail.getSerialNumber().equals(serialNumber)) {
Line 1752... Line 1823...
1752
        customAddress.setCountry(customerAddress.getCountry());
1823
        customAddress.setCountry(customerAddress.getCountry());
1753
        customAddress.setPhoneNumber(customerAddress.getPhoneNumber());
1824
        customAddress.setPhoneNumber(customerAddress.getPhoneNumber());
1754
        return customAddress;
1825
        return customAddress;
1755
    }
1826
    }
1756
 
1827
 
1757
    private CustomAddress createCustomAddressWithoutId(CustomCustomer customerAddress, CustomAddress retailerAddress) {
1828
    private CustomAddress createCustomAddressWithoutId(CustomCustomer customerAddress, CustomAddress
-
 
1829
            retailerAddress) {
1758
        CustomAddress customAddress = new CustomAddress();
1830
        CustomAddress customAddress = new CustomAddress();
1759
        customAddress.setName(customerAddress.getFirstName());
1831
        customAddress.setName(customerAddress.getFirstName());
1760
        customAddress.setLastName(customerAddress.getLastName());
1832
        customAddress.setLastName(customerAddress.getLastName());
1761
        customAddress.setLine1("");
1833
        customAddress.setLine1("");
1762
        customAddress.setLine2("");
1834
        customAddress.setLine2("");
Line 1767... Line 1839...
1767
        customAddress.setCountry("");
1839
        customAddress.setCountry("");
1768
        customAddress.setPhoneNumber(customerAddress.getMobileNumber());
1840
        customAddress.setPhoneNumber(customerAddress.getMobileNumber());
1769
        return customAddress;
1841
        return customAddress;
1770
    }
1842
    }
1771
 
1843
 
1772
    private void validatePaymentOptionsAndTotalAmount(Set<CustomPaymentOption> customPaymentOptions, float totalAmount) throws ProfitMandiBusinessException {
1844
    private void validatePaymentOptionsAndTotalAmount(Set<CustomPaymentOption> customPaymentOptions,
-
 
1845
                                                      float totalAmount) throws ProfitMandiBusinessException {
1773
        Set<Integer> paymentOptionIds = new HashSet<>();
1846
        Set<Integer> paymentOptionIds = new HashSet<>();
1774
 
1847
 
1775
        float calculatedAmount = 0;
1848
        float calculatedAmount = 0;
1776
        for (CustomPaymentOption customPaymentOption : customPaymentOptions) {
1849
        for (CustomPaymentOption customPaymentOption : customPaymentOptions) {
1777
            paymentOptionIds.add(customPaymentOption.getPaymentOptionId());
1850
            paymentOptionIds.add(customPaymentOption.getPaymentOptionId());
Line 1815... Line 1888...
1815
            }
1888
            }
1816
        };
1889
        };
1817
        return fofoOrderItems.stream().map(fofoOrderItemToFofoOrderItemIdFunction).collect(Collectors.toSet());
1890
        return fofoOrderItems.stream().map(fofoOrderItemToFofoOrderItemIdFunction).collect(Collectors.toSet());
1818
    }
1891
    }
1819
 
1892
 
1820
    private Map<Integer, Set<FofoLineItem>> toFofoOrderItemIdFofoLineItems(List<FofoOrderItem> fofoOrderItems) throws ProfitMandiBusinessException {
1893
    private Map<Integer, Set<FofoLineItem>> toFofoOrderItemIdFofoLineItems(List<FofoOrderItem> fofoOrderItems) throws
-
 
1894
            ProfitMandiBusinessException {
1821
        Set<Integer> fofoOrderItemIds = this.toFofoOrderItemIds(fofoOrderItems);
1895
        Set<Integer> fofoOrderItemIds = this.toFofoOrderItemIds(fofoOrderItems);
1822
        List<FofoLineItem> fofoLineItems = fofoLineItemRepository.selectByFofoOrderItemIds(fofoOrderItemIds);
1896
        List<FofoLineItem> fofoLineItems = fofoLineItemRepository.selectByFofoOrderItemIds(fofoOrderItemIds);
1823
        Map<Integer, Set<FofoLineItem>> fofoOrderItemIdFofoLineItemsMap = new HashMap<>();
1897
        Map<Integer, Set<FofoLineItem>> fofoOrderItemIdFofoLineItemsMap = new HashMap<>();
1824
        for (FofoLineItem fofoLineItem : fofoLineItems) {
1898
        for (FofoLineItem fofoLineItem : fofoLineItems) {
1825
            if (!fofoOrderItemIdFofoLineItemsMap.containsKey(fofoLineItem.getFofoOrderItemId())) {
1899
            if (!fofoOrderItemIdFofoLineItemsMap.containsKey(fofoLineItem.getFofoOrderItemId())) {
Line 1832... Line 1906...
1832
        }
1906
        }
1833
        return fofoOrderItemIdFofoLineItemsMap;
1907
        return fofoOrderItemIdFofoLineItemsMap;
1834
    }
1908
    }
1835
 
1909
 
1836
    @Override
1910
    @Override
1837
    public void updateCustomerDetails(CustomCustomer customCustomer, String invoiceNumber) throws ProfitMandiBusinessException {
1911
    public void updateCustomerDetails(CustomCustomer customCustomer, String invoiceNumber) throws
-
 
1912
            ProfitMandiBusinessException {
1838
        FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
1913
        FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
1839
        Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
1914
        Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
1840
        customer.setFirstName(customCustomer.getFirstName());
1915
        customer.setFirstName(customCustomer.getFirstName());
1841
        customer.setLastName(customCustomer.getLastName());
1916
        customer.setLastName(customCustomer.getLastName());
1842
        customer.setMobileNumber(customCustomer.getMobileNumber());
1917
        customer.setMobileNumber(customCustomer.getMobileNumber());
Line 1849... Line 1924...
1849
        }
1924
        }
1850
        this.setCustomerAddress(customerAddress, customCustomer.getAddress());
1925
        this.setCustomerAddress(customerAddress, customCustomer.getAddress());
1851
        fofoOrder.setCustomerGstNumber(customCustomer.getGstNumber());
1926
        fofoOrder.setCustomerGstNumber(customCustomer.getGstNumber());
1852
    }
1927
    }
1853
 
1928
 
1854
    private void resetTaxation(int fofoId, CustomerAddress customerAddress, List<FofoOrderItem> fofoOrderItems) throws ProfitMandiBusinessException {
1929
    private void resetTaxation(int fofoId, CustomerAddress customerAddress, List<FofoOrderItem> fofoOrderItems) throws
-
 
1930
            ProfitMandiBusinessException {
1855
        int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(fofoId);
1931
        int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(fofoId);
1856
 
1932
 
1857
        Address retailerAddress = addressRepository.selectById(retailerAddressId);
1933
        Address retailerAddress = addressRepository.selectById(retailerAddressId);
1858
 
1934
 
1859
        Integer stateId = null;
1935
        Integer stateId = null;
Line 1878... Line 1954...
1878
            fofoOrderItem.setIgstRate(rate.getIgstRate());
1954
            fofoOrderItem.setIgstRate(rate.getIgstRate());
1879
        }
1955
        }
1880
    }
1956
    }
1881
 
1957
 
1882
    @Override
1958
    @Override
1883
    public CustomerCreditNote badReturn(int fofoId, FoiBadReturnRequest foiBadReturnRequest) throws ProfitMandiBusinessException {
1959
    public CustomerCreditNote badReturn(int fofoId, FoiBadReturnRequest foiBadReturnRequest) throws
-
 
1960
            ProfitMandiBusinessException {
1884
        FofoOrderItem foi = fofoOrderItemRepository.selectById(foiBadReturnRequest.getFofoOrderItemId());
1961
        FofoOrderItem foi = fofoOrderItemRepository.selectById(foiBadReturnRequest.getFofoOrderItemId());
1885
        FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(foi.getOrderId());
1962
        FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(foi.getOrderId());
1886
        if (fofoOrder.getFofoId() != fofoId) {
1963
        if (fofoOrder.getFofoId() != fofoId) {
1887
            throw new ProfitMandiBusinessException("Partner Auth", "", "Invalid Order");
1964
            throw new ProfitMandiBusinessException("Partner Auth", "", "Invalid Order");
1888
        }
1965
        }
Line 1912... Line 1989...
1912
        fofoOrder.setCancelledTimestamp(LocalDateTime.now());
1989
        fofoOrder.setCancelledTimestamp(LocalDateTime.now());
1913
        this.reverseScheme(fofoOrder);
1990
        this.reverseScheme(fofoOrder);
1914
        return creditNote;
1991
        return creditNote;
1915
    }
1992
    }
1916
 
1993
 
-
 
1994
    private CustomerCreditNote generateCreditNote(FofoOrder
1917
    private CustomerCreditNote generateCreditNote(FofoOrder fofoOrder, List<CustomerReturnItem> customerReturnItems) throws ProfitMandiBusinessException {
1995
                                                          fofoOrder, List<CustomerReturnItem> customerReturnItems) throws ProfitMandiBusinessException {
1918
 
1996
 
1919
        InvoiceNumberGenerationSequence sequence = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoOrder.getFofoId());
1997
        InvoiceNumberGenerationSequence sequence = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoOrder.getFofoId());
1920
        sequence.setCreditNoteSequence(sequence.getCreditNoteSequence() + 1);
1998
        sequence.setCreditNoteSequence(sequence.getCreditNoteSequence() + 1);
1921
        invoiceNumberGenerationSequenceRepository.persist(sequence);
1999
        invoiceNumberGenerationSequenceRepository.persist(sequence);
1922
 
2000
 
Line 1942... Line 2020...
1942
    public CreditNotePdfModel getCreditNotePdfModel(int customerCreditNoteId) throws ProfitMandiBusinessException {
2020
    public CreditNotePdfModel getCreditNotePdfModel(int customerCreditNoteId) throws ProfitMandiBusinessException {
1943
        CustomerCreditNote creditNote = customerCreditNoteRepository.selectById(customerCreditNoteId);
2021
        CustomerCreditNote creditNote = customerCreditNoteRepository.selectById(customerCreditNoteId);
1944
        return getCreditNotePdfModel(creditNote);
2022
        return getCreditNotePdfModel(creditNote);
1945
    }
2023
    }
1946
 
2024
 
1947
    private CreditNotePdfModel getCreditNotePdfModel(CustomerCreditNote creditNote) throws ProfitMandiBusinessException {
2025
    private CreditNotePdfModel getCreditNotePdfModel(CustomerCreditNote creditNote) throws
-
 
2026
            ProfitMandiBusinessException {
1948
        FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(creditNote.getFofoOrderId());
2027
        FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(creditNote.getFofoOrderId());
1949
        List<CustomerReturnItem> customerReturnItems = customerReturnItemRepository.selectAllByCreditNoteId(creditNote.getId());
2028
        List<CustomerReturnItem> customerReturnItems = customerReturnItemRepository.selectAllByCreditNoteId(creditNote.getId());
1950
        CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoOrder.getFofoId());
2029
        CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoOrder.getFofoId());
1951
        CustomCustomer customCustomer = getCustomCustomer(fofoOrder, customRetailer.getAddress());
2030
        CustomCustomer customCustomer = getCustomCustomer(fofoOrder, customRetailer.getAddress());
1952
 
2031
 
Line 2189... Line 2268...
2189
            }
2268
            }
2190
        }
2269
        }
2191
    }
2270
    }
2192
 
2271
 
2193
    @Override
2272
    @Override
2194
    public boolean refundOrder(int orderId, String refundedBy, String refundReason) throws ProfitMandiBusinessException {
2273
    public boolean refundOrder(int orderId, String refundedBy, String refundReason) throws
-
 
2274
            ProfitMandiBusinessException {
2195
        /*def refund_order(order_id, refunded_by, reason):
2275
        /*def refund_order(order_id, refunded_by, reason):
2196
        """
2276
        """
2197
        If the order is in RTO_RECEIVED_PRESTINE, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
2277
        If the order is in RTO_RECEIVED_PRESTINE, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
2198
            1. Creates a refund request for batch processing.
2278
            1. Creates a refund request for batch processing.
2199
            2. Creates a return order for the warehouse executive to return the shipped material.
2279
            2. Creates a return order for the warehouse executive to return the shipped material.