Skip to content

Commit

Permalink
Closes #6425
Browse files Browse the repository at this point in the history
Signed-off-by: buddhika75 <[email protected]>
  • Loading branch information
buddhika75 committed Jul 24, 2024
1 parent 3eaaa80 commit 3bfdbe5
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ public ReportTemplateRowBundle addChannellingByCategories(

bundle = combineBundlesByCategory(ins, outs);

System.out.println("bundle = " + bundle.getReportTemplateRows().size());

return bundle;
}

Expand All @@ -295,10 +293,11 @@ public ReportTemplateRowBundle addOpdByDepartments(
Institution paramCreditCompany,
Long paramStartId,
Long paramEndId) {
System.out.println("addOpdByDepartments");

ReportTemplateRowBundle bundle;
List<BillTypeAtomic> inBts = BillTypeAtomic.findByServiceTypeAndFinanceType(ServiceType.OPD, BillFinanceType.CASH_IN);
List<BillTypeAtomic> outBts = BillTypeAtomic.findByServiceTypeAndFinanceType(ServiceType.OPD, BillFinanceType.CASH_OUT);
List<BillTypeAtomic> inBts = BillTypeAtomic.findByCountedServiceType(CountedServiceType.OPD_IN);
List<BillTypeAtomic> outBts = BillTypeAtomic.findByCountedServiceType(CountedServiceType.OPD_OUT);

ReportTemplateRowBundle ins = reportTemplateController.generateReport(
type,
Expand Down Expand Up @@ -338,9 +337,7 @@ public ReportTemplateRowBundle addOpdByDepartments(

System.out.println("outes = " + outs.getReportTemplateRows().size());

bundle = combineBundlesByDepartment(ins, outs);

System.out.println("bundle = " + bundle.getReportTemplateRows().size());
bundle = combineBundlesByItemDepartment(ins, outs);

return bundle;
}
Expand All @@ -364,7 +361,7 @@ public void processShiftEndReport() {
Long paramStartId = nonClosedShiftStartFundBill.getId();
Long paramEndId = nonClosedShiftStartFundBill.getReferenceBill().getId();

ReportTemplateRowBundle channelingBundle = addChannellingByCategories(
ReportTemplateRowBundle tmpChannellingBundle = addChannellingByCategories(
channelingType,
btas,
paramDate,
Expand All @@ -382,28 +379,29 @@ public void processShiftEndReport() {
paramEndId
);

ReportTemplateRowBundle opdBundle = addOpdByDepartments(
opdType,
btas,
paramDate,
paramFromDate,
paramToDate,
paramInstitution,
paramDepartment,
paramFromInstitution,
paramFromDepartment,
paramToInstitution,
paramToDepartment,
paramUser,
paramCreditCompany,
paramStartId,
paramEndId
);

channelingBundle.setName("Channelling");
opdBundle.setName("OPD Bundle");
shiftEndBundles.add(channelingBundle);
shiftEndBundles.add(opdBundle);
ReportTemplateRowBundle tmpOpdBundle
= addOpdByDepartments(
opdType,
btas,
paramDate,
paramFromDate,
paramToDate,
paramInstitution,
paramDepartment,
paramFromInstitution,
paramFromDepartment,
paramToInstitution,
paramToDepartment,
paramUser,
paramCreditCompany,
paramStartId,
paramEndId
);

tmpChannellingBundle.setName("Channelling");
tmpOpdBundle.setName("OPD Bundle");
shiftEndBundles.add(tmpChannellingBundle);
shiftEndBundles.add(tmpOpdBundle);

}

Expand Down Expand Up @@ -689,40 +687,65 @@ private ReportTemplateRowBundle combineBundlesByCategory(ReportTemplateRowBundle
return temOutBundle;
}

private ReportTemplateRowBundle combineBundlesByDepartment(ReportTemplateRowBundle inBundle, ReportTemplateRowBundle outBundle) {


private ReportTemplateRowBundle combineBundlesByItemDepartment(ReportTemplateRowBundle inBundle, ReportTemplateRowBundle outBundle) {
System.out.println("Starting combineBundlesByDepartment method");

ReportTemplateRowBundle temOutBundle = new ReportTemplateRowBundle();
Map<Department, ReportTemplateRow> combinedRows = new HashMap<>();
temOutBundle.setReportTemplateRows(new ArrayList<>()); // Ensure the list is initialized
Map<Object, ReportTemplateRow> combinedRows = new HashMap<>();

final Object NULL_DEPARTMENT_KEY = new Object(); // Placeholder for null departments

if (inBundle != null && inBundle.getReportTemplateRows() != null) {
System.out.println("Processing inBundle");
for (ReportTemplateRow inRow : inBundle.getReportTemplateRows()) {
if (inRow != null) {
Department d = inRow.getDepartment();
if (d != null) {
if (!combinedRows.containsKey(d)) {
combinedRows.put(d, new ReportTemplateRow(d));
}
ReportTemplateRow combinedRow = combinedRows.get(d);
combinedRow.setRowCountIn((combinedRow.getRowCountIn() != null ? combinedRow.getRowCountIn() : 0L) + (inRow.getRowCount() != null ? inRow.getRowCount() : 0L));
combinedRow.setRowValueIn((combinedRow.getRowValueIn() != null ? combinedRow.getRowValueIn() : 0.0) + (inRow.getRowValue() != null ? inRow.getRowValue() : 0.0));
Department d = inRow.getItemDepartment();
Object key = (d != null) ? d : NULL_DEPARTMENT_KEY;
if (d == null) {
System.out.println("Department is null in inRow");
} else {
System.out.println("Processing inRow for Department: " + d.getName());
}
if (!combinedRows.containsKey(key)) {
combinedRows.put(key, new ReportTemplateRow(d));
}
ReportTemplateRow combinedRow = combinedRows.get(key);
combinedRow.setRowCountIn((combinedRow.getRowCountIn() != null ? combinedRow.getRowCountIn() : 0L) + (inRow.getRowCount() != null ? inRow.getRowCount() : 0L));
combinedRow.setRowValueIn((combinedRow.getRowValueIn() != null ? combinedRow.getRowValueIn() : 0.0) + (inRow.getRowValue() != null ? inRow.getRowValue() : 0.0));
} else {
System.out.println("inRow is null");
}
}
} else {
System.out.println("inBundle or inBundle.getReportTemplateRows() is null");
}

if (outBundle != null && outBundle.getReportTemplateRows() != null) {
System.out.println("Processing outBundle");
for (ReportTemplateRow outRow : outBundle.getReportTemplateRows()) {
if (outRow != null) {
Department d = outRow.getDepartment();
if (d != null) {
if (!combinedRows.containsKey(d)) {
combinedRows.put(d, new ReportTemplateRow(d));
}
ReportTemplateRow combinedRow = combinedRows.get(d);
combinedRow.setRowCountOut((combinedRow.getRowCountOut() != null ? combinedRow.getRowCountOut() : 0L) + (outRow.getRowCount() != null ? outRow.getRowCount() : 0L));
combinedRow.setRowValueOut((combinedRow.getRowValueOut() != null ? combinedRow.getRowValueOut() : 0.0) + (outRow.getRowValue() != null ? outRow.getRowValue() : 0.0));
Department d = outRow.getItemDepartment();
Object key = (d != null) ? d : NULL_DEPARTMENT_KEY;
if (d == null) {
System.out.println("Department is null in outRow");
} else {
System.out.println("Processing outRow for Department: " + d.getName());
}
if (!combinedRows.containsKey(key)) {
combinedRows.put(key, new ReportTemplateRow(d));
}
ReportTemplateRow combinedRow = combinedRows.get(key);
combinedRow.setRowCountOut((combinedRow.getRowCountOut() != null ? combinedRow.getRowCountOut() : 0L) + (outRow.getRowCount() != null ? outRow.getRowCount() : 0L));
combinedRow.setRowValueOut((combinedRow.getRowValueOut() != null ? combinedRow.getRowValueOut() : 0.0) + (outRow.getRowValue() != null ? outRow.getRowValue() : 0.0));
} else {
System.out.println("outRow is null");
}
}
} else {
System.out.println("outBundle or outBundle.getReportTemplateRows() is null");
}

long totalInCount = 0;
Expand All @@ -731,6 +754,8 @@ private ReportTemplateRowBundle combineBundlesByDepartment(ReportTemplateRowBund
double totalOutValue = 0.0;

for (ReportTemplateRow row : combinedRows.values()) {
String deptName = (row.getItemDepartment() != null) ? row.getItemDepartment().getName() : "NULL_DEPARTMENT";
System.out.println("Combining row for Department: " + deptName);
row.setRowCount((row.getRowCountIn() != null ? row.getRowCountIn() : 0L) + (row.getRowCountOut() != null ? row.getRowCountOut() : 0L));
row.setRowValue((row.getRowValueIn() != null ? row.getRowValueIn() : 0.0) + (row.getRowValueOut() != null ? row.getRowValueOut() : 0.0));
temOutBundle.getReportTemplateRows().add(row);
Expand All @@ -748,17 +773,25 @@ private ReportTemplateRowBundle combineBundlesByDepartment(ReportTemplateRowBund
temOutBundle.setTotalOut(totalOutValue);
temOutBundle.setTotal(totalInValue + totalOutValue);

System.out.println("Total In Count: " + totalInCount);
System.out.println("Total Out Count: " + totalOutCount);
System.out.println("Total In Value: " + totalInValue);
System.out.println("Total Out Value: " + totalOutValue);

System.out.println("Finished combineBundlesByDepartment method");
return temOutBundle;
}



public void processShiftEndReportOpdCategory() {
reportTemplateType = ReportTemplateType.ITEM_CATEGORY_SUMMARY_BY_BILL_ITEM;
List<BillTypeAtomic> bts = new ArrayList<>();
bts.addAll(BillTypeAtomic.findByServiceTypeAndFinanceType(ServiceType.OPD, BillFinanceType.CASH_IN));
bts.addAll(BillTypeAtomic.findByCountedServiceType(CountedServiceType.OPD));
bts.addAll(BillTypeAtomic.findByCountedServiceType(CountedServiceType.OPD_IN));
opdBilled = reportTemplateController.generateReport(
ReportTemplateType.ITEM_CATEGORY_SUMMARY_BY_BILL_ITEM,
BillTypeAtomic.findByCountedServiceType(CountedServiceType.OPD),
BillTypeAtomic.findByCountedServiceType(CountedServiceType.OPD_IN),
null,
null,
null,
Expand Down Expand Up @@ -795,10 +828,10 @@ public void processShiftEndReportOpdItem() {
reportTemplateType = ReportTemplateType.ITEM_SUMMARY_BY_BILL;
List<BillTypeAtomic> bts = new ArrayList<>();
bts.addAll(BillTypeAtomic.findByServiceTypeAndFinanceType(ServiceType.OPD, BillFinanceType.CASH_IN));
bts.addAll(BillTypeAtomic.findByCountedServiceType(CountedServiceType.OPD));
bts.addAll(BillTypeAtomic.findByCountedServiceType(CountedServiceType.OPD_IN));
opdBilled = reportTemplateController.generateReport(
ReportTemplateType.ITEM_SUMMARY_BY_BILL,
BillTypeAtomic.findByCountedServiceType(CountedServiceType.OPD),
BillTypeAtomic.findByCountedServiceType(CountedServiceType.OPD_IN),
null,
null,
null,
Expand Down Expand Up @@ -1564,7 +1597,6 @@ public String navigateToDayEndSummary() {
}

public void processDayEndSummary() {
System.out.println("processDayEndSummary");
resetClassVariables();
fillPaymentsForDateRange();
createPaymentSummery();
Expand All @@ -1573,7 +1605,6 @@ public void processDayEndSummary() {

private void createPaymentSummery() {
System.out.println("createPaymentSummery");
System.out.println("paymentsFromShiftSratToNow = " + paymentsFromShiftSratToNow);

if (paymentsFromShiftSratToNow == null) {
return;
Expand All @@ -1583,7 +1614,6 @@ private void createPaymentSummery() {
Map<String, ReportTemplateRow> keyMap = new HashMap<>();

for (Payment p : paymentsFromShiftSratToNow) {
System.out.println("p = " + p);

if (p == null || p.getBill() == null) {
continue; // Skip this iteration if p or p.getBill() is null
Expand Down Expand Up @@ -1733,7 +1763,6 @@ public void fillPaymentsForDateRange() {
m.put("td", getToDate());
m.put("ret", true);
System.out.println("m = " + m);
System.out.println("jpql = " + jpql);
}

public void fillPaymentsFromShiftStartToNow(Bill startBill, WebUser user) {
Expand Down Expand Up @@ -2241,15 +2270,13 @@ public void updateCashDenominations(AjaxBehaviorEvent event) {
System.out.println("updateCashDenominations called");

if (currentPayment == null) {
System.out.println("currentPayment is null");
return;
}

double total = 0;
List<Denomination> denominations = currentPayment.getCurrencyDenominations();
for (Denomination denomination : denominations) {
int value = denomination.getCount();
System.out.println("Processing denomination: " + denomination.getValue() + " with count: " + value);
total += denomination.getValue() * value;
}
currentPayment.setPaidValue(total);
Expand All @@ -2264,7 +2291,6 @@ public void updateCashDenominations(AjaxBehaviorEvent event) {
jsonArray.put(jsonObject);
}
currentPayment.setCurrencyDenominationsJson(jsonArray.toString());
System.out.println("Updated currencyDenominationsJson: " + currentPayment.getCurrencyDenominationsJson());
}

public void setCurrentPayment(Payment currentPayment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,7 @@ private ReportTemplateRowBundle handleItemCategorySummaryByBill(
long idCounter = 1;
Double total = 0.0;
for (ReportTemplateRow row : rs) {

row.setId(idCounter++);
total = row.getRowValue();
}
Expand Down Expand Up @@ -1633,8 +1634,8 @@ private ReportTemplateRowBundle handleItemDepartmentummaryByBill(
parameters.put("creditCompany", paramCreditCompany);
}

jpql += " and bi.item is not null "
+ " and bi.item.department is not null ";
// jpql += " and bi.item is not null "
// + " and bi.item.department is not null ";

jpql += " group by bi.item.department ";

Expand All @@ -1654,10 +1655,13 @@ private ReportTemplateRowBundle handleItemDepartmentummaryByBill(
long idCounter = 1;
Double total = 0.0;
for (ReportTemplateRow row : rs) {
System.out.println("row = " + row.getItemDepartment());
System.out.println("row = " + row.getRowCount());
row.setId(idCounter++);
total = row.getRowValue();
}
bundle.setReportTemplateRows(rs);
bundle.setTotal(total);
return bundle;
}

Expand Down
Loading

0 comments on commit 3bfdbe5

Please sign in to comment.