Subversion Repositories SmartDukaan

Rev

Rev 35771 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35771 Rev 35775
Line 684... Line 684...
684
            model.addAttribute("item", item);
684
            model.addAttribute("item", item);
685
            model.addAttribute("schemeInOut", schemeInOuts);
685
            model.addAttribute("schemeInOut", schemeInOuts);
686
            model.addAttribute("schemes", schemes);
686
            model.addAttribute("schemes", schemes);
687
            model.addAttribute("customRetailer", customRetailer);
687
            model.addAttribute("customRetailer", customRetailer);
688
            model.addAttribute("searchImei", searchImei);
688
            model.addAttribute("searchImei", searchImei);
-
 
689
            // Return IMEI results only when modal and searchImei provided
-
 
690
            if (modal) {
-
 
691
                return "scheme-imei-results-modal";
-
 
692
            }
689
        }
693
        }
690
        if (modal) {
694
        if (modal) {
691
            return "scheme-imei-history-modal";
695
            return "scheme-imei-history-modal";
692
        }
696
        }
693
        return "scheme-imei-history";
697
        return "scheme-imei-history";
694
    }
698
    }
695
 
699
 
-
 
700
    /**
-
 
701
     * New endpoint for modal IMEI-wise margin search
-
 
702
     * Returns shell when searchImei is empty, results when searchImei is provided
-
 
703
     */
-
 
704
    @RequestMapping(value = "/getImeiMarginModal", method = RequestMethod.GET)
-
 
705
    public String getImeiMarginModal(HttpServletRequest request,
-
 
706
                                     @RequestParam(defaultValue = "") String searchImei,
-
 
707
                                     @RequestParam(name = "fofoId") int fofoId,
-
 
708
                                     Model model) throws ProfitMandiBusinessException {
-
 
709
 
-
 
710
        if (org.apache.commons.lang3.StringUtils.isEmpty(searchImei)) {
-
 
711
            // Return empty shell with search boxes
-
 
712
            return "scheme-imei-history-modal";
-
 
713
        }
-
 
714
 
-
 
715
        // Fetch IMEI margin data
-
 
716
        List<Scheme> schemes = null;
-
 
717
        List<SchemeInOut> schemeInOuts = null;
-
 
718
 
-
 
719
        InventoryItem inventoryItem = inventoryItemRepository.selectBySerialNumber(searchImei);
-
 
720
        if (inventoryItem == null) {
-
 
721
            model.addAttribute("searchImei", searchImei);
-
 
722
            return "scheme-imei-results-modal";
-
 
723
        }
-
 
724
 
-
 
725
        int itemFofoId = inventoryItem.getFofoId();
-
 
726
        List<ItemPurchaseSummaryModel> itemPurchaseSummaryModels = inventoryItemRepository.selectPurchaseSummary(new ArrayList<>(Arrays.asList(inventoryItem.getId())));
-
 
727
 
-
 
728
        List<FofoOrder> fofoOrders = fofoOrderRepository.selectByFofoIdAndSerialNumber(itemFofoId, searchImei, null, null, 0, 0);
-
 
729
        List<FofoOrder> filterOrders = fofoOrders.stream().filter(x -> x.getCancelledTimestamp() == null).collect(Collectors.toList());
-
 
730
        CustomRetailer customRetailer = retailerService.getFofoRetailer(itemFofoId);
-
 
731
        Item item = itemRepository.selectById(inventoryItem.getItemId());
-
 
732
        Map<Integer, Scheme> schemeMap = new HashMap<>();
-
 
733
        double netEarnings = 0;
-
 
734
 
-
 
735
        // Offer payout
-
 
736
        List<OfferPayout> offerPayouts = offerPayoutRepository.selectAllBySerialNumber(itemFofoId, searchImei);
-
 
737
        Map<Integer, CreateOfferRequest> offerRequestMap = offerPayouts.stream().map(x -> x.getOfferId())
-
 
738
                .distinct().map(offerId -> {
-
 
739
                    try {
-
 
740
                        return offerService.getOffer(itemFofoId, offerId.intValue());
-
 
741
                    } catch (ProfitMandiBusinessException e) {
-
 
742
                        throw new RuntimeException(e);
-
 
743
                    }
-
 
744
                }).collect(Collectors.toMap(x -> x.getId(), x -> x));
-
 
745
 
-
 
746
        schemeInOuts = schemeInOutRepository.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItem.getId())));
-
 
747
        ActivatedImei activatedImei = activatedImeiRepository.selectBySerialNumber(searchImei);
-
 
748
 
-
 
749
        if (!schemeInOuts.isEmpty()) {
-
 
750
            netEarnings += schemeInOuts.stream().filter(x -> x.getStatus().equals(SchemePayoutStatus.CREDITED)).collect(Collectors.summingDouble(x -> x.getAmount()));
-
 
751
            List<Integer> schemeIds = schemeInOuts.stream().map(x -> x.getSchemeId()).collect(Collectors.toList());
-
 
752
 
-
 
753
            schemes = schemeRepository.selectBySchemeIds(schemeIds);
-
 
754
            for (Scheme scheme : schemes) {
-
 
755
                if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
-
 
756
                    scheme.setAmountModel(scheme.getAmount() + "%");
-
 
757
                } else {
-
 
758
                    scheme.setAmountModel(scheme.getAmount() + "");
-
 
759
                }
-
 
760
            }
-
 
761
            schemeMap = schemes.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
-
 
762
        }
-
 
763
 
-
 
764
        List<PriceDropIMEI> priceDropImeis = priceDropIMEIRepository.selectByFofoIdImei(itemFofoId, searchImei);
-
 
765
        if (priceDropImeis.size() > 0) {
-
 
766
            for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
-
 
767
                int priceDropId = priceDropIMEI.getPriceDropId();
-
 
768
                PriceDrop pd = priceDropRepository.selectById(priceDropId);
-
 
769
                priceDropIMEI.setPriceDrop(pd);
-
 
770
            }
-
 
771
            model.addAttribute("priceDropImeis", priceDropImeis);
-
 
772
        }
-
 
773
 
-
 
774
        netEarnings += offerPayouts.stream().collect(Collectors.summingDouble(x -> x.getAmount()));
-
 
775
        model.addAttribute("offerPayouts", offerPayouts);
-
 
776
        model.addAttribute("offerRequestMap", offerRequestMap);
-
 
777
        model.addAttribute("inventoryItem", inventoryItem);
-
 
778
        model.addAttribute("itemPurchaseSummaryModels", itemPurchaseSummaryModels);
-
 
779
        model.addAttribute("fofoOrders", filterOrders);
-
 
780
        model.addAttribute("activatedImei", activatedImei);
-
 
781
        model.addAttribute("netEarnings", netEarnings);
-
 
782
        model.addAttribute("fofoId", itemFofoId);
-
 
783
        model.addAttribute("schemeMap", schemeMap);
-
 
784
        model.addAttribute("item", item);
-
 
785
        model.addAttribute("schemeInOut", schemeInOuts);
-
 
786
        model.addAttribute("schemes", schemes);
-
 
787
        model.addAttribute("customRetailer", customRetailer);
-
 
788
        model.addAttribute("searchImei", searchImei);
-
 
789
 
-
 
790
        return "scheme-imei-results-modal";
-
 
791
    }
-
 
792
 
-
 
793
    /**
-
 
794
     * New endpoint for modal model-wise margin search
-
 
795
     * Accepts fofoId as parameter to work for both admin and partner views
-
 
796
     */
-
 
797
    @RequestMapping(value = "/getModelMarginModal", method = RequestMethod.GET)
-
 
798
    public String getModelMarginModal(HttpServletRequest request,
-
 
799
                                      @RequestParam(name = "searchModel") int searchModel,
-
 
800
                                      @RequestParam(name = "fofoId") int fofoId,
-
 
801
                                      @RequestParam(required = false) LocalDate date,
-
 
802
                                      Model model) throws ProfitMandiBusinessException {
-
 
803
        if (date == null) {
-
 
804
            date = LocalDate.now();
-
 
805
        } else if (date.isAfter(LocalDate.now())) {
-
 
806
            date = LocalDate.now();
-
 
807
        }
-
 
808
 
-
 
809
        Item item = itemRepository.selectAllByCatalogItemId(searchModel).get(0);
-
 
810
        TagListing tagListing = tagListingRepository.selectByItemId(item.getId());
-
 
811
        if (tagListing != null) {
-
 
812
            model.addAttribute("dp", tagListing.getSellingPrice());
-
 
813
            model.addAttribute("mop", tagListing.getMop());
-
 
814
        }
-
 
815
        model.addAttribute("modelName", item.getItemDescriptionNoColor());
-
 
816
        model.addAttribute("searchModel", searchModel);
-
 
817
        model.addAttribute("date", date);
-
 
818
 
-
 
819
        PriceCircularModel priceCircularModel = priceCircularService.getPriceCircularByOffer(fofoId, Arrays.asList(searchModel), date);
-
 
820
        FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
821
        priceDropController.getPriceCircularView(priceCircularModel, model, fs.getCode());
-
 
822
 
-
 
823
        return "schemes-model-modal";
-
 
824
    }
-
 
825
 
696
 
826
 
697
    @Autowired
827
    @Autowired
698
    PriceDropController priceDropController;
828
    PriceDropController priceDropController;
699
 
829
 
700
    @Autowired
830
    @Autowired