Skip to content

Commit

Permalink
Merge pull request #4579 from hmislk/Issue#4578
Browse files Browse the repository at this point in the history
Signed-off-by: Senula88 <[email protected]>
  • Loading branch information
buddhika75 authored Apr 10, 2024
2 parents cced31d + 6dbb405 commit 92d3e17
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 16 deletions.
131 changes: 127 additions & 4 deletions src/main/java/com/divudi/bean/common/BillController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1640,13 +1645,115 @@ public List<BillFee> 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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
}

/**
*
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/divudi/bean/common/BillSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0.20240410.17
3.0.0.20240410.19
164 changes: 164 additions & 0 deletions src/main/webapp/opd/batch_bill_cancel.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:common="http://xmlns.jcp.org/jsf/composite/ezcomp/common"
xmlns:bi="http://xmlns.jcp.org/jsf/composite/bill"
xmlns:prints="http://xmlns.jcp.org/jsf/composite/ezcomp/prints">

<h:body>
<ui:composition template="/resources/template/template.xhtml">
<ui:define name="content">
<h:form>
<h:panelGroup rendered="#{!billSearch.printPreview}" styleClass="alignTop">
<p:panel>
<f:facet name="header">
<h:outputText value="Cancellation" class="mt-5"/>
<h:panelGrid columns="3" style="float: right" class="w-50">
<p:inputText placeholder="Enter Comments to Cancel Bill" value="#{billController.comment}" style="float: right" class="p-2 w-100"/>

<p:commandButton
ajax="false"
value="Cancel Bill"
icon="fa fa-cancel"
style="float: right"
class="ui-button-danger" action="#{billController.cancelBatchBill()}">
</p:commandButton>
</h:panelGrid>
</f:facet>

<!-- Payment Mode Panel -->
<p:panel>
<f:facet name="header">
<h:outputText styleClass="fas fa-money-bill"></h:outputText>
<h:outputLabel value="Payment Mode" class="mx-2"></h:outputLabel>
</f:facet>
<p:selectOneMenu id="cmbPs" value="#{billController.paymentMethod}"
disabled="#{billController.batchBill.paymentMethod eq 'Cash'}"
rendered="#{billController.batchBill.billType eq 'OpdBathcBill'}">
<f:selectItem itemLabel="Select paymentMethod"/>
<f:selectItems value="#{inwardPaymentController.paymentMethods}"/>
</p:selectOneMenu>

<p:selectOneMenu id="cmbPs2" value="#{billController.paymentMethod}"
disabled="#{billController.batchBill.paymentMethod eq 'Agent'}"
rendered="#{billController.batchBill.billType eq 'CollectingCentreBill'}">
<f:selectItem itemLabel="Select paymentMethod"/>
<f:selectItems value="#{enumController.collectingCentrePaymentMethods}"/>
</p:selectOneMenu>
</p:panel>

<!-- Patient Details and Bill Details Panels -->
<div class="row">
<div class="col-6">
<p:panel>
<f:facet name="header">
<h:outputText styleClass="fas fa-id-card-alt"></h:outputText>
<h:outputLabel value="Patient Details" class="mx-2"></h:outputLabel>
</f:facet>
<common:patient patient="#{billController.batchBill.patient}" class="w-100"/>
</p:panel>
</div>
<div class="col-6">
<p:panel>
<f:facet name="header">
<h:outputText styleClass="fas fa-list-alt"></h:outputText>
<h:outputLabel value="Batch Bill Detail" class="mx-2"></h:outputLabel>
</f:facet>
<p:panelGrid columns="2">
<h:outputLabel value="Bill No :" ></h:outputLabel>
<h:outputLabel value="#{billController.batchBill.insId}" ></h:outputLabel>
<h:outputLabel value="Total :" ></h:outputLabel>
<h:outputLabel value="#{billController.batchBill.total}" ></h:outputLabel>
<h:outputLabel value="Discount :" ></h:outputLabel>
<h:outputLabel value="#{billController.batchBill.discount}" ></h:outputLabel>
<h:outputLabel value="Net Total :" ></h:outputLabel>
<h:outputLabel value="#{billController.batchBill.netTotal}" ></h:outputLabel>
</p:panelGrid>
</p:panel>
</div>
</div>

<!-- Bill Item Detail Panel -->
<p:panel>
<f:facet name="header">
<h:outputText styleClass="fas fa-list-alt"></h:outputText>
<h:outputLabel value="Cancelling Bills Details" class="mx-2"></h:outputLabel>
</f:facet>
<p:dataTable rowIndexVar="rowIndex" value="#{billController.bills}" var="bill">
<p:column>
<f:facet name="header">Bill No</f:facet>
<h:outputLabel value="#{bill.deptId}"/>
</p:column>
<p:column>
<f:facet name="header">Billed At</f:facet>
<h:outputLabel value="#{bill.createdAt}"/>
</p:column>
<p:column>
<f:facet name="header">Billed For</f:facet>
<h:outputLabel value="#{bill.toDepartment.name}"/>
</p:column>
<p:column>
<f:facet name="header">Net Total</f:facet>
<h:outputLabel value="#{bill.netTotal}"/>
</p:column>
</p:dataTable>
</p:panel>
</p:panel>
</h:panelGroup>

<!-- Print Preview Panel -->
<h:panelGroup rendered="#{billSearch.printPreview}" >
<div class="d-flex justify-content-center">
<p:outputLabel value="Paper Type" class="m-2"></p:outputLabel>
<p:selectOneMenu value="#{sessionController.departmentPreference.opdBillPaperType}" class="m-1" style="width: 13em;">
<f:selectItem itemLabel="Please Select Paper Type" />
<f:selectItems value="#{enumController.paperTypes}" />
</p:selectOneMenu>
<p:commandButton ajax="false" icon="fa fa-sync-alt" class="ui-button m-1" title="Redraw Bill"></p:commandButton>
<p:commandButton value="Print"
class="ui-button-info m-1"
icon="fa fa-print"
ajax="false">
</p:commandButton>
<h:panelGroup rendered="#{billSearch.bill.billType ne 'CollectingCentreBill'}">
<p:commandButton
value="New OPD Bill"
ajax="false"
icon="fa fa-plus"
class="ui-button-success"
action="#{opdBillController.navigateToNewOpdBill()}" >
</p:commandButton>
</h:panelGroup>

<h:panelGroup rendered="#{billSearch.bill.billType eq 'CollectingCentreBill'}">
<p:commandButton
value="New Collectiong Centre Bill"
ajax="false"
icon="fa fa-plus"
class="ui-button-success"
action="#{collectingCentreBillController.navigateToCollectingCenterBillingromMenu()}" >
</p:commandButton>
</h:panelGroup>
</div>
<h:panelGroup id="groupPrint" >
<!-- Bill Print Templates -->
<prints:five_five_paper_with_headings bill="#{billSearch.bill.cancelledBill}"/>
<prints:five_five_paper_without_headings
bill="#{billSearch.bill.cancelledBill}"
duplicate="#{opdBillController.duplicatePrint}"
payments="#{opdBillController.payments}"/>
<prints:posOpdBillWithoutLogo bill="#{billSearch.bill.cancelledBill}" duplicate="#{opdBillController.duplicatePrint}"/>
<prints:posOpdBill bill="#{billSearch.bill.cancelledBill}" duplicate="#{opdBillController.duplicatePrint}"/>
<prints:A4_paper_with_headings bill="#{billSearch.bill.cancelledBill}" duplicate="#{opdBillController.duplicatePrint}"/>
<prints:A4_paper_without_headings bill="#{billSearch.bill.cancelledBill}" duplicate="#{opdBillController.duplicatePrint}"/>
</h:panelGroup>
</h:panelGroup>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
Loading

0 comments on commit 92d3e17

Please sign in to comment.