Subversion Repositories SmartDukaan

Rev

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

Rev 30078 Rev 30087
Line 3... Line 3...
3
import java.time.LocalDate;
3
import java.time.LocalDate;
4
import java.time.LocalDateTime;
4
import java.time.LocalDateTime;
5
import java.time.LocalTime;
5
import java.time.LocalTime;
6
import java.util.ArrayList;
6
import java.util.ArrayList;
7
import java.util.Arrays;
7
import java.util.Arrays;
-
 
8
import java.util.Comparator;
-
 
9
import java.util.HashMap;
8
import java.util.List;
10
import java.util.List;
9
import java.util.Map;
11
import java.util.Map;
10
import java.util.Map.Entry;
12
import java.util.Map.Entry;
11
import java.util.Set;
13
import java.util.Set;
12
import java.util.stream.Collectors;
14
import java.util.stream.Collectors;
Line 28... Line 30...
28
import org.springframework.web.bind.annotation.RequestParam;
30
import org.springframework.web.bind.annotation.RequestParam;
29
 
31
 
30
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
32
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
31
import com.spice.profitmandi.common.model.CustomRetailer;
33
import com.spice.profitmandi.common.model.CustomRetailer;
32
import com.spice.profitmandi.common.model.ProfitMandiConstants;
34
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
35
import com.spice.profitmandi.common.services.mandii.TransactionSummaryResponseOut;
33
import com.spice.profitmandi.common.web.util.ResponseSender;
36
import com.spice.profitmandi.common.web.util.ResponseSender;
34
import com.spice.profitmandi.dao.entity.auth.AuthUser;
37
import com.spice.profitmandi.dao.entity.auth.AuthUser;
35
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionPlan;
38
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionPlan;
36
import com.spice.profitmandi.dao.entity.auth.PartnerSecondaryPlan;
39
import com.spice.profitmandi.dao.entity.auth.PartnerSecondaryPlan;
37
import com.spice.profitmandi.dao.entity.cs.Position;
-
 
38
import com.spice.profitmandi.dao.entity.dtr.User;
40
import com.spice.profitmandi.dao.entity.dtr.User;
39
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
41
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
40
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
42
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
-
 
43
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
41
import com.spice.profitmandi.dao.entity.fofo.PartnerOnBoardingPanel;
44
import com.spice.profitmandi.dao.entity.fofo.PartnerOnBoardingPanel;
42
import com.spice.profitmandi.dao.entity.user.FranchiseeActivity;
45
import com.spice.profitmandi.dao.entity.user.FranchiseeActivity;
43
import com.spice.profitmandi.dao.entity.user.FranchiseeVisit;
46
import com.spice.profitmandi.dao.entity.user.FranchiseeVisit;
44
import com.spice.profitmandi.dao.entity.user.Lead;
47
import com.spice.profitmandi.dao.entity.user.Lead;
45
import com.spice.profitmandi.dao.entity.user.LeadActivity;
48
import com.spice.profitmandi.dao.entity.user.LeadActivity;
Line 65... Line 68...
65
import com.spice.profitmandi.dao.repository.dtr.LeadActivityRepository;
68
import com.spice.profitmandi.dao.repository.dtr.LeadActivityRepository;
66
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
69
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
67
import com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository;
70
import com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository;
68
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
71
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
69
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
72
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
70
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
73
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
71
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
74
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
72
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
75
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
73
import com.spice.profitmandi.service.user.RetailerService;
76
import com.spice.profitmandi.service.user.RetailerService;
74
import com.spice.profitmandi.service.user.StoreTimelineTatService;
77
import com.spice.profitmandi.service.user.StoreTimelineTatService;
75
import com.spice.profitmandi.web.req.CreateFranchiseeRequest;
78
import com.spice.profitmandi.web.req.CreateFranchiseeRequest;
Line 543... Line 546...
543
		return responseSender.ok(status);
546
		return responseSender.ok(status);
544
 
547
 
545
	}
548
	}
546
 
549
 
547
	@Autowired
550
	@Autowired
548
	private com.spice.profitmandi.service.transaction.TransactionService transactionService;
-
 
549
 
-
 
550
	@Autowired
-
 
551
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
-
 
552
 
-
 
553
	@Autowired
-
 
554
	private OrderRepository orderRepository;
551
	private OrderRepository orderRepository;
555
 
552
 
556
	@Autowired
553
	@Autowired
557
	private PositionRepository positionRepository;
554
	private PositionRepository positionRepository;
558
 
555
 
Line 563... Line 560...
563
	private PartnerCollectionPlanRepository partnerCollectionPlanRepository;
560
	private PartnerCollectionPlanRepository partnerCollectionPlanRepository;
564
 
561
 
565
	@Autowired
562
	@Autowired
566
	private PartnerSecondaryPlanRepository partnerSecondaryPlanRepository;
563
	private PartnerSecondaryPlanRepository partnerSecondaryPlanRepository;
567
 
564
 
-
 
565
	@Autowired
-
 
566
	private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
-
 
567
 
568
	@RequestMapping(value = "/getPartnerTarget", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
568
	@RequestMapping(value = "/getPartnerTarget", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
569
	@ApiImplicitParams({
569
	@ApiImplicitParams({
570
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
570
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
571
	public ResponseEntity<?> getPartnerTarget(HttpServletRequest request,
571
	public ResponseEntity<?> getPartnerTarget(HttpServletRequest request,
572
			@RequestParam(name = "gmailId") String gmailId) throws ProfitMandiBusinessException {
572
			@RequestParam(name = "gmailId") String gmailId, @RequestParam String dayValue)
-
 
573
			throws ProfitMandiBusinessException {
573
 
574
 
574
		AuthUser authUser = authRepository.selectByGmailId(gmailId);
575
		AuthUser authUser = authRepository.selectByGmailId(gmailId);
575
 
576
 
576
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
577
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
577
 
578
 
578
		Set<Integer> fofoIds = storeGuyMap.get("ankit.bhatia@smartdukaan.com");
579
		Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
579
 
580
 
580
		LOGGER.info("fofoIds" + fofoIds);
581
		LOGGER.info("fofoIds" + fofoIds);
581
 
582
 
582
		if (fofoIds == null) {
-
 
583
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
-
 
584
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
-
 
585
					.count() > 0) {
-
 
586
				fofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream())
-
 
587
						.map(x -> x.getPartnerId()).collect(Collectors.toSet());
-
 
588
			}
-
 
589
		}
-
 
590
 
-
 
591
		List<String> brands = Arrays.asList("Vivo", "Samsung", "Oppo", "Itel", "Others");
583
		List<String> brands = Arrays.asList("Vivo", "Samsung", "Oppo", "Itel", "Others");
592
		float totalPartnerTargetSecondary = 0;
584
		float totalPartnerTargetSecondary = 0;
593
		float totalPartnerTargetCollection = 0;
585
		float totalPartnerTargetCollection = 0;
594
 
-
 
595
		float totalPartnerAchievementSecondary = 0;
586
		float totalPartnerAchievementSecondary = 0;
596
		float totalPartnerAchievementCollection = 0;
587
		float totalPartnerAchievementCollection = 0;
597
		TargetModel tm = new TargetModel();
588
		TargetModel tm = new TargetModel();
-
 
589
		Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = new HashMap<>();
598
 
590
 
599
		List<PartnerTargetAchievementModel> ptams = new ArrayList<>();
591
		List<PartnerTargetAchievementModel> ptams = new ArrayList<>();
600
 
592
 
601
		if (fofoIds.size() > 0 && fofoIds != null) {
593
		if (fofoIds.size() > 0 && fofoIds != null) {
602
			List<Integer> fofoIdList = new ArrayList<>(fofoIds);
594
			List<Integer> fofoIdl = new ArrayList<>(fofoIds);
-
 
595
			List<Integer> fofoIdList = fofoStoreRepository.selectByRetailerIds(fofoIdl).stream()
-
 
596
					.filter(x -> !x.isInternal()).map(x -> x.getId()).collect(Collectors.toList());
603
 
597
 
604
			LocalDateTime startDate = LocalDate.now().atStartOfDay();
598
			LocalDateTime startDate = LocalDate.now().atStartOfDay();
-
 
599
			LocalDateTime endDate = LocalDate.now().atTime(LocalTime.MAX);
-
 
600
 
-
 
601
			if (dayValue.equals("previous")) {
-
 
602
				startDate = LocalDate.now().minusDays(1).atStartOfDay();
-
 
603
				endDate = LocalDate.now().minusDays(1).atTime(LocalTime.MAX);
-
 
604
			}
-
 
605
 
-
 
606
			List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
-
 
607
					.selectAll(fofoIdList, startDate.minusDays(3).toLocalDate());
-
 
608
			if (!partnerDailyInvestments.isEmpty()) {
-
 
609
				partnerDailyInvestmentMap = partnerDailyInvestments.stream()
-
 
610
						.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
-
 
611
			}
605
 
612
 
606
			Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(fofoIdList);
613
			Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(fofoIdList);
607
 
614
 
608
			Map<Integer, PartnerCollectionPlanModel> collectionPlans = userWalletRepository
615
			Map<Integer, PartnerCollectionPlanModel> collectionPlans = userWalletRepository
609
					.getPartnerWiseTargetCollections(fofoIdList, startDate).stream()
616
					.getPartnerWiseTargetCollections(fofoIdList, startDate, endDate).stream()
610
					.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
617
					.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
611
 
618
 
612
			LOGGER.info("collectionPlans {}", collectionPlans);
619
			LOGGER.info("collectionPlans {}", collectionPlans);
613
 
620
 
614
			Map<Integer, List<PartnerSecondaryPlanModel>> partnerSecondayPlans = orderRepository
621
			Map<Integer, List<PartnerSecondaryPlanModel>> partnerSecondayPlans = orderRepository
615
					.selectPartnerSecondaryGroupByBrand(fofoIdList, startDate).stream()
622
					.selectPartnerSecondaryGroupByBrand(fofoIdList, startDate, endDate).stream()
616
					.collect(Collectors.groupingBy(x -> x.getFofoId()));
623
					.collect(Collectors.groupingBy(x -> x.getFofoId()));
617
 
624
 
618
			LOGGER.info("partnerSecondayPlans {}", partnerSecondayPlans);
625
			LOGGER.info("partnerSecondayPlans {}", partnerSecondayPlans);
619
			for (Entry<Integer, CustomRetailer> customRetailerEntry : customRetailers.entrySet()) {
626
			for (Entry<Integer, CustomRetailer> customRetailerEntry : customRetailers.entrySet()) {
620
				int fofoId = customRetailerEntry.getKey();
627
				int fofoId = customRetailerEntry.getKey();
Line 624... Line 631...
624
 
631
 
625
				PartnerTargetAchievementModel ptam = new PartnerTargetAchievementModel();
632
				PartnerTargetAchievementModel ptam = new PartnerTargetAchievementModel();
626
				ptam.setFofoId(fofoId);
633
				ptam.setFofoId(fofoId);
627
				ptam.setBusinessName(customRetailer.getBusinessName());
634
				ptam.setBusinessName(customRetailer.getBusinessName());
628
 
635
 
-
 
636
				if (partnerDailyInvestmentMap.get(fofoId) != null) {
-
 
637
					ptam.setWalletAmount(partnerDailyInvestmentMap.get(fofoId).getWalletAmount());
-
 
638
					ptam.setShortInvestment(partnerDailyInvestmentMap.get(fofoId).getShortInvestment());
-
 
639
				}
-
 
640
 
629
				if (collectionPlans.get(fofoId) != null) {
641
				if (collectionPlans.get(fofoId) != null) {
630
					totalPartnerTargetCollection += collectionPlans.get(fofoId).getTargetPlan();
642
					Integer authId = collectionPlans.get(fofoId).getAuthId();
-
 
643
					LOGGER.info("authId" + authId);
-
 
644
					if (authId != null && authId == authUser.getId()) {
631
 
645
 
-
 
646
						if (collectionPlans.get(fofoId).getTargetPlan() != null) {
-
 
647
							totalPartnerTargetCollection += collectionPlans.get(fofoId).getTargetPlan();
-
 
648
						}
-
 
649
						if (collectionPlans.get(fofoId).getAchievementPlan() != null) {
632
					totalPartnerAchievementCollection += collectionPlans.get(fofoId).getAchievementPlan();
650
							totalPartnerAchievementCollection += collectionPlans.get(fofoId).getAchievementPlan();
-
 
651
						}
-
 
652
 
-
 
653
					}
-
 
654
 
-
 
655
					if (authId != null && authId != authUser.getId()) {
-
 
656
						ptam.setAuthUser(authRepository.selectById(authId));
-
 
657
						ptam.setCollectionColor("red");
-
 
658
					}
-
 
659
					if (collectionPlans.get(fofoId).getTargetPlan() != null) {
-
 
660
 
633
					ptam.setCollectionTarget(collectionPlans.get(fofoId).getTargetPlan());
661
						ptam.setCollectionTarget(collectionPlans.get(fofoId).getTargetPlan());
-
 
662
					}
-
 
663
 
-
 
664
					if (collectionPlans.get(fofoId).getAchievementPlan() != null) {
634
					ptam.setCollectionAchievement(collectionPlans.get(fofoId).getAchievementPlan());
665
						ptam.setCollectionAchievement(collectionPlans.get(fofoId).getAchievementPlan());
-
 
666
					}
635
				}
667
				}
636
 
668
 
637
				PartnerSecondaryPlanModel otherPartnerSecondaryPlanModel = null;
669
				PartnerSecondaryPlanModel otherPartnerSecondaryPlanModel = null;
-
 
670
				Map<String, PartnerSecondaryPlanModel> secondaryModelMap = new HashMap<>();
638
				if (partnerSecondayPlans.get(fofoId) != null) {
671
				if (partnerSecondayPlans.get(fofoId) != null) {
-
 
672
 
639
					long otherBrandSecondary = 0;
673
					long otherBrandSecondary = 0;
640
					for (PartnerSecondaryPlanModel pspm : partnerSecondayPlans.get(fofoId)) {
674
					for (PartnerSecondaryPlanModel pspm : partnerSecondayPlans.get(fofoId)) {
-
 
675
 
-
 
676
						Integer authId = pspm.getAuthId();
-
 
677
 
641
						if (!brands.contains(pspm.getBrand())) {
678
						if (!brands.contains(pspm.getBrand())) {
-
 
679
							if (pspm.getAchievementPlan() != null) {
642
							otherBrandSecondary += pspm.getAchievementPlan();
680
								otherBrandSecondary += pspm.getAchievementPlan();
-
 
681
							}
643
						} else {
682
						} else {
644
							otherPartnerSecondaryPlanModel = pspm;
683
							otherPartnerSecondaryPlanModel = pspm;
645
						}
684
						}
-
 
685
 
-
 
686
						if (pspm.getTargetPlan() != null) {
-
 
687
 
646
						totalSecondaryPlan += pspm.getTargetPlan();
688
							totalSecondaryPlan += pspm.getTargetPlan();
-
 
689
						}
-
 
690
 
-
 
691
						if (pspm.getAchievementPlan() != null) {
647
						totalSecondaryAchivement += pspm.getAchievementPlan();
692
							totalSecondaryAchivement += pspm.getAchievementPlan();
-
 
693
						}
-
 
694
						if (authId != null && authId == authUser.getId()) {
-
 
695
 
-
 
696
							if (pspm.getTargetPlan() != null) {
-
 
697
 
-
 
698
								totalPartnerTargetSecondary += pspm.getTargetPlan();
-
 
699
							}
-
 
700
 
-
 
701
							if (pspm.getAchievementPlan() != null) {
-
 
702
								totalPartnerAchievementSecondary += pspm.getAchievementPlan();
-
 
703
							}
-
 
704
 
-
 
705
						}
648
					}
706
					}
649
					if (otherPartnerSecondaryPlanModel != null) {
707
					if (otherPartnerSecondaryPlanModel != null) {
650
						otherPartnerSecondaryPlanModel.setAchievementPlan(otherBrandSecondary);
708
						otherPartnerSecondaryPlanModel.setAchievementPlan(otherBrandSecondary);
651
					}
709
					}
652
					Map<String, PartnerSecondaryPlanModel> secondaryModelMap = partnerSecondayPlans.get(fofoId).stream()
710
					secondaryModelMap = partnerSecondayPlans.get(fofoId).stream()
653
							.filter(x -> brands.contains(x.getBrand()))
711
							.filter(x -> brands.contains(x.getBrand()))
654
							.collect(Collectors.toMap(x -> x.getBrand(), x -> x));
712
							.collect(Collectors.toMap(x -> x.getBrand(), x -> x));
655
 
713
 
656
					if (secondaryModelMap.containsKey("Others")) {
714
					if (secondaryModelMap.containsKey("Others")) {
657
						PartnerSecondaryPlanModel psp = secondaryModelMap.get("Others");
715
						PartnerSecondaryPlanModel psp = secondaryModelMap.get("Others");
658
						psp.setAchievementPlan(otherBrandSecondary);
716
						psp.setAchievementPlan(otherBrandSecondary);
659
					} else {
717
					} else {
660
						secondaryModelMap.put("Others",
718
						secondaryModelMap.put("Others", new PartnerSecondaryPlanModel(fofoId, "Others", (long) 0,
661
								new PartnerSecondaryPlanModel(fofoId, "Others", 0, otherBrandSecondary));
719
								otherBrandSecondary, authUser.getId()));
662
					}
720
					}
663
					for (String brand : brands) {
721
					for (String brand : brands) {
664
 
722
 
665
						if (!secondaryModelMap.containsKey(brand)) {
723
						if (!secondaryModelMap.containsKey(brand)) {
-
 
724
							secondaryModelMap.put(brand,
-
 
725
									new PartnerSecondaryPlanModel(fofoId, brand, (long) 0, (long) 0, authUser.getId()));
-
 
726
						}
-
 
727
 
-
 
728
					}
-
 
729
 
-
 
730
					for (Entry<String, PartnerSecondaryPlanModel> secondaryModelEntry : secondaryModelMap.entrySet()) {
-
 
731
 
-
 
732
						Integer authId = secondaryModelEntry.getValue().getAuthId();
-
 
733
 
-
 
734
						if (authId != null && authId != authUser.getId()) {
-
 
735
 
666
							secondaryModelMap.put(brand, new PartnerSecondaryPlanModel(fofoId, brand, 0, 0));
736
							secondaryModelEntry.getValue().setAuthUser(authRepository.selectById(authId));
-
 
737
 
-
 
738
							ptam.setSecondaryColor("red");
667
						}
739
						}
668
 
740
 
669
					}
741
					}
670
 
742
 
671
					ptam.setPartnerSecondaryModel(secondaryModelMap);
743
					ptam.setPartnerSecondaryModel(secondaryModelMap);
672
					ptam.setTotalSecondaryPlan(totalSecondaryPlan);
744
					ptam.setTotalSecondaryPlan(totalSecondaryPlan);
673
 
745
 
674
					totalPartnerTargetSecondary += totalSecondaryPlan;
746
					ptam.setTotalSecondaryAchievement(totalSecondaryAchivement);
675
 
747
 
-
 
748
				} else {
-
 
749
					for (String brand : brands) {
676
					totalPartnerAchievementSecondary += totalSecondaryAchivement;
750
						PartnerSecondaryPlanModel pspm = new PartnerSecondaryPlanModel();
-
 
751
						pspm.setAchievementPlan((long) 0);
-
 
752
						pspm.setTargetPlan((long) 0);
-
 
753
						pspm.setBrand(brand);
-
 
754
						pspm.setFofoId(fofoId);
-
 
755
						secondaryModelMap.put(brand, pspm);
677
 
756
 
-
 
757
					}
-
 
758
 
678
					ptam.setTotalSecondaryAchivewment(totalSecondaryAchivement);
759
					ptam.setPartnerSecondaryModel(secondaryModelMap);
679
 
760
 
680
				}
761
				}
681
 
762
 
682
				ptams.add(ptam);
763
				ptams.add(ptam);
683
 
764
 
Line 685... Line 766...
685
 
766
 
686
			tm.setTotalPartnerTargetCollection(totalPartnerTargetCollection);
767
			tm.setTotalPartnerTargetCollection(totalPartnerTargetCollection);
687
			tm.setTotalPartnerTargetSecondary(totalPartnerTargetSecondary);
768
			tm.setTotalPartnerTargetSecondary(totalPartnerTargetSecondary);
688
			tm.setTotalPartnerSecondary(totalPartnerAchievementSecondary);
769
			tm.setTotalPartnerSecondary(totalPartnerAchievementSecondary);
689
			tm.setTotalPartnerCollection(totalPartnerAchievementCollection);
770
			tm.setTotalPartnerCollection(totalPartnerAchievementCollection);
-
 
771
 
690
			tm.setTargetAchievement(ptams);
772
			tm.setTargetAchievement(ptams.stream()
-
 
773
					.sorted(Comparator.comparing(PartnerTargetAchievementModel::getShortInvestment).reversed())
-
 
774
					.collect(Collectors.toList()));
691
 
775
 
692
		}
776
		}
693
 
777
 
694
		return responseSender.ok(tm);
778
		return responseSender.ok(tm);
695
 
779
 
Line 699... Line 783...
699
	@ApiImplicitParams({
783
	@ApiImplicitParams({
700
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
784
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
701
	public ResponseEntity<?> createPartnerTarget(HttpServletRequest request,
785
	public ResponseEntity<?> createPartnerTarget(HttpServletRequest request,
702
			@RequestBody PartnerTargetAchievementModel ptam) throws ProfitMandiBusinessException {
786
			@RequestBody PartnerTargetAchievementModel ptam) throws ProfitMandiBusinessException {
703
 
787
 
704
		AuthUser authUser = authRepository.selectByGmailId("ankit.bhatia@shop2020.in");
788
		AuthUser authUser = authRepository.selectByGmailId(ptam.getCreatedBy());
705
 
789
 
706
		PartnerCollectionPlan pcp = partnerCollectionPlanRepository.selectByLocalDate(LocalDate.now(),
790
		PartnerCollectionPlan partnerCollectionPlan = partnerCollectionPlanRepository.selectByLocalDate(LocalDate.now(),
707
				ptam.getFofoId());
791
				ptam.getFofoId(), true);
708
		LOGGER.info("pcp" + pcp);
792
		LOGGER.info("pcp" + partnerCollectionPlan);
709
 
793
 
710
		if (pcp == null) {
794
		if (partnerCollectionPlan == null) {
711
			if (ptam.getCollectionTarget() > 0) {
795
			if (ptam.getCollectionTarget() > 0) {
-
 
796
 
712
				PartnerCollectionPlan partnerCollectionPlan = new PartnerCollectionPlan();
797
				partnerCollectionPlan = new PartnerCollectionPlan();
-
 
798
				partnerCollectionPlan.setCreateTimestamp(LocalDateTime.now());
713
				partnerCollectionPlan.setAuthId(authUser.getId());
799
				partnerCollectionPlan.setAuthId(authUser.getId());
714
				partnerCollectionPlan.setFofoId(ptam.getFofoId());
800
				partnerCollectionPlan.setFofoId(ptam.getFofoId());
-
 
801
				partnerCollectionPlan.setActive(true);
715
				partnerCollectionPlan.setCollectionPlan(ptam.getCollectionTarget());
802
				partnerCollectionPlan.setCollectionPlan(ptam.getCollectionTarget());
716
				partnerCollectionPlan.setCreateTimestamp(LocalDateTime.now());
-
 
717
				partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
803
				partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
718
				partnerCollectionPlanRepository.persist(partnerCollectionPlan);
804
				partnerCollectionPlanRepository.persist(partnerCollectionPlan);
719
			}
805
			}
-
 
806
 
-
 
807
		} else {
-
 
808
			if (partnerCollectionPlan.getCollectionPlan() != ptam.getCollectionTarget()) {
-
 
809
				float totalCollectionPlan = partnerCollectionPlan.getCollectionPlan() + 10000;
-
 
810
				if (authUser.getId() == partnerCollectionPlan.getAuthId()) {
-
 
811
					if (ptam.getCollectionTarget() >= totalCollectionPlan) {
-
 
812
						partnerCollectionPlan.setCollectionPlan(ptam.getCollectionTarget());
-
 
813
						partnerCollectionPlan.setActive(true);
-
 
814
						partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
-
 
815
					} else {
-
 
816
						throw new ProfitMandiBusinessException("collection target", "",
-
 
817
								"collection target should be more than " + totalCollectionPlan);
-
 
818
					}
-
 
819
 
-
 
820
				} else {
-
 
821
 
-
 
822
					if (ptam.getCollectionTarget() >= totalCollectionPlan) {
-
 
823
 
-
 
824
						partnerCollectionPlan.setActive(false);
-
 
825
						partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
-
 
826
						partnerCollectionPlan = new PartnerCollectionPlan();
-
 
827
						partnerCollectionPlan.setCreateTimestamp(LocalDateTime.now());
-
 
828
						partnerCollectionPlan.setAuthId(authUser.getId());
-
 
829
						partnerCollectionPlan.setFofoId(ptam.getFofoId());
-
 
830
						partnerCollectionPlan.setActive(true);
-
 
831
						partnerCollectionPlan.setCollectionPlan(ptam.getCollectionTarget());
-
 
832
						partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
-
 
833
						partnerCollectionPlanRepository.persist(partnerCollectionPlan);
-
 
834
					} else {
-
 
835
						throw new ProfitMandiBusinessException("collection target", "",
-
 
836
								"collection target should be more than " + totalCollectionPlan);
-
 
837
					}
-
 
838
				}
-
 
839
			}
720
		}
840
		}
721
 
841
 
722
		for (Entry<String, PartnerSecondaryPlanModel> pspm : ptam.getPartnerSecondaryModel().entrySet()) {
842
		for (Entry<String, PartnerSecondaryPlanModel> pspm : ptam.getPartnerSecondaryModel().entrySet()) {
723
			if (pspm.getValue().getTargetPlan() > 0) {
-
 
724
				PartnerSecondaryPlanModel plan = pspm.getValue();
843
			PartnerSecondaryPlanModel plan = pspm.getValue();
725
				PartnerSecondaryPlan psp = partnerSecondaryPlanRepository.selectByLocalDateBrand(plan.getBrand(),
844
			PartnerSecondaryPlan psp = partnerSecondaryPlanRepository.selectByLocalDateBrand(plan.getBrand(),
726
						LocalDate.now(), ptam.getFofoId());
845
					LocalDate.now(), ptam.getFofoId(), true);
727
				LOGGER.info("psp" + psp);
846
			LOGGER.info("psp" + psp);
-
 
847
 
728
				if (psp == null)
848
			if (psp == null) {
-
 
849
				if (plan.getTargetPlan() > 0) {
-
 
850
 
729
					psp = new PartnerSecondaryPlan();
851
					psp = new PartnerSecondaryPlan();
730
				psp.setAuthId(authUser.getId());
852
					psp.setAuthId(authUser.getId());
731
				psp.setBrand(pspm.getKey());
853
					psp.setBrand(pspm.getKey());
732
				psp.setFofoId(pspm.getValue().getFofoId());
854
					psp.setFofoId(pspm.getValue().getFofoId());
733
				psp.setSecondaryPlan(pspm.getValue().getTargetPlan());
855
					psp.setSecondaryPlan(pspm.getValue().getTargetPlan());
734
				psp.setCreateTimestamp(LocalDateTime.now());
856
					psp.setCreateTimestamp(LocalDateTime.now());
735
				psp.setUpdatedTimestamp(LocalDateTime.now());
857
					psp.setUpdatedTimestamp(LocalDateTime.now());
-
 
858
					psp.setActive(true);
736
				partnerSecondaryPlanRepository.persist(psp);
859
					partnerSecondaryPlanRepository.persist(psp);
-
 
860
				}
-
 
861
 
-
 
862
			} else {
-
 
863
				if (plan.getTargetPlan() != psp.getSecondaryPlan()) {
-
 
864
					float totalSecondaryPlan = psp.getSecondaryPlan() + 10000;
-
 
865
					if (authUser.getId() == plan.getAuthId()) {
-
 
866
						if (plan.getTargetPlan() >= totalSecondaryPlan) {
-
 
867
							psp.setSecondaryPlan(pspm.getValue().getTargetPlan());
-
 
868
							psp.setUpdatedTimestamp(LocalDateTime.now());
-
 
869
							psp.setActive(true);
-
 
870
						} else {
-
 
871
							throw new ProfitMandiBusinessException("secondary target", "",
-
 
872
									"secondary target should be more than " + totalSecondaryPlan);
-
 
873
						}
-
 
874
 
-
 
875
					} else {
-
 
876
 
-
 
877
						if (plan.getTargetPlan() >= totalSecondaryPlan) {
-
 
878
 
-
 
879
							psp.setUpdatedTimestamp(LocalDateTime.now());
-
 
880
							psp.setActive(false);
-
 
881
 
-
 
882
							psp = new PartnerSecondaryPlan();
-
 
883
							psp.setAuthId(authUser.getId());
-
 
884
							psp.setBrand(pspm.getKey());
-
 
885
							psp.setFofoId(pspm.getValue().getFofoId());
-
 
886
							psp.setSecondaryPlan(pspm.getValue().getTargetPlan());
-
 
887
							psp.setCreateTimestamp(LocalDateTime.now());
-
 
888
							psp.setUpdatedTimestamp(LocalDateTime.now());
-
 
889
							psp.setActive(true);
-
 
890
							partnerSecondaryPlanRepository.persist(psp);
-
 
891
						} else {
-
 
892
							throw new ProfitMandiBusinessException("secondary target", "",
-
 
893
									"secondary target should be more than " + totalSecondaryPlan);
-
 
894
						}
-
 
895
					}
-
 
896
				}
737
			}
897
			}
738
		}
898
		}
739
 
899
 
740
		return responseSender.ok(true);
900
		return responseSender.ok(true);
741
	}
901
	}