Subversion Repositories SmartDukaan

Rev

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

Rev 37869 Rev 37936
Line 36... Line 36...
36
import com.spice.profitmandi.service.PartnerInvestmentService;
36
import com.spice.profitmandi.service.PartnerInvestmentService;
37
import com.spice.profitmandi.service.authentication.RoleManager;
37
import com.spice.profitmandi.service.authentication.RoleManager;
38
import com.spice.profitmandi.service.catalog.BrandsService;
38
import com.spice.profitmandi.service.catalog.BrandsService;
39
import com.spice.profitmandi.service.inventory.InventoryService;
39
import com.spice.profitmandi.service.inventory.InventoryService;
40
import com.spice.profitmandi.dao.enumuration.fofo.StoreClosureReason;
40
import com.spice.profitmandi.dao.enumuration.fofo.StoreClosureReason;
-
 
41
import com.spice.profitmandi.dao.enumuration.fofo.StoreStatus;
-
 
42
import com.spice.profitmandi.dao.enumuration.fofo.StoreStatusSource;
41
import com.spice.profitmandi.service.user.RetailerService;
43
import com.spice.profitmandi.service.user.RetailerService;
42
import com.spice.profitmandi.service.user.StoreAccess;
44
import com.spice.profitmandi.service.user.StoreAccess;
43
import com.spice.profitmandi.service.user.StoreClosureService;
45
import com.spice.profitmandi.service.user.StoreClosureService;
-
 
46
import com.spice.profitmandi.service.user.StoreStatusService;
44
import com.spice.profitmandi.service.user.StoreTimelineTatService;
47
import com.spice.profitmandi.service.user.StoreTimelineTatService;
45
import com.spice.profitmandi.web.model.LoginDetails;
48
import com.spice.profitmandi.web.model.LoginDetails;
46
import com.spice.profitmandi.web.util.CookiesProcessor;
49
import com.spice.profitmandi.web.util.CookiesProcessor;
47
import com.spice.profitmandi.web.util.MVCResponseSender;
50
import com.spice.profitmandi.web.util.MVCResponseSender;
48
import org.apache.logging.log4j.LogManager;
51
import org.apache.logging.log4j.LogManager;
Line 86... Line 89...
86
    private RetailerService retailerService;
89
    private RetailerService retailerService;
87
 
90
 
88
    @Autowired
91
    @Autowired
89
    private StoreClosureService storeClosureService;
92
    private StoreClosureService storeClosureService;
90
    @Autowired
93
    @Autowired
-
 
94
    private StoreStatusService storeStatusService;
-
 
95
    @Autowired
91
    private RetailerRepository retailerRepository;
96
    private RetailerRepository retailerRepository;
92
    @Autowired
97
    @Autowired
93
    private PincodePartnerRepository pincodePartnerRepository;
98
    private PincodePartnerRepository pincodePartnerRepository;
94
    @Autowired
99
    @Autowired
95
    private BrandLimitRepository brandLimitRepository;
100
    private BrandLimitRepository brandLimitRepository;
Line 190... Line 195...
190
        boolean isStoreCodeNotCreated = (storeCode == null || storeCode.isEmpty());
195
        boolean isStoreCodeNotCreated = (storeCode == null || storeCode.isEmpty());
191
        LOGGER.info("isStoreCodeNotCreated - "+isStoreCodeNotCreated);
196
        LOGGER.info("isStoreCodeNotCreated - "+isStoreCodeNotCreated);
192
        if (!updateRetailerRequest.getFofoType().equals(FofoType.INTERNAL) && isStoreCodeNotCreated) {
197
        if (!updateRetailerRequest.getFofoType().equals(FofoType.INTERNAL) && isStoreCodeNotCreated) {
193
            checkLoiCompletion(updateRetailerRequest);
198
            checkLoiCompletion(updateRetailerRequest);
194
        }
199
        }
195
        Map<String, Object> map = retailerService.updateRetailerDetails(updateRetailerRequest);
200
        Map<String, Object> map = retailerService.updateRetailerDetails(updateRetailerRequest,
-
 
201
                cookiesProcessor.getCookiesObject(request).getEmailId());
196
        //retailerService.up
202
        //retailerService.up
197
 
203
 
198
        model.addAllAttributes(map);
204
        model.addAllAttributes(map);
199
        model.addAttribute("counterSizes", CounterSize.values());
205
        model.addAttribute("counterSizes", CounterSize.values());
200
        Map<Integer, String> warehouseMap = this.partnerZones(map.get("fofoStore"));
206
        Map<Integer, String> warehouseMap = this.partnerZones(map.get("fofoStore"));
Line 445... Line 451...
445
        model.addAttribute("fofoStores", fofoStores);
451
        model.addAttribute("fofoStores", fofoStores);
446
        model.addAttribute("investments", investments);
452
        model.addAttribute("investments", investments);
447
        model.addAttribute("customRetailers", customRetailers);
453
        model.addAttribute("customRetailers", customRetailers);
448
        boolean canChangeCategory = CHANGE_PARTNER_CATEGORY_PERMISSIONS.contains(loginDetails.getEmailId());
454
        boolean canChangeCategory = CHANGE_PARTNER_CATEGORY_PERMISSIONS.contains(loginDetails.getEmailId());
449
        model.addAttribute("canChangeCategory", canChangeCategory);
455
        model.addAttribute("canChangeCategory", canChangeCategory);
-
 
456
        model.addAttribute("statusPermissions", storeStatusService.listPermissions(loginDetails.getEmailId()));
450
 
457
 
451
        return "store-investment";
458
        return "store-investment";
452
 
459
 
453
    }
460
    }
454
 
461
 
455
    @GetMapping(value = "/getAllStores")
462
    @GetMapping(value = "/getAllStores")
456
    public String getAllStores(HttpServletRequest request, Model model) throws Exception {
463
    public String getAllStores(HttpServletRequest request, Model model) throws Exception {
457
 
464
 
458
        List<FofoStore> fofoStores = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive())
465
        List<FofoStore> fofoStores = new ArrayList<>(fofoStoreRepository.selectByStoreStatus(StoreStatus.ACTIVE));
459
                .collect(Collectors.toList());
466
        fofoStores.addAll(fofoStoreRepository.selectByStoreStatus(StoreStatus.PAUSED));
460
        Map<Integer, Boolean> investments = new HashMap<>();
467
        Map<Integer, Boolean> investments = new HashMap<>();
461
 
468
 
462
        for (FofoStore fofoStore : fofoStores) {
469
        for (FofoStore fofoStore : fofoStores) {
463
            boolean isOk = false;
470
            boolean isOk = false;
464
            if (fofoStore.getGraceDate() != null && fofoStore.getGraceDate().isAfter(LocalDate.now())) {
471
            if (fofoStore.getGraceDate() != null && fofoStore.getGraceDate().isAfter(LocalDate.now())) {
Line 483... Line 490...
483
        model.addAttribute("customRetailers", customRetailers);
490
        model.addAttribute("customRetailers", customRetailers);
484
 
491
 
485
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
492
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
486
        boolean canChangeCategory = CHANGE_PARTNER_CATEGORY_PERMISSIONS.contains(loginDetails.getEmailId());
493
        boolean canChangeCategory = CHANGE_PARTNER_CATEGORY_PERMISSIONS.contains(loginDetails.getEmailId());
487
        model.addAttribute("canChangeCategory", canChangeCategory);
494
        model.addAttribute("canChangeCategory", canChangeCategory);
-
 
495
        model.addAttribute("statusPermissions", storeStatusService.listPermissions(loginDetails.getEmailId()));
488
 
496
 
489
        return "store-investment";
497
        return "store-investment";
490
 
498
 
491
    }
499
    }
492
 
500
 
Line 535... Line 543...
535
                        .filter(x -> x.getDisplayName().toLowerCase().contains(query.toLowerCase()))
543
                        .filter(x -> x.getDisplayName().toLowerCase().contains(query.toLowerCase()))
536
                        .collect(Collectors.toList())));
544
                        .collect(Collectors.toList())));
537
        return "response";
545
        return "response";
538
    }
546
    }
539
 
547
 
540
    @PostMapping(value = "/deactivateStore")
548
    @PostMapping(value = "/pauseStore")
541
    public String deActivateStore(HttpServletRequest request,
549
    public String pauseStore(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId,
542
                                  @RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
550
                             @RequestParam(name = "reason", required = false) String reason, Model model) throws Exception {
543
        FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
544
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
551
        storeStatusService.pause(fofoId, reason, cookiesProcessor.getCookiesObject(request).getEmailId(), StoreStatusSource.FOFO_PORTAL);
545
        StoreAccess.check(StoreAccess.DEACTIVATE, loginDetails.getEmailId(), "deactivate retailer");
552
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
546
        if (fofoStore.isClosed()) {
553
        return "response";
547
            throw new ProfitMandiBusinessException("Store Closed", "Store Already Closed",
-
 
548
                    "This store is permanently closed and cannot be modified");
-
 
549
        }
554
    }
-
 
555
 
550
        fofoStore.setActive(false);
556
    @PostMapping(value = "/unpauseStore")
-
 
557
    public String unpauseStore(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId,
-
 
558
                               @RequestParam(name = "reason", required = false) String reason, Model model) throws Exception {
551
        LOGGER.info("inserted into InActiveFofoStore successfully");
559
        storeStatusService.unpause(fofoId, reason, cookiesProcessor.getCookiesObject(request).getEmailId(), StoreStatusSource.FOFO_PORTAL);
552
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
560
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
553
        return "response";
561
        return "response";
554
    }
562
    }
555
 
563
 
-
 
564
    @PostMapping(value = "/suspendStore")
-
 
565
    public String suspendStore(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId,
-
 
566
                               @RequestParam(name = "reason", required = false) String reason, Model model) throws Exception {
-
 
567
        storeStatusService.suspend(fofoId, reason, cookiesProcessor.getCookiesObject(request).getEmailId(), StoreStatusSource.FOFO_PORTAL);
-
 
568
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
-
 
569
        return "response";
-
 
570
    }
-
 
571
 
-
 
572
    @GetMapping(value = "/storeStatusHistory")
-
 
573
    public String storeStatusHistory(@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
-
 
574
        model.addAttribute("response1", mvcResponseSender.createResponseString(storeStatusService.history(fofoId)));
-
 
575
        return "response";
-
 
576
    }
-
 
577
 
556
    @PostMapping(value = "/closeStore")
578
    @PostMapping(value = "/closeStore")
557
    public String closeStore(HttpServletRequest request,
579
    public String closeStore(HttpServletRequest request,
558
                             @RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId,
580
                             @RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId,
559
                             @RequestParam(name = "storeCode") String storeCode,
581
                             @RequestParam(name = "storeCode") String storeCode,
560
                             @RequestParam(name = "reason", required = false) StoreClosureReason reason,
582
                             @RequestParam(name = "reason", required = false) StoreClosureReason reason,
561
                             @RequestParam(name = "remark", required = false) String remark,
583
                             @RequestParam(name = "remark", required = false) String remark,
562
                             @RequestParam(name = "approvalDocumentId", defaultValue = "0") int approvalDocumentId,
584
                             @RequestParam(name = "approvalDocumentId", defaultValue = "0") int approvalDocumentId,
563
                             Model model) throws Exception {
585
                             Model model) throws Exception {
564
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
586
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
565
        storeClosureService.closeStore(fofoId, storeCode, reason, remark, approvalDocumentId, loginDetails.getEmailId());
587
        storeClosureService.closeStore(fofoId, storeCode, reason, remark, approvalDocumentId, loginDetails.getEmailId(),
-
 
588
                StoreStatusSource.FOFO_PORTAL);
566
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
589
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
567
        return "response";
590
        return "response";
568
    }
591
    }
569
 
592
 
570
    @PostMapping(value = "/activateStoreForever")
593
    @PostMapping(value = "/activateStoreForever")
571
    public String activateStoreForever(HttpServletRequest request,
594
    public String activateStoreForever(HttpServletRequest request,
572
                                       @RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
595
                                       @RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
573
        FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
574
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
596
        storeStatusService.activate(fofoId, cookiesProcessor.getCookiesObject(request).getEmailId(), StoreStatusSource.FOFO_PORTAL);
575
        StoreAccess.check(StoreAccess.ACTIVATE, loginDetails.getEmailId(), "activate retailer");
-
 
576
        if (fofoStore.isClosed()) {
-
 
577
            throw new ProfitMandiBusinessException("Store Closed", "Store Permanently Closed",
-
 
578
                    "This store is permanently closed and cannot be reactivated");
-
 
579
        }
-
 
580
        fofoStore.setActive(true);
-
 
581
        LOGGER.info("inserted into ActiveFofoStore successfully");
-
 
582
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
597
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
583
        return "response";
598
        return "response";
584
    }
599
    }
585
 
600
 
586
    @PostMapping(value = "/activateStoreTemporary")
601
    @PostMapping(value = "/activateStoreTemporary")
587
    public String activateStoreTemporary(HttpServletRequest request,
602
    public String activateStoreTemporary(HttpServletRequest request,
588
                                         @RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId,
603
                                         @RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId,
589
                                         @RequestParam(name = "days", required = true) int days, Model model) throws Exception {
604
                                         @RequestParam(name = "days", required = true) int days, Model model) throws Exception {
590
 
-
 
591
        FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
592
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
605
        storeStatusService.activateTemporarily(fofoId, days, cookiesProcessor.getCookiesObject(request).getEmailId(),
593
        StoreAccess.check(StoreAccess.ACTIVATE, loginDetails.getEmailId(), "activate retailer");
-
 
594
 
-
 
595
        if (fofoStore.isClosed()) {
-
 
596
            throw new ProfitMandiBusinessException("Store Closed", "Store Permanently Closed",
-
 
597
                    "This store is permanently closed and cannot be reactivated");
-
 
598
        }
-
 
599
 
-
 
600
        LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
601
 
-
 
602
        LocalDateTime EndDate = currentDate.plusDays(days);
-
 
603
        fofoStore.setActiveTimeStamp(EndDate);
-
 
604
 
-
 
605
        LOGGER.info("EndDate" + EndDate);
-
 
606
        LOGGER.info("getActiveTimeStamp" + fofoStore.getActiveTimeStamp());
-
 
607
 
-
 
608
        if (currentDate.isBefore(fofoStore.getActiveTimeStamp())) {
-
 
609
            fofoStore.setActive(true);
606
                StoreStatusSource.FOFO_PORTAL);
610
            LOGGER.info("inserted into InActiveFofoStore successfully");
-
 
611
        }
-
 
612
 
-
 
613
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
607
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
614
        return "response";
608
        return "response";
615
    }
609
    }
616
 
610
 
617
    @GetMapping(value = "/getAllInactiveStores")
611
    @GetMapping(value = "/getAllInactiveStores")
618
    public String getInactiveStores(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
612
    public String getInactiveStores(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
619
        List<FofoStore> inActiveFofoStores = fofoStoreRepository.selectInActiveStore();
613
        List<FofoStore> inActiveFofoStores = fofoStoreRepository.selectInactiveStores();
620
 
614
 
621
        LOGGER.info("inActiveFofoStores {}", inActiveFofoStores);
615
        LOGGER.info("inActiveFofoStores {}", inActiveFofoStores);
622
        Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
616
        Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
623
 
617
 
624
        List<Integer> fofoIds = inActiveFofoStores.stream().map(x -> x.getId()).collect(Collectors.toList());
618
        List<Integer> fofoIds = inActiveFofoStores.stream().map(x -> x.getId()).collect(Collectors.toList());
Line 628... Line 622...
628
                .collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
622
                .collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
629
        LOGGER.info("customRetailers {}", customRetailers);
623
        LOGGER.info("customRetailers {}", customRetailers);
630
 
624
 
631
        model.addAttribute("inActiveFofoStores", inActiveFofoStores);
625
        model.addAttribute("inActiveFofoStores", inActiveFofoStores);
632
        model.addAttribute("customRetailers", customRetailers);
626
        model.addAttribute("customRetailers", customRetailers);
-
 
627
        model.addAttribute("statusPermissions",
-
 
628
                storeStatusService.listPermissions(cookiesProcessor.getCookiesObject(request).getEmailId()));
633
        return "inactive-stores";
629
        return "inactive-stores";
634
    }
630
    }
635
 
631
 
636
    // Extend billing for 2 days
632
    // Extend billing for 2 days
637
    @PostMapping(value = "/extendBilling")
633
    @PostMapping(value = "/extendBilling")