Subversion Repositories SmartDukaan

Rev

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

Rev 30959 Rev 30965
Line 85... Line 85...
85
import okhttp3.Response;
85
import okhttp3.Response;
86
import org.apache.commons.io.output.ByteArrayOutputStream;
86
import org.apache.commons.io.output.ByteArrayOutputStream;
87
import org.apache.commons.lang.StringUtils;
87
import org.apache.commons.lang.StringUtils;
88
import org.apache.http.client.methods.CloseableHttpResponse;
88
import org.apache.http.client.methods.CloseableHttpResponse;
89
import org.apache.http.client.methods.HttpPost;
89
import org.apache.http.client.methods.HttpPost;
-
 
90
import org.apache.http.conn.HttpHostConnectException;
90
import org.apache.http.entity.StringEntity;
91
import org.apache.http.entity.StringEntity;
91
import org.apache.http.impl.client.CloseableHttpClient;
92
import org.apache.http.impl.client.CloseableHttpClient;
92
import org.apache.http.impl.client.HttpClients;
93
import org.apache.http.impl.client.HttpClients;
93
import org.apache.logging.log4j.LogManager;
94
import org.apache.logging.log4j.LogManager;
94
import org.apache.logging.log4j.Logger;
95
import org.apache.logging.log4j.Logger;
Line 107... Line 108...
107
import javax.mail.MessagingException;
108
import javax.mail.MessagingException;
108
import javax.mail.internet.InternetAddress;
109
import javax.mail.internet.InternetAddress;
109
import javax.mail.internet.MimeMessage;
110
import javax.mail.internet.MimeMessage;
110
import java.io.*;
111
import java.io.*;
111
import java.math.BigDecimal;
112
import java.math.BigDecimal;
-
 
113
import java.net.URLEncoder;
-
 
114
import java.nio.charset.StandardCharsets;
112
import java.nio.file.Files;
115
import java.nio.file.Files;
113
import java.nio.file.Paths;
116
import java.nio.file.Paths;
114
import java.sql.Timestamp;
117
import java.sql.Timestamp;
115
import java.text.DecimalFormat;
118
import java.text.DecimalFormat;
116
import java.time.*;
119
import java.time.*;
Line 2229... Line 2232...
2229
				// check if pricedrop has been rolled out
2232
				// check if pricedrop has been rolled out
2230
				List<UserWalletHistory> uwh = walletService.getAllByReference(inventoryItem.getFofoId(),
2233
				List<UserWalletHistory> uwh = walletService.getAllByReference(inventoryItem.getFofoId(),
2231
						priceDropIMEI.getPriceDropId(), WalletReferenceType.PRICE_DROP);
2234
						priceDropIMEI.getPriceDropId(), WalletReferenceType.PRICE_DROP);
2232
				if (uwh.size() > 0) {
2235
				if (uwh.size() > 0) {
2233
					Item item = itemRepository.selectById(inventoryItem.getItemId());
2236
					Item item = itemRepository.selectById(inventoryItem.getItemId());
2234
					System.out.println(String.join("\t", Arrays.asList(priceDropIMEI.getImei(),
2237
					System.out.println(String.join("\t",
-
 
2238
							Arrays.asList(priceDropIMEI.getImei(), inventoryItem.getItemId() + "", item.getBrand(),
2235
							inventoryItem.getItemId() + "", item.getBrand(), item.getModelName(), item.getModelNumber(),
2239
									item.getModelName(), item.getModelNumber(), inventoryItem.getFofoId() + "",
2236
							inventoryItem.getFofoId() + "", customRetailer.getBusinessName(),
2240
									customRetailer.getBusinessName(), inventoryItem.getCreateTimestamp().format(dtf),
2237
							inventoryItem.getCreateTimestamp().format(dtf), priceDrop.getAffectedOn().format(dtf),
2241
									priceDrop.getAffectedOn().format(dtf),
2238
							priceDropIMEI.getUpdateTimestamp().format(dtf),
2242
									priceDropIMEI.getUpdateTimestamp().format(dtf),
-
 
2243
									inventoryItem.getUpdateTimestamp().format(dtf),
2239
							inventoryItem.getUpdateTimestamp().format(dtf), priceDrop.getAutoPartnerPayout(inventoryItem.getUpdateTimestamp()) + "",
2244
									priceDrop.getAutoPartnerPayout(inventoryItem.getUpdateTimestamp()) + "",
2240
							inventoryItem.getLastScanType().equals(ScanType.DOA_OUT) + "")));
2245
									inventoryItem.getLastScanType().equals(ScanType.DOA_OUT) + "")));
2241
				}
2246
				}
2242
			}
2247
			}
2243
		}
2248
		}
2244
	}
2249
	}
2245
 
2250
 
Line 3220... Line 3225...
3220
					}
3225
					}
3221
 
3226
 
3222
					SendNotificationModel sendNotificationModel = new SendNotificationModel();
3227
					SendNotificationModel sendNotificationModel = new SendNotificationModel();
3223
					sendNotificationModel.setCampaignName("Order Delivered");
3228
					sendNotificationModel.setCampaignName("Order Delivered");
3224
					sendNotificationModel.setTitle("Order Delivered");
3229
					sendNotificationModel.setTitle("Order Delivered");
3225
					sendNotificationModel.setMessage(String.format("Dear partner, your SmartDukaan ORDER " + aws
3230
					sendNotificationModel.setMessage(String.format("Dear partner, your SmartDukaan Order " + aws
3226
							+ "has been delivered to you in a safe sealed bag" + "."));
3231
							+ "has been delivered to you in a safe sealed bag" + "."));
3227
					sendNotificationModel.setType("url");
3232
					sendNotificationModel.setType("url");
3228
					sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
3233
					sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
3229
					sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
3234
					sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
3230
					sendNotificationModel.setMessageType(MessageType.notification);
3235
					sendNotificationModel.setMessageType(MessageType.notification);
Line 3544... Line 3549...
3544
		uwh.setDescription("Amount adjusted against loan");
3549
		uwh.setDescription("Amount adjusted against loan");
3545
		userWalletHistoryRepository.persist(uwh);
3550
		userWalletHistoryRepository.persist(uwh);
3546
 
3551
 
3547
	}
3552
	}
3548
 
3553
 
3549
	public void dailyLoanAlert() throws ProfitMandiBusinessException {
3554
	public void dailyLoanAlert()
-
 
3555
			throws ProfitMandiBusinessException, HttpHostConnectException, UnsupportedEncodingException {
3550
		List<Loan> loans = loanRepository.selectAllActiveLoan();
3556
		List<Loan> loans = loanRepository.selectAllActiveLoan();
3551
 
3557
 
3552
		Map<Integer, Double> partnerLoanAmount = new HashMap<>();
3558
		Map<Integer, Double> partnerLoanAmount = new HashMap<>();
3553
 
3559
 
3554
		if (!loans.isEmpty()) {
3560
		if (!loans.isEmpty()) {
Line 3574... Line 3580...
3574
 
3580
 
3575
			for (Entry<Integer, Double> partnerLoanAmountEnrty : partnerLoanAmount.entrySet()) {
3581
			for (Entry<Integer, Double> partnerLoanAmountEnrty : partnerLoanAmount.entrySet()) {
3576
 
3582
 
3577
				int fofoId = partnerLoanAmountEnrty.getKey();
3583
				int fofoId = partnerLoanAmountEnrty.getKey();
3578
 
3584
 
-
 
3585
				com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(fofoId);
-
 
3586
 
-
 
3587
				Address address = addressRepository.selectById(user.getAddressId());
-
 
3588
 
3579
				String title = "Alert! Credit o/s";
3589
				String title = "Alert Credit Outstanding!";
3580
				String url = "http://app.smartdukaan.com/pages/home/credit";
3590
				String url = "http://app.smartdukaan.com/pages/home/credit";
3581
				String message = "Your total pending Loan amount is Rs."
3591
				String message = "Your total pending Loan amount is Rs. "
3582
						+ FormattingUtils.formatDecimal(Math.abs(partnerLoanAmountEnrty.getValue()));
3592
						+ FormattingUtils.formatDecimal(Math.abs(partnerLoanAmountEnrty.getValue()));
3583
				notificationService.sendNotification(fofoId, title, MessageType.notification, title, message, url);
3593
				notificationService.sendNotification(fofoId, title, MessageType.notification, title, message, url);
3584
 
3594
 
-
 
3595
				// notificationService.sendWhatsappMessage(message, title,
-
 
3596
				// address.getPhoneNumber());
-
 
3597
 
3585
			}
3598
			}
3586
 
3599
 
3587
		}
3600
		}
3588
 
3601
 
3589
	}
3602
	}
Line 3657... Line 3670...
3657
 
3670
 
3658
			sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
3671
			sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
3659
 
3672
 
3660
			CreditAccount creditAccount = creditAccountRepository
3673
			CreditAccount creditAccount = creditAccountRepository
3661
					.selectByFofoIdAndGateway(sdCreditRequirement.getFofoId(), Gateway.SDDIRECT);
3674
					.selectByFofoIdAndGateway(sdCreditRequirement.getFofoId(), Gateway.SDDIRECT);
3662
			if (creditAccount == null) {
3675
			if (creditAccount != null) {
3663
				creditAccount = new CreditAccount();
-
 
3664
				creditAccount.setFofoId(sdCreditRequirement.getFofoId());
-
 
3665
				creditAccount.setGateway(Gateway.SDDIRECT);
-
 
3666
				creditAccount.setCreditStatus(CreditStatus.SANCTIONED);
-
 
3667
				creditAccount.setActive(false);
-
 
3668
 
3676
 
-
 
3677
				creditAccount.setInterestRate(sdCreditRequirement.getInterestRate().floatValue());
-
 
3678
				creditAccount.setSanctionedAmount(sdCreditRequirement.getLimit().floatValue());
-
 
3679
				creditAccount.setAvailableAmount(availableLimit.floatValue());
-
 
3680
				creditAccount.setFreeDays(sdCreditRequirement.getFreeDays());
3669
				creditAccount.setUpdatedOn(LocalDateTime.now());
3681
				creditAccount.setUpdatedOn(LocalDateTime.now());
3670
 
-
 
3671
				creditAccountRepository.persist(creditAccount);
-
 
3672
			}
3682
			}
3673
 
3683
 
3674
			creditAccount.setInterestRate(sdCreditRequirement.getInterestRate().floatValue());
-
 
3675
			creditAccount.setSanctionedAmount(sdCreditRequirement.getLimit().floatValue());
-
 
3676
			creditAccount.setAvailableAmount(availableLimit.floatValue());
-
 
3677
			creditAccount.setFreeDays(sdCreditRequirement.getFreeDays());
-
 
3678
			creditAccount.setUpdatedOn(LocalDateTime.now());
-
 
3679
 
-
 
3680
		}
3684
		}
3681
 
3685
 
3682
	}
3686
	}
3683
 
3687
 
3684
	public void notifyDefaultLoans() throws ProfitMandiBusinessException, MessagingException, IOException {
3688
	public void notifyDefaultLoans() throws ProfitMandiBusinessException, MessagingException, IOException {
Line 3735... Line 3739...
3735
			String title = "Loan amount overdue!";
3739
			String title = "Loan amount overdue!";
3736
			String url = "http://app.smartdukaan.com/pages/home/credit";
3740
			String url = "http://app.smartdukaan.com/pages/home/credit";
3737
			String message = "Your loan due date ("
3741
			String message = "Your loan due date ("
3738
					+ defaultLoan.getDueDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))
3742
					+ defaultLoan.getDueDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))
3739
					+ ") has been exceeded. Additional penal interest of " + defaultLoan.getInterestRate()
3743
					+ ") has been exceeded. Additional penal interest of " + defaultLoan.getInterestRate()
3740
					+ "%  + Rs.100 shall be levied on daily basis. " + "Your total pending Loan amount is Rs."
3744
					+ "%  + and Rs.100 shall be levied on daily basis. " + "Your total pending Loan amount is Rs."
3741
					+ FormattingUtils.formatDecimal(Math.abs(amount)) + ". !!Pay Now!!";
3745
					+ FormattingUtils.formatDecimal(Math.abs(amount)) + ". !!Pay Now!!";
3742
			notificationService.sendNotification(defaultLoan.getFofoId(), title, MessageType.notification, title,
3746
			notificationService.sendNotification(defaultLoan.getFofoId(), title, MessageType.notification, title,
3743
					message, url);
3747
					message, url);
3744
 
3748
 
3745
		}
3749
		}
Line 3833... Line 3837...
3833
				if (noOfdaysBetween <= 4 && noOfdaysBetween >= 0) {
3837
				if (noOfdaysBetween <= 4 && noOfdaysBetween >= 0) {
3834
					List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
3838
					List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
3835
					double amount = loanStatements.stream().map(x -> x.getAmount())
3839
					double amount = loanStatements.stream().map(x -> x.getAmount())
3836
							.collect(Collectors.summingDouble(x -> x.doubleValue()));
3840
							.collect(Collectors.summingDouble(x -> x.doubleValue()));
3837
 
3841
 
3838
					String title = "Alert! Credit o/s";
3842
					String title = "Alert!";
3839
					String url = "http://app.smartdukaan.com/pages/home/credit";
3843
					String url = "http://app.smartdukaan.com/pages/home/credit";
3840
					String message = null;
3844
					String message = null;
3841
					if (noOfdaysBetween == 0) {
3845
					if (noOfdaysBetween == 0) {
3842
 
3846
 
3843
						message = "Your total pending Loan amount is Rs."
3847
						message = "Your total pending Loan amount is Rs."