Subversion Repositories SmartDukaan

Rev

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

Rev 30292 Rev 30416
Line 8... Line 8...
8
import java.util.Arrays;
8
import java.util.Arrays;
9
import java.util.HashMap;
9
import java.util.HashMap;
10
import java.util.HashSet;
10
import java.util.HashSet;
11
import java.util.List;
11
import java.util.List;
12
import java.util.Map;
12
import java.util.Map;
-
 
13
import java.util.Set;
-
 
14
import java.util.TreeMap;
13
import java.util.stream.Collectors;
15
import java.util.stream.Collectors;
14
 
16
 
15
import javax.servlet.http.HttpServletRequest;
17
import javax.servlet.http.HttpServletRequest;
16
import javax.servlet.http.HttpServletResponse;
18
import javax.servlet.http.HttpServletResponse;
17
import javax.transaction.Transactional;
19
import javax.transaction.Transactional;
Line 24... Line 26...
24
import org.springframework.http.HttpHeaders;
26
import org.springframework.http.HttpHeaders;
25
import org.springframework.http.HttpStatus;
27
import org.springframework.http.HttpStatus;
26
import org.springframework.http.ResponseEntity;
28
import org.springframework.http.ResponseEntity;
27
import org.springframework.stereotype.Controller;
29
import org.springframework.stereotype.Controller;
28
import org.springframework.ui.Model;
30
import org.springframework.ui.Model;
-
 
31
import org.springframework.util.StringUtils;
29
import org.springframework.web.bind.annotation.RequestBody;
32
import org.springframework.web.bind.annotation.RequestBody;
30
import org.springframework.web.bind.annotation.RequestMapping;
33
import org.springframework.web.bind.annotation.RequestMapping;
31
import org.springframework.web.bind.annotation.RequestMethod;
34
import org.springframework.web.bind.annotation.RequestMethod;
32
import org.springframework.web.bind.annotation.RequestParam;
35
import org.springframework.web.bind.annotation.RequestParam;
33
import org.springframework.web.bind.annotation.RequestPart;
36
import org.springframework.web.bind.annotation.RequestPart;
34
import org.springframework.web.multipart.MultipartFile;
37
import org.springframework.web.multipart.MultipartFile;
35
 
38
 
36
import com.google.gson.Gson;
39
import com.google.gson.Gson;
37
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
40
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
41
import com.spice.profitmandi.common.model.CustomRetailer;
38
import com.spice.profitmandi.common.model.Legend;
42
import com.spice.profitmandi.common.model.Legend;
39
import com.spice.profitmandi.common.model.OptionModel;
43
import com.spice.profitmandi.common.model.OptionModel;
40
import com.spice.profitmandi.common.model.PieLables;
44
import com.spice.profitmandi.common.model.PieLables;
41
import com.spice.profitmandi.common.model.ProfitMandiConstants;
45
import com.spice.profitmandi.common.model.ProfitMandiConstants;
42
import com.spice.profitmandi.common.util.FileUtil;
46
import com.spice.profitmandi.common.util.FileUtil;
43
import com.spice.profitmandi.dao.entity.auth.AuthUser;
47
import com.spice.profitmandi.dao.entity.auth.AuthUser;
-
 
48
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
44
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
49
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
45
import com.spice.profitmandi.dao.entity.user.Lead;
50
import com.spice.profitmandi.dao.entity.user.Lead;
46
import com.spice.profitmandi.dao.entity.user.LeadActivity;
51
import com.spice.profitmandi.dao.entity.user.LeadActivity;
47
import com.spice.profitmandi.dao.enumuration.dtr.LeadSource;
52
import com.spice.profitmandi.dao.enumuration.dtr.LeadSource;
48
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
53
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
49
import com.spice.profitmandi.dao.model.ChartLeadModel;
54
import com.spice.profitmandi.dao.model.ChartLeadModel;
50
import com.spice.profitmandi.dao.model.CreateLeacdActivityRequest;
55
import com.spice.profitmandi.dao.model.CreateLeacdActivityRequest;
51
import com.spice.profitmandi.dao.model.CreateRefferalRequest;
56
import com.spice.profitmandi.dao.model.CreateRefferalRequest;
52
import com.spice.profitmandi.dao.model.DataLeadModel;
57
import com.spice.profitmandi.dao.model.DataLeadModel;
53
import com.spice.profitmandi.dao.model.LeadStatusData;
58
import com.spice.profitmandi.dao.model.LeadStatusData;
-
 
59
import com.spice.profitmandi.dao.model.PartnerCollectionPlanModel;
54
import com.spice.profitmandi.dao.model.TeamCommitmentModel;
60
import com.spice.profitmandi.dao.model.TeamCommitmentModel;
55
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
61
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
56
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionPlanRepository;
62
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionPlanRepository;
-
 
63
import com.spice.profitmandi.dao.repository.cs.CsService;
57
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
64
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
-
 
65
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
58
import com.spice.profitmandi.dao.repository.dtr.LeadActivityRepository;
66
import com.spice.profitmandi.dao.repository.dtr.LeadActivityRepository;
59
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
67
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
-
 
68
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
60
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
69
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
61
import com.spice.profitmandi.service.AuthService;
70
import com.spice.profitmandi.service.AuthService;
-
 
71
import com.spice.profitmandi.service.PartnerCollectionService;
-
 
72
import com.spice.profitmandi.service.user.RetailerService;
62
import com.spice.profitmandi.web.model.LoginDetails;
73
import com.spice.profitmandi.web.model.LoginDetails;
63
import com.spice.profitmandi.web.util.CookiesProcessor;
74
import com.spice.profitmandi.web.util.CookiesProcessor;
64
import com.spice.profitmandi.web.util.MVCResponseSender;
75
import com.spice.profitmandi.web.util.MVCResponseSender;
65
 
76
 
66
@Controller
77
@Controller
Line 96... Line 107...
96
	private MVCResponseSender mvcResponseSender;
107
	private MVCResponseSender mvcResponseSender;
97
 
108
 
98
	@Autowired
109
	@Autowired
99
	private PartnerCollectionPlanRepository partnerCollectionPlanRepository;
110
	private PartnerCollectionPlanRepository partnerCollectionPlanRepository;
100
 
111
 
-
 
112
	@Autowired
-
 
113
	private CsService csService;
-
 
114
 
-
 
115
	@Autowired
-
 
116
	private FofoStoreRepository fofoStoreRepository;
-
 
117
 
-
 
118
	@Autowired
-
 
119
	private PartnerCollectionService partnerCollectionService;
-
 
120
 
-
 
121
	@Autowired
-
 
122
	private RetailerService retailerService;
-
 
123
 
-
 
124
	@Autowired
-
 
125
	private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
101
	List<LeadStatus> status = Arrays.asList(LeadStatus.notInterested, LeadStatus.finalized);
126
	List<LeadStatus> status = Arrays.asList(LeadStatus.notInterested, LeadStatus.finalized);
102
 
127
 
103
	@RequestMapping(value = "/getOpenLead", method = RequestMethod.GET)
128
	@RequestMapping(value = "/getOpenLead", method = RequestMethod.GET)
104
	public String getOpenLead(HttpServletRequest request,
129
	public String getOpenLead(HttpServletRequest request,
105
			@RequestParam(name = "leadStatus", required = false, defaultValue = "All") List<LeadStatus> leadStatus,
130
			@RequestParam(name = "leadStatus", required = false, defaultValue = "All") List<LeadStatus> leadStatus,
Line 800... Line 825...
800
 
825
 
801
		model.addAttribute("commitments", commitments);
826
		model.addAttribute("commitments", commitments);
802
		return "team-commitment-table";
827
		return "team-commitment-table";
803
 
828
 
804
	}
829
	}
-
 
830
 
-
 
831
	@RequestMapping(value = "/partnerHealth", method = RequestMethod.GET)
-
 
832
	public String partnerHealth(HttpServletRequest request,
-
 
833
			@RequestParam(name = "email", required = false) String email, Model model) throws Exception {
-
 
834
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
835
 
-
 
836
		if (StringUtils.isEmpty(email)) {
-
 
837
			email = loginDetails.getEmailId();
-
 
838
		} else {
-
 
839
			AuthUser selectedUser = authRepository.selectByEmailOrMobile(email);
-
 
840
 
-
 
841
			model.addAttribute("selectedUser", selectedUser);
-
 
842
 
-
 
843
		}
-
 
844
 
-
 
845
		AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
-
 
846
 
-
 
847
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
-
 
848
		Set<Integer> fofoIds = storeGuyMap.get(email);
-
 
849
		LocalDateTime startDate = LocalDate.now().atStartOfDay();
-
 
850
		if (fofoIds.size() > 0 && fofoIds != null) {
-
 
851
			List<Integer> fofoIdl = new ArrayList<>(fofoIds);
-
 
852
			List<Integer> fofoIdList = fofoStoreRepository.selectByRetailerIds(fofoIdl).stream()
-
 
853
					.filter(x -> !x.isInternal()).map(x -> x.getId()).collect(Collectors.toList());
-
 
854
 
-
 
855
			Map<Integer, PartnerCollectionPlanModel> foundCollectionMap = partnerCollectionService
-
 
856
					.getCollectionMap(fofoIdList, startDate);
-
 
857
 
-
 
858
			ChartLeadModel cm = this
-
 
859
					.getCollectionCount(foundCollectionMap.values().stream().collect(Collectors.toList()));
-
 
860
			model.addAttribute("chartPartnerHealth", gson.toJson(cm));
-
 
861
			Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = new HashMap<>();
-
 
862
 
-
 
863
			List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
-
 
864
					.selectAll(fofoIdList, startDate.toLocalDate().minusDays(1));
-
 
865
			if (!partnerDailyInvestments.isEmpty()) {
-
 
866
				partnerDailyInvestmentMap = partnerDailyInvestments.stream()
-
 
867
						.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
-
 
868
			}
-
 
869
 
-
 
870
			Map<LocalDate, Map<Integer, PartnerCollectionPlanModel>> pcpmMap = new TreeMap<>();
-
 
871
			for (int i = 0; i <= 6; i++) {
-
 
872
 
-
 
873
				Map<Integer, PartnerCollectionPlanModel> collectionMap = partnerCollectionService
-
 
874
						.getCollectionMap(fofoIdList, startDate.minusDays(i));
-
 
875
 
-
 
876
				pcpmMap.put(startDate.minusDays(i).toLocalDate(), collectionMap);
-
 
877
			}
-
 
878
 
-
 
879
			Map<Integer, PartnerCollectionPlanModel> todayPcpmMap = pcpmMap.get(startDate.toLocalDate());
-
 
880
			model.addAttribute("todayPcpmMap", todayPcpmMap);
-
 
881
 
-
 
882
			Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(fofoIdList);
-
 
883
			List<Integer> allReportees = authService.getAllReportees(authUser.getId());
-
 
884
			LOGGER.info("allReportees" + allReportees);
-
 
885
			List<Integer> salesPositionsAuthIds = positionRepository
-
 
886
					.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES).stream()
-
 
887
					.map(x -> x.getAuthUserId()).collect(Collectors.toList());
-
 
888
			LOGGER.info("salesPositionsAuthIds" + salesPositionsAuthIds);
-
 
889
			List<Integer> rbmPositionsAuthIds = positionRepository
-
 
890
					.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM).stream()
-
 
891
					.map(x -> x.getAuthUserId()).collect(Collectors.toList());
-
 
892
			LOGGER.info("rbmPositionsAuthIds" + rbmPositionsAuthIds);
-
 
893
 
-
 
894
			salesPositionsAuthIds.addAll(rbmPositionsAuthIds);
-
 
895
 
-
 
896
			LOGGER.info("sdddd" + salesPositionsAuthIds);
-
 
897
 
-
 
898
			Set<Integer> empHierarchy = allReportees.stream().filter(x -> salesPositionsAuthIds.contains(x))
-
 
899
					.collect(Collectors.toSet());
-
 
900
 
-
 
901
			LOGGER.info("empHierarchy" + empHierarchy);
-
 
902
			List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(new ArrayList<>(empHierarchy));
-
 
903
 
-
 
904
			LOGGER.info("dddd" + authUsers);
-
 
905
			model.addAttribute("authUsers", authUsers);
-
 
906
			model.addAttribute("partnerCollectionPlanMap", pcpmMap);
-
 
907
			model.addAttribute("partnerDailyInvestmentMap", partnerDailyInvestmentMap);
-
 
908
			model.addAttribute("customRetailers", customRetailers);
-
 
909
			model.addAttribute("rankColorMap", ProfitMandiConstants.Rank_Color_Map);
-
 
910
 
-
 
911
		}
-
 
912
		return "partner-health";
-
 
913
 
-
 
914
	}
-
 
915
 
-
 
916
	public ChartLeadModel getCollectionCount(List<PartnerCollectionPlanModel> pcpm)
-
 
917
			throws ProfitMandiBusinessException {
-
 
918
 
-
 
919
		Map<Integer, Long> rankCount = pcpm.stream().collect(Collectors.groupingBy(x -> x.getRank(),
-
 
920
				Collectors.mapping(PartnerCollectionPlanModel::getRank, Collectors.counting())));
-
 
921
 
-
 
922
		ChartLeadModel cm = new ChartLeadModel();
-
 
923
 
-
 
924
		HashSet<String> labels = new HashSet<String>();
-
 
925
		labels.add("Plan for Today");
-
 
926
		labels.add("Carry Forward");
-
 
927
		labels.add("Untouched");
-
 
928
		labels.add("Plan for Future");
-
 
929
		labels.add("Normal");
-
 
930
 
-
 
931
		List<String> backgroundColor = new ArrayList<>();
-
 
932
		List<Long> values = new ArrayList<>();
-
 
933
 
-
 
934
		for (String label : labels) {
-
 
935
 
-
 
936
			if (label.equals("Plan for Today")) {
-
 
937
				backgroundColor.add("#007bff");
-
 
938
				values.add(rankCount.get(1));
-
 
939
			}
-
 
940
			if (label.equals("Carry Forward")) {
-
 
941
				backgroundColor.add("#ffc107");
-
 
942
				values.add(rankCount.get(2));
-
 
943
			}
-
 
944
			if (label.equals("Untouched")) {
-
 
945
				backgroundColor.add("#dc3545");
-
 
946
				values.add(rankCount.get(3));
-
 
947
			}
-
 
948
			if (label.equals("Plan for Future")) {
-
 
949
				backgroundColor.add("#6c757d");
-
 
950
				values.add(rankCount.get(4));
-
 
951
			}
-
 
952
			if (label.equals("Normal")) {
-
 
953
				backgroundColor.add("White");
-
 
954
				values.add(rankCount.get(5));
-
 
955
			}
-
 
956
 
-
 
957
		}
-
 
958
 
-
 
959
		LOGGER.info("backgroundColor" + backgroundColor);
-
 
960
		LOGGER.info("labelsChartLead" + labels);
-
 
961
		LeadStatusData data = new LeadStatusData();
-
 
962
		data.setData(values);
-
 
963
		data.setBackgroundColor(backgroundColor);
-
 
964
		data.setLabel("DataSet 1");
-
 
965
 
-
 
966
		PieLables label = new PieLables();
-
 
967
		label.setFontColor("black");
-
 
968
		label.setFontSize(15);
-
 
969
 
-
 
970
		Legend legend = new Legend();
-
 
971
		legend.setLabels(label);
-
 
972
		legend.setPosition("left");
-
 
973
 
-
 
974
		List<LeadStatusData> dataList = new ArrayList<>();
-
 
975
		dataList.add(data);
-
 
976
 
-
 
977
		DataLeadModel datasets = new DataLeadModel();
-
 
978
		datasets.setDatasets(dataList);
-
 
979
		datasets.setLabels(labels);
-
 
980
 
-
 
981
		OptionModel om = new OptionModel();
-
 
982
		om.setLegend(legend);
-
 
983
 
-
 
984
		cm.setType("pie");
-
 
985
		cm.setData(datasets);
-
 
986
		cm.setOptions(om);
-
 
987
 
-
 
988
		return cm;
-
 
989
	}
-
 
990
 
805
}
991
}