d366cc878063fd86e681fe8e147d1b15a7ca3ccf
[koha.git] / members / printfeercpt.pl
1 #!/usr/bin/perl
2
3 # Copyright Koustubha Kale 2010
4 # Copyright PTFS Europe 2020
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21 use Modern::Perl;
22
23 use C4::Auth qw( get_template_and_user );
24 use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
25 use CGI qw ( -utf8 );
26 use C4::Letters;
27 use Koha::Account::Lines;
28
29 my $input = CGI->new;
30
31 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
32     {
33         template_name => "members/printfeercpt.tt",
34         query         => $input,
35         type          => "intranet",
36         flagsrequired => {
37             borrowers     => 'edit_borrowers',
38             updatecharges => 'remaining_permissions'
39         }
40     }
41 );
42
43 my $credit_id = $input->param('accountlines_id');
44 my $credit    = Koha::Account::Lines->find($credit_id);
45 my $patron    = $credit->patron;
46
47 my $logged_in_user = Koha::Patrons->find($loggedinuser) or die "Not logged in";
48 output_and_exit_if_error(
49     $input, $cookie,
50     $template,
51     {
52         module         => 'members',
53         logged_in_user => $logged_in_user,
54         current_patron => $patron
55     }
56 );
57
58 my $letter = C4::Letters::GetPreparedLetter(
59     module                 => 'circulation',
60     letter_code            => 'ACCOUNT_CREDIT',
61     branchcode             => C4::Context::mybranch,
62     message_transport_type => 'print',
63     lang                   => $patron->lang,
64     tables                 => {
65         credits   => $credit_id,
66         borrowers => $patron->borrowernumber
67     },
68     substitute => {
69         tendered => scalar $input->param('tendered'),
70         change   => scalar $input->param('change')
71     }
72 );
73
74 $template->param(
75     slip   => $letter->{content},
76     plain  => !$letter->{is_html},
77     patron => $patron,
78 );
79
80 output_html_with_http_headers $input, $cookie, $template->output;