| Line 193... |
Line 193... |
| 193 |
|
193 |
|
| 194 |
|
194 |
|
| 195 |
Map<String, String> headersMap = new HashMap<>();
|
195 |
Map<String, String> headersMap = new HashMap<>();
|
| 196 |
headersMap.put("Authorization", "Basic " + Base64.getEncoder().encodeToString("smartdukaan:$smart@123#".getBytes()));
|
196 |
headersMap.put("Authorization", "Basic " + Base64.getEncoder().encodeToString("smartdukaan:$smart@123#".getBytes()));
|
| 197 |
if (invoiceNumbers.size() == 1) {
|
197 |
if (invoiceNumbers.size() == 1) {
|
| - |
|
198 |
Order order = invoiceOrdersMap.get(invoiceNumbers.get(0)).get(0);
|
| 198 |
String invoicePath = this.getInvoicePath(invoiceOrdersMap.get(invoiceNumbers.get(0)).get(0));
|
199 |
String invoicePath = this.getInvoicePath(invoiceOrdersMap.get(invoiceNumbers.get(0)).get(0));
|
| - |
|
200 |
HttpResponse response;
|
| - |
|
201 |
try {
|
| 199 |
HttpResponse response = restClient.getResponse("http://45.79.106.95/" + invoicePath, null, headersMap);
|
202 |
response = restClient.getResponse("http://45.79.106.95/" + invoicePath, null, headersMap);
|
| - |
|
203 |
} catch (Exception e) {
|
| - |
|
204 |
invoicePath = this.getInvoicePathLastMonth(order);
|
| - |
|
205 |
response = restClient.getResponse("http://45.79.106.95/" + invoicePath, null, headersMap);
|
| - |
|
206 |
}
|
| 200 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
207 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
| 201 |
headers.set("Content-Type", "application/pdf");
|
208 |
headers.set("Content-Type", "application/pdf");
|
| 202 |
headers.set("Content-disposition", "inline; filename=" + invoiceNumber + ".pdf");
|
209 |
headers.set("Content-disposition", "inline; filename=" + invoiceNumber + ".pdf");
|
| 203 |
InputStreamResource is = new InputStreamResource(response.getEntity().getContent());
|
210 |
InputStreamResource is = new InputStreamResource(response.getEntity().getContent());
|
| 204 |
return new ResponseEntity<>(is, headers, HttpStatus.OK);
|
211 |
return new ResponseEntity<>(is, headers, HttpStatus.OK);
|
| Line 207... |
Line 214... |
| 207 |
|
214 |
|
| 208 |
ByteArrayOutputStream fos = new ByteArrayOutputStream();
|
215 |
ByteArrayOutputStream fos = new ByteArrayOutputStream();
|
| 209 |
ZipOutputStream zipOut = new ZipOutputStream(fos);
|
216 |
ZipOutputStream zipOut = new ZipOutputStream(fos);
|
| 210 |
|
217 |
|
| 211 |
for (String invoice : invoiceNumbers) {
|
218 |
for (String invoice : invoiceNumbers) {
|
| 212 |
List<Order> orders = invoiceOrdersMap.get(invoice);
|
219 |
Order order = invoiceOrdersMap.get(invoiceNumbers.get(0)).get(0);
|
| 213 |
String invoicePath = this.getInvoicePath(orders.get(0));
|
220 |
String invoicePath = this.getInvoicePath(order);
|
| - |
|
221 |
HttpResponse response;
|
| - |
|
222 |
try {
|
| - |
|
223 |
response = restClient.getResponse("http://45.79.106.95/" + invoicePath, null, headersMap);
|
| - |
|
224 |
} catch (Exception e) {
|
| - |
|
225 |
invoicePath = this.getInvoicePathLastMonth(order);
|
| 214 |
HttpResponse response = restClient.getResponse("http://45.79.106.95/" + invoicePath, null, headersMap);
|
226 |
response = restClient.getResponse("http://45.79.106.95/" + invoicePath, null, headersMap);
|
| - |
|
227 |
}
|
| 215 |
this.addFileToZip(zipOut, response.getEntity().getContent(), invoice + ".pdf");
|
228 |
this.addFileToZip(zipOut, response.getEntity().getContent(), invoice + ".pdf");
|
| 216 |
}
|
229 |
}
|
| 217 |
zipOut.close();
|
230 |
zipOut.close();
|
| 218 |
byte[] byteArray = fos.toByteArray();
|
231 |
byte[] byteArray = fos.toByteArray();
|
| 219 |
headers.set("Content-Type", ContentType.APPLICATION_OCTET_STREAM.getMimeType());
|
232 |
headers.set("Content-Type", ContentType.APPLICATION_OCTET_STREAM.getMimeType());
|
| Line 242... |
Line 255... |
| 242 |
LocalDateTime billTime = order.getBillingTimestamp();
|
255 |
LocalDateTime billTime = order.getBillingTimestamp();
|
| 243 |
String dirPath = billTime.getYear() + "-" + (billTime.getMonthValue() - 1) + File.separator + order.getRetailerId();
|
256 |
String dirPath = billTime.getYear() + "-" + (billTime.getMonthValue() - 1) + File.separator + order.getRetailerId();
|
| 244 |
String filename = dirPath + File.separator + order.getInvoiceNumber() + ".pdf";
|
257 |
String filename = dirPath + File.separator + order.getInvoiceNumber() + ".pdf";
|
| 245 |
return filename;
|
258 |
return filename;
|
| 246 |
}
|
259 |
}
|
| - |
|
260 |
|
| - |
|
261 |
private String getInvoicePathLastMonth(Order order) {
|
| - |
|
262 |
LocalDateTime billTime = order.getBillingTimestamp();
|
| - |
|
263 |
billTime = billTime.minusMonths(1);
|
| - |
|
264 |
String dirPath = billTime.getYear() + "-" + (billTime.getMonthValue() - 1) + File.separator + order.getRetailerId();
|
| - |
|
265 |
String filename = dirPath + File.separator + order.getInvoiceNumber() + ".pdf";
|
| - |
|
266 |
return filename;
|
| - |
|
267 |
}
|
| 247 |
}
|
268 |
}
|
| 248 |
|
269 |
|