diff --git a/src/main/java/com/reporting/controller/ReportingController.java b/src/main/java/com/reporting/controller/ReportingController.java index 3ac0e1e..c73756b 100644 --- a/src/main/java/com/reporting/controller/ReportingController.java +++ b/src/main/java/com/reporting/controller/ReportingController.java @@ -2299,4 +2299,51 @@ public class ReportingController { } } + @RequestMapping(value = {"/laporan-smpk-satusehat"}, method = {RequestMethod.GET}) + public void handleSMPKSatuSehat( + @RequestParam("tglAwal") String tglAwal, + @RequestParam("tglAkhir") String tglAkhir, + @RequestParam(value = "noregistrasi", required = false, defaultValue = "") String noregistrasi, + @RequestParam(value = "format", required = false, defaultValue = "pdf") String format, + @RequestParam(value = "mode", required = false, defaultValue = "download") String mode, + @RequestParam(value = "printBy", required = false, defaultValue = "") String printBy, + HttpServletResponse response) throws Exception { + + JasperPrint jasperPrint = null; + try { + // Generate report (common for both PDF/Excel) + jasperPrint = this.reportingService.exportSMPKSatuSehat(tglAwal, tglAkhir, noregistrasi, printBy); + + if ("excel".equalsIgnoreCase(format)) { + // Handle Excel export + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader("Content-Disposition", "attachment; filename=Laporan_Satusehat_SMPK.xlsx"); + + JRXlsxExporter exporter = new JRXlsxExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + SimpleXlsxReportConfiguration config = new SimpleXlsxReportConfiguration(); + config.setOnePagePerSheet(false); + config.setDetectCellType(true); + config.setCollapseRowSpan(false); + config.setRemoveEmptySpaceBetweenRows(true); + config.setWhitePageBackground(false); + exporter.setConfiguration(config); + exporter.exportReport(); + + } else { + // Handle PDF preview + response.setContentType("application/pdf"); + response.setHeader("Content-Disposition", "inline; filename=Laporan_Satusehat_SMPK.pdf"); + + JRPdfExporter exporter = new JRPdfExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + exporter.exportReport(); + } + } finally { + jasperPrint = null; + } + } + } diff --git a/src/main/java/com/reporting/dao/ReportingDao.java b/src/main/java/com/reporting/dao/ReportingDao.java index 438d257..20d5ab8 100644 --- a/src/main/java/com/reporting/dao/ReportingDao.java +++ b/src/main/java/com/reporting/dao/ReportingDao.java @@ -1584,7 +1584,7 @@ public class ReportingDao { public JasperPrint exportLpDetailResepPerDokter(Timestamp tglAwal, Timestamp tglAkhir, Integer idInstalasi, Integer idUnit, Integer idRuangan, Integer idDokter, String printBy) { try (Connection conn = this.jdbcTemplate1.getDataSource().getConnection()) { - String path = jasperDirPath + "Lap_detail_resep_perdokter.jrxml"; + String path = jaspersim2DirPath + "Lap_detail_resep_perdokter.jrxml"; JasperReport jasperReport = JasperCompileManager.compileReport(path); Map parameters = new HashMap<>(); parameters.put("tglAwal", tglAwal); @@ -1604,7 +1604,7 @@ public class ReportingDao { public JasperPrint exportMasterObat() { try (Connection conn = this.jdbcTemplate1.getDataSource().getConnection()) { - String path = jasperDirPath + "Cetakan_master_obat.jrxml"; + String path = jaspersim2DirPath + "Cetakan_master_obat.jrxml"; JasperReport jasperReport = JasperCompileManager.compileReport(path); Map parameters = new HashMap<>(); return JasperFillManager.fillReport(jasperReport, parameters, conn); @@ -1617,7 +1617,7 @@ public class ReportingDao { public JasperPrint exportWaktuTungguFarmasi(Timestamp tglAwal, Timestamp tglAkhir, Integer idInstalasi, Integer idUnit, Integer idRuangan, Integer idDokter, String printBy) { try (Connection conn = this.jdbcTemplate1.getDataSource().getConnection()) { - String path = jasperDirPath + "waktu_tunggu_farmasi.jrxml"; + String path = jaspersim2DirPath + "waktu_tunggu_farmasi.jrxml"; JasperReport jasperReport = JasperCompileManager.compileReport(path); Map parameters = new HashMap<>(); parameters.put("tglAwal", tglAwal); @@ -1635,4 +1635,21 @@ public class ReportingDao { return null; } + public JasperPrint exportSMPKSatuSehat(Timestamp tglAwal, Timestamp tglAkhir, String noregistrasi, String printBy) { + try (Connection conn = this.jdbcTemplate1.getDataSource().getConnection()) { + String path = jaspersim2DirPath + "smpk_satusehat.jrxml"; + JasperReport jasperReport = JasperCompileManager.compileReport(path); + Map parameters = new HashMap<>(); + parameters.put("tglAwal", tglAwal); + parameters.put("tglAkhir", tglAkhir); + parameters.put("noregistrasi", noregistrasi); + parameters.put("printBy", printBy); + return JasperFillManager.fillReport(jasperReport, parameters, conn); + } catch (Exception var15) { + LOG.error("Exception at exportSMPKSatuSehat"); + LOG.error(ReportingDao.class, var15); + } + return null; + } + } diff --git a/src/main/java/com/reporting/service/ReportingService.java b/src/main/java/com/reporting/service/ReportingService.java index be1f39d..39ba8bd 100644 --- a/src/main/java/com/reporting/service/ReportingService.java +++ b/src/main/java/com/reporting/service/ReportingService.java @@ -584,4 +584,17 @@ public class ReportingService { } } + public JasperPrint exportSMPKSatuSehat(String tglAwal, String tglAkhir, String noregistrasi, String printBy) { + log.info("Starting exportSMPKSatuSehat with tglAwal: {}, tglAkhir: {}, noregistrasi: {}, printBy: {}", tglAwal, tglAkhir, noregistrasi, printBy); + try { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + Timestamp parse = new Timestamp(formatter.parse(tglAwal).getTime()); + Timestamp parse2 = new Timestamp(formatter.parse(tglAkhir).getTime()); + return this.reportingDao.exportSMPKSatuSehat(parse, parse2, noregistrasi, printBy); + } catch (ParseException e) { + log.error(e.getMessage()); + return null; + } + } + } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 9e39b57..856c689 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -32,6 +32,6 @@ spring.mvc.dispatch-trace-request=true spring.main.banner-mode=off application.jasper-xml.dir-path=/mnt/files/jasper-xml/ application.jasper-xml.dir-bintaro-path=/mnt/files/jasper-xml-bintaro/ -application.jasper-xml.dir-sim2-path=D:/mnt/files/jasper-xml-sim2/ +application.jasper-xml.dir-sim2-path=/mnt/files/jasper-xml-sim2/ application.pdf.dir-sep=/mnt/files/sep/ application.pdf.dir-lis=/mnt/lis/ \ No newline at end of file