| 33507 |
tejus.loha |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
4 |
import com.spice.profitmandi.common.enumuration.BusinessType;
|
|
|
5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 34107 |
tejus.loha |
6 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 33507 |
tejus.loha |
7 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
|
|
8 |
import com.spice.profitmandi.dao.entity.brandFee.BrandFee;
|
|
|
9 |
import com.spice.profitmandi.dao.entity.brandFee.BrandFeeCollection;
|
|
|
10 |
import com.spice.profitmandi.dao.entity.dtr.Otp;
|
|
|
11 |
import com.spice.profitmandi.dao.entity.onBoarding.*;
|
| 34107 |
tejus.loha |
12 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 33507 |
tejus.loha |
13 |
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
|
|
|
14 |
import com.spice.profitmandi.dao.enumuration.onBorading.onBoardingFormEnums.FeePaymentStatus;
|
|
|
15 |
import com.spice.profitmandi.dao.enumuration.onBorading.onBoardingFormEnums.LoiStatus;
|
|
|
16 |
import com.spice.profitmandi.dao.enumuration.onBorading.onBoardingFormEnums.StoreType;
|
|
|
17 |
import com.spice.profitmandi.dao.model.LoiFormModel;
|
|
|
18 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
|
|
19 |
import com.spice.profitmandi.dao.repository.brandFee.BrandFeeCollectionRepository;
|
|
|
20 |
import com.spice.profitmandi.dao.repository.brandFee.BrandFeeRepository;
|
| 33658 |
tejus.loha |
21 |
import com.spice.profitmandi.dao.repository.catalog.BrandCategoryRepository;
|
|
|
22 |
import com.spice.profitmandi.dao.repository.catalog.BrandsRepository;
|
| 33507 |
tejus.loha |
23 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
|
|
24 |
import com.spice.profitmandi.dao.repository.dtr.DistrictMasterRepository;
|
|
|
25 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
|
|
26 |
import com.spice.profitmandi.dao.repository.dtr.OtpRepository;
|
| 33747 |
tejus.loha |
27 |
import com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository;
|
| 33507 |
tejus.loha |
28 |
import com.spice.profitmandi.dao.repository.inventory.PartnerOnboardingService;
|
|
|
29 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 33658 |
tejus.loha |
30 |
import com.spice.profitmandi.dao.repository.onboarding.BrandCommitRepository;
|
|
|
31 |
import com.spice.profitmandi.dao.repository.onboarding.LoiBrandCommitmentRepository;
|
| 33507 |
tejus.loha |
32 |
import com.spice.profitmandi.dao.repository.onboarding.LoiDocMasterRepository;
|
|
|
33 |
import com.spice.profitmandi.dao.repository.onboarding.LoiDocRepository;
|
|
|
34 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 33658 |
tejus.loha |
35 |
import com.spice.profitmandi.dao.repository.user.BillingAddressRepository;
|
| 33507 |
tejus.loha |
36 |
import com.spice.profitmandi.dao.repository.user.LoiFormRepository;
|
|
|
37 |
import com.spice.profitmandi.dao.service.LoiDocModel;
|
|
|
38 |
import com.spice.profitmandi.dao.service.OTPResponse;
|
|
|
39 |
import com.spice.profitmandi.dao.service.OtpProcessor;
|
|
|
40 |
import com.spice.profitmandi.dao.service.loiForm.LoiFormService;
|
|
|
41 |
import com.spice.profitmandi.service.integrations.gstpro.GstProService;
|
|
|
42 |
import com.spice.profitmandi.service.integrations.gstpro.entity.GstDetails;
|
|
|
43 |
import com.spice.profitmandi.service.user.StoreTimelineTatService;
|
|
|
44 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
45 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
46 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
47 |
import org.apache.commons.lang3.tuple.Pair;
|
|
|
48 |
import org.apache.logging.log4j.LogManager;
|
|
|
49 |
import org.apache.logging.log4j.Logger;
|
|
|
50 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
51 |
import org.springframework.http.ResponseEntity;
|
|
|
52 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
53 |
import org.springframework.stereotype.Controller;
|
|
|
54 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
55 |
import org.springframework.ui.Model;
|
|
|
56 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
57 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
58 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
59 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
60 |
|
|
|
61 |
import javax.servlet.http.HttpServletRequest;
|
| 33617 |
tejus.loha |
62 |
import java.time.LocalDate;
|
| 33507 |
tejus.loha |
63 |
import java.time.LocalDateTime;
|
|
|
64 |
import java.util.*;
|
|
|
65 |
import java.util.stream.Collectors;
|
|
|
66 |
|
|
|
67 |
@Controller
|
|
|
68 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
69 |
public class LoiFormController {
|
| 34149 |
tejus.loha |
70 |
private static final Logger LOGGER = LogManager.getLogger(LoiFormController.class);
|
| 33507 |
tejus.loha |
71 |
@Autowired
|
|
|
72 |
DocumentRepository documentRepository;
|
|
|
73 |
@Autowired
|
|
|
74 |
AuthRepository authRepository;
|
|
|
75 |
@Autowired
|
|
|
76 |
StateRepository stateRepository;
|
|
|
77 |
@Autowired
|
|
|
78 |
DistrictMasterRepository districtMasterRepository;
|
|
|
79 |
@Autowired
|
|
|
80 |
LoiFormRepository loiFormRepository;
|
|
|
81 |
@Autowired
|
|
|
82 |
GstProService gstProService;
|
|
|
83 |
@Autowired
|
|
|
84 |
ObjectMapper objectMapper;
|
|
|
85 |
@Autowired
|
|
|
86 |
OrderRepository orderRepository;
|
|
|
87 |
@Autowired
|
|
|
88 |
LoiFormService loiFormService;
|
|
|
89 |
@Autowired
|
|
|
90 |
BrandFeeCollectionRepository brandFeeCollectionRepository;
|
|
|
91 |
@Autowired
|
|
|
92 |
BrandFeeRepository brandFeeRepository;
|
|
|
93 |
@Autowired
|
|
|
94 |
OtpProcessor otpProcessor;
|
|
|
95 |
@Autowired
|
|
|
96 |
OtpRepository otpRepository;
|
|
|
97 |
@Autowired
|
|
|
98 |
JavaMailSender mailSender;
|
|
|
99 |
@Autowired
|
|
|
100 |
LoiDocMasterRepository loiDocMasterList;
|
|
|
101 |
@Autowired
|
|
|
102 |
CsService csService;
|
|
|
103 |
@Autowired
|
|
|
104 |
PartnerOnboardingService partnerOnboardingService;
|
|
|
105 |
@Autowired
|
|
|
106 |
StoreTimelineTatService storeTimelineTatService;
|
|
|
107 |
@Autowired
|
|
|
108 |
LoiDocRepository loiDocRepository;
|
|
|
109 |
@Autowired
|
|
|
110 |
MVCResponseSender mvcResponseSender;
|
|
|
111 |
@Autowired
|
|
|
112 |
private CookiesProcessor cookiesProcessor;
|
| 33658 |
tejus.loha |
113 |
@Autowired
|
| 33879 |
tejus.loha |
114 |
BrandCommitRepository brandCommitRepository;
|
| 33658 |
tejus.loha |
115 |
@Autowired
|
|
|
116 |
BrandsRepository brandsRepository;
|
|
|
117 |
@Autowired
|
|
|
118 |
BrandCategoryRepository brandCategoryRepository;
|
|
|
119 |
@Autowired
|
|
|
120 |
BillingAddressRepository billingAddressRepository;
|
|
|
121 |
@Autowired
|
|
|
122 |
LoiBrandCommitmentRepository brandCommitmentRepository;
|
| 33747 |
tejus.loha |
123 |
@Autowired
|
|
|
124 |
PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
|
|
|
125 |
|
| 33710 |
tejus.loha |
126 |
List<String> agreedBrandFeeChangerEmail = Arrays.asList("sm@smartdukaan.com");
|
| 33507 |
tejus.loha |
127 |
|
| 33845 |
tejus.loha |
128 |
// Loi Form
|
|
|
129 |
@RequestMapping(value = "/loiForm", method = RequestMethod.GET)
|
| 33507 |
tejus.loha |
130 |
public String loiForm(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 33579 |
tejus.loha |
131 |
List<AuthUser> authUsersList = loiFormService.getReferalAuthList();
|
| 33507 |
tejus.loha |
132 |
List<BrandFee> brandFee = brandFeeRepository.selectFeeOnDate(LocalDateTime.now());
|
|
|
133 |
Set<Pair<StoreType, BrandFee>> storeTypeFeePairs = new HashSet<>();
|
|
|
134 |
for (BrandFee fee : brandFee) {
|
|
|
135 |
for (StoreType storeType : StoreType.values()) {
|
|
|
136 |
storeTypeFeePairs.add(Pair.of(storeType, fee));
|
|
|
137 |
}
|
|
|
138 |
}
|
| 34107 |
tejus.loha |
139 |
List<AuthUser> stateHeadList = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_SALES, Arrays.asList(EscalationType.L2, EscalationType.L3));
|
|
|
140 |
List<AuthUser> bdmList = csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L1);
|
| 33885 |
tejus.loha |
141 |
List<BrandCommit> brandCommits = brandCommitRepository.selectAllActiveBrand();
|
| 34195 |
tejus.loha |
142 |
model.addAttribute("businessTypes", BusinessType.values());
|
| 33658 |
tejus.loha |
143 |
model.addAttribute("brandCommits", brandCommits);
|
| 33507 |
tejus.loha |
144 |
model.addAttribute("storeTypeFeePairs", storeTypeFeePairs);
|
|
|
145 |
model.addAttribute("authUsersList", authUsersList);
|
| 34107 |
tejus.loha |
146 |
model.addAttribute("stateHeadList", stateHeadList);
|
|
|
147 |
model.addAttribute("bdmList", bdmList);
|
| 33845 |
tejus.loha |
148 |
return "loi-form";
|
| 33507 |
tejus.loha |
149 |
}
|
|
|
150 |
|
|
|
151 |
// use to validate GSTIN
|
|
|
152 |
@RequestMapping(value = "/gstValidate", method = RequestMethod.GET)
|
|
|
153 |
public ResponseEntity<?> gstValidate(HttpServletRequest request, @RequestParam String gstNo) throws Exception {
|
|
|
154 |
LOGGER.info("gstNo -" + gstNo);
|
|
|
155 |
GstDetails gstDetails = gstProService.getGstDetails(gstNo);
|
|
|
156 |
LOGGER.info("gstDetails -" + gstDetails);
|
| 34310 |
tejus.loha |
157 |
if(gstDetails !=null){
|
|
|
158 |
List<GstDetails.Pradr> adadr = gstDetails.getAdadr();
|
|
|
159 |
adadr.add(gstDetails.getPradr());
|
|
|
160 |
Collections.reverse(adadr);
|
|
|
161 |
LOGGER.info("list_of_adadr-" + adadr);
|
|
|
162 |
}
|
| 34026 |
tejus.loha |
163 |
return ResponseEntity.ok(gstDetails);
|
| 33507 |
tejus.loha |
164 |
}
|
|
|
165 |
|
| 34026 |
tejus.loha |
166 |
// Save Loi data in fofo.loi_form table
|
| 33577 |
tejus.loha |
167 |
@RequestMapping(value = "/submitLoiForm", method = RequestMethod.POST)
|
| 33568 |
tejus.loha |
168 |
public String submitLoiForm(HttpServletRequest request, @RequestBody LoiFormData loiFormData, Model model) throws Exception {
|
| 33507 |
tejus.loha |
169 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 33577 |
tejus.loha |
170 |
LOGGER.info("filledBy - " + loginDetails.getEmailId());
|
|
|
171 |
boolean isDataCreated = loiFormService.createLoiForm(loiFormData, loginDetails.getEmailId());
|
| 33507 |
tejus.loha |
172 |
if (isDataCreated) {
|
|
|
173 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
174 |
return "response";
|
|
|
175 |
} else {
|
|
|
176 |
model.addAttribute("response1", mvcResponseSender.createResponseString(false));
|
|
|
177 |
return "response";
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
|
| 34026 |
tejus.loha |
181 |
// show all pending loi form to specific auth user who have filled the form(type based)
|
| 33710 |
tejus.loha |
182 |
@RequestMapping(value = "/pendingLoiForm", method = RequestMethod.GET)
|
| 33507 |
tejus.loha |
183 |
public String pendingLoiForm(HttpServletRequest request, Model model) throws Exception {
|
|
|
184 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
185 |
String email = loginDetails.getEmailId();
|
|
|
186 |
boolean isDocApprover = false;
|
|
|
187 |
String approverEmail = "gaurav.sharma@smartdukaan.com";
|
|
|
188 |
if (email.equals(approverEmail)) {
|
|
|
189 |
isDocApprover = true;
|
|
|
190 |
}
|
| 33710 |
tejus.loha |
191 |
boolean isAgreedBrandFeeChanger = agreedBrandFeeChangerEmail.stream().anyMatch(x -> x.equals(email));
|
| 33711 |
tejus.loha |
192 |
List<String> authEmail = Arrays.asList("sm@smartdukaan.com", "tarun.verma@smartdukaan.com", "ashutosh.verma@smartdukaan.com");
|
| 33710 |
tejus.loha |
193 |
boolean isAuthUser = authEmail.stream().anyMatch(x -> x.equals(email));
|
| 33507 |
tejus.loha |
194 |
List<LoiFormModel> pendingFormList = loiFormService.pendingFormList(email);
|
|
|
195 |
model.addAttribute("isDocApprover", isDocApprover);
|
| 33617 |
tejus.loha |
196 |
model.addAttribute("isAuthUser", isAuthUser);
|
| 33710 |
tejus.loha |
197 |
model.addAttribute("isAgreedBrandFeeChanger", isAgreedBrandFeeChanger);
|
| 33507 |
tejus.loha |
198 |
model.addAttribute("pendingFormList", pendingFormList);
|
| 34085 |
tejus.loha |
199 |
model.addAttribute("brandType", StoreType.valueList);
|
| 33507 |
tejus.loha |
200 |
return "pendingForm";
|
|
|
201 |
}
|
|
|
202 |
|
| 34085 |
tejus.loha |
203 |
// @RequestMapping(value = "/pendingLoiFormList", method = RequestMethod.GET)
|
|
|
204 |
// public String pendingLoiForm1(HttpServletRequest request, @RequestParam int pageSize, @RequestParam int pageNumber, Model model) throws Exception {
|
|
|
205 |
// LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
206 |
// String email = loginDetails.getEmailId();
|
|
|
207 |
// Map<String, Object> pendingFormMap = loiFormService.pendingFormList(email);
|
|
|
208 |
// model.addAttribute("pendingFormList", pendingFormMap.get("pendingFormModelList"));
|
|
|
209 |
// model.addAttribute("paginationInfo", this.getPaginationInfo(pageNumber,pageSize,(long)pendingFormMap.get("totalCount")));
|
|
|
210 |
// return "loiData";
|
|
|
211 |
// }
|
|
|
212 |
// public String getPaginationInfo(int currentPage, int pageSize, long totalEntries) {
|
|
|
213 |
// // Calculate the starting index
|
|
|
214 |
// int start = (currentPage - 1) * pageSize + 1; // Start from 1
|
|
|
215 |
// // Calculate the ending index
|
|
|
216 |
// int end = Math.min(start + pageSize - 1, (int) totalEntries); // Ensure it doesn't exceed totalEntries
|
|
|
217 |
//
|
|
|
218 |
// return "Showing " + start + " to " + end + " of " + totalEntries + " entries";
|
|
|
219 |
// }
|
|
|
220 |
|
| 33507 |
tejus.loha |
221 |
// generate LOI for specific Form data
|
|
|
222 |
@RequestMapping(value = "/generateLoi", method = RequestMethod.GET)
|
| 33845 |
tejus.loha |
223 |
public String generateLoi(HttpServletRequest request, @RequestParam int loiId, Model model) throws ProfitMandiBusinessException {
|
| 33507 |
tejus.loha |
224 |
LoiForm loiForm = loiFormRepository.selectById(loiId);
|
| 33630 |
tejus.loha |
225 |
String filledBy = authRepository.selectByEmailOrMobile(loiForm.getFilledBy()).getFullName();
|
| 33507 |
tejus.loha |
226 |
loiForm.setLoiGeneratedOn(LocalDateTime.now());
|
|
|
227 |
BrandFee brandFee = brandFeeRepository.selectById(1);
|
| 33658 |
tejus.loha |
228 |
BillingAddress address = billingAddressRepository.selectByLoiFormId(loiId);
|
|
|
229 |
List<LoiBrandCommitment> loiBrandCommitments = brandCommitmentRepository.selectByLoiId(loiId).stream().filter(x -> x.getAmount() > 0).collect(Collectors.toList());
|
|
|
230 |
double totalCommitment = loiBrandCommitments.stream().mapToDouble(x -> x.getAmount()).sum();
|
| 33845 |
tejus.loha |
231 |
List<BrandFeeCollection> brandFeeCollections = brandFeeCollectionRepository.selectAllConfirmPaymetByLoiId(loiId);
|
|
|
232 |
double brandFeeAmount = brandFeeCollections.stream().mapToDouble(x -> x.getCollectedAmount()).sum();
|
| 33658 |
tejus.loha |
233 |
BrandFeeCollection brandFeeCollection = brandFeeCollections.get(0);
|
|
|
234 |
model.addAttribute("totalCommitment", totalCommitment);
|
|
|
235 |
model.addAttribute("loiBrandCommitments", loiBrandCommitments);
|
| 33507 |
tejus.loha |
236 |
model.addAttribute("brandFeeAmount", brandFeeAmount);
|
|
|
237 |
model.addAttribute("brandFee", brandFee);
|
|
|
238 |
model.addAttribute("brandFeeCollection", brandFeeCollection);
|
|
|
239 |
model.addAttribute("address", address);
|
| 33658 |
tejus.loha |
240 |
model.addAttribute("loiForm", loiForm);
|
| 33630 |
tejus.loha |
241 |
model.addAttribute("filledBy", filledBy);
|
| 33507 |
tejus.loha |
242 |
return "auto-Loi";
|
|
|
243 |
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
|
|
|
247 |
// send Filled form for update purpose
|
| 33658 |
tejus.loha |
248 |
@RequestMapping(value = "/updateLoiForm", method = RequestMethod.GET)
|
| 33507 |
tejus.loha |
249 |
public String UpdateLoiForm(HttpServletRequest request,
|
|
|
250 |
@RequestParam int loiId,
|
|
|
251 |
Model model) throws ProfitMandiBusinessException {
|
|
|
252 |
LoiForm loiForm = loiFormRepository.selectById(loiId);
|
| 33658 |
tejus.loha |
253 |
model.addAttribute("updateForm", true);
|
|
|
254 |
model.addAttribute("loiForm", loiForm);
|
|
|
255 |
return "loiForm/update-loiForm";
|
| 33507 |
tejus.loha |
256 |
}
|
|
|
257 |
|
| 33577 |
tejus.loha |
258 |
@RequestMapping(value = "/updateLoiFormData", method = RequestMethod.POST)
|
| 33507 |
tejus.loha |
259 |
public String UpdateLoiFormDetail(HttpServletRequest request,
|
|
|
260 |
@RequestParam int loiId,
|
| 33658 |
tejus.loha |
261 |
@RequestBody LoiFormData loiFormData,
|
| 33507 |
tejus.loha |
262 |
Model model) throws Exception {
|
| 33658 |
tejus.loha |
263 |
loiFormService.updateLoiForm(loiFormData, loiId);
|
| 33507 |
tejus.loha |
264 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
265 |
return "response";
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
@RequestMapping(value = "/brandfeeCollection", method = RequestMethod.POST)
|
|
|
269 |
public String addBrandFee(HttpServletRequest request, @RequestBody BrandFeeCollection brandFeeCollection, @RequestParam int loiId, Model model) throws Exception {
|
|
|
270 |
LoiForm loiForm = loiFormRepository.selectById(loiId);
|
| 34086 |
tejus.loha |
271 |
double totatcollectedfee = brandFeeCollectionRepository.selectAllConfirmPaymetByLoiId(loiId).stream().mapToDouble(x -> x.getCollectedAmount()).sum();
|
| 33507 |
tejus.loha |
272 |
double brandFee = loiForm.getAgreedBrandFees();
|
|
|
273 |
double differanceAmount = brandFee - totatcollectedfee;
|
|
|
274 |
if (totatcollectedfee + brandFeeCollection.getCollectedAmount() <= brandFee) {
|
|
|
275 |
brandFeeCollection.setPaymentStatus(FeePaymentStatus.PENDING);
|
| 33658 |
tejus.loha |
276 |
brandFeeCollection.setLoiFormId(loiId);
|
|
|
277 |
brandFeeCollectionRepository.persist(brandFeeCollection);
|
| 33885 |
tejus.loha |
278 |
// loiFormService.sentMailToPaymentApprover(brandFeeCollection, loiForm);
|
| 33507 |
tejus.loha |
279 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
280 |
return "response";
|
|
|
281 |
} else {
|
|
|
282 |
throw new ProfitMandiBusinessException("You need to add only due brand fee that is Only, " + differanceAmount + " INR", null, "Pay differance amount or less then differance amount");
|
|
|
283 |
}
|
|
|
284 |
}
|
|
|
285 |
|
|
|
286 |
|
| 33617 |
tejus.loha |
287 |
@RequestMapping(value = "/paymentsDetail", method = RequestMethod.GET)
|
| 33507 |
tejus.loha |
288 |
public String paymentsDetails(HttpServletRequest request, @RequestParam int loiId, Model model) throws ProfitMandiBusinessException {
|
|
|
289 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
290 |
String email = loginDetails.getEmailId();
|
|
|
291 |
boolean isNiraj = false;
|
|
|
292 |
if (email.equals("neeraj.gupta@smartdukaan.com")) {
|
|
|
293 |
isNiraj = true;
|
|
|
294 |
}
|
| 33658 |
tejus.loha |
295 |
List<BrandFeeCollection> brandFeeCollections = brandFeeCollectionRepository.selectAllByLoiFormId(loiId);
|
| 33507 |
tejus.loha |
296 |
model.addAttribute("brandFeeCollections", brandFeeCollections);
|
|
|
297 |
model.addAttribute("confirm", FeePaymentStatus.CONFIRM);
|
|
|
298 |
model.addAttribute("isNiraj", isNiraj);
|
|
|
299 |
return "payment-collection-details";
|
|
|
300 |
}
|
|
|
301 |
|
|
|
302 |
// bfcId - Brand Fee Collection Id
|
| 33617 |
tejus.loha |
303 |
@RequestMapping(value = "/feePaymentApproval", method = RequestMethod.PUT)
|
| 33525 |
tejus.loha |
304 |
public String feePaymentApproval(HttpServletRequest request, @RequestParam int bfcId, @RequestParam FeePaymentStatus feePaymentStatus, @RequestParam String description,
|
|
|
305 |
Model model) throws Exception {
|
| 33507 |
tejus.loha |
306 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
307 |
String authEmail = loginDetails.getEmailId();
|
|
|
308 |
BrandFeeCollection brandFeeCollection = brandFeeCollectionRepository.selectById(bfcId);
|
|
|
309 |
brandFeeCollection.setApproverEmail(authEmail);
|
|
|
310 |
brandFeeCollection.setPaymentStatus(feePaymentStatus);
|
| 33525 |
tejus.loha |
311 |
brandFeeCollection.setDescription(description);
|
| 34195 |
tejus.loha |
312 |
brandFeeCollection.setApprovalTimeStamp(LocalDateTime.now());
|
| 33848 |
tejus.loha |
313 |
if (feePaymentStatus.equals(FeePaymentStatus.CONFIRM)) {
|
|
|
314 |
loiFormService.checkLoiDetailsCompletion(loiFormRepository.selectById(brandFeeCollection.getLoiFormId()));
|
|
|
315 |
}
|
| 33845 |
tejus.loha |
316 |
loiFormService.sendPaymentStatusMailToLoiFormFilledBy(brandFeeCollection);
|
|
|
317 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 33507 |
tejus.loha |
318 |
return "response";
|
|
|
319 |
|
|
|
320 |
}
|
|
|
321 |
|
| 33658 |
tejus.loha |
322 |
|
| 33617 |
tejus.loha |
323 |
@RequestMapping(value = "/uploadDocumentForm", method = RequestMethod.GET)
|
| 33507 |
tejus.loha |
324 |
public String uploadDocumentForm(HttpServletRequest request, @RequestParam int loiId, Model model) throws ProfitMandiBusinessException {
|
|
|
325 |
List<LoiDocMaster> activeDocMasterList = loiDocMasterList.getAllActiveDoc();
|
|
|
326 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
327 |
String authEmail = authRepository.selectByEmailOrMobile(loginDetails.getEmailId()).getEmailId();
|
|
|
328 |
String approverEmail = "gaurav.sharma@smartdukaan.com";
|
|
|
329 |
boolean isApprover = false;
|
|
|
330 |
if (authEmail.equals(approverEmail)) {
|
|
|
331 |
isApprover = true;
|
|
|
332 |
}
|
| 33845 |
tejus.loha |
333 |
Map<Integer, LoiDoc> masterDocIdLoiDocMap = loiDocRepository.selectByLoiFormId(loiId).stream().collect(Collectors.toMap(x -> x.getMasterDocId(), x -> x));
|
| 33507 |
tejus.loha |
334 |
model.addAttribute("isApprover", isApprover);
|
|
|
335 |
model.addAttribute("loiId", loiId);
|
|
|
336 |
model.addAttribute("activeDocMasterList", activeDocMasterList);
|
|
|
337 |
model.addAttribute("masterDocIdLoiDocMap", masterDocIdLoiDocMap);
|
|
|
338 |
return "loiForm/document-upload";
|
|
|
339 |
}
|
|
|
340 |
|
|
|
341 |
@RequestMapping(value = "/uploadOnboardingDocument", method = RequestMethod.POST)
|
|
|
342 |
public String uploadDocument(HttpServletRequest request, @RequestParam int loiId, @RequestBody List<LoiDocModel> loiDocModels, Model model) throws Exception {
|
|
|
343 |
LoiForm loiForm = loiFormRepository.selectById(loiId);
|
|
|
344 |
loiFormService.setDocs(loiForm, loiDocModels);
|
|
|
345 |
model.addAttribute("response1", mvcResponseSender.createResponseString("Document uploaded successfully"));
|
|
|
346 |
return "response";
|
|
|
347 |
|
|
|
348 |
}
|
|
|
349 |
|
|
|
350 |
|
| 33617 |
tejus.loha |
351 |
@RequestMapping(value = "/documentVerify", method = RequestMethod.PUT)
|
| 33507 |
tejus.loha |
352 |
public String docApproval(HttpServletRequest request, @RequestParam int loiId, @RequestParam int docMasterId, @RequestParam boolean flag, Model model) throws Exception {
|
|
|
353 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
354 |
AuthUser auth = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
355 |
LoiDoc loiDoc = loiDocRepository.selectByLoiIdAndMasterDocId(loiId, docMasterId);
|
|
|
356 |
if (flag) {
|
|
|
357 |
loiDoc.setOk(true);
|
|
|
358 |
loiDoc.setVerifyBy(auth.getId());
|
|
|
359 |
model.addAttribute("response1", mvcResponseSender.createResponseString(loiDoc.getDocType() + " is Accepted "));
|
|
|
360 |
return "response";
|
|
|
361 |
} else {
|
|
|
362 |
loiDoc.setOk(false);
|
|
|
363 |
loiDoc.setVerifyBy(auth.getId());
|
| 33658 |
tejus.loha |
364 |
loiFormService.sendDocRejectionMail(loiDoc);
|
| 33507 |
tejus.loha |
365 |
model.addAttribute("response1", mvcResponseSender.createResponseString(loiDoc.getDocType() + " is Rejected"));
|
|
|
366 |
return "response";
|
|
|
367 |
}
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
@RequestMapping(value = "/loiAcceptanceOtp", method = RequestMethod.POST)
|
|
|
371 |
public String sentLoiAcceptanceOtp(@RequestParam int loiId, Model model) throws Exception {
|
| 33658 |
tejus.loha |
372 |
LoiForm loiForm = loiFormRepository.selectById(loiId);
|
|
|
373 |
String mobile = String.valueOf(loiForm.getMobile());
|
| 33525 |
tejus.loha |
374 |
OTPResponse otpResponse = otpProcessor.generateOtp(mobile, OtpType.LOI_ACCEPTANCE);
|
| 33658 |
tejus.loha |
375 |
String message = "OTP send on your register mobile and EmailId - ";
|
| 33568 |
tejus.loha |
376 |
LOGGER.info("OTPResponse Message - " + otpResponse.getMessage());
|
|
|
377 |
if (otpResponse.isResult()) {
|
| 33658 |
tejus.loha |
378 |
model.addAttribute("response1", mvcResponseSender.createResponseString(message + mobile + " and " + loiForm.getEmail()));
|
| 33568 |
tejus.loha |
379 |
return "response";
|
| 33525 |
tejus.loha |
380 |
} else {
|
|
|
381 |
model.addAttribute("response1", mvcResponseSender.createResponseString("Something went wrong.."));
|
| 33568 |
tejus.loha |
382 |
return "response";
|
| 33525 |
tejus.loha |
383 |
}
|
| 33507 |
tejus.loha |
384 |
}
|
|
|
385 |
|
|
|
386 |
@RequestMapping(value = "/validateLoiOtp", method = RequestMethod.PUT)
|
|
|
387 |
public String validateLoiAcceptanceOtp(@RequestParam int loiId, @RequestParam String provideOtp, Model model) throws Exception {
|
| 33658 |
tejus.loha |
388 |
LoiForm loiForm = loiFormRepository.selectById(loiId);
|
|
|
389 |
String mobile = String.valueOf(loiForm.getMobile());
|
| 33507 |
tejus.loha |
390 |
Otp otp = otpRepository.selectAllByMobileWithTime(mobile).get(0);
|
|
|
391 |
OTPResponse otpResponse = otpProcessor.validateOtp(otp.getId(), mobile, provideOtp);
|
|
|
392 |
if (otpResponse.isResult()) {
|
| 33658 |
tejus.loha |
393 |
loiForm.setLoiSignOtp(provideOtp);
|
|
|
394 |
loiForm.setLoiSignedOn(LocalDateTime.now());
|
| 33507 |
tejus.loha |
395 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 33845 |
tejus.loha |
396 |
} else {
|
|
|
397 |
throw new ProfitMandiBusinessException("Wrong OTP", "", "Your given Otp ->" + provideOtp + " is wrong , please check OTP and try again");
|
| 33507 |
tejus.loha |
398 |
}
|
|
|
399 |
return "response";
|
|
|
400 |
}
|
|
|
401 |
|
| 33845 |
tejus.loha |
402 |
@RequestMapping(value = "/saveLoiDoc", method = RequestMethod.POST)
|
|
|
403 |
public String saveLoiDoc(@RequestParam int loiId, @RequestParam int loiDocId, Model model) throws Exception {
|
|
|
404 |
LOGGER.info("loi_docId-" + loiDocId);
|
|
|
405 |
LoiForm loiForm = loiFormRepository.selectById(loiId);
|
|
|
406 |
if (loiDocId > 0) {
|
|
|
407 |
loiForm.setLoiDoc(loiDocId);
|
|
|
408 |
loiFormService.sendSignedLoiPdfToPartner(loiForm);
|
| 33848 |
tejus.loha |
409 |
loiFormService.checkLoiDetailsCompletion(loiForm);
|
| 33845 |
tejus.loha |
410 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
411 |
} else {
|
|
|
412 |
loiForm.setLoiSignOtp("");
|
|
|
413 |
loiForm.setLoiGeneratedOn(null);
|
|
|
414 |
loiForm.setLoiSignedOn(null);
|
|
|
415 |
model.addAttribute("response1", mvcResponseSender.createResponseString(false));
|
|
|
416 |
}
|
|
|
417 |
return "response";
|
|
|
418 |
|
|
|
419 |
}
|
|
|
420 |
|
| 33617 |
tejus.loha |
421 |
@RequestMapping(value = "/downloadLoiFromReport", method = RequestMethod.GET)
|
|
|
422 |
public ResponseEntity<?> downloadAllLoiForm(@RequestParam LocalDate from, @RequestParam LocalDate to) throws Exception {
|
|
|
423 |
ResponseEntity<?> responseEntity = loiFormService.createLoiFormReport(from, to);
|
|
|
424 |
return responseEntity;
|
|
|
425 |
}
|
|
|
426 |
|
| 33658 |
tejus.loha |
427 |
@RequestMapping(value = "/updatePayment", method = RequestMethod.POST)
|
|
|
428 |
public String updateForm(@RequestBody BrandFeeCollection brandFeeCollection, Model model) throws Exception {
|
|
|
429 |
BrandFeeCollection brandFeeCollection1 = brandFeeCollectionRepository.selectById(brandFeeCollection.getId());
|
| 33845 |
tejus.loha |
430 |
LoiForm loiForm = loiFormRepository.selectById(brandFeeCollection1.getLoiFormId());
|
| 33850 |
tejus.loha |
431 |
brandFeeCollection1.setFeeCollectingTimeStamp(brandFeeCollection.getFeeCollectingTimeStamp());
|
|
|
432 |
brandFeeCollection1.setCollectedAmount(brandFeeCollection.getCollectedAmount());
|
| 33885 |
tejus.loha |
433 |
brandFeeCollection1.setPaymentAttachment(brandFeeCollection.getPaymentAttachment());
|
| 33850 |
tejus.loha |
434 |
brandFeeCollection1.setPaymentReferenceNo(brandFeeCollection.getPaymentReferenceNo());
|
|
|
435 |
brandFeeCollection1.setPaymentMode(brandFeeCollection.getPaymentMode());
|
|
|
436 |
double totalCollectedFee = brandFeeCollectionRepository.selectAllByLoiFormId(loiForm.getId()).stream().mapToDouble(x -> x.getCollectedAmount()).sum();
|
|
|
437 |
if (totalCollectedFee <= loiForm.getAgreedBrandFees()) {
|
| 33845 |
tejus.loha |
438 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
439 |
} else {
|
| 33850 |
tejus.loha |
440 |
double differanceAmount = totalCollectedFee - loiForm.getAgreedBrandFees();
|
| 33845 |
tejus.loha |
441 |
throw new ProfitMandiBusinessException("You need to add only due brand fee that is Only, " + differanceAmount + " INR", null, "Pay differance amount or less then differance amount");
|
|
|
442 |
}
|
| 33658 |
tejus.loha |
443 |
return "response";
|
|
|
444 |
}
|
| 33617 |
tejus.loha |
445 |
|
| 33710 |
tejus.loha |
446 |
@RequestMapping(value = "/updateAgreedBrandFee", method = RequestMethod.PUT)
|
| 34085 |
tejus.loha |
447 |
public String updateAgreedBrandFee(HttpServletRequest request, @RequestParam int loiId, @RequestParam double brandFee, @RequestParam StoreType storeType, Model model) throws Exception {
|
| 33710 |
tejus.loha |
448 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
449 |
boolean isAgreedBrandFeeChanger = agreedBrandFeeChangerEmail.stream().anyMatch(x -> x.equals(loginDetails.getEmailId()));
|
|
|
450 |
if (isAgreedBrandFeeChanger) {
|
|
|
451 |
LoiForm loiForm = loiFormRepository.selectById(loiId);
|
|
|
452 |
loiForm.setAgreedBrandFees(brandFee);
|
| 34085 |
tejus.loha |
453 |
loiForm.setBrandType(storeType);
|
| 34086 |
tejus.loha |
454 |
loiFormService.checkLoiDetailsCompletion(loiFormRepository.selectById(loiId));
|
| 33710 |
tejus.loha |
455 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
456 |
return "response";
|
|
|
457 |
} else {
|
|
|
458 |
throw new ProfitMandiBusinessException("failed in Authority check ", null, "Sorry " + authRepository.selectByEmailOrMobile(loginDetails.getEmailId()).getName() + " you have no authority to change agreed brand fee");
|
|
|
459 |
}
|
|
|
460 |
}
|
|
|
461 |
|
| 33845 |
tejus.loha |
462 |
|
|
|
463 |
@RequestMapping(value = "/approve-reject-Loi", method = RequestMethod.PUT)
|
|
|
464 |
public String approveDetails(HttpServletRequest request, @RequestParam int loiId, @RequestParam boolean flag, Model model) throws Exception {
|
|
|
465 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
466 |
String email = loginDetails.getEmailId();
|
| 33711 |
tejus.loha |
467 |
LoiForm loiForm = loiFormRepository.selectById(loiId);
|
| 33845 |
tejus.loha |
468 |
AuthUser filledBy = authRepository.selectByEmailOrMobile(loiForm.getFilledBy());
|
|
|
469 |
AuthUser manager = authRepository.selectById(filledBy.getManagerId());
|
|
|
470 |
AuthUser upperManager = null;
|
|
|
471 |
List<String> approverMail = new ArrayList<>();
|
|
|
472 |
approverMail.add(manager.getEmailId());
|
|
|
473 |
upperManager = authRepository.selectById(manager.getManagerId());
|
|
|
474 |
approverMail.add(upperManager.getEmailId());
|
|
|
475 |
|
|
|
476 |
LOGGER.info("approverMail-" + approverMail);
|
|
|
477 |
// Approver - Manager or Upper manager of loi filledBy(BM)
|
|
|
478 |
boolean isApprover = approverMail.contains(email);
|
|
|
479 |
LOGGER.info("isApprover-" + isApprover);
|
|
|
480 |
List<String> authEmail = Arrays.asList("sm@smartdukaan.com", "tarun.verma@smartdukaan.com", "ashutosh.verma@smartdukaan.com");
|
|
|
481 |
boolean isAuthUser = authEmail.stream().anyMatch(x -> x.equals(email));
|
|
|
482 |
if (flag) {
|
|
|
483 |
if (isApprover || isAuthUser) {
|
|
|
484 |
loiForm.setLoiApprover(email);
|
|
|
485 |
loiForm.setLoiApproved(flag);
|
|
|
486 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
487 |
} else {
|
|
|
488 |
throw new ProfitMandiBusinessException("Failed in Authority check ", "Read", "Sorry " + authRepository.selectByEmailOrMobile(loginDetails.getEmailId()).getName() + " you have no authority to Approve this Loi Form ,Only reporting manager and upper can Approve");
|
|
|
489 |
}
|
|
|
490 |
} else {
|
|
|
491 |
if (isApprover || isAuthUser) {
|
|
|
492 |
loiForm.setLoiApprover(email);
|
|
|
493 |
loiForm.setLoiApproved(flag);
|
|
|
494 |
loiForm.setStatus(LoiStatus.LOI_REJECT);
|
|
|
495 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
496 |
} else {
|
|
|
497 |
throw new ProfitMandiBusinessException("Failed in Authority check ", "Read", "Sorry " + authRepository.selectByEmailOrMobile(loginDetails.getEmailId()).getName() + " you have no authority to Approve this Loi Form ,Only reporting manager and upper can Approve");
|
|
|
498 |
}
|
|
|
499 |
}
|
| 33711 |
tejus.loha |
500 |
return "response";
|
|
|
501 |
}
|
|
|
502 |
|
| 33845 |
tejus.loha |
503 |
|
| 33507 |
tejus.loha |
504 |
}
|