Subversion Repositories SmartDukaan

Rev

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

Rev 31388 Rev 31397
Line 3958... Line 3958...
3958
					+ "%  and Rs.100 shall be levied on daily basis." + " Your total pending Loan amount is Rs."
3958
					+ "%  and Rs.100 shall be levied on daily basis." + " Your total pending Loan amount is Rs."
3959
					+ FormattingUtils.formatDecimal(Math.abs(amount)) + ". !!Pay Now!!";
3959
					+ FormattingUtils.formatDecimal(Math.abs(amount)) + ". !!Pay Now!!";
3960
			notificationService.sendNotification(defaultLoan.getFofoId(), title, MessageType.notification, title,
3960
			notificationService.sendNotification(defaultLoan.getFofoId(), title, MessageType.notification, title,
3961
					message, url);
3961
					message, url);
3962
 
3962
 
3963
			notificationService.sendWhatsappMessage(message, title, address.getPhoneNumber());
3963
			// notificationService.sendWhatsappMessage(message, title,
-
 
3964
			// address.getPhoneNumber());
3964
 
3965
 
3965
		}
3966
		}
3966
	}
3967
	}
3967
 
3968
 
3968
	private String getMessageForDueDateExtend(List<Loan> loans) throws ProfitMandiBusinessException {
3969
	private String getMessageForDueDateExtend(List<Loan> loans) throws ProfitMandiBusinessException {
Line 4005... Line 4006...
4005
		sb.append("</tbody></table></body></html>");
4006
		sb.append("</tbody></table></body></html>");
4006
 
4007
 
4007
		return sb.toString();
4008
		return sb.toString();
4008
	}
4009
	}
4009
 
4010
 
-
 
4011
	private String getMessageForDueDateCross(List<Loan> loans) throws ProfitMandiBusinessException {
-
 
4012
		StringBuilder sb = new StringBuilder();
-
 
4013
		sb.append("<html><body><p>Alert</p><p>Due Date Cross Partners :-</p>"
-
 
4014
				+ "<br/><p>Additional penal interest of  shall be levied on daily basis.</p>"
-
 
4015
				+ "<br/><table style='border:1px solid black ;padding: 5px';>");
-
 
4016
		sb.append("<tbody>\n" + "	    				<tr>\n"
-
 
4017
				+ "	    					<th style='border:1px solid black;padding: 5px'>PartnerName</th>\n"
-
 
4018
				+ "	    					<th style='border:1px solid black;padding: 5px'>due date</th>\n"
-
 
4019
				+ "	    					<th style='border:1px solid black;padding: 5px'>Days</th>\n"
-
 
4020
				+ "	    					<th style='border:1px solid black;padding: 5px'>Pending Amount</th>\n"
-
 
4021
 
-
 
4022
				+ "	    				</tr>");
-
 
4023
		for (Loan entry : loans) {
-
 
4024
 
-
 
4025
			List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(entry.getId());
-
 
4026
 
-
 
4027
			double amount = loanStatements.stream().map(x -> x.getAmount())
-
 
4028
					.collect(Collectors.summingDouble(x -> x.doubleValue()));
-
 
4029
 
-
 
4030
			long noOfdaysBetween = ChronoUnit.DAYS.between(entry.getDueDate().toLocalDate(), LocalDateTime.now());
-
 
4031
 
-
 
4032
			CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
-
 
4033
 
-
 
4034
			sb.append("<tr>");
-
 
4035
			sb.append("<td style='border:1px solid black;padding: 5px'>" + customRetailer.getBusinessName() + "("
-
 
4036
					+ customRetailer.getCode() + ")" + "</td>");
-
 
4037
 
-
 
4038
			sb.append("<td style='border:1px solid black;padding: 5px'>"
-
 
4039
					+ entry.getDueDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
-
 
4040
			sb.append("<td style='border:1px solid black;padding: 5px'>" + noOfdaysBetween + "</td>");
-
 
4041
			sb.append("<td style='border:1px solid black;padding: 5px'>"
-
 
4042
					+ new DecimalFormat("#.##").format(Math.abs(amount)) + "</td>");
-
 
4043
 
-
 
4044
			sb.append("</tr>");
-
 
4045
 
-
 
4046
		}
-
 
4047
 
-
 
4048
		sb.append("</tbody></table></body></html>");
-
 
4049
 
-
 
4050
		return sb.toString();
-
 
4051
	}
-
 
4052
 
4010
	public void notifyLoanDueDateCross() throws ProfitMandiBusinessException, MessagingException, IOException {
4053
	public void notifyLoanDueDateCross() throws ProfitMandiBusinessException, MessagingException, IOException {
4011
 
4054
 
4012
		List<Loan> loans = loanRepository.selectAllActiveLoan().stream()
4055
		List<Loan> dueDateCrossLoans = sdCreditService.getDueDateCrossLoan();
-
 
4056
		if (!dueDateCrossLoans.isEmpty()) {
-
 
4057
			this.sendDueDateCrossLoanAlert(dueDateCrossLoans);
-
 
4058
		}
-
 
4059
 
-
 
4060
	}
-
 
4061
 
4013
				.filter(x -> x.getDueDate().isBefore(LocalDateTime.now())).collect(Collectors.toList());
4062
	private void sendDueDateCrossLoanAlert(List<Loan> dueDateCrossLoans)
-
 
4063
			throws ProfitMandiBusinessException, MessagingException, IOException {
-
 
4064
		List<Integer> categoryIds = Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_CATEGORY,
-
 
4065
				ProfitMandiConstants.TICKET_CATEGORY_RBM, ProfitMandiConstants.TICKET_CATEGORY_SALES,
-
 
4066
				ProfitMandiConstants.TICKET_CATEGORY_ACCOUNTS,
-
 
4067
				ProfitMandiConstants.TICKET_CATEGORY_BUSINESSINTELLIGENT);
-
 
4068
 
-
 
4069
		for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService
-
 
4070
				.getAuthUserPartnerIdMappingByCategoryIds(categoryIds).entrySet()) {
-
 
4071
			List<Loan> filteredRows = new ArrayList<>();
-
 
4072
			for (Loan loan : dueDateCrossLoans) {
-
 
4073
 
-
 
4074
				if (storeGuyEntry.getValue().contains(loan.getFofoId())) {
-
 
4075
 
-
 
4076
					filteredRows.add(loan);
-
 
4077
				}
-
 
4078
			}
4014
		if (!loans.isEmpty()) {
4079
			if (!filteredRows.isEmpty()) {
-
 
4080
				String messageText = this.getMessageForDueDateCross(filteredRows);
-
 
4081
				String[] email = new String[] { storeGuyEntry.getKey() };
-
 
4082
 
-
 
4083
				this.sendMailHtmlFormat(email, messageText, null, "Due Date Cross");
-
 
4084
 
-
 
4085
			}
-
 
4086
 
-
 
4087
		}
-
 
4088
		if (!dueDateCrossLoans.isEmpty()) {
4015
			for (Loan loan : loans) {
4089
			for (Loan loan : dueDateCrossLoans) {
4016
 
4090
 
4017
				long noOfdaysBetween = ChronoUnit.DAYS.between(loan.getDueDate().toLocalDate(), LocalDate.now());
4091
				long noOfdaysBetween = ChronoUnit.DAYS.between(loan.getDueDate().toLocalDate(), LocalDate.now());
4018
 
4092
 
4019
				com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(loan.getFofoId());
4093
				com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(loan.getFofoId());
4020
 
4094
 
4021
				Address address = addressRepository.selectById(user.getAddressId());
4095
				Address address = addressRepository.selectById(user.getAddressId());
4022
 
4096
 
4023
				LOGGER.info("noOfdaysBetween {} ", noOfdaysBetween);
4097
				LOGGER.info("noOfdaysBetween {} ", noOfdaysBetween);
4024
 
4098
 
4025
				if (noOfdaysBetween <= 15 && noOfdaysBetween >= 0) {
-
 
4026
					List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
4099
				List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
4027
 
4100
 
4028
					double amount = loanStatements.stream().map(x -> x.getAmount())
4101
				double amount = loanStatements.stream().map(x -> x.getAmount())
4029
							.collect(Collectors.summingDouble(x -> x.doubleValue()));
4102
						.collect(Collectors.summingDouble(x -> x.doubleValue()));
4030
 
4103
 
4031
					String url = "http://app.smartdukaan.com/pages/home/credit";
4104
				String url = "http://app.smartdukaan.com/pages/home/credit";
4032
 
4105
 
4033
					String title = "Alert!";
4106
				String title = "Alert!";
4034
					String message = "Your loan due date "
4107
				String message = "Your loan due date "
4035
							+ loan.getDueDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))
4108
						+ loan.getDueDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))
4036
							+ " has been exceeded. Additional penal interest of "
4109
						+ " has been exceeded. Additional penal interest of "
4037
							+ loan.getInterestRate().setScale(2, RoundingMode.HALF_UP)
4110
						+ loan.getInterestRate().setScale(2, RoundingMode.HALF_UP)
4038
							+ "% shall be levied on daily basis. Your total pending loan amount is Rs."
4111
						+ "% shall be levied on daily basis. Your total pending loan amount is Rs."
4039
							+ FormattingUtils.formatDecimal(Math.abs(amount)) + ". !!Pay Now!!";
4112
						+ FormattingUtils.formatDecimal(Math.abs(amount)) + ". !!Pay Now!!";
4040
 
4113
 
4041
					notificationService.sendNotification(loan.getFofoId(), title, MessageType.notification, title,
4114
				notificationService.sendNotification(loan.getFofoId(), title, MessageType.notification, title, message,
4042
							message, url);
4115
						url);
4043
 
4116
 
4044
					notificationService.sendWhatsappMessage(message, title, address.getPhoneNumber());
4117
				notificationService.sendWhatsappMessage(message, title, address.getPhoneNumber());
4045
 
4118
 
4046
				}
-
 
4047
			}
4119
			}
4048
		}
4120
		}
4049
 
4121
 
4050
	}
4122
	}
4051
 
4123