Skip to content

Commit

Permalink
#10583 stock ledger improvement (#10623)
Browse files Browse the repository at this point in the history
* Signed-off-by: pubudu piyankara <[email protected]>

* Signed-off-by: pubudu piyankara <[email protected]>

* Signed-off-by: pubudu piyankara <[email protected]>
  • Loading branch information
Pubudu-Piyankara authored Feb 18, 2025
1 parent bea77b7 commit fd00a63
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public void settleDirectIssue() {
//Addinng Staff
// System.out.println("//Addinng Staff = ");
System.out.println(i.getPharmaceuticalBillItem() + " 1 " + i.getPharmaceuticalBillItem().getQtyInUnit() + " " + getIssuedBill().getToStaff());
Stock staffStock = pharmacyBean.addToStockWihtoutStockHistory(i.getPharmaceuticalBillItem(),
Stock staffStock = pharmacyBean.addToStock(i.getPharmaceuticalBillItem(),
Math.abs(i.getPharmaceuticalBillItem().getQtyInUnit()), getIssuedBill().getToStaff());

i.getPharmaceuticalBillItem().setStaffStock(staffStock);
Expand Down Expand Up @@ -611,7 +611,7 @@ public void settle() {
if (returnFlag) {

//Addinng Staff
Stock staffStock = pharmacyBean.addToStockWihtoutStockHistory(i.getPharmaceuticalBillItem(),
Stock staffStock = pharmacyBean.addToStock(i.getPharmaceuticalBillItem(),
Math.abs(i.getPharmaceuticalBillItem().getQtyInUnit()), getIssuedBill().getToStaff());

i.getPharmaceuticalBillItem().setStaffStock(staffStock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void settle() {
double qty = Math.abs(i.getPharmaceuticalBillItem().getQtyInUnit());

// Deduct Staff Stock
boolean returnFlag = getPharmacyBean().deductFromStockWithoutStockHistory(tmpPh, Math.abs(qty), getIssuedBill().getToStaff());
boolean returnFlag = getPharmacyBean().deductFromStock(tmpPh, Math.abs(qty), getIssuedBill().getToStaff());

if (returnFlag) {
// Add Stock To Department
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2003,6 +2003,9 @@ public void processStockLedgerReport() {
jpql += "and s.item=:itm ";
m.put("itm", item);
}
if ("transferReceiveDoc".equals(documentType) || "transferIssueDoc".equals(documentType)) {
jpql += " and s.department IS NOT NULL ";
}

jpql += " order by s.createdAt ";
stockLedgerHistories = facade.findByJpql(jpql, m, TemporalType.TIMESTAMP);
Expand Down
49 changes: 0 additions & 49 deletions src/main/java/com/divudi/ejb/PharmacyBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -472,28 +472,6 @@ public Stock addToStock(PharmaceuticalBillItem pharmaceuticalBillItem, double qt
return s;
}

public Stock addToStockWihtoutStockHistory(PharmaceuticalBillItem pharmaceuticalBillItem, double qty, Staff staff) {
String sql;
HashMap hm = new HashMap();
sql = "Select s from Stock s where s.itemBatch=:bc and s.staff=:stf";
hm.put("bc", pharmaceuticalBillItem.getItemBatch());
hm.put("stf", staff);
Stock s = getStockFacade().findFirstByJpql(sql, hm);
if (s == null) {
s = new Stock();
s.setStaff(staff);
s.setItemBatch(pharmaceuticalBillItem.getItemBatch());
}
if (s.getId() == null || s.getId() == 0) {
s.setStock(s.getStock() + qty);
getStockFacade().create(s);
} else {
s.setStock(s.getStock() + qty);
getStockFacade().edit(s);
}
return s;
}

public Stock addToStock(PharmaceuticalBillItem pharmaceuticalBillItem, double qty, Department department) {
String sql;
HashMap hm = new HashMap();
Expand Down Expand Up @@ -578,33 +556,6 @@ public boolean deductFromStock(PharmaceuticalBillItem pharmaceuticalBillItem, do
return true;
}

public boolean deductFromStockWithoutStockHistory(PharmaceuticalBillItem pharmaceuticalBillItem, double qty, Staff staff) {
String sql;
HashMap hm = new HashMap();
sql = "Select s from Stock s where s.itemBatch=:batch "
+ "and s.staff=:stf";
hm.put("batch", pharmaceuticalBillItem.getItemBatch());
hm.put("stf", staff);
Stock s = getStockFacade().findFirstByJpql(sql, hm);
if (s == null) {
s = new Stock();
s.setStaff(staff);
s.setItemBatch(pharmaceuticalBillItem.getItemBatch());
}
if (s.getStock() < qty) {
return false;
}

if (s.getId() == null || s.getId() == 0) {
s.setStock(s.getStock() - qty);
getStockFacade().create(s);
} else {
s.setStock(s.getStock() - qty);
getStockFacade().edit(s);
}
return true;
}

public boolean deductFromStock(ItemBatch batch, double qty, Department department, boolean minusAllowed) {
if (!minusAllowed) {
return deductFromStock(batch, qty, department);
Expand Down

0 comments on commit fd00a63

Please sign in to comment.