Subversion Repositories SmartDukaan

Rev

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

Rev 30934 Rev 30936
Line 107... Line 107...
107
import javax.mail.MessagingException;
107
import javax.mail.MessagingException;
108
import javax.mail.internet.InternetAddress;
108
import javax.mail.internet.InternetAddress;
109
import javax.mail.internet.MimeMessage;
109
import javax.mail.internet.MimeMessage;
110
import java.io.*;
110
import java.io.*;
111
import java.math.BigDecimal;
111
import java.math.BigDecimal;
-
 
112
import java.math.RoundingMode;
112
import java.nio.file.Files;
113
import java.nio.file.Files;
113
import java.nio.file.Paths;
114
import java.nio.file.Paths;
114
import java.sql.Timestamp;
115
import java.sql.Timestamp;
-
 
116
import java.text.DecimalFormat;
115
import java.time.*;
117
import java.time.*;
116
import java.time.format.DateTimeFormatter;
118
import java.time.format.DateTimeFormatter;
117
import java.time.temporal.ChronoField;
119
import java.time.temporal.ChronoField;
118
import java.time.temporal.ChronoUnit;
120
import java.time.temporal.ChronoUnit;
119
import java.util.*;
121
import java.util.*;
Line 3351... Line 3353...
3351
	private SDCreditService sdCreditService;
3353
	private SDCreditService sdCreditService;
3352
 
3354
 
3353
	@Autowired
3355
	@Autowired
3354
	private SDCreditRequirementRepository sdCreditRequirementRepository;
3356
	private SDCreditRequirementRepository sdCreditRequirementRepository;
3355
 
3357
 
-
 
3358
	@Autowired
-
 
3359
	private CurrentPartnerDailyInvestmentRepository currentPartnerDailyInvestmentRepository;
-
 
3360
 
-
 
3361
	@Autowired
-
 
3362
	private TransactionRepository transactionRepository;
-
 
3363
 
-
 
3364
	@Autowired
-
 
3365
	private CreditAccountRepository crediRepository;
-
 
3366
 
3356
	public void calculateInterestAccured() throws ProfitMandiBusinessException {
3367
	public void calculateInterestAccured() throws ProfitMandiBusinessException {
3357
 
3368
 
3358
		List<Loan> loans = loanRepository.selectAllActiveLoan();
3369
		List<Loan> loans = loanRepository.selectAllActiveLoan();
3359
 
3370
 
3360
		if (!loans.isEmpty()) {
3371
		if (!loans.isEmpty()) {
Line 3366... Line 3377...
3366
				Map<LoanReferenceType, Double> loanStatusAmount = loanStatements.stream().collect(Collectors.groupingBy(
3377
				Map<LoanReferenceType, Double> loanStatusAmount = loanStatements.stream().collect(Collectors.groupingBy(
3367
						x -> x.getLoanReferenceType(), Collectors.summingDouble(x -> x.getAmount().doubleValue())));
3378
						x -> x.getLoanReferenceType(), Collectors.summingDouble(x -> x.getAmount().doubleValue())));
3368
 
3379
 
3369
				if (loan.getFreeDays() > 0) {
3380
				if (loan.getFreeDays() > 0) {
3370
					LocalDateTime freeDaysLimitDate = loan.getCreatedOn().plusDays(loan.getFreeDays() - 1);
3381
					LocalDateTime freeDaysLimitDate = loan.getCreatedOn().plusDays(loan.getFreeDays() - 1);
-
 
3382
 
-
 
3383
					LOGGER.info("freeDaysLimitDate {}", freeDaysLimitDate);
3371
					if (LocalDateTime.now().isAfter(freeDaysLimitDate)) {
3384
					if (LocalDateTime.now().isAfter(freeDaysLimitDate)) {
-
 
3385
						int loanStatementId = loanStatementRepository.selectLatestLoanSatement(loan.getFofoId(),
-
 
3386
								loan.getId());
-
 
3387
						LOGGER.info("loanStatementId {}", loanStatementId);
-
 
3388
 
-
 
3389
						if (loanStatementId != 0) {
-
 
3390
 
-
 
3391
							this.calculateInterest(loan, loanStatusAmount, loanStatementId);
-
 
3392
 
-
 
3393
						} else {
3372
						sdCreditService.calculateInterest(freeDaysLimitDate.toLocalDate(), LocalDate.now(), loan,
3394
							sdCreditService.addInterest(freeDaysLimitDate.toLocalDate(), LocalDate.now(), loan,
3373
								loanStatusAmount);
3395
									loanStatusAmount);
-
 
3396
						}
3374
 
3397
 
3375
					}
3398
					}
3376
				} else {
3399
				} else {
3377
 
3400
 
3378
					int loanStatementId = loanStatementRepository.selectLatestLoanSatement(loan.getFofoId(),
3401
					int loanStatementId = loanStatementRepository.selectLatestLoanSatement(loan.getFofoId(),
3379
							loan.getId());
3402
							loan.getId());
3380
					LOGGER.info("loanStatementId {}", loanStatementId);
3403
					LOGGER.info("loanStatementId2 {}", loanStatementId);
3381
					LoanStatement loanStatement = loanStatementRepository.selectById(loanStatementId);
-
 
3382
					if (loanStatement.getLoanId() == loan.getId()) {
-
 
3383
 
3404
 
3384
						sdCreditService.calculateInterest(loanStatement.getCreatedAt().toLocalDate(), LocalDate.now(),
3405
					this.calculateInterest(loan, loanStatusAmount, loanStatementId);
3385
								loan, loanStatusAmount);
-
 
3386
 
-
 
3387
					} else {
-
 
3388
						throw new ProfitMandiBusinessException("loanstament", loanStatement.getLoanId(),
-
 
3389
								"Invalid LoanId");
-
 
3390
					}
-
 
3391
 
3406
 
3392
				}
3407
				}
3393
 
3408
 
3394
			}
3409
			}
3395
		}
3410
		}
3396
 
3411
 
3397
	}
3412
	}
3398
 
3413
 
-
 
3414
	private void calculateInterest(Loan loan, Map<LoanReferenceType, Double> loanStatusAmount, int loanStatementId)
-
 
3415
			throws ProfitMandiBusinessException {
-
 
3416
		LoanStatement loanStatement = loanStatementRepository.selectById(loanStatementId);
-
 
3417
 
-
 
3418
		if (loanStatement.getLoanId() == loan.getId()) {
-
 
3419
 
-
 
3420
			sdCreditService.addInterest(loanStatement.getCreatedAt().toLocalDate(), LocalDate.now(), loan,
-
 
3421
					loanStatusAmount);
-
 
3422
 
-
 
3423
		} else {
-
 
3424
			throw new ProfitMandiBusinessException("loanstament", loanStatement.getLoanId(), "Invalid LoanId");
-
 
3425
		}
-
 
3426
	}
-
 
3427
 
3399
	public void loanSettlement() throws ProfitMandiBusinessException {
3428
	public void loanSettlement() throws ProfitMandiBusinessException {
3400
		List<Loan> loans = loanRepository.selectAllActiveLoan();
3429
		List<Loan> loans = loanRepository.selectAllActiveLoan();
3401
 
3430
 
3402
		if (!loans.isEmpty()) {
3431
		if (!loans.isEmpty()) {
3403
 
3432
 
Line 3562... Line 3591...
3562
 
3591
 
3563
	public void processActivatedImeisForSchemes() throws ProfitMandiBusinessException {
3592
	public void processActivatedImeisForSchemes() throws ProfitMandiBusinessException {
3564
		schemeService.processActivatedImeisForSchemes();
3593
		schemeService.processActivatedImeisForSchemes();
3565
	}
3594
	}
3566
 
3595
 
3567
	@Autowired
-
 
3568
	private CurrentPartnerDailyInvestmentRepository currentPartnerDailyInvestmentRepository;
-
 
3569
 
-
 
3570
	@Autowired
-
 
3571
	private TransactionRepository transactionRepository;
-
 
3572
 
-
 
3573
	@Autowired
-
 
3574
	private CreditAccountRepository crediRepository;
-
 
3575
 
-
 
3576
	public void updatePartnerLimit() throws ProfitMandiBusinessException {
3596
	public void updatePartnerLimit() throws ProfitMandiBusinessException {
3577
		Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
3597
		Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
3578
 
3598
 
3579
		Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream()
3599
		Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream()
3580
				.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
3600
				.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
Line 3616... Line 3636...
3616
				sdCreditRequirement.setCreateTimestamp(LocalDateTime.now());
3636
				sdCreditRequirement.setCreateTimestamp(LocalDateTime.now());
3617
				sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
3637
				sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
3618
				sdCreditRequirementRepository.persist(sdCreditRequirement);
3638
				sdCreditRequirementRepository.persist(sdCreditRequirement);
3619
			}
3639
			}
3620
 
3640
 
3621
			CreditRisk creditRisk = getCurrentRisk(sdCreditRequirement, firstBillingDate);
3641
			CreditRisk creditRisk = sdCreditService.getCurrentRisk(sdCreditRequirement, firstBillingDate);
3622
 
3642
 
3623
			sdCreditRequirement.setRisk(creditRisk);
3643
			sdCreditRequirement.setRisk(creditRisk);
3624
 
3644
 
3625
			sdCreditRequirement.setSuggestedLimit(suggestedAmount);
3645
			sdCreditRequirement.setSuggestedLimit(suggestedAmount);
3626
			sdCreditRequirement.setLimit(suggestedAmount);
3646
			sdCreditRequirement.setLimit(suggestedAmount);
Line 3660... Line 3680...
3660
 
3680
 
3661
		}
3681
		}
3662
 
3682
 
3663
	}
3683
	}
3664
 
3684
 
3665
	private static final List<CreditRisk> ORDERED_RISKS = Arrays.asList(CreditRisk.HIGH_RISK, CreditRisk.LOW_RISK,
-
 
3666
			CreditRisk.NO_RISK);
-
 
3667
 
-
 
3668
	private CreditRisk getCurrentRisk(SDCreditRequirement sdCreditRequirement, LocalDateTime firstBillingDate) {
3685
	public void notifyDefaultLoans() throws ProfitMandiBusinessException, MessagingException, IOException {
3669
		CreditRisk currentRisk = sdCreditRequirement.getRisk();
-
 
3670
		long noOfDaysBetween = 0;
-
 
3671
		LocalDateTime riskDate = sdCreditRequirement.getRiskTimestamp() == null ? firstBillingDate
-
 
3672
				: sdCreditRequirement.getRiskTimestamp();
-
 
3673
		if (riskDate == null) {
-
 
3674
			return CreditRisk.HIGH_RISK;
-
 
3675
		} else {
-
 
3676
			noOfDaysBetween = ChronoUnit.DAYS.between(riskDate, LocalDateTime.now());
-
 
3677
			if (noOfDaysBetween < 90) {
-
 
3678
				return currentRisk;
-
 
3679
			} else if (noOfDaysBetween >= 90 && noOfDaysBetween < 180) {
-
 
3680
				return currentRisk.decrease();
-
 
3681
			} else {
-
 
3682
				return currentRisk.decrease();
-
 
3683
			}
-
 
3684
 
3686
 
-
 
3687
		sdCreditService.updateRisk();
-
 
3688
		List<Loan> defaultLoans = sdCreditService.getDefaultLoan();
-
 
3689
		if (!defaultLoans.isEmpty()) {
-
 
3690
			this.sendDefaultLoanAlert(defaultLoans);
3685
		}
3691
		}
3686
 
3692
 
3687
	}
3693
	}
3688
 
3694
 
3689
	public void setDefaultPartnersRisk()
3695
	public void sendDefaultLoanAlert(List<Loan> defaultLoans)
3690
			throws ProfitMandiBusinessException, MessagingException, UnsupportedEncodingException {
3696
			throws ProfitMandiBusinessException, MessagingException, IOException {
3691
 
-
 
3692
		List<Loan> loans = loanRepository.selectAllActiveLoan().stream()
3697
		String subject = "Default Partners";
3693
				.filter(x -> x.getDueDate().isBefore(LocalDateTime.now())).collect(Collectors.toList());
-
 
3694
 
3698
 
3695
		List<Loan> defaulterLoan = new ArrayList<>();
3699
		List<AuthUser> authUsers = csService
-
 
3700
				.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_FINANCIAL_SERVICES);
-
 
3701
		if (!authUsers.isEmpty()) {
-
 
3702
			List<String> financeEmails = authUsers.stream().map(x -> x.getEmailId()).collect(Collectors.toList());
-
 
3703
			String messageText = this.getMessageForDueDateExtend(defaultLoans);
3696
 
3704
 
3697
		if (!loans.isEmpty()) {
-
 
3698
			for (Loan loan : loans) {
3705
			String[] email = financeEmails.toArray(new String[financeEmails.size()]);
3699
 
3706
 
3700
				SDCreditRequirement sdCreditRequirement = sdCreditRequirementRepository
3707
			this.sendMailHtmlFormat(email, messageText, null, subject);
3701
						.selectByFofoId(loan.getFofoId());
-
 
3702
				long noOfdaysBetween = ChronoUnit.DAYS.between(loan.getDueDate().toLocalDate(), LocalDateTime.now());
-
 
3703
 
3708
 
3704
				LOGGER.info("noOfdaysBetween {} ", noOfdaysBetween);
-
 
3705
 
3709
		}
3706
				if (noOfdaysBetween > 30) {
-
 
3707
					CreditAccount creditAccount = crediRepository.selectByFofoIdAndGateway(loan.getFofoId(),
-
 
3708
							Gateway.SDDIRECT);
-
 
3709
					creditAccount.setActive(false);
-
 
3710
					sdCreditRequirement.setRisk(CreditRisk.HIGH_RISK);
-
 
3711
					sdCreditRequirement.setRiskTimestamp(LocalDateTime.now());
-
 
3712
 
3710
 
-
 
3711
		for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMapping().entrySet()) {
-
 
3712
			List<Loan> filteredRows = new ArrayList<>();
3713
					defaulterLoan.add(loan);
3713
			for (Loan loan : defaultLoans) {
3714
 
3714
 
3715
				} else {
3715
				if (storeGuyEntry.getValue().contains(loan.getFofoId())) {
3716
 
3716
 
-
 
3717
					filteredRows.add(loan);
-
 
3718
				}
-
 
3719
			}
-
 
3720
			if (!filteredRows.isEmpty()) {
3717
					sdCreditRequirement.setRisk(sdCreditRequirement.getRisk().increase());
3721
				String messageText = this.getMessageForDueDateExtend(filteredRows);
-
 
3722
				String[] email = new String[] { storeGuyEntry.getKey() };
3718
 
3723
 
3719
					sdCreditRequirement.setRiskTimestamp(LocalDateTime.now());
3724
				this.sendMailHtmlFormat(email, messageText, null, subject);
3720
 
3725
 
3721
				}
-
 
3722
			}
3726
			}
-
 
3727
 
3723
		}
3728
		}
3724
 
3729
 
3725
		if (!defaulterLoan.isEmpty()) {
3730
		for (Loan defaultLoan : defaultLoans) {
-
 
3731
			List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(defaultLoan.getId());
3726
 
3732
 
3727
			List<AuthUser> authUsers = csService
-
 
3728
					.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_FINANCIAL_SERVICES);
-
 
3729
			List<String> allEmails = new ArrayList<>();
-
 
3730
			if (!authUsers.isEmpty()) {
-
 
3731
				List<String> financeEmails = authUsers.stream().map(x -> x.getEmailId()).collect(Collectors.toList());
3733
			double amount = loanStatements.stream().map(x -> x.getAmount())
3732
				allEmails.addAll(financeEmails);
3734
					.collect(Collectors.summingDouble(x -> x.doubleValue()));
3733
			}
-
 
3734
 
3735
 
3735
			for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMapping().entrySet()) {
-
 
3736
				allEmails.add(storeGuyEntry.getKey());
3736
			String title = "Loan amount overdue!";
3737
				String subject = "Time Limit Cross";
3737
			String url = "http://app.smartdukaan.com/pages/home/credit";
3738
				String messageText = this.getMessageForDueDateExtend(defaulterLoan);
3738
			String message = "Your loan due date ("
3739
 
-
 
3740
				MimeMessage message = mailSender.createMimeMessage();
3739
					+ defaultLoan.getDueDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))
3741
				MimeMessageHelper helper = new MimeMessageHelper(message, true);
3740
					+ ") has been exceeded. Additional penal interest of " + defaultLoan.getInterestRate()
3742
				String[] email = allEmails.toArray(new String[allEmails.size()]);
3741
					+ "%  + Rs.100 shall be levied on daily basis. " + "Your total pending Loan amount is Rs."
3743
 
-
 
3744
				helper.setSubject(subject);
-
 
3745
				helper.setText(messageText, true);
3742
					+ FormattingUtils.formatDecimal(Math.abs(amount)) + ". !!Pay Now!!";
3746
				helper.setTo(email);
-
 
3747
				InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
3743
			notificationService.sendNotification(defaultLoan.getFofoId(), title, MessageType.notification, title,
3748
				helper.setFrom(senderAddress);
-
 
3749
				mailSender.send(message);
3744
					message, url);
3750
 
3745
 
3751
			}
-
 
3752
		}
3746
		}
3753
 
-
 
3754
	}
3747
	}
3755
 
3748
 
3756
	private String getMessageForDueDateExtend(List<Loan> loans) throws ProfitMandiBusinessException {
3749
	private String getMessageForDueDateExtend(List<Loan> loans) throws ProfitMandiBusinessException {
3757
		StringBuilder sb = new StringBuilder();
3750
		StringBuilder sb = new StringBuilder();
-
 
3751
		sb.append(
3758
		sb.append("<html><body><p>Alert</p><p>Time Limit Cross :-</p>"
3752
				"<html><body><p>Alert</p><p>Default Partners :-</p>" + "<br/><p>EveryDay Rs.100 charged as Penalty</p>"
3759
				+ "<br/><table style='border:1px solid black ;padding: 5px';>");
3753
						+ "<br/><table style='border:1px solid black ;padding: 5px';>");
3760
		sb.append("<tbody>\n" + "	    				<tr>\n"
3754
		sb.append("<tbody>\n" + "	    				<tr>\n"
3761
				+ "	    					<th style='border:1px solid black;padding: 5px'>PartnerName</th>\n"
3755
				+ "	    					<th style='border:1px solid black;padding: 5px'>PartnerName</th>\n"
3762
				+ "	    					<th style='border:1px solid black;padding: 5px'>due date</th>\n"
3756
				+ "	    					<th style='border:1px solid black;padding: 5px'>due date</th>\n"
3763
				+ "	    					<th style='border:1px solid black;padding: 5px'>Days</th>\n"
3757
				+ "	    					<th style='border:1px solid black;padding: 5px'>Days</th>\n"
-
 
3758
				+ "	    					<th style='border:1px solid black;padding: 5px'>Pending Amount</th>\n"
3764
 
3759
 
3765
				+ "	    				</tr>");
3760
				+ "	    				</tr>");
3766
		for (Loan entry : loans) {
3761
		for (Loan entry : loans) {
-
 
3762
 
-
 
3763
			List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(entry.getId());
-
 
3764
 
-
 
3765
			double amount = loanStatements.stream().map(x -> x.getAmount())
-
 
3766
					.collect(Collectors.summingDouble(x -> x.doubleValue()));
-
 
3767
 
3767
			long noOfdaysBetween = ChronoUnit.DAYS.between(entry.getDueDate().toLocalDate(), LocalDateTime.now());
3768
			long noOfdaysBetween = ChronoUnit.DAYS.between(entry.getDueDate().toLocalDate(), LocalDateTime.now());
3768
 
3769
 
3769
			CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
3770
			CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
3770
 
3771
 
3771
			sb.append("<tr>");
3772
			sb.append("<tr>");
Line 3773... Line 3774...
3773
					+ customRetailer.getCode() + ")" + "</td>");
3774
					+ customRetailer.getCode() + ")" + "</td>");
3774
 
3775
 
3775
			sb.append("<td style='border:1px solid black;padding: 5px'>"
3776
			sb.append("<td style='border:1px solid black;padding: 5px'>"
3776
					+ entry.getDueDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
3777
					+ entry.getDueDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
3777
			sb.append("<td style='border:1px solid black;padding: 5px'>" + noOfdaysBetween + "</td>");
3778
			sb.append("<td style='border:1px solid black;padding: 5px'>" + noOfdaysBetween + "</td>");
-
 
3779
			sb.append("<td style='border:1px solid black;padding: 5px'>"
-
 
3780
					+ new DecimalFormat("#.##").format(Math.abs(amount)) + "</td>");
3778
 
3781
 
3779
			sb.append("</tr>");
3782
			sb.append("</tr>");
3780
 
3783
 
3781
		}
3784
		}
3782
 
3785
 
3783
		sb.append("</tbody></table></body></html>");
3786
		sb.append("</tbody></table></body></html>");
3784
 
3787
 
3785
		return sb.toString();
3788
		return sb.toString();
3786
	}
3789
	}
3787
 
3790
 
-
 
3791
	public void notifyLoanDueDateCross() throws ProfitMandiBusinessException, MessagingException, IOException {
-
 
3792
 
-
 
3793
		List<Loan> loans = loanRepository.selectAllActiveLoan().stream()
-
 
3794
				.filter(x -> x.getDueDate().isBefore(LocalDateTime.now())).collect(Collectors.toList());
-
 
3795
		if (!loans.isEmpty()) {
-
 
3796
			for (Loan loan : loans) {
-
 
3797
 
-
 
3798
				long noOfdaysBetween = ChronoUnit.DAYS.between(loan.getDueDate().toLocalDate(), LocalDate.now());
-
 
3799
 
-
 
3800
				LOGGER.info("noOfdaysBetween {} ", noOfdaysBetween);
-
 
3801
 
-
 
3802
				if (noOfdaysBetween <= 15 && noOfdaysBetween >= 0) {
-
 
3803
					List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
-
 
3804
 
-
 
3805
					double amount = loanStatements.stream().map(x -> x.getAmount())
-
 
3806
							.collect(Collectors.summingDouble(x -> x.doubleValue()));
-
 
3807
 
-
 
3808
					String title = "Alert! Credit o/s";
-
 
3809
					String url = "http://app.smartdukaan.com/pages/home/credit";
-
 
3810
					String message = "Your loan due date ("
-
 
3811
							+ loan.getDueDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))
-
 
3812
							+ ") has been exceeded. Additional penal interest of " + loan.getInterestRate()
-
 
3813
							+ "% shall be levied on daily basis. Your total pending Loan amount is Rs."
-
 
3814
							+ FormattingUtils.formatDecimal(Math.abs(amount)) + ". !!Pay Now!!";
-
 
3815
					notificationService.sendNotification(loan.getFofoId(), title, MessageType.notification, title,
-
 
3816
							message, url);
-
 
3817
				}
-
 
3818
			}
-
 
3819
		}
-
 
3820
 
-
 
3821
	}
-
 
3822
 
-
 
3823
	public void alertForDueDate() throws ProfitMandiBusinessException, MessagingException, IOException {
-
 
3824
 
-
 
3825
		List<Loan> loans = loanRepository.selectAllActiveLoan();
-
 
3826
 
-
 
3827
		if (!loans.isEmpty()) {
-
 
3828
			for (Loan loan : loans) {
-
 
3829
 
-
 
3830
				long noOfdaysBetween = ChronoUnit.DAYS.between(LocalDate.now(), loan.getDueDate().toLocalDate());
-
 
3831
 
-
 
3832
				LOGGER.info("noOfdaysBetween {} ", noOfdaysBetween);
-
 
3833
 
-
 
3834
				if (noOfdaysBetween <= 4 && noOfdaysBetween >= 0) {
-
 
3835
					List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
-
 
3836
					double amount = loanStatements.stream().map(x -> x.getAmount())
-
 
3837
							.collect(Collectors.summingDouble(x -> x.doubleValue()));
-
 
3838
 
-
 
3839
					String title = "Alert! Credit o/s";
-
 
3840
					String url = "http://app.smartdukaan.com/pages/home/credit";
-
 
3841
					String message = null;
-
 
3842
					if (noOfdaysBetween == 0) {
-
 
3843
 
-
 
3844
						message = "Your total pending Loan amount is Rs."
-
 
3845
								+ FormattingUtils.formatDecimal(Math.abs(amount)) + " is due for Today, Pay Now!!";
-
 
3846
 
-
 
3847
					} else {
-
 
3848
 
-
 
3849
						message = "Your total pending Loan amount is Rs."
-
 
3850
								+ FormattingUtils.formatDecimal(Math.abs(amount)) + " is due by "
-
 
3851
								+ loan.getDueDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))
-
 
3852
								+ ", Pay Now!!";
-
 
3853
 
-
 
3854
					}
-
 
3855
					notificationService.sendNotification(loan.getFofoId(), title, MessageType.notification, title,
-
 
3856
							message, url);
-
 
3857
				}
-
 
3858
			}
-
 
3859
		}
-
 
3860
 
-
 
3861
	}
-
 
3862
 
3788
}
3863
}
3789
 
3864
 
3790
//2284
3865
//2284
3791
3866