Subversion Repositories SmartDukaan

Rev

Rev 34947 | Rev 35169 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34947 Rev 35038
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import com.fasterxml.jackson.databind.ObjectMapper;
3
import com.fasterxml.jackson.databind.ObjectMapper;
-
 
4
import com.google.common.hash.Hashing;
4
import com.spice.profitmandi.common.enumuration.BusinessType;
5
import com.spice.profitmandi.common.enumuration.BusinessType;
5
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
6
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
6
import com.spice.profitmandi.common.model.ProfitMandiConstants;
7
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
8
import com.spice.profitmandi.common.web.util.ResponseSender;
7
import com.spice.profitmandi.dao.entity.auth.AuthUser;
9
import com.spice.profitmandi.dao.entity.auth.AuthUser;
8
import com.spice.profitmandi.dao.entity.brandFee.BrandFee;
10
import com.spice.profitmandi.dao.entity.brandFee.BrandFee;
9
import com.spice.profitmandi.dao.entity.brandFee.BrandFeeCollection;
11
import com.spice.profitmandi.dao.entity.brandFee.BrandFeeCollection;
10
import com.spice.profitmandi.dao.entity.dtr.Otp;
12
import com.spice.profitmandi.dao.entity.dtr.Otp;
11
import com.spice.profitmandi.dao.entity.onBoarding.*;
13
import com.spice.profitmandi.dao.entity.onBoarding.*;
Line 25... Line 27...
25
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
27
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
26
import com.spice.profitmandi.dao.repository.dtr.OtpRepository;
28
import com.spice.profitmandi.dao.repository.dtr.OtpRepository;
27
import com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository;
29
import com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository;
28
import com.spice.profitmandi.dao.repository.inventory.PartnerOnboardingService;
30
import com.spice.profitmandi.dao.repository.inventory.PartnerOnboardingService;
29
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
31
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
30
import com.spice.profitmandi.dao.repository.onboarding.BrandCommitRepository;
-
 
31
import com.spice.profitmandi.dao.repository.onboarding.LoiBrandCommitmentRepository;
-
 
32
import com.spice.profitmandi.dao.repository.onboarding.LoiDocMasterRepository;
-
 
33
import com.spice.profitmandi.dao.repository.onboarding.LoiDocRepository;
32
import com.spice.profitmandi.dao.repository.onboarding.*;
34
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
33
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
35
import com.spice.profitmandi.dao.repository.user.BillingAddressRepository;
34
import com.spice.profitmandi.dao.repository.user.BillingAddressRepository;
36
import com.spice.profitmandi.dao.repository.user.LoiFormRepository;
35
import com.spice.profitmandi.dao.repository.user.LoiFormRepository;
37
import com.spice.profitmandi.dao.service.LoiDocModel;
36
import com.spice.profitmandi.dao.service.LoiDocModel;
38
import com.spice.profitmandi.dao.service.OTPResponse;
37
import com.spice.profitmandi.dao.service.OTPResponse;
Line 57... Line 56...
57
import org.springframework.web.bind.annotation.RequestMapping;
56
import org.springframework.web.bind.annotation.RequestMapping;
58
import org.springframework.web.bind.annotation.RequestMethod;
57
import org.springframework.web.bind.annotation.RequestMethod;
59
import org.springframework.web.bind.annotation.RequestParam;
58
import org.springframework.web.bind.annotation.RequestParam;
60
 
59
 
61
import javax.servlet.http.HttpServletRequest;
60
import javax.servlet.http.HttpServletRequest;
-
 
61
import java.nio.charset.StandardCharsets;
62
import java.time.LocalDate;
62
import java.time.LocalDate;
63
import java.time.LocalDateTime;
63
import java.time.LocalDateTime;
64
import java.util.*;
64
import java.util.*;
65
import java.util.stream.Collectors;
65
import java.util.stream.Collectors;
66
 
66
 
Line 120... Line 120...
120
    BillingAddressRepository billingAddressRepository;
120
    BillingAddressRepository billingAddressRepository;
121
    @Autowired
121
    @Autowired
122
    LoiBrandCommitmentRepository brandCommitmentRepository;
122
    LoiBrandCommitmentRepository brandCommitmentRepository;
123
    @Autowired
123
    @Autowired
124
    PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
124
    PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
-
 
125
    @Autowired
-
 
126
    LoiAuditTrailRepository loiAuditTrailRepository;
-
 
127
 
-
 
128
    @Autowired
-
 
129
    ResponseSender responseSender;
125
 
130
 
126
    List<String> agreedBrandFeeChangerEmail = Arrays.asList("sm@smartdukaan.com");
131
    List<String> agreedBrandFeeChangerEmail = Arrays.asList("sm@smartdukaan.com");
127
 
132
 
128
    // Loi Form
133
    // Loi Form
129
    @RequestMapping(value = "/loiForm", method = RequestMethod.GET)
134
    @RequestMapping(value = "/loiForm", method = RequestMethod.GET)
Line 136... Line 141...
136
                storeTypeFeePairs.add(Pair.of(storeType, fee));
141
                storeTypeFeePairs.add(Pair.of(storeType, fee));
137
            }
142
            }
138
        }
143
        }
139
        List<AuthUser> stateHeadList = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_SALES, Arrays.asList(EscalationType.L2, EscalationType.L3));
144
        List<AuthUser> stateHeadList = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_SALES, Arrays.asList(EscalationType.L2, EscalationType.L3));
140
        List<AuthUser> bdmList = csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L1);
145
        List<AuthUser> bdmList = csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L1);
-
 
146
        List<AuthUser> abmHeadList = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_ABM, Arrays.asList(EscalationType.L2, EscalationType.L3));
-
 
147
        List<AuthUser> abmList = csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_ABM, EscalationType.L1);
-
 
148
        bdmList.addAll(abmList);
-
 
149
        stateHeadList.addAll(abmHeadList);
141
        List<BrandCommit> brandCommits = brandCommitRepository.selectAllActiveBrand();
150
        List<BrandCommit> brandCommits = brandCommitRepository.selectAllActiveBrand();
142
        model.addAttribute("businessTypes", BusinessType.values());
151
        model.addAttribute("businessTypes", BusinessType.values());
143
        model.addAttribute("brandCommits", brandCommits);
152
        model.addAttribute("brandCommits", brandCommits);
144
        model.addAttribute("storeTypeFeePairs", storeTypeFeePairs);
153
        model.addAttribute("storeTypeFeePairs", storeTypeFeePairs);
145
        model.addAttribute("authUsersList", authUsersList);
154
        model.addAttribute("authUsersList", authUsersList);
Line 152... Line 161...
152
    @RequestMapping(value = "/gstValidate", method = RequestMethod.GET)
161
    @RequestMapping(value = "/gstValidate", method = RequestMethod.GET)
153
    public ResponseEntity<?> gstValidate(HttpServletRequest request, @RequestParam String gstNo) throws Exception {
162
    public ResponseEntity<?> gstValidate(HttpServletRequest request, @RequestParam String gstNo) throws Exception {
154
        LOGGER.info("gstNo -" + gstNo);
163
        LOGGER.info("gstNo -" + gstNo);
155
        GstDetails gstDetails = gstProService.getGstDetails(gstNo);
164
        GstDetails gstDetails = gstProService.getGstDetails(gstNo);
156
        LOGGER.info("gstDetails -" + gstDetails);
165
        LOGGER.info("gstDetails -" + gstDetails);
157
        if(gstDetails !=null){
166
        if (gstDetails != null) {
158
            List<GstDetails.Pradr> adadr = gstDetails.getAdadr();
167
            List<GstDetails.Pradr> adadr = gstDetails.getAdadr();
159
            adadr.add(gstDetails.getPradr());
168
            adadr.add(gstDetails.getPradr());
160
            Collections.reverse(adadr);
169
            Collections.reverse(adadr);
161
            LOGGER.info("list_of_adadr-" + adadr);
170
            LOGGER.info("list_of_adadr-" + adadr);
162
        }
171
        }
Line 241... Line 250...
241
        model.addAttribute("filledBy", filledBy);
250
        model.addAttribute("filledBy", filledBy);
242
        return "auto-Loi";
251
        return "auto-Loi";
243
 
252
 
244
    }
253
    }
245
 
254
 
-
 
255
    private String getHash256(String originalString) {
-
 
256
        String hashString = Hashing.sha256().hashString(originalString, StandardCharsets.UTF_8).toString();
-
 
257
        LOGGER.info("Hash String {}", hashString);
-
 
258
        return hashString;
-
 
259
    }
246
 
260
 
247
    // send Filled form for update purpose
261
    // send Filled form for update purpose
248
    @RequestMapping(value = "/updateLoiForm", method = RequestMethod.GET)
262
    @RequestMapping(value = "/updateLoiForm", method = RequestMethod.GET)
249
    public String UpdateLoiForm(HttpServletRequest request,
263
    public String UpdateLoiForm(HttpServletRequest request,
250
                                @RequestParam int loiId,
264
                                @RequestParam int loiId,
Line 391... Line 405...
391
            return "response";
405
            return "response";
392
        }
406
        }
393
    }
407
    }
394
 
408
 
395
    @RequestMapping(value = "/validateLoiOtp", method = RequestMethod.PUT)
409
    @RequestMapping(value = "/validateLoiOtp", method = RequestMethod.PUT)
396
    public String validateLoiAcceptanceOtp(@RequestParam int loiId, @RequestParam String provideOtp, Model model) throws Exception {
410
    public ResponseEntity<?> validateLoiAcceptanceOtp(HttpServletRequest request, @RequestParam int loiId, @RequestParam String provideOtp, Model model) throws Exception {
397
        LoiForm loiForm = loiFormRepository.selectById(loiId);
411
        LoiForm loiForm = loiFormRepository.selectById(loiId);
398
        String mobile = String.valueOf(loiForm.getMobile());
412
        String mobile = String.valueOf(loiForm.getMobile());
399
        Otp otp = otpRepository.selectAllByMobileWithTime(mobile).get(0);
413
        Otp otp = otpRepository.selectAllByMobileWithTime(mobile).get(0);
400
        OTPResponse otpResponse = otpProcessor.validateOtp(otp.getId(), mobile, provideOtp);
414
        OTPResponse otpResponse = otpProcessor.validateOtp(otp.getId(), mobile, provideOtp);
-
 
415
        Map<String, Object> response = new HashMap<>();
401
        if (otpResponse.isResult()) {
416
        if (otpResponse.isResult()) {
402
            loiForm.setLoiSignOtp(provideOtp);
417
            loiForm.setLoiSignOtp(provideOtp);
403
            loiForm.setLoiSignedOn(LocalDateTime.now());
418
            loiForm.setLoiSignedOn(LocalDateTime.now());
-
 
419
 
-
 
420
            List<LoiBrandCommitment> loiBrandCommitments = brandCommitmentRepository.selectByLoiId(loiId).stream().filter(x -> x.getAmount() > 0).collect(Collectors.toList());
-
 
421
            double totalCommitment = loiBrandCommitments.stream().mapToDouble(x -> x.getAmount()).sum();
-
 
422
            List<BrandFeeCollection> brandFeeCollections = brandFeeCollectionRepository.selectAllConfirmPaymetByLoiId(loiId);
-
 
423
            double brandFeeAmount = brandFeeCollections.stream().mapToDouble(x -> x.getCollectedAmount()).sum();
404
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
424
            BrandFeeCollection brandFeeCollection = brandFeeCollections.get(0);
-
 
425
            String prevHash = loiAuditTrailRepository.findDocumentHashByLoiId(loiId);
-
 
426
            String rawData = loiId + "|"
-
 
427
                    + loiForm.getCompanyName() + "|"
-
 
428
                    + loiForm.getBrandType() + "|"
-
 
429
                    + brandFeeAmount + "|"
-
 
430
                    + brandFeeCollection.getPaymentMode() + "|"
-
 
431
                    + totalCommitment;
-
 
432
            String hash = getHash256(rawData);
-
 
433
 
-
 
434
            LoiAuditTrail audit = new LoiAuditTrail();
-
 
435
            audit.setLoiId(loiId);
-
 
436
            audit.setCompanyName(loiForm.getCompanyName());
-
 
437
            audit.setReferBy(loiForm.getReferBy());
-
 
438
            audit.setReferId(loiForm.getReferId());
-
 
439
            audit.setFilledBy(loiForm.getFilledBy());
-
 
440
            audit.setFranchiseeName(loiForm.getFullName());
-
 
441
            audit.setBrandType(loiForm.getBrandType());
-
 
442
            audit.setBrandFeeAmount(brandFeeAmount);
-
 
443
            audit.setPaymentMode(brandFeeCollection.getPaymentMode());
-
 
444
            audit.setTotalCommitment(totalCommitment);
-
 
445
            audit.setLoiSignedOn(LocalDateTime.now());
-
 
446
            audit.setLoiGeneratedOn(loiForm.getLoiGeneratedOn());
-
 
447
            audit.setLoiOtp(provideOtp);
-
 
448
            if (prevHash != null) {
-
 
449
                audit.setPrevHash(prevHash);
-
 
450
            }
-
 
451
            audit.setIpAddress(request.getRemoteAddr());
-
 
452
            audit.setDocumentHash(hash);
-
 
453
 
-
 
454
            response.put("success", true);
-
 
455
            response.put("documentHash", audit.getDocumentHash());
-
 
456
            response.put("ipAddress", audit.getIpAddress());
-
 
457
            response.put("generatedAt", audit.getCreatedAt());
-
 
458
            response.put("loiId", loiId);
-
 
459
            loiAuditTrailRepository.persist(audit);
-
 
460
 
405
        } else {
461
        } else {
406
            throw new ProfitMandiBusinessException("Wrong OTP", "", "Your given Otp ->" + provideOtp + " is wrong , please check OTP and try again");
462
            throw new ProfitMandiBusinessException("Wrong OTP", "", "Your given Otp ->" + provideOtp + " is wrong , please check OTP and try again");
407
        }
463
        }
408
        return "response";
464
        return responseSender.ok(response);
409
    }
465
    }
410
 
466
 
411
    @RequestMapping(value = "/saveLoiDoc", method = RequestMethod.POST)
467
    @RequestMapping(value = "/saveLoiDoc", method = RequestMethod.POST)
412
    public String saveLoiDoc(@RequestParam int loiId, @RequestParam int loiDocId, Model model) throws Exception {
468
    public String saveLoiDoc(@RequestParam int loiId, @RequestParam int loiDocId, Model model) throws Exception {
413
        LOGGER.info("loi_docId-" + loiDocId);
469
        LOGGER.info("loi_docId-" + loiDocId);
Line 466... Line 522...
466
        } else {
522
        } else {
467
            throw new ProfitMandiBusinessException("failed in Authority check ", null, "Sorry " + authRepository.selectByEmailOrMobile(loginDetails.getEmailId()).getName() + " you have no authority to change agreed brand fee");
523
            throw new ProfitMandiBusinessException("failed in Authority check ", null, "Sorry " + authRepository.selectByEmailOrMobile(loginDetails.getEmailId()).getName() + " you have no authority to change agreed brand fee");
468
        }
524
        }
469
    }
525
    }
470
 
526
 
471
 
-
 
472
    @RequestMapping(value = "/approve-reject-Loi", method = RequestMethod.PUT)
527
    @RequestMapping(value = "/approve-reject-Loi", method = RequestMethod.PUT)
473
    public String approveDetails(HttpServletRequest request, @RequestParam int loiId, @RequestParam boolean flag, Model model) throws Exception {
528
    public String approveDetails(HttpServletRequest request, @RequestParam int loiId, @RequestParam boolean flag, Model model) throws Exception {
474
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
529
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
475
        String email = loginDetails.getEmailId();
530
        String email = loginDetails.getEmailId();
476
        LoiForm loiForm = loiFormRepository.selectById(loiId);
531
        LoiForm loiForm = loiFormRepository.selectById(loiId);