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 <sally.healey@cheshiresharedservices.gov.uk>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Martin Renvoize 2022-08-24 08:28:12 +01:00 committed by Tomas Cohen Arazi
parent bdc2deba99
commit a4b687c3aa
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 61 additions and 0 deletions

View file

@ -42,6 +42,17 @@
<div class="col-sm-10 col-sm-push-2">
<main>
[% IF receipt_sent == '1' %]
<div id="receipt_sent_dialog" class="dialog message">
Receipt sent.
</div>
[% END %]
[% IF receipt_sent == '-1' %]
<div id="receipt_sent_dialog" class="dialog warning">
Receipt not sent, failed to find template.
</div>
[% END %]
[% INCLUDE 'members-toolbar.inc' %]
<h1>Account for [% INCLUDE 'patron-title.inc' %]</h1>
<form action="/cgi-bin/koha/members/boraccount.pl" method="get"><input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber | html %]" /></form>
@ -120,7 +131,17 @@
[% IF account.amountoutstanding <= 0 %]<td class="credit" style="text-align: right;">[% ELSE %]<td class="debit" style="text-align: right;">[% END %][% account.amountoutstanding | $Price %]</td>
<td class="actions">
[% IF ( account.is_credit ) %]
[% IF Koha.Preference('UseEmailReceipts') %]
<div class="btn-group">
<button class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown"><i class="fa fa-receipt"></i> Receipt <span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right">
<li><a target="_blank" href="printfeercpt.pl?accountlines_id=[% account.accountlines_id | uri %]" class="receipt-print-action"><i class="fa fa-print"></i> Print</a></li>
<li><a href="boraccount.pl?action=send_receipt&amp;accountlines_id=[% account.accountlines_id | uri %]&amp;borrowernumber=[% account.borrowernumber | uri %]" class="receipt-email-action"><i class="fa fa-envelope"></i> Email</a></li>
</ul>
</div>
[% ELSE %]
<a target="_blank" href="printfeercpt.pl?action=print&amp;accountlines_id=[% account.accountlines_id | uri %]" class="btn btn-default btn-xs receipt-print-action"><i class="fa fa-print"></i> Print</a>
[% END %]
[% ELSE %]
<a target="_blank" href="printinvoice.pl?action=print&amp;accountlines_id=[% account.accountlines_id | uri %]" class="btn btn-default btn-xs invoice-print-action"><i class="fa fa-print"></i> Print</a>
[% END %]

View file

@ -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,
);