Bug 12497: Fix search history non-accessible when OPAC was private
[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 strict;
26 use warnings;
27
28 use C4::Auth;
29 use C4::Output;
30 use CGI qw ( -utf8 );
31 use C4::Members;
32 use C4::Accounts;
33 use Koha::DateUtils;
34 use Koha::Patrons;
35 use Koha::Patron::Categories;
36
37 my $input=new CGI;
38
39
40 my ($template, $loggedinuser, $cookie)
41     = get_template_and_user({template_name => "members/printfeercpt.tt",
42                             query => $input,
43                             type => "intranet",
44                             authnotrequired => 0,
45                             flagsrequired => {borrowers => 1, updatecharges => 'remaining_permissions'},
46                             debug => 1,
47                             });
48
49 my $borrowernumber=$input->param('borrowernumber');
50 my $action = $input->param('action') || '';
51 my $accountlines_id = $input->param('accountlines_id');
52
53 my $patron = Koha::Patrons->find( $borrowernumber );
54 unless ( $patron ) {
55     print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber");
56     exit;
57 }
58 my $category = $patron->category;
59 my $data = $patron->unblessed;
60 $data->{description} = $category->description;
61 $data->{category_type} = $category->category_type;
62
63 if ( $action eq 'print' ) {
64 #  ReversePayment( $borrowernumber, $input->param('accountno') );
65 }
66
67 if ( $data->{'category_type'} eq 'C') {
68     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
69     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
70     $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
71 }
72
73 #get account details
74 my ($total,$accts,$numaccts)=GetMemberAccountRecords($borrowernumber);
75 my $totalcredit;
76 if($total <= 0){
77         $totalcredit = 1;
78 }
79 my @accountrows; # this is for the tmpl-loop
80
81 my $toggle;
82 for (my $i=0;$i<$numaccts;$i++){
83     next if ( $accts->[$i]{'accountlines_id'} ne $accountlines_id );
84     if($i%2){
85             $toggle = 0;
86     } else {
87             $toggle = 1;
88     }
89     $accts->[$i]{'toggle'} = $toggle;
90     $accts->[$i]{'amount'}+=0.00;
91     if($accts->[$i]{'amount'} <= 0){
92         $accts->[$i]{'amountcredit'} = 1;
93         $accts->[$i]{'amount'}*=-1.00;
94     }
95     $accts->[$i]{'amountoutstanding'}+=0.00;
96     if($accts->[$i]{'amountoutstanding'} <= 0){
97         $accts->[$i]{'amountoutstandingcredit'} = 1;
98     }
99
100     my %row = ( 'date'         => dt_from_string( $accts->[$i]{'date'} ),
101                 'amountcredit' => $accts->[$i]{'amountcredit'},
102                 'amountoutstandingcredit' => $accts->[$i]{'amountoutstandingcredit'},
103                 'toggle' => $accts->[$i]{'toggle'},
104                 'description'       => $accts->[$i]{'description'},
105                                 'itemnumber'       => $accts->[$i]{'itemnumber'},
106                                 'biblionumber'       => $accts->[$i]{'biblionumber'},
107                 'amount'            => sprintf("%.2f",$accts->[$i]{'amount'}),
108                 'amountoutstanding' => sprintf("%.2f",$accts->[$i]{'amountoutstanding'}),
109                 'accountno' => $accts->[$i]{'accountno'},
110                 accounttype => $accts->[$i]{accounttype},
111                 'note' => $accts->[$i]{'note'},
112                 );
113
114     if ($accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU'){
115         $row{'printtitle'}=1;
116         $row{'title'} = $accts->[$i]{'title'};
117     }
118
119     push(@accountrows, \%row);
120 }
121
122 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' || $data->{'category_type'} eq 'I' );
123
124 $template->param( picture => 1 ) if $patron->image;
125
126 $template->param(
127     finesview           => 1,
128     firstname           => $data->{'firstname'},
129     surname             => $data->{'surname'},
130     borrowernumber      => $borrowernumber,
131     cardnumber          => $data->{'cardnumber'},
132     categorycode        => $data->{'categorycode'},
133     category_type       => $data->{'category_type'},
134  #   category_description => $data->{'description'},
135     categoryname                 => $data->{'description'},
136     address             => $data->{'address'},
137     address2            => $data->{'address2'},
138     city                => $data->{'city'},
139     zipcode             => $data->{'zipcode'},
140     country             => $data->{'country'},
141     phone               => $data->{'phone'},
142     email               => $data->{'email'},
143     branchcode          => $data->{'branchcode'},
144     total               => sprintf("%.2f",$total),
145     totalcredit         => $totalcredit,
146         is_child        => ($data->{'category_type'} eq 'C'),
147     accounts            => \@accountrows );
148
149 output_html_with_http_headers $input, $cookie, $template->output;