| Line 105... |
Line 105... |
| 105 |
|
105 |
|
| 106 |
@Autowired
|
106 |
@Autowired
|
| 107 |
CreditNoteService creditNoteService;
|
107 |
CreditNoteService creditNoteService;
|
| 108 |
|
108 |
|
| 109 |
@Autowired
|
109 |
@Autowired
|
| - |
|
110 |
com.spice.profitmandi.dao.repository.transaction.EInvoiceDetailsRepository eInvoiceDetailsRepository;
|
| - |
|
111 |
|
| - |
|
112 |
@Autowired
|
| - |
|
113 |
com.spice.profitmandi.dao.repository.transaction.CreditNoteLineRepository creditNoteLineRepository;
|
| - |
|
114 |
|
| - |
|
115 |
@Autowired
|
| 110 |
PriceDropIMEIRepository priceDropIMEIRepository;
|
116 |
PriceDropIMEIRepository priceDropIMEIRepository;
|
| 111 |
|
117 |
|
| 112 |
@Autowired
|
118 |
@Autowired
|
| 113 |
SchemeInOutRepository schemeInOutRepository;
|
119 |
SchemeInOutRepository schemeInOutRepository;
|
| 114 |
|
120 |
|
| Line 1710... |
Line 1716... |
| 1710 |
);
|
1716 |
);
|
| 1711 |
|
1717 |
|
| 1712 |
return orderService.downloadReportInCsv(byteArrayOutputStream, finalRows, "CN Detail Report");
|
1718 |
return orderService.downloadReportInCsv(byteArrayOutputStream, finalRows, "CN Detail Report");
|
| 1713 |
}
|
1719 |
}
|
| 1714 |
|
1720 |
|
| - |
|
1721 |
@RequestMapping(value = "/credit-note/download-all", method = RequestMethod.GET)
|
| - |
|
1722 |
public ResponseEntity<?> downloadAllCreditNotes(HttpServletRequest request,
|
| - |
|
1723 |
@RequestParam("yearMonth") YearMonth yearMonth) throws Exception {
|
| - |
|
1724 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
1725 |
if (!roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| - |
|
1726 |
return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Admin access required");
|
| - |
|
1727 |
}
|
| - |
|
1728 |
|
| - |
|
1729 |
List<CreditNote> creditNotes = creditNoteRepository.selectAllMarginsTypeByMonth(yearMonth);
|
| - |
|
1730 |
if (creditNotes.isEmpty()) {
|
| - |
|
1731 |
return ResponseEntity.noContent().build();
|
| - |
|
1732 |
}
|
| - |
|
1733 |
|
| - |
|
1734 |
// Bulk-fetch IRN and line items
|
| - |
|
1735 |
List<String> cnNumbers = creditNotes.stream().map(CreditNote::getCreditNoteNumber).collect(Collectors.toList());
|
| - |
|
1736 |
Map<String, com.spice.profitmandi.dao.entity.transaction.EInvoiceDetails> eiMap =
|
| - |
|
1737 |
eInvoiceDetailsRepository.selectByInvoiceNumbers(cnNumbers).stream()
|
| - |
|
1738 |
.collect(Collectors.toMap(com.spice.profitmandi.dao.entity.transaction.EInvoiceDetails::getInvoiceNumber, e -> e, (a, b) -> a));
|
| - |
|
1739 |
List<Integer> cnIds = creditNotes.stream().map(CreditNote::getId).collect(Collectors.toList());
|
| - |
|
1740 |
Map<Integer, List<com.spice.profitmandi.dao.entity.transaction.CreditNoteLine>> linesMap =
|
| - |
|
1741 |
creditNoteLineRepository.selectAllByCreditNoteIds(cnIds).stream()
|
| - |
|
1742 |
.collect(Collectors.groupingBy(com.spice.profitmandi.dao.entity.transaction.CreditNoteLine::getCreditNoteId));
|
| - |
|
1743 |
|
| - |
|
1744 |
// Build partner lookup
|
| - |
|
1745 |
Map<Integer, com.spice.profitmandi.common.model.CustomRetailer> retailers = retailerService.getAllFofoRetailers();
|
| - |
|
1746 |
|
| - |
|
1747 |
List<List<?>> rows = new ArrayList<>();
|
| - |
|
1748 |
for (CreditNote cn : creditNotes) {
|
| - |
|
1749 |
com.spice.profitmandi.dao.entity.transaction.EInvoiceDetails ei = eiMap.get(cn.getCreditNoteNumber());
|
| - |
|
1750 |
List<com.spice.profitmandi.dao.entity.transaction.CreditNoteLine> lines =
|
| - |
|
1751 |
linesMap.getOrDefault(cn.getId(), java.util.Collections.emptyList());
|
| - |
|
1752 |
float total = (float) lines.stream().mapToDouble(l -> l.getAmount()).sum();
|
| - |
|
1753 |
com.spice.profitmandi.common.model.CustomRetailer retailer = retailers.get(cn.getFofoId());
|
| - |
|
1754 |
String partnerName = retailer != null ? retailer.getBusinessName() : "";
|
| - |
|
1755 |
String partnerCode = retailer != null ? retailer.getCode() : "";
|
| - |
|
1756 |
|
| - |
|
1757 |
rows.add(Arrays.asList(
|
| - |
|
1758 |
cn.getCreditNoteNumber(),
|
| - |
|
1759 |
cn.getFofoId(),
|
| - |
|
1760 |
partnerCode,
|
| - |
|
1761 |
partnerName,
|
| - |
|
1762 |
com.spice.profitmandi.common.util.FormattingUtils.formatDDMMMyyyyFormatter(cn.getCnDate().toLocalDate()),
|
| - |
|
1763 |
cn.getType(),
|
| - |
|
1764 |
Math.round(total),
|
| - |
|
1765 |
ei != null ? ei.getIrn() : "",
|
| - |
|
1766 |
ei != null ? ei.getAcknowledgeNumber() : "",
|
| - |
|
1767 |
ei != null && ei.getAcknowledgeDate() != null
|
| - |
|
1768 |
? com.spice.profitmandi.common.util.FormattingUtils.formatDDMMMyyyyFormatter(ei.getAcknowledgeDate().toLocalDate())
|
| - |
|
1769 |
: ""
|
| - |
|
1770 |
));
|
| - |
|
1771 |
}
|
| 1715 |
|
1772 |
|
| - |
|
1773 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
| - |
|
1774 |
Arrays.asList("CN Number", "FofoId", "Partner Code", "Partner Name", "CN Date", "CN Type",
|
| - |
|
1775 |
"Total Amount", "IRN", "Ack Number", "IRN Ack Date"),
|
| - |
|
1776 |
rows);
|
| - |
|
1777 |
|
| - |
|
1778 |
return orderService.downloadReportInCsv(baos, rows,
|
| - |
|
1779 |
"CN Summary Report - " + yearMonth.toString());
|
| - |
|
1780 |
}
|
| 1716 |
|
1781 |
|
| 1717 |
}
|
1782 |
}
|