diff --git a/src/main/java/com/reporting/controller/ReportingController.java b/src/main/java/com/reporting/controller/ReportingController.java index 07f9acf..d37d6d5 100644 --- a/src/main/java/com/reporting/controller/ReportingController.java +++ b/src/main/java/com/reporting/controller/ReportingController.java @@ -336,6 +336,7 @@ public class ReportingController { response.setContentType("application/pdf"); JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream()); } +/* @RequestMapping(value = {"/bukti-layanan-farmasi/{norec}/{user}"}, method = {RequestMethod.GET}) public void exportPdfBuktiLayanan(@PathVariable("norec") String norec, @@ -345,6 +346,7 @@ public class ReportingController { response.setContentType("application/pdf"); JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream()); } +*/ @RequestMapping(value = {"/bukti-nonlayanan-farmasi/{norec}"}, method = {RequestMethod.GET}) public void exportPdfBuktiNoLayanFarmasi(@PathVariable("norec") String norec, @@ -1174,4 +1176,49 @@ public class ReportingController { } } + @RequestMapping(value = {"/laporan-pendapatan-poli"}, method = {RequestMethod.GET}) + public void handleLpPendapatanPoli( + @RequestParam("tglAwal") String tglAwal, + @RequestParam("tglAkhir") String tglAkhir, + @RequestParam(value = "IdDepartemen", required = false, defaultValue = "") Integer IdDepartemen, + @RequestParam(value = "IdRuangan", required = false, defaultValue = "") Integer IdRuangan, + @RequestParam(value = "IdKelompokPasien", required = false, defaultValue = "") Integer IdKelompokPasien, + @RequestParam(value = "IdDokter", required = false, defaultValue = "") Integer IdDokter, + @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 { + + // Generate report (common for both PDF/Excel) + JasperPrint jasperPrint = this.reportingService.exportLpPendapatanPoli(tglAwal, tglAkhir, IdDepartemen, IdRuangan, IdKelompokPasien, IdDokter, printBy); + + if ("excel".equalsIgnoreCase(format)) { + // Handle Excel export + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader("Content-Disposition", "attachment; filename=Laporan_Pendapatan_Poli.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_Pendapatan_Poli.pdf"); + + JRPdfExporter exporter = new JRPdfExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + exporter.exportReport(); + } + } + } diff --git a/src/main/java/com/reporting/dao/ReportingDao.java b/src/main/java/com/reporting/dao/ReportingDao.java index 0b93d01..ce784c6 100644 --- a/src/main/java/com/reporting/dao/ReportingDao.java +++ b/src/main/java/com/reporting/dao/ReportingDao.java @@ -620,6 +620,7 @@ public class ReportingDao { } return null; } +/* public JasperPrint exportPdfBuktiLayanan(String norec, String user) { try (Connection conn = this.jdbcTemplate1.getDataSource().getConnection()) { @@ -635,6 +636,7 @@ public class ReportingDao { } return null; } +*/ public JasperPrint exportPdfBuktiNoLayanFarmasi(String norec) { try (Connection conn = this.jdbcTemplate1.getDataSource().getConnection()) { @@ -1370,4 +1372,24 @@ public class ReportingDao { return null; } + public JasperPrint exportLpPendapatanPoli(Timestamp tglAwal, Timestamp tglAkhir, Integer IdDepartemen, Integer IdRuangan, Integer IdKelompokPasien, Integer IdDokter, String printBy) { + try (Connection conn = this.jdbcTemplate1.getDataSource().getConnection()) { + String path = jasperDirPath + "laporan_pendapatan_poli.jrxml"; + JasperReport jasperReport = JasperCompileManager.compileReport(path); + Map parameters = new HashMap<>(); + parameters.put("tglAwal", tglAwal); + parameters.put("tglAkhir", tglAkhir); + parameters.put("IdDepartemen", IdDepartemen); + parameters.put("IdRuangan", IdRuangan); + parameters.put("IdKelompokPasien", IdKelompokPasien); + parameters.put("IdDokter", IdDokter); + parameters.put("printBy", printBy); + return JasperFillManager.fillReport(jasperReport, parameters, conn); + } catch (Exception var15) { + LOG.error("Exception at exportLpPendapatanPoli"); + 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 f0721f3..bb221be 100644 --- a/src/main/java/com/reporting/service/ReportingService.java +++ b/src/main/java/com/reporting/service/ReportingService.java @@ -175,10 +175,12 @@ public class ReportingService { return this.reportingDao.exportPdfSppb(norec); } } +/* public JasperPrint exportPdfBuktiLayanan(String norec, String user) { return this.reportingDao.exportPdfBuktiLayanan(norec, user); } +*/ public JasperPrint exportPdfBuktiNoLayanFarmasi(String norec) { return this.reportingDao.exportPdfBuktiNoLayanFarmasi(norec); @@ -454,4 +456,16 @@ public class ReportingService { } } + public JasperPrint exportLpPendapatanPoli(String tglAwal, String tglAkhir, Integer IdDepartemen, Integer IdRuangan, Integer IdKelompokPasien, Integer IdDokter, String 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.exportLpPendapatanPoli(parse, parse2, IdDepartemen, IdRuangan, IdKelompokPasien, IdDokter, printBy); + } catch (ParseException e) { + log.error(e.getMessage()); + return null; + } + } + }