Subversion Repositories SmartDukaan

Rev

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

Rev 33399 Rev 33436
Line 13... Line 13...
13
import com.spice.profitmandi.common.util.Utils;
13
import com.spice.profitmandi.common.util.Utils;
14
import com.spice.profitmandi.common.web.client.RestClient;
14
import com.spice.profitmandi.common.web.client.RestClient;
15
import com.spice.profitmandi.common.web.util.ResponseSender;
15
import com.spice.profitmandi.common.web.util.ResponseSender;
16
import com.spice.profitmandi.dao.entity.catalog.Item;
16
import com.spice.profitmandi.dao.entity.catalog.Item;
17
import com.spice.profitmandi.dao.entity.catalog.TagListing;
17
import com.spice.profitmandi.dao.entity.catalog.TagListing;
18
import com.spice.profitmandi.dao.entity.dtr.ScratchOffer;
-
 
19
import com.spice.profitmandi.dao.entity.dtr.User;
18
import com.spice.profitmandi.dao.entity.dtr.*;
20
import com.spice.profitmandi.dao.entity.dtr.WebListing;
-
 
21
import com.spice.profitmandi.dao.entity.dtr.WebOffer;
-
 
22
import com.spice.profitmandi.dao.entity.fofo.*;
19
import com.spice.profitmandi.dao.entity.fofo.*;
23
import com.spice.profitmandi.dao.entity.inventory.State;
20
import com.spice.profitmandi.dao.entity.inventory.State;
24
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
21
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
25
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
22
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
26
import com.spice.profitmandi.dao.enumuration.dtr.WebListingSource;
23
import com.spice.profitmandi.dao.enumuration.dtr.WebListingSource;
27
import com.spice.profitmandi.dao.enumuration.inventory.ScratchedGift;
24
import com.spice.profitmandi.dao.enumuration.inventory.ScratchedGift;
28
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
25
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
29
import com.spice.profitmandi.dao.model.*;
26
import com.spice.profitmandi.dao.model.*;
-
 
27
import com.spice.profitmandi.dao.model.pendingOrder.PendingOrderDetail;
30
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
28
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
31
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
29
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
32
import com.spice.profitmandi.dao.repository.cs.CsService;
30
import com.spice.profitmandi.dao.repository.cs.CsService;
33
import com.spice.profitmandi.dao.repository.dtr.*;
31
import com.spice.profitmandi.dao.repository.dtr.*;
34
import com.spice.profitmandi.dao.repository.fofo.*;
32
import com.spice.profitmandi.dao.repository.fofo.*;
Line 202... Line 200...
202
 
200
 
203
    @Autowired
201
    @Autowired
204
    private OrderService orderService;
202
    private OrderService orderService;
205
 
203
 
206
    @Autowired
204
    @Autowired
-
 
205
    InsurancePolicyRepository insurancePolicyRepository;
-
 
206
 
-
 
207
    @Autowired
-
 
208
    PendingOrderPlanRepository pendingOrderPlanRepository;
-
 
209
 
-
 
210
    @Autowired
207
    private ScratchOfferRepository scratchOfferRepository;
211
    private ScratchOfferRepository scratchOfferRepository;
208
    private static final List<String> offlineOrders = Arrays.asList("EMIOD", "POD");
212
    private static final List<String> offlineOrders = Arrays.asList("EMIOD", "POD");
209
 
213
 
210
    List<String> filterableParams = Arrays.asList("brand");
214
    List<String> filterableParams = Arrays.asList("brand");
211
 
215
 
Line 342... Line 346...
342
        customer.setLastName(userModel.getLastName());
346
        customer.setLastName(userModel.getLastName());
343
        customer.setMobileNumber(userModel.getMobile());
347
        customer.setMobileNumber(userModel.getMobile());
344
        return responseSender.ok(customerService.addCustomer(customer));
348
        return responseSender.ok(customerService.addCustomer(customer));
345
    }
349
    }
346
 
350
 
347
    @RequestMapping(value = "/checkplans", method = RequestMethod.GET)
351
        @RequestMapping(value = "/store/checkplans", method = RequestMethod.GET)
348
    public String getInsurancePrices(HttpServletRequest request, @RequestParam float price, Model model,
352
    public ResponseEntity<?> getInsurancePrices(HttpServletRequest request, @RequestParam float price, Model model,
349
                                     @RequestParam int itemId) throws ProfitMandiBusinessException {
353
                                     @RequestParam int itemId) throws ProfitMandiBusinessException {
350
        logger.info("Request received at url : {}", request.getRequestURI());
354
        logger.info("Request received at url : {}", request.getRequestURI());
351
 
355
 
352
        try {
356
        try {
353
            String response = String.valueOf(responseSender.ok(this.getPlans(price, itemId)));
357
            Map<String, List<MobileInsurancePlan>> response = this.getPlans(price, itemId);
-
 
358
            List<MobileInsurancePlan> combinedPlans = new ArrayList<>();
-
 
359
            for (List<MobileInsurancePlan> plans : response.values()) {
-
 
360
                combinedPlans.addAll(plans);
-
 
361
            }
354
            return response;
362
            return responseSender.ok(combinedPlans);
355
        } catch (Exception e) {
363
        } catch (Exception e) {
356
            logger.info(e.getMessage(), e);
364
            logger.info(e.getMessage(), e);
357
            throw new ProfitMandiBusinessException("Plans", "Plans API", "Error formatting insurance plans");
365
            throw new ProfitMandiBusinessException("Plans", "Plans API", "Error formatting insurance plans");
358
        }
366
        }
359
 
367
 
360
 
-
 
361
    }
368
    }
362
 
369
 
363
    @Autowired
370
    @Autowired
364
    InsuranceService insuranceService;
371
    InsuranceService insuranceService;
365
 
372
 
366
    private Map<String, List<MobileInsurancePlan>> getPlans(float sellingPrice, int itemId)
373
    private Map<String, List<MobileInsurancePlan>> getPlans(float sellingPrice, int itemId)
367
            throws ProfitMandiBusinessException {
374
            throws ProfitMandiBusinessException {
368
        try {
375
        try {
369
            Map<String, List<MobileInsurancePlan>> productDurationPlans = insuranceService.getAllPlans(itemId,
376
            Map<String, List<MobileInsurancePlan>> productDurationPlans = insuranceService.getAllPlans(itemId, sellingPrice,true);
370
                    sellingPrice);
-
 
371
            return productDurationPlans;
377
            return productDurationPlans;
372
        } catch (Exception e) {
378
        } catch (Exception e) {
373
            logger.info(e, e);
379
            logger.info(e, e);
374
            throw new ProfitMandiBusinessException("Fetch Insurance Plans", "Insurance",
380
            throw new ProfitMandiBusinessException("Fetch Insurance Plans", "Insurance",
375
                    "Could not fetch insurance Plans");
381
                    "Could not fetch insurance Plans");
Line 387... Line 393...
387
        pendingOrderItems.stream().forEach(x -> {
393
        pendingOrderItems.stream().forEach(x -> {
388
            CartItem ci = new CartItem();
394
            CartItem ci = new CartItem();
389
            ci.setItemId(x.getItemId());
395
            ci.setItemId(x.getItemId());
390
            ci.setQuantity(x.getQuantity());
396
            ci.setQuantity(x.getQuantity());
391
            ci.setSellingPrice(x.getSellingPrice());
397
            ci.setSellingPrice(x.getSellingPrice());
392
            ci.setExtendedWarrantyPrice(x.getExtendedWarrantyPrice());
398
            ci.setPendingOrderItemPolicyPlan(x.getPendingOrderItemPolicyPlan());
393
            cartItems.add(ci);
399
            cartItems.add(ci);
394
        });
400
        });
395
        logger.info("cartItems {}",cartItems);
401
        logger.info("cartItems {}",cartItems);
396
        CartResponse cr = this.validateCart(storeId, cartItems);
402
        CartResponse cr = this.validateCart(storeId, cartItems);
397
        if (cr.getCartMessageChanged() > 0 || cr.getTotalAmount() != createPendingOrderRequest.getTotalAmount()) {
403
        if (cr.getCartMessageChanged() > 0 || cr.getTotalAmount() != createPendingOrderRequest.getTotalAmount()) {
Line 584... Line 590...
584
 
590
 
585
        logger.info("customerRetailers" + customerRetailers);
591
        logger.info("customerRetailers" + customerRetailers);
586
        return responseSender.ok(customerRetailers);
592
        return responseSender.ok(customerRetailers);
587
    }
593
    }
588
 
594
 
-
 
595
 
589
    @RequestMapping(value = "/store/order", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
596
    @RequestMapping(value = "/store/order", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
590
    public ResponseEntity<?> getOrderDetail(HttpServletRequest request, @RequestParam(value = "id") int id, @RequestParam(name = "offset") int offset, @RequestParam(name = "limit") int limit) throws Exception {
597
    public ResponseEntity<?> getOrderDetail(HttpServletRequest request, @RequestParam(value = "id") int id, @RequestParam(name = "offset") int offset, @RequestParam(name = "limit") int limit) throws Exception {
-
 
598
 
591
        List<CustomerOrderDetail> customerOrderDetails = new ArrayList<>();
599
        List<PendingOrderDetail> pendingOrderDetails = new ArrayList<>();
592
        List<Integer> catalogIds = new ArrayList<>();
600
        List<Integer> catalogIds = new ArrayList<>();
593
        List<PendingOrder> pendingOrders = pendingOrderRepository.selectByCustomerId(id, offset, limit);
601
        List<PendingOrder> pendingOrders = pendingOrderRepository.selectByCustomerId(id, offset, limit);
594
 
602
 
595
        if (!pendingOrders.isEmpty()) {
603
        if (!pendingOrders.isEmpty()) {
596
            for (PendingOrder po : pendingOrders) {
604
            for (PendingOrder po : pendingOrders) {
Line 603... Line 611...
603
 
611
 
604
                Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
612
                Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
605
 
613
 
606
                for (PendingOrderItem poi : pois) {
614
                for (PendingOrderItem poi : pois) {
607
 
615
 
608
                    CustomerOrderDetail customerOrderDetail = new CustomerOrderDetail();
616
                    PendingOrderDetail pendingOrderDetail = new PendingOrderDetail();
609
 
617
 
610
                    Item item = itemRepository.selectById(poi.getItemId());
618
                    Item item = itemRepository.selectById(poi.getItemId());
611
                    JSONObject jsonObj = contentMap.get(item.getCatalogItemId());
619
                    JSONObject jsonObj = contentMap.get(item.getCatalogItemId());
612
                    customerOrderDetail.setImageUrl(jsonObj.getString("imageUrl_s"));
620
                    pendingOrderDetail.setImageUrl(jsonObj.getString("imageUrl_s"));
613
                    customerOrderDetail.setBrand(item.getBrand());
621
                    pendingOrderDetail.setBrand(item.getBrand());
614
                    customerOrderDetail.setColor(item.getColor());
622
                    pendingOrderDetail.setColor(item.getColor());
615
                    customerOrderDetail.setPendingOrderItemId(poi.getId());
623
                    pendingOrderDetail.setPendingOrderItemId(poi.getId());
616
                    customerOrderDetail.setId(poi.getOrderId());
624
                    pendingOrderDetail.setId(poi.getOrderId());
617
                    customerOrderDetail.setItemId(poi.getItemId());
625
                    pendingOrderDetail.setItemId(poi.getItemId());
618
                    customerOrderDetail.setModelName(item.getModelName());
626
                    pendingOrderDetail.setModelName(item.getModelName());
619
                    customerOrderDetail.setModelNumber(item.getModelNumber());
627
                    pendingOrderDetail.setModelNumber(item.getModelNumber());
620
                    customerOrderDetail.setQuantity(poi.getQuantity());
628
                    pendingOrderDetail.setQuantity(poi.getQuantity());
621
                    customerOrderDetail.setBilledTimestamp(poi.getBilledTimestamp());
629
                    pendingOrderDetail.setBilledTimestamp(poi.getBilledTimestamp());
622
                    customerOrderDetail.setStatus(poi.getStatus());
630
                    pendingOrderDetail.setStatus(poi.getStatus());
623
                    customerOrderDetail.setTotalPrice(poi.getSellingPrice());
631
                    pendingOrderDetail.setTotalPrice(poi.getSellingPrice());
624
                    customerOrderDetail.setPayMethod(po.getPayMethod());
632
                    pendingOrderDetail.setPayMethod(po.getPayMethod());
625
                    customerOrderDetail.setCreatedTimeStamp(po.getCreateTimestamp());
633
                    pendingOrderDetail.setCreatedTimeStamp(po.getCreateTimestamp());
-
 
634
                    pendingOrderDetail.setPendingOrderPlan(pendingOrderPlanRepository.selectByPoid(poi.getId()));
626
                    customerOrderDetails.add(customerOrderDetail);
635
                    pendingOrderDetails.add(pendingOrderDetail);
627
                }
636
                }
628
            }
637
            }
629
        }
638
        }
630
 
639
 
631
        return responseSender.ok(customerOrderDetails);
640
        return responseSender.ok(pendingOrderDetails);
632
    }
641
    }
633
 
642
 
634
    @RequestMapping(value = "/store/invoiceOrder", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
643
    @RequestMapping(value = "/store/invoiceOrder", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
635
    public ResponseEntity<?> getOrderInvoiceDetail(HttpServletRequest request, @RequestParam(value = "id") int id, @RequestParam(name = "offset") int offset, @RequestParam(name = "limit") int limit) throws Exception {
644
    public ResponseEntity<?> getOrderInvoiceDetail(HttpServletRequest request, @RequestParam(value = "id") int id, @RequestParam(name = "offset") int offset, @RequestParam(name = "limit") int limit) throws Exception {
636
        List<CustomerOrderDetail> customerOrderDetails = new ArrayList<>();
645
        List<CustomerOrderAndInsuranceDetails> customerOrderAndInsuranceDetails = new ArrayList<>();
637
        List<Integer> catalogIds = new ArrayList<>();
646
        List<Integer> catalogIds = new ArrayList<>();
638
        List<FofoOrder> fofoOrders = fofoOrderRepository.selectOrderByCustomerId(id, offset, limit);
647
        List<FofoOrder> fofoOrders = fofoOrderRepository.selectOrderByCustomerId(id, offset, limit);
639
 
648
 
640
        if (!fofoOrders.isEmpty()) {
649
        if (!fofoOrders.isEmpty()) {
641
            for (FofoOrder fo : fofoOrders) {
650
            for (FofoOrder fo : fofoOrders) {
Line 646... Line 655...
646
                    catalogIds.add(item.getCatalogItemId());
655
                    catalogIds.add(item.getCatalogItemId());
647
                }
656
                }
648
 
657
 
649
                Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
658
                Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
650
                for (FofoOrderItem foi : fofoOrderItems) {
659
                for (FofoOrderItem foi : fofoOrderItems) {
651
 
-
 
652
                    CustomerOrderDetail customerOrderDetail = new CustomerOrderDetail();
660
                    CustomerOrderAndInsuranceDetails customerOrderDetail = new CustomerOrderAndInsuranceDetails();
653
 
-
 
654
                    Item item = itemRepository.selectById(foi.getItemId());
661
                    Item item = itemRepository.selectById(foi.getItemId());
655
                    JSONObject jsonObj = contentMap.get(item.getCatalogItemId());
662
                    JSONObject jsonObj = contentMap.get(item.getCatalogItemId());
656
                    customerOrderDetail.setImageUrl(jsonObj.getString("imageUrl_s"));
663
                    customerOrderDetail.setImageUrl(jsonObj.getString("imageUrl_s"));
657
                    customerOrderDetail.setBrand(item.getBrand());
664
                    customerOrderDetail.setBrand(item.getBrand());
658
                    customerOrderDetail.setColor(item.getColor());
665
                    customerOrderDetail.setColor(item.getColor());
Line 664... Line 671...
664
                    customerOrderDetail.setQuantity(foi.getQuantity());
671
                    customerOrderDetail.setQuantity(foi.getQuantity());
665
                    customerOrderDetail.setTotalPrice(foi.getSellingPrice());
672
                    customerOrderDetail.setTotalPrice(foi.getSellingPrice());
666
                    customerOrderDetail.setCreatedTimeStamp(foi.getCreateTimestamp());
673
                    customerOrderDetail.setCreatedTimeStamp(foi.getCreateTimestamp());
667
                    customerOrderDetail.setInvoiceNumber(fo.getInvoiceNumber());
674
                    customerOrderDetail.setInvoiceNumber(fo.getInvoiceNumber());
668
                    customerOrderDetail.setCancelledTimestamp(fo.getCancelledTimestamp());
675
                    customerOrderDetail.setCancelledTimestamp(fo.getCancelledTimestamp());
-
 
676
                    customerOrderDetail.setInsurancePolicies(insurancePolicyRepository.selectByRetailerIdInvoiceNumber(fo.getInvoiceNumber()));
669
                    customerOrderDetails.add(customerOrderDetail);
677
                    customerOrderAndInsuranceDetails.add(customerOrderDetail);
670
                }
678
                }
-
 
679
 
671
            }
680
            }
672
 
681
 
673
        }
682
        }
674
        return responseSender.ok(customerOrderDetails);
683
        return responseSender.ok(customerOrderAndInsuranceDetails);
675
    }
684
    }
676
 
685
 
677
    @RequestMapping(value = "/store/generateInvoice", method = RequestMethod.GET)
686
    @RequestMapping(value = "/store/generateInvoice", method = RequestMethod.GET)
678
    public ResponseEntity<?> generateInvoice(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws ProfitMandiBusinessException {
687
    public ResponseEntity<?> generateInvoice(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws ProfitMandiBusinessException {
679
        InvoicePdfModel pdfModel = null;
688
        InvoicePdfModel pdfModel = null;
Line 786... Line 795...
786
        return responseSender.ok(vc);
795
        return responseSender.ok(vc);
787
    }
796
    }
788
 
797
 
789
    // Validate Cart for B2C Customers
798
    // Validate Cart for B2C Customers
790
    private CartResponse validateCart(int storeId, List<CartItem> cartItems) throws Exception {
799
    private CartResponse validateCart(int storeId, List<CartItem> cartItems) throws Exception {
-
 
800
 
-
 
801
        logger.info("cartItems {}",cartItems);
791
        cartItems = cartItems.stream().filter(x -> x.getQuantity() > 0).collect(Collectors.toList());
802
        cartItems = cartItems.stream().filter(x -> x.getQuantity() > 0).collect(Collectors.toList());
792
        List<Integer> itemIds = cartItems.stream().map(x -> x.getItemId()).collect(Collectors.toList());
803
        List<Integer> itemIds = cartItems.stream().map(x -> x.getItemId()).collect(Collectors.toList());
793
        Map<Integer, AvailabilityModel> inventoryItemAvailabilityMap = inventoryService.getStoreAndOurStock(storeId, itemIds);
804
        Map<Integer, AvailabilityModel> inventoryItemAvailabilityMap = inventoryService.getStoreAndOurStock(storeId, itemIds);
794
        CartResponse cartResponse = new CartResponse();
805
        CartResponse cartResponse = new CartResponse();
795
        List<CartItemResponseModel> cartItemResponseModels = new ArrayList<>();
806
        List<CartItemResponseModel> cartItemResponseModels = new ArrayList<>();
Line 818... Line 829...
818
                    .get(itemsMap.get(cartItem.getItemId()).getCatalogItemId());
829
                    .get(itemsMap.get(cartItem.getItemId()).getCatalogItemId());
819
            cashback = cashback == null ? 0 : cashback;
830
            cashback = cashback == null ? 0 : cashback;
820
            float itemSellingPrice = tagListing.getMop() - cashback;
831
            float itemSellingPrice = tagListing.getMop() - cashback;
821
            CartItemResponseModel cartItemResponseModel = new CartItemResponseModel();
832
            CartItemResponseModel cartItemResponseModel = new CartItemResponseModel();
822
            cartItemResponseModel.setSellingPrice(cartItem.getSellingPrice());
833
            cartItemResponseModel.setSellingPrice(cartItem.getSellingPrice());
823
            cartItemResponseModel.setExtendedWarrantyPrice(cartItem.getExtendedWarrantyPrice());
834
            cartItemResponseModel.setPendingOrderItemPolicyPlan(cartItem.getPendingOrderItemPolicyPlan());
824
            if (itemSellingPrice != cartItem.getSellingPrice()) {
835
            if (itemSellingPrice != cartItem.getSellingPrice()) {
825
                cartItemResponseModel.setSellingPrice(itemSellingPrice);
836
                cartItemResponseModel.setSellingPrice(itemSellingPrice);
826
                cartMessageChanged++;
837
                cartMessageChanged++;
827
            }
838
            }
828
            int estimate = -2;
839
            int estimate = -2;
Line 850... Line 861...
850
            if (estimate >= 0 && LocalTime.now().isAfter(CUTOFF_TIME)) {
861
            if (estimate >= 0 && LocalTime.now().isAfter(CUTOFF_TIME)) {
851
                estimate = estimate + 1;
862
                estimate = estimate + 1;
852
                promiseDeliveryTime = promiseDeliveryTime.plusDays(3);
863
                promiseDeliveryTime = promiseDeliveryTime.plusDays(3);
853
            }
864
            }
854
            totalQty += qtyRequired;
865
            totalQty += qtyRequired;
-
 
866
            if(cartItem.getPendingOrderItemPolicyPlan() != null){
855
            totalAmount += qtyRequired * itemSellingPrice + cartItem.getExtendedWarrantyPrice() ;
867
                totalAmount += qtyRequired * itemSellingPrice + qtyRequired*cartItem.getPendingOrderItemPolicyPlan().getPrice() ;
-
 
868
            }else{
-
 
869
                totalAmount += qtyRequired * itemSellingPrice;
-
 
870
            }
-
 
871
 
856
            cartItemResponseModel.setEstimate(estimate);
872
            cartItemResponseModel.setEstimate(estimate);
857
            cartItemResponseModel.setTitle(item.getItemDescriptionNoColor());
873
            cartItemResponseModel.setTitle(item.getItemDescriptionNoColor());
858
            cartItemResponseModel.setItemId(cartItem.getItemId());
874
            cartItemResponseModel.setItemId(cartItem.getItemId());
859
            cartItemResponseModel.setMinBuyQuantity(1);
875
            cartItemResponseModel.setMinBuyQuantity(1);
860
            cartItemResponseModel.setQuantity(qtyRequired);
876
            cartItemResponseModel.setQuantity(qtyRequired);