Bug 26638: DBRev 20.06.00.057
[koha.git] / members / printinvoice.pl
blob9fd49fb178858bd533aaddb5ccdfd2639eccec49
1 #!/usr/bin/perl
3 #written 3rd May 2010 by kmkale@anantcorp.com adapted from boraccount.pl by chris@katipo.oc.nz
4 #script to print fee receipts
6 # Copyright Koustubha Kale
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use Modern::Perl;
25 use C4::Auth;
26 use C4::Output;
27 use Koha::DateUtils;
28 use CGI qw ( -utf8 );
29 use C4::Members;
30 use C4::Accounts;
32 use Koha::Account::Lines;
33 use Koha::Patrons;
34 use Koha::Patron::Categories;
36 my $input = CGI->new;
38 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39 { template_name => "members/printinvoice.tt",
40 query => $input,
41 type => "intranet",
42 flagsrequired => { borrowers => 'edit_borrowers', updatecharges => 'remaining_permissions' },
43 debug => 1,
47 my $borrowernumber = $input->param('borrowernumber');
48 my $action = $input->param('action') || '';
49 my $accountlines_id = $input->param('accountlines_id');
51 my $logged_in_user = Koha::Patrons->find( $loggedinuser );
52 my $patron = Koha::Patrons->find( $borrowernumber );
53 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
55 #get account details
56 my $total = $patron->account->balance;
57 my $accountline_object = Koha::Account::Lines->find($accountlines_id);
58 my $accountline = $accountline_object->unblessed;
60 my $totalcredit;
61 if ( $total <= 0 ) {
62 $totalcredit = 1;
66 $accountline->{'amount'} += 0.00;
67 if ( $accountline->{'amount'} <= 0 ) {
68 $accountline->{'amountcredit'} = 1;
69 $accountline->{'amount'} *= -1.00;
71 $accountline->{'amountoutstanding'} += 0.00;
72 if ( $accountline->{'amountoutstanding'} <= 0 ) {
73 $accountline->{'amountoutstandingcredit'} = 1;
76 my @account_offsets = Koha::Account::Offsets->search( { debit_id => $accountline_object->id } );
78 my $letter = C4::Letters::getletter( 'circulation', 'ACCOUNT_DEBIT', C4::Context::mybranch, 'print', $patron->lang );
80 $template->param(
81 letter => $letter,
82 patron => $patron,
83 library => C4::Context::mybranch,
84 offsets => \@account_offsets,
85 debit => $accountline_object,
87 finesview => 1,
88 total => sprintf( "%.2f", $total ),
89 totalcredit => $totalcredit,
90 accounts => [$accountline], # FIXME There is always only 1 row!
93 output_html_with_http_headers $input, $cookie, $template->output;