Subversion Repositories SmartDukaan

Rev

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

Rev 30459 Rev 30522
Line 2... Line 2...
2
 
2
 
3
import java.io.ByteArrayInputStream;
3
import java.io.ByteArrayInputStream;
4
import java.io.InputStream;
4
import java.io.InputStream;
5
import java.time.LocalDate;
5
import java.time.LocalDate;
6
import java.time.LocalDateTime;
6
import java.time.LocalDateTime;
-
 
7
import java.time.format.DateTimeFormatter;
7
import java.util.ArrayList;
8
import java.util.ArrayList;
8
import java.util.Arrays;
9
import java.util.Arrays;
9
import java.util.HashMap;
10
import java.util.HashMap;
10
import java.util.HashSet;
11
import java.util.HashSet;
11
import java.util.List;
12
import java.util.List;
Line 22... Line 23...
22
 
23
 
23
import org.apache.commons.collections.map.HashedMap;
24
import org.apache.commons.collections.map.HashedMap;
24
import org.apache.commons.csv.CSVRecord;
25
import org.apache.commons.csv.CSVRecord;
25
import org.apache.logging.log4j.LogManager;
26
import org.apache.logging.log4j.LogManager;
26
import org.apache.logging.log4j.Logger;
27
import org.apache.logging.log4j.Logger;
-
 
28
import org.jsoup.select.Evaluator.IsEmpty;
27
import org.springframework.beans.factory.annotation.Autowired;
29
import org.springframework.beans.factory.annotation.Autowired;
28
import org.springframework.core.io.InputStreamResource;
30
import org.springframework.core.io.InputStreamResource;
29
import org.springframework.http.HttpHeaders;
31
import org.springframework.http.HttpHeaders;
30
import org.springframework.http.HttpStatus;
32
import org.springframework.http.HttpStatus;
31
import org.springframework.http.ResponseEntity;
33
import org.springframework.http.ResponseEntity;
Line 48... Line 50...
48
import com.spice.profitmandi.common.model.ProfitMandiConstants;
50
import com.spice.profitmandi.common.model.ProfitMandiConstants;
49
import com.spice.profitmandi.common.util.FileUtil;
51
import com.spice.profitmandi.common.util.FileUtil;
50
import com.spice.profitmandi.dao.entity.auth.AuthUser;
52
import com.spice.profitmandi.dao.entity.auth.AuthUser;
51
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
53
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
52
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
54
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
-
 
55
import com.spice.profitmandi.dao.entity.user.FranchiseeActivity;
-
 
56
import com.spice.profitmandi.dao.entity.user.FranchiseeVisit;
53
import com.spice.profitmandi.dao.entity.user.Lead;
57
import com.spice.profitmandi.dao.entity.user.Lead;
54
import com.spice.profitmandi.dao.entity.user.LeadActivity;
58
import com.spice.profitmandi.dao.entity.user.LeadActivity;
55
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
59
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
56
import com.spice.profitmandi.dao.enumuration.dtr.LeadSource;
60
import com.spice.profitmandi.dao.enumuration.dtr.LeadSource;
57
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
61
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
58
import com.spice.profitmandi.dao.model.ChartLeadModel;
62
import com.spice.profitmandi.dao.model.ChartLeadModel;
59
import com.spice.profitmandi.dao.model.CreateLeacdActivityRequest;
63
import com.spice.profitmandi.dao.model.CreateLeacdActivityRequest;
60
import com.spice.profitmandi.dao.model.CreateRefferalRequest;
64
import com.spice.profitmandi.dao.model.CreateRefferalRequest;
61
import com.spice.profitmandi.dao.model.DataLeadModel;
65
import com.spice.profitmandi.dao.model.DataLeadModel;
-
 
66
import com.spice.profitmandi.dao.model.DateRangeModel;
62
import com.spice.profitmandi.dao.model.LeadStatusData;
67
import com.spice.profitmandi.dao.model.LeadStatusData;
63
import com.spice.profitmandi.dao.model.PartnerCollectionAchievementModel;
68
import com.spice.profitmandi.dao.model.PartnerCollectionAchievementModel;
64
import com.spice.profitmandi.dao.model.PartnerCollectionPlanModel;
69
import com.spice.profitmandi.dao.model.PartnerCollectionPlanModel;
65
import com.spice.profitmandi.dao.model.TeamCommitmentModel;
70
import com.spice.profitmandi.dao.model.TeamCommitmentModel;
66
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
71
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
67
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionPlanRepository;
72
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionPlanRepository;
68
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionRemarkRepository;
73
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionRemarkRepository;
69
import com.spice.profitmandi.dao.repository.cs.CsService;
74
import com.spice.profitmandi.dao.repository.cs.CsService;
70
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
75
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
71
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
76
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
-
 
77
import com.spice.profitmandi.dao.repository.dtr.FranchiseeActivityRepository;
-
 
78
import com.spice.profitmandi.dao.repository.dtr.FranchiseeVisitRepository;
72
import com.spice.profitmandi.dao.repository.dtr.LeadActivityRepository;
79
import com.spice.profitmandi.dao.repository.dtr.LeadActivityRepository;
73
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
80
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
74
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
81
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
75
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
82
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
76
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
83
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
Line 135... Line 142...
135
	private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
142
	private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
136
 
143
 
137
	@Autowired
144
	@Autowired
138
	private UserWalletRepository userWalletRepository;
145
	private UserWalletRepository userWalletRepository;
139
 
146
 
-
 
147
	@Autowired
-
 
148
	private FranchiseeVisitRepository franchiseeVisitRepository;
-
 
149
 
-
 
150
	@Autowired
-
 
151
	private FranchiseeActivityRepository franchiseeActivityRepository;
-
 
152
 
140
	List<LeadStatus> status = Arrays.asList(LeadStatus.notInterested, LeadStatus.finalized);
153
	List<LeadStatus> status = Arrays.asList(LeadStatus.notInterested, LeadStatus.finalized);
141
 
154
 
142
	@RequestMapping(value = "/getOpenLead", method = RequestMethod.GET)
155
	@RequestMapping(value = "/getOpenLead", method = RequestMethod.GET)
143
	public String getOpenLead(HttpServletRequest request,
156
	public String getOpenLead(HttpServletRequest request,
144
			@RequestParam(name = "leadStatus", required = false, defaultValue = "All") List<LeadStatus> leadStatus,
157
			@RequestParam(name = "leadStatus", required = false, defaultValue = "All") List<LeadStatus> leadStatus,
Line 1061... Line 1074...
1061
		cm.setOptions(om);
1074
		cm.setOptions(om);
1062
 
1075
 
1063
		return cm;
1076
		return cm;
1064
	}
1077
	}
1065
 
1078
 
-
 
1079
	@RequestMapping(value = "/franchiseVisit", method = RequestMethod.GET)
-
 
1080
	public String franchiseVisit(HttpServletRequest request,
-
 
1081
			@RequestParam(name = "email", required = false) String email, Model model) throws Exception {
-
 
1082
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
1083
 
-
 
1084
		AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
-
 
1085
 
-
 
1086
		List<Integer> salesPositionsAuthIds = positionRepository
-
 
1087
				.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES).stream()
-
 
1088
				.map(x -> x.getAuthUserId()).collect(Collectors.toList());
-
 
1089
		List<Integer> rbmPositionsAuthIds = positionRepository
-
 
1090
				.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM).stream()
-
 
1091
				.map(x -> x.getAuthUserId()).collect(Collectors.toList());
-
 
1092
 
-
 
1093
		salesPositionsAuthIds.addAll(rbmPositionsAuthIds);
-
 
1094
 
-
 
1095
		List<Integer> allReportees = authService.getAllReportees(authUser.getId());
-
 
1096
 
-
 
1097
		Set<Integer> empHierarchy = allReportees.stream().filter(x -> salesPositionsAuthIds.contains(x))
-
 
1098
				.collect(Collectors.toSet());
-
 
1099
 
-
 
1100
		List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(new ArrayList<>(empHierarchy));
-
 
1101
 
-
 
1102
		Map<Integer, String> monthValueMap = new HashMap<>();
-
 
1103
		for (int i = 0; i <= 5; i++) {
-
 
1104
			LocalDateTime startOfMonth = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
-
 
1105
			monthValueMap.put(i, startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
-
 
1106
		}
-
 
1107
 
-
 
1108
		model.addAttribute("authUsers", authUsers);
-
 
1109
		model.addAttribute("monthValueMap", monthValueMap);
-
 
1110
 
-
 
1111
		return "franchise-visit";
-
 
1112
 
-
 
1113
	}
-
 
1114
 
-
 
1115
	@RequestMapping(value = "/getFranchiseVisit", method = RequestMethod.GET)
-
 
1116
	public String getFranchiseVisit(HttpServletRequest request,
-
 
1117
			@RequestParam(name = "authId", required = false) int authId, int yearMonth, Model model) throws Exception {
-
 
1118
 
-
 
1119
		LocalDateTime startDate = LocalDate.now().minusMonths(8).withDayOfMonth(1).atStartOfDay();
-
 
1120
		LocalDateTime endDate = startDate.plusMonths(1).withDayOfMonth(1).toLocalDate().atStartOfDay();
-
 
1121
 
-
 
1122
		DateRangeModel drm = DateRangeModel.of(startDate, endDate);
-
 
1123
 
-
 
1124
		List<FranchiseeVisit> visits = franchiseeVisitRepository.selectByAuthUserAndDateRange(drm, authId);
-
 
1125
 
-
 
1126
		if (!visits.isEmpty()) {
-
 
1127
 
-
 
1128
			Map<Integer, List<FranchiseeVisit>> franchiseeVisitMap = visits.stream()
-
 
1129
					.collect(Collectors.groupingBy(x -> x.getScheduleTimestamp().getDayOfMonth()));
-
 
1130
 
-
 
1131
			model.addAttribute("franchiseeVisitMap", franchiseeVisitMap);
-
 
1132
 
-
 
1133
		}
-
 
1134
 
-
 
1135
		model.addAttribute("visits", visits);
-
 
1136
		model.addAttribute("monthLength", startDate.toLocalDate().lengthOfMonth());
-
 
1137
 
-
 
1138
		// Calender
-
 
1139
 
-
 
1140
		int Year = startDate.getYear(); // year
-
 
1141
		int startDayOfMonth = 5;
-
 
1142
		int spaces = startDayOfMonth;
-
 
1143
 
-
 
1144
		int month = startDate.getMonthValue();
-
 
1145
 
-
 
1146
		int[] days = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
-
 
1147
 
-
 
1148
		LOGGER.info("visits {} ", visits);
-
 
1149
 
-
 
1150
		if ((((Year % 4 == 0) && (Year % 100 != 0)) || (Year % 400 == 0)) && month == 2) {
-
 
1151
			days[month] = 29;
-
 
1152
		}
-
 
1153
 
-
 
1154
		spaces = (days[month - 1] + spaces) % 7;
-
 
1155
 
-
 
1156
		model.addAttribute("month", month);
-
 
1157
		model.addAttribute("spaces", spaces);
-
 
1158
		model.addAttribute("days", days);
-
 
1159
 
-
 
1160
		return "franchise-visit-container";
-
 
1161
 
-
 
1162
	}
-
 
1163
 
-
 
1164
	@RequestMapping(value = "/getFranchiseeActivity", method = RequestMethod.GET)
-
 
1165
	public String getFranchiseeActivity(HttpServletRequest request, int visitId, Model model) throws Exception {
-
 
1166
 
-
 
1167
		List<FranchiseeActivity> franchiseeActivities = franchiseeActivityRepository.selectByFranchiseeVisitId(visitId);
-
 
1168
 
-
 
1169
		FranchiseeVisit franchiseeVisit = franchiseeVisitRepository.selectById(visitId);
-
 
1170
 
-
 
1171
		Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAll().stream()
-
 
1172
				.collect(Collectors.toMap(x -> x.getId(), x -> x));
-
 
1173
		model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
-
 
1174
 
-
 
1175
		model.addAttribute("franchiseeVisit", franchiseeVisit);
-
 
1176
		model.addAttribute("franchiseeActivity", franchiseeActivities.get(0));
-
 
1177
 
-
 
1178
		return "franchie-visit-detail";
-
 
1179
 
-
 
1180
	}
-
 
1181
 
1066
}
1182
}