| Line 3568... |
Line 3568... |
| 3568 |
private CurrentPartnerDailyInvestmentRepository currentPartnerDailyInvestmentRepository;
|
3568 |
private CurrentPartnerDailyInvestmentRepository currentPartnerDailyInvestmentRepository;
|
| 3569 |
|
3569 |
|
| 3570 |
@Autowired
|
3570 |
@Autowired
|
| 3571 |
private TransactionRepository transactionRepository;
|
3571 |
private TransactionRepository transactionRepository;
|
| 3572 |
|
3572 |
|
| - |
|
3573 |
@Autowired
|
| - |
|
3574 |
private CreditAccountRepository crediRepository;
|
| - |
|
3575 |
|
| 3573 |
public void updatePartnerLimit() throws ProfitMandiBusinessException {
|
3576 |
public void updatePartnerLimit() throws ProfitMandiBusinessException {
|
| 3574 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
|
3577 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
|
| 3575 |
|
3578 |
|
| 3576 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream()
|
3579 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream()
|
| 3577 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
3580 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 3578 |
Map<Integer, CurrentPartnerDailyInvestment> currentPartnerDailyInvestmentMap = currentPartnerDailyInvestmentRepository
|
3581 |
Map<Integer, CurrentPartnerDailyInvestment> currentPartnerDailyInvestmentMap = currentPartnerDailyInvestmentRepository
|
| 3579 |
.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
3582 |
.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 3580 |
|
3583 |
|
| 3581 |
for (Entry<Integer, CustomRetailer> customRetailerEntry : customRetailerMap.entrySet()) {
|
3584 |
for (Entry<Integer, CustomRetailer> customRetailerEntry : customRetailerMap.entrySet()) {
|
| 3582 |
int fofoId = customRetailerEntry.getKey();
|
3585 |
int fofoId = customRetailerEntry.getKey();
|
| 3583 |
|
- |
|
| 3584 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementMap.get(customRetailerEntry.getKey());
|
3586 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementMap.get(customRetailerEntry.getKey());
|
| 3585 |
|
- |
|
| - |
|
3587 |
LocalDateTime firstBillingDate = transactionRepository.getFirstBillingDate(fofoId);
|
| 3586 |
CurrentPartnerDailyInvestment currentPartnerDailyInvestment = currentPartnerDailyInvestmentMap.get(fofoId);
|
3588 |
CurrentPartnerDailyInvestment currentPartnerDailyInvestment = currentPartnerDailyInvestmentMap.get(fofoId);
|
| 3587 |
BigDecimal suggestedAmount = BigDecimal.ZERO;
|
3589 |
BigDecimal suggestedAmount = BigDecimal.ZERO;
|
| 3588 |
if (currentPartnerDailyInvestment != null) {
|
3590 |
if (currentPartnerDailyInvestment != null) {
|
| 3589 |
suggestedAmount = BigDecimal.valueOf(currentPartnerDailyInvestment.getTotalInvestment() * 0.1);
|
3591 |
suggestedAmount = BigDecimal.valueOf(currentPartnerDailyInvestment.getTotalInvestment() * 0.1);
|
| 3590 |
}
|
3592 |
}
|
| Line 3602... |
Line 3604... |
| 3602 |
LOGGER.info("suggestedAmount {} ", suggestedAmount);
|
3604 |
LOGGER.info("suggestedAmount {} ", suggestedAmount);
|
| 3603 |
|
3605 |
|
| 3604 |
if (sdCreditRequirement == null) {
|
3606 |
if (sdCreditRequirement == null) {
|
| 3605 |
sdCreditRequirement = new SDCreditRequirement();
|
3607 |
sdCreditRequirement = new SDCreditRequirement();
|
| 3606 |
sdCreditRequirement.setFofoId(fofoId);
|
3608 |
sdCreditRequirement.setFofoId(fofoId);
|
| 3607 |
sdCreditRequirement.setRisk(CreditRisk.NO_RISK);
|
- |
|
| 3608 |
sdCreditRequirement.setCreditDays(15);
|
3609 |
sdCreditRequirement.setCreditDays(15);
|
| 3609 |
sdCreditRequirement.setInterestRate(BigDecimal.valueOf(0.05));
|
3610 |
sdCreditRequirement.setInterestRate(BigDecimal.valueOf(0.05));
|
| 3610 |
sdCreditRequirement.setSuggestedLimit(suggestedAmount);
|
3611 |
sdCreditRequirement.setSuggestedLimit(suggestedAmount);
|
| - |
|
3612 |
sdCreditRequirement.setRisk(CreditRisk.HIGH_RISK);
|
| 3611 |
sdCreditRequirement.setLimit(suggestedAmount);
|
3613 |
sdCreditRequirement.setLimit(suggestedAmount);
|
| 3612 |
sdCreditRequirement.setUtilizedAmount(BigDecimal.ZERO);
|
3614 |
sdCreditRequirement.setUtilizedAmount(BigDecimal.ZERO);
|
| 3613 |
sdCreditRequirement.setAvailableLimit(suggestedAmount);
|
3615 |
sdCreditRequirement.setAvailableLimit(suggestedAmount);
|
| 3614 |
sdCreditRequirement.setCreateTimestamp(LocalDateTime.now());
|
3616 |
sdCreditRequirement.setCreateTimestamp(LocalDateTime.now());
|
| 3615 |
sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
|
3617 |
sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
|
| 3616 |
sdCreditRequirementRepository.persist(sdCreditRequirement);
|
3618 |
sdCreditRequirementRepository.persist(sdCreditRequirement);
|
| 3617 |
}
|
3619 |
}
|
| - |
|
3620 |
|
| - |
|
3621 |
CreditRisk creditRisk = getCurrentRisk(sdCreditRequirement, firstBillingDate);
|
| - |
|
3622 |
|
| - |
|
3623 |
sdCreditRequirement.setRisk(creditRisk);
|
| - |
|
3624 |
|
| 3618 |
sdCreditRequirement.setSuggestedLimit(suggestedAmount);
|
3625 |
sdCreditRequirement.setSuggestedLimit(suggestedAmount);
|
| 3619 |
sdCreditRequirement.setLimit(suggestedAmount);
|
3626 |
sdCreditRequirement.setLimit(suggestedAmount);
|
| 3620 |
BigDecimal utilizedLimit = new BigDecimal(sdCreditService.getUtilizationAmount(fofoId));
|
3627 |
BigDecimal utilizedLimit = new BigDecimal(sdCreditService.getUtilizationAmount(fofoId));
|
| 3621 |
|
3628 |
|
| 3622 |
BigDecimal availableLimit = sdCreditRequirement.getLimit().subtract(utilizedLimit);
|
3629 |
BigDecimal availableLimit = sdCreditRequirement.getLimit().subtract(utilizedLimit);
|
| Line 3633... |
Line 3640... |
| 3633 |
|
3640 |
|
| 3634 |
}
|
3641 |
}
|
| 3635 |
|
3642 |
|
| 3636 |
}
|
3643 |
}
|
| 3637 |
|
3644 |
|
| - |
|
3645 |
private static final List<CreditRisk> ORDERED_RISKS = Arrays.asList(CreditRisk.HIGH_RISK, CreditRisk.LOW_RISK,
|
| - |
|
3646 |
CreditRisk.NO_RISK);
|
| - |
|
3647 |
|
| - |
|
3648 |
private CreditRisk getCurrentRisk(SDCreditRequirement sdCreditRequirement, LocalDateTime firstBillingDate) {
|
| - |
|
3649 |
CreditRisk currentRisk = sdCreditRequirement.getRisk();
|
| - |
|
3650 |
long noOfDaysBetween = 0;
|
| - |
|
3651 |
LocalDateTime riskDate = sdCreditRequirement.getRiskTimestamp() == null ? firstBillingDate
|
| - |
|
3652 |
: sdCreditRequirement.getRiskTimestamp();
|
| - |
|
3653 |
if (riskDate == null) {
|
| - |
|
3654 |
return CreditRisk.HIGH_RISK;
|
| - |
|
3655 |
} else {
|
| - |
|
3656 |
noOfDaysBetween = ChronoUnit.DAYS.between(riskDate, LocalDateTime.now());
|
| - |
|
3657 |
if (noOfDaysBetween < 90) {
|
| - |
|
3658 |
return currentRisk;
|
| - |
|
3659 |
} else if (noOfDaysBetween >= 90 && noOfDaysBetween < 180) {
|
| - |
|
3660 |
return currentRisk.decrease();
|
| - |
|
3661 |
} else {
|
| - |
|
3662 |
return currentRisk.decrease();
|
| - |
|
3663 |
}
|
| - |
|
3664 |
|
| - |
|
3665 |
}
|
| - |
|
3666 |
|
| - |
|
3667 |
}
|
| - |
|
3668 |
|
| - |
|
3669 |
public void setDefaultPartnersRisk()
|
| - |
|
3670 |
throws ProfitMandiBusinessException, MessagingException, UnsupportedEncodingException {
|
| - |
|
3671 |
|
| - |
|
3672 |
List<Loan> loans = loanRepository.selectAllActiveLoan().stream()
|
| - |
|
3673 |
.filter(x -> x.getDueDate().isBefore(LocalDateTime.now())).collect(Collectors.toList());
|
| - |
|
3674 |
|
| - |
|
3675 |
List<Loan> defaulterLoan = new ArrayList<>();
|
| - |
|
3676 |
|
| - |
|
3677 |
if (!loans.isEmpty()) {
|
| - |
|
3678 |
for (Loan loan : loans) {
|
| - |
|
3679 |
|
| - |
|
3680 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementRepository
|
| - |
|
3681 |
.selectByFofoId(loan.getFofoId());
|
| - |
|
3682 |
long noOfdaysBetween = ChronoUnit.DAYS.between(loan.getDueDate().toLocalDate(), LocalDateTime.now());
|
| - |
|
3683 |
|
| - |
|
3684 |
LOGGER.info("noOfdaysBetween {} ", noOfdaysBetween);
|
| - |
|
3685 |
|
| - |
|
3686 |
if (noOfdaysBetween > 30) {
|
| - |
|
3687 |
CreditAccount creditAccount = crediRepository.selectByFofoIdAndGateway(loan.getFofoId(),
|
| - |
|
3688 |
Gateway.SDDIRECT);
|
| - |
|
3689 |
creditAccount.setActive(false);
|
| - |
|
3690 |
sdCreditRequirement.setRisk(CreditRisk.HIGH_RISK);
|
| - |
|
3691 |
sdCreditRequirement.setRiskTimestamp(LocalDateTime.now());
|
| - |
|
3692 |
|
| - |
|
3693 |
defaulterLoan.add(loan);
|
| - |
|
3694 |
|
| - |
|
3695 |
} else {
|
| - |
|
3696 |
|
| - |
|
3697 |
sdCreditRequirement.setRisk(sdCreditRequirement.getRisk().increase());
|
| - |
|
3698 |
|
| - |
|
3699 |
sdCreditRequirement.setRiskTimestamp(LocalDateTime.now());
|
| - |
|
3700 |
|
| - |
|
3701 |
}
|
| - |
|
3702 |
}
|
| - |
|
3703 |
}
|
| - |
|
3704 |
|
| - |
|
3705 |
if (!defaulterLoan.isEmpty()) {
|
| - |
|
3706 |
|
| - |
|
3707 |
for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMapping().entrySet()) {
|
| - |
|
3708 |
|
| - |
|
3709 |
String subject = "Extend Due Date";
|
| - |
|
3710 |
String messageText = this.getMessageForDueDateExtend(defaulterLoan);
|
| - |
|
3711 |
|
| - |
|
3712 |
MimeMessage message = mailSender.createMimeMessage();
|
| - |
|
3713 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
| - |
|
3714 |
String[] email = new String[] { storeGuyEntry.getKey() };
|
| - |
|
3715 |
|
| - |
|
3716 |
helper.setSubject(subject);
|
| - |
|
3717 |
helper.setText(messageText, true);
|
| - |
|
3718 |
helper.setTo(email);
|
| - |
|
3719 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
|
| - |
|
3720 |
helper.setFrom(senderAddress);
|
| - |
|
3721 |
mailSender.send(message);
|
| - |
|
3722 |
|
| - |
|
3723 |
}
|
| - |
|
3724 |
}
|
| - |
|
3725 |
|
| - |
|
3726 |
}
|
| - |
|
3727 |
|
| - |
|
3728 |
private String getMessageForDueDateExtend(List<Loan> loans) throws ProfitMandiBusinessException {
|
| - |
|
3729 |
StringBuilder sb = new StringBuilder();
|
| - |
|
3730 |
sb.append("<html><body><p>Alert</p><p>Time Limit Cross :-</p>"
|
| - |
|
3731 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
| - |
|
3732 |
sb.append("<tbody>\n" + " <tr>\n"
|
| - |
|
3733 |
+ " <th style='border:1px solid black;padding: 5px'>PartnerName</th>\n"
|
| - |
|
3734 |
+ " <th style='border:1px solid black;padding: 5px'>due date</th>\n"
|
| - |
|
3735 |
+ " <th style='border:1px solid black;padding: 5px'>Days</th>\n"
|
| - |
|
3736 |
|
| - |
|
3737 |
+ " </tr>");
|
| - |
|
3738 |
for (Loan entry : loans) {
|
| - |
|
3739 |
long noOfdaysBetween = ChronoUnit.DAYS.between(entry.getDueDate().toLocalDate(), LocalDateTime.now());
|
| - |
|
3740 |
|
| - |
|
3741 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
|
| - |
|
3742 |
|
| - |
|
3743 |
sb.append("<tr>");
|
| - |
|
3744 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + customRetailer.getBusinessName() + "("
|
| - |
|
3745 |
+ customRetailer.getCode() + ")" + "</td>");
|
| - |
|
3746 |
|
| - |
|
3747 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| - |
|
3748 |
+ entry.getDueDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
|
| - |
|
3749 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + noOfdaysBetween + "</td>");
|
| - |
|
3750 |
|
| - |
|
3751 |
sb.append("</tr>");
|
| - |
|
3752 |
|
| - |
|
3753 |
}
|
| - |
|
3754 |
|
| - |
|
3755 |
sb.append("</tbody></table></body></html>");
|
| - |
|
3756 |
|
| - |
|
3757 |
return sb.toString();
|
| - |
|
3758 |
}
|
| - |
|
3759 |
|
| 3638 |
}
|
3760 |
}
|
| 3639 |
|
3761 |
|
| 3640 |
//2284
|
3762 |
//2284
|
| 3641 |
|
3763 |
|