| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.dao.service;
|
1 |
package com.spice.profitmandi.dao.service;
|
| 2 |
|
2 |
|
| 3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 4 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
4 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| - |
|
5 |
import com.spice.profitmandi.common.util.FileUtil;
|
| - |
|
6 |
import com.spice.profitmandi.common.util.Utils;
|
| 5 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
7 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 6 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
8 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 7 |
import com.spice.profitmandi.dao.model.WarehouseItemAgeingModel;
|
9 |
import com.spice.profitmandi.dao.model.WarehouseItemAgeingModel;
|
| 8 |
import com.spice.profitmandi.dao.model.purchaseSaleRatio.CatalogAgedModel;
|
10 |
import com.spice.profitmandi.dao.model.purchaseSaleRatio.CatalogAgedModel;
|
| 9 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
11 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| Line 11... |
Line 13... |
| 11 |
import com.spice.profitmandi.dao.repository.warehouse.WarehouseSupplierInvoiceRepository;
|
13 |
import com.spice.profitmandi.dao.repository.warehouse.WarehouseSupplierInvoiceRepository;
|
| 12 |
import com.spice.profitmandi.service.AuthService;
|
14 |
import com.spice.profitmandi.service.AuthService;
|
| 13 |
import org.apache.logging.log4j.LogManager;
|
15 |
import org.apache.logging.log4j.LogManager;
|
| 14 |
import org.apache.logging.log4j.Logger;
|
16 |
import org.apache.logging.log4j.Logger;
|
| 15 |
import org.springframework.beans.factory.annotation.Autowired;
|
17 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
18 |
import org.springframework.core.io.ByteArrayResource;
|
| 16 |
import org.springframework.mail.javamail.JavaMailSender;
|
19 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 17 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
20 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 18 |
import org.springframework.stereotype.Service;
|
21 |
import org.springframework.stereotype.Service;
|
| 19 |
import org.springframework.transaction.annotation.Transactional;
|
22 |
import org.springframework.transaction.annotation.Transactional;
|
| 20 |
|
23 |
|
| Line 38... |
Line 41... |
| 38 |
|
41 |
|
| 39 |
@Autowired
|
42 |
@Autowired
|
| 40 |
WarehouseSupplierInvoiceRepository warehouseSupplierInvoiceRepository;
|
43 |
WarehouseSupplierInvoiceRepository warehouseSupplierInvoiceRepository;
|
| 41 |
|
44 |
|
| 42 |
@Autowired
|
45 |
@Autowired
|
| 43 |
JavaMailSender mailSender;
|
46 |
JavaMailSender googleMailSender;
|
| 44 |
|
47 |
|
| 45 |
@Autowired
|
48 |
@Autowired
|
| 46 |
AuthService authService;
|
49 |
AuthService authService;
|
| 47 |
@Autowired
|
50 |
@Autowired
|
| 48 |
AuthRepository authRepository;
|
51 |
AuthRepository authRepository;
|
| Line 96... |
Line 99... |
| 96 |
}
|
99 |
}
|
| 97 |
sb.append("</tbody>");
|
100 |
sb.append("</tbody>");
|
| 98 |
sb.append("</table>");
|
101 |
sb.append("</table>");
|
| 99 |
|
102 |
|
| 100 |
|
103 |
|
| 101 |
List<WarehouseItemAgeingModel> warehouseAgeQtyModel = getAgeingModelsGtDays(startDate, endDate, 4);
|
104 |
List<WarehouseItemAgeingModel> warehouseAgeQtyModels = getAgeingModelsGtDays(startDate, endDate, 4);
|
| 102 |
sb.append("<br /><br /><b>Warehouse Stock</b>");
|
- |
|
| 103 |
sb.append("<table style='border:1px solid black;border-collapse: collapse;' ><thead>")
|
- |
|
| 104 |
.append("<th>No.</th>")
|
- |
|
| 105 |
.append("<th>Vendor</th>")
|
- |
|
| 106 |
.append("<th>Category</th>")
|
- |
|
| 107 |
.append("<th>Brand</th>")
|
- |
|
| 108 |
.append("<th>Model</th>")
|
- |
|
| 109 |
.append("<th>Color</th>")
|
- |
|
| 110 |
.append("<th>Age</th>")
|
- |
|
| 111 |
.append("<th>Warehouse</th>")
|
- |
|
| 112 |
.append("<th>Grn On</th>")
|
- |
|
| 113 |
.append("<th>In Stock</th>")
|
- |
|
| 114 |
.append("</thead>")
|
- |
|
| 115 |
.append("<tbody>");
|
- |
|
| 116 |
i = 0;
|
- |
|
| 117 |
for (WarehouseItemAgeingModel warehouseItemAgeingModel : warehouseAgeQtyModel) {
|
- |
|
| 118 |
|
105 |
|
| - |
|
106 |
org.apache.commons.io.output.ByteArrayOutputStream byteArrayOutputStream = null;
|
| 119 |
sb.append("<tr>")
|
107 |
try {
|
| 120 |
.append("<td style='border:1px solid black;padding:5px'>").append(++i).append("</td>")
|
- |
|
| 121 |
.append("<td style='border:1px solid black;padding:5px'>").append(warehouseItemAgeingModel.getSupplierName()).append("</td>")
|
- |
|
| 122 |
.append("<td style='border:1px solid black;padding:5px'>").append(warehouseItemAgeingModel.getStatus()).append("</td>")
|
- |
|
| 123 |
.append("<td style='border:1px solid black;padding:5px'>").append(warehouseItemAgeingModel.getBrand()).append("</td>")
|
108 |
byteArrayOutputStream = FileUtil.getCSVByteStream(Arrays.asList("Vendor", "Category", "Brand", "Model", "Color",
|
| 124 |
.append("<td style='border:1px solid black;padding:5px'>").append(warehouseItemAgeingModel.getModelName() + " " + warehouseItemAgeingModel.getModelNumber()).append("</td>")
|
- |
|
| 125 |
.append("<td style='border:1px solid black;padding:5px'>").append(warehouseItemAgeingModel.getColor()).append("</td>")
|
109 |
"Age", "Warehouse", "Grn On", "In Stock"),
|
| 126 |
.append("<td style='border:1px solid black;padding:5px'>").append(warehouseItemAgeingModel.getAge()).append("</td>")
|
110 |
warehouseAgeQtyModels.stream().map(x -> x.toRow()).collect(Collectors.toList()));
|
| 127 |
.append("<td style='border:1px solid black;padding:5px'>").append(warehouseItemAgeingModel.getWarehouseName()).append("</td>")
|
- |
|
| 128 |
.append("<td style='border:1px solid black;padding:5px'>").append(warehouseItemAgeingModel.getCreated()).append("</td>")
|
111 |
} catch (Exception e) {
|
| 129 |
.append("<td style='border:1px solid black;padding:5px'>").append(warehouseItemAgeingModel.getCurrentQuantity()).append("</td>")
|
- |
|
| 130 |
.append("</tr>");
|
112 |
throw new RuntimeException(e);
|
| 131 |
}
|
113 |
}
|
| 132 |
|
114 |
|
| 133 |
sb.append("</tbody></table></body></html>");
|
115 |
sb.append("</body></html>");
|
| - |
|
116 |
|
| - |
|
117 |
|
| - |
|
118 |
Utils.Attachment attachment1 = new Utils.Attachment("warehousewise-aged.csv", new ByteArrayResource(byteArrayOutputStream.toByteArray()));
|
| - |
|
119 |
System.out.println("Sending mail ....");
|
| - |
|
120 |
//Utils.sendMailWithAttachments(mailSender, new String[]{"amit.gupta@smartdukaan.com"}, new String[]{"cnc.center@shop2020.in"}, mailSubject, "Dear Partner, \nPlease find attached Credit Note(s)", attachments.toArray(new Utils.Attachment[0]));
|
| - |
|
121 |
//System.out.println("Mail sent ....");
|
| - |
|
122 |
//break;
|
| - |
|
123 |
//Utils.sendMailWithAttachments(mailSender, new String[]{customRetailer.getEmail()}, new String[]{"cnc.center@shop2020.in"}, mailSubject, "Dear Partner, \nPlease find attached Credit Note(s)", attachments.toArray(new Utils.Attachment[0]));
|
| 134 |
String subject = "Aging Stock Report: 4 Days or Older";
|
124 |
String subject = "Aging Stock Report: 4 Days or Older";
|
| 135 |
String messageText = sb.toString();
|
125 |
String messageText = sb.toString();
|
| 136 |
MimeMessage message = mailSender.createMimeMessage();
|
126 |
MimeMessage message = googleMailSender.createMimeMessage();
|
| 137 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
127 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
| 138 |
|
128 |
|
| 139 |
List<AuthUser> accountsAuthUserList = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_ACCOUNTS, Arrays.asList(EscalationType.L1, EscalationType.L2));
|
129 |
List<AuthUser> accountsAuthUserList = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_ACCOUNTS, Arrays.asList(EscalationType.L1, EscalationType.L2));
|
| 140 |
List<String> accountTeamMails = accountsAuthUserList.stream().map(x -> x.getEmailId()).collect(Collectors.toList());
|
130 |
List<String> accountTeamMails = accountsAuthUserList.stream().map(x -> x.getEmailId()).collect(Collectors.toList());
|
| 141 |
accountTeamMails.add("neeraj.gupta@smartdukaan.com");
|
131 |
accountTeamMails.add("neeraj.gupta@smartdukaan.com");
|
| Line 176... |
Line 166... |
| 176 |
String[] emailBcc = bccEmails.toArray(new String[0]);
|
166 |
String[] emailBcc = bccEmails.toArray(new String[0]);
|
| 177 |
helper.setBcc(emailBcc);
|
167 |
helper.setBcc(emailBcc);
|
| 178 |
|
168 |
|
| 179 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
169 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| 180 |
helper.setFrom(senderAddress);
|
170 |
helper.setFrom(senderAddress);
|
| - |
|
171 |
try {
|
| - |
|
172 |
Utils.sendMailWithAttachments(googleMailSender, emailTo, null, emailBcc, subject, messageText, true, attachment1);
|
| - |
|
173 |
//Utils.sendMailWithAttachments(googleMailSender, new String[]{"amit.gupta@smartdukaan.com"}, null, null, subject, messageText, true, attachment1);
|
| 181 |
mailSender.send(message);
|
174 |
} catch (Exception e) {
|
| - |
|
175 |
throw new RuntimeException(e);
|
| 182 |
|
176 |
}
|
| 183 |
}
|
177 |
}
|
| 184 |
|
178 |
|
| 185 |
@Override
|
179 |
@Override
|
| 186 |
public List<CatalogAgedModel> getCatalogModelsOlderThan10Days(LocalDateTime startDate, LocalDateTime endDate) {
|
180 |
public List<CatalogAgedModel> getCatalogModelsOlderThan10Days(LocalDateTime startDate, LocalDateTime endDate) {
|
| 187 |
List<CatalogAgedModel> fiterCatalogAgedModels =
|
181 |
List<CatalogAgedModel> fiterCatalogAgedModels =
|