Subversion Repositories SmartDukaan

Rev

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