Bug 20009: use Modern::Perl in Members perl scripts
[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 => 1, 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 $patron = Koha::Patrons->find( $borrowernumber );
53 unless ( $patron ) {
54     print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber");
55     exit;
56 }
57 my $category = $patron->category;
58 my $data = $patron->unblessed;
59 $data->{description} = $category->description;
60 $data->{category_type} = $category->category_type;
61
62 if ( $action eq 'print' ) {
63 #  ReversePayment( $borrowernumber, $input->param('accountno') );
64 }
65
66 if ( $data->{'category_type'} eq 'C') {
67     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
68     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
69     $template->param( 'catcode' => $patron_categories->next->categorycde )  if $patron_categories->count == 1;
70 }
71
72 #get account details
73 my ($total,$accts,$numaccts)=GetMemberAccountRecords($borrowernumber);
74 my $totalcredit;
75 if($total <= 0){
76         $totalcredit = 1;
77 }
78 my @accountrows; # this is for the tmpl-loop
79
80 my $toggle;
81 for (my $i=0;$i<$numaccts;$i++){
82     next if ( $accts->[$i]{'accountlines_id'} ne $accountlines_id );
83     if($i%2){
84             $toggle = 0;
85     } else {
86             $toggle = 1;
87     }
88     $accts->[$i]{'toggle'} = $toggle;
89     $accts->[$i]{'amount'}+=0.00;
90     if($accts->[$i]{'amount'} <= 0){
91         $accts->[$i]{'amountcredit'} = 1;
92         $accts->[$i]{'amount'}*=-1.00;
93     }
94     $accts->[$i]{'amountoutstanding'}+=0.00;
95     if($accts->[$i]{'amountoutstanding'} <= 0){
96         $accts->[$i]{'amountoutstandingcredit'} = 1;
97     }
98
99     my %row = ( 'date'         => dt_from_string( $accts->[$i]{'date'} ),
100                 'amountcredit' => $accts->[$i]{'amountcredit'},
101                 'amountoutstandingcredit' => $accts->[$i]{'amountoutstandingcredit'},
102                 'toggle' => $accts->[$i]{'toggle'},
103                 'description'       => $accts->[$i]{'description'},
104                                 'itemnumber'       => $accts->[$i]{'itemnumber'},
105                                 'biblionumber'       => $accts->[$i]{'biblionumber'},
106                 'amount'            => sprintf("%.2f",$accts->[$i]{'amount'}),
107                 'amountoutstanding' => sprintf("%.2f",$accts->[$i]{'amountoutstanding'}),
108                 'accountno' => $accts->[$i]{'accountno'},
109                 accounttype => $accts->[$i]{accounttype},
110                 'note' => $accts->[$i]{'note'},
111                 );
112
113     if ($accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU'){
114         $row{'printtitle'}=1;
115         $row{'title'} = $accts->[$i]{'title'};
116     }
117
118     push(@accountrows, \%row);
119 }
120
121 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' || $data->{'category_type'} eq 'I' );
122
123 $template->param( picture => 1 ) if $patron->image;
124
125 $template->param(
126     finesview           => 1,
127     firstname           => $data->{'firstname'},
128     surname             => $data->{'surname'},
129     borrowernumber      => $borrowernumber,
130     cardnumber          => $data->{'cardnumber'},
131     categorycode        => $data->{'categorycode'},
132     category_type       => $data->{'category_type'},
133  #   category_description => $data->{'description'},
134     categoryname                 => $data->{'description'},
135     address             => $data->{'address'},
136     address2            => $data->{'address2'},
137     city                => $data->{'city'},
138     zipcode             => $data->{'zipcode'},
139     country             => $data->{'country'},
140     phone               => $data->{'phone'},
141     email               => $data->{'email'},
142     branchcode          => $data->{'branchcode'},
143     total               => sprintf("%.2f",$total),
144     totalcredit         => $totalcredit,
145         is_child        => ($data->{'category_type'} eq 'C'),
146     accounts            => \@accountrows );
147
148 output_html_with_http_headers $input, $cookie, $template->output;