Skip to content

Commit

Permalink
Merge pull request #4593 from hmislk/Issue#4592
Browse files Browse the repository at this point in the history
Issue#4592
  • Loading branch information
Senula88 authored Apr 15, 2024
2 parents 59dd311 + 6a59b67 commit 8faf6c7
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/build/
/dist/
/target/
/src/main/resources/VERSION.txt
/src/main/webapp/WEB-INF/glassfish-resources.xml
/faces-config.NavData
38 changes: 30 additions & 8 deletions src/main/java/com/divudi/bean/pharmacy/GoodsReturnController.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public class GoodsReturnController implements Serializable {
private Bill returnBill;
private boolean printPreview;
private List<BillItem> billItems;

private String comment;
///////

public Bill getBill() {
Expand Down Expand Up @@ -123,12 +125,11 @@ public void setPrintPreview(boolean printPreview) {

public void onEdit(BillItem tmp) {
// PharmaceuticalBillItem tmp = (PharmaceuticalBillItem) event.getObject();

if (tmp.getPharmaceuticalBillItem().getQtyInUnit() > getPharmacyRecieveBean().calQty(tmp.getReferanceBillItem().getReferanceBillItem().getPharmaceuticalBillItem())) {
if ((tmp.getPharmaceuticalBillItem().getQtyInUnit()+tmp.getTmpFreeQty())> getPharmacyRecieveBean().calQty(tmp.getReferanceBillItem().getReferanceBillItem().getPharmaceuticalBillItem())) {
tmp.setTmpQty(0.0);
tmp.setTmpFreeQty(0.0);
JsfUtil.addErrorMessage("You cant return over than ballanced Qty ");
}

calTotal();
getPharmacyController().setPharmacyItem(tmp.getPharmaceuticalBillItem().getBillItem().getItem());
}
Expand All @@ -154,6 +155,7 @@ private void saveReturnBill() {
// getReturnBill().setReferenceBill(getBill());
getReturnBill().setCreater(getSessionController().getLoggedUser());
getReturnBill().setCreatedAt(Calendar.getInstance().getTime());
getReturnBill().setComments(comment);

if (getReturnBill().getId() == null) {
getBillFacade().create(getReturnBill());
Expand Down Expand Up @@ -227,7 +229,7 @@ private void saveComponent(Payment p) {
i.setPharmaceuticalBillItem(tmpPh);
getBillItemFacade().edit(i);

boolean returnFlag = getPharmacyBean().deductFromStock(i.getPharmaceuticalBillItem().getStock(), Math.abs(i.getPharmaceuticalBillItem().getQtyInUnit()), i.getPharmaceuticalBillItem(), getSessionController().getDepartment());
boolean returnFlag = getPharmacyBean().deductFromStock(i.getPharmaceuticalBillItem().getStock(), Math.abs(i.getPharmaceuticalBillItem().getQtyInUnit()+i.getPharmaceuticalBillItem().getFreeQtyInUnit()), i.getPharmaceuticalBillItem(), getSessionController().getDepartment());

if (!returnFlag) {
i.setTmpQty(0);
Expand All @@ -246,7 +248,7 @@ private void saveComponent(Payment p) {
private boolean checkStock(PharmaceuticalBillItem pharmaceuticalBillItem) {
double stockQty = getPharmacyBean().getStockQty(pharmaceuticalBillItem.getItemBatch(), getSessionController().getDepartment());

if (pharmaceuticalBillItem.getQtyInUnit() > stockQty) {
if (pharmaceuticalBillItem.getQtyInUnit()+ pharmaceuticalBillItem.getFreeQtyInUnit() > stockQty) {
return true;
} else {
return false;
Expand All @@ -258,6 +260,10 @@ private boolean checkGrnItems() {
if (bi.getTmpQty() == 0.0) {
continue;
}

if (bi.getTmpFreeQty() == 0.0) {
continue;
}

if (checkStock(bi.getPharmaceuticalBillItem())) {
return true;
Expand All @@ -268,11 +274,15 @@ private boolean checkGrnItems() {
}

public void settle() {

if (getReturnBill().getToInstitution() == null) {
JsfUtil.addErrorMessage("Select Dealor");
return;
}
if (getComment() == null || getComment().trim().equals("")) {
JsfUtil.addErrorMessage("Please enter a comment");
return;
}
if (checkGrnItems()) {
JsfUtil.addErrorMessage("ITems for this GRN Already issued so you can't Return ");
return;
Expand Down Expand Up @@ -317,18 +327,22 @@ private void generateBillComponent() {
bi.setSearialNo(getBillItems().size());
PharmaceuticalBillItem retPh = new PharmaceuticalBillItem();
retPh.copy(grnPh);
retPh.setFreeQty(0.0);
retPh.setBillItem(bi);

double rBilled = getPharmacyRecieveBean().getTotalQty(grnPh.getBillItem(), BillType.PharmacyGrnReturn, new BilledBill());
double rCacnelled = getPharmacyRecieveBean().getTotalQty(grnPh.getBillItem(), BillType.PharmacyGrnReturn, new CancelledBill());

double netQty = Math.abs(rBilled) - Math.abs(rCacnelled);


double rFreeBilled = getPharmacyRecieveBean().getTotalFreeQty(grnPh.getBillItem(), BillType.PharmacyGrnReturn, new BilledBill());
double rFreeCacnelled = getPharmacyRecieveBean().getTotalFreeQty(grnPh.getBillItem(), BillType.PharmacyGrnReturn, new CancelledBill());
double netFreeQty = Math.abs(rFreeBilled) - Math.abs(rFreeCacnelled);
//System.err.println("Billed " + rBilled);
//System.err.println("Cancelled " + rCacnelled);
//System.err.println("Net " + netQty);
retPh.setQtyInUnit((double) (grnPh.getQtyInUnit() - netQty));

retPh.setFreeQtyInUnit((double) (grnPh.getFreeQtyInUnit() - netFreeQty));

List<Item> suggessions = new ArrayList<>();
Item item = bi.getItem();
Expand Down Expand Up @@ -534,4 +548,12 @@ public void setPaymentFacade(PaymentFacade paymentFacade) {
this.paymentFacade = paymentFacade;
}

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}

}
38 changes: 34 additions & 4 deletions src/main/java/com/divudi/ejb/PharmacyCalculation.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@ public double getTotalQty(BillItem b, BillType billType, Bill bill) {
return value;
}

public double getTotalQtyWithFreeQty(BillItem b, BillType billType, Bill bill) {
String sql = "Select sum(p.pharmaceuticalBillItem.qty+p.pharmaceuticalBillItem.freeQty) from BillItem p where"
+ " type(p.bill)=:class and p.creater is not null and"
+ " p.referanceBillItem=:bt and p.bill.billType=:btp";

HashMap hm = new HashMap();
hm.put("bt", b);
hm.put("btp", billType);
hm.put("class", bill.getClass());

double value = getPharmaceuticalBillItemFacade().findDoubleByJpql(sql, hm);

//System.err.println("GETTING TOTAL QTY " + value);
return value;
}

public double getTotalFreeQty(BillItem b, BillType billType, Bill bill) {
String sql = "Select sum(p.pharmaceuticalBillItem.freeQty) from BillItem p where"
+ " type(p.bill)=:class and p.creater is not null and"
Expand Down Expand Up @@ -328,6 +344,20 @@ public double getReturnedTotalQty(BillItem b, BillType billType, Bill bill) {

}

public double getReturnedTotalQtyWithFreeQty(BillItem b, BillType billType, Bill bill) {
String sql = "Select sum(p.pharmaceuticalBillItem.qty+p.pharmaceuticalBillItem.freeQty) from BillItem p where"
+ " type(p.bill)=:class and p.bill.creater is not null and"
+ " p.referanceBillItem.referanceBillItem=:bt and p.bill.billType=:btp";

HashMap hm = new HashMap();
hm.put("bt", b);
hm.put("btp", billType);
hm.put("class", bill.getClass());

return getPharmaceuticalBillItemFacade().findDoubleByJpql(sql, hm);

}

public double getReturnedTotalFreeQty(BillItem b, BillType billType, Bill bill) {
String sql = "Select sum(p.pharmaceuticalBillItem.freeQty) from BillItem p where"
+ " type(p.bill)=:class and p.bill.creater is not null and"
Expand Down Expand Up @@ -370,10 +400,10 @@ public double getReturnedTotalFreeQty(BillItem b, BillType billType) {

public double calQty(PharmaceuticalBillItem po) {

double billed = getTotalQty(po.getBillItem(), BillType.PharmacyGrnBill, new BilledBill());
double cancelled = getTotalQty(po.getBillItem(), BillType.PharmacyGrnBill, new CancelledBill());;
double returnedB = getReturnedTotalQty(po.getBillItem(), BillType.PharmacyGrnReturn, new BilledBill());
double returnedC = getReturnedTotalQty(po.getBillItem(), BillType.PharmacyGrnReturn, new CancelledBill());
double billed = getTotalQtyWithFreeQty(po.getBillItem(), BillType.PharmacyGrnBill, new BilledBill());
double cancelled = getTotalQtyWithFreeQty(po.getBillItem(), BillType.PharmacyGrnBill, new CancelledBill());;
double returnedB = getReturnedTotalQtyWithFreeQty(po.getBillItem(), BillType.PharmacyGrnReturn, new BilledBill());
double returnedC = getReturnedTotalQtyWithFreeQty(po.getBillItem(), BillType.PharmacyGrnReturn, new CancelledBill());

double recieveNet = Math.abs(billed) - Math.abs(cancelled);
double retuernedNet = Math.abs(returnedB) - Math.abs(returnedC);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/divudi/entity/BillItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,6 @@ public void setTmpFreeQty(double tmpFreeQty) {
} else {
this.tmpFreeQty = tmpFreeQty;
}

if (getPharmaceuticalBillItem() != null) {
getPharmaceuticalBillItem().setFreeQty((double) this.tmpFreeQty);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
3.0.0.20240415.4

15 changes: 8 additions & 7 deletions src/main/webapp/pharmacy/pharmacy_grn_list_for_return.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<div class="col-10">
<p:dataTable
value="#{searchController.bills}"
class="w-100"
var="p"
paginator="true"
paginatorPosition="bottom"
Expand All @@ -58,12 +59,12 @@
<f:setPropertyActionListener target="#{pharmacyBillSearch.bill}" value="#{p}"/>
</h:commandLink>
</p:column>
<p:column headerText="Invoice No" >
<h:commandLink action="pharmacy_reprint_grn" >
<h:outputLabel value="#{p.invoiceNumber}"/>
<f:setPropertyActionListener target="#{pharmacyBillSearch.bill}" value="#{p}"/>
</h:commandLink>
</p:column>
<!-- <p:column headerText="Invoice No" >
<h:commandLink action="pharmacy_reprint_grn" >
<h:outputLabel value="#{p.invoiceNumber}"/>
<f:setPropertyActionListener target="#{pharmacyBillSearch.bill}" value="#{p}"/>
</h:commandLink>
</p:column> -->
<p:column headerText="PO No">
<h:commandLink action="pharmacy_reprint_grn" >
<h:outputLabel value="#{p.referenceBill.deptId}"/>
Expand Down Expand Up @@ -145,7 +146,7 @@
</p:commandButton>
</p:column>

<p:column headerText="Return Bill">
<p:column headerText="Return Bill" width="25%">
<p:dataTable var="b" value="#{p.listOfBill}">
<p:column >
<h:commandLink action="pharmacy_reprint_grn_return" >
Expand Down
52 changes: 36 additions & 16 deletions src/main/webapp/pharmacy/pharmacy_return_good.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

<f:facet name="header" >

<h:panelGrid columns="15" >
<h:outputLabel value="Supplier : "/>
<div class="w-100 d-flex" >
<h:outputLabel value="Supplier : " class="my-1"/>
<p:autoComplete converter="deal" value="#{goodsReturnController.returnBill.toInstitution}"
forceSelection="true"
completeMethod="#{dealerController.completeDealor}"
var="vt" itemLabel="#{vt.name}" itemValue="#{vt}" >
</p:autoComplete>
<p:selectOneMenu id="cmbPs" value="#{goodsReturnController.returnBill.paymentMethod}">

<p:selectOneMenu id="cmbPs" value="#{goodsReturnController.returnBill.paymentMethod}" class="mx-4">
<f:selectItems value="#{enumController.paymentMethods}"/>
<p:ajax process="cmbPs" update="lblCardRef txtCardRef lblCheqRef txtCheqRef
bank lblSlipRef txtSlipRef slipBank" event="change" />
Expand All @@ -45,15 +45,20 @@
<f:selectItem itemLabel="Select Bank"/>
<f:selectItems value="#{institutionController.banks}" var="inst" itemLabel="#{inst.name}" itemValue="#{inst}"/>
</h:selectOneMenu>

<p:commandButton value="Return"
action="#{goodsReturnController.settle}" ajax="false" style="width: 150px; padding: 1px;border: 1px solid ; margin: auto;">
</p:commandButton>
<p:outputLabel value="Recievable Amount" />
<p:outputLabel id="total" value="#{goodsReturnController.returnBill.total}" style="float: right;">
<f:convertNumber pattern="#,##0.00" />
</p:outputLabel>
</h:panelGrid>
<p:inputText placeholder="Enter Comments to Return Bill" value="#{goodsReturnController.comment}" class="p-2 w-25"/>

<p:outputLabel value="Recievable Amount" class="mx-4 my-2"/>
<div class="my-2">
<p:outputLabel id="total" value="#{goodsReturnController.returnBill.total}" style=" my-4">
<f:convertNumber pattern="#,##0.00" />
</p:outputLabel>
</div>
<div style="float: right">
<p:commandButton value="Return"
action="#{goodsReturnController.settle}" ajax="false" icon="fa fa-cancel" style="float: right;" class="mx-5 ui-button-danger">
</p:commandButton>
</div>
</div>
</f:facet>
</p:panel>

Expand Down Expand Up @@ -83,6 +88,9 @@
<p:column headerText="Balance Qty in Unit" style="width:25px!important;">
<h:outputText id="qty" value="#{ph.pharmaceuticalBillItem.qty}" />
</p:column>
<p:column headerText="Balance Free Qty in Unit" style="width:25px!important;">
<h:outputText id="freeQty" value="#{ph.pharmaceuticalBillItem.freeQty}" />
</p:column>

<p:column headerText="Purchase Rate" style="width:25px!important;">
<h:panelGroup id="purchase" >
Expand Down Expand Up @@ -114,7 +122,19 @@
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
</p:column>
<p:column headerText="Returning Free Qty in Unit" style="width:25px!important;">
<p:cellEditor>
<f:facet name="output">
<h:outputLabel value="#{ph.tmpFreeQty}" />

</f:facet>
<f:facet name="input">
<p:inputText autocomplete="off" value="#{ph.tmpFreeQty}" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>

</p:dataTable>
<p:spacer height="50"/>
Expand All @@ -129,11 +149,11 @@
<p:panel id="gpBillPreview">

<!-- <ph:grnReturn bill="#{goodsReturnController.returnBill}"/>-->

<h:panelGroup rendered="#{sessionController.loggedPreference.grnBillDetailed eq false}" >
<ph:grnReturn bill="#{goodsReturnController.returnBill}"/>
</h:panelGroup>

<h:panelGroup rendered="#{sessionController.loggedPreference.grnBillDetailed eq true}" >
<ph:grn_detail bill="#{goodsReturnController.returnBill}"/>
</h:panelGroup>
Expand Down
4 changes: 4 additions & 0 deletions src/main/webapp/resources/pharmacy/grnReturn.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
<f:facet name="header">Return QTY</f:facet>
#{bip.pharmaceuticalBillItem.qty}
</p:column>
<p:column>
<f:facet name="header">Return Free QTY</f:facet>
#{bip.pharmaceuticalBillItem.freeQty}
</p:column>
<p:column>
<f:facet name="header">Rate</f:facet>
#{bip.pharmaceuticalBillItem.purchaseRate}
Expand Down

0 comments on commit 8faf6c7

Please sign in to comment.