Subversion Repositories SmartDukaan

Rev

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

Rev 32818 Rev 32822
Line 134... Line 134...
134
import java.util.*;
134
import java.util.*;
135
import java.util.Map.Entry;
135
import java.util.Map.Entry;
136
import java.util.stream.Collectors;
136
import java.util.stream.Collectors;
137
import java.util.stream.Stream;
137
import java.util.stream.Stream;
138
 
138
 
-
 
139
 
139
import static java.util.stream.Collectors.groupingBy;
140
import static java.util.stream.Collectors.groupingBy;
140
import static java.util.stream.Collectors.mapping;
141
import static java.util.stream.Collectors.mapping;
141
 
142
 
142
 
143
 
143
@Component
144
@Component
Line 2967... Line 2968...
2967
        sb.append("</tbody></table></body></html>");
2968
        sb.append("</tbody></table></body></html>");
2968
 
2969
 
2969
        return sb.toString();
2970
        return sb.toString();
2970
    }
2971
    }
2971
 
2972
 
2972
    private String getMessageForRBMEscalatedPartners(List<PartnerCollectionRemark> pcrs) throws
2973
    private String getMessageForUncontacblePartner(List<PartnerCollectionRemark> pcrs) throws
2973
            ProfitMandiBusinessException {
2974
            ProfitMandiBusinessException {
2974
        StringBuilder sb = new StringBuilder();
2975
        StringBuilder sb = new StringBuilder();
2975
        sb.append("<html><body><p>Alert</p><p>Escalated by RBM-L1:-</p>" + "<br/><table style='border:1px solid black ;padding: 5px';>");
2976
        sb.append("<html><body><p>Alert</p><p>Not Responding Partner:-</p>" + "<br/><table style='border:1px solid black ;padding: 5px';>");
2976
        sb.append("<tbody>" +
-
 
2977
                "<tr>" +
-
 
2978
                "<th style='border:1px solid black;padding: 5px'>PartnerName</th>" +
2977
        sb.append("<tbody>\n" + "	    				<tr>\n" + "	    					<th style='border:1px solid black;padding: 5px'>PartnerName</th>\n" + "	    					<th style='border:1px solid black;padding: 5px'>from</th>\n"
2979
                "<th style='border:1px solid black;padding: 5px'>Escalated Since</th>" +
-
 
2980
                "<th style='border:1px solid black;padding: 5px'>Message</th>" +
-
 
2981
                "</tr>");
-
 
2982
 
2978
 
-
 
2979
                + "	    				</tr>");
2983
        for (PartnerCollectionRemark entry : pcrs) {
2980
        for (PartnerCollectionRemark entry : pcrs) {
2984
 
2981
 
2985
            CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
2982
            CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
2986
 
2983
 
2987
            sb.append("<tr>");
2984
            sb.append("<tr>");
2988
            sb.append("<td style='border:1px solid black;padding: 5px'>" + customRetailer.getBusinessName() + "(" + customRetailer.getCode() + ")" + "</td>");
2985
            sb.append("<td style='border:1px solid black;padding: 5px'>" + customRetailer.getBusinessName() + "(" + customRetailer.getCode() + ")" + "</td>");
-
 
2986
 
2989
            sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getCreateTimestamp().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
2987
            sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getCreateTimestamp().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
2990
            sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getMessage() + "</td>");
-
 
2991
 
2988
 
2992
            sb.append("</tr>");
2989
            sb.append("</tr>");
2993
 
2990
 
2994
        }
2991
        }
2995
 
2992
 
Line 3407... Line 3404...
3407
        if (!orders.isEmpty()) {
3404
        if (!orders.isEmpty()) {
3408
 
3405
 
3409
            Set<String> airwayBillNo = orders.stream().map(x -> x.getAirwayBillNumber()).collect(Collectors.toSet());
3406
            Set<String> airwayBillNo = orders.stream().map(x -> x.getAirwayBillNumber()).collect(Collectors.toSet());
3410
 
3407
 
3411
            LOGGER.info("airwayBill" + airwayBillNo);
3408
            LOGGER.info("airwayBill" + airwayBillNo);
3412
            //String url = "https://api.bluedart.com/servlet/RoutingServlet?handler=tnt&action=custawbquery";
3409
            String url = "https://api.bluedart.com/servlet/RoutingServlet?handler=tnt&action=custawbquery";
3413
            String url = "https://apigateway.bluedart.com/in/transportation/tracking/v1/shipment?scan=1";
-
 
3414
            // String dataheader="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJzdWJqZWN0LXN1YmplY3QiLCJhdWQiOlsiYXVkaWVuY2UxIiwiYXVkaWVuY2UyIl0sIkNsaWVudFNlY3JldCI6IkV5SGp5OFNVcmtGNzZVc2ciLCJpc3MiOiJ1cm46XC9cL2FwaWdlZS1lZGdlLUpXVC1wb2xpY3ktdGVzdCIsIkNsaWVudElEIjoiRWJGSEdrazdOODU2R0dJZjlkclUzZ3BuRjZLbGNxUnUiLCJleHAiOjE3MDQzNjA1OTQsImlhdCI6MTcwNDI3NDE5NCwianRpIjoiNGVjZjZjMjEtYTE4MC00OGMwLThkYzUtNTM4OWRlYWFlM2JmIn0.miLZjZkqvgpr4N3eDEeahSXwK0jJSKuRMdnZRTXoF98";
3410
 
3415
            String response = restClient.get(url + "&loginid=" + loginId + "&awb=awb&numbers=" + String.join(",", airwayBillNo) + "&format=xml&lickey=" + licencekey + "&verno=1.3", null, null);
3411
            String response = restClient.get(url + "&loginid=" + loginId + "&awb=awb&numbers=" + String.join(",", airwayBillNo) + "&format=xml&lickey=" + licencekey + "&verno=1.3&scan=1", null, null);
3416
            LOGGER.info("API Response: " + response);
-
 
-
 
3412
 
3417
            JSONObject updateJson = XML.toJSONObject(response);
3413
            JSONObject updateJson = XML.toJSONObject(response);
3418
 
3414
 
3419
            JSONObject shipmentData = updateJson.getJSONObject("ShipmentData");
3415
            JSONObject shipmentData = updateJson.getJSONObject("ShipmentData");
3420
            Object shipmentObject = shipmentData.get("Shipment");
3416
            Object shipmentObject = shipmentData.get("Shipment");
3421
 
3417
 
Line 3430... Line 3426...
3430
                    String status = jsonObject.getString("Status");
3426
                    String status = jsonObject.getString("Status");
3431
 
3427
 
3432
                    if (status.equals("SHIPMENT DELIVERED")) {
3428
                    if (status.equals("SHIPMENT DELIVERED")) {
3433
                        airwaybillStatus.add(awb.toString());
3429
                        airwaybillStatus.add(awb.toString());
3434
                    }
3430
                    }
3435
                    System.out.println("AWB: " + awb + ", Status: " + status);
-
 
3436
 
3431
 
3437
                }
3432
                }
3438
            } else {
3433
            } else {
3439
                JSONObject jsonObject = (JSONObject) shipmentObject;
3434
                JSONObject jsonObject = (JSONObject) shipmentObject;
3440
                Number awb = jsonObject.getNumber("WaybillNo");
3435
                Number awb = jsonObject.getNumber("WaybillNo");
3441
                String status = jsonObject.getString("Status");
3436
                String status = jsonObject.getString("Status");
3442
 
3437
 
3443
                if (status.equals("SHIPMENT DELIVERED")) {
3438
                if (status.equals("SHIPMENT DELIVERED")) {
3444
                    airwaybillStatus.add(awb.toString());
3439
                    airwaybillStatus.add(awb.toString());
3445
                }
3440
                }
3446
                System.out.println("AWB: " + awb + ", Status: " + status);
-
 
3447
 
3441
 
3448
            }
3442
            }
3449
 
3443
 
3450
            LOGGER.info("airwaybillStatus" + airwaybillStatus);
3444
            LOGGER.info("airwaybillStatus" + airwaybillStatus);
3451
 
3445
 
Line 3552... Line 3546...
3552
    }
3546
    }
3553
 
3547
 
3554
    @Autowired
3548
    @Autowired
3555
    private PartnerCollectionRemarkRepository partnerCollectionRemarkRepository;
3549
    private PartnerCollectionRemarkRepository partnerCollectionRemarkRepository;
3556
 
3550
 
3557
    //RBM L2 Escalations
-
 
3558
    public void reviewUncontactablePartner() throws
3551
    public void reviewUncontactablePartner() throws
3559
            ProfitMandiBusinessException, MessagingException, UnsupportedEncodingException {
3552
            ProfitMandiBusinessException, MessagingException, UnsupportedEncodingException {
3560
 
3553
 
3561
        Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
3554
        Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
3562
 
3555
 
3563
        List<Integer> partnerLastCollectionRemarkIds = partnerCollectionRemarkRepository.selectMaxRemarkId(new ArrayList<>(customRetailerMap.keySet()));
3556
        List<Integer> pcrms = partnerCollectionRemarkRepository.selectMaxRemarkId(new ArrayList<>(customRetailerMap.keySet()));
3564
 
-
 
3565
        if (!partnerLastCollectionRemarkIds.isEmpty()) {
-
 
3566
            List<PartnerCollectionRemark> partnerCollectionRemarks = partnerCollectionRemarkRepository.selectByIds(partnerLastCollectionRemarkIds);
-
 
3567
 
-
 
3568
            Map<Integer, PartnerCollectionRemark> rbmEscalatedRemarksMap = partnerCollectionRemarks.stream().filter(x -> x.getRemark().equals(CollectionRemark.COLLECTION_PLAN)).collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
-
 
3569
            Map<Integer, PartnerCollectionRemark> salesEscalatedRemarksMap = partnerCollectionRemarks.stream().filter(x -> x.getRemark().equals(CollectionRemark.SALES_ESCALATION)).collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
-
 
3570
 
-
 
3571
 
-
 
3572
            if (!rbmEscalatedRemarksMap.isEmpty()) {
-
 
3573
                //
-
 
3574
                for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMappingByCategoryIds(Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_RBM), true).entrySet()) {
-
 
3575
                    List<PartnerCollectionRemark> filteredRows = storeGuyEntry.getValue().stream()
-
 
3576
                            .map(x -> rbmEscalatedRemarksMap.get(x)).filter(x -> x != null).collect(Collectors.toList());
-
 
3577
                    String subject = "Partners escalated to RBM-L2";
-
 
3578
                    String messageText = this.getMessageForRBMEscalatedPartners(filteredRows);
-
 
3579
 
-
 
3580
                    MimeMessage message = mailSender.createMimeMessage();
-
 
3581
                    MimeMessageHelper helper = new MimeMessageHelper(message, true);
-
 
3582
                    String[] email = new String[]{storeGuyEntry.getKey()};
-
 
3583
 
-
 
3584
                    helper.setSubject(subject);
-
 
3585
                    helper.setText(messageText, true);
-
 
3586
                    helper.setTo(email);
-
 
3587
                    InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
-
 
3588
                    helper.setFrom(senderAddress);
-
 
3589
                    mailSender.send(message);
-
 
3590
 
3557
 
-
 
3558
        if (!pcrms.isEmpty()) {
3591
                    LOGGER.info("filteredRows {}", filteredRows);
3559
            Map<Integer, PartnerCollectionRemark> partnerCollectionRemarksMap = partnerCollectionRemarkRepository.selectByIds(pcrms).stream().filter(x -> x.getRemark().equals(CollectionRemark.NOT_RESPONDING)).collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
3592
 
3560
 
3593
                }
-
 
3594
            }
-
 
3595
            if (!salesEscalatedRemarksMap.isEmpty()) {
3561
            if (!partnerCollectionRemarksMap.isEmpty()) {
3596
                //
-
 
3597
                for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMappingByCategoryIds(Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_SALES, ProfitMandiConstants.TICKET_CATEGORY_RBM), true).entrySet()) {
3562
                for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMapping().entrySet()) {
3598
                    List<PartnerCollectionRemark> filteredRows = storeGuyEntry.getValue().stream()
-
 
3599
                            .map(x -> salesEscalatedRemarksMap.get(x)).filter(x -> x != null).collect(Collectors.toList());
3563
                    List<PartnerCollectionRemark> filteredRows = storeGuyEntry.getValue().stream().map(x -> partnerCollectionRemarksMap.get(x)).filter(x -> x != null).collect(Collectors.toList());
3600
                    String subject = "Partners escalated to Sales";
3564
                    String subject = "UNCONTACTABLE PARTNERS";
3601
                    String messageText = this.getMessageForSalesEscalatedPartners(filteredRows);
3565
                    String messageText = this.getMessageForUncontacblePartner(filteredRows);
3602
 
3566
 
3603
                    MimeMessage message = mailSender.createMimeMessage();
3567
                    MimeMessage message = mailSender.createMimeMessage();
3604
                    MimeMessageHelper helper = new MimeMessageHelper(message, true);
3568
                    MimeMessageHelper helper = new MimeMessageHelper(message, true);
3605
                    String[] email = new String[]{storeGuyEntry.getKey()};
3569
                    String[] email = new String[]{storeGuyEntry.getKey()};
3606
 
3570
 
Line 4715... Line 4679...
4715
            vendorCatalogPricingService.createVendorCatalogPricing(vendorCatalogPricingLog);
4679
            vendorCatalogPricingService.createVendorCatalogPricing(vendorCatalogPricingLog);
4716
        }
4680
        }
4717
 
4681
 
4718
    }
4682
    }
4719
 
4683
 
-
 
4684
    public void sendMailWhatsAppAfterLoanDueDate() throws Exception {
-
 
4685
        sdCreditService.updateRisk();
-
 
4686
        List<Loan> defaultLoans = sdCreditService.getLoanALert();
-
 
4687
        if (!defaultLoans.isEmpty()) {
-
 
4688
            this.sendLoanAlert(defaultLoans);
-
 
4689
        }
-
 
4690
 
-
 
4691
 
-
 
4692
    }
-
 
4693
 
-
 
4694
    public void sendLoanAlert(List<Loan> defaultLoans) throws
-
 
4695
            Exception {
-
 
4696
        String subject = "Default Partners";
-
 
4697
 
-
 
4698
        List<Integer> categoryIds = Arrays.asList(
-
 
4699
                ProfitMandiConstants.TICKET_CATEGORY_CATEGORY,
-
 
4700
                ProfitMandiConstants.TICKET_CATEGORY_RBM,
-
 
4701
                ProfitMandiConstants.TICKET_CATEGORY_SALES,
-
 
4702
                ProfitMandiConstants.TICKET_CATEGORY_ACCOUNTS,
-
 
4703
                ProfitMandiConstants.TICKET_CATEGORY_BUSINESSINTELLIGENT);
-
 
4704
 
-
 
4705
        /*for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMappingByCategoryIds(categoryIds, false).entrySet()) {
-
 
4706
            List<Loan> filteredRows = defaultLoans.stream()
-
 
4707
                    .filter(loan -> storeGuyEntry.getValue().contains(loan.getFofoId()))
-
 
4708
                    .collect(Collectors.toList());
-
 
4709
 
-
 
4710
            if (!filteredRows.isEmpty()) {
-
 
4711
                for (Loan defaultLoan : filteredRows) {
-
 
4712
                    List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(defaultLoan.getId());
-
 
4713
                    double amount = loanStatements.stream().map(LoanStatement::getAmount).collect(Collectors.summingDouble(BigDecimal::doubleValue));
-
 
4714
                    String messageText = getMessageForDueDateExtend(defaultLoan,amount);
-
 
4715
                   // String[] email = new String[]{storeGuyEntry.getKey()};
-
 
4716
                    String[] email = {"ranu.rajput@smartdukaan.com"};
-
 
4717
                    sendMailOfHtmlFormat(mailSender, email, messageText, null, subject);
-
 
4718
 
-
 
4719
                }
-
 
4720
            }
-
 
4721
        }*/
-
 
4722
 
-
 
4723
        for (Loan defaultLoan : defaultLoans) {
-
 
4724
            List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(defaultLoan.getId());
-
 
4725
 
-
 
4726
            double amount = loanStatements.stream().map(LoanStatement::getAmount).collect(Collectors.summingDouble(BigDecimal::doubleValue));
-
 
4727
 
-
 
4728
            com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(defaultLoan.getFofoId());
-
 
4729
 
-
 
4730
            Address address = addressRepository.selectById(user.getAddressId());
-
 
4731
 
-
 
4732
            String title = "Alert!";
-
 
4733
            String url = "http://app.smartdukaan.com/pages/home/credit";
-
 
4734
 
-
 
4735
            String message = getMessageForDueDateExtend(defaultLoan,amount);
-
 
4736
            String whatsAppMessage = getWhatsAppMessageForDueDateExtend(defaultLoan,amount);
-
 
4737
            notificationService.sendWhatsappMessage(whatsAppMessage, title, address.getPhoneNumber());
-
 
4738
            String[] email = {user.getEmailId()};
-
 
4739
            sendMailOfHtmlFormat(mailSender, email, message, null, "Loan Alert - SmartDukaan");
-
 
4740
        }
-
 
4741
    }
-
 
4742
 
-
 
4743
    private String getMessageForDueDateExtend(Loan defaultLoan, double amount) throws ProfitMandiBusinessException {
-
 
4744
 
-
 
4745
        double absoluteAmount = Math.abs(amount);
-
 
4746
        long roundedAmount = Math.round(absoluteAmount);
-
 
4747
        String formattedAmount = (amount < 0) ? "" + roundedAmount : "" + roundedAmount;
-
 
4748
 
-
 
4749
        LocalDate dueDate = defaultLoan.getDueDate().toLocalDate();
-
 
4750
        LocalDate defaultDate = defaultLoan.getDueDate().toLocalDate().plusDays(15);
-
 
4751
 
-
 
4752
        // Retrieve the name of the user associated with the loan
-
 
4753
        String name = userUserRepository.selectById(defaultLoan.getFofoId()).getName();
-
 
4754
 
-
 
4755
        // Initialize a StringBuilder to construct the HTML message
-
 
4756
        StringBuilder sb = new StringBuilder();
-
 
4757
 
-
 
4758
        if(LocalDate.now().isBefore(dueDate)){
-
 
4759
            long noOfdaysBetween = ChronoUnit.DAYS.between(LocalDate.now() , defaultLoan.getDueDate().toLocalDate());
-
 
4760
            String payDate = defaultLoan.getDueDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"));
-
 
4761
            // 5 Days Before Due Date - daily
-
 
4762
            if (noOfdaysBetween <= 5) {
-
 
4763
                sb.append("<html><body><p><b>Loan Repayment Alert !</b></p></br><p>Dear " + name + "</p>");
-
 
4764
                sb.append("<p>This is a friendly reminder that your loan payment is due in " + noOfdaysBetween + "days, on " +
-
 
4765
                        payDate +
-
 
4766
                        ". Please ensure that the payment is made on time to avoid any late fees or penalties.</p>");
-
 
4767
                sb.append("<p>As per the terms of your loan agreement, the total amount due is Rs. " + formattedAmount + ". " +
-
 
4768
                        "You can make the payment by adding money to your wallet. If you have any questions or need assistance, " +
-
 
4769
                        "our customer service team is available to help you.</p>");
-
 
4770
                sb.append("<p>Thank you for your cooperation and prompt attention to this matter.</p></br><p> Smart Dukaan Team !!</p>");
-
 
4771
            }
-
 
4772
        }else if(LocalDate.now().isBefore(defaultDate)){
-
 
4773
            long noOfdaysBetween = ChronoUnit.DAYS.between(defaultDate, LocalDate.now());
-
 
4774
 
-
 
4775
            // After Due Date – Alternate days
-
 
4776
            if ((noOfdaysBetween % 2 == 0) && (noOfdaysBetween > 5)) {
-
 
4777
                sb.append("<html><body><p><b>Loan Repayment Alert !</b></p></br><p>Dear " + name + "</p>");
-
 
4778
                sb.append("<p>We would like to remind you that your payment for the outstanding balance on your account is now overdue. " +
-
 
4779
                        "As per our terms and conditions, a higher interest rate will be levied on the overdue amount Rs. " + formattedAmount + ".</p>");
-
 
4780
                sb.append("<p>To avoid further charges and any negative impact on your CIBIL score, we kindly request that you settle the " +
-
 
4781
                        "outstanding balance as soon as possible.</p>");
-
 
4782
                sb.append("<p>Thank you for your attention to this matter.</p></br><p> Smart Dukaan Team !!</p>");
-
 
4783
            }
-
 
4784
            // 5 Days before default - daily
-
 
4785
            if (noOfdaysBetween <= 5 ) {
-
 
4786
                sb.append("<html><body><p><b>Loan Repayment Alert !</b></p></br>");
-
 
4787
                sb.append("<p>Attention: High Alert</p>");
-
 
4788
                sb.append("<p>Dear " + name + "</p>");
-
 
4789
                sb.append("<p>This is to inform you that the due date for your payment of Rs. " + formattedAmount + " has been crossed, " +
-
 
4790
                        "and you are approaching the default date on " + defaultDate.format(DateTimeFormatter.ofPattern("dd-MM-yyyy")) + ". " +
-
 
4791
                        "Please be aware that this will have a significant impact on your CIBIL score and may result in substantial penalties as well.</p>");
-
 
4792
                sb.append("<p>To rectify this situation, it is imperative that you take immediate action. " +
-
 
4793
                        "Please make the necessary payment immediately to avoid further consequences.</p>");
-
 
4794
                sb.append("<p>Thank you for your attention to this matter.</p></br><p> Smart Dukaan Team !!</p>");
-
 
4795
            }
-
 
4796
        }else{
-
 
4797
            // Post Default - Daily
-
 
4798
                sb.append("<html><body><p><b>Loan Repayment Alert !</b></p></br><p>Dear " + name + "</p>");
-
 
4799
                sb.append("<p>We regret to inform you that you are currently in loan default. As a result, " +
-
 
4800
                        "higher penalties are being charged, which is also negatively impacting your CIBIL score. " +
-
 
4801
                        "It is imperative that you make an immediate payment to rectify this situation.</p>");
-
 
4802
                sb.append("<p>Please note that failing to make the payment promptly will result in further consequences, " +
-
 
4803
                        "including potential legal action and additional financial penalties. " +
-
 
4804
                        "We strongly urge you to take this matter seriously and settle the outstanding amount as soon as possible.</p>");
-
 
4805
                sb.append("<p>To make the payment, please add Rs. " + formattedAmount + " to your wallet. We are here to help you resolve this issue and get back on track.</p>");
-
 
4806
                sb.append("<p>Thank you for your attention to this matter.</p></br><p> Smart Dukaan Team !!</p>");
-
 
4807
 
-
 
4808
        }
-
 
4809
 
-
 
4810
        // Return the constructed HTML message
-
 
4811
        sb.append("</body></html>");
-
 
4812
        return sb.toString();
-
 
4813
    }
-
 
4814
 
-
 
4815
    private String getWhatsAppMessageForDueDateExtend(Loan defaultLoan, double amount) throws ProfitMandiBusinessException {
-
 
4816
 
-
 
4817
        double absoluteAmount = Math.abs(amount);
-
 
4818
        long roundedAmount = Math.round(absoluteAmount);
-
 
4819
        String formattedAmount = (amount < 0) ? "" + roundedAmount : "" + roundedAmount;
-
 
4820
 
-
 
4821
        LocalDate dueDate = defaultLoan.getDueDate().toLocalDate();
-
 
4822
        LocalDate defaultDate = defaultLoan.getDueDate().toLocalDate().plusDays(15);
-
 
4823
 
-
 
4824
        // Retrieve the name of the user associated with the loan
-
 
4825
        String name = userUserRepository.selectById(defaultLoan.getFofoId()).getName();
-
 
4826
 
-
 
4827
        // Initialize a StringBuilder to construct the HTML message
-
 
4828
        String message = null;
-
 
4829
 
-
 
4830
        if(LocalDate.now().isBefore(dueDate)){
-
 
4831
            long noOfdaysBetween = ChronoUnit.DAYS.between(LocalDate.now(), defaultLoan.getDueDate().toLocalDate());
-
 
4832
            String payDate = defaultLoan.getDueDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"));
-
 
4833
            // 5 Days Before Due Date - daily
-
 
4834
            if (noOfdaysBetween <= 5) {
-
 
4835
 
-
 
4836
                message = "Dear %s, This is a friendly reminder that your loan payment is due in %d days, on %s.\n" +
-
 
4837
                        "\n" +
-
 
4838
                        "Please ensure that the payment is made on time to avoid any late fees or penalties.As per the terms of your loan agreement, the total amount due is Rs. %s. You can make the payment by adding money to wallet.\n" +
-
 
4839
                        "\n" +
-
 
4840
                        "If you have any questions or need assistance, our customer service team is available to help you.\n" +
-
 
4841
                        "Thank you for your cooperation and prompt attention to this matter.\n" +
-
 
4842
                        "\n" +
-
 
4843
                        "Team SmartDukaan";
-
 
4844
                message = String.format(message, name, noOfdaysBetween, payDate,formattedAmount);
-
 
4845
                  }
-
 
4846
        }else if(LocalDate.now().isBefore(defaultDate)){
-
 
4847
            long noOfdaysBetween = ChronoUnit.DAYS.between(defaultDate, LocalDate.now());
-
 
4848
            // After Due Date – Alternate days
-
 
4849
            if ((noOfdaysBetween % 2 == 0) && (noOfdaysBetween > 5)) {
-
 
4850
                message = "Dear %s, We would like to remind you that your payment for the outstanding balance on your account is now overdue. \n" +
-
 
4851
                        "As per our terms and conditions, a higher interest rate will be levied on the overdue amount Rs.%s.\n" +
-
 
4852
                        "To avoid further charges and any negative impact on your CIBIL score, we kindly request that you settle the outstanding balance as soon as possible.\n" +
-
 
4853
                        "Thank you for your attention to this matter. \n" +
-
 
4854
                        "\n" +
-
 
4855
                        "Team SmartDukaan";
-
 
4856
                message = String.format(message, name, formattedAmount);
-
 
4857
            }
-
 
4858
            // 5 Days before default - daily
-
 
4859
            if (noOfdaysBetween <= 5 ) {
-
 
4860
                String defaultPayDate = defaultDate.format(DateTimeFormatter.ofPattern("dd-MM-yyyy"));
-
 
4861
                message = "Attention: High Alert!! Dear %s, \n" +
-
 
4862
                        "\n" +
-
 
4863
                        "This is to inform you that the due date for your payment of Rs. %s has been crossed, and as a result, you are now about to reach default date %s.\n" +
-
 
4864
                        "Please be aware that this will have a significant impact on your CIBIL score and may result in substantial penalties as well. To rectify this situation, it is imperative that you take immediate action.\n" +
-
 
4865
                        "\n" +
-
 
4866
                        "Please make the necessary payment immediately to avoid further consequences. Thank you for your attention to this matter.\n" +
-
 
4867
                        "\n" +
-
 
4868
                        "Team SmartDukaan";
-
 
4869
                message = String.format(message, name, formattedAmount, defaultPayDate);
-
 
4870
            }
-
 
4871
        }else {
-
 
4872
            // Post Default - Daily
-
 
4873
            message = "Dear %s, We regret to inform you that you are currently in loan default. As a result, higher penalties are being charged, which is also negatively impacting your CIBIL score. \n" +
-
 
4874
                    "\n" +
-
 
4875
                    "It is imperative that you make an immediate payment to rectify this situation. \n" +
-
 
4876
                    "\n" +
-
 
4877
                    "Please note that failing to make the payment promptly will result in further consequences, including potential legal action and additional financial penalties. \n" +
-
 
4878
                    "\n" +
-
 
4879
                    "We strongly urge you to take this matter seriously and settle the outstanding amount as soon as possible. \n" +
-
 
4880
                    "\n" +
-
 
4881
                    "To make the payment, please add Rs. %s  to wallet. We are here to help you resolve this issue and get back on track. Thank you for your attention to this matter. \n" +
-
 
4882
                    "\n" +
-
 
4883
                    "Team SmartDukaan";
-
 
4884
            message = String.format(message, name, formattedAmount);
-
 
4885
 
-
 
4886
        }
-
 
4887
        // Return the constructed HTML message
-
 
4888
        return message;
-
 
4889
    }
4720
 
4890
 
4721
}
4891
}
4722
// 2284'
4892
// 2284'
4723
4893