Subversion Repositories SmartDukaan

Rev

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

Rev 32816 Rev 32892
Line 518... Line 518...
518
        }
518
        }
519
 
519
 
520
        List<FofoOrderItem> fofoItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
520
        List<FofoOrderItem> fofoItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
521
 
521
 
522
        boolean smartPhone = false;
522
        boolean smartPhone = false;
-
 
523
        float purchaseAmount = 0;
-
 
524
 
523
        for (FofoOrderItem fofoItem : fofoItems) {
525
        for (FofoOrderItem fofoOrderItem : fofoItems) {
524
            Item orderItem = itemRepository.selectById(fofoItem.getItemId());
526
            Item item = itemRepository.selectById(fofoOrderItem.getItemId());
-
 
527
 
525
            if (orderItem.isSmartPhone()) {
528
            if (item.isSmartPhone()) {
-
 
529
                LOGGER.info("fofoItem {}", fofoOrderItem);
526
                smartPhone = true;
530
                smartPhone = true;
-
 
531
                purchaseAmount = Math.max( fofoOrderItem.getSellingPrice(), purchaseAmount);
-
 
532
 
527
            }
533
            }
-
 
534
        }
528
 
535
 
-
 
536
        if (!smartPhone) {
-
 
537
            LOGGER.warn("No smartphones found in fofoItems.");
529
        }
538
        }
530
 
539
 
-
 
540
 
-
 
541
 
531
        if (smartPhone) {
542
        if (smartPhone) {
532
            this.createAndGetHygieneData(fofoOrder.getId(), fofoOrder.getFofoId());
543
            this.createAndGetHygieneData(fofoOrder.getId(), fofoOrder.getFofoId());
533
        }
544
        }
534
        // insurance calculation is insurance flag is enabled
545
        // insurance calculation is insurance flag is enabled
535
        //
546
        //
Line 554... Line 565...
554
            poi.setBilledTimestamp(LocalDateTime.now());
565
            poi.setBilledTimestamp(LocalDateTime.now());
555
        }
566
        }
556
 
567
 
557
        LocalDate startDate = ProfitMandiConstants.SCRATCH_OFFER_START_DATE;
568
        LocalDate startDate = ProfitMandiConstants.SCRATCH_OFFER_START_DATE;
558
        LocalDate endDate = ProfitMandiConstants.SCRATCH_OFFER_END_DATE;
569
        LocalDate endDate = ProfitMandiConstants.SCRATCH_OFFER_END_DATE;
559
 
-
 
-
 
570
        boolean specificPriceOffer = ProfitMandiConstants.SPECIFIC_PRICE_OFFER;
560
 
571
 
561
        if (smartPhone) {
572
        if (smartPhone) {
562
            if (LocalDateTime.now().isAfter(startDate.atStartOfDay()) && LocalDateTime.now().isBefore(endDate.atTime(Utils.MAX_TIME))) {
573
            if (LocalDateTime.now().isAfter(startDate.atStartOfDay()) && LocalDateTime.now().isBefore(endDate.atTime(Utils.MAX_TIME))) {
563
 
574
 
564
                try {
575
                try {
565
                    this.sendAppDownloadBillingOffer(customer.getMobileNumber());
576
                    this.sendAppDownloadBillingOffer(customer.getMobileNumber());
566
                } catch (Exception e) {
577
                } catch (Exception e) {
567
                    // TODO Auto-generated catch block
578
                    // TODO Auto-generated catch block
568
                    e.printStackTrace();
579
                    e.printStackTrace();
569
                }
580
                }
-
 
581
                if(specificPriceOffer){
-
 
582
                    this.createSpecificPriceScratchOffer(fofoId, fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId(),purchaseAmount);
-
 
583
                }else{
-
 
584
                    this.createScratchOffer(fofoId, fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
-
 
585
                }
570
 
586
 
571
                this.createScratchOffer(fofoId, fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
-
 
572
            }
587
            }
573
        }
588
        }
574
 
589
 
575
        return fofoOrder.getId();
590
        return fofoOrder.getId();
576
    }
591
    }
Line 650... Line 665...
650
            }
665
            }
651
            scratchOfferRepository.persist(so2);
666
            scratchOfferRepository.persist(so2);
652
        }
667
        }
653
    }
668
    }
654
 
669
 
-
 
670
    private void createSpecificPriceScratchOffer(int fofoId, String invoiceNumber, int customerId , float purchaseAmount) {
-
 
671
 
-
 
672
        Map<Double, ScratchedGift> giftSeries = new HashMap<>();
-
 
673
        giftSeries.put(12000.0, ScratchedGift.GIFT_BOWL);
-
 
674
        giftSeries.put(25000.0, ScratchedGift.NECK_BAND);
-
 
675
        giftSeries.put(25001.0, ScratchedGift.BT_SOUNDBAR);
-
 
676
 
-
 
677
        ScratchedGift selectedGift = getSelectedGift(purchaseAmount, giftSeries);
-
 
678
 
-
 
679
        List<ScratchOffer> scratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(customerId, ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
-
 
680
        if (scratchOffers.size() == 0) {
-
 
681
            ScratchOffer so2 = new ScratchOffer();
-
 
682
            so2.setInvoiceNumber(invoiceNumber);
-
 
683
            so2.setScratched(false);
-
 
684
            so2.setCreatedTimestamp(LocalDateTime.now());
-
 
685
            so2.setExpiredTimestamp(ProfitMandiConstants.SCRATCH_OFFER_END_DATE.plusDays(3).atTime(LocalTime.MAX));
-
 
686
            so2.setOfferName(selectedGift);
-
 
687
            so2.setCustomerId(customerId);
-
 
688
            so2.setUnlockedAt(LocalDateTime.now());
-
 
689
            scratchOfferRepository.persist(so2);
-
 
690
        }
-
 
691
    }
-
 
692
 
-
 
693
    private ScratchedGift getSelectedGift(double purchaseAmount, Map<Double, ScratchedGift> giftSeries) {
-
 
694
        for (Map.Entry<Double, ScratchedGift> entry : giftSeries.entrySet()) {
-
 
695
            if (purchaseAmount <= entry.getKey()) {
-
 
696
                return entry.getValue();
-
 
697
            }
-
 
698
            if(purchaseAmount > 25000){
-
 
699
                return ScratchedGift.BT_SOUNDBAR;
-
 
700
            }
-
 
701
        }
-
 
702
        return ScratchedGift.BLNT; // Default gift if no match found
-
 
703
    }
-
 
704
 
655
    private ScratchedGift getScratchedGiftRandom(int fofoId, int customerId) {
705
    private ScratchedGift getScratchedGiftRandom(int fofoId, int customerId) {
656
        Map<Integer, ScratchedGift> giftSeries = new HashMap<>();
706
        Map<Integer, ScratchedGift> giftSeries = new HashMap<>();
657
        giftSeries.put(1, ScratchedGift.MINI_CHOPPER);
707
        giftSeries.put(1, ScratchedGift.MINI_CHOPPER);
658
        giftSeries.put(2, ScratchedGift.FRUIT_JUICER);
708
        giftSeries.put(2, ScratchedGift.FRUIT_JUICER);
659
        giftSeries.put(3, ScratchedGift.STEAM_IRON);
709
        giftSeries.put(3, ScratchedGift.STEAM_IRON);