Skip to content

Commit

Permalink
Merge pull request #6470 from hmislk/Issue#6447
Browse files Browse the repository at this point in the history
Issue#6447 Closes #6447
  • Loading branch information
Deshani Pubudu authored Jul 21, 2024
2 parents 30f8fd2 + 3ee71a4 commit 57a2797
Show file tree
Hide file tree
Showing 19 changed files with 1,373 additions and 191 deletions.
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@
<version>3.8.1</version>
<configuration>
<release>8</release> <!-- Compile with Java 8 compatibility -->
<debug>false</debug>
<showDeprecation>false</showDeprecation>
</configuration>
</plugin>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.stream.Collectors;
import javax.ejb.EJB;
import javax.inject.Inject;
import javax.persistence.TemporalType;
import org.bouncycastle.mail.smime.handlers.pkcs7_mime;

/**
Expand Down Expand Up @@ -73,7 +72,6 @@ public class FinancialTransactionController implements Serializable {
private Payment removingPayment;
private List<Payment> currentBillPayments;
private List<Bill> currentBills;
private List<Bill> shiaftStartBills;
private List<Bill> fundTransferBillsToReceive;
private List<Bill> fundBillsForClosureBills;
private Bill selectedBill;
Expand Down Expand Up @@ -127,8 +125,6 @@ public class FinancialTransactionController implements Serializable {
private double additions;

private int fundTransferBillsToReceiveCount;
private Date fromDate;
private Date toDate;

private Date fromDate;
private Date toDate;
Expand Down Expand Up @@ -159,27 +155,6 @@ public String navigateToCreateNewInitialFundBill() {
return "/cashier/initial_fund_bill?faces-redirect=true;";
}

public String navigateToListShiftEndSummaries() {
resetClassVariables();
shiaftStartBills = new ArrayList<>();
return "/cashier/initial_fund_bill_list?faces-redirect=true;";
}

public void listShiftStartBills() {
String jpql = "select b "
+ " from Bill b "
+ " where b.retired=:ret"
+ " and b.billTypeAtomic=:bta "
+ " and b.createdAt between :fd and :td "
+ " order by b.id ";
Map params = new HashMap<>();
params.put("ret", false);
params.put("bta", BillTypeAtomic.FUND_SHIFT_START_BILL);
params.put("fd", fromDate);
params.put("td", toDate);
shiaftStartBills = billFacade.findByJpql(jpql, params, TemporalType.TIMESTAMP);
}

public String navigateToFundTransferBill() {
resetClassVariables();
prepareToAddNewFundTransferBill();
Expand Down Expand Up @@ -670,17 +645,79 @@ public String navigateToViewEndOfSelectedShiftStartSummaryBill(Bill startBill) {
return "/cashier/shift_end_summery_bill_of_selected_user_not_closed?faces-redirect=true";
}

public String navigateToViewStartToEndOfSelectedShiftStartSummaryBill(Bill startBill) {
public void processDayEndSummary() {
System.out.println("processDayEndSummary");
resetClassVariables();
if (startBill == null) {
JsfUtil.addErrorMessage("No Start Bill");
return null;
fillPaymentsForDateRange();
createPaymentSummery();

}

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

if (paymentsFromShiftSratToNow == null) {
return;
}
Bill endBill;
if (startBill.getReferenceBill() == null) {
JsfUtil.addErrorMessage("No Start Bill");
return null;

paymentSummaryBundle = new ReportTemplateRowBundle();
Map<String, Double> aggregatedPayments = new HashMap<>();
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
}

ReportTemplateRow row = new ReportTemplateRow();

if (p.getBill().getCategory() != null) {
row.setCategory(p.getBill().getCategory());
}

if (p.getBill().getBillTypeAtomic() != null) {
row.setBillTypeAtomic(p.getBill().getBillTypeAtomic());

if (p.getBill().getBillTypeAtomic().getServiceType() != null) {
row.setServiceType(p.getBill().getBillTypeAtomic().getServiceType());
}
}

if (p.getBill().getCreditCompany() != null) {
row.setCreditCompany(p.getBill().getCreditCompany());
}

if (p.getBill().getToDepartment() != null) {
row.setToDepartment(p.getBill().getToDepartment());
}

row.setRowValue(p.getPaidValue());

String keyString = row.getCustomKey();

if (keyString != null) {
keyMap.putIfAbsent(keyString, row);
aggregatedPayments.merge(keyString, p.getPaidValue(), Double::sum);
}
}

List<ReportTemplateRow> rows = aggregatedPayments.entrySet().stream().map(entry -> {
ReportTemplateRow row = keyMap.get(entry.getKey());

if (row != null) {
row.setRowValue(entry.getValue());
}

return row;
}).collect(Collectors.toList());

if (paymentSummaryBundle != null) {
paymentSummaryBundle.getReportTemplateRows().addAll(rows);
}

endBill = startBill.getReferenceBill();
nonClosedShiftStartFundBill = startBill;
fillPaymentsFromShiftStartToEnd(startBill, endBill, startBill.getCreater());
Expand Down Expand Up @@ -735,62 +772,20 @@ public void fillPaymentsFromShiftStartToNow() {

}

public void fillPaymentsFromShiftStartToNow(Bill startBill, WebUser user) {
public void fillPaymentsForDateRange() {
System.out.println("fillPaymentsForDateRange");
paymentsFromShiftSratToNow = new ArrayList<>();
if (startBill == null) {
JsfUtil.addErrorMessage("No Start Bill");
return;
}
if (user == null) {
JsfUtil.addErrorMessage("No User");
return;
}
Long shiftStartBillId = startBill.getId();
String jpql = "SELECT p "
+ "FROM Payment p "
+ "WHERE p.creater = :cr "
+ "AND p.retired = :ret "
+ "AND p.id > :cid "
+ "WHERE p.bill.retired <> :ret "
+ "AND p.bill.createdAt between :fd and :td "
+ "ORDER BY p.id DESC";
Map<String, Object> m = new HashMap<>();
m.put("cr", user);
m.put("ret", false);
m.put("cid", shiftStartBillId);
paymentsFromShiftSratToNow = paymentFacade.findByJpql(jpql, m);
atomicBillTypeTotalsByPayments = new AtomicBillTypeTotals();
for (Payment p : paymentsFromShiftSratToNow) {
if (p.getBill().getBillTypeAtomic() == null) {
} else {
atomicBillTypeTotalsByPayments.addOrUpdateAtomicRecord(p.getBill().getBillTypeAtomic(), p.getPaymentMethod(), p.getPaidValue());
}
}
financialReportByPayments = new FinancialReport(atomicBillTypeTotalsByPayments);
}

public void fillPaymentsFromShiftStartToEnd(Bill startBill, Bill endBill, WebUser user) {
paymentsFromShiftSratToNow = new ArrayList<>();
if (startBill == null) {
JsfUtil.addErrorMessage("No Start Bill");
return;
}
if (user == null) {
JsfUtil.addErrorMessage("No User");
return;
}
Long shiftStartBillId = startBill.getId();
Long shiftEndBillId = endBill.getId();
String jpql = "SELECT p "
+ "FROM Payment p "
+ "WHERE p.creater = :cr "
+ "AND p.retired = :ret "
+ "AND p.id > :sid "
+ "AND p.id < :eid "
+ "ORDER BY p.id DESC";
Map<String, Object> m = new HashMap<>();
m.put("cr", user);
m.put("ret", false);
m.put("sid", shiftStartBillId);
m.put("eid", shiftEndBillId);
m.put("fd", getFromDate());
m.put("td", getToDate());
m.put("ret", true);
System.out.println("m = " + m);
System.out.println("jpql = " + jpql);
paymentsFromShiftSratToNow = paymentFacade.findByJpql(jpql, m);
atomicBillTypeTotalsByPayments = new AtomicBillTypeTotals();
for (Payment p : paymentsFromShiftSratToNow) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,6 @@ public class ReportTemplateController implements Serializable {
private ReportTemplateFacade ejbFacade;
private ReportTemplate current;
private List<ReportTemplate> items = null;


private Date date;
private Date fromDate;
private Date toDate;
private Institution institution;
private Department department;
private WebUser user;
private Staff staff;


private Date date;
private Date fromDate;
Expand Down Expand Up @@ -100,10 +90,6 @@ public void save(ReportTemplate reportTemplate) {
}
}





public ReportTemplate findReportTemplateByName(String name) {
if (name == null) {
return null;
Expand Down Expand Up @@ -322,6 +308,42 @@ private void handleBillFeeGroupedByBillTypeAtomic() {
reportTemplateRowBundle.setReportTemplateRows(rs);
}

private void handleBillFeeGroupedByToDepartmentAndCategory() {
String jpql;
Map<String, Object> parameters = new HashMap<>();
reportTemplateRowBundle = new ReportTemplateRowBundle();

jpql = "select new com.divudi.data.ReportTemplateRow("
+ " bill.billTypeAtomic, sum(bf.feeValue)) "
+ " from BillFee bf "
+ " join bf.bill bill "
+ " where bf.retired<>:bfr "
+ " and bf.billItem.retired<>:bir "
+ " and bill.retired<>:br ";
parameters.put("bfr", true);
parameters.put("bir", true);
parameters.put("br", true);

jpql += " group by bill.billTypeAtomic";

System.out.println("jpql = " + jpql);
System.out.println("parameters = " + parameters);

List<ReportTemplateRow> rs = (List<ReportTemplateRow>) ejbFacade.findLightsByJpql(jpql, parameters, TemporalType.DATE);

if (rs == null || rs.isEmpty()) {
System.out.println("No results found.");
} else {
System.out.println("Results found: " + rs.size());
}

long idCounter = 1;
for (ReportTemplateRow row : rs) {
row.setId(idCounter++);
}
reportTemplateRowBundle.setReportTemplateRows(rs);
}

private void handleBillFeeGroupedByToDepartmentAndCategory() {
String jpql;
Map<String, Object> parameters = new HashMap<>();
Expand Down Expand Up @@ -528,10 +550,6 @@ private void handlePaymentTypeSummaryPayments() {

private void handlePaymentTypeSummaryUsingBills() {
// Method implementation here

public void processReport() {


}

public void saveSelected() {
Expand Down Expand Up @@ -696,14 +714,6 @@ public String navigateToGenerateReport() {
return "/dataAdmin/report?faces-redirect=true";
}

public String navigateToEditGenerateReport() {
if (current == null) {
JsfUtil.addErrorMessage("Nothing Selected");
return null;
}
return "/dataAdmin/report";
}

public List<ReportTemplate> getAllItems() {
List<ReportTemplate> allItems;
String j;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/divudi/bean/common/EnumController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.divudi.data.BillClassType;
import com.divudi.data.BillItemStatus;
import com.divudi.data.BillType;
import com.divudi.data.BillTypeAtomic;
import com.divudi.data.CalculationType;
import com.divudi.data.CreditDuration;
import com.divudi.data.CssVerticalAlign;
Expand Down
Loading

0 comments on commit 57a2797

Please sign in to comment.