Bug 15407: Koha::Patron::Categories - replace GetborCatFromCatType
[koha.git] / members / boraccount.pl
blob7fb52b9b2d83538416d19e5d4f895890cafddaff
1 #!/usr/bin/perl
4 #written 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
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.
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.
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>.
25 use strict;
26 use warnings;
28 use C4::Auth;
29 use C4::Output;
30 use CGI qw ( -utf8 );
31 use C4::Members;
32 use C4::Branch;
33 use C4::Accounts;
34 use C4::Members::Attributes qw(GetBorrowerAttributes);
35 use Koha::Patron::Images;
37 use Koha::Patron::Categories;
39 my $input=new CGI;
42 my ($template, $loggedinuser, $cookie) = get_template_and_user(
44 template_name => "members/boraccount.tt",
45 query => $input,
46 type => "intranet",
47 authnotrequired => 0,
48 flagsrequired => { borrowers => 1,
49 updatecharges => 'remaining_permissions'},
50 debug => 1,
54 my $borrowernumber=$input->param('borrowernumber');
55 my $action = $input->param('action') || '';
57 #get borrower details
58 my $data=GetMember('borrowernumber' => $borrowernumber);
60 if ( $action eq 'reverse' ) {
61 ReversePayment( $input->param('accountlines_id') );
64 if ( $data->{'category_type'} eq 'C') {
65 my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
66 $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
67 $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1;
70 #get account details
71 my ($total,$accts,undef)=GetMemberAccountRecords($borrowernumber);
72 my $totalcredit;
73 if($total <= 0){
74 $totalcredit = 1;
77 my $reverse_col = 0; # Flag whether we need to show the reverse column
78 foreach my $accountline ( @{$accts}) {
79 $accountline->{amount} += 0.00;
80 if ($accountline->{amount} <= 0 ) {
81 $accountline->{amountcredit} = 1;
83 $accountline->{amountoutstanding} += 0.00;
84 if ( $accountline->{amountoutstanding} <= 0 ) {
85 $accountline->{amountoutstandingcredit} = 1;
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 $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
99 $template->param( picture => 1 ) if $patron_image;
101 if (C4::Context->preference('ExtendedPatronAttributes')) {
102 my $attributes = GetBorrowerAttributes($borrowernumber);
103 $template->param(
104 ExtendedPatronAttributes => 1,
105 extendedattributes => $attributes
109 $template->param(%$data);
111 $template->param(
112 finesview => 1,
113 borrowernumber => $borrowernumber,
114 branchname => GetBranchName($data->{'branchcode'}),
115 total => sprintf("%.2f",$total),
116 totalcredit => $totalcredit,
117 is_child => ($data->{'category_type'} eq 'C'),
118 reverse_col => $reverse_col,
119 accounts => $accts,
120 activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''),
121 RoutingSerials => C4::Context->preference('RoutingSerials'),
124 output_html_with_http_headers $input, $cookie, $template->output;