Jump to content
We've recently updated our Privacy Statement, available here ×

Solve the error


Recommended Posts

@Override

public ResponseEntity<?> getInvoiceReport(Long id) {

try {

Optional<InvoiceReport> invReport = reportDao.invoiceDetailsById(id);

if (invReport.isPresent()) {

Optional<BillingMaster> billMasterOptional = billDao.findById(id);

BillingMasterDTO billDtoList = returnBillProduct(billMasterOptional.get());

JRBeanCollectionDataSource billDtlsList = new JRBeanCollectionDataSource(

billDtoList.getBillingDetails());

 

InvoiceReport invoiceReport = invReport.get();

 

Map<String, Object> params = new HashMap<>();

params.put("billDtlsList", billDtlsList);

params.put("instituteName", invoiceReport.getInstituteName());

params.put("instituteAddress", invoiceReport.getInstituteAddress());

params.put("institutePhone", invoiceReport.getInstitutePhone());

params.put("instituteGst", invoiceReport.getInstituteGst());

params.put("customerName", invoiceReport.getCustomerName());

params.put("customerPhone", invoiceReport.getCustomerPhone());

params.put("customerAddress", invoiceReport.getCustomerAddress());

params.put("customerGst", invoiceReport.getCustomerGst());

params.put("billDate", invoiceReport.getBillDate());

params.put("jobNo", invoiceReport.getJobNo());

params.put("vehicleModel", invoiceReport.getVehicleModel());

params.put("meterReading", invoiceReport.getMeterReading());

params.put("referenceNo", invoiceReport.getReferenceNo());

 

Resource template = new ClassPathResource("/templates/reports/Invoice.jrxml");

JasperReport jasperReport = JasperCompileManager.compileReport(template.getInputStream());

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());

byte[] pdfData = JasperExportManager.exportReportToPdf(jasperPrint);

 

HttpHeaders headers = new HttpHeaders();

headers.add("Content-Disposition", "inline; filename=Invoice.pdf");

return ResponseEntity.ok().headers(headers).contentType(MediaType.APPLICATION_PDF).body(pdfData);

 

} else {

return new ResponseEntity<>("Collection Id Not Found", HttpStatus.NOT_FOUND);

}

} catch (IOException | JRException e) {

e.printStackTrace();

return new ResponseEntity<>("Error generating PDF", HttpStatus.INTERNAL_SERVER_ERROR);

}

}

@Repository

public interface IReportDAO extends JpaRepository<InvoiceReport, Long>{

 

@Query(value="select bm.id,getofficename(bm.institute_id) as institute_name,getofficeaddress(bm.institute_id) as institute_address, "

+ " getofficephone(bm.institute_id) as institute_phone, getofficegst(bm.institute_id) as institute_gst,"

+ " getcustomername(bm.customer_id) as customer_name,getcustomeraddress(bm.customer_id) as customer_address,"

+ " getcustomerphone(bm.customer_id) as customer_phone,getcustomerpin(bm.customer_id) as customer_pin,"

+ " getcustomergst(bm.customer_id) as customer_gst,getcustomervehiclemodel(bm.customer_id) as vehicle_model,"

+ " getcustomervehicle(bm.customer_id) as vehicle_no,getjobkms(bm.job_no) as meter_reading,"

+ " bm.invoice_no,bm.bill_date,bm.reference_no,bm.job_no"

+ " from billing_master bm where bm.id=:id ",nativeQuery = true)

Optional<InvoiceReport> invoiceDetailsById(Long id);

 

 

}

private BillingMasterDTO returnBillProduct(BillingMaster bill) {

BillingMasterDTO masterDto = new BillingMasterDTO();

BeanUtils.copyProperties(bill, masterDto);

 

List<BillingDetailsDTO> billDtlsDto = bill.getBillingDetails().stream().map(billDetails -> {

BillingDetailsDTO billDto = new BillingDetailsDTO();

BeanUtils.copyProperties(billDetails, billDto);

billDto.setItemId(billDetails.getItemId());

billDto.setItemName(billDetails.getItemName());

billDto.setHsnCode(billDetails.getHsnCode());

billDto.setQuantity(billDetails.getQuantity());

billDto.setRate(billDetails.getRate());

return billDto;

 

}).collect(Collectors.toList());

masterDto.setBillingDetails(billDtlsDto);

return masterDto;

}

correct the error
 

net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :

1. Parameter not found : billDtlsList

2. Unknown dataset name Dataset1.

Invoice.jrxml

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...