Skip to content

Collection center statement print pdf excel improvements#19616

Open
denuwanhendalage wants to merge 5 commits intodevelopmentfrom
collection-center-statement-print-pdf-excel-improvements
Open

Collection center statement print pdf excel improvements#19616
denuwanhendalage wants to merge 5 commits intodevelopmentfrom
collection-center-statement-print-pdf-excel-improvements

Conversation

@denuwanhendalage
Copy link
Copy Markdown
Collaborator

@denuwanhendalage denuwanhendalage commented Mar 31, 2026

improved collection center statement PDF, Excel, and Print preview
changed files

  1. reportController (PDF generation method, postProcessor for Excel)
  2. collection_center_statement_report.xhtml
  3. collection_center_statement_view.xhtml (print preview)

Summary by CodeRabbit

  • New Features

    • Print-optimized "Collection Center Statement" report view added.
    • End-to-end PDF export with formatted headers, generation timestamp, and A4 landscape layout.
    • Excel post-processing: sheet renamed, rows adjusted, and filter metadata embedded.
  • UI

    • Export filenames now include formatted from/to date ranges.
    • Print flow changed to a dedicated report view; print button label updated.
    • One table column disabled from exports.

Signed-off-by: denuwanhendalage <shashankadenuwanb@gmail.com>
Signed-off-by: denuwanhendalage <shashankadenuwanb@gmail.com>
Signed-off-by: denuwanhendalage <shashankadenuwanb@gmail.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

Walkthrough

Adds a "Collection Center Statement" report: new JSF print view, controller methods to build filters, export the report to PDF (rotated A4, header, filters, 17-column table) and post-process Excel exports (rename sheet, insert filter metadata), and updates the report UI to wire these handlers and filenames.

Changes

Cohort / File(s) Summary
Report Controller — new export APIs
src/main/java/com/divudi/bean/report/ReportController.java
Added three public methods: getFiltersForCollectionCenterStatementReport() (ordered filter map with formatted dates and "All" fallbacks), exportCollectionCenterStatementReportToPDF() (validates agentHistories, sets response headers, creates rotated A4 PDF with institution/title/timestamp, info table and 17-column data table), and postProcessCollectionCenterStatementReportExcel(Object) (validates XSSFWorkbook, renames first sheet to Collection Center Statement, shifts rows, and inserts filter metadata).
Report view — new print page
src/main/webapp/reports/collectionCenterReports/collection_center_statement_view.xhtml
New JSF Facelets print view: A4 landscape print styles, header/title, filter summary, and data table iterating reportController.agentHistories with conditional column rendering, row coloring, and number/date formatting. Includes print and back controls.
Report component — export wiring & UI tweaks
src/main/webapp/resources/ezcomp/reports/cc_statement.xhtml
Rewired Print button to navigate to the new print view; PDF export now calls exportCollectionCenterStatementReportToPDF(); Excel export uses dynamic filename with date range and postProcessCollectionCenterStatementReportExcel as postProcessor; set Developers column exportable="false".

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Browser
    participant ReportController
    participant Database
    participant PDFEngine
    participant ExcelEngine

    User->>Browser: Click "Export PDF"
    Browser->>ReportController: exportCollectionCenterStatementReportToPDF()
    ReportController->>ReportController: getFiltersForCollectionCenterStatementReport()
    ReportController->>Database: load agentHistories
    Database-->>ReportController: return agentHistories
    ReportController->>PDFEngine: create rotated A4, write header, timestamp, info table
    ReportController->>PDFEngine: render 17-column data table
    PDFEngine-->>ReportController: PDF bytes
    ReportController->>Browser: stream PDF with Content-Disposition

    User->>Browser: Click "Export XLSX"
    Browser->>ReportController: trigger XLSX exporter
    ReportController->>Database: load agentHistories
    Database-->>ReportController: return agentHistories
    ReportController->>ExcelEngine: generate XSSFWorkbook
    ReportController->>ReportController: postProcessCollectionCenterStatementReportExcel(document)
    ReportController->>Browser: stream XLSX with Content-Disposition
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: improvements to Collection Center Statement reporting for PDF, Excel, and print outputs across multiple components.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch collection-center-statement-print-pdf-excel-improvements

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.42.0)
src/main/java/com/divudi/bean/report/ReportController.java

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/webapp/resources/ezcomp/reports/cc_statement.xhtml (1)

100-106: ⚠️ Potential issue | 🟠 Major

Process the report before redirecting to the print view.

This submit now updates the filters but skips the agentHistories refresh. src/main/java/com/divudi/bean/report/ReportController.java:2388-2421 is still the code path that rebuilds the table data, so the print page can show stale rows under the newly submitted filters.

🛠️ Suggested change
 <p:commandButton 
     icon="fa-solid fa-print"
     style="width: 150px"
     class="mx-2 ui-button-info"
     ajax="false" 
     value="To Print"
+    actionListener="#{reportController.processCollectingCentreStatementReportNew()}"
     action="collection_center_statement_view?faces-redirect=true">
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/webapp/resources/ezcomp/reports/cc_statement.xhtml` around lines 100
- 106, The print button currently navigates directly to
collection_center_statement_view, skipping the ReportController code that
rebuilds agentHistories (the logic around ReportController methods at lines
~2388-2421); update the p:commandButton in cc_statement.xhtml so it invokes the
ReportController method that refreshes the report data (the method that rebuilds
agentHistories / prepares the collection center statement) before performing the
redirect—either call that bean method via the action (returning the same
navigation string) or add an actionListener to invoke the ReportController
refresh method, then navigate to
"collection_center_statement_view?faces-redirect=true".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/com/divudi/bean/report/ReportController.java`:
- Around line 2436-2440: The commented-out guard in
exportCollectionCenterStatementReportToPDF allows agentHistories to be
null/empty and leads to a runtime exception later; restore the precondition
check by verifying agentHistories != null && !agentHistories.isEmpty() at the
start of exportCollectionCenterStatementReportToPDF and, if it fails, call
JsfUtil.addErrorMessage("No data to export. Please process the report first.")
and return so the method exits safely.
- Around line 2505-2509: The code wrongly compares the enum returned by
row.getHistoryType() to the string "RepaymentToCollectingCentre", causing the
ternary for CCCodeString and CCNameString to always pick the first branch;
update the condition to compare against the enum constant (e.g.,
row.getHistoryType() != HistoryType.RepaymentToCollectingCentre or
!HistoryType.RepaymentToCollectingCentre.equals(row.getHistoryType())) so that
CCCodeString and CCNameString correctly use row.getAgency() when the history
type is RepaymentToCollectingCentre; ensure HistoryType is imported or fully
qualified and handle possible null row.getHistoryType() if needed.

In
`@src/main/webapp/reports/collectionCenterReports/collection_center_statement_view.xhtml`:
- Around line 161-164: The invoice summary's else branch incorrectly references
reportsController.invoiceNumber instead of the intended
reportController.invoiceNumber, causing a mismatch with the filter state (and
potential missing property errors); update the h:outputText so both sides of the
ternary use reportController.invoiceNumber (i.e., change reportsController to
reportController) to ensure the header reflects the same invoice filter used for
agentHistories.

---

Outside diff comments:
In `@src/main/webapp/resources/ezcomp/reports/cc_statement.xhtml`:
- Around line 100-106: The print button currently navigates directly to
collection_center_statement_view, skipping the ReportController code that
rebuilds agentHistories (the logic around ReportController methods at lines
~2388-2421); update the p:commandButton in cc_statement.xhtml so it invokes the
ReportController method that refreshes the report data (the method that rebuilds
agentHistories / prepares the collection center statement) before performing the
redirect—either call that bean method via the action (returning the same
navigation string) or add an actionListener to invoke the ReportController
refresh method, then navigate to
"collection_center_statement_view?faces-redirect=true".
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b3756c32-2816-49f0-9244-c998f4354546

📥 Commits

Reviewing files that changed from the base of the PR and between 1f3e9be and 60e9862.

📒 Files selected for processing (3)
  • src/main/java/com/divudi/bean/report/ReportController.java
  • src/main/webapp/reports/collectionCenterReports/collection_center_statement_view.xhtml
  • src/main/webapp/resources/ezcomp/reports/cc_statement.xhtml

Signed-off-by: denuwanhendalage <shashankadenuwanb@gmail.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/main/java/com/divudi/bean/report/ReportController.java (1)

2505-2508: ⚠️ Potential issue | 🟠 Major

Fix enum comparison for repayment rows (current condition is incorrect).

At Line 2505 and Line 2507, "RepaymentToCollectingCentre".equals(row.getHistoryType()) compares String to HistoryType, so it does not evaluate as intended and can select the wrong CC source branch.

💡 Proposed fix
-                String CCCodeString =!"RepaymentToCollectingCentre".equals(row.getHistoryType()) ? row.getBill().getFromInstitution().getCode() : row.getAgency().getCode();
+                boolean repaymentToCollectingCentre = HistoryType.RepaymentToCollectingCentre.equals(row.getHistoryType());
+                String CCCodeString = !repaymentToCollectingCentre ? row.getBill().getFromInstitution().getCode() : row.getAgency().getCode();
                 table.addCell(textCell(CCCodeString,bodyFontSmall));
-                String CCNameString =!"RepaymentToCollectingCentre".equals(row.getHistoryType()) ? row.getBill().getFromInstitution().getName() : row.getAgency().getName() ;
+                String CCNameString = !repaymentToCollectingCentre ? row.getBill().getFromInstitution().getName() : row.getAgency().getName();

Use this read-only verification to confirm both the offending code and the enum type:

#!/bin/bash
set -euo pipefail

# 1) Show the problematic comparison in ReportController
rg -n -C2 '"RepaymentToCollectingCentre"\.equals\(row\.getHistoryType\(\)\)' src/main/java/com/divudi/bean/report/ReportController.java

# 2) Confirm AgentHistory#getHistoryType() is HistoryType (enum), not String
fd -i 'AgentHistory.java' src/main/java --exec rg -n -C3 'class AgentHistory|getHistoryType\(|HistoryType' {}

Expected result: step (1) finds Line 2505/2507 pattern, step (2) shows getHistoryType() is based on HistoryType.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/divudi/bean/report/ReportController.java` around lines 2505
- 2508, The ternary checks that build CCCodeString and CCNameString in
ReportController incorrectly compare the String literal
"RepaymentToCollectingCentre" to row.getHistoryType(); change these to compare
the enum properly by using the HistoryType constant
(HistoryType.RepaymentToCollectingCentre) against row.getHistoryType() and keep
the same ternary branches: when the history type is not
RepaymentToCollectingCentre use
row.getBill().getFromInstitution().getCode()/getName(), otherwise use
row.getAgency().getCode()/getName(); update both CCCodeString and CCNameString
accordingly.
🧹 Nitpick comments (1)
src/main/java/com/divudi/bean/report/ReportController.java (1)

2527-2528: Unify logger context/message in new collection-center exporters.

These logs reference ReportsController and legacy method/report names, which makes operational tracing harder for this new report path.

💡 Proposed cleanup
-            Logger.getLogger(ReportsController.class
-                    .getName()).log(Level.SEVERE, "Error exporting Test Wise Count Report to PDF", e);
+            Logger.getLogger(ReportController.class
+                    .getName()).log(Level.SEVERE, "Error exporting Collection Center Statement Report to PDF", e);
-            Logger.getLogger(ReportsController.class.getName()).log(Level.SEVERE, "Document is null in postProcessBillWiseItemMovementReportExcel");
+            Logger.getLogger(ReportController.class.getName()).log(Level.SEVERE, "Document is null in postProcessCollectionCenterStatementReportExcel");
-            Logger.getLogger(ReportsController.class.getName()).log(Level.SEVERE, "Expected document to be an instance of XSSFWorkbook, but got: {0}", document.getClass().getName());
+            Logger.getLogger(ReportController.class.getName()).log(Level.SEVERE, "Expected XSSFWorkbook in postProcessCollectionCenterStatementReportExcel, but got: {0}", document.getClass().getName());

Also applies to: 2535-2539

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/divudi/bean/report/ReportController.java` around lines 2527
- 2528, The log calls in ReportController.java currently reference the wrong
class and legacy report names (e.g.,
Logger.getLogger(ReportsController.class.getName()) and messages like "Error
exporting Test Wise Count Report to PDF"); update these logger invocations to
use the correct class context (ReportController.class) and adjust the message
text to reflect the new collection-center exporter and accurate report name used
by the surrounding code (also fix the similar occurrences around the block at
lines referenced 2535-2539) so operational traces point to ReportController and
the correct export action.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/com/divudi/bean/report/ReportController.java`:
- Line 2432: The filter metadata currently uses filters.put("Invoice No.",
invoiceNumber != null ? invoiceNumber : "All") which treats only null as "All"
but leaves blank strings; change the check to treat blank or whitespace-only
values as "All" by testing invoiceNumber == null ||
invoiceNumber.trim().isEmpty() (or equivalent) before putting the value into
filters, e.g., replace the ternary condition in filters.put("Invoice No.", ...)
to use that combined null-or-empty test so blank invoice numbers become "All".

---

Duplicate comments:
In `@src/main/java/com/divudi/bean/report/ReportController.java`:
- Around line 2505-2508: The ternary checks that build CCCodeString and
CCNameString in ReportController incorrectly compare the String literal
"RepaymentToCollectingCentre" to row.getHistoryType(); change these to compare
the enum properly by using the HistoryType constant
(HistoryType.RepaymentToCollectingCentre) against row.getHistoryType() and keep
the same ternary branches: when the history type is not
RepaymentToCollectingCentre use
row.getBill().getFromInstitution().getCode()/getName(), otherwise use
row.getAgency().getCode()/getName(); update both CCCodeString and CCNameString
accordingly.

---

Nitpick comments:
In `@src/main/java/com/divudi/bean/report/ReportController.java`:
- Around line 2527-2528: The log calls in ReportController.java currently
reference the wrong class and legacy report names (e.g.,
Logger.getLogger(ReportsController.class.getName()) and messages like "Error
exporting Test Wise Count Report to PDF"); update these logger invocations to
use the correct class context (ReportController.class) and adjust the message
text to reflect the new collection-center exporter and accurate report name used
by the surrounding code (also fix the similar occurrences around the block at
lines referenced 2535-2539) so operational traces point to ReportController and
the correct export action.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0e8cca3d-a3d5-4c2b-9000-0876cc711e4d

📥 Commits

Reviewing files that changed from the base of the PR and between 60e9862 and 13f304e.

📒 Files selected for processing (2)
  • src/main/java/com/divudi/bean/report/ReportController.java
  • src/main/webapp/reports/collectionCenterReports/collection_center_statement_view.xhtml
✅ Files skipped from review due to trivial changes (1)
  • src/main/webapp/reports/collectionCenterReports/collection_center_statement_view.xhtml

Signed-off-by: denuwanhendalage <shashankadenuwanb@gmail.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
src/main/java/com/divudi/bean/report/ReportController.java (1)

2505-2507: ⚠️ Potential issue | 🟠 Major

Compare HistoryType as an enum, not as a string.

Line 2505 and Line 2507 call String.equals(HistoryType), so the repayment branch never matches. RepaymentToCollectingCentre rows always fall back to row.getBill().getFromInstitution(), which makes the exported CC code/name wrong for those entries.

Suggested fix
-                String CCCodeString =!"RepaymentToCollectingCentre".equals(row.getHistoryType()) ? row.getBill().getFromInstitution().getCode() : row.getAgency().getCode();
+                boolean repaymentToCollectingCentre = HistoryType.RepaymentToCollectingCentre.equals(row.getHistoryType());
+                String CCCodeString = !repaymentToCollectingCentre ? row.getBill().getFromInstitution().getCode() : row.getAgency().getCode();
                 table.addCell(textCell(CCCodeString,bodyFontSmall));
-                String CCNameString =!"RepaymentToCollectingCentre".equals(row.getHistoryType()) ? row.getBill().getFromInstitution().getName() : row.getAgency().getName() ;
+                String CCNameString = !repaymentToCollectingCentre ? row.getBill().getFromInstitution().getName() : row.getAgency().getName();

Run the following script to verify the type mismatch and the affected enum constant:

#!/bin/bash
set -euo pipefail

# Expectation:
# 1) `AgentHistory.getHistoryType()` returns `HistoryType`.
# 2) `RepaymentToCollectingCentre` is an enum constant, not a string value.
# 3) The current exporter compares that enum-backed value to a string literal.

echo "=== Current comparison in ReportController ==="
sed -n '2503,2508p' src/main/java/com/divudi/bean/report/ReportController.java

echo
echo "=== AgentHistory.getHistoryType() return type ==="
rg -n -C2 'HistoryType getHistoryType\(' src/main/java/com/divudi/core/entity/AgentHistory.java

echo
echo "=== HistoryType enum constant ==="
rg -n -C1 '\bRepaymentToCollectingCentre\b' src/main/java/com/divudi/core/data/HistoryType.java
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/divudi/bean/report/ReportController.java` around lines 2505
- 2507, The comparison currently treats HistoryType as a string, causing the
RepaymentToCollectingCentre branch to never match; update the ternary
expressions building CCCodeString and CCNameString in ReportController to
compare the enum value returned by row.getHistoryType() against the enum
constant HistoryType.RepaymentToCollectingCentre (e.g. use row.getHistoryType()
== HistoryType.RepaymentToCollectingCentre or Objects.equals to handle nulls) so
that CCCodeString and CCNameString correctly use row.getAgency() for that enum
case.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/main/java/com/divudi/bean/report/ReportController.java`:
- Around line 2505-2507: The comparison currently treats HistoryType as a
string, causing the RepaymentToCollectingCentre branch to never match; update
the ternary expressions building CCCodeString and CCNameString in
ReportController to compare the enum value returned by row.getHistoryType()
against the enum constant HistoryType.RepaymentToCollectingCentre (e.g. use
row.getHistoryType() == HistoryType.RepaymentToCollectingCentre or
Objects.equals to handle nulls) so that CCCodeString and CCNameString correctly
use row.getAgency() for that enum case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dd47cb05-2559-4a09-8773-4217e32332af

📥 Commits

Reviewing files that changed from the base of the PR and between 13f304e and 5a0a50a.

📒 Files selected for processing (1)
  • src/main/java/com/divudi/bean/report/ReportController.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant