Bug 15758: Koha::Libraries - Remove GetBranchName
[koha.git] / members / printinvoice.pl
1 #!/usr/bin/perl
2
3 #written 3rd May 2010 by kmkale@anantcorp.com adapted from boraccount.pl by chris@katipo.oc.nz
4 #script to print fee receipts
5
6 # Copyright Koustubha Kale
7 #
8 # This file is part of Koha.
9 #
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.
14 #
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.
19 #
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>.
22
23 use strict;
24 use warnings;
25
26 use C4::Auth;
27 use C4::Output;
28 use Koha::DateUtils;
29 use CGI qw ( -utf8 );
30 use C4::Members;
31 use C4::Branch;
32 use C4::Accounts;
33 use Koha::Patron::Images;
34
35 use Koha::Patron::Categories;
36
37 my $input = new CGI;
38
39 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
40     {   template_name   => "members/printinvoice.tt",
41         query           => $input,
42         type            => "intranet",
43         authnotrequired => 0,
44         flagsrequired => { borrowers => 1, updatecharges => 'remaining_permissions' },
45         debug           => 1,
46     }
47 );
48
49 my $borrowernumber  = $input->param('borrowernumber');
50 my $action          = $input->param('action') || '';
51 my $accountlines_id = $input->param('accountlines_id');
52
53 #get borrower details
54 my $data = GetMember( 'borrowernumber' => $borrowernumber );
55
56 if ( $data->{'category_type'} eq 'C' ) {
57     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
58     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
59     $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
60 }
61
62 #get account details
63 my ( $total, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber);
64 my $totalcredit;
65 if ( $total <= 0 ) {
66     $totalcredit = 1;
67 }
68
69 my @accountrows;    # this is for the tmpl-loop
70
71 my $toggle;
72 for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
73     next if ( $accts->[$i]{'accountlines_id'} ne $accountlines_id );
74
75     if ( $i % 2 ) {
76         $toggle = 0;
77     } else {
78         $toggle = 1;
79     }
80
81     $accts->[$i]{'toggle'} = $toggle;
82     $accts->[$i]{'amount'} += 0.00;
83
84     if ( $accts->[$i]{'amount'} <= 0 ) {
85         $accts->[$i]{'amountcredit'} = 1;
86     }
87
88     $accts->[$i]{'amountoutstanding'} += 0.00;
89     if ( $accts->[$i]{'amountoutstanding'} <= 0 ) {
90         $accts->[$i]{'amountoutstandingcredit'} = 1;
91     }
92
93     my %row = (
94         'date'                    => output_pref({ dt => dt_from_string( $accts->[$i]{'date'} ), dateonly => 1 }),
95         'amountcredit'            => $accts->[$i]{'amountcredit'},
96         'amountoutstandingcredit' => $accts->[$i]{'amountoutstandingcredit'},
97         'toggle'                  => $accts->[$i]{'toggle'},
98         'description'             => $accts->[$i]{'description'},
99         'itemnumber'              => $accts->[$i]{'itemnumber'},
100         'biblionumber'            => $accts->[$i]{'biblionumber'},
101         'amount'                  => sprintf( "%.2f", $accts->[$i]{'amount'} ),
102         'amountoutstanding'       => sprintf( "%.2f", $accts->[$i]{'amountoutstanding'} ),
103         'accountno'               => $accts->[$i]{'accountno'},
104         accounttype               => $accts->[$i]{accounttype},
105     );
106
107     if ( $accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU' ) {
108         $row{'printtitle'} = 1;
109         $row{'title'}      = $accts->[$i]{'title'};
110     }
111
112     push( @accountrows, \%row );
113 }
114
115 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
116
117 my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
118 $template->param( picture => 1 ) if $patron_image;
119
120 $template->param(
121     finesview      => 1,
122     firstname      => $data->{'firstname'},
123     surname        => $data->{'surname'},
124     borrowernumber => $borrowernumber,
125     cardnumber     => $data->{'cardnumber'},
126     categorycode   => $data->{'categorycode'},
127     category_type  => $data->{'category_type'},
128     categoryname   => $data->{'description'},
129     address        => $data->{'address'},
130     address2       => $data->{'address2'},
131     city           => $data->{'city'},
132     zipcode        => $data->{'zipcode'},
133     country        => $data->{'country'},
134     phone          => $data->{'phone'},
135     email          => $data->{'email'},
136     branchcode     => $data->{'branchcode'},
137     total          => sprintf( "%.2f", $total ),
138     totalcredit    => $totalcredit,
139     is_child       => ( $data->{'category_type'} eq 'C' ),
140     accounts       => \@accountrows
141 );
142
143 output_html_with_http_headers $input, $cookie, $template->output;