Subversion Repositories SmartDukaan

Rev

Rev 33624 | Rev 33658 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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.common.model.ProfitMandiConstants;
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.fofo.PartnerOnBoardingPanel;
12
import com.spice.profitmandi.dao.entity.onBoarding.*;
13
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
14
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
15
import com.spice.profitmandi.dao.enumuration.onBorading.onBoardingFormEnums.FeePaymentStatus;
16
import com.spice.profitmandi.dao.enumuration.onBorading.onBoardingFormEnums.LoiStatus;
17
import com.spice.profitmandi.dao.enumuration.onBorading.onBoardingFormEnums.StoreType;
18
import com.spice.profitmandi.dao.model.LoiFormModel;
19
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
20
import com.spice.profitmandi.dao.repository.brandFee.BrandFeeCollectionRepository;
21
import com.spice.profitmandi.dao.repository.brandFee.BrandFeeRepository;
22
import com.spice.profitmandi.dao.repository.cs.CsService;
23
import com.spice.profitmandi.dao.repository.dtr.DistrictMasterRepository;
24
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
25
import com.spice.profitmandi.dao.repository.dtr.OtpRepository;
26
import com.spice.profitmandi.dao.repository.inventory.PartnerOnboardingService;
27
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
28
import com.spice.profitmandi.dao.repository.onboarding.LoiDocMasterRepository;
29
import com.spice.profitmandi.dao.repository.onboarding.LoiDocRepository;
30
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
31
import com.spice.profitmandi.dao.repository.user.LoiFormRepository;
32
import com.spice.profitmandi.dao.service.LoiDocModel;
33
import com.spice.profitmandi.dao.service.OTPResponse;
34
import com.spice.profitmandi.dao.service.OtpProcessor;
35
import com.spice.profitmandi.dao.service.loiForm.LoiFormService;
36
import com.spice.profitmandi.service.integrations.gstpro.GstProService;
37
import com.spice.profitmandi.service.integrations.gstpro.entity.GstDetails;
38
import com.spice.profitmandi.service.user.StoreTimelineTatService;
39
import com.spice.profitmandi.web.model.LoginDetails;
40
import com.spice.profitmandi.web.util.CookiesProcessor;
41
import com.spice.profitmandi.web.util.MVCResponseSender;
42
import org.apache.commons.lang3.tuple.Pair;
43
import org.apache.logging.log4j.LogManager;
44
import org.apache.logging.log4j.Logger;
45
import org.springframework.beans.factory.annotation.Autowired;
46
import org.springframework.http.HttpStatus;
47
import org.springframework.http.ResponseEntity;
48
import org.springframework.mail.javamail.JavaMailSender;
49
import org.springframework.stereotype.Controller;
50
import org.springframework.transaction.annotation.Transactional;
51
import org.springframework.ui.Model;
52
import org.springframework.web.bind.annotation.RequestBody;
53
import org.springframework.web.bind.annotation.RequestMapping;
54
import org.springframework.web.bind.annotation.RequestMethod;
55
import org.springframework.web.bind.annotation.RequestParam;
56
 
57
import javax.servlet.http.HttpServletRequest;
33617 tejus.loha 58
import java.time.LocalDate;
33507 tejus.loha 59
import java.time.LocalDateTime;
60
import java.util.*;
61
import java.util.stream.Collectors;
62
 
63
@Controller
64
@Transactional(rollbackFor = Throwable.class)
65
public class LoiFormController {
66
    private static final Logger LOGGER = LogManager.getLogger(PartnerOnBoardingPanelController.class);
67
    @Autowired
68
    DocumentRepository documentRepository;
69
    @Autowired
70
    AuthRepository authRepository;
71
    @Autowired
72
    StateRepository stateRepository;
73
    @Autowired
74
    DistrictMasterRepository districtMasterRepository;
75
    @Autowired
76
    LoiFormRepository loiFormRepository;
77
    @Autowired
78
    GstProService gstProService;
79
    @Autowired
80
    ObjectMapper objectMapper;
81
    @Autowired
82
    OrderRepository orderRepository;
83
    @Autowired
84
    LoiFormService loiFormService;
85
    @Autowired
86
    BrandFeeCollectionRepository brandFeeCollectionRepository;
87
    @Autowired
88
    BrandFeeRepository brandFeeRepository;
89
    @Autowired
90
    OtpProcessor otpProcessor;
91
    @Autowired
92
    OtpRepository otpRepository;
93
    @Autowired
94
    JavaMailSender mailSender;
95
    @Autowired
96
    LoiDocMasterRepository loiDocMasterList;
97
    @Autowired
98
    CsService csService;
99
    @Autowired
100
    PartnerOnboardingService partnerOnboardingService;
101
    @Autowired
102
    StoreTimelineTatService storeTimelineTatService;
103
    @Autowired
104
    LoiDocRepository loiDocRepository;
105
    @Autowired
106
    MVCResponseSender mvcResponseSender;
107
    @Autowired
108
    private CookiesProcessor cookiesProcessor;
109
 
110
    // OnBoarding Form
111
    @RequestMapping(value = "/onboardingForm", method = RequestMethod.GET)
112
    public String loiForm(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
113
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
114
        AuthUser selfAuth = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
33579 tejus.loha 115
        List<AuthUser> authUsersList = loiFormService.getReferalAuthList();
33507 tejus.loha 116
        List<BrandFee> brandFee = brandFeeRepository.selectFeeOnDate(LocalDateTime.now());
117
        LOGGER.info("brandFee - " + brandFee);
118
        Set<Pair<StoreType, BrandFee>> storeTypeFeePairs = new HashSet<>();
119
        for (BrandFee fee : brandFee) {
120
            for (StoreType storeType : StoreType.values()) {
121
                storeTypeFeePairs.add(Pair.of(storeType, fee));
122
            }
123
        }
124
        List<BusinessType> businessTypes = Arrays.asList(BusinessType.Proprietorship, BusinessType.Partnership, BusinessType.Company);
125
        model.addAttribute("businessTypes", businessTypes);
126
        model.addAttribute("storeTypeFeePairs", storeTypeFeePairs);
127
        model.addAttribute("authUsersList", authUsersList);
128
        model.addAttribute("selfAuth", selfAuth);
129
        return "partner-onboarding-form";
130
    }
131
 
132
    // use to validate GSTIN
133
    @RequestMapping(value = "/gstValidate", method = RequestMethod.GET)
134
    public ResponseEntity<?> gstValidate(HttpServletRequest request, @RequestParam String gstNo) throws Exception {
135
        LOGGER.info("gstNo -" + gstNo);
136
        GstDetails gstDetails = gstProService.getGstDetails(gstNo);
137
        LOGGER.info("gstDetails -" + gstDetails);
138
        List<GstDetails.Pradr> adadr = gstDetails.getAdadr();
139
        adadr.add(gstDetails.getPradr());
140
        Collections.reverse(adadr);
141
        LOGGER.info("list_of_adadr-" + adadr);
142
        String status = gstDetails.getSts();
143
        if (status.equals("Active")) {
144
            return ResponseEntity.ok(gstDetails);
145
        } else {
146
            String errorMsg = "GSTIN - " + gstNo + " Not Active";
147
            return new ResponseEntity(errorMsg, HttpStatus.INTERNAL_SERVER_ERROR);
148
        }
149
    }
150
 
151
    // bind the form data and save in fofo.Onboarding_form table
33577 tejus.loha 152
    @RequestMapping(value = "/submitLoiForm", method = RequestMethod.POST)
33568 tejus.loha 153
    public String submitLoiForm(HttpServletRequest request, @RequestBody LoiFormData loiFormData, Model model) throws Exception {
33507 tejus.loha 154
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
33577 tejus.loha 155
        LOGGER.info("filledBy - " + loginDetails.getEmailId());
156
        boolean isDataCreated = loiFormService.createLoiForm(loiFormData, loginDetails.getEmailId());
33507 tejus.loha 157
        List<LoiFormModel> formList = loiFormService.pendingFormList(loginDetails.getEmailId());
158
        model.addAttribute("formList", formList);
159
        if (isDataCreated) {
160
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
161
            return "response";
162
        } else {
163
            model.addAttribute("response1", mvcResponseSender.createResponseString(false));
164
            return "response";
165
        }
166
    }
167
 
168
    // show all pending Form to specific auth user who have filled the form(type based)
33617 tejus.loha 169
    @RequestMapping(value = "/pendingOnboardingForm", method = RequestMethod.GET)
33507 tejus.loha 170
    public String pendingLoiForm(HttpServletRequest request, Model model) throws Exception {
171
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
172
        String email = loginDetails.getEmailId();
173
        boolean isDocApprover = false;
174
        //todo:replace
175
        String approverEmail = "gaurav.sharma@smartdukaan.com";
176
        if (email.equals(approverEmail)) {
177
            isDocApprover = true;
178
        }
33617 tejus.loha 179
        boolean isAuthUser = false;
180
        List<String> authEmail = Arrays.asList("sm@smartdukaan.com", "gaurav.sharma@smartdukaan.com", "tejus.lohani@smartdukaan.com");
181
        isAuthUser = authEmail.stream().anyMatch(x -> x.equals(email));
33507 tejus.loha 182
        List<LoiFormModel> pendingFormList = loiFormService.pendingFormList(email);
183
        LOGGER.info("pendingFormList {}", pendingFormList);
184
        model.addAttribute("isDocApprover", isDocApprover);
33617 tejus.loha 185
        model.addAttribute("isAuthUser", isAuthUser);
33507 tejus.loha 186
        model.addAttribute("pendingFormList", pendingFormList);
187
        return "pendingForm";
188
    }
189
 
190
    // generate LOI for specific Form data
191
    @RequestMapping(value = "/generateLoi", method = RequestMethod.GET)
192
    public String generateLoi(HttpServletRequest request, @RequestParam int loiId, Model model) throws ProfitMandiBusinessException {
193
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
194
        int authId = authRepository.selectByEmailOrMobile(loginDetails.getEmailId()).getId();
195
        LoiForm loiForm = loiFormRepository.selectById(loiId);
33630 tejus.loha 196
        String filledBy = authRepository.selectByEmailOrMobile(loiForm.getFilledBy()).getFullName();
33507 tejus.loha 197
        loiForm.setLoiGeneratedBy(authId);
198
        loiForm.setLoiGeneratedOn(LocalDateTime.now());
199
        loiForm.setStatus(LoiStatus.LOI_GENERATED);
200
        BrandFee brandFee = brandFeeRepository.selectById(1);
201
        BrandFee givenFee = brandFeeRepository.selectById(loiForm.getBrandFeeId());
202
        BillingAddress address = loiForm.getBillingAddress();
203
        double brandFeeAmount = loiForm.getBrandFeeCollection().stream().filter(x -> x.getPaymentStatus().equals(FeePaymentStatus.CONFIRM)).mapToDouble(x -> x.getCollectedAmount()).sum();
204
        BrandFeeCollection brandFeeCollection = loiForm.getBrandFeeCollection().get(0);
205
        model.addAttribute("brandFeeAmount", brandFeeAmount);
206
        model.addAttribute("brandFee", brandFee);
207
        model.addAttribute("givenFee", givenFee);
208
        model.addAttribute("brandFeeCollection", brandFeeCollection);
209
        model.addAttribute("address", address);
210
        model.addAttribute("pod", loiForm);
33630 tejus.loha 211
        model.addAttribute("filledBy", filledBy);
33507 tejus.loha 212
        return "auto-Loi";
213
 
214
    }
215
 
33617 tejus.loha 216
    @RequestMapping(value = "/saveLoiDoc", method = RequestMethod.POST)
33507 tejus.loha 217
    public String saveLoiDoc(@RequestParam int loiId, @RequestParam int loiDocId, Model model) throws Exception {
218
        LOGGER.info("loi_docId-" + loiDocId);
219
        LoiForm loiForm = loiFormRepository.selectById(loiId);
220
        LOGGER.info("loiForm - " + loiForm);
221
        int loiDoc = loiForm.getLoiDoc();
222
        if (loiDoc == 0) {
223
            loiForm.setLoiDoc(loiDocId);
224
            loiFormService.sendSignedLoiPdfToPartner(loiForm);
225
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
226
            return "response";
227
        } else {
228
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
229
            return "response";
230
        }
231
 
232
    }
233
 
234
    // send Filled form for update purpose
33617 tejus.loha 235
    @RequestMapping(value = "/updateOnboardingForm", method = RequestMethod.GET)
33507 tejus.loha 236
    public String UpdateLoiForm(HttpServletRequest request,
237
                                @RequestParam int loiId,
238
                                Model model) throws ProfitMandiBusinessException {
239
        LoiForm loiForm = loiFormRepository.selectById(loiId);
33579 tejus.loha 240
        List<AuthUser> salesAuthList = loiFormService.getReferalAuthList();
33507 tejus.loha 241
        List<BrandFee> brandFee = brandFeeRepository.selectFeeOnDate(LocalDateTime.now());
242
        Set<Pair<StoreType, BrandFee>> storeTypeFeePairs = new HashSet<>();
243
        for (BrandFee fee : brandFee) {
244
            for (StoreType storeType : StoreType.values()) {
245
                storeTypeFeePairs.add(Pair.of(storeType, fee));
246
            }
247
        }
248
        model.addAttribute("storeTypeFeePairs", storeTypeFeePairs);
249
        model.addAttribute("authUsersList", salesAuthList);
250
        model.addAttribute("onBoardingData", loiForm);
251
        return "partner-onboarding-form";
252
    }
253
 
33577 tejus.loha 254
    @RequestMapping(value = "/updateLoiFormData", method = RequestMethod.POST)
33507 tejus.loha 255
    public String UpdateLoiFormDetail(HttpServletRequest request,
256
                                      @RequestParam int loiId,
257
                                      @RequestBody LoiFormData partnerOnBoardingFormData,
258
                                      Model model) throws Exception {
259
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
260
        String email = loginDetails.getEmailId();
261
        loiFormService.updateLoiForm(partnerOnBoardingFormData, loiId);
262
        List<LoiFormModel> pendingFormList = loiFormService.pendingFormList(email);
263
        model.addAttribute("formList", pendingFormList);
264
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
265
        return "response";
266
    }
267
 
268
    // TODO , add paymnet if brand fee due
269
    @RequestMapping(value = "/brandfeeCollection", method = RequestMethod.POST)
270
    public String addBrandFee(HttpServletRequest request, @RequestBody BrandFeeCollection brandFeeCollection, @RequestParam int loiId, Model model) throws Exception {
271
        LoiForm loiForm = loiFormRepository.selectById(loiId);
272
        List<BrandFeeCollection> brandFeeCollections = loiForm.getBrandFeeCollection();
33525 tejus.loha 273
        double totatcollectedfee = brandFeeCollections.stream().filter(x -> x.getPaymentStatus().equals(FeePaymentStatus.CONFIRM) || x.getPaymentStatus().equals(FeePaymentStatus.PENDING)).mapToDouble(x -> x.getCollectedAmount()).sum();
33507 tejus.loha 274
        double brandFee = loiForm.getAgreedBrandFees();
275
        double differanceAmount = brandFee - totatcollectedfee;
276
        if (totatcollectedfee + brandFeeCollection.getCollectedAmount() <= brandFee) {
277
            brandFeeCollection.setTimeStamp(LocalDateTime.now());
278
            brandFeeCollection.setPaymentStatus(FeePaymentStatus.PENDING);
279
            brandFeeCollection.setLoiData(loiForm);
280
            brandFeeCollections.add(brandFeeCollection);
281
            loiForm.setBrandFeeCollection(brandFeeCollections);
282
            loiFormService.sentMailToPaymentApprover(brandFeeCollection);
283
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
284
            return "response";
285
        } else {
286
            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");
287
        }
288
    }
289
 
290
 
33617 tejus.loha 291
    @RequestMapping(value = "/paymentsDetail", method = RequestMethod.GET)
33507 tejus.loha 292
    public String paymentsDetails(HttpServletRequest request, @RequestParam int loiId, Model model) throws ProfitMandiBusinessException {
293
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
294
        String email = loginDetails.getEmailId();
295
        boolean isNiraj = false;
296
        if (email.equals("neeraj.gupta@smartdukaan.com")) {
297
            isNiraj = true;
298
        }
299
        LoiForm loiForm = loiFormRepository.selectById(loiId);
300
        List<BrandFeeCollection> brandFeeCollections = loiForm.getBrandFeeCollection();
301
        model.addAttribute("brandFeeCollections", brandFeeCollections);
302
        model.addAttribute("confirm", FeePaymentStatus.CONFIRM);
303
        model.addAttribute("isNiraj", isNiraj);
304
        return "payment-collection-details";
305
    }
306
 
307
    // bfcId - Brand Fee Collection Id
33617 tejus.loha 308
    @RequestMapping(value = "/feePaymentApproval", method = RequestMethod.PUT)
33525 tejus.loha 309
    public String feePaymentApproval(HttpServletRequest request, @RequestParam int bfcId, @RequestParam FeePaymentStatus feePaymentStatus, @RequestParam String description,
310
                                     Model model) throws Exception {
33507 tejus.loha 311
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
312
        String authEmail = loginDetails.getEmailId();
313
        BrandFeeCollection brandFeeCollection = brandFeeCollectionRepository.selectById(bfcId);
314
        LoiForm loiForm = brandFeeCollection.getLoiData();
33525 tejus.loha 315
        List<BrandFeeCollection> brandFeeCollections = brandFeeCollectionRepository.selectAllConfirmPaymetByLoiForm(loiForm);
33507 tejus.loha 316
        brandFeeCollection.setApproverEmail(authEmail);
317
        brandFeeCollection.setPaymentStatus(feePaymentStatus);
33525 tejus.loha 318
        brandFeeCollection.setDescription(description);
33507 tejus.loha 319
        double agreedBrandFee = loiForm.getAgreedBrandFees();
320
        double totalBrandFeeCollection = brandFeeCollections.stream().mapToDouble(x -> x.getCollectedAmount()).sum() + brandFeeCollection.getCollectedAmount();
321
        LOGGER.info("agreedBrandeFee -" + agreedBrandFee);
322
        LOGGER.info("totalBrandFeeCollection -" + totalBrandFeeCollection);
323
        boolean b = agreedBrandFee == totalBrandFeeCollection && loiForm.getLoiSignOtp() != null;
33525 tejus.loha 324
        if (brandFeeCollection.getPaymentStatus().equals(FeePaymentStatus.REJECT)) {
33617 tejus.loha 325
            loiFormService.sendPaymentStatusMailToLoiFormFilledBy(brandFeeCollection);
33525 tejus.loha 326
            model.addAttribute("response1", mvcResponseSender.createResponseString(false));
327
        } else {
33617 tejus.loha 328
            loiFormService.sendPaymentStatusMailToLoiFormFilledBy(brandFeeCollection);
33525 tejus.loha 329
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
330
        }
33507 tejus.loha 331
        if (agreedBrandFee == totalBrandFeeCollection && loiForm.getLoiSignOtp() != null) {
332
            loiForm.setStatus(LoiStatus.PRE_ONBOARDING_DONE);
333
        }
334
        return "response";
335
 
336
    }
337
 
33617 tejus.loha 338
    @RequestMapping(value = "/uploadDocumentForm", method = RequestMethod.GET)
33507 tejus.loha 339
    public String uploadDocumentForm(HttpServletRequest request, @RequestParam int loiId, Model model) throws ProfitMandiBusinessException {
340
        List<LoiDocMaster> activeDocMasterList = loiDocMasterList.getAllActiveDoc();
341
        LoiForm loiForm = loiFormRepository.selectById(loiId);
342
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
343
        String authEmail = authRepository.selectByEmailOrMobile(loginDetails.getEmailId()).getEmailId();
344
        String approverEmail = "gaurav.sharma@smartdukaan.com";
345
        boolean isApprover = false;
346
        if (authEmail.equals(approverEmail)) {
347
            isApprover = true;
348
        }
349
        Map<Integer, LoiDoc> masterDocIdLoiDocMap = loiForm.getLoiDocs().stream().collect(Collectors.toMap(x -> x.getMasterDocId(), x -> x));
350
        model.addAttribute("isApprover", isApprover);
351
        model.addAttribute("loiId", loiId);
352
        model.addAttribute("activeDocMasterList", activeDocMasterList);
353
        model.addAttribute("masterDocIdLoiDocMap", masterDocIdLoiDocMap);
354
        return "loiForm/document-upload";
355
    }
356
 
357
    @RequestMapping(value = "/uploadOnboardingDocument", method = RequestMethod.POST)
358
    public String uploadDocument(HttpServletRequest request, @RequestParam int loiId, @RequestBody List<LoiDocModel> loiDocModels, Model model) throws Exception {
359
        LoiForm loiForm = loiFormRepository.selectById(loiId);
360
        LOGGER.info("loiForm - " + loiForm);
361
        LOGGER.info("loiDocModels - " + loiDocModels);
362
        loiFormService.setDocs(loiForm, loiDocModels);
363
        model.addAttribute("response1", mvcResponseSender.createResponseString("Document uploaded successfully"));
364
        return "response";
365
 
366
    }
367
 
368
 
33617 tejus.loha 369
    @RequestMapping(value = "/documentVerify", method = RequestMethod.PUT)
33507 tejus.loha 370
    public String docApproval(HttpServletRequest request, @RequestParam int loiId, @RequestParam int docMasterId, @RequestParam boolean flag, Model model) throws Exception {
371
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
372
        AuthUser auth = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
373
        LoiDoc loiDoc = loiDocRepository.selectByLoiIdAndMasterDocId(loiId, docMasterId);
374
        if (flag) {
375
            loiDoc.setOk(true);
376
            loiDoc.setVerifyBy(auth.getId());
377
            model.addAttribute("response1", mvcResponseSender.createResponseString(loiDoc.getDocType() + " is Accepted "));
378
            return "response";
379
        } else {
380
            loiDoc.setOk(false);
381
            loiDoc.setVerifyBy(auth.getId());
33617 tejus.loha 382
            loiFormService.sendDocApprovalMail(loiDoc);
33507 tejus.loha 383
            model.addAttribute("response1", mvcResponseSender.createResponseString(loiDoc.getDocType() + " is Rejected"));
384
            return "response";
385
        }
386
    }
387
 
388
    @RequestMapping(value = "/loiAcceptanceOtp", method = RequestMethod.POST)
389
    public String sentLoiAcceptanceOtp(@RequestParam int loiId, Model model) throws Exception {
390
        LoiForm pod = loiFormRepository.selectById(loiId);
391
        String mobile = String.valueOf(pod.getMobile());
33525 tejus.loha 392
        OTPResponse otpResponse = otpProcessor.generateOtp(mobile, OtpType.LOI_ACCEPTANCE);
33507 tejus.loha 393
        String message = "OTP send to your register mobile number -";
33568 tejus.loha 394
        LOGGER.info("OTPResponse Message - " + otpResponse.getMessage());
395
        if (otpResponse.isResult()) {
33525 tejus.loha 396
            model.addAttribute("response1", mvcResponseSender.createResponseString(message + mobile));
33568 tejus.loha 397
            return "response";
33525 tejus.loha 398
        } else {
399
            model.addAttribute("response1", mvcResponseSender.createResponseString("Something went wrong.."));
33568 tejus.loha 400
            return "response";
33525 tejus.loha 401
        }
33507 tejus.loha 402
    }
403
 
404
    @RequestMapping(value = "/validateLoiOtp", method = RequestMethod.PUT)
405
    public String validateLoiAcceptanceOtp(@RequestParam int loiId, @RequestParam String provideOtp, Model model) throws Exception {
406
        LOGGER.info("loiId -" + loiId);
407
        LOGGER.info("provideOtp -" + provideOtp);
408
        LoiForm pod = loiFormRepository.selectById(loiId);
409
        double brandFee = pod.getAgreedBrandFees();
410
        double totalCollectfee = pod.getBrandFeeCollection().stream().filter(x -> x.getPaymentStatus().equals(FeePaymentStatus.CONFIRM)).mapToDouble(x -> x.getCollectedAmount()).sum();
411
        String mobile = String.valueOf(pod.getMobile());
412
        Otp otp = otpRepository.selectAllByMobileWithTime(mobile).get(0);
413
        LOGGER.info("otp-" + otp);
414
        OTPResponse otpResponse = otpProcessor.validateOtp(otp.getId(), mobile, provideOtp);
415
        if (!otpResponse.isResult()) {
33577 tejus.loha 416
            throw new ProfitMandiBusinessException("Wrong OTP", provideOtp, "Your given Otp ->" + provideOtp + " is wrong , please check OTP and try again");
33507 tejus.loha 417
        }
418
        if (otpResponse.isResult()) {
419
            pod.setLoiSignOtp(provideOtp);
420
            pod.setLoiSignedOn(LocalDateTime.now());
421
            if (brandFee == totalCollectfee && pod.getLoiSignOtp() != null) {
422
                pod.setStatus(LoiStatus.PRE_ONBOARDING_DONE);
423
            } else {
424
                pod.setStatus(LoiStatus.LOI_SIGNED);
425
            }
426
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
427
        }
428
        return "response";
429
    }
430
 
33617 tejus.loha 431
    @RequestMapping(value = "/completedLoiForms", method = RequestMethod.GET)
33624 tejus.loha 432
    public String completeLoiFormList(Model model) throws ProfitMandiBusinessException {
33507 tejus.loha 433
        List<LoiForm> loiForms = loiFormRepository.selectAllCompleteForm();
33624 tejus.loha 434
        List<LoiFormModel> loiFormModels = new ArrayList<>();
435
        for (LoiForm loiForm : loiForms) {
436
            LoiFormModel loiFormModel = new LoiFormModel();
437
            loiFormModel.setId(loiForm.getId());
438
            loiFormModel.setLoiFormFilledBy(authRepository.selectByEmailOrMobile(loiForm.getFilledBy()).getFullName());
439
            loiFormModel.setCompanyName(loiForm.getCompanyName());
440
            loiFormModel.setOwnerName(loiForm.getFullName());
441
            loiFormModel.setMobile(loiForm.getMobile());
442
            loiFormModel.setCity(loiForm.getBillingAddress().getLoc());
443
            loiFormModels.add(loiFormModel);
444
        }
33507 tejus.loha 445
        List<EscalationType> EscalationTypeList = new ArrayList<>();
446
        EscalationTypeList.add(EscalationType.L2);
447
        EscalationTypeList.add(EscalationType.L1);
448
        EscalationTypeList.add(EscalationType.L4);
449
        List<AuthUser> authUsers = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_RBM,
450
                EscalationTypeList);
33624 tejus.loha 451
        model.addAttribute("loiFormModels", loiFormModels);
33507 tejus.loha 452
        model.addAttribute("authUsers", authUsers);
453
        return "loiForm/completed-loi-form";
454
    }
455
 
33617 tejus.loha 456
    @RequestMapping(value = "/createNewOnboardingPanel", method = RequestMethod.POST)
33507 tejus.loha 457
    public String CreateNewOnboardingPanel(@RequestParam int loiId, @RequestParam int authId, Model model) throws Exception {
458
        PartnerOnBoardingPanel partnerOnboardingPanel = loiFormService.createPartnerOnboardingPanel(loiId, authId);
459
        loiFormRepository.selectById(loiId).setStatus(LoiStatus.IN_ONBOARDING_PROCESS);
460
        if (partnerOnboardingPanel.getId() != 0)
461
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
462
        else
463
            model.addAttribute("response1", mvcResponseSender.createResponseString(false));
464
        return "response";
465
    }
33617 tejus.loha 466
 
467
    @RequestMapping(value = "/downloadLoiFromReport", method = RequestMethod.GET)
468
    public ResponseEntity<?> downloadAllLoiForm(@RequestParam LocalDate from, @RequestParam LocalDate to) throws Exception {
469
        ResponseEntity<?> responseEntity = loiFormService.createLoiFormReport(from, to);
470
 
471
        return responseEntity;
472
    }
473
 
474
 
33507 tejus.loha 475
}