Bug 12059: Prefer to list fields in the query
[koha.git] / members / boraccount.pl
blob50f5db9fd12ccb99378a4b71af69bfa57b63ec1e
1 #!/usr/bin/perl
4 #writen 11/1/2000 by chris@katipo.oc.nz
5 #script to display borrowers account details
8 # Copyright 2000-2002 Katipo Communications
10 # This file is part of Koha.
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.
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.
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.
25 use strict;
26 use warnings;
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);
37 my $input=new CGI;
40 my ($template, $loggedinuser, $cookie) = get_template_and_user(
42 template_name => "members/boraccount.tt",
43 query => $input,
44 type => "intranet",
45 authnotrequired => 0,
46 flagsrequired => { borrowers => 1,
47 updatecharges => 'remaining_permissions'},
48 debug => 1,
52 my $borrowernumber=$input->param('borrowernumber');
53 my $action = $input->param('action') || '';
55 #get borrower details
56 my $data=GetMember('borrowernumber' => $borrowernumber);
58 if ( $action eq 'reverse' ) {
59 ReversePayment( $input->param('accountlines_id') );
62 if ( $data->{'category_type'} eq 'C') {
63 my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
64 my $cnt = scalar(@$catcodes);
65 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
66 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
69 #get account details
70 my ($total,$accts,undef)=GetMemberAccountRecords($borrowernumber);
71 my $totalcredit;
72 if($total <= 0){
73 $totalcredit = 1;
76 my $reverse_col = 0; # Flag whether we need to show the reverse column
77 foreach my $accountline ( @{$accts}) {
78 $accountline->{amount} += 0.00;
79 if ($accountline->{amount} <= 0 ) {
80 $accountline->{amountcredit} = 1;
82 $accountline->{amountoutstanding} += 0.00;
83 if ( $accountline->{amountoutstanding} <= 0 ) {
84 $accountline->{amountoutstandingcredit} = 1;
87 $accountline->{date} = format_date($accountline->{date});
88 $accountline->{amount} = sprintf '%.2f', $accountline->{amount};
89 $accountline->{amountoutstanding} = sprintf '%.2f', $accountline->{amountoutstanding};
90 if ($accountline->{accounttype} =~ /^Pay/) {
91 $accountline->{payment} = 1;
92 $reverse_col = 1;
96 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
98 my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'});
99 $template->param( picture => 1 ) if $picture;
101 if (C4::Context->preference('ExtendedPatronAttributes')) {
102 my $attributes = GetBorrowerAttributes($borrowernumber);
103 $template->param(
104 ExtendedPatronAttributes => 1,
105 extendedattributes => $attributes
109 # Computes full borrower address
110 my $roadtype = C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $data->{streettype} );
111 my $address = $data->{'streetnumber'} . " $roadtype " . $data->{'address'};
113 $template->param(
114 finesview => 1,
115 firstname => $data->{'firstname'},
116 surname => $data->{'surname'},
117 othernames => $data->{'othernames'},
118 borrowernumber => $borrowernumber,
119 cardnumber => $data->{'cardnumber'},
120 categorycode => $data->{'categorycode'},
121 category_type => $data->{'category_type'},
122 categoryname => $data->{'description'},
123 address => $address,
124 address2 => $data->{'address2'},
125 city => $data->{'city'},
126 state => $data->{'state'},
127 zipcode => $data->{'zipcode'},
128 country => $data->{'country'},
129 phone => $data->{'phone'},
130 phonepro => $data->{'phonepro'},
131 mobile => $data->{'mobile'},
132 email => $data->{'email'},
133 emailpro => $data->{'emailpro'},
134 branchcode => $data->{'branchcode'},
135 branchname => GetBranchName($data->{'branchcode'}),
136 total => sprintf("%.2f",$total),
137 totalcredit => $totalcredit,
138 is_child => ($data->{'category_type'} eq 'C'),
139 reverse_col => $reverse_col,
140 accounts => $accts,
141 activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''),
142 RoutingSerials => C4::Context->preference('RoutingSerials'),
145 output_html_with_http_headers $input, $cookie, $template->output;