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