@Transactional @Override public void generateStatementPdf(final Long billId) { try { BillMaster billMaster = this.billMasterRepository.findOne(billId); final String fileLocation = FileUtils.MIFOSX_BASE_DIR; /** Recursively create the directory if it does not exist * */ if (!new File(fileLocation).isDirectory()) { new File(fileLocation).mkdirs(); } final String statementDetailsLocation = fileLocation + File.separator + "StatementPdfFiles"; if (!new File(statementDetailsLocation).isDirectory()) { new File(statementDetailsLocation).mkdirs(); } final String printStatementLocation = statementDetailsLocation + File.separator + "Bill_" + billMaster.getId() + ".pdf"; final String jpath = fileLocation + File.separator + "jasper"; final String tenant = ThreadLocalContextUtil.getTenant().getTenantIdentifier(); final String jfilepath = jpath + File.separator + "Statement_" + tenant + ".jasper"; File destinationFile = new File(jfilepath); if (!destinationFile.exists()) { File sourceFile = new File( this.getClass().getClassLoader().getResource("Files/Statement.jasper").getFile()); FileUtils.copyFileUsingApacheCommonsIO(sourceFile, destinationFile); } final Connection connection = this.dataSource.getConnection(); Map<String, Object> parameters = new HashMap<String, Object>(); final Integer id = Integer.valueOf(billMaster.getId().toString()); parameters.put("param1", id); parameters.put("SUBREPORT_DIR", jpath + "" + File.separator); final JasperPrint jasperPrint = JasperFillManager.fillReport(jfilepath, parameters, connection); JasperExportManager.exportReportToPdfFile(jasperPrint, printStatementLocation); billMaster.setFileName(printStatementLocation); this.billMasterRepository.save(billMaster); connection.close(); System.out.println("Filling report successfully..."); } catch (final DataIntegrityViolationException ex) { LOGGER.error("Filling report failed..." + ex.getLocalizedMessage()); System.out.println("Filling report failed..."); ex.printStackTrace(); } catch (final JRException | JRRuntimeException e) { LOGGER.error("Filling report failed..." + e.getLocalizedMessage()); System.out.println("Filling report failed..."); e.printStackTrace(); } catch (final Exception e) { LOGGER.error("Filling report failed..." + e.getLocalizedMessage()); System.out.println("Filling report failed..."); e.printStackTrace(); } }
@Transactional @Override public String generateInovicePdf(final Long invoiceId) { final String fileLocation = FileUtils.MIFOSX_BASE_DIR; /** Recursively create the directory if it does not exist * */ if (!new File(fileLocation).isDirectory()) { new File(fileLocation).mkdirs(); } final String InvoiceDetailsLocation = fileLocation + File.separator + "InvoicePdfFiles"; if (!new File(InvoiceDetailsLocation).isDirectory()) { new File(InvoiceDetailsLocation).mkdirs(); } final String printInvoiceLocation = InvoiceDetailsLocation + File.separator + "Invoice_" + invoiceId + ".pdf"; final Integer id = Integer.valueOf(invoiceId.toString()); try { final String jpath = fileLocation + File.separator + "jasper"; final String tenant = ThreadLocalContextUtil.getTenant().getTenantIdentifier(); final String jasperfilepath = jpath + File.separator + "Invoicereport_" + tenant + ".jasper"; File destinationFile = new File(jasperfilepath); if (!destinationFile.exists()) { File sourceFile = new File( this.getClass() .getClassLoader() .getResource("Files/Invoicereport.jasper") .getFile()); FileUtils.copyFileUsingApacheCommonsIO(sourceFile, destinationFile); } final Connection connection = this.dataSource.getConnection(); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("param1", id); final JasperPrint jasperPrint = JasperFillManager.fillReport(jasperfilepath, parameters, connection); JasperExportManager.exportReportToPdfFile(jasperPrint, printInvoiceLocation); connection.close(); System.out.println("Filling report successfully..."); } catch (final DataIntegrityViolationException ex) { LOGGER.error("Filling report failed..." + ex.getLocalizedMessage()); System.out.println("Filling report failed..."); ex.printStackTrace(); } catch (final JRException | JRRuntimeException e) { LOGGER.error("Filling report failed..." + e.getLocalizedMessage()); System.out.println("Filling report failed..."); e.printStackTrace(); } catch (final Exception e) { LOGGER.error("Filling report failed..." + e.getLocalizedMessage()); System.out.println("Filling report failed..."); e.printStackTrace(); } return printInvoiceLocation; }
@Override public CommandProcessingResult updateBillMaster( final List<BillDetail> billDetails, final BillMaster billMaster, final BigDecimal clientBalance) { try { BigDecimal chargeAmount = BigDecimal.ZERO; BigDecimal adjustmentAmount = BigDecimal.ZERO; BigDecimal paymentAmount = BigDecimal.ZERO; BigDecimal dueAmount = BigDecimal.ZERO; BigDecimal taxAmount = BigDecimal.ZERO; BigDecimal oneTimeSaleAmount = BigDecimal.ZERO; BigDecimal serviceTransferAmount = BigDecimal.ZERO; BigDecimal depositRefundAmount = BigDecimal.ZERO; for (final BillDetail billDetail : billDetails) { if ("SERVICE_CHARGES".equalsIgnoreCase(billDetail.getTransactionType())) { if (billDetail.getAmount() != null) chargeAmount = chargeAmount.add(billDetail.getAmount()); } else if ("TAXES".equalsIgnoreCase(billDetail.getTransactionType())) { if (billDetail.getAmount() != null) taxAmount = taxAmount.add(billDetail.getAmount()); } else if ("ADJUSTMENT".equalsIgnoreCase(billDetail.getTransactionType())) { if (billDetail.getAmount() != null) adjustmentAmount = adjustmentAmount.add(billDetail.getAmount()); } else if (billDetail.getTransactionType().contains("PAYMENT")) { if (billDetail.getAmount() != null) paymentAmount = paymentAmount.add(billDetail.getAmount()); } else if ("ONETIME_CHARGES".equalsIgnoreCase(billDetail.getTransactionType())) { if (billDetail.getAmount() != null) oneTimeSaleAmount = oneTimeSaleAmount.add(billDetail.getAmount()); } else if ("SERVICE_TRANSFER".equalsIgnoreCase(billDetail.getTransactionType())) { if (billDetail.getAmount() != null) serviceTransferAmount = serviceTransferAmount.add(billDetail.getAmount()); } else if ("DEPOSIT&REFUND".equalsIgnoreCase(billDetail.getTransactionType())) { if (billDetail.getAmount() != null) depositRefundAmount = depositRefundAmount.add(billDetail.getAmount()); } } dueAmount = chargeAmount .add(taxAmount) .add(oneTimeSaleAmount) .add(clientBalance) .add(depositRefundAmount) .add(serviceTransferAmount) .subtract(paymentAmount) .subtract(adjustmentAmount); billMaster.setChargeAmount(chargeAmount.add(oneTimeSaleAmount).add(serviceTransferAmount)); billMaster.setAdjustmentAmount(adjustmentAmount); billMaster.setTaxAmount(taxAmount); billMaster.setPaidAmount(paymentAmount); billMaster.setDueAmount(dueAmount); billMaster.setPreviousBalance(clientBalance); billMaster.setDepositRefundAmount(depositRefundAmount); this.billMasterRepository.save(billMaster); return new CommandProcessingResult(billMaster.getId(), billMaster.getClientId()); } catch (DataIntegrityViolationException dve) { LOGGER.error("unable to retrieve data" + dve.getLocalizedMessage()); return CommandProcessingResult.empty(); } }