Skip to content

Commit

Permalink
OP-1187 | Add function for printing inventory report (#1442)
Browse files Browse the repository at this point in the history
* Add function for printing inventory repport

* Add review remark

* Add function for printing inventory report

* Apply change request

* Applying suggestions for change

* Applying suggestions for change

---------

Co-authored-by: loique70 <[email protected]>
Co-authored-by: Alessandro Domanico <[email protected]>
  • Loading branch information
3 people authored Nov 18, 2024
1 parent 5c891a4 commit ff3ee06
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions src/main/java/org/isf/stat/manager/JasperReportsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.isf.generaldata.MessageBundle;
import org.isf.hospital.manager.HospitalBrowsingManager;
import org.isf.hospital.model.Hospital;
import org.isf.medicalinventory.model.MedicalInventory;
import org.isf.medicals.model.Medical;
import org.isf.patient.model.Patient;
import org.isf.patient.service.PatientIoOperations;
Expand Down Expand Up @@ -966,11 +967,11 @@ private void addBundleParameter(String jasperFileFolder, String jasperFileName,

/*
* Jasper Reports may contain subreports and we should pass also those. The parent report must contain parameters like:
*
*
* SUBREPORT_RESOURCE_BUNDLE_1 SUBREPORT_RESOURCE_BUNDLE_2 SUBREPORT_RESOURCE_BUNDLE_...
*
*
* and pass them as REPORT_RESOURCE_BUNDLE to each related subreport.
*
*
* If nothing is passed, subreports still work, but REPORT_LOCALE will be used (if passed to the subreport) and corresponding bundle (UTF-8 decoding not
* available)
*/
Expand Down Expand Up @@ -1084,7 +1085,7 @@ public String compileDefaultFilename(String defaultFileName) {

/**
* Converts a {@link LocalDateTime} to a {@link Date}.
*
*
* @param localDateTime the localDateTime to convert.
* @return the converted value or {@code null} if the passed value is {@code null}.
*/
Expand All @@ -1096,4 +1097,31 @@ private static Date toDate(LocalDate localDate) {
return Optional.ofNullable(localDate).map(t -> Date.from(t.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())).orElse(null);
}

}
public JasperReportResultDto getInventoryReportPdf(MedicalInventory inventory, String jasperFileName, int printRealQty) throws OHServiceException {
try {
String status = inventory.getStatus();
Map<String, Object> parameters = new HashMap<>(getHospitalParameters());
parameters.put("inventoryId", String.valueOf(inventory.getId()));
parameters.put("inventoryReference", inventory.getInventoryReference());
parameters.put("inventoryStatus", status != null ? status : inventory.getStatus());
parameters.put("printRealQty", printRealQty);

LocalDateTime inventoryDateTime = inventory.getInventoryDate();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DD_MM_YYYY);
String formattedDate = inventoryDateTime.format(formatter);
parameters.put("inventoryDate", formattedDate);

String pdfFilename = compilePDFFilename(RPT_BASE, jasperFileName, Arrays.asList(String.valueOf(inventory.getId())), "pdf ");
LOGGER.info("Generated PDF File: {}", pdfFilename);

JasperReportResultDto result = generateJasperReport(compileJasperFilename(RPT_BASE, jasperFileName), pdfFilename, parameters);
JasperExportManager.exportReportToPdfFile(result.getJasperPrint(), pdfFilename);

return result;
} catch (Exception e) {
LOGGER.error("", e);
throw new OHServiceException(e, new OHExceptionMessage(MessageBundle.getMessage(STAT_REPORTERROR_MSG)));
}
}

}

0 comments on commit ff3ee06

Please sign in to comment.