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