Bug 18789: Use Koha::Patron->is_adult where needed
[koha.git] / members / printfeercpt.pl
1 #!/usr/bin/perl
2
3
4 #written 3rd May 2010 by kmkale@anantcorp.com adapted from boraccount.pl by chris@katipo.oc.nz
5 #script to print fee receipts
6
7
8 # Copyright Koustubha Kale
9 #
10 # This file is part of Koha.
11 #
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.
16 #
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.
21 #
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>.
24
25 use Modern::Perl;
26
27 use C4::Auth;
28 use C4::Output;
29 use CGI qw ( -utf8 );
30 use C4::Members;
31 use C4::Accounts;
32 use Koha::DateUtils;
33 use Koha::Patrons;
34 use Koha::Patron::Categories;
35
36 my $input=new CGI;
37
38
39 my ($template, $loggedinuser, $cookie)
40     = get_template_and_user({template_name => "members/printfeercpt.tt",
41                             query => $input,
42                             type => "intranet",
43                             authnotrequired => 0,
44                             flagsrequired => {borrowers => 'edit_borrowers', updatecharges => 'remaining_permissions'},
45                             debug => 1,
46                             });
47
48 my $borrowernumber=$input->param('borrowernumber');
49 my $action = $input->param('action') || '';
50 my $accountlines_id = $input->param('accountlines_id');
51
52 my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
53 my $patron         = Koha::Patrons->find( $borrowernumber );
54 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
55
56 my $category = $patron->category;
57
58 if ( $action eq 'print' ) {
59 #  ReversePayment( $borrowernumber, $input->param('accountno') );
60 }
61
62 if ( $category->category_type eq 'C') {
63     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
64     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
65     $template->param( 'catcode' => $patron_categories->next->categorycde )  if $patron_categories->count == 1;
66 }
67
68 #get account details
69 my ($total,$accts,$numaccts)=GetMemberAccountRecords($borrowernumber);
70 my $totalcredit;
71 if($total <= 0){
72         $totalcredit = 1;
73 }
74 my @accountrows; # this is for the tmpl-loop
75
76 my $toggle;
77 for (my $i=0;$i<$numaccts;$i++){
78     next if ( $accts->[$i]{'accountlines_id'} ne $accountlines_id );
79     if($i%2){
80             $toggle = 0;
81     } else {
82             $toggle = 1;
83     }
84     $accts->[$i]{'toggle'} = $toggle;
85     $accts->[$i]{'amount'}+=0.00;
86     if($accts->[$i]{'amount'} <= 0){
87         $accts->[$i]{'amountcredit'} = 1;
88         $accts->[$i]{'amount'}*=-1.00;
89     }
90     $accts->[$i]{'amountoutstanding'}+=0.00;
91     if($accts->[$i]{'amountoutstanding'} <= 0){
92         $accts->[$i]{'amountoutstandingcredit'} = 1;
93     }
94
95     my %row = ( 'date'         => dt_from_string( $accts->[$i]{'date'} ),
96                 'amountcredit' => $accts->[$i]{'amountcredit'},
97                 'amountoutstandingcredit' => $accts->[$i]{'amountoutstandingcredit'},
98                 'toggle' => $accts->[$i]{'toggle'},
99                 'description'       => $accts->[$i]{'description'},
100                                 'itemnumber'       => $accts->[$i]{'itemnumber'},
101                                 'biblionumber'       => $accts->[$i]{'biblionumber'},
102                 'amount'            => sprintf("%.2f",$accts->[$i]{'amount'}),
103                 'amountoutstanding' => sprintf("%.2f",$accts->[$i]{'amountoutstanding'}),
104                 'accountno' => $accts->[$i]{'accountno'},
105                 accounttype => $accts->[$i]{accounttype},
106                 'note' => $accts->[$i]{'note'},
107                 );
108
109     if ($accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU'){
110         $row{'printtitle'}=1;
111         $row{'title'} = $accts->[$i]{'title'};
112     }
113
114     push(@accountrows, \%row);
115 }
116
117 $template->param(
118     patron               => $patron,
119     finesview           => 1,
120     total               => sprintf("%.2f",$total),
121     totalcredit         => $totalcredit,
122     accounts            => \@accountrows );
123
124 output_html_with_http_headers $input, $cookie, $template->output;