Skip to content

Commit

Permalink
Merge pull request #6558 from hmislk/Issue#6527
Browse files Browse the repository at this point in the history
Issue#6527 Closes #6527
  • Loading branch information
Irani96 authored Jul 25, 2024
2 parents 6018b71 + a19e3b8 commit 9e498d9
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -219,7 +226,6 @@ public void saveBillComponent() {

// PharmaceuticalBillItem tmpPh = b.getPharmaceuticalBillItem();
// b.setPharmaceuticalBillItem(null);

if (b.getId() == null) {
getBillItemFacade().create(b);
} else {
Expand All @@ -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<BillItem> 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;
Expand All @@ -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() {
Expand Down
35 changes: 14 additions & 21 deletions src/main/resources/META-INF/persistence.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
<persistence-unit name="hmisPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/vfs</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.logging.level.sql" value="SEVERE"/>
<property name="eclipselink.logging.parameters" value="false"/>
<property name="javax.persistence.schema-generation.database.action" value="create-or-extend-tables"/>
</properties>
</persistence-unit>
<persistence-unit name="hmisAuditPU" transaction-type="JTA">
<jta-data-source>jdbc/vfsAudit</jta-data-source>
<class>com.divudi.entity.AuditEvent</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.logging.level.sql" value="SEVERE"/>
<property name="eclipselink.logging.parameters" value="false"/>
<property name="javax.persistence.schema-generation.database.action" value="create-or-extend-tables"/>
</properties>
</persistence-unit>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="hmisPU" transaction-type="JTA">
<jta-data-source>jdbc/hims</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="create-or-extend-tables"/>
</properties>
</persistence-unit>
<persistence-unit name="hmisAuditPU" transaction-type="JTA">
<jta-data-source>jdbc/himsAduit</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
</properties>
</persistence-unit>
</persistence>
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@
</p:column>

<p:column headerText="Actions" width="9em">
<p:commandButton
id="edit"
ajax="false"
icon="fas fa-edit"
class="ui-button-warning"
action="#{storePurchaseOrderRequestController.navigateToUpdatePurchaseOrder()}"
>
<f:setPropertyActionListener target="#{storePurchaseOrderRequestController.currentBill}" value="#{b}"/>
</p:commandButton>
<p:commandButton
id="approve"
ajax="false"
Expand Down
7 changes: 7 additions & 0 deletions src/main/webapp/store/store_purhcase_order_request.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@
</h:panelGrid>

<p:spacer height="5" />
<p:commandButton
id="btnSave"
ajax="false"
value="Save"
action="#{storePurchaseOrderRequestController.save}"
icon="pi pi-save"
class="ui-button-success m-1"/>
<p:commandButton ajax="false" value="Request"
icon="pi pi-check"
class="ui-button-success m-1"
Expand Down

0 comments on commit 9e498d9

Please sign in to comment.