Subversion Repositories SmartDukaan

Rev

Rev 33617 | Rev 33630 | 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);
196
        loiForm.setLoiGeneratedBy(authId);
197
        loiForm.setLoiGeneratedOn(LocalDateTime.now());
198
        loiForm.setStatus(LoiStatus.LOI_GENERATED);
199
        BrandFee brandFee = brandFeeRepository.selectById(1);
200
        BrandFee givenFee = brandFeeRepository.selectById(loiForm.getBrandFeeId());
201
        BillingAddress address = loiForm.getBillingAddress();
202
        double brandFeeAmount = loiForm.getBrandFeeCollection().stream().filter(x -> x.getPaymentStatus().equals(FeePaymentStatus.CONFIRM)).mapToDouble(x -> x.getCollectedAmount()).sum();
203
        BrandFeeCollection brandFeeCollection = loiForm.getBrandFeeCollection().get(0);
204
        model.addAttribute("brandFeeAmount", brandFeeAmount);
205
        model.addAttribute("brandFee", brandFee);
206
        model.addAttribute("givenFee", givenFee);
207
        model.addAttribute("brandFeeCollection", brandFeeCollection);
208
        model.addAttribute("address", address);
209
        model.addAttribute("pod", loiForm);
210
        return "auto-Loi";
211
 
212
    }
213
 
33617 tejus.loha 214
    @RequestMapping(value = "/saveLoiDoc", method = RequestMethod.POST)
33507 tejus.loha 215
    public String saveLoiDoc(@RequestParam int loiId, @RequestParam int loiDocId, Model model) throws Exception {
216
        LOGGER.info("loi_docId-" + loiDocId);
217
        LoiForm loiForm = loiFormRepository.selectById(loiId);
218
        LOGGER.info("loiForm - " + loiForm);
219
        int loiDoc = loiForm.getLoiDoc();
220
        if (loiDoc == 0) {
221
            loiForm.setLoiDoc(loiDocId);
222
            loiFormService.sendSignedLoiPdfToPartner(loiForm);
223
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
224
            return "response";
225
        } else {
226
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
227
            return "response";
228
        }
229
 
230
    }
231
 
232
    // send Filled form for update purpose
33617 tejus.loha 233
    @RequestMapping(value = "/updateOnboardingForm", method = RequestMethod.GET)
33507 tejus.loha 234
    public String UpdateLoiForm(HttpServletRequest request,
235
                                @RequestParam int loiId,
236
                                Model model) throws ProfitMandiBusinessException {
237
        LoiForm loiForm = loiFormRepository.selectById(loiId);
33579 tejus.loha 238
        List<AuthUser> salesAuthList = loiFormService.getReferalAuthList();
33507 tejus.loha 239
        List<BrandFee> brandFee = brandFeeRepository.selectFeeOnDate(LocalDateTime.now());
240
        Set<Pair<StoreType, BrandFee>> storeTypeFeePairs = new HashSet<>();
241
        for (BrandFee fee : brandFee) {
242
            for (StoreType storeType : StoreType.values()) {
243
                storeTypeFeePairs.add(Pair.of(storeType, fee));
244
            }
245
        }
246
        model.addAttribute("storeTypeFeePairs", storeTypeFeePairs);
247
        model.addAttribute("authUsersList", salesAuthList);
248
        model.addAttribute("onBoardingData", loiForm);
249
        return "partner-onboarding-form";
250
    }
251
 
33577 tejus.loha 252
    @RequestMapping(value = "/updateLoiFormData", method = RequestMethod.POST)
33507 tejus.loha 253
    public String UpdateLoiFormDetail(HttpServletRequest request,
254
                                      @RequestParam int loiId,
255
                                      @RequestBody LoiFormData partnerOnBoardingFormData,
256
                                      Model model) throws Exception {
257
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
258
        String email = loginDetails.getEmailId();
259
        loiFormService.updateLoiForm(partnerOnBoardingFormData, loiId);
260
        List<LoiFormModel> pendingFormList = loiFormService.pendingFormList(email);
261
        model.addAttribute("formList", pendingFormList);
262
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
263
        return "response";
264
    }
265
 
266
    // TODO , add paymnet if brand fee due
267
    @RequestMapping(value = "/brandfeeCollection", method = RequestMethod.POST)
268
    public String addBrandFee(HttpServletRequest request, @RequestBody BrandFeeCollection brandFeeCollection, @RequestParam int loiId, Model model) throws Exception {
269
        LoiForm loiForm = loiFormRepository.selectById(loiId);
270
        List<BrandFeeCollection> brandFeeCollections = loiForm.getBrandFeeCollection();
33525 tejus.loha 271
        double totatcollectedfee = brandFeeCollections.stream().filter(x -> x.getPaymentStatus().equals(FeePaymentStatus.CONFIRM) || x.getPaymentStatus().equals(FeePaymentStatus.PENDING)).mapToDouble(x -> x.getCollectedAmount()).sum();
33507 tejus.loha 272
        double brandFee = loiForm.getAgreedBrandFees();
273
        double differanceAmount = brandFee - totatcollectedfee;
274
        if (totatcollectedfee + brandFeeCollection.getCollectedAmount() <= brandFee) {
275
            brandFeeCollection.setTimeStamp(LocalDateTime.now());
276
            brandFeeCollection.setPaymentStatus(FeePaymentStatus.PENDING);
277
            brandFeeCollection.setLoiData(loiForm);
278
            brandFeeCollections.add(brandFeeCollection);
279
            loiForm.setBrandFeeCollection(brandFeeCollections);
280
            loiFormService.sentMailToPaymentApprover(brandFeeCollection);
281
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
282
            return "response";
283
        } else {
284
            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");
285
        }
286
    }
287
 
288
 
33617 tejus.loha 289
    @RequestMapping(value = "/paymentsDetail", method = RequestMethod.GET)
33507 tejus.loha 290
    public String paymentsDetails(HttpServletRequest request, @RequestParam int loiId, Model model) throws ProfitMandiBusinessException {
291
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
292
        String email = loginDetails.getEmailId();
293
        boolean isNiraj = false;
294
        if (email.equals("neeraj.gupta@smartdukaan.com")) {
295
            isNiraj = true;
296
        }
297
        LoiForm loiForm = loiFormRepository.selectById(loiId);
298
        List<BrandFeeCollection> brandFeeCollections = loiForm.getBrandFeeCollection();
299
        model.addAttribute("brandFeeCollections", brandFeeCollections);
300
        model.addAttribute("confirm", FeePaymentStatus.CONFIRM);
301
        model.addAttribute("isNiraj", isNiraj);
302
        return "payment-collection-details";
303
    }
304
 
305
    // bfcId - Brand Fee Collection Id
33617 tejus.loha 306
    @RequestMapping(value = "/feePaymentApproval", method = RequestMethod.PUT)
33525 tejus.loha 307
    public String feePaymentApproval(HttpServletRequest request, @RequestParam int bfcId, @RequestParam FeePaymentStatus feePaymentStatus, @RequestParam String description,
308
                                     Model model) throws Exception {
33507 tejus.loha 309
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
310
        String authEmail = loginDetails.getEmailId();
311
        BrandFeeCollection brandFeeCollection = brandFeeCollectionRepository.selectById(bfcId);
312
        LoiForm loiForm = brandFeeCollection.getLoiData();
33525 tejus.loha 313
        List<BrandFeeCollection> brandFeeCollections = brandFeeCollectionRepository.selectAllConfirmPaymetByLoiForm(loiForm);
33507 tejus.loha 314
        brandFeeCollection.setApproverEmail(authEmail);
315
        brandFeeCollection.setPaymentStatus(feePaymentStatus);
33525 tejus.loha 316
        brandFeeCollection.setDescription(description);
33507 tejus.loha 317
        double agreedBrandFee = loiForm.getAgreedBrandFees();
318
        double totalBrandFeeCollection = brandFeeCollections.stream().mapToDouble(x -> x.getCollectedAmount()).sum() + brandFeeCollection.getCollectedAmount();
319
        LOGGER.info("agreedBrandeFee -" + agreedBrandFee);
320
        LOGGER.info("totalBrandFeeCollection -" + totalBrandFeeCollection);
321
        boolean b = agreedBrandFee == totalBrandFeeCollection && loiForm.getLoiSignOtp() != null;
33525 tejus.loha 322
        if (brandFeeCollection.getPaymentStatus().equals(FeePaymentStatus.REJECT)) {
33617 tejus.loha 323
            loiFormService.sendPaymentStatusMailToLoiFormFilledBy(brandFeeCollection);
33525 tejus.loha 324
            model.addAttribute("response1", mvcResponseSender.createResponseString(false));
325
        } else {
33617 tejus.loha 326
            loiFormService.sendPaymentStatusMailToLoiFormFilledBy(brandFeeCollection);
33525 tejus.loha 327
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
328
        }
33507 tejus.loha 329
        if (agreedBrandFee == totalBrandFeeCollection && loiForm.getLoiSignOtp() != null) {
330
            loiForm.setStatus(LoiStatus.PRE_ONBOARDING_DONE);
331
        }
332
        return "response";
333
 
334
    }
335
 
33617 tejus.loha 336
    @RequestMapping(value = "/uploadDocumentForm", method = RequestMethod.GET)
33507 tejus.loha 337
    public String uploadDocumentForm(HttpServletRequest request, @RequestParam int loiId, Model model) throws ProfitMandiBusinessException {
338
        List<LoiDocMaster> activeDocMasterList = loiDocMasterList.getAllActiveDoc();
339
        LoiForm loiForm = loiFormRepository.selectById(loiId);
340
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
341
        String authEmail = authRepository.selectByEmailOrMobile(loginDetails.getEmailId()).getEmailId();
342
        String approverEmail = "gaurav.sharma@smartdukaan.com";
343
        boolean isApprover = false;
344
        if (authEmail.equals(approverEmail)) {
345
            isApprover = true;
346
        }
347
        Map<Integer, LoiDoc> masterDocIdLoiDocMap = loiForm.getLoiDocs().stream().collect(Collectors.toMap(x -> x.getMasterDocId(), x -> x));
348
        model.addAttribute("isApprover", isApprover);
349
        model.addAttribute("loiId", loiId);
350
        model.addAttribute("activeDocMasterList", activeDocMasterList);
351
        model.addAttribute("masterDocIdLoiDocMap", masterDocIdLoiDocMap);
352
        return "loiForm/document-upload";
353
    }
354
 
355
    @RequestMapping(value = "/uploadOnboardingDocument", method = RequestMethod.POST)
356
    public String uploadDocument(HttpServletRequest request, @RequestParam int loiId, @RequestBody List<LoiDocModel> loiDocModels, Model model) throws Exception {
357
        LoiForm loiForm = loiFormRepository.selectById(loiId);
358
        LOGGER.info("loiForm - " + loiForm);
359
        LOGGER.info("loiDocModels - " + loiDocModels);
360
        loiFormService.setDocs(loiForm, loiDocModels);
361
        model.addAttribute("response1", mvcResponseSender.createResponseString("Document uploaded successfully"));
362
        return "response";
363
 
364
    }
365
 
366
 
33617 tejus.loha 367
    @RequestMapping(value = "/documentVerify", method = RequestMethod.PUT)
33507 tejus.loha 368
    public String docApproval(HttpServletRequest request, @RequestParam int loiId, @RequestParam int docMasterId, @RequestParam boolean flag, Model model) throws Exception {
369
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
370
        AuthUser auth = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
371
        LoiDoc loiDoc = loiDocRepository.selectByLoiIdAndMasterDocId(loiId, docMasterId);
372
        if (flag) {
373
            loiDoc.setOk(true);
374
            loiDoc.setVerifyBy(auth.getId());
375
            model.addAttribute("response1", mvcResponseSender.createResponseString(loiDoc.getDocType() + " is Accepted "));
376
            return "response";
377
        } else {
378
            loiDoc.setOk(false);
379
            loiDoc.setVerifyBy(auth.getId());
33617 tejus.loha 380
            loiFormService.sendDocApprovalMail(loiDoc);
33507 tejus.loha 381
            model.addAttribute("response1", mvcResponseSender.createResponseString(loiDoc.getDocType() + " is Rejected"));
382
            return "response";
383
        }
384
    }
385
 
386
    @RequestMapping(value = "/loiAcceptanceOtp", method = RequestMethod.POST)
387
    public String sentLoiAcceptanceOtp(@RequestParam int loiId, Model model) throws Exception {
388
        LoiForm pod = loiFormRepository.selectById(loiId);
389
        String mobile = String.valueOf(pod.getMobile());
33525 tejus.loha 390
        OTPResponse otpResponse = otpProcessor.generateOtp(mobile, OtpType.LOI_ACCEPTANCE);
33507 tejus.loha 391
        String message = "OTP send to your register mobile number -";
33568 tejus.loha 392
        LOGGER.info("OTPResponse Message - " + otpResponse.getMessage());
393
        if (otpResponse.isResult()) {
33525 tejus.loha 394
            model.addAttribute("response1", mvcResponseSender.createResponseString(message + mobile));
33568 tejus.loha 395
            return "response";
33525 tejus.loha 396
        } else {
397
            model.addAttribute("response1", mvcResponseSender.createResponseString("Something went wrong.."));
33568 tejus.loha 398
            return "response";
33525 tejus.loha 399
        }
33507 tejus.loha 400
    }
401
 
402
    @RequestMapping(value = "/validateLoiOtp", method = RequestMethod.PUT)
403
    public String validateLoiAcceptanceOtp(@RequestParam int loiId, @RequestParam String provideOtp, Model model) throws Exception {
404
        LOGGER.info("loiId -" + loiId);
405
        LOGGER.info("provideOtp -" + provideOtp);
406
        LoiForm pod = loiFormRepository.selectById(loiId);
407
        double brandFee = pod.getAgreedBrandFees();
408
        double totalCollectfee = pod.getBrandFeeCollection().stream().filter(x -> x.getPaymentStatus().equals(FeePaymentStatus.CONFIRM)).mapToDouble(x -> x.getCollectedAmount()).sum();
409
        String mobile = String.valueOf(pod.getMobile());
410
        Otp otp = otpRepository.selectAllByMobileWithTime(mobile).get(0);
411
        LOGGER.info("otp-" + otp);
412
        OTPResponse otpResponse = otpProcessor.validateOtp(otp.getId(), mobile, provideOtp);
413
        if (!otpResponse.isResult()) {
33577 tejus.loha 414
            throw new ProfitMandiBusinessException("Wrong OTP", provideOtp, "Your given Otp ->" + provideOtp + " is wrong , please check OTP and try again");
33507 tejus.loha 415
        }
416
        if (otpResponse.isResult()) {
417
            pod.setLoiSignOtp(provideOtp);
418
            pod.setLoiSignedOn(LocalDateTime.now());
419
            if (brandFee == totalCollectfee && pod.getLoiSignOtp() != null) {
420
                pod.setStatus(LoiStatus.PRE_ONBOARDING_DONE);
421
            } else {
422
                pod.setStatus(LoiStatus.LOI_SIGNED);
423
            }
424
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
425
        }
426
        return "response";
427
    }
428
 
33617 tejus.loha 429
    @RequestMapping(value = "/completedLoiForms", method = RequestMethod.GET)
33624 tejus.loha 430
    public String completeLoiFormList(Model model) throws ProfitMandiBusinessException {
33507 tejus.loha 431
        List<LoiForm> loiForms = loiFormRepository.selectAllCompleteForm();
33624 tejus.loha 432
        List<LoiFormModel> loiFormModels = new ArrayList<>();
433
        for (LoiForm loiForm : loiForms) {
434
            LoiFormModel loiFormModel = new LoiFormModel();
435
            loiFormModel.setId(loiForm.getId());
436
            loiFormModel.setLoiFormFilledBy(authRepository.selectByEmailOrMobile(loiForm.getFilledBy()).getFullName());
437
            loiFormModel.setCompanyName(loiForm.getCompanyName());
438
            loiFormModel.setOwnerName(loiForm.getFullName());
439
            loiFormModel.setMobile(loiForm.getMobile());
440
            loiFormModel.setCity(loiForm.getBillingAddress().getLoc());
441
            loiFormModels.add(loiFormModel);
442
        }
33507 tejus.loha 443
        List<EscalationType> EscalationTypeList = new ArrayList<>();
444
        EscalationTypeList.add(EscalationType.L2);
445
        EscalationTypeList.add(EscalationType.L1);
446
        EscalationTypeList.add(EscalationType.L4);
447
        List<AuthUser> authUsers = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_RBM,
448
                EscalationTypeList);
33624 tejus.loha 449
        model.addAttribute("loiFormModels", loiFormModels);
33507 tejus.loha 450
        model.addAttribute("authUsers", authUsers);
451
        return "loiForm/completed-loi-form";
452
    }
453
 
33617 tejus.loha 454
    @RequestMapping(value = "/createNewOnboardingPanel", method = RequestMethod.POST)
33507 tejus.loha 455
    public String CreateNewOnboardingPanel(@RequestParam int loiId, @RequestParam int authId, Model model) throws Exception {
456
        PartnerOnBoardingPanel partnerOnboardingPanel = loiFormService.createPartnerOnboardingPanel(loiId, authId);
457
        loiFormRepository.selectById(loiId).setStatus(LoiStatus.IN_ONBOARDING_PROCESS);
458
        if (partnerOnboardingPanel.getId() != 0)
459
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
460
        else
461
            model.addAttribute("response1", mvcResponseSender.createResponseString(false));
462
        return "response";
463
    }
33617 tejus.loha 464
 
465
    @RequestMapping(value = "/downloadLoiFromReport", method = RequestMethod.GET)
466
    public ResponseEntity<?> downloadAllLoiForm(@RequestParam LocalDate from, @RequestParam LocalDate to) throws Exception {
467
        ResponseEntity<?> responseEntity = loiFormService.createLoiFormReport(from, to);
468
 
469
        return responseEntity;
470
    }
471
 
472
 
33507 tejus.loha 473
}