Bug 13897: Surround columns with backticks
[koha.git] / members / printfeercpt.pl
blob5c56514a9675612fd7f1bffde76d0180025417d6
1 #!/usr/bin/perl
4 #written 3rd May 2010 by kmkale@anantcorp.com adapted from boraccount.pl by chris@katipo.oc.nz
5 #script to print fee receipts
8 # Copyright Koustubha Kale
10 # This file is part of Koha.
12 # Koha is free software; you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 3 of the License, or
15 # (at your option) any later version.
17 # Koha is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 use Modern::Perl;
27 use C4::Auth;
28 use C4::Output;
29 use CGI qw ( -utf8 );
30 use C4::Members;
31 use C4::Accounts;
32 use C4::Letters;
33 use Koha::Account::Lines;
34 use Koha::DateUtils;
35 use Koha::Patrons;
36 use Koha::Patron::Categories;
38 my $input=new CGI;
41 my ($template, $loggedinuser, $cookie)
42 = get_template_and_user({template_name => "members/printfeercpt.tt",
43 query => $input,
44 type => "intranet",
45 authnotrequired => 0,
46 flagsrequired => {borrowers => 'edit_borrowers', updatecharges => 'remaining_permissions'},
47 debug => 1,
48 });
50 my $borrowernumber=$input->param('borrowernumber');
51 my $action = $input->param('action') || '';
52 my $accountlines_id = $input->param('accountlines_id');
53 my $change_given = $input->param('change_given');
55 my $logged_in_user = Koha::Patrons->find( $loggedinuser );
56 my $patron = Koha::Patrons->find( $borrowernumber );
57 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
59 #get account details
60 my $total = $patron->account->balance;
62 # FIXME This whole stuff is ugly and should be rewritten
63 # FIXME We should pass the $accts iterator to the template and do this formatting part there
64 my $accountline_object = Koha::Account::Lines->find($accountlines_id);
65 my $accountline = $accountline_object->unblessed;
66 my $totalcredit;
67 if($total <= 0){
68 $totalcredit = 1;
71 $accountline->{'amount'} += 0.00;
72 if ( $accountline->{'amount'} <= 0 ) {
73 $accountline->{'amountcredit'} = 1;
74 $accountline->{'amount'} *= -1.00;
76 $accountline->{'amountoutstanding'} += 0.00;
77 if ( $accountline->{'amountoutstanding'} <= 0 ) {
78 $accountline->{'amountoutstandingcredit'} = 1;
81 my $letter = C4::Letters::getletter( 'circulation', 'ACCOUNT_CREDIT', C4::Context::mybranch, 'print', $patron->lang );
83 my @account_offsets = Koha::Account::Offsets->search( { credit_id => $accountline_object->id } );
85 $template->param(
86 letter => $letter,
87 patron => $patron,
88 library => C4::Context::mybranch,
89 offsets => \@account_offsets,
90 credit => $accountline_object,
92 finesview => 1,
93 total => $total,
94 totalcredit => $totalcredit,
95 accounts => [$accountline], # FIXME There is always only 1 row!
97 change_given => $change_given,
100 output_html_with_http_headers $input, $cookie, $template->output;