| 34240 |
tejus.loha |
1 |
package com.spice.profitmandi.dao.service;
|
|
|
2 |
|
| 34275 |
tejus.loha |
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
4 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 34240 |
tejus.loha |
5 |
import com.spice.profitmandi.dao.model.purchaseSaleRatio.CatalogAgedModel;
|
| 34275 |
tejus.loha |
6 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 34240 |
tejus.loha |
7 |
import com.spice.profitmandi.dao.repository.warehouse.WarehouseSupplierInvoiceRepository;
|
| 34275 |
tejus.loha |
8 |
import com.spice.profitmandi.service.AuthService;
|
| 34249 |
tejus.loha |
9 |
import org.apache.logging.log4j.LogManager;
|
|
|
10 |
import org.apache.logging.log4j.Logger;
|
| 34240 |
tejus.loha |
11 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
12 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
13 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
|
|
14 |
import org.springframework.stereotype.Service;
|
| 34250 |
tejus.loha |
15 |
import org.springframework.transaction.annotation.Transactional;
|
| 34240 |
tejus.loha |
16 |
|
|
|
17 |
import javax.mail.MessagingException;
|
|
|
18 |
import javax.mail.internet.InternetAddress;
|
|
|
19 |
import javax.mail.internet.MimeMessage;
|
|
|
20 |
import java.io.UnsupportedEncodingException;
|
|
|
21 |
import java.time.LocalDateTime;
|
| 34275 |
tejus.loha |
22 |
import java.util.*;
|
| 34240 |
tejus.loha |
23 |
import java.util.stream.Collectors;
|
|
|
24 |
|
|
|
25 |
@Service
|
| 34250 |
tejus.loha |
26 |
@Transactional(rollbackFor = Throwable.class)
|
| 34240 |
tejus.loha |
27 |
public class PurSaleServiceImpl implements PurSaleService {
|
|
|
28 |
|
| 34249 |
tejus.loha |
29 |
private static final Logger LOGGER = LogManager.getLogger(PurSaleServiceImpl.class);
|
|
|
30 |
|
|
|
31 |
|
| 34240 |
tejus.loha |
32 |
@Autowired
|
|
|
33 |
WarehouseSupplierInvoiceRepository warehouseSupplierInvoiceRepository;
|
|
|
34 |
|
|
|
35 |
@Autowired
|
|
|
36 |
JavaMailSender mailSender;
|
|
|
37 |
|
| 34275 |
tejus.loha |
38 |
@Autowired
|
|
|
39 |
AuthService authService;
|
|
|
40 |
@Autowired
|
|
|
41 |
AuthRepository authRepository;
|
|
|
42 |
|
| 34240 |
tejus.loha |
43 |
@Override
|
| 34275 |
tejus.loha |
44 |
public void moreThen10DaysEgedStockReport() throws MessagingException, UnsupportedEncodingException, ProfitMandiBusinessException {
|
|
|
45 |
LocalDateTime startDate = LocalDateTime.now().minusMonths(3);
|
|
|
46 |
LocalDateTime endDate = LocalDateTime.now();
|
|
|
47 |
List<CatalogAgedModel> moreThen10DaysAgedCatalogModels = getCatalogModelsOlderThan10Days(startDate,endDate);
|
| 34240 |
tejus.loha |
48 |
StringBuilder sb = new StringBuilder();
|
| 34275 |
tejus.loha |
49 |
sb.append("<html><body><b>Aging Stock List: Items that are 10 days old or older (Date Range - "+startDate.toLocalDate()+" To "+endDate.toLocalDate()+" )</b>" + "<br/><table style='border:1px solid black ;padding: 5px ;bgColor=green'>");
|
| 34240 |
tejus.loha |
50 |
sb.append("<tbody>" +
|
|
|
51 |
"<tr>" +
|
|
|
52 |
"<th style='border:1px solid black;padding: 5px'>No.</th>" +
|
|
|
53 |
"<th style='border:1px solid black;padding: 5px'>Brand</th>" +
|
|
|
54 |
"<th style='border:1px solid black;padding: 5px'>Vendor</th>" +
|
|
|
55 |
"<th style='border:1px solid black;padding: 5px'>Category</th>" +
|
|
|
56 |
"<th style='border:1px solid black;padding: 5px'>Model</th>" +
|
|
|
57 |
"<th style='border:1px solid black;padding: 5px'>Purchase</th>" +
|
|
|
58 |
"<th style='border:1px solid black;padding: 5px'>Sold</th>" +
|
|
|
59 |
"<th style='border:1px solid black;padding: 5px'>Unsold</th>" +
|
|
|
60 |
"<th style='border:1px solid black;padding: 5px'>Age</th>" +
|
|
|
61 |
|
|
|
62 |
"</tr>");
|
|
|
63 |
|
|
|
64 |
int i = 1;
|
|
|
65 |
for (CatalogAgedModel catalogAgedModel : moreThen10DaysAgedCatalogModels) {
|
|
|
66 |
sb.append("<tr>");
|
|
|
67 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + (i++) + "</td>");
|
|
|
68 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + catalogAgedModel.getBrand() + "</td>");
|
|
|
69 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + catalogAgedModel.getSupplier() + "</td>");
|
|
|
70 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + catalogAgedModel.getStatus() + "</td>");
|
| 34275 |
tejus.loha |
71 |
if (catalogAgedModel.getBrand().equals("Samsung")) {
|
|
|
72 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + catalogAgedModel.getModel() + "</td>");
|
|
|
73 |
} else {
|
| 34262 |
tejus.loha |
74 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + catalogAgedModel.getModelName() + "</td>");
|
|
|
75 |
}
|
| 34240 |
tejus.loha |
76 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + catalogAgedModel.getPurchase() + "</td>");
|
|
|
77 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + catalogAgedModel.getSold() + "</td>");
|
|
|
78 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + catalogAgedModel.getUnsold() + "</td>");
|
|
|
79 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + catalogAgedModel.getAge() + "</td>");
|
|
|
80 |
sb.append("</tr>");
|
|
|
81 |
|
|
|
82 |
}
|
| 34275 |
tejus.loha |
83 |
String subject = "Aging Stock Report: 10 Days or Older";
|
| 34240 |
tejus.loha |
84 |
String messageText = sb.toString();
|
|
|
85 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
86 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
| 34275 |
tejus.loha |
87 |
|
|
|
88 |
List<String> allEmails = new ArrayList<>(Arrays.asList(
|
| 34263 |
tejus.loha |
89 |
"sm@smartdukaan.com",
|
| 34275 |
tejus.loha |
90 |
"manish.gupta1@smartdukaan.com",
|
| 34263 |
tejus.loha |
91 |
"tarun.verma@smartdukaan.com",
|
| 34275 |
tejus.loha |
92 |
"chiranjib.sarkar@smartdukaan.com",
|
|
|
93 |
"niranjan.kala@smartdukaan.com",
|
|
|
94 |
"mohit.gulati@smartdukaan.com"
|
|
|
95 |
// "tejus.lohani@smartdukaan.com"
|
|
|
96 |
));
|
| 34254 |
tejus.loha |
97 |
|
| 34275 |
tejus.loha |
98 |
// niranjan kala(authId -54) Team Emails,
|
|
|
99 |
List<Integer> allReportees = authService.getAllReportees(54);
|
|
|
100 |
List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(allReportees);
|
|
|
101 |
List<String> categotyTeamEmails = authUsers.stream().map(x -> x.getEmailId()).collect(Collectors.toList());
|
|
|
102 |
|
|
|
103 |
allEmails.addAll(categotyTeamEmails);
|
|
|
104 |
String[] emailTo = allEmails.toArray(new String[allEmails.size()]);
|
| 34240 |
tejus.loha |
105 |
helper.setSubject(subject);
|
|
|
106 |
helper.setText(messageText, true);
|
|
|
107 |
helper.setTo(emailTo);
|
| 34275 |
tejus.loha |
108 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| 34240 |
tejus.loha |
109 |
helper.setFrom(senderAddress);
|
|
|
110 |
mailSender.send(message);
|
|
|
111 |
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
@Override
|
| 34275 |
tejus.loha |
115 |
public List<CatalogAgedModel> getCatalogModelsOlderThan10Days(LocalDateTime startDate, LocalDateTime endDate) {
|
| 34240 |
tejus.loha |
116 |
List<CatalogAgedModel> fiterCatalogAgedModels =
|
| 34275 |
tejus.loha |
117 |
warehouseSupplierInvoiceRepository.selectCatalogAge(startDate, endDate, null, 0, null)
|
| 34274 |
tejus.loha |
118 |
.stream().filter(x -> x.getAge() >= 10 && x.getUnsold() > 0).collect(Collectors.toList());
|
| 34275 |
tejus.loha |
119 |
LOGGER.info("fiterCatalogAgedModels - " + fiterCatalogAgedModels);
|
| 34240 |
tejus.loha |
120 |
return fiterCatalogAgedModels;
|
|
|
121 |
}
|
|
|
122 |
// 192.168.0.16:8080
|
|
|
123 |
}
|