From fa1cc46e772580a455b6533934b6923bcc76a0c4 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 --- .../prog/en/modules/members/boraccount.tt | 10 ++ members/printfeercpt.pl | 106 ++++++++++++------ 2 files changed, 79 insertions(+), 37 deletions(-) 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 5223997277..5ebc349819 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt @@ -106,7 +106,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/printfeercpt.pl b/members/printfeercpt.pl index 6c695e469a..0cc2bc25bc 100755 --- a/members/printfeercpt.pl +++ b/members/printfeercpt.pl @@ -21,7 +21,8 @@ use Modern::Perl; use C4::Auth qw( get_template_and_user ); -use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers ); +use C4::Output + qw( output_and_exit_if_error output_and_exit output_html_with_http_headers ); use CGI qw ( -utf8 ); use C4::Letters; use Koha::Account::Lines; @@ -40,6 +41,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); +my $action = $input->param('action'); my $credit_id = $input->param('accountlines_id'); my $credit = Koha::Account::Lines->find($credit_id); my $patron = $credit->patron; @@ -55,42 +57,72 @@ output_and_exit_if_error( } ); -my $letter = C4::Letters::GetPreparedLetter( - module => 'circulation', - letter_code => 'CREDIT_' . $credit->credit_type_code, - branchcode => C4::Context::mybranch, - message_transport_type => 'print', - lang => $patron->lang, - tables => { - credits => $credit_id, - borrowers => $patron->borrowernumber - }, - substitute => { - tendered => scalar $input->param('tendered'), - change => scalar $input->param('change') - } -); +if ( $action eq 'print' ) { + my $letter = C4::Letters::GetPreparedLetter( + module => 'circulation', + letter_code => 'CREDIT_' . $credit->credit_type_code, + branchcode => C4::Context::mybranch, + message_transport_type => 'print', + lang => $patron->lang, + tables => { + credits => $credit_id, + borrowers => $patron->borrowernumber + }, + substitute => { + tendered => scalar $input->param('tendered'), + change => scalar $input->param('change') + } + ); -$letter //= C4::Letters::GetPreparedLetter( - module => 'circulation', - letter_code => 'ACCOUNT_CREDIT', - branchcode => C4::Context::mybranch, - message_transport_type => 'print', - lang => $patron->lang, - tables => { - credits => $credit_id, - borrowers => $patron->borrowernumber - }, - substitute => { - tendered => scalar $input->param('tendered'), - change => scalar $input->param('change') - } -); + $letter //= C4::Letters::GetPreparedLetter( + module => 'circulation', + letter_code => 'ACCOUNT_CREDIT', + branchcode => C4::Context::mybranch, + message_transport_type => 'print', + lang => $patron->lang, + tables => { + credits => $credit_id, + borrowers => $patron->borrowernumber + }, + substitute => { + tendered => scalar $input->param('tendered'), + change => scalar $input->param('change') + } + ); -$template->param( - slip => $letter->{content}, - plain => !$letter->{is_html}, - patron => $patron, -); + $template->param( + slip => $letter->{content}, + plain => !$letter->{is_html}, + patron => $patron, + ); + + output_html_with_http_headers $input, $cookie, $template->output; +} +elsif ( $action eq 'email' ) { + if ( + my $letter = C4::Letters::GetPreparedLetter( + module => 'circulation', + letter_code => uc("ACCOUNT_$type"), + message_transport_type => 'email', + lang => $patron->lang, + tables => { + borrowers => $patron->borrowernumber, + branches => $library_id, + }, + substitute => { + credit => $payment, + offsets => \@account_offsets, + }, + ) + ) + { + C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $patron->borrowernumber, + message_transport_type => 'email', + } + ) or warn "can't enqueue letter $letter"; + } -output_html_with_http_headers $input, $cookie, $template->output; +} -- 2.20.1