Merge remote branch 'kc/new/bug_3072' into kcmaster
[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
22 # with Koha; if not, write to the Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25 use strict;
26 use warnings;
27
28 use C4::Auth;
29 use C4::Output;
30 use C4::Dates qw/format_date/;
31 use CGI;
32 use C4::Members;
33 use C4::Branch;
34 use C4::Accounts;
35
36 my $input=new CGI;
37
38
39 my ($template, $loggedinuser, $cookie)
40     = get_template_and_user({template_name => "members/boraccount.tmpl",
41                             query => $input,
42                             type => "intranet",
43                             authnotrequired => 0,
44                             flagsrequired => {borrowers => 1, updatecharges => 1},
45                             debug => 1,
46                             });
47
48 my $borrowernumber=$input->param('borrowernumber');
49 my $action = $input->param('action') || '';
50
51 #get borrower details
52 my $data=GetMember('borrowernumber' => $borrowernumber);
53
54 if ( $action eq 'reverse' ) {
55   ReversePayment( $borrowernumber, $input->param('accountno') );
56 }
57
58 if ( $data->{'category_type'} eq 'C') {
59    my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
60    my $cnt = scalar(@$catcodes);
61    $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
62    $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
63 }
64
65 #get account details
66 my ($total,$accts,undef)=GetMemberAccountRecords($borrowernumber);
67 my $totalcredit;
68 if($total <= 0){
69         $totalcredit = 1;
70 }
71
72 my $reverse_col = 0; # Flag whether we need to show the reverse column
73 foreach my $accountline ( @{$accts}) {
74     $accountline->{amount} += 0.00;
75     if ($accountline->{amount} <= 0 ) {
76         $accountline->{amountcredit} = 1;
77     }
78     $accountline->{amountoutstanding} += 0.00;
79     if ( $accountline->{amountoutstanding} <= 0 ) {
80         $accountline->{amountoutstandingcredit} = 1;
81     }
82
83     $accountline->{date} = format_date($accountline->{date});
84     $accountline->{amount} = sprintf '%.2f', $accountline->{amount};
85     $accountline->{amountoutstanding} = sprintf '%.2f', $accountline->{amountoutstanding};
86     if ($accountline->{accounttype} eq 'Pay') {
87         $accountline->{payment} = 1;
88         $reverse_col = 1;
89     }
90     if ($accountline->{accounttype} ne 'F' && $accountline->{accounttype} ne 'FU'){
91         $accountline->{printtitle} = 1;
92     }
93 }
94
95 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
96
97 my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
98 $template->param( picture => 1 ) if $picture;
99
100 $template->param(
101     finesview           => 1,
102     firstname           => $data->{'firstname'},
103     surname             => $data->{'surname'},
104     borrowernumber      => $borrowernumber,
105     cardnumber          => $data->{'cardnumber'},
106     categorycode        => $data->{'categorycode'},
107     category_type       => $data->{'category_type'},
108     categoryname                 => $data->{'description'},
109     address             => $data->{'address'},
110     address2            => $data->{'address2'},
111     city                => $data->{'city'},
112     state               => $data->{'state'},
113     zipcode             => $data->{'zipcode'},
114     country             => $data->{'country'},
115     phone               => $data->{'phone'},
116     email               => $data->{'email'},
117     branchcode          => $data->{'branchcode'},
118         branchname                      => GetBranchName($data->{'branchcode'}),
119     total               => sprintf("%.2f",$total),
120     totalcredit         => $totalcredit,
121     is_child            => ($data->{'category_type'} eq 'C'),
122     reverse_col         => $reverse_col,
123     accounts            => $accts );
124
125 output_html_with_http_headers $input, $cookie, $template->output;