From 8f48e48e5321f82033efdf8c849ef13854879866 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 24 Aug 2022 08:28:12 +0100 Subject: [PATCH] Bug 31448: Replace 'Print' with 'Receipt' dropdown This patch replaces the 'Print' button with a 'Receipt' menu dropdown exposing 'Print' and 'Email' options when `UseEmailReceipts` is enabled Test plan 1. Enable `UseEmailReceipts` 2. Navigate to a patron with paid charges 3. Note the new dropdown 'Receipt' menu 4. Confirm 'Print' works as expected 5. Confirm 'Email' works as expected Signed-off-by: Sally Signed-off-by: Katrin Fischer --- .../prog/en/modules/members/boraccount.tt | 21 ++++++++++ members/boraccount.pl | 40 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt index de9a2f3d12..334f8c3f86 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt @@ -46,6 +46,17 @@
+ [% IF receipt_sent == '1' %] +
+ Receipt sent. +
+ [% END %] + [% IF receipt_sent == '-1' %] +
+ Receipt not sent, failed to find template. +
+ [% END %] + [% INCLUDE 'members-toolbar.inc' %]

Account for [% INCLUDE 'patron-title.inc' %]

@@ -124,7 +135,17 @@ [% IF account.amountoutstanding <= 0 %][% ELSE %][% END %][% account.amountoutstanding | $Price %] [% IF ( account.is_credit ) %] + [% IF Koha.Preference('UseEmailReceipts') %] +
+ + +
+ [% ELSE %] Print + [% END %] [% ELSE %] Print [% END %] diff --git a/members/boraccount.pl b/members/boraccount.pl index 83fa43bf65..2d625a459c 100755 --- a/members/boraccount.pl +++ b/members/boraccount.pl @@ -30,6 +30,7 @@ use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_htt use CGI qw ( -utf8 ); use C4::Members; use C4::Accounts; +use C4::Letters; use Koha::Cash::Registers; use Koha::Patrons; use Koha::Patron::Categories; @@ -171,6 +172,44 @@ if ( $action eq 'discount' ) { ); } +my $receipt_sent = 0; +if ( $action eq 'send_receipt' ) { + my $credit_id = scalar $input->param('accountlines_id'); + my $credit = Koha::Account::Lines->find($credit_id); + my @credit_offsets = + $credit->credit_offsets( { type => 'APPLY' } )->as_list; + if ( + my $letter = C4::Letters::GetPreparedLetter( + module => 'circulation', + letter_code => uc( "ACCOUNT_" . $credit->credit_type_code ), + message_transport_type => 'email', + lang => $patron->lang, + tables => { + borrowers => $patron->borrowernumber, + branches => C4::Context::mybranch, + }, + substitute => { + credit => $credit, + offsets => \@credit_offsets, + }, + ) + ) + { + my $message_id = C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $patron->borrowernumber, + message_transport_type => 'email', + } + ); + C4::Letters::SendQueuedMessages( { message_id => $message_id } ); + $receipt_sent = 1; + } + else { + $receipt_sent = -1; + } +} + #get account details my $total = $patron->account->balance; @@ -213,6 +252,7 @@ $template->param( payment_id => $payment_id, change_given => $change_given, renew_results => $renew_results_display, + receipt_sent => $receipt_sent, csrf_token => $csrf_token, ); -- 2.30.2