From e9c11ddd830cde9495855e9bb1968bb44edffa8c Mon Sep 17 00:00:00 2001 From: Pubudu-Piyankara Date: Mon, 23 Dec 2024 17:36:39 +0530 Subject: [PATCH 1/7] Signed-off-by: Pubudu-Piyankara --- src/main/webapp/reports/inventoryReports/consumption.xhtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/reports/inventoryReports/consumption.xhtml b/src/main/webapp/reports/inventoryReports/consumption.xhtml index 8867077d32..90ed7e075f 100644 --- a/src/main/webapp/reports/inventoryReports/consumption.xhtml +++ b/src/main/webapp/reports/inventoryReports/consumption.xhtml @@ -342,7 +342,7 @@ - + From 6c7211932debb73a8bdfcd7fb344b63e9cbb4626 Mon Sep 17 00:00:00 2001 From: Pubudu-Piyankara Date: Mon, 23 Dec 2024 17:44:09 +0530 Subject: [PATCH 2/7] Signed-off-by: Pubudu-Piyankara --- .../inventoryReports/consumption.xhtml | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/main/webapp/reports/inventoryReports/consumption.xhtml b/src/main/webapp/reports/inventoryReports/consumption.xhtml index 90ed7e075f..96e0661f24 100644 --- a/src/main/webapp/reports/inventoryReports/consumption.xhtml +++ b/src/main/webapp/reports/inventoryReports/consumption.xhtml @@ -302,16 +302,6 @@ - - - - - - - - - - @@ -381,23 +371,12 @@ - - - - - - - - - - - - + From 9e26b69a6386cdc4cd05624e89f1657515402862 Mon Sep 17 00:00:00 2001 From: Pubudu-Piyankara Date: Mon, 23 Dec 2024 22:14:46 +0530 Subject: [PATCH 3/7] Signed-off-by: Pubudu-Piyankara --- .../bean/pharmacy/PharmacyController.java | 91 ++++++++++++-- .../data/DepartmentCategoryWiseItems.java | 112 ++++++++++++++++++ .../inventoryReports/consumption.xhtml | 19 +-- 3 files changed, 208 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/divudi/data/DepartmentCategoryWiseItems.java diff --git a/src/main/java/com/divudi/bean/pharmacy/PharmacyController.java b/src/main/java/com/divudi/bean/pharmacy/PharmacyController.java index a8e11bb42e..396b4ffd8a 100644 --- a/src/main/java/com/divudi/bean/pharmacy/PharmacyController.java +++ b/src/main/java/com/divudi/bean/pharmacy/PharmacyController.java @@ -54,6 +54,7 @@ import com.divudi.bean.common.util.JsfUtil; import com.divudi.data.BillClassType; import com.divudi.data.BillTypeAtomic; +import com.divudi.data.DepartmentCategoryWiseItems; import com.divudi.data.PaymentMethod; import com.divudi.data.dataStructure.CategoryWithItem; import com.divudi.data.dataStructure.PharmacySummery; @@ -737,6 +738,7 @@ public void deleteMultipleAmpps() { private List billItems; private List departmentSummaries; private List issueDepartmentCategoryWiseItems; + private List resultsList; private String transferType; private Institution FromSite; @@ -936,13 +938,7 @@ public void createConsumptionReportTable() { bills = null; billItems = null; - generateConsumptionReportTableByDepartmentAndCategoryWise(); - - } else { - bills = null; - billItems = null; - departmentSummaries = null; - generateConsumptionReportTableByDepartmentAndCategoryWise(); + generateConsumptionReportTableByDepartmentAndCategoryWise(BillType.PharmacyIssue); } @@ -1227,6 +1223,79 @@ public void generateConsumptionReportTableByDepartmentAndCategoryWise() { } } + public List generateConsumptionReportTableByDepartmentAndCategoryWise(BillType billType) { + Map parameters = new HashMap<>(); + String jpql = "SELECT new com.divudi.data.DepartmentCategoryWiseItems(" + + "bi.bill.department, " + + "bi.bill.toDepartment, " + + "bi.item, " + + "bi.item.category, " + + "SUM(bi.qty * bi.pharmaceuticalBillItem.purchaseRate), " + + "bi.pharmaceuticalBillItem.purchaseRate, " + + "SUM(bi.qty)) " + + "FROM BillItem bi " + + "WHERE bi.retired = false AND bi.bill.retired = false " + + "AND bi.bill.createdAt BETWEEN :fromDate AND :toDate " + + "AND bi.bill.billType = :billType "; + + // Mandatory parameters + parameters.put("fromDate", fromDate); + parameters.put("toDate", toDate); + parameters.put("billType", billType); + + // Dynamic filters + if (institution != null) { + jpql += "AND bi.bill.institution = :institution "; + parameters.put("institution", institution); + } + + if (site != null) { + jpql += "AND bi.bill.department.site = :site "; + parameters.put("site", site); + } + + if (dept != null) { + jpql += "AND bi.bill.department = :department "; + parameters.put("department", dept); + } + + if (category != null) { + jpql += "AND bi.item.category = :category "; + parameters.put("category", category); + } + + if (item != null) { + jpql += "AND bi.item = :item "; + parameters.put("item", item); + } + + if (toDepartment != null) { + jpql += "AND bi.bill.toDepartment = :toDepartment "; + parameters.put("toDepartment", toDepartment); + } + + // Group by clause + jpql += "GROUP BY bi.bill.department, bi.bill.toDepartment, bi.item, bi.item.category, bi.pharmaceuticalBillItem.purchaseRate " + + "ORDER BY bi.bill.toDepartment, bi.item.category"; + + try { + resultsList = (List) getBillItemFacade().findLightsByJpql(jpql, parameters, TemporalType.TIMESTAMP); + + if (resultsList.isEmpty()) { + FacesContext.getCurrentInstance().addMessage(null, + new FacesMessage(FacesMessage.SEVERITY_WARN, "No Data", "No records found for the selected criteria.")); + return Collections.emptyList(); + } + + return resultsList; + } catch (Exception e) { + e.printStackTrace(); + FacesContext.getCurrentInstance().addMessage(null, + new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Failed to generate report. Please try again.")); + return Collections.emptyList(); + } + } + public List calculateTotals(List billList) { data = new ArrayList<>(); @@ -3748,4 +3817,12 @@ public void setToSite(Institution toSite) { this.toSite = toSite; } + public List getResultsList() { + return resultsList; + } + + public void setResultsList(List resultsList) { + this.resultsList = resultsList; + } + } diff --git a/src/main/java/com/divudi/data/DepartmentCategoryWiseItems.java b/src/main/java/com/divudi/data/DepartmentCategoryWiseItems.java new file mode 100644 index 0000000000..c9b5ee2d94 --- /dev/null +++ b/src/main/java/com/divudi/data/DepartmentCategoryWiseItems.java @@ -0,0 +1,112 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package com.divudi.data; + +import com.divudi.entity.Category; +import com.divudi.entity.Department; +import com.divudi.entity.Item; + +/** + * + * @author Pubudu Piyankara + */ +public class DepartmentCategoryWiseItems { + + + private Department mainDepartment; + private Department consumptionDepartment; + private Item item; + private Category category; + private Double netTotal; + private Double purchaseRate; + private double qty; + private double paidAmount; + + public DepartmentCategoryWiseItems(){ } + + public DepartmentCategoryWiseItems( + Department mainDepartment, + Department consumptionDepartment, + Item item, + Category category, + Double netTotal, + Double purchaseRate, + double qty + ) { + this.mainDepartment = mainDepartment; + this.consumptionDepartment = consumptionDepartment; + this.item = item; + this.category = category; + this.netTotal = netTotal; + this.purchaseRate = purchaseRate; + this.qty = qty; + } + + public Department getMainDepartment() { + return mainDepartment; + } + + public void setMainDepartment(Department mainDepartment) { + this.mainDepartment = mainDepartment; + } + + public Department getConsumptionDepartment() { + return consumptionDepartment; + } + + public void setConsumptionDepartment(Department consumptionDepartment) { + this.consumptionDepartment = consumptionDepartment; + } + + public Item getItem() { + return item; + } + + public void setItem(Item item) { + this.item = item; + } + + public Category getCategory() { + return category; + } + + public void setCategory(Category category) { + this.category = category; + } + + public Double getNetTotal() { + return netTotal; + } + + public void setNetTotal(Double netTotal) { + this.netTotal = netTotal; + } + + public Double getPurchaseRate() { + return purchaseRate; + } + + public void setPurchaseRate(Double purchaseRate) { + this.purchaseRate = purchaseRate; + } + + public double getQty() { + return qty; + } + + public void setQty(double qty) { + this.qty = qty; + } + + public double getPaidAmount() { + return paidAmount; + } + + public void setPaidAmount(double paidAmount) { + this.paidAmount = paidAmount; + } + + +} diff --git a/src/main/webapp/reports/inventoryReports/consumption.xhtml b/src/main/webapp/reports/inventoryReports/consumption.xhtml index 96e0661f24..124015909e 100644 --- a/src/main/webapp/reports/inventoryReports/consumption.xhtml +++ b/src/main/webapp/reports/inventoryReports/consumption.xhtml @@ -284,11 +284,12 @@ - + - + + @@ -366,7 +367,8 @@ - + + @@ -391,7 +393,7 @@
Department Summary
- + + + - + - + @@ -425,7 +430,7 @@ - + From e8acf1bc4f03c63e888e7e9adec4347a21099617 Mon Sep 17 00:00:00 2001 From: Pubudu-Piyankara Date: Mon, 23 Dec 2024 23:53:58 +0530 Subject: [PATCH 4/7] Signed-off-by: Pubudu-Piyankara closed #9783 --- .../bean/pharmacy/PharmacyController.java | 103 +++++++++++++----- .../data/dataStructure/PharmacySummery.java | 15 +++ .../inventoryReports/consumption.xhtml | 7 ++ 3 files changed, 100 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/divudi/bean/pharmacy/PharmacyController.java b/src/main/java/com/divudi/bean/pharmacy/PharmacyController.java index 396b4ffd8a..4c6f347140 100644 --- a/src/main/java/com/divudi/bean/pharmacy/PharmacyController.java +++ b/src/main/java/com/divudi/bean/pharmacy/PharmacyController.java @@ -912,36 +912,32 @@ public void generateGRNReportTable() { } public void createConsumptionReportTable() { + resetFields(); - if ("byBillItem".equals(reportType)) { + switch (reportType) { + case "byBillItem": + generateConsumptionReportTableByBillItems(BillType.PharmacyIssue); + break; - bills = null; - departmentSummaries = null; - issueDepartmentCategoryWiseItems = null; - generateConsumptionReportTableByBillItems(BillType.PharmacyIssue); - - } else if ("byBill".equals(reportType)) { + case "byBill": + generateConsumptionReportTableByBill(BillType.PharmacyIssue); + break; - billItems = null; - departmentSummaries = null; - issueDepartmentCategoryWiseItems = null; - generateConsumptionReportTableByBill(BillType.PharmacyIssue); - - } else if ("summeryReport".equals(reportType)) { - - bills = null; - billItems = null; - issueDepartmentCategoryWiseItems = null; - generateConsumptionReportTableAsSummary(BillType.PharmacyIssue); - - } else if ("categoryWise".equals(reportType)) { - - bills = null; - billItems = null; - generateConsumptionReportTableByDepartmentAndCategoryWise(BillType.PharmacyIssue); + case "summeryReport": + case "categoryWise": + generateConsumptionReportTableByDepartmentAndCategoryWise(BillType.PharmacyIssue); + break; + default: + throw new IllegalArgumentException("Invalid report type: " + reportType); } + } + private void resetFields() { + bills = null; + billItems = null; + departmentSummaries = null; + issueDepartmentCategoryWiseItems = null; } public void generateConsumptionReportTableByBill(BillType billType) { @@ -989,7 +985,7 @@ public void generateConsumptionReportTableByBill(BillType billType) { } totalPurchase = 0.0; for (Bill i : bills) { - totalPurchase += i.getNetTotal(); + totalPurchase += i.getPaidAmount(); } } @@ -1115,6 +1111,7 @@ public void generateConsumptionReportTableAsSummary(BillType billType) { } } + @Deprecated public void generateConsumptionReportTableByDepartmentAndCategoryWise() { totalPurchase = 0.0; grantIssueQty = 0.0; @@ -1287,6 +1284,15 @@ public List generateConsumptionReportTableByDepartm return Collections.emptyList(); } + totalPurchase = 0.0; + grantIssueQty = 0.0; + for (DepartmentCategoryWiseItems i : resultsList) { + totalPurchase += i.getNetTotal(); + grantIssueQty += i.getQty(); + } + if ("summeryReport".equals(reportType)) { + generateConsumptionReportTableAsDepartmentSummary(resultsList); + } return resultsList; } catch (Exception e) { e.printStackTrace(); @@ -1296,6 +1302,53 @@ public List generateConsumptionReportTableByDepartm } } + public void generateConsumptionReportTableAsDepartmentSummary(List list) { + // Initialize department summaries and reset total sales value + departmentSummaries = new ArrayList<>(); + totalSaleValue = 0.0; + + // Create a map to store net totals grouped by main and consumption departments + Map> departmentTotals = new HashMap<>(); + + // Populate the map with department-wise data + for (DepartmentCategoryWiseItems item : list) { + String mainDepartmentName = item.getMainDepartment().getName(); + String consumptionDepartmentName = item.getConsumptionDepartment().getName(); + double paidAmount = item.getNetTotal(); + + // Initialize nested maps if necessary + departmentTotals.putIfAbsent(mainDepartmentName, new HashMap<>()); + Map consumptionMap = departmentTotals.get(mainDepartmentName); + + // Accumulate paid amounts for consumption departments + consumptionMap.put(consumptionDepartmentName, + consumptionMap.getOrDefault(consumptionDepartmentName, 0.0) + paidAmount); + + // Accumulate the total sale value for the main department + totalSaleValue += paidAmount; + } + + // Build the summaries + for (Map.Entry> mainEntry : departmentTotals.entrySet()) { + String mainDepartmentName = mainEntry.getKey(); + Map consumptionMap = mainEntry.getValue(); + + // Add a header entry for the main department + departmentSummaries.add(new PharmacySummery(mainDepartmentName, null, null)); // Main department header + + // Add each consumption department's contribution + for (Map.Entry consumptionEntry : consumptionMap.entrySet()) { + String consumptionDepartmentName = consumptionEntry.getKey(); + double netTotal = consumptionEntry.getValue(); + departmentSummaries.add(new PharmacySummery(null, consumptionDepartmentName, netTotal)); + } + + // Add a total entry for the main department + double mainTotal = consumptionMap.values().stream().mapToDouble(Double::doubleValue).sum(); + departmentSummaries.add(new PharmacySummery("Total", null, mainTotal)); + } + } + public List calculateTotals(List billList) { data = new ArrayList<>(); diff --git a/src/main/java/com/divudi/data/dataStructure/PharmacySummery.java b/src/main/java/com/divudi/data/dataStructure/PharmacySummery.java index 5656f7a103..4bf311cfb9 100644 --- a/src/main/java/com/divudi/data/dataStructure/PharmacySummery.java +++ b/src/main/java/com/divudi/data/dataStructure/PharmacySummery.java @@ -6,6 +6,7 @@ package com.divudi.data.dataStructure; import com.divudi.data.table.String1Value3; +import com.divudi.entity.Department; import java.util.List; /** @@ -21,11 +22,17 @@ public class PharmacySummery { private Long count; private String departmentName; private double netTotal; + private String department; public PharmacySummery(String departmentName, double netTotal) { this.departmentName = departmentName; this.netTotal = netTotal; } + public PharmacySummery(String departmentName, String department, double netTotal) { + this.departmentName = departmentName; + this.department = department; + this.netTotal = netTotal; + } public PharmacySummery() { } @@ -86,4 +93,12 @@ public void setNetTotal(double netTotal) { this.netTotal = netTotal; } + public String getDepartment() { + return department; + } + + public void setDepartment(String department) { + this.department = department; + } + } diff --git a/src/main/webapp/reports/inventoryReports/consumption.xhtml b/src/main/webapp/reports/inventoryReports/consumption.xhtml index 124015909e..db351bf49d 100644 --- a/src/main/webapp/reports/inventoryReports/consumption.xhtml +++ b/src/main/webapp/reports/inventoryReports/consumption.xhtml @@ -246,11 +246,18 @@ + + + + + + + > From cc02b2813493c616589afc7efe5ea5caa498084a Mon Sep 17 00:00:00 2001 From: Pubudu-Piyankara Date: Mon, 23 Dec 2024 23:56:43 +0530 Subject: [PATCH 5/7] Signed-off-by: Pubudu-Piyankara --- .../java/com/divudi/bean/pharmacy/PharmacyController.java | 5 +++-- src/main/webapp/reports/inventoryReports/consumption.xhtml | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/divudi/bean/pharmacy/PharmacyController.java b/src/main/java/com/divudi/bean/pharmacy/PharmacyController.java index 4c6f347140..507dd99af3 100644 --- a/src/main/java/com/divudi/bean/pharmacy/PharmacyController.java +++ b/src/main/java/com/divudi/bean/pharmacy/PharmacyController.java @@ -938,6 +938,7 @@ private void resetFields() { billItems = null; departmentSummaries = null; issueDepartmentCategoryWiseItems = null; + resultsList = null; } public void generateConsumptionReportTableByBill(BillType billType) { @@ -1048,7 +1049,7 @@ public void generateConsumptionReportTableByBillItems(BillType billType) { totalPurchase += i.getQty() * i.getPharmaceuticalBillItem().getPurchaseRate(); } } - +@Deprecated public void generateConsumptionReportTableAsSummary(BillType billType) { // Initialize bill types List bt = new ArrayList<>(); @@ -1334,7 +1335,7 @@ public void generateConsumptionReportTableAsDepartmentSummary(List consumptionMap = mainEntry.getValue(); // Add a header entry for the main department - departmentSummaries.add(new PharmacySummery(mainDepartmentName, null, null)); // Main department header + departmentSummaries.add(new PharmacySummery(mainDepartmentName, null, 0.0)); // Main department header // Add each consumption department's contribution for (Map.Entry consumptionEntry : consumptionMap.entrySet()) { diff --git a/src/main/webapp/reports/inventoryReports/consumption.xhtml b/src/main/webapp/reports/inventoryReports/consumption.xhtml index db351bf49d..f003d53c5c 100644 --- a/src/main/webapp/reports/inventoryReports/consumption.xhtml +++ b/src/main/webapp/reports/inventoryReports/consumption.xhtml @@ -441,7 +441,8 @@ - + + From e0f48787c968beb7226021f6d0bfe6af7c949dee Mon Sep 17 00:00:00 2001 From: Pubudu-Piyankara Date: Mon, 23 Dec 2024 23:57:49 +0530 Subject: [PATCH 6/7] Signed-off-by: Pubudu-Piyankara --- src/main/webapp/reports/inventoryReports/consumption.xhtml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/webapp/reports/inventoryReports/consumption.xhtml b/src/main/webapp/reports/inventoryReports/consumption.xhtml index f003d53c5c..fc76c90335 100644 --- a/src/main/webapp/reports/inventoryReports/consumption.xhtml +++ b/src/main/webapp/reports/inventoryReports/consumption.xhtml @@ -433,7 +433,8 @@ - + + From 3c5cb4373ec59d672c02881a7230ff3bd95f2aef Mon Sep 17 00:00:00 2001 From: Pubudu-Piyankara Date: Tue, 24 Dec 2024 00:14:00 +0530 Subject: [PATCH 7/7] Signed-off-by: Pubudu-Piyankara --- src/main/java/com/divudi/bean/pharmacy/PharmacyController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/divudi/bean/pharmacy/PharmacyController.java b/src/main/java/com/divudi/bean/pharmacy/PharmacyController.java index 507dd99af3..66d160a872 100644 --- a/src/main/java/com/divudi/bean/pharmacy/PharmacyController.java +++ b/src/main/java/com/divudi/bean/pharmacy/PharmacyController.java @@ -1049,7 +1049,8 @@ public void generateConsumptionReportTableByBillItems(BillType billType) { totalPurchase += i.getQty() * i.getPharmaceuticalBillItem().getPurchaseRate(); } } -@Deprecated + + @Deprecated public void generateConsumptionReportTableAsSummary(BillType billType) { // Initialize bill types List bt = new ArrayList<>();