rel_3_0 moved to HEAD
[koha.git] / opac / opac-account.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 # wrriten 15/10/2002 by finlay@katipo.oc.nz
19 # script to display borrowers account details in the opac
20
21 use strict;
22 use C4::Output;
23 use CGI;
24 use C4::Members;
25 use C4::Circulation::Circ2;
26 use C4::Auth;
27 use C4::Interface::CGI::Output;
28
29 use C4::Date;
30
31 my $query = new CGI;
32 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
33     {
34         template_name   => "opac-account.tmpl",
35         query           => $query,
36         type            => "opac",
37         authnotrequired => 0,
38         flagsrequired   => { borrow => 1 },
39         debug           => 1,
40     }
41 );
42
43 # get borrower information ....
44 my ( $borr, $flags ) = getpatroninformation( undef, $borrowernumber );
45
46 my @bordat;
47 $bordat[0] = $borr;
48
49 $template->param( BORROWER_INFO => \@bordat );
50
51 #get account details
52 my ( $numaccts, $accts, $total ) = getboracctrecord( undef, $borr );
53
54 for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
55     $accts->[$i]{'date'} = format_date( $accts->[$i]{'date'} );
56     $accts->[$i]{'amount'} = sprintf( "%.2f", $accts->[$i]{'amount'} );
57     if ( $accts->[$i]{'amount'} >= 0 ) {
58         $accts->[$i]{'amountcredit'} = 1;
59     }
60     $accts->[$i]{'amountoutstanding'} =
61       sprintf( "%.2f", $accts->[$i]{'amountoutstanding'} );
62     if ( $accts->[$i]{'amountoutstanding'} >= 0 ) {
63         $accts->[$i]{'amountoutstandingcredit'} = 1;
64     }
65     if (   $accts->[$i]{'accounttype'} ne 'F'
66         && $accts->[$i]{'accounttype'} ne 'FU' )
67     {
68         $accts->[$i]{'print_title'};
69     }
70 }
71
72 # add the row parity
73 my $num = 0;
74 foreach my $row (@$accts) {
75     $row->{'even'} = 1 if $num % 2 == 0;
76     $row->{'odd'}  = 1 if $num % 2 == 1;
77     $num++;
78 }
79
80 $template->param (
81     ACCOUNT_LINES => $accts,
82     total => sprintf( "%.2f", $total )
83 );
84
85 output_html_with_http_headers $query, $cookie, $template->output;
86