From 4d5ff3ea1f8c70f2ef2a26e979a33f817cff0e5c Mon Sep 17 00:00:00 2001 From: Senula88 Date: Wed, 10 Apr 2024 21:29:43 +0530 Subject: [PATCH] Signed-off-by: Senula88 --- .../divudi/bean/common/BillController.java | 131 +++++++++++++- .../com/divudi/bean/common/BillSearch.java | 2 +- src/main/resources/version.txt | 2 +- src/main/webapp/opd/batch_bill_cancel.xhtml | 164 ++++++++++++++++++ .../webapp/opd/opd_batch_bill_print.xhtml | 19 +- 5 files changed, 302 insertions(+), 16 deletions(-) create mode 100644 src/main/webapp/opd/batch_bill_cancel.xhtml diff --git a/src/main/java/com/divudi/bean/common/BillController.java b/src/main/java/com/divudi/bean/common/BillController.java index faa83834db..90771599c6 100644 --- a/src/main/java/com/divudi/bean/common/BillController.java +++ b/src/main/java/com/divudi/bean/common/BillController.java @@ -56,6 +56,7 @@ import com.divudi.facade.PaymentFacade; import com.divudi.facade.PersonFacade; import com.divudi.bean.common.util.JsfUtil; +import com.divudi.bean.opd.OpdBillController; import com.divudi.data.BillTypeAtomic; import com.divudi.data.HistoryType; import com.divudi.data.dataStructure.ComponentDetail; @@ -142,6 +143,10 @@ public class BillController implements Serializable { private EnumController enumController; @Inject CollectingCentreBillController collectingCentreBillController; + @Inject + private WebUserController webUserController; + @Inject + private OpdBillController opdBillController; /** * Class Vairables @@ -1640,13 +1645,115 @@ public List billFeesOfBillItem(BillItem billItem) { return billFeeFacade.findByJpql(jpql, m); } + public String navigateToCancelOpdBatchBill() { + if (batchBill == null) { + JsfUtil.addErrorMessage("No Batch bill is selected"); + return ""; + } + bills = billsOfBatchBill(batchBill); + paymentMethod = batchBill.getPaymentMethod(); + comment = null; + printPreview = false; + return "/opd/batch_bill_cancel?faces-redirect=true;"; + } + + public String cancelBatchBill() { + if (getBatchBill() == null) { + JsfUtil.addErrorMessage("No bill"); + return ""; + } + if (getBatchBill().getId() == null) { + JsfUtil.addErrorMessage("No Saved bill"); + return ""; + } + + if (errorsPresentOnOpdBatchBillCancellation()) { + return ""; + } + + if (!getWebUserController().hasPrivilege("OpdCancel")) { + JsfUtil.addErrorMessage("You have no privilege to cancel OPD bills. Please contact System Administrator."); + return ""; + } + + Bill cancellationBatchBill = new CancelledBill(); + cancellationBatchBill.setDepartment(sessionController.getDepartment()); + cancellationBatchBill.setInstitution(sessionController.getInstitution()); + cancellationBatchBill.setFromDepartment(batchBill.getFromDepartment()); + cancellationBatchBill.setToDepartment(batchBill.getToDepartment()); + cancellationBatchBill.setFromInstitution(batchBill.getFromInstitution()); + cancellationBatchBill.setToInstitution(batchBill.getToInstitution()); + + cancellationBatchBill.setBillType(BillType.OpdBathcBill); + cancellationBatchBill.setBillTypeAtomic(BillTypeAtomic.OPD_BATCH_BILL_CANCELLATION); + String deptId = getBillNumberGenerator().generateBillNumber(cancellationBatchBill.getDepartment(), cancellationBatchBill.getToDepartment(), cancellationBatchBill.getBillType(), cancellationBatchBill.getBillClassType()); + String insId = getBillNumberGenerator().generateBillNumber(cancellationBatchBill.getInstitution(), cancellationBatchBill.getBillType(), cancellationBatchBill.getBillClassType()); + + cancellationBatchBill.setInsId(deptId); + cancellationBatchBill.setInsId(insId); + cancellationBatchBill.setCreatedAt(new Date()); + cancellationBatchBill.setCreater(getSessionController().getLoggedUser()); + + cancellationBatchBill.setTotal(0 - Math.abs(batchBill.getTotal())); + cancellationBatchBill.setGrantTotal(0 - Math.abs(batchBill.getGrantTotal())); + cancellationBatchBill.setDiscount(0 - Math.abs(batchBill.getDiscount())); + cancellationBatchBill.setNetTotal(0 - Math.abs(batchBill.getNetTotal())); + cancellationBatchBill.setPaymentMethod(paymentMethod); + + cancellationBatchBill.setForwardReferenceBill(batchBill); + batchBill.setCancelled(true); + batchBill.setCancelledBill(cancellationBatchBill); + getBillFacade().edit(batchBill); + + getBillFacade().create(cancellationBatchBill); + + for (Bill originalBill : bills) { + System.out.println("originalBills = " + originalBill); + cancelSingleBillWhenCancellingOpdBatchBill(originalBill, cancellationBatchBill); + } + + cancellationBatchBill.copy(batchBill); + cancellationBatchBill.setBilledBill(batchBill); + + createPaymentForOpdBatchBillCancellation(cancellationBatchBill, batchBill.getPaymentMethod()); + + WebUser wb = getCashTransactionBean().saveBillCashOutTransaction(cancellationBatchBill, getSessionController().getLoggedUser()); + opdBillController.setBills(bills); + opdBillController.setBatchBill(batchBill); + getSessionController().setLoggedUser(wb); + return "/opd/opd_batch_bill_print?faces-redirect=true"; + } + + private boolean errorsPresentOnOpdBatchBillCancellation() { + if (getBatchBill().isCancelled()) { + JsfUtil.addErrorMessage("Already Cancelled. Can not cancel again"); + return true; + } + + if (getBatchBill().isRefunded()) { + JsfUtil.addErrorMessage("Already Returned. Can not cancel."); + return true; + } + + if (getPaymentMethod() == null) { + JsfUtil.addErrorMessage("Please select a payment scheme for Cancellation."); + return true; + } + + if (getComment() == null || getComment().trim().equals("")) { + JsfUtil.addErrorMessage("Please enter a comment"); + return true; + } + + return false; + } + public void cancellAllBillsOfBatchBill() { if (batchBill == null) { JsfUtil.addErrorMessage("No Batch bill is selected"); return; } bills = billsOfBatchBill(batchBill); - if (bills == null) { JsfUtil.addErrorMessage("No bills to cancel"); return; @@ -1679,7 +1786,7 @@ public void cancellAllBillsOfBatchBill() { cancellationBatchBill.setGrantTotal(0 - Math.abs(batchBill.getGrantTotal())); cancellationBatchBill.setDiscount(0 - Math.abs(batchBill.getDiscount())); cancellationBatchBill.setNetTotal(0 - Math.abs(batchBill.getNetTotal())); - cancellationBatchBill.setPaymentMethod(batchBill.getPaymentMethod()); + cancellationBatchBill.setPaymentMethod(paymentMethod); cancellationBatchBill.setForwardReferenceBill(batchBill); batchBill.setCancelled(true); @@ -1695,11 +1802,11 @@ public void cancellAllBillsOfBatchBill() { cancellationBatchBill.copy(batchBill); cancellationBatchBill.setBilledBill(batchBill); - + createPaymentForOpdBatchBillCancellation(cancellationBatchBill, batchBill.getPaymentMethod()); WebUser wb = getCashTransactionBean().saveBillCashOutTransaction(cancellationBatchBill, getSessionController().getLoggedUser()); - + getSessionController().setLoggedUser(wb); } @@ -3597,6 +3704,22 @@ public void setBatchBill(Bill batchBill) { this.batchBill = batchBill; } + public WebUserController getWebUserController() { + return webUserController; + } + + public void setWebUserController(WebUserController webUserController) { + this.webUserController = webUserController; + } + + public OpdBillController getOpdBillController() { + return opdBillController; + } + + public void setOpdBillController(OpdBillController opdBillController) { + this.opdBillController = opdBillController; + } + /** * */ diff --git a/src/main/java/com/divudi/bean/common/BillSearch.java b/src/main/java/com/divudi/bean/common/BillSearch.java index c6d54c5b59..d35cade603 100644 --- a/src/main/java/com/divudi/bean/common/BillSearch.java +++ b/src/main/java/com/divudi/bean/common/BillSearch.java @@ -2674,7 +2674,7 @@ public String navigateToCancelOpdBill() { printPreview = false; return "/opd/bill_cancel?faces-redirect=true;"; } - + public String navigateToViewOpdBill() { if (bill == null) { JsfUtil.addErrorMessage("Nothing to cancel"); diff --git a/src/main/resources/version.txt b/src/main/resources/version.txt index 642bc60c53..4c01e9a367 100644 --- a/src/main/resources/version.txt +++ b/src/main/resources/version.txt @@ -1 +1 @@ -3.0.0.20240410.16 +3.0.0.20240410.19 diff --git a/src/main/webapp/opd/batch_bill_cancel.xhtml b/src/main/webapp/opd/batch_bill_cancel.xhtml new file mode 100644 index 0000000000..53d1115056 --- /dev/null +++ b/src/main/webapp/opd/batch_bill_cancel.xhtml @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + +
+
+ + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + Bill No + + + + Billed At + + + + Billed For + + + + Net Total + + + + +
+
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+
+
+
+
+ diff --git a/src/main/webapp/opd/opd_batch_bill_print.xhtml b/src/main/webapp/opd/opd_batch_bill_print.xhtml index 2fd63f7a5f..fbf272a712 100644 --- a/src/main/webapp/opd/opd_batch_bill_print.xhtml +++ b/src/main/webapp/opd/opd_batch_bill_print.xhtml @@ -50,7 +50,7 @@ value="#{opdBillController.bills[0].patient}" target="#{patientController.current}" /> - + Batch Bill Details + + action="#{billController.navigateToCancelOpdBatchBill()}" + styleClass="m-1 ui-button-danger"> @@ -235,19 +234,19 @@ - + Batch Bill ID #{opdBillController.batchBill.id} - + Batch Bill Ins ID #{opdBillController.batchBill.insId} - + Batch Bill Dept ID #{opdBillController.batchBill.deptId} - + Net Total #{opdBillController.batchBill.netTotal}