Subversion Repositories SmartDukaan

Rev

Rev 37663 | 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;
35038 aman 4
import com.google.common.hash.Hashing;
33507 tejus.loha 5
import com.spice.profitmandi.common.enumuration.BusinessType;
6
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
34107 tejus.loha 7
import com.spice.profitmandi.common.model.ProfitMandiConstants;
35038 aman 8
import com.spice.profitmandi.common.web.util.ResponseSender;
33507 tejus.loha 9
import com.spice.profitmandi.dao.entity.auth.AuthUser;
10
import com.spice.profitmandi.dao.entity.brandFee.BrandFee;
11
import com.spice.profitmandi.dao.entity.brandFee.BrandFeeCollection;
12
import com.spice.profitmandi.dao.entity.dtr.Otp;
37523 ranu 13
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
37671 ranu 14
import com.spice.profitmandi.dao.entity.fofo.PartnerOnBoardingPanel;
15
import com.spice.profitmandi.dao.entity.fofo.PartnerOnboardingTrainingPanel;
35971 aman 16
import com.spice.profitmandi.dao.entity.fofo.PaymentOption;
33507 tejus.loha 17
import com.spice.profitmandi.dao.entity.onBoarding.*;
34107 tejus.loha 18
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
33507 tejus.loha 19
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
35971 aman 20
import com.spice.profitmandi.dao.enumuration.dtr.StoreTimeline;
37523 ranu 21
import com.spice.profitmandi.dao.enumuration.onBorading.OnboardingType;
33507 tejus.loha 22
import com.spice.profitmandi.dao.enumuration.onBorading.onBoardingFormEnums.FeePaymentStatus;
23
import com.spice.profitmandi.dao.enumuration.onBorading.onBoardingFormEnums.LoiStatus;
24
import com.spice.profitmandi.dao.enumuration.onBorading.onBoardingFormEnums.StoreType;
37671 ranu 25
import com.spice.profitmandi.dao.enumuration.transaction.PartnerOnBoardingStatus;
33507 tejus.loha 26
import com.spice.profitmandi.dao.model.LoiFormModel;
27
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
28
import com.spice.profitmandi.dao.repository.brandFee.BrandFeeCollectionRepository;
29
import com.spice.profitmandi.dao.repository.brandFee.BrandFeeRepository;
33658 tejus.loha 30
import com.spice.profitmandi.dao.repository.catalog.BrandCategoryRepository;
31
import com.spice.profitmandi.dao.repository.catalog.BrandsRepository;
33507 tejus.loha 32
import com.spice.profitmandi.dao.repository.cs.CsService;
37523 ranu 33
import com.spice.profitmandi.dao.repository.dtr.*;
35971 aman 34
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
33507 tejus.loha 35
import com.spice.profitmandi.dao.repository.inventory.PartnerOnboardingService;
36
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
35038 aman 37
import com.spice.profitmandi.dao.repository.onboarding.*;
33507 tejus.loha 38
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
37660 ranu 39
import com.spice.profitmandi.dao.repository.user.AgreementEsignRepository;
33658 tejus.loha 40
import com.spice.profitmandi.dao.repository.user.BillingAddressRepository;
33507 tejus.loha 41
import com.spice.profitmandi.dao.repository.user.LoiFormRepository;
37660 ranu 42
import com.spice.profitmandi.dao.repository.user.StoreTimelinetbRepository;
33507 tejus.loha 43
import com.spice.profitmandi.dao.service.LoiDocModel;
44
import com.spice.profitmandi.dao.service.OTPResponse;
45
import com.spice.profitmandi.dao.service.OtpProcessor;
46
import com.spice.profitmandi.dao.service.loiForm.LoiFormService;
47
import com.spice.profitmandi.service.integrations.gstpro.GstProService;
48
import com.spice.profitmandi.service.integrations.gstpro.entity.GstDetails;
49
import com.spice.profitmandi.service.user.StoreTimelineTatService;
50
import com.spice.profitmandi.web.model.LoginDetails;
51
import com.spice.profitmandi.web.util.CookiesProcessor;
52
import com.spice.profitmandi.web.util.MVCResponseSender;
53
import org.apache.commons.lang3.tuple.Pair;
54
import org.apache.logging.log4j.LogManager;
55
import org.apache.logging.log4j.Logger;
56
import org.springframework.beans.factory.annotation.Autowired;
57
import org.springframework.http.ResponseEntity;
58
import org.springframework.mail.javamail.JavaMailSender;
59
import org.springframework.stereotype.Controller;
60
import org.springframework.transaction.annotation.Transactional;
61
import org.springframework.ui.Model;
62
import org.springframework.web.bind.annotation.RequestBody;
63
import org.springframework.web.bind.annotation.RequestMapping;
64
import org.springframework.web.bind.annotation.RequestMethod;
65
import org.springframework.web.bind.annotation.RequestParam;
66
 
67
import javax.servlet.http.HttpServletRequest;
35038 aman 68
import java.nio.charset.StandardCharsets;
33617 tejus.loha 69
import java.time.LocalDate;
33507 tejus.loha 70
import java.time.LocalDateTime;
71
import java.util.*;
72
import java.util.stream.Collectors;
73
 
74
@Controller
75
@Transactional(rollbackFor = Throwable.class)
76
public class LoiFormController {
34149 tejus.loha 77
    private static final Logger LOGGER = LogManager.getLogger(LoiFormController.class);
33507 tejus.loha 78
    @Autowired
79
    DocumentRepository documentRepository;
80
    @Autowired
81
    AuthRepository authRepository;
82
    @Autowired
83
    StateRepository stateRepository;
84
    @Autowired
85
    DistrictMasterRepository districtMasterRepository;
86
    @Autowired
87
    LoiFormRepository loiFormRepository;
88
    @Autowired
89
    GstProService gstProService;
90
    @Autowired
91
    ObjectMapper objectMapper;
92
    @Autowired
93
    OrderRepository orderRepository;
94
    @Autowired
95
    LoiFormService loiFormService;
96
    @Autowired
97
    BrandFeeCollectionRepository brandFeeCollectionRepository;
98
    @Autowired
99
    BrandFeeRepository brandFeeRepository;
100
    @Autowired
101
    OtpProcessor otpProcessor;
102
    @Autowired
103
    OtpRepository otpRepository;
104
    @Autowired
36401 amit 105
    JavaMailSender gmailRelaySender;
33507 tejus.loha 106
    @Autowired
107
    LoiDocMasterRepository loiDocMasterList;
108
    @Autowired
109
    CsService csService;
110
    @Autowired
111
    PartnerOnboardingService partnerOnboardingService;
112
    @Autowired
113
    StoreTimelineTatService storeTimelineTatService;
114
    @Autowired
115
    LoiDocRepository loiDocRepository;
116
    @Autowired
117
    MVCResponseSender mvcResponseSender;
118
    @Autowired
119
    private CookiesProcessor cookiesProcessor;
33658 tejus.loha 120
    @Autowired
33879 tejus.loha 121
    BrandCommitRepository brandCommitRepository;
33658 tejus.loha 122
    @Autowired
123
    BrandsRepository brandsRepository;
124
    @Autowired
125
    BrandCategoryRepository brandCategoryRepository;
126
    @Autowired
127
    BillingAddressRepository billingAddressRepository;
128
    @Autowired
129
    LoiBrandCommitmentRepository brandCommitmentRepository;
33747 tejus.loha 130
    @Autowired
131
    PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
35038 aman 132
    @Autowired
133
    LoiAuditTrailRepository loiAuditTrailRepository;
33747 tejus.loha 134
 
35038 aman 135
    @Autowired
35971 aman 136
    PaymentOptionRepository paymentOptionRepository;
137
 
138
    @Autowired
37523 ranu 139
    FofoStoreRepository fofoStoreRepository;
140
 
141
    @Autowired
37660 ranu 142
    StoreTimelinetbRepository storeTimelinetbRepository;
143
 
144
    @Autowired
145
    AgreementEsignRepository agreementEsignRepository;
146
 
147
    @Autowired
37671 ranu 148
    PartnerDashboardTrainingRepository partnerDashboardTrainingRepository;
149
 
150
    @Autowired
35038 aman 151
    ResponseSender responseSender;
152
 
37630 amit 153
    List<String> agreedBrandFeeChangerEmail = Arrays.asList("kamini.sharma@smartdukaan.com");
33507 tejus.loha 154
 
33845 tejus.loha 155
    // Loi Form
156
    @RequestMapping(value = "/loiForm", method = RequestMethod.GET)
33507 tejus.loha 157
    public String loiForm(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
33579 tejus.loha 158
        List<AuthUser> authUsersList = loiFormService.getReferalAuthList();
33507 tejus.loha 159
        List<BrandFee> brandFee = brandFeeRepository.selectFeeOnDate(LocalDateTime.now());
160
        Set<Pair<StoreType, BrandFee>> storeTypeFeePairs = new HashSet<>();
161
        for (BrandFee fee : brandFee) {
162
            for (StoreType storeType : StoreType.values()) {
163
                storeTypeFeePairs.add(Pair.of(storeType, fee));
164
            }
165
        }
37243 ranu 166
        // BM (labelled "State Head" on the LOI form) is now the L4/L5 sales head — was
167
        // L2/L3 previously, which no longer matches the org hierarchy.
168
        List<AuthUser> stateHeadList = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_SALES, Arrays.asList(EscalationType.L4, EscalationType.L5));
37262 ranu 169
        List<AuthUser> bdmList = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_SALES, Arrays.asList(EscalationType.L1, EscalationType.L2));
37243 ranu 170
        List<AuthUser> abmHeadList = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_ABM, Arrays.asList(EscalationType.L4, EscalationType.L5));
35038 aman 171
        List<AuthUser> abmList = csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_ABM, EscalationType.L1);
172
        bdmList.addAll(abmList);
173
        stateHeadList.addAll(abmHeadList);
33885 tejus.loha 174
        List<BrandCommit> brandCommits = brandCommitRepository.selectAllActiveBrand();
35971 aman 175
        List<PaymentOption> paperFinanceOptions = paymentOptionRepository.selectAllPaperFinanceOption();
34195 tejus.loha 176
        model.addAttribute("businessTypes", BusinessType.values());
33658 tejus.loha 177
        model.addAttribute("brandCommits", brandCommits);
33507 tejus.loha 178
        model.addAttribute("storeTypeFeePairs", storeTypeFeePairs);
179
        model.addAttribute("authUsersList", authUsersList);
34107 tejus.loha 180
        model.addAttribute("stateHeadList", stateHeadList);
181
        model.addAttribute("bdmList", bdmList);
35971 aman 182
        model.addAttribute("paperFinanceOptions", paperFinanceOptions);
33845 tejus.loha 183
        return "loi-form";
33507 tejus.loha 184
    }
185
 
186
    // use to validate GSTIN
187
    @RequestMapping(value = "/gstValidate", method = RequestMethod.GET)
188
    public ResponseEntity<?> gstValidate(HttpServletRequest request, @RequestParam String gstNo) throws Exception {
189
        LOGGER.info("gstNo -" + gstNo);
190
        GstDetails gstDetails = gstProService.getGstDetails(gstNo);
191
        LOGGER.info("gstDetails -" + gstDetails);
35038 aman 192
        if (gstDetails != null) {
34310 tejus.loha 193
            List<GstDetails.Pradr> adadr = gstDetails.getAdadr();
194
            adadr.add(gstDetails.getPradr());
195
            Collections.reverse(adadr);
196
            LOGGER.info("list_of_adadr-" + adadr);
197
        }
34026 tejus.loha 198
        return ResponseEntity.ok(gstDetails);
33507 tejus.loha 199
    }
200
 
34026 tejus.loha 201
    // Save Loi data in fofo.loi_form table
33577 tejus.loha 202
    @RequestMapping(value = "/submitLoiForm", method = RequestMethod.POST)
33568 tejus.loha 203
    public String submitLoiForm(HttpServletRequest request, @RequestBody LoiFormData loiFormData, Model model) throws Exception {
33507 tejus.loha 204
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
33577 tejus.loha 205
        LOGGER.info("filledBy - " + loginDetails.getEmailId());
37523 ranu 206
 
207
        String validationError = validateOnboardingTypeFields(loiFormData);
208
        if (validationError != null) {
209
            LOGGER.warn("LOI submit rejected for " + loginDetails.getEmailId() + ": " + validationError);
210
            model.addAttribute("response1", mvcResponseSender.createResponseString(false));
211
            return "response";
212
        }
213
 
33577 tejus.loha 214
        boolean isDataCreated = loiFormService.createLoiForm(loiFormData, loginDetails.getEmailId());
33507 tejus.loha 215
        if (isDataCreated) {
216
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
217
            return "response";
218
        } else {
219
            model.addAttribute("response1", mvcResponseSender.createResponseString(false));
220
            return "response";
221
        }
222
    }
223
 
37523 ranu 224
    // Returns null if valid, else an error message. NEW is default; only REVIVAL / ANY_OTHER need extras.
225
    private String validateOnboardingTypeFields(LoiFormData loiFormData) throws ProfitMandiBusinessException {
226
        String rawType = loiFormData.getOnboardingType();
227
        if (rawType == null || rawType.trim().isEmpty()) {
228
            loiFormData.setOnboardingType(OnboardingType.NEW.name());
229
            return null;
230
        }
231
        OnboardingType type;
232
        try {
233
            type = OnboardingType.valueOf(rawType.trim().toUpperCase());
234
        } catch (IllegalArgumentException e) {
235
            return "Invalid onboarding type: " + rawType;
236
        }
237
        if (type == OnboardingType.NEW) return null;
238
 
239
        String reason = loiFormData.getRevivalReason();
240
        if (reason == null || reason.trim().isEmpty()) {
241
            return "Reason is mandatory for " + type + " onboarding";
242
        }
243
 
244
        if (type == OnboardingType.REVIVAL) {
245
            String oldCode = loiFormData.getOldStoreCode();
246
            if (oldCode == null || oldCode.trim().isEmpty()) {
247
                return "Old Store Code is mandatory for REVIVAL";
248
            }
249
            FofoStore existing = fofoStoreRepository.selectByStoreCode(oldCode.trim());
250
            if (existing == null) {
251
                return "Old Store Code " + oldCode + " does not exist";
252
            }
253
            boolean stillActive = fofoStoreRepository.selectActiveStores().stream()
254
                    .anyMatch(s -> oldCode.trim().equalsIgnoreCase(s.getCode()));
255
            if (stillActive) {
256
                return "Old Store Code " + oldCode + " is still active — revival is only for closed stores";
257
            }
258
        }
259
        return null;
260
    }
261
 
34026 tejus.loha 262
    // show all pending loi form to specific auth user who have filled the form(type based)
33710 tejus.loha 263
    @RequestMapping(value = "/pendingLoiForm", method = RequestMethod.GET)
33507 tejus.loha 264
    public String pendingLoiForm(HttpServletRequest request, Model model) throws Exception {
265
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
266
        String email = loginDetails.getEmailId();
267
        boolean isDocApprover = false;
268
        String approverEmail = "gaurav.sharma@smartdukaan.com";
269
        if (email.equals(approverEmail)) {
270
            isDocApprover = true;
271
        }
33710 tejus.loha 272
        boolean isAgreedBrandFeeChanger = agreedBrandFeeChangerEmail.stream().anyMatch(x -> x.equals(email));
37516 ranu 273
        List<String> authEmails = Arrays.asList("raj.singh@smartdukaan.com", "kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com");
35169 aman 274
        boolean isAuthUser = authEmails.stream().anyMatch(x -> x.equals(email));
33507 tejus.loha 275
        List<LoiFormModel> pendingFormList = loiFormService.pendingFormList(email);
276
        model.addAttribute("isDocApprover", isDocApprover);
33617 tejus.loha 277
        model.addAttribute("isAuthUser", isAuthUser);
33710 tejus.loha 278
        model.addAttribute("isAgreedBrandFeeChanger", isAgreedBrandFeeChanger);
33507 tejus.loha 279
        model.addAttribute("pendingFormList", pendingFormList);
34085 tejus.loha 280
        model.addAttribute("brandType", StoreType.valueList);
33507 tejus.loha 281
        return "pendingForm";
282
    }
283
 
34085 tejus.loha 284
//    @RequestMapping(value = "/pendingLoiFormList", method = RequestMethod.GET)
285
//    public String pendingLoiForm1(HttpServletRequest request, @RequestParam int pageSize, @RequestParam int pageNumber, Model model) throws Exception {
286
//        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
287
//        String email = loginDetails.getEmailId();
288
//        Map<String, Object> pendingFormMap = loiFormService.pendingFormList(email);
289
//        model.addAttribute("pendingFormList", pendingFormMap.get("pendingFormModelList"));
290
//        model.addAttribute("paginationInfo", this.getPaginationInfo(pageNumber,pageSize,(long)pendingFormMap.get("totalCount")));
291
//        return "loiData";
292
//    }
293
//    public String getPaginationInfo(int currentPage, int pageSize, long totalEntries) {
294
//        // Calculate the starting index
295
//        int start = (currentPage - 1) * pageSize + 1; // Start from 1
296
//        // Calculate the ending index
297
//        int end = Math.min(start + pageSize - 1, (int) totalEntries); // Ensure it doesn't exceed totalEntries
298
//
299
//        return "Showing " + start + " to " + end + " of " + totalEntries + " entries";
300
//    }
301
 
33507 tejus.loha 302
    // generate LOI for specific Form data
303
    @RequestMapping(value = "/generateLoi", method = RequestMethod.GET)
33845 tejus.loha 304
    public String generateLoi(HttpServletRequest request, @RequestParam int loiId, Model model) throws ProfitMandiBusinessException {
33507 tejus.loha 305
        LoiForm loiForm = loiFormRepository.selectById(loiId);
33630 tejus.loha 306
        String filledBy = authRepository.selectByEmailOrMobile(loiForm.getFilledBy()).getFullName();
33507 tejus.loha 307
        loiForm.setLoiGeneratedOn(LocalDateTime.now());
35754 amit 308
        BrandFee brandFee = brandFeeRepository.selectById(1L);
33658 tejus.loha 309
        BillingAddress address = billingAddressRepository.selectByLoiFormId(loiId);
310
        List<LoiBrandCommitment> loiBrandCommitments = brandCommitmentRepository.selectByLoiId(loiId).stream().filter(x -> x.getAmount() > 0).collect(Collectors.toList());
311
        double totalCommitment = loiBrandCommitments.stream().mapToDouble(x -> x.getAmount()).sum();
33845 tejus.loha 312
        List<BrandFeeCollection> brandFeeCollections = brandFeeCollectionRepository.selectAllConfirmPaymetByLoiId(loiId);
313
        double brandFeeAmount = brandFeeCollections.stream().mapToDouble(x -> x.getCollectedAmount()).sum();
33658 tejus.loha 314
        BrandFeeCollection brandFeeCollection = brandFeeCollections.get(0);
315
        model.addAttribute("totalCommitment", totalCommitment);
316
        model.addAttribute("loiBrandCommitments", loiBrandCommitments);
33507 tejus.loha 317
        model.addAttribute("brandFeeAmount", brandFeeAmount);
318
        model.addAttribute("brandFee", brandFee);
319
        model.addAttribute("brandFeeCollection", brandFeeCollection);
320
        model.addAttribute("address", address);
33658 tejus.loha 321
        model.addAttribute("loiForm", loiForm);
33630 tejus.loha 322
        model.addAttribute("filledBy", filledBy);
33507 tejus.loha 323
        return "auto-Loi";
324
 
325
    }
326
 
35038 aman 327
    private String getHash256(String originalString) {
328
        String hashString = Hashing.sha256().hashString(originalString, StandardCharsets.UTF_8).toString();
329
        LOGGER.info("Hash String {}", hashString);
330
        return hashString;
331
    }
33507 tejus.loha 332
 
333
    // send Filled form for update purpose
33658 tejus.loha 334
    @RequestMapping(value = "/updateLoiForm", method = RequestMethod.GET)
33507 tejus.loha 335
    public String UpdateLoiForm(HttpServletRequest request,
336
                                @RequestParam int loiId,
337
                                Model model) throws ProfitMandiBusinessException {
338
        LoiForm loiForm = loiFormRepository.selectById(loiId);
33658 tejus.loha 339
        model.addAttribute("updateForm", true);
340
        model.addAttribute("loiForm", loiForm);
341
        return "loiForm/update-loiForm";
33507 tejus.loha 342
    }
343
 
33577 tejus.loha 344
    @RequestMapping(value = "/updateLoiFormData", method = RequestMethod.POST)
33507 tejus.loha 345
    public String UpdateLoiFormDetail(HttpServletRequest request,
346
                                      @RequestParam int loiId,
33658 tejus.loha 347
                                      @RequestBody LoiFormData loiFormData,
33507 tejus.loha 348
                                      Model model) throws Exception {
33658 tejus.loha 349
        loiFormService.updateLoiForm(loiFormData, loiId);
33507 tejus.loha 350
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
351
        return "response";
352
    }
353
 
354
    @RequestMapping(value = "/brandfeeCollection", method = RequestMethod.POST)
355
    public String addBrandFee(HttpServletRequest request, @RequestBody BrandFeeCollection brandFeeCollection, @RequestParam int loiId, Model model) throws Exception {
356
        LoiForm loiForm = loiFormRepository.selectById(loiId);
34086 tejus.loha 357
        double totatcollectedfee = brandFeeCollectionRepository.selectAllConfirmPaymetByLoiId(loiId).stream().mapToDouble(x -> x.getCollectedAmount()).sum();
33507 tejus.loha 358
        double brandFee = loiForm.getAgreedBrandFees();
359
        double differanceAmount = brandFee - totatcollectedfee;
360
        if (totatcollectedfee + brandFeeCollection.getCollectedAmount() <= brandFee) {
361
            brandFeeCollection.setPaymentStatus(FeePaymentStatus.PENDING);
33658 tejus.loha 362
            brandFeeCollection.setLoiFormId(loiId);
363
            brandFeeCollectionRepository.persist(brandFeeCollection);
35971 aman 364
            loiFormService.sentMailToPaymentApprover(brandFeeCollection, loiForm);
33507 tejus.loha 365
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
366
            return "response";
367
        } else {
368
            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");
369
        }
370
    }
371
 
372
 
33617 tejus.loha 373
    @RequestMapping(value = "/paymentsDetail", method = RequestMethod.GET)
33507 tejus.loha 374
    public String paymentsDetails(HttpServletRequest request, @RequestParam int loiId, Model model) throws ProfitMandiBusinessException {
375
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
376
        String email = loginDetails.getEmailId();
377
        boolean isNiraj = false;
378
        if (email.equals("neeraj.gupta@smartdukaan.com")) {
379
            isNiraj = true;
380
        }
33658 tejus.loha 381
        List<BrandFeeCollection> brandFeeCollections = brandFeeCollectionRepository.selectAllByLoiFormId(loiId);
33507 tejus.loha 382
        model.addAttribute("brandFeeCollections", brandFeeCollections);
383
        model.addAttribute("confirm", FeePaymentStatus.CONFIRM);
384
        model.addAttribute("isNiraj", isNiraj);
385
        return "payment-collection-details";
386
    }
387
 
388
    // bfcId - Brand Fee Collection Id
33617 tejus.loha 389
    @RequestMapping(value = "/feePaymentApproval", method = RequestMethod.PUT)
33525 tejus.loha 390
    public String feePaymentApproval(HttpServletRequest request, @RequestParam int bfcId, @RequestParam FeePaymentStatus feePaymentStatus, @RequestParam String description,
391
                                     Model model) throws Exception {
33507 tejus.loha 392
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
393
        String authEmail = loginDetails.getEmailId();
394
        BrandFeeCollection brandFeeCollection = brandFeeCollectionRepository.selectById(bfcId);
395
        brandFeeCollection.setApproverEmail(authEmail);
396
        brandFeeCollection.setPaymentStatus(feePaymentStatus);
33525 tejus.loha 397
        brandFeeCollection.setDescription(description);
34195 tejus.loha 398
        brandFeeCollection.setApprovalTimeStamp(LocalDateTime.now());
33848 tejus.loha 399
        if (feePaymentStatus.equals(FeePaymentStatus.CONFIRM)) {
35971 aman 400
            // Payment Approval timeline entry
401
            storeTimelineTatService.createStoreTimeline(brandFeeCollection.getLoiFormId(), StoreTimeline.PAYMENT_APPROVAL);
37660 ranu 402
            LoiForm approvedLoi = loiFormRepository.selectById(brandFeeCollection.getLoiFormId());
403
            applyRevivalPaymentHooks(approvedLoi);
404
            loiFormService.checkLoiDetailsCompletion(approvedLoi);
33848 tejus.loha 405
        }
33845 tejus.loha 406
        loiFormService.sendPaymentStatusMailToLoiFormFilledBy(brandFeeCollection);
407
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
33507 tejus.loha 408
        return "response";
409
 
410
    }
411
 
34739 aman.kumar 412
    @RequestMapping(value = "/feePaymentDeletion", method = RequestMethod.PUT)
413
    public String feePaymentDeletion(HttpServletRequest request, @RequestParam int bfcId,
414
                                     Model model) throws Exception {
415
        brandFeeCollectionRepository.deleteById(bfcId);
416
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
417
        return "response";
33658 tejus.loha 418
 
34739 aman.kumar 419
    }
420
 
421
 
33617 tejus.loha 422
    @RequestMapping(value = "/uploadDocumentForm", method = RequestMethod.GET)
33507 tejus.loha 423
    public String uploadDocumentForm(HttpServletRequest request, @RequestParam int loiId, Model model) throws ProfitMandiBusinessException {
424
        List<LoiDocMaster> activeDocMasterList = loiDocMasterList.getAllActiveDoc();
425
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
426
        String authEmail = authRepository.selectByEmailOrMobile(loginDetails.getEmailId()).getEmailId();
427
        String approverEmail = "gaurav.sharma@smartdukaan.com";
428
        boolean isApprover = false;
429
        if (authEmail.equals(approverEmail)) {
430
            isApprover = true;
431
        }
33845 tejus.loha 432
        Map<Integer, LoiDoc> masterDocIdLoiDocMap = loiDocRepository.selectByLoiFormId(loiId).stream().collect(Collectors.toMap(x -> x.getMasterDocId(), x -> x));
33507 tejus.loha 433
        model.addAttribute("isApprover", isApprover);
434
        model.addAttribute("loiId", loiId);
435
        model.addAttribute("activeDocMasterList", activeDocMasterList);
436
        model.addAttribute("masterDocIdLoiDocMap", masterDocIdLoiDocMap);
437
        return "loiForm/document-upload";
438
    }
439
 
440
    @RequestMapping(value = "/uploadOnboardingDocument", method = RequestMethod.POST)
441
    public String uploadDocument(HttpServletRequest request, @RequestParam int loiId, @RequestBody List<LoiDocModel> loiDocModels, Model model) throws Exception {
442
        LoiForm loiForm = loiFormRepository.selectById(loiId);
443
        loiFormService.setDocs(loiForm, loiDocModels);
444
        model.addAttribute("response1", mvcResponseSender.createResponseString("Document uploaded successfully"));
445
        return "response";
446
 
447
    }
448
 
449
 
33617 tejus.loha 450
    @RequestMapping(value = "/documentVerify", method = RequestMethod.PUT)
33507 tejus.loha 451
    public String docApproval(HttpServletRequest request, @RequestParam int loiId, @RequestParam int docMasterId, @RequestParam boolean flag, Model model) throws Exception {
452
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
453
        AuthUser auth = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
454
        LoiDoc loiDoc = loiDocRepository.selectByLoiIdAndMasterDocId(loiId, docMasterId);
455
        if (flag) {
456
            loiDoc.setOk(true);
457
            loiDoc.setVerifyBy(auth.getId());
35971 aman 458
            // Document Approval timeline entry
459
            storeTimelineTatService.createStoreTimeline(loiId, StoreTimeline.LOI_DOCUMENT_APPROVAL);
33507 tejus.loha 460
            model.addAttribute("response1", mvcResponseSender.createResponseString(loiDoc.getDocType() + " is Accepted "));
461
            return "response";
462
        } else {
463
            loiDoc.setOk(false);
464
            loiDoc.setVerifyBy(auth.getId());
35971 aman 465
            LoiForm loiForm = loiFormRepository.selectById(loiId);
466
            if (loiForm.isLoiApproved()) {
467
                loiForm.setLoiApproved(false);
468
            }
33658 tejus.loha 469
            loiFormService.sendDocRejectionMail(loiDoc);
33507 tejus.loha 470
            model.addAttribute("response1", mvcResponseSender.createResponseString(loiDoc.getDocType() + " is Rejected"));
471
            return "response";
472
        }
473
    }
474
 
475
    @RequestMapping(value = "/loiAcceptanceOtp", method = RequestMethod.POST)
476
    public String sentLoiAcceptanceOtp(@RequestParam int loiId, Model model) throws Exception {
33658 tejus.loha 477
        LoiForm loiForm = loiFormRepository.selectById(loiId);
478
        String mobile = String.valueOf(loiForm.getMobile());
37194 aman 479
        Map<String, Object> response = new HashMap<>();
480
 
481
        OTPResponse otpResponse;
482
        try {
483
            otpResponse = otpProcessor.generateOtp(mobile, OtpType.LOI_ACCEPTANCE);
484
        } catch (Exception e) {
485
            // The dispatch itself blew up (gateway error, duplicate loi_form on this mobile, ...). Never
486
            // report this as a send - the panel used to show "OTP Sent Successfully!" for exactly this case.
487
            LOGGER.error("LOI acceptance OTP dispatch failed for loiId " + loiId + ", mobile " + mobile, e);
488
            response.put("status", false);
489
            response.put("sent", false);
490
            response.put("message", "OTP could not be sent due to a system error. Please report to tech support.");
491
            model.addAttribute("response1", mvcResponseSender.createResponseString(response));
33568 tejus.loha 492
            return "response";
37194 aman 493
        }
494
 
495
        LOGGER.info("OTPResponse for loiId " + loiId + " - result=" + otpResponse.isResult()
496
                + ", sent=" + otpResponse.isSent() + ", message=" + otpResponse.getMessage());
497
 
498
        response.put("status", otpResponse.isResult());
499
        response.put("sent", otpResponse.isSent());
500
        if (otpResponse.isResult() && otpResponse.isSent()) {
501
            response.put("message", "OTP sent on registered mobile and EmailId - " + mobile + " and " + loiForm.getEmail());
33525 tejus.loha 502
        } else {
37194 aman 503
            // Accepted-but-not-dispatched (resend throttle) and outright rejections (daily cap) both land
504
            // here. Pass the processor's own reason through instead of a generic "Something went wrong..".
505
            response.put("message", otpResponse.getMessage());
33525 tejus.loha 506
        }
37194 aman 507
        model.addAttribute("response1", mvcResponseSender.createResponseString(response));
508
        return "response";
33507 tejus.loha 509
    }
510
 
511
    @RequestMapping(value = "/validateLoiOtp", method = RequestMethod.PUT)
35038 aman 512
    public ResponseEntity<?> validateLoiAcceptanceOtp(HttpServletRequest request, @RequestParam int loiId, @RequestParam String provideOtp, Model model) throws Exception {
33658 tejus.loha 513
        LoiForm loiForm = loiFormRepository.selectById(loiId);
37632 aman 514
        if (loiForm.getLoiSignOtp() != null && loiForm.getLoiDoc() > 0) {
515
            throw new ProfitMandiBusinessException("LOI already signed", loiId, "This LOI is already signed and saved. Refresh the Pending LOI list.");
516
        }
33658 tejus.loha 517
        String mobile = String.valueOf(loiForm.getMobile());
37632 aman 518
        List<Otp> otps = otpRepository.selectAllByMobileWithTime(mobile);
519
        if (otps.isEmpty()) {
520
            throw new ProfitMandiBusinessException("No OTP", mobile, "No OTP was sent to " + mobile + " in the last 24 hours. Click Send OTP first.");
521
        }
522
        OTPResponse otpResponse = otpProcessor.validateOtp(otps.get(0).getId(), mobile, provideOtp);
35038 aman 523
        Map<String, Object> response = new HashMap<>();
33507 tejus.loha 524
        if (otpResponse.isResult()) {
33658 tejus.loha 525
            loiForm.setLoiSignOtp(provideOtp);
526
            loiForm.setLoiSignedOn(LocalDateTime.now());
35038 aman 527
 
528
            List<LoiBrandCommitment> loiBrandCommitments = brandCommitmentRepository.selectByLoiId(loiId).stream().filter(x -> x.getAmount() > 0).collect(Collectors.toList());
529
            double totalCommitment = loiBrandCommitments.stream().mapToDouble(x -> x.getAmount()).sum();
530
            List<BrandFeeCollection> brandFeeCollections = brandFeeCollectionRepository.selectAllConfirmPaymetByLoiId(loiId);
531
            double brandFeeAmount = brandFeeCollections.stream().mapToDouble(x -> x.getCollectedAmount()).sum();
532
            BrandFeeCollection brandFeeCollection = brandFeeCollections.get(0);
533
            String prevHash = loiAuditTrailRepository.findDocumentHashByLoiId(loiId);
534
            String rawData = loiId + "|"
535
                    + loiForm.getCompanyName() + "|"
536
                    + loiForm.getBrandType() + "|"
537
                    + brandFeeAmount + "|"
538
                    + brandFeeCollection.getPaymentMode() + "|"
539
                    + totalCommitment;
540
            String hash = getHash256(rawData);
541
 
542
            LoiAuditTrail audit = new LoiAuditTrail();
543
            audit.setLoiId(loiId);
544
            audit.setCompanyName(loiForm.getCompanyName());
545
            audit.setReferBy(loiForm.getReferBy());
546
            audit.setReferId(loiForm.getReferId());
547
            audit.setFilledBy(loiForm.getFilledBy());
548
            audit.setFranchiseeName(loiForm.getFullName());
549
            audit.setBrandType(loiForm.getBrandType());
550
            audit.setBrandFeeAmount(brandFeeAmount);
551
            audit.setPaymentMode(brandFeeCollection.getPaymentMode());
552
            audit.setTotalCommitment(totalCommitment);
553
            audit.setLoiSignedOn(LocalDateTime.now());
554
            audit.setLoiGeneratedOn(loiForm.getLoiGeneratedOn());
555
            audit.setLoiOtp(provideOtp);
556
            if (prevHash != null) {
557
                audit.setPrevHash(prevHash);
558
            }
559
            audit.setIpAddress(request.getRemoteAddr());
560
            audit.setDocumentHash(hash);
561
 
562
            response.put("success", true);
563
            response.put("documentHash", audit.getDocumentHash());
564
            response.put("ipAddress", audit.getIpAddress());
565
            response.put("generatedAt", audit.getCreatedAt());
566
            response.put("loiId", loiId);
567
            loiAuditTrailRepository.persist(audit);
568
 
33845 tejus.loha 569
        } else {
37632 aman 570
            // "OTP expired" also covers an OTP that was already used - e.g. re-entering the code after
571
            // the signed PDF failed to save. Say so instead of calling it wrong.
572
            throw new ProfitMandiBusinessException("Wrong OTP", "", "OTP " + provideOtp + " not accepted (" + otpResponse.getMessage()
573
                    + "). An OTP works only once - if it was already entered, click Send OTP to get a new one.");
33507 tejus.loha 574
        }
35038 aman 575
        return responseSender.ok(response);
33507 tejus.loha 576
    }
577
 
33845 tejus.loha 578
    @RequestMapping(value = "/saveLoiDoc", method = RequestMethod.POST)
579
    public String saveLoiDoc(@RequestParam int loiId, @RequestParam int loiDocId, Model model) throws Exception {
580
        LOGGER.info("loi_docId-" + loiDocId);
581
        LoiForm loiForm = loiFormRepository.selectById(loiId);
582
        if (loiDocId > 0) {
37632 aman 583
            if (loiForm.getLoiSignOtp() == null) {
584
                throw new ProfitMandiBusinessException("LOI OTP not verified", loiId, "Partner OTP is not verified for this LOI. Click Send OTP and Confirm Sign again.");
585
            }
586
            if (loiForm.getLoiDoc() > 0) {
587
                // Retry of a save that already went through: don't mail the partner or complete the LOI twice.
588
                LOGGER.info("Signed LOI already saved for loiId {} (doc {}), ignoring doc {}", loiId, loiForm.getLoiDoc(), loiDocId);
589
                model.addAttribute("response1", mvcResponseSender.createResponseString(true));
590
                return "response";
591
            }
33845 tejus.loha 592
            loiForm.setLoiDoc(loiDocId);
593
            loiFormService.sendSignedLoiPdfToPartner(loiForm);
33848 tejus.loha 594
            loiFormService.checkLoiDetailsCompletion(loiForm);
33845 tejus.loha 595
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
596
        } else {
34947 aman 597
            loiForm.setLoiSignOtp(null);
33845 tejus.loha 598
            loiForm.setLoiGeneratedOn(null);
599
            loiForm.setLoiSignedOn(null);
600
            model.addAttribute("response1", mvcResponseSender.createResponseString(false));
601
        }
602
        return "response";
603
 
604
    }
605
 
33617 tejus.loha 606
    @RequestMapping(value = "/downloadLoiFromReport", method = RequestMethod.GET)
607
    public ResponseEntity<?> downloadAllLoiForm(@RequestParam LocalDate from, @RequestParam LocalDate to) throws Exception {
608
        ResponseEntity<?> responseEntity = loiFormService.createLoiFormReport(from, to);
609
        return responseEntity;
610
    }
611
 
33658 tejus.loha 612
    @RequestMapping(value = "/updatePayment", method = RequestMethod.POST)
613
    public String updateForm(@RequestBody BrandFeeCollection brandFeeCollection, Model model) throws Exception {
614
        BrandFeeCollection brandFeeCollection1 = brandFeeCollectionRepository.selectById(brandFeeCollection.getId());
33845 tejus.loha 615
        LoiForm loiForm = loiFormRepository.selectById(brandFeeCollection1.getLoiFormId());
33850 tejus.loha 616
        brandFeeCollection1.setFeeCollectingTimeStamp(brandFeeCollection.getFeeCollectingTimeStamp());
617
        brandFeeCollection1.setCollectedAmount(brandFeeCollection.getCollectedAmount());
33885 tejus.loha 618
        brandFeeCollection1.setPaymentAttachment(brandFeeCollection.getPaymentAttachment());
33850 tejus.loha 619
        brandFeeCollection1.setPaymentReferenceNo(brandFeeCollection.getPaymentReferenceNo());
620
        brandFeeCollection1.setPaymentMode(brandFeeCollection.getPaymentMode());
621
        double totalCollectedFee = brandFeeCollectionRepository.selectAllByLoiFormId(loiForm.getId()).stream().mapToDouble(x -> x.getCollectedAmount()).sum();
622
        if (totalCollectedFee <= loiForm.getAgreedBrandFees()) {
33845 tejus.loha 623
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
624
        } else {
33850 tejus.loha 625
            double differanceAmount = totalCollectedFee - loiForm.getAgreedBrandFees();
33845 tejus.loha 626
            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");
627
        }
33658 tejus.loha 628
        return "response";
629
    }
33617 tejus.loha 630
 
33710 tejus.loha 631
    @RequestMapping(value = "/updateAgreedBrandFee", method = RequestMethod.PUT)
34085 tejus.loha 632
    public String updateAgreedBrandFee(HttpServletRequest request, @RequestParam int loiId, @RequestParam double brandFee, @RequestParam StoreType storeType, Model model) throws Exception {
33710 tejus.loha 633
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
634
        boolean isAgreedBrandFeeChanger = agreedBrandFeeChangerEmail.stream().anyMatch(x -> x.equals(loginDetails.getEmailId()));
635
        if (isAgreedBrandFeeChanger) {
636
            LoiForm loiForm = loiFormRepository.selectById(loiId);
637
            loiForm.setAgreedBrandFees(brandFee);
34085 tejus.loha 638
            loiForm.setBrandType(storeType);
34086 tejus.loha 639
            loiFormService.checkLoiDetailsCompletion(loiFormRepository.selectById(loiId));
33710 tejus.loha 640
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
641
            return "response";
642
        } else {
643
            throw new ProfitMandiBusinessException("failed in Authority check ", null, "Sorry " + authRepository.selectByEmailOrMobile(loginDetails.getEmailId()).getName() + " you have no authority to change agreed brand fee");
644
        }
645
    }
646
 
33845 tejus.loha 647
    @RequestMapping(value = "/approve-reject-Loi", method = RequestMethod.PUT)
648
    public String approveDetails(HttpServletRequest request, @RequestParam int loiId, @RequestParam boolean flag, Model model) throws Exception {
649
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
650
        String email = loginDetails.getEmailId();
33711 tejus.loha 651
        LoiForm loiForm = loiFormRepository.selectById(loiId);
33845 tejus.loha 652
        AuthUser filledBy = authRepository.selectByEmailOrMobile(loiForm.getFilledBy());
653
        AuthUser manager = authRepository.selectById(filledBy.getManagerId());
654
        AuthUser upperManager = null;
655
        List<String> approverMail = new ArrayList<>();
656
        approverMail.add(manager.getEmailId());
657
        upperManager = authRepository.selectById(manager.getManagerId());
658
        approverMail.add(upperManager.getEmailId());
659
 
660
        LOGGER.info("approverMail-" + approverMail);
661
        // Approver - Manager or Upper manager of loi filledBy(BM)
662
        boolean isApprover = approverMail.contains(email);
663
        LOGGER.info("isApprover-" + isApprover);
37630 amit 664
        List<String> authEmail = Arrays.asList("tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com");
33845 tejus.loha 665
        boolean isAuthUser = authEmail.stream().anyMatch(x -> x.equals(email));
666
        if (flag) {
667
            if (isApprover || isAuthUser) {
668
                loiForm.setLoiApprover(email);
669
                loiForm.setLoiApproved(flag);
35971 aman 670
                if (loiForm.getStatus() == LoiStatus.LOI_REJECT) {
671
                    loiForm.setStatus(LoiStatus.PENDING);
672
                }
673
                // BM Approval timeline entry
674
                storeTimelineTatService.createStoreTimeline(loiId, StoreTimeline.BM_APPROVAL);
675
                // Check if all LOI conditions are now met (BM approval could be the last step)
676
                loiFormService.checkLoiDetailsCompletion(loiForm);
33845 tejus.loha 677
                model.addAttribute("response1", mvcResponseSender.createResponseString(true));
678
            } else {
679
                throw new ProfitMandiBusinessException("Failed in Authority check ", "Read", "Sorry " + authRepository.selectByEmailOrMobile(loginDetails.getEmailId()).getName() + " you have no authority to Approve this Loi Form ,Only reporting manager and upper can Approve");
680
            }
681
        } else {
682
            if (isApprover || isAuthUser) {
683
                loiForm.setLoiApprover(email);
684
                loiForm.setLoiApproved(flag);
685
                loiForm.setStatus(LoiStatus.LOI_REJECT);
686
                model.addAttribute("response1", mvcResponseSender.createResponseString(true));
687
            } else {
688
                throw new ProfitMandiBusinessException("Failed in Authority check ", "Read", "Sorry " + authRepository.selectByEmailOrMobile(loginDetails.getEmailId()).getName() + " you have no authority to Approve this Loi Form ,Only reporting manager and upper can Approve");
689
            }
690
        }
33711 tejus.loha 691
        return "response";
692
    }
693
 
37660 ranu 694
    // For a REVIVAL LOI whose brand-fee payment just got confirmed:
695
    //   1. Reactivate the FofoStore behind the old code so orders / wallet / inventory
696
    //      start honoring the store again.
37671 ranu 697
    //   2. Wipe all Store Setup + Launch timeline events (RECCE, WOD, FIN_CODE,
698
    //      WOD_FINANCE_MAPPING, BRANDING, ADVANCE_STOCK_PAYMENT, FULL_STOCK_PAYMENT,
699
    //      AGREEMENT_ESIGN, PO_CREATION, PO_APPROVAL, BILLING, INAUGRATION, TRAINING)
700
    //      plus RBM_ASSIGNMENT so the revived partner has to redo the full lifecycle.
701
    //      Kept from old life: ON_BOARDING, VERIFICATION, STORE_CODE_CREATED,
702
    //      DOCUMENTS, WELCOME_CALL — partner is already known + verified.
703
    //   3. Reset the backing panel fields (billingStatus, inaugrationDate,
704
    //      deploymentDate, receeActual, status) and the training panel's
705
    //      appTraining / dashboardTraning flags so the events can actually re-fire.
706
    //   4. Wipe the AgreementEsign record so the upload widget starts blank.
37660 ranu 707
    // No-op for NEW and ANY_OTHER LOIs.
37663 vikas 708
    private void applyRevivalPaymentHooks(LoiForm loi) throws ProfitMandiBusinessException {
37660 ranu 709
        if (loi == null || loi.getOnboardingType() != OnboardingType.REVIVAL) return;
710
        String oldCode = loi.getOldStoreCode();
711
        if (oldCode != null && !oldCode.trim().isEmpty()) {
712
            FofoStore store = fofoStoreRepository.selectByStoreCode(oldCode.trim());
713
            if (store != null && !store.isActive()) {
714
                store.setActive(true);
715
                store.setActiveTimeStamp(LocalDateTime.now());
716
                fofoStoreRepository.persist(store);
717
                LOGGER.info("Revival PAYMENT_APPROVAL: reactivated FofoStore code=" + oldCode);
718
            }
719
        }
720
        int onboardingId = loi.getOnBoardingId();
721
        if (onboardingId > 0) {
37671 ranu 722
            StoreTimeline[] revivalClearEvents = {
723
                    StoreTimeline.RECCE,
724
                    StoreTimeline.WOD,
725
                    StoreTimeline.FIN_CODE,
726
                    StoreTimeline.WOD_FINANCE_MAPPING,
727
                    StoreTimeline.BRANDING,
728
                    StoreTimeline.ADVANCE_STOCK_PAYMENT,
729
                    StoreTimeline.FULL_STOCK_PAYMENT,
730
                    StoreTimeline.AGREEMENT_ESIGN,
731
                    StoreTimeline.PO_CREATION,
732
                    StoreTimeline.PO_APPROVAL,
733
                    StoreTimeline.BILLING,
734
                    StoreTimeline.INAUGRATION,
735
                    StoreTimeline.TRAINING,
736
                    StoreTimeline.RBM_ASSIGNMENT
737
            };
738
            for (StoreTimeline ev : revivalClearEvents) {
739
                storeTimelinetbRepository.deleteByOnboardingIdAndEvent(onboardingId, ev);
740
            }
37660 ranu 741
            agreementEsignRepository.deleteByOnboardingId(onboardingId);
37671 ranu 742
 
743
            PartnerOnBoardingPanel panel = partnerOnBoardingPanelRepository.selectById(onboardingId);
744
            if (panel != null) {
745
                panel.setBillingStatus(0);
746
                panel.setInaugrationDate(null);
747
                panel.setDeploymentDate(null);
748
                panel.setReceeActual(null);
749
                panel.setStatus(PartnerOnBoardingStatus.pending);
750
                panel.setUpdatedTimestamp(LocalDateTime.now());
751
                partnerOnBoardingPanelRepository.persist(panel);
752
            }
753
 
754
            PartnerOnboardingTrainingPanel training = partnerDashboardTrainingRepository.selectByOnboardingId(onboardingId);
755
            if (training != null) {
756
                training.setAppTraining(null);
757
                training.setDashboardTraning(null);
758
                training.setDateCompleted(null);
759
                training.setUpdateTimestamp(LocalDateTime.now());
760
                partnerDashboardTrainingRepository.persist(training);
761
            }
762
 
763
            LOGGER.info("Revival PAYMENT_APPROVAL: cleared " + revivalClearEvents.length
764
                    + " timeline events + AgreementEsign + reset panel/training state for onboardingId=" + onboardingId);
37660 ranu 765
        }
766
    }
33507 tejus.loha 767
}