| Line 261... |
Line 261... |
| 261 |
|
261 |
|
| 262 |
@RequestMapping(value = "/saleDetails", method = RequestMethod.GET)
|
262 |
@RequestMapping(value = "/saleDetails", method = RequestMethod.GET)
|
| 263 |
public String getSaleDetails(HttpServletRequest request,
|
263 |
public String getSaleDetails(HttpServletRequest request,
|
| 264 |
@RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId, Model model) throws Exception {
|
264 |
@RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId, Model model) throws Exception {
|
| 265 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
265 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 266 |
|
- |
|
| - |
|
266 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
| 267 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
267 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
| 268 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
268 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 269 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
269 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 270 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
270 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
| 271 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
271 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
| Line 308... |
Line 308... |
| 308 |
for (FofoLineItem fli : foi.getFofoLineItems()) {
|
308 |
for (FofoLineItem fli : foi.getFofoLineItems()) {
|
| 309 |
inventoryItemBilledQtyMap.put(fli.getInventoryItemId(), fli.getQuantity());
|
309 |
inventoryItemBilledQtyMap.put(fli.getInventoryItemId(), fli.getQuantity());
|
| 310 |
}
|
310 |
}
|
| 311 |
List<CustomerReturnItem> customerReturnItems = customerReturnItemRepository
|
311 |
List<CustomerReturnItem> customerReturnItems = customerReturnItemRepository
|
| 312 |
.selectAllByOrderItemId(foi.getId());
|
312 |
.selectAllByOrderItemId(foi.getId());
|
| 313 |
this.markDoa(fofoOrder, foi);
|
313 |
this.markDoa(fofoOrder, foi, isAdmin);
|
| 314 |
for (CustomerReturnItem customerReturnItem : customerReturnItems) {
|
314 |
for (CustomerReturnItem customerReturnItem : customerReturnItems) {
|
| 315 |
inventoryItemBilledQtyMap.put(customerReturnItem.getInventoryItemId(),
|
315 |
inventoryItemBilledQtyMap.put(customerReturnItem.getInventoryItemId(),
|
| 316 |
inventoryItemBilledQtyMap.get(customerReturnItem.getInventoryItemId()) - 1);
|
316 |
inventoryItemBilledQtyMap.get(customerReturnItem.getInventoryItemId()) - 1);
|
| 317 |
}
|
317 |
}
|
| 318 |
}
|
318 |
}
|
| Line 332... |
Line 332... |
| 332 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
332 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
| 333 |
model.addAttribute("markDefective", this.markDefective(fofoOrder));
|
333 |
model.addAttribute("markDefective", this.markDefective(fofoOrder));
|
| 334 |
return "sale-details";
|
334 |
return "sale-details";
|
| 335 |
}
|
335 |
}
|
| 336 |
|
336 |
|
| 337 |
private void markDoa(FofoOrder fofoOrder, FofoOrderItem foi) {
|
337 |
private void markDoa(FofoOrder fofoOrder, FofoOrderItem foi, boolean isAdmin) {
|
| 338 |
if (foi.getBrand().equals("Nokia") && foi.getCost() < 4990) {
|
338 |
if(isAdmin) {
|
| 339 |
foi.setDoa(true);
|
339 |
foi.setDoa(true);
|
| - |
|
340 |
return;
|
| 340 |
}
|
341 |
}
|
| 341 |
LocalDateTime buyDate = fofoOrder.getCreateTimestamp().truncatedTo(ChronoUnit.DAYS);
|
342 |
LocalDateTime buyDate = fofoOrder.getCreateTimestamp().truncatedTo(ChronoUnit.DAYS);
|
| 342 |
LocalDateTime curDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
343 |
LocalDateTime curDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
| 343 |
if (buyDate.isAfter(curDate.minusDays(45))) {
|
344 |
if (buyDate.isAfter(curDate.minusDays(45))) {
|
| 344 |
foi.setDoa(true);
|
345 |
foi.setDoa(true);
|
| Line 586... |
Line 587... |
| 586 |
throws ProfitMandiBusinessException {
|
587 |
throws ProfitMandiBusinessException {
|
| 587 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
588 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 588 |
|
589 |
|
| 589 |
Map<String, Object> map = orderService.getSaleHistory(loginDetails.getFofoId(), searchType, searchValue,
|
590 |
Map<String, Object> map = orderService.getSaleHistory(loginDetails.getFofoId(), searchType, searchValue,
|
| 590 |
startTime, endTime, offset, 100);
|
591 |
startTime, endTime, offset, 100);
|
| 591 |
List<FofoOrder> fofoOrders = (List<FofoOrder>)map.get("saleHistories");
|
592 |
List<FofoOrder> fofoOrders = (List<FofoOrder>) map.get("saleHistories");
|
| 592 |
|
593 |
|
| 593 |
if(fofoOrders.size() == 0) {
|
594 |
if (fofoOrders.size() == 0) {
|
| 594 |
throw new ProfitMandiBusinessException("Search criteria", "", "No orders found for criteria");
|
595 |
throw new ProfitMandiBusinessException("Search criteria", "", "No orders found for criteria");
|
| 595 |
}
|
596 |
}
|
| 596 |
|
597 |
|
| 597 |
final HttpHeaders headers = new HttpHeaders();
|
598 |
final HttpHeaders headers = new HttpHeaders();
|
| 598 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
599 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
| 599 |
headers.set("Content-disposition", "inline; filename=invoices.pdf");
|
600 |
headers.set("Content-disposition", "inline; filename=invoices.pdf");
|
| 600 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
601 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| 601 |
List<PdfModel> pdfModels = new ArrayList<>();
|
602 |
List<PdfModel> pdfModels = new ArrayList<>();
|
| 602 |
for(FofoOrder fofoOrder : fofoOrders) {
|
603 |
for (FofoOrder fofoOrder : fofoOrders) {
|
| 603 |
try {
|
604 |
try {
|
| 604 |
pdfModels.add(orderService.getInvoicePdfModel(fofoOrder.getId()));
|
605 |
pdfModels.add(orderService.getInvoicePdfModel(fofoOrder.getId()));
|
| 605 |
} catch(Exception e) {
|
606 |
} catch(Exception e) {
|
| 606 |
LOGGER.info("could not create invoice for {}, invoice number {}", fofoOrder.getId(), fofoOrder.getInvoiceNumber());
|
607 |
LOGGER.info("could not create invoice for {}, invoice number {}", fofoOrder.getId(), fofoOrder.getInvoiceNumber());
|
| 607 |
}
|
608 |
}
|