From b19ec5f33e3b41039a66db1da6d01a9bf285ba4e Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 7 Nov 2025 16:48:08 +0000 Subject: [PATCH] Bug 40445: Add cashup summary preview for in-progress cashups In the two-phase cashup workflow, staff start a cashup and then count cash while continuing to process transactions. There was no way to preview what would be included in the cashup until it was completed. This patch adds a "Preview expected summary" link in the "Cashup in progress" alert that allows staff to: - See what transactions will be included in the cashup - Review expected cash amounts before completing - Verify the session period is correct - Check for any unexpected transactions Changes: Backend (Koha/REST/V1/CashRegisters/Cashups.pm): - Modified get() endpoint to handle CASHUP_START actions for preview - Fallback lookup finds CASHUP_START by ID when not found as completed - Wraps CASHUP_START as Cashup object to generate summary Frontend (pos/register.tt): - Added "Preview expected summary" link in cashup-in-progress alert - Link includes data-in-progress="true" attribute for JS handling - Uses existing cashupSummaryModal for consistent UX JavaScript (cashup_modal.js): - Detects in-progress flag from link data attribute - Changes modal title to "Cashup summary preview (in progress)" - Adds informational alert explaining this is a preview - Note clarifies that transactions will update values until completion - Removes preview notice for completed cashup summaries The preview uses the same summary generation logic as completed cashups, showing accurate period boundaries and transaction totals. Staff can open the preview multiple times to see updated values as they process transactions. Test plan: 1. Start a cashup on a register (two-phase workflow) 2. Verify "Cashup in progress" alert appears 3. Click "Preview expected summary" link 4. Verify modal shows: - Title includes "(in progress)" - Blue info alert explaining this is a preview - Correct period dates - Current transaction totals 5. Add a new cash transaction 6. Re-open preview, verify totals updated 7. Complete the cashup normally 8. View completed cashup summary 9. Verify no preview notice shown, title is normal --- Koha/REST/V1/CashRegisters/Cashups.pm | 16 ++++++++++ .../prog/en/modules/pos/register.tt | 10 ++++++- .../intranet-tmpl/prog/js/cashup_modal.js | 29 +++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/Koha/REST/V1/CashRegisters/Cashups.pm b/Koha/REST/V1/CashRegisters/Cashups.pm index 375eab431e0..ffb8e63b9f1 100644 --- a/Koha/REST/V1/CashRegisters/Cashups.pm +++ b/Koha/REST/V1/CashRegisters/Cashups.pm @@ -63,8 +63,24 @@ sub get { my $c = shift->openapi->valid_input or return; return try { + + # Try to find as a completed cashup first my $cashup = Koha::Cash::Register::Cashups->find( $c->param('cashup_id') ); + # If not found, try as a CASHUP_START action (for preview) + unless ($cashup) { + require Koha::Cash::Register::Actions; + my $action = Koha::Cash::Register::Actions->find( $c->param('cashup_id') ); + + # Only allow CASHUP_START actions for preview + if ( $action && $action->code eq 'CASHUP_START' ) { + + # Wrap as Cashup object for summary generation + require Koha::Cash::Register::Cashup; + $cashup = Koha::Cash::Register::Cashup->_new_from_dbic( $action->_result ); + } + } + return $c->render_resource_not_found("Cashup") unless $cashup; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt index a23383c01e0..3e1179a0330 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt @@ -96,7 +96,15 @@ [% IF cashup_in_progress %]
- Cashup in progress - started [% cashup_in_progress.timestamp | $KohaDates with_hours => 1 %]. You can continue to make transactions while counting cash. + Cashup in progress - started [% cashup_in_progress.timestamp | $KohaDates with_hours => 1 %]. You can continue to make transactions while counting cash. (Preview expected summary)
[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/cashup_modal.js b/koha-tmpl/intranet-tmpl/prog/js/cashup_modal.js index 667a8205890..67f4d89c626 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/cashup_modal.js +++ b/koha-tmpl/intranet-tmpl/prog/js/cashup_modal.js @@ -3,7 +3,18 @@ $(document).ready(function () { var button = $(e.relatedTarget); var cashup = button.data("cashup"); var description = button.data("register"); + var inProgress = button.data("in-progress") || false; var summary_modal = $(this); + + // Update title based on whether this is a preview + if (inProgress) { + summary_modal + .find("#cashupSummaryLabel") + .text("Cashup summary preview (in progress)"); + } else { + summary_modal.find("#cashupSummaryLabel").text("Cashup summary"); + } + summary_modal.find("#register_description").text(description); $.ajax({ url: "/api/v1/cashups/" + cashup, @@ -17,6 +28,24 @@ $(document).ready(function () { let to_date = $datetime(data.summary.to_date); summary_modal.find("#to_date").text(to_date); + // Add preview notice if this is an in-progress cashup + if (inProgress) { + var previewNotice = summary_modal.find(".preview-notice"); + if (previewNotice.length === 0) { + summary_modal + .find(".modal-body > ul") + .after( + '
' + + ' ' + + "Preview: This summary shows the current expected cashup amounts. " + + "New transactions will update these values until you complete the cashup." + + "
" + ); + } + } else { + summary_modal.find(".preview-notice").remove(); + } + // Check for reconciliation (surplus or deficit) from dedicated fields var surplus = data.summary.surplus_total; var deficit = data.summary.deficit_total; -- 2.51.1