diff --git a/src/main/java/com/divudi/bean/common/ReportsController.java b/src/main/java/com/divudi/bean/common/ReportsController.java index d58d7fceca..d8d30a840f 100644 --- a/src/main/java/com/divudi/bean/common/ReportsController.java +++ b/src/main/java/com/divudi/bean/common/ReportsController.java @@ -335,6 +335,7 @@ public class ReportsController implements Serializable { Map>> weeklyDailyBillItemMap7to1; Map>> weeklyDailyBillItemMap1to7; + private boolean showChart; public String getDischargedStatus() { @@ -3506,7 +3507,7 @@ private void groupBills() { bundle.setGroupedBillItemsByInstitution(billMap); } - public Double calculateNetTotalByBills(List bills) { + public Double calculateNetAmountSubTotalByBills(List bills) { Double netTotal = 0.0; for (Bill bill : bills) { @@ -3516,7 +3517,7 @@ public Double calculateNetTotalByBills(List bills) { return netTotal; } - public Double calculateDiscountByBills(List bills) { + public Double calculateDiscountSubTotalByBills(List bills) { Double discount = 0.0; for (Bill bill : bills) { @@ -3632,6 +3633,111 @@ public Double calculateDueAmountNetTotal() { return dueAmountNetTotal; } + public Double calculateNetAmountNetTotal() { + double netAmountNetTotal = 0.0; + Map> billMap = bundle.getGroupedBillItemsByInstitution(); + + for (Map.Entry> entry : billMap.entrySet()) { + List bills = entry.getValue(); + + netAmountNetTotal += calculateNetAmountSubTotalByBills(bills); + } + + return netAmountNetTotal; + } + + public Double calculateGrossAmountSubTotalByBills(List bills) { + Double billTotal = 0.0; + + for (Bill bill : bills) { + billTotal += bill.getBillTotal(); + } + + return billTotal; + } + + public Double calculatePatientShareSubTotalByBills(List bills) { + Double settledAmountByPatient = 0.0; + + for (Bill bill : bills) { + settledAmountByPatient += bill.getSettledAmountByPatient(); + } + + return settledAmountByPatient; + } + + public Double calculateSponsorShareSubTotalByBills(List bills) { + Double settledAmountBySponsor = 0.0; + + for (Bill bill : bills) { + settledAmountBySponsor += bill.getSettledAmountBySponsor(); + } + + return settledAmountBySponsor; + } + + public Double calculateDueAmountSubTotalByBills(List bills) { + Double balance = 0.0; + + for (Bill bill : bills) { + balance += bill.getBalance(); + } + + return balance; + } + + public Double calculateGrossAmountNetTotal() { + double grossAmountNetTotal = 0.0; + Map> billMap = bundle.getGroupedBillItemsByInstitution(); + + for (Map.Entry> entry : billMap.entrySet()) { + List bills = entry.getValue(); + + grossAmountNetTotal += calculateGrossAmountSubTotalByBills(bills); + } + + return grossAmountNetTotal; + } + + public Double calculateDiscountNetTotal() { + double discountNetTotal = 0.0; + Map> billMap = bundle.getGroupedBillItemsByInstitution(); + + for (Map.Entry> entry : billMap.entrySet()) { + List bills = entry.getValue(); + + discountNetTotal += calculateDiscountSubTotalByBills(bills); + } + + return discountNetTotal; + } + + public Double calculatePatientShareNetTotal() { + double patientShareNetTotal = 0.0; + Map> billMap = bundle.getGroupedBillItemsByInstitution(); + + for (Map.Entry> entry : billMap.entrySet()) { + List bills = entry.getValue(); + + patientShareNetTotal += calculatePatientShareSubTotalByBills(bills); + } + + return patientShareNetTotal; + } + + public Double calculateDueAmountNetTotal() { + double dueAmountNetTotal = 0.0; + Map> billMap = bundle.getGroupedBillItemsByInstitution(); + + for (Map.Entry> entry : billMap.entrySet()) { + List bills = entry.getValue(); + + dueAmountNetTotal += calculateDueAmountSubTotalByBills(bills); + } + + return dueAmountNetTotal; + } + public Double calculateSponsorShareNetTotal() { double sponsorShareNetTotal = 0.0; Map> billMap = bundle.getGroupedBillItemsByInstitution(); @@ -3644,6 +3750,19 @@ public Double calculateSponsorShareNetTotal() { return sponsorShareNetTotal; } + + public Double calculateNetAmountNetTotal() { + double netAmountNetTotal = 0.0; + Map> billMap = bundle.getGroupedBillItemsByInstitution(); + + for (Map.Entry> entry : billMap.entrySet()) { + List bills = entry.getValue(); + + netAmountNetTotal += calculateNetAmountSubTotalByBills(bills); + } + + return sponsorShareNetTotal; + } public Double calculateNetAmountSubTotalByBills(List bills) { Double netTotal = 0.0; diff --git a/src/main/java/com/divudi/bean/lab/LabReportExportImportController.java b/src/main/java/com/divudi/bean/lab/LabReportExportImportController.java index 573499f409..6a4801309e 100644 --- a/src/main/java/com/divudi/bean/lab/LabReportExportImportController.java +++ b/src/main/java/com/divudi/bean/lab/LabReportExportImportController.java @@ -41,10 +41,14 @@ import com.divudi.data.CssVerticalAlign; import com.divudi.facade.ReportItemFacade; import com.divudi.java.CommonFunctions; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.InputStream; import static org.apache.poi.ss.usermodel.CellType.FORMULA; import static org.apache.poi.ss.usermodel.CellType.NUMERIC; import static org.apache.poi.ss.usermodel.CellType.STRING; +import org.primefaces.model.DefaultStreamedContent; +import org.primefaces.model.StreamedContent; /** * @@ -78,6 +82,7 @@ public class LabReportExportImportController implements Serializable { private List uploadedSuccessItems; private List uploadedRejectedItems; private UploadedFile file; + private StreamedContent downloadingExcel; // @@ -133,20 +138,26 @@ public List listInvestigationItemsFilteredByItemTypes(Investi return tis; } - public void export() throws IOException { + public StreamedContent export(){ if (getCurrent() == null) { JsfUtil.addErrorMessage("Pleace select Investigations "); - return; + return null; } List items = investigationItemController.getUserChangableItems(); + if (items == null) { JsfUtil.addErrorMessage("This Investigation has no InvestigationItem"); - return; + return null; } - exportInvestigationItemsToExcel(items); - JsfUtil.addSuccessMessage("Successfuly Uploaed !"); - + try { + downloadingExcel = exportInvestigationItemsToExcel(items); + } catch (IOException e) { + // Handle IOException + } + JsfUtil.addSuccessMessage("Successfuly Download !"); + return downloadingExcel; + } public void importFormat() { @@ -193,19 +204,21 @@ private String defaultIfNullOrEmpty(String value, String defaultValue) { return (value == null || value.trim().isEmpty()) ? defaultValue : value; } - public void exportInvestigationItemsToExcel(List investigationItems) throws IOException { + public StreamedContent exportInvestigationItemsToExcel(List investigationItems) throws IOException { // Define a predefined directory (e.g., user's desktop) System.out.println("Investigation Items = " + investigationItems.size()); - String userHome = System.getProperty("user.home"); - String defaultDirectory = userHome + File.separator + "Desktop"; // Change to any other directory if needed - String fileName = getCurrent().getName() + ".xlsx"; - String fullFilePath = defaultDirectory + File.separator + fileName; +// String userHome = System.getProperty("user.home"); +// String defaultDirectory = userHome + File.separator + "Desktop"; // Change to any other directory if needed +// String fullFilePath = defaultDirectory + File.separator + fileName; +// +// // Ensure the directory exists +// File file = new File(fullFilePath); +// file.getParentFile().mkdirs(); // Create parent directories if they don't exist - // Ensure the directory exists - File file = new File(fullFilePath); - file.getParentFile().mkdirs(); // Create parent directories if they don't exist + StreamedContent excelSc; // Create a new workbook and a sheet + XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("InvestigationItems"); @@ -262,17 +275,21 @@ public void exportInvestigationItemsToExcel(List investigatio sheet.autoSizeColumn(i); } - // Write the workbook to the default file path - System.out.println("Attempting to write to: " + fullFilePath); - try (FileOutputStream outputStream = new FileOutputStream(file)) { - workbook.write(outputStream); - System.out.println("Excel file created successfully at " + fullFilePath); - } catch (IOException e) { - System.out.println("Error writing Excel file: " + e.getMessage()); - e.printStackTrace(); - } finally { - workbook.close(); - } + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + workbook.write(outputStream); + workbook.close(); + + InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); + + String fileName = getCurrent().getName() + ".xlsx"; + // Set the downloading file + excelSc = DefaultStreamedContent.builder() + .name(fileName) + .contentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") + .stream(() -> inputStream) + .build(); + + return excelSc; } // @@ -762,4 +779,12 @@ public void setDataUploadController(DataUploadController dataUploadController) { } // + public StreamedContent getDownloadingExcel() { + return downloadingExcel; + } + + public void setDownloadingExcel(StreamedContent downloadingExcel) { + this.downloadingExcel = downloadingExcel; + } + } diff --git a/src/main/webapp/admin/lims/export.xhtml b/src/main/webapp/admin/lims/export.xhtml index 9ffc3e46c5..1392dfae56 100644 --- a/src/main/webapp/admin/lims/export.xhtml +++ b/src/main/webapp/admin/lims/export.xhtml @@ -11,6 +11,8 @@ + +
@@ -30,15 +32,17 @@
- +
+ value="Export" + onclick="PrimeFaces.monitorDownload(start, stop);" > + +
diff --git a/src/main/webapp/admin/lims/import_report_format.xhtml b/src/main/webapp/admin/lims/import_report_format.xhtml index a0ebfd4425..504d05581c 100644 --- a/src/main/webapp/admin/lims/import_report_format.xhtml +++ b/src/main/webapp/admin/lims/import_report_format.xhtml @@ -12,7 +12,21 @@ - + + + + + + + + +
@@ -70,7 +84,7 @@ - +
diff --git a/src/main/webapp/admin/lims/investigation.xhtml b/src/main/webapp/admin/lims/investigation.xhtml index c01eb3ddef..2b814f61d4 100644 --- a/src/main/webapp/admin/lims/investigation.xhtml +++ b/src/main/webapp/admin/lims/investigation.xhtml @@ -555,6 +555,7 @@ icon="fas fa-file-export export-icon" action="#{investigationController.navigateExportReoirtFormat()}" value="Export Format" > +