Skip to content

Commit

Permalink
Merge pull request #9774 from hmislk/Issue#9773-discount-report
Browse files Browse the repository at this point in the history
Issue#9773 Discount Report  Closes #9773
  • Loading branch information
Irani96 authored Dec 21, 2024
2 parents 4bc7ab4 + 27c5c6a commit 6600958
Show file tree
Hide file tree
Showing 3 changed files with 725 additions and 357 deletions.
274 changes: 274 additions & 0 deletions src/main/java/com/divudi/bean/common/ReportsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ public class ReportsController implements Serializable {
private Date maxDate;
private Doctor referingDoctor;
private Month month;
private PaymentScheme paymentScheme;
private String remarks;

private double cashTotal;
private double cardTotal;
Expand Down Expand Up @@ -313,13 +315,16 @@ public class ReportsController implements Serializable {
private String settlementStatus;
private String dischargedStatus;

private String selectedDateType = "invoice";

private Investigation investigation;

// Map<Week, Map<ItemName, Map<dayOfMonth, Count>>>
Map<Integer, Map<String, Map<Integer, Double>>> weeklyDailyBillItemMap7to7;
Map<Integer, Map<String, Map<Integer, Double>>> weeklyDailyBillItemMap7to1;
Map<Integer, Map<String, Map<Integer, Double>>> weeklyDailyBillItemMap1to7;


private boolean showChart;

public String getDischargedStatus() {
Expand Down Expand Up @@ -363,12 +368,36 @@ public void setPatientReportFacade(PatientReportFacade patientReportFacade) {
this.patientReportFacade = patientReportFacade;
}

public PaymentScheme getPaymentScheme() {
return paymentScheme;
}

public void setPaymentScheme(PaymentScheme paymentScheme) {
this.paymentScheme = paymentScheme;
}

public String getRemarks() {
return remarks;
}

public void setRemarks(String remarks) {
this.remarks = remarks;
}

public String getSelectedDateType() {
return selectedDateType;
}

public void setSelectedDateType(String selectedDateType) {
this.selectedDateType = selectedDateType;

public Investigation getInvestigation() {
return investigation;
}

public void setInvestigation(Investigation investigation) {
this.investigation = investigation;

}

public Institution getCreditCompany() {
Expand Down Expand Up @@ -3500,4 +3529,249 @@ public Double calculateSubTotal() {
return subTotal;
}

public void generateDiscountReport() {
if (visitType == null || visitType.trim().isEmpty()) {
JsfUtil.addErrorMessage("Please select a visit type");
return;
}

System.out.println("generateDiscountReport = " + this);
bundle = new ReportTemplateRowBundle();

List<BillTypeAtomic> opdBts = new ArrayList<>();
bundle = new ReportTemplateRowBundle();

if (visitType.equalsIgnoreCase("IP")) {
opdBts.add(BillTypeAtomic.INWARD_SERVICE_BATCH_BILL);
opdBts.add(BillTypeAtomic.INWARD_SERVICE_BILL);
opdBts.add(BillTypeAtomic.INWARD_SERVICE_BATCH_BILL_CANCELLATION);
opdBts.add(BillTypeAtomic.INWARD_SERVICE_BILL_CANCELLATION);
opdBts.add(BillTypeAtomic.INWARD_FINAL_BILL);
} else if (visitType.equalsIgnoreCase("OP")) {
opdBts.add(BillTypeAtomic.OPD_BILL_WITH_PAYMENT);
opdBts.add(BillTypeAtomic.OPD_BILL_PAYMENT_COLLECTION_AT_CASHIER);
opdBts.add(BillTypeAtomic.OPD_BATCH_BILL_WITH_PAYMENT);
opdBts.add(BillTypeAtomic.OPD_BATCH_BILL_PAYMENT_COLLECTION_AT_CASHIER);
opdBts.add(BillTypeAtomic.PACKAGE_OPD_BATCH_BILL_WITH_PAYMENT);
opdBts.add(BillTypeAtomic.PACKAGE_OPD_BILL_PAYMENT_COLLECTION_AT_CASHIER);
opdBts.add(BillTypeAtomic.OPD_BATCH_BILL_CANCELLATION);
opdBts.add(BillTypeAtomic.OPD_BILL_CANCELLATION);
opdBts.add(BillTypeAtomic.PACKAGE_OPD_BATCH_BILL_CANCELLATION);
opdBts.add(BillTypeAtomic.PACKAGE_OPD_BILL_CANCELLATION);
}

if (reportType.equalsIgnoreCase("detail")) {
bundle.setName("BillItems");
bundle.setBundleType("billItemList");

bundle = generateDiscountBillItems(opdBts);
bundle.calculateTotalDiscountByBillItems();
} else if (reportType.equalsIgnoreCase("summary")) {
bundle.setName("Bills");
bundle.setBundleType("billList");

bundle = generateDiscountBills(opdBts);
bundle.calculateTotalDiscountByBills();
}
}

public ReportTemplateRowBundle generateDiscountBills(List<BillTypeAtomic> bts) {
Map<String, Object> parameters = new HashMap<>();

String jpql = "SELECT new com.divudi.data.ReportTemplateRow(bill) "
+ "FROM Bill bill "
+ "WHERE bill.retired <> :br "
+ "AND bill.paymentScheme is not null ";

parameters.put("br", true);

jpql += "AND bill.billTypeAtomic in :bts ";
parameters.put("bts", bts);

if (paymentMethod != null) {
List<PaymentMethod> billPaymentMethods = new ArrayList<>();
billPaymentMethods.add(paymentMethod);

jpql += "AND bill.paymentMethod in :bpms ";
parameters.put("bpms", billPaymentMethods);
}

if (visitType != null && (visitType.equalsIgnoreCase("IP") && admissionType != null)) {
jpql += "AND bill.patientEncounter.admissionType = :type ";
parameters.put("type", admissionType);
}

if (visitType != null && (visitType.equalsIgnoreCase("IP") && roomCategory != null)) {
jpql += "AND bill.patientEncounter.currentPatientRoom.roomFacilityCharge.roomCategory = :category ";
parameters.put("category", roomCategory);
}

if (discount > 0) {
jpql += "AND bill.discount = :dis ";
parameters.put("dis", discount);
}

if (remarks != null && !remarks.trim().isEmpty()) {
jpql += "AND bill.comments LIKE :rem ";
parameters.put("rem", remarks + "%");
}

if (institution != null) {
jpql += "AND bill.department.institution = :ins ";
parameters.put("ins", institution);
}

if (department != null) {
jpql += "AND bill.department = :dep ";
parameters.put("dep", department);
}
if (site != null) {
jpql += "AND bill.department.site = :site ";
parameters.put("site", site);
}
if (webUser != null) {
jpql += "AND bill.creater = :wu ";
parameters.put("wu", webUser);
}

if (collectingCentre != null) {
jpql += "AND bill.collectingCentre = :cc ";
parameters.put("cc", collectingCentre);
}

if (creditCompany != null) {
jpql += "AND bill.creditCompany = :cc ";
parameters.put("cc", creditCompany);
}

if (paymentScheme != null) {
jpql += "AND bill.paymentScheme = :ps ";
parameters.put("ps", paymentScheme);
}

if (selectedDateType != null && !selectedDateType.trim().isEmpty() && selectedDateType.equalsIgnoreCase("admission")) {
jpql += "AND bill.patientEncounter.dateOfAdmission BETWEEN :fd AND :td ";
} else if (selectedDateType != null && !selectedDateType.trim().isEmpty() && selectedDateType.equalsIgnoreCase("discharge")) {
jpql += "AND bill.patientEncounter.dateOfDischarge BETWEEN :fd AND :td ";
} else {
jpql += "AND bill.createdAt BETWEEN :fd AND :td ";
}

parameters.put("fd", fromDate);
parameters.put("td", toDate);

jpql += "GROUP BY bill";

List<ReportTemplateRow> rs = (List<ReportTemplateRow>) paymentFacade.findLightsByJpql(jpql, parameters, TemporalType.TIMESTAMP);

ReportTemplateRowBundle b = new ReportTemplateRowBundle();
b.setReportTemplateRows(rs);
b.createRowValuesFromBill();
b.calculateTotalsWithCredit();
return b;
}

public ReportTemplateRowBundle generateDiscountBillItems(List<BillTypeAtomic> bts) {
Map<String, Object> parameters = new HashMap<>();

String jpql = "SELECT new com.divudi.data.ReportTemplateRow(billItem) "
+ "FROM BillItem billItem "
+ "JOIN billItem.bill bill "
+ "WHERE billItem.retired <> :bfr AND bill.retired <> :br "
+ "AND billItem.bill.paymentScheme is not null ";

parameters.put("bfr", true);
parameters.put("br", true);

jpql += "AND bill.billTypeAtomic in :bts ";
parameters.put("bts", bts);

if (paymentMethod != null) {
List<PaymentMethod> billPaymentMethods = new ArrayList<>();
billPaymentMethods.add(paymentMethod);

jpql += "AND bill.paymentMethod in :bpms ";
parameters.put("bpms", billPaymentMethods);
}

if (discount > 0) {
jpql += "AND billItem.bill.discount = :dis ";
parameters.put("dis", discount);
}

if (remarks != null && !remarks.trim().isEmpty()) {
jpql += "AND billItem.bill.comments LIKE :rem ";
parameters.put("rem", remarks + "%");
}

if (visitType != null && (visitType.equalsIgnoreCase("IP") && admissionType != null)) {
jpql += "AND bill.patientEncounter.admissionType = :type ";
parameters.put("type", admissionType);
}

if (visitType != null && (visitType.equalsIgnoreCase("IP") && roomCategory != null)) {
jpql += "AND bill.patientEncounter.currentPatientRoom.roomFacilityCharge.roomCategory = :category ";
parameters.put("category", roomCategory);
}

if (institution != null) {
jpql += "AND bill.department.institution = :ins ";
parameters.put("ins", institution);
}

if (department != null) {
jpql += "AND bill.department = :dep ";
parameters.put("dep", department);
}
if (site != null) {
jpql += "AND bill.department.site = :site ";
parameters.put("site", site);
}
if (webUser != null) {
jpql += "AND bill.creater = :wu ";
parameters.put("wu", webUser);
}

if (collectingCentre != null) {
jpql += "AND bill.collectingCentre = :cc ";
parameters.put("cc", collectingCentre);
}

if (creditCompany != null) {
jpql += "AND bill.creditCompany = :cc ";
parameters.put("cc", creditCompany);
}

if (paymentScheme != null) {
jpql += "AND bill.paymentScheme = :ps ";
parameters.put("ps", paymentScheme);
}

if ("notSettled".equalsIgnoreCase(settlementStatus)) {
jpql += "AND (billItem.referenceBill.netTotal + billItem.referenceBill.vat + billItem.referenceBill.paidAmount) <> 0 ";
} else if ("settled".equalsIgnoreCase(settlementStatus)) {
jpql += "AND (billItem.referenceBill.netTotal + billItem.referenceBill.vat + billItem.referenceBill.paidAmount) = 0 ";
}

if (selectedDateType != null && !selectedDateType.trim().isEmpty() && selectedDateType.equalsIgnoreCase("admission")) {
jpql += "AND bill.patientEncounter.dateOfAdmission BETWEEN :fd AND :td ";
} else if (selectedDateType != null && !selectedDateType.trim().isEmpty() && selectedDateType.equalsIgnoreCase("discharge")) {
jpql += "AND bill.patientEncounter.dateOfDischarge BETWEEN :fd AND :td ";
} else {
jpql += "AND bill.createdAt BETWEEN :fd AND :td ";
}

parameters.put("fd", fromDate);
parameters.put("td", toDate);

jpql += "GROUP BY billItem";

List<ReportTemplateRow> rs = (List<ReportTemplateRow>) paymentFacade.findLightsByJpql(jpql, parameters, TemporalType.TIMESTAMP);

ReportTemplateRowBundle b = new ReportTemplateRowBundle();
b.setReportTemplateRows(rs);
b.createRowValuesFromBillItems();
b.calculateTotalsWithCredit();
return b;
}
}
26 changes: 26 additions & 0 deletions src/main/java/com/divudi/data/ReportTemplateRowBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,32 @@ public void calculateTotalByHospitalFee() {
}
}

public void calculateTotalDiscountByBillItems() {
discount = 0.0;
if (this.reportTemplateRows != null && !this.reportTemplateRows.isEmpty()) {
for (ReportTemplateRow row : this.reportTemplateRows) {
if (row.getBillItem().getBill() == null) {
continue;
}
Double amount = safeDouble(row.getBillItem().getBill().getDiscount());
discount += amount;
}
}
}

public void calculateTotalDiscountByBills() {
discount = 0.0;
if (this.reportTemplateRows != null && !this.reportTemplateRows.isEmpty()) {
for (ReportTemplateRow row : this.reportTemplateRows) {
if (row.getBill() == null) {
continue;
}
Double amount = safeDouble(row.getBill().getDiscount());
discount += amount;
}
}
}

public void calculateTotalCCFee() {
ccTotal = 0.0;
if (this.reportTemplateRows != null && !this.reportTemplateRows.isEmpty()) {
Expand Down
Loading

0 comments on commit 6600958

Please sign in to comment.