| Line 824... |
Line 824... |
| 824 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
824 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
| 825 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
825 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
| 826 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
826 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 827 |
}
|
827 |
}
|
| 828 |
|
828 |
|
| 829 |
@RequestMapping(value = "/account/closing-statements", method = RequestMethod.GET)
|
- |
|
| 830 |
public ResponseEntity<?> getAccountStatement(HttpServletRequest request, @RequestParam LocalDate closingDate, Model model) throws Exception {
|
- |
|
| 831 |
boolean isAdmin = roleManager.isAdmin(cookiesProcessor.getCookiesObject(request).getRoleIds());
|
- |
|
| 832 |
if (!isAdmin) {
|
- |
|
| 833 |
throw new ProfitMandiBusinessException("Unauthorised access", "PartnerId", "Permission Denied");
|
- |
|
| 834 |
}
|
- |
|
| 835 |
LocalDateTime closingDateTime = closingDate.atStartOfDay().plusDays(1);
|
- |
|
| 836 |
|
- |
|
| 837 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
- |
|
| 838 |
Set<Integer> retailersSet = customRetailerMap.keySet();
|
- |
|
| 839 |
|
- |
|
| 840 |
Map<Integer, Float> closingPurchaseMap = orderRepository.selectOpeningAmount(closingDateTime, retailersSet);
|
- |
|
| 841 |
|
- |
|
| 842 |
Map<Integer, UserWallet> retailerWalletMap = walletService.getRetailerIdUserWalletMap(retailersSet);
|
- |
|
| 843 |
Map<Integer, Integer> walletRetailerMap = retailerWalletMap.entrySet().stream().collect(Collectors.toMap(x -> x.getValue().getId(), x -> x.getKey()));
|
- |
|
| 844 |
|
- |
|
| 845 |
Set<Integer> walletSet = walletRetailerMap.keySet();
|
- |
|
| 846 |
Map<Integer, Float> closingBalanceMap = userWalletHistoryRepository.getSumTillDateExcludingPurchase(closingDateTime, walletSet);
|
- |
|
| 847 |
|
- |
|
| 848 |
List<List<?>> rows = new ArrayList<>();
|
- |
|
| 849 |
for (Map.Entry<Integer, Float> closingWalletBalance : closingBalanceMap.entrySet()) {
|
- |
|
| 850 |
int walletId = closingWalletBalance.getKey();
|
- |
|
| 851 |
int retailerId = walletRetailerMap.get(walletId);
|
- |
|
| 852 |
if (!closingPurchaseMap.containsKey(retailerId)) {
|
- |
|
| 853 |
closingPurchaseMap.put(retailerId, closingWalletBalance.getValue());
|
- |
|
| 854 |
} else {
|
- |
|
| 855 |
closingPurchaseMap.put(retailerId, closingWalletBalance.getValue() - closingPurchaseMap.get(retailerId));
|
- |
|
| 856 |
}
|
- |
|
| 857 |
float closingValue = closingPurchaseMap.get(retailerId);
|
- |
|
| 858 |
CustomRetailer cr = customRetailerMap.get(retailerId);
|
- |
|
| 859 |
|
- |
|
| 860 |
rows.add(Arrays.asList(retailerId, cr.getBusinessName(), cr.getAddress().getCity(), cr.getAddress().getState(), closingValue));
|
- |
|
| 861 |
}
|
- |
|
| 862 |
|
- |
|
| 863 |
org.apache.commons.io.output.ByteArrayOutputStream byteArrayOutputStream = FileUtil.getCSVByteStream(Arrays.asList("Id", "Partner Name", "City", "State", "Closing Balance"), rows);
|
- |
|
| 864 |
final HttpHeaders headers = new HttpHeaders();
|
- |
|
| 865 |
headers.set("Content-Type", "text/csv");
|
- |
|
| 866 |
headers.set("Content-disposition", "inline; filename=account-statement-closing-." + StringUtils.toHyphenatedString(closingDate) + ".csv");
|
- |
|
| 867 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
- |
|
| 868 |
|
- |
|
| 869 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
- |
|
| 870 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
- |
|
| 871 |
|
- |
|
| 872 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
- |
|
| 873 |
|
- |
|
| 874 |
}
|
- |
|
| 875 |
|
- |
|
| 876 |
@RequestMapping(value = "/account/statement", method = RequestMethod.GET)
|
829 |
@RequestMapping(value = "/account/statement", method = RequestMethod.GET)
|
| 877 |
public ResponseEntity<?> getAccountStatement(HttpServletRequest request, @RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, Model model, @RequestParam(defaultValue = "0") int fofoId) throws Exception {
|
830 |
public ResponseEntity<?> getAccountStatement(HttpServletRequest request, @RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, Model model, @RequestParam(defaultValue = "0") int fofoId) throws Exception {
|
| 878 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
831 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 879 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
832 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
| 880 |
if (!isAdmin) {
|
833 |
if (!isAdmin) {
|