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