Subversion Repositories SmartDukaan

Rev

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