Subversion Repositories SmartDukaan

Rev

Rev 28515 | Rev 28540 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 28515 Rev 28538
Line 655... Line 655...
655
		} else {
655
		} else {
656
			fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
656
			fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
657
		}
657
		}
658
		float openingBalance = walletService.getOpeningTillExcludingPurchase(fofoId, startDate);
658
		float openingBalance = walletService.getOpeningTillExcludingPurchase(fofoId, startDate);
659
		float closingBalance = walletService.getOpeningTillExcludingPurchase(fofoId, endDate);
659
		float closingBalance = walletService.getOpeningTillExcludingPurchase(fofoId, endDate);
-
 
660
		UserWallet uw = walletService.getUserWallet(fofoId);
660
		List<AccountStatementModel> accountModels = userWalletRepository.getStatement(fofoId, startDate, endDate)
661
		List<UserWalletHistory> history = userWalletHistoryRepository.selectPaginatedByWalletId(uw.getId(), startDate, endDate, 0, 0);
661
				.stream().filter(x -> !x.getWalletReferenceType().equals(WalletReferenceType.PURCHASE))
662
		history = history.stream().filter(x -> !x.getReferenceType().equals(WalletReferenceType.PURCHASE))
662
				.collect(Collectors.toList());
663
				.collect(Collectors.toList());
663
		Map<WalletReferenceType, AccountStatementModel> accountModelsMap = accountModels.stream()
-
 
664
				.collect(Collectors.toMap(AccountStatementModel::getWalletReferenceType, x -> x));
-
 
665
		InputStream is = getClass().getClassLoader().getResourceAsStream("account-statement.xlsx");
664
		InputStream is = getClass().getClassLoader().getResourceAsStream("account-statement.xlsx");
666
		String partnerName = retailerService.getAllFofoRetailerIdNameMap().get(fofoId);
665
		String partnerName = retailerService.getAllFofoRetailerIdNameMap().get(fofoId);
667
		List<StatementDetailModel> details = orderRepository.selectDetailsBetween(fofoId, startDate, endDate);
666
		List<StatementDetailModel> details = orderRepository.selectDetailsBetween(fofoId, startDate, endDate);
668
		float openingAmount = orderRepository.selectOpeningAmount(fofoId, startDate);
667
		float openingAmount = orderRepository.selectOpeningAmount(fofoId, startDate);
669
		float closingAmount = orderRepository.selectOpeningAmount(fofoId, endDate);
668
		float closingAmount = orderRepository.selectOpeningAmount(fofoId, endDate);
670
		LOGGER.info("Opening - {}, Closing - {}", openingAmount, closingAmount);
669
		LOGGER.info("Opening - {}, Closing - {}", openingAmount, closingAmount);
671
		ByteArrayOutputStream byteArrayOutputStream = this.populateData(is, openingBalance - openingAmount,
670
		ByteArrayOutputStream byteArrayOutputStream = this.populateData(is, openingBalance - openingAmount,
672
				closingBalance - closingAmount, partnerName, accountModelsMap, startDate, endDate, details);
671
				closingBalance - closingAmount, partnerName, history, startDate, endDate, details);
673
 
672
 
674
		final HttpHeaders headers = new HttpHeaders();
673
		final HttpHeaders headers = new HttpHeaders();
675
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
674
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
676
		headers.set("Content-disposition",
675
		headers.set("Content-disposition",
677
				"inline; filename=account-statement." + StringUtils.toHyphenatedString(startDate.toLocalDate()) + "-"
676
				"inline; filename=account-statement." + StringUtils.toHyphenatedString(startDate.toLocalDate()) + "-"
Line 684... Line 683...
684
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
683
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
685
 
684
 
686
	}
685
	}
687
 
686
 
688
	private ByteArrayOutputStream populateData(InputStream is, float openingBalance, float closingBalance,
687
	private ByteArrayOutputStream populateData(InputStream is, float openingBalance, float closingBalance,
689
			String partnerName, Map<WalletReferenceType, AccountStatementModel> accountModels, LocalDateTime startDate,
688
			String partnerName, List<UserWalletHistory> history, LocalDateTime startDate,
690
			LocalDateTime endDate, List<StatementDetailModel> invoiceDetails) throws Exception {
689
			LocalDateTime endDate, List<StatementDetailModel> invoiceDetails) throws Exception {
691
		XSSFWorkbook workbook = new XSSFWorkbook(is);
690
		XSSFWorkbook workbook = new XSSFWorkbook(is);
692
		CreationHelper creationHelper = workbook.getCreationHelper();
691
		CreationHelper creationHelper = workbook.getCreationHelper();
693
		CellStyle style2 = workbook.createCellStyle();
692
		CellStyle style2 = workbook.createCellStyle();
694
		style2.setDataFormat(creationHelper.createDataFormat().getFormat(
693
		style2.setDataFormat(creationHelper.createDataFormat().getFormat(
Line 703... Line 702...
703
				.setCellValue(new Date(endDate.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
702
				.setCellValue(new Date(endDate.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
704
		sheet.getRow(2).getCell(2).setCellValue(openingBalance);
703
		sheet.getRow(2).getCell(2).setCellValue(openingBalance);
705
		long grandTotalDebit = 0l;
704
		long grandTotalDebit = 0l;
706
		long grandTotalCredit = 0l;
705
		long grandTotalCredit = 0l;
707
		int row = 4;
706
		int row = 4;
708
		for (Map.Entry<WalletReferenceType, AccountStatementModel> walletRow : accountModels.entrySet()) {
707
		for (UserWalletHistory walletEntry : history) {
709
			sheet.createRow(row).createCell(0).setCellValue(walletRow.getKey().toString());
708
			sheet.createRow(row).createCell(0).setCellValue(walletEntry.getReferenceType().toString());
-
 
709
			if(walletEntry.getAmount() > 0) {
-
 
710
				sheet.getRow(row).createCell(1).setCellValue(0);
710
			sheet.getRow(row).createCell(1).setCellValue(walletRow.getValue().getDebit());
711
				sheet.getRow(row).createCell(2).setCellValue(walletEntry.getAmount());
-
 
712
				grandTotalCredit += walletEntry.getAmount();
-
 
713
			} else {
711
			sheet.getRow(row).createCell(2).setCellValue(walletRow.getValue().getCredit());
714
				sheet.getRow(row).createCell(1).setCellValue(walletEntry.getAmount());
-
 
715
				sheet.getRow(row).createCell(2).setCellValue(0);
712
			grandTotalDebit += walletRow.getValue().getDebit();
716
				grandTotalDebit += walletEntry.getAmount();
-
 
717
			}
713
			grandTotalCredit += walletRow.getValue().getCredit();
718
			Cell dateCell = sheet.getRow(row).createCell(3);
-
 
719
			dateCell.setCellValue(new Date(walletEntry.getTimestamp().atZone( ZoneId.systemDefault()).toInstant().toEpochMilli()));
-
 
720
			dateCell.setCellStyle(style2);
-
 
721
			sheet.getRow(row).createCell(3).setCellValue(walletEntry.getDescription());
-
 
722
			sheet.getRow(row).createCell(3).setCellValue(walletEntry.getReference());
714
			row++;
723
			row++;
715
		}
724
		}
716
		for (StatementDetailModel statementDetailModel : invoiceDetails) {
725
		for (StatementDetailModel statementDetailModel : invoiceDetails) {
717
			sheet.createRow(row).createCell(0).setCellValue(statementDetailModel.getInvoiceNumber());
726
			sheet.createRow(row).createCell(0).setCellValue("BILLING");
718
			if (statementDetailModel.getAmount() > 0) {
727
			if (statementDetailModel.getAmount() > 0) {
719
				sheet.getRow(row).createCell(1).setCellValue(statementDetailModel.getAmount());
728
				sheet.getRow(row).createCell(1).setCellValue(statementDetailModel.getAmount());
720
				sheet.getRow(row).createCell(2).setCellValue(0);
729
				sheet.getRow(row).createCell(2).setCellValue(0);
721
				grandTotalDebit += statementDetailModel.getAmount(); 
730
				grandTotalDebit += statementDetailModel.getAmount(); 
722
			} else {
731
			} else {
Line 726... Line 735...
726
			}
735
			}
727
			Cell dateCell = sheet.getRow(row).createCell(3);
736
			Cell dateCell = sheet.getRow(row).createCell(3);
728
			dateCell.setCellValue(statementDetailModel.getOnDate());
737
			dateCell.setCellValue(statementDetailModel.getOnDate());
729
			dateCell.setCellStyle(style2);
738
			dateCell.setCellStyle(style2);
730
			
739
			
-
 
740
			sheet.getRow(row).createCell(4).setCellValue(statementDetailModel.getReferenceType());
-
 
741
			sheet.getRow(row).createCell(5).setCellValue(statementDetailModel.getInvoiceNumber());
731
			
742
			
732
 
743
 
733
			row += 1;
744
			row += 1;
734
		}
745
		}
735
		sheet.createRow(row).createCell(0).setCellValue("Grand Total");
746
		sheet.createRow(row).createCell(0).setCellValue("Grand Total");