From 4a3aec72ce7efa6009f9641b7988fe83f94958be Mon Sep 17 00:00:00 2001 From: Piyankara N W M G P Date: Wed, 24 Jul 2024 15:09:39 +0530 Subject: [PATCH] Signed-off-by: Piyankara N W M G P closes Issue#6527 --- .../StorePurchaseOrderRequestController.java | 147 +++++++++++++++--- src/main/resources/META-INF/persistence.xml | 4 +- ...store_purhcase_order_list_to_approve.xhtml | 9 ++ .../store/store_purhcase_order_request.xhtml | 7 + 4 files changed, 142 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/divudi/bean/store/StorePurchaseOrderRequestController.java b/src/main/java/com/divudi/bean/store/StorePurchaseOrderRequestController.java index 0741c6028c..0c6d745323 100644 --- a/src/main/java/com/divudi/bean/store/StorePurchaseOrderRequestController.java +++ b/src/main/java/com/divudi/bean/store/StorePurchaseOrderRequestController.java @@ -7,7 +7,7 @@ import com.divudi.bean.common.CommonController; import com.divudi.bean.common.ItemController; import com.divudi.bean.common.SessionController; - +import com.divudi.bean.common.NotificationController; import com.divudi.data.BillClassType; import com.divudi.data.BillNumberSuffix; import com.divudi.data.BillType; @@ -28,7 +28,9 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.ejb.EJB; import javax.enterprise.context.SessionScoped; import javax.inject.Inject; @@ -69,6 +71,11 @@ public class StorePurchaseOrderRequestController implements Serializable { StoreCalculation storeCalculation; private boolean printPreview; + @Inject + NotificationController notificationController; + + private double totalBillItemsCount; + public void removeSelected() { // //System.err.println("1"); if (selectedBillItems == null) { @@ -219,7 +226,6 @@ public void saveBillComponent() { // PharmaceuticalBillItem tmpPh = b.getPharmaceuticalBillItem(); // b.setPharmaceuticalBillItem(null); - if (b.getId() == null) { getBillItemFacade().create(b); } else { @@ -244,7 +250,97 @@ public void createOrderWithItems() { } - public void request() { + public void finalizeBill() { + if (currentBill == null) { + JsfUtil.addErrorMessage("No Bill"); + return; + } + if (currentBill.getId() == null) { + request(); + } + getCurrentBill().setEditedAt(new Date()); + getCurrentBill().setEditor(sessionController.getLoggedUser()); + getCurrentBill().setCheckeAt(new Date()); + getCurrentBill().setCheckedBy(sessionController.getLoggedUser()); + getCurrentBill().setBillTypeAtomic(BillTypeAtomic.PHARMACY_ORDER); + getBillFacade().edit(getCurrentBill()); + notificationController.createNotification(getCurrentBill()); + + } + + public List generateBillItems(Bill bill) { + String jpql = "select bi " + + " from BillItem bi " + + " where bi.retired=:ret " + + " and bi.bill=:bill"; + Map m = new HashMap(); + m.put("ret", false); + m.put("bill", bill); + return billItemFacade.findByJpql(jpql, m); + } + + public void resetBillValues() { + currentBill = null; + currentBillItem = null; + billItems = null; + printPreview = false; + } + + public String navigateToUpdatePurchaseOrder() { + if (currentBill == null) { + JsfUtil.addErrorMessage("No Bill"); + return ""; + } + Bill tmpBill = currentBill; + resetBillValues(); + setCurrentBill(tmpBill); + setBillItems(generateBillItems(currentBill)); +// for(BillItem bi: getBillItems()){ +// System.out.println("bi = " + bi.getPharmaceuticalBillItem()); +// if(bi.getPharmaceuticalBillItem()==null){ +// bi.setPharmaceuticalBillItem(generatePharmaceuticalBillItem(bi)); +// } +// } + calTotal(); + return "/store/store_purhcase_order_request.xhtml?faces-redirect=true"; + } + + public void finalizeBillComponent() { + getBillItems().removeIf(BillItem::isRetired); + for (BillItem b : getBillItems()) { + b.setRate(b.getPharmaceuticalBillItem().getPurchaseRateInUnit()); + b.setNetValue(b.getPharmaceuticalBillItem().getQtyInUnit() * b.getPharmaceuticalBillItem().getPurchaseRateInUnit()); + b.setBill(getCurrentBill()); + b.setCreatedAt(new Date()); + b.setCreater(getSessionController().getLoggedUser()); + + double qty = 0.0; + qty = b.getQty() + b.getPharmaceuticalBillItem().getFreeQty(); + if (qty <= 0.0) { + b.setRetired(true); + b.setRetirer(sessionController.getLoggedUser()); + b.setRetiredAt(new Date()); + b.setRetireComments("Retired at Finalising PO"); + + } + totalBillItemsCount = totalBillItemsCount + qty; +// PharmaceuticalBillItem tmpPh = b.getPharmaceuticalBillItem(); +// b.setPharmaceuticalBillItem(null); + if (b.getId() == null) { + getBillItemFacade().create(b); + } else { + getBillItemFacade().edit(b); + } + + if (b.getPharmaceuticalBillItem().getId() == null) { + getPharmaceuticalBillItemFacade().create(b.getPharmaceuticalBillItem()); + } else { + getPharmaceuticalBillItemFacade().edit(b.getPharmaceuticalBillItem()); + } + } + } + + public void save() { Date startTime = new Date(); Date fromDate = null; Date toDate = null; @@ -253,33 +349,38 @@ public void request() { JsfUtil.addErrorMessage("Please Select Paymntmethod"); return; } - - if (getCurrentBill().getToInstitution() == null) { - JsfUtil.addErrorMessage("Distributor ?"); - return; - } - - if (getBillItems().isEmpty()) { - JsfUtil.addErrorMessage("Please Select Item or Items"); + if (getBillItems() == null || getBillItems().isEmpty()) { + JsfUtil.addErrorMessage("Please add bill items"); return; } - -// -// if (checkItemPrice()) { -// JsfUtil.addErrorMessage("Please enter purchase price for all"); -// return; -// } - calTotal(); - saveBill(); saveBillComponent(); + JsfUtil.addSuccessMessage("Request Saved"); + } - JsfUtil.addSuccessMessage("Request Succesfully Created"); + public void request() { + Date startTime = new Date(); + Date fromDate = null; + Date toDate = null; - printPreview = true; - - + if (getCurrentBill().getPaymentMethod() == null) { + JsfUtil.addErrorMessage("Please Select Paymntmethod"); + return; + } + if (getBillItems() == null || getBillItems().isEmpty()) { + JsfUtil.addErrorMessage("Please add bill items"); + return; + } + finalizeBill(); + totalBillItemsCount = 0; + finalizeBillComponent(); + if (totalBillItemsCount == 0) { + JsfUtil.addErrorMessage("Please add item quantities for the bill"); + return; + } + JsfUtil.addSuccessMessage("Request Succesfully Finalized"); + printPreview = true; } public void calTotal() { diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml index 6d8623993e..42fe5625f4 100644 --- a/src/main/resources/META-INF/persistence.xml +++ b/src/main/resources/META-INF/persistence.xml @@ -2,14 +2,14 @@ - jdbc/arogya + jdbc/hims false - jdbc/arogyaAudit + jdbc/himsAduit false diff --git a/src/main/webapp/store/store_purhcase_order_list_to_approve.xhtml b/src/main/webapp/store/store_purhcase_order_list_to_approve.xhtml index 02cbc7b72e..78d6444585 100644 --- a/src/main/webapp/store/store_purhcase_order_list_to_approve.xhtml +++ b/src/main/webapp/store/store_purhcase_order_list_to_approve.xhtml @@ -120,6 +120,15 @@ + + + +