Correcting code to display patronimage correctly
[koha.git] / members / boraccount.pl
1 #!/usr/bin/perl
2
3
4 #writen 11/1/2000 by chris@katipo.oc.nz
5 #script to display borrowers account details
6
7
8 # Copyright 2000-2002 Katipo Communications
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 #
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA  02111-1307 USA
24
25 use strict;
26 use C4::Auth;
27 use C4::Output;
28 use C4::Dates qw/format_date/;
29 use CGI;
30 use C4::Members;
31
32
33 my $input=new CGI;
34
35
36 my ($template, $loggedinuser, $cookie)
37     = get_template_and_user({template_name => "members/boraccount.tmpl",
38                             query => $input,
39                             type => "intranet",
40                             authnotrequired => 0,
41                             flagsrequired => {borrowers => 1},
42                             debug => 1,
43                             });
44
45 my $borrowernumber=$input->param('borrowernumber');
46 #get borrower details
47 my $data=GetMember($borrowernumber,'borrowernumber');
48
49 #get account details
50 my ($total,$accts,$numaccts)=GetMemberAccountRecords($borrowernumber);
51 my $totalcredit;
52 if($total <= 0){
53         $totalcredit = 1;
54 }
55 my @accountrows; # this is for the tmpl-loop
56
57 my $toggle;
58 for (my $i=0;$i<$numaccts;$i++){
59     if($i%2){
60             $toggle = 0;
61     } else {
62             $toggle = 1;
63     }
64     $accts->[$i]{'toggle'} = $toggle;
65     $accts->[$i]{'amount'}+=0.00;
66     if($accts->[$i]{'amount'} <= 0){
67         $accts->[$i]{'amountcredit'} = 1;
68     }
69     $accts->[$i]{'amountoutstanding'}+=0.00;
70     if($accts->[$i]{'amountoutstanding'} <= 0){
71         $accts->[$i]{'amountoutstandingcredit'} = 1;
72     }
73     my %row = ( 'date'              => format_date($accts->[$i]{'date'}),
74                 'amountcredit' => $accts->[$i]{'amountcredit'},
75                 'amountoutstandingcredit' => $accts->[$i]{'amountoutstandingcredit'},
76                 'toggle' => $accts->[$i]{'toggle'},
77                 'description'       => $accts->[$i]{'description'},
78                 'amount'            => sprintf("%.2f",$accts->[$i]{'amount'}),
79                 'amountoutstanding' => sprintf("%.2f",$accts->[$i]{'amountoutstanding'}) );
80     
81     if ($accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU'){
82         $row{'printtitle'}=1;
83         $row{'title'} = $accts->[$i]{'title'};
84     }
85     
86     push(@accountrows, \%row);
87 }
88
89 my $borrowercategory = GetBorrowercategory( $data->{'categorycode'} );
90 my $category_type = $borrowercategory->{'category_type'};
91 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
92
93 my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
94 $template->param( picture => 1 ) if $picture;
95
96 $template->param(
97     finesview           => 1,
98     firstname           => $data->{'firstname'},
99     surname             => $data->{'surname'},
100     borrowernumber      => $borrowernumber,
101     cardnumber          => $data->{'cardnumber'},
102     categorycode        => $data->{'categorycode'},
103     category_type       => $data->{'category_type'},
104     category_description => $data->{'description'},
105     address             => $data->{'address'},
106     address2            => $data->{'address2'},
107     city                => $data->{'city'},
108     zipcode             => $data->{'zipcode'},
109     phone               => $data->{'phone'},
110     email               => $data->{'email'},
111     branchcode          => $data->{'branchcode'},
112     total               => sprintf("%.2f",$total),
113     totalcredit         => $totalcredit,
114     accounts            => \@accountrows );
115
116 output_html_with_http_headers $input, $cookie, $template->output;