bug 3464: Takes columns country and B_country of table borrowers into account in...
[wip/koha-chris_n.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 with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA  02111-1307 USA
24
25 use strict;
26 use C4::Auth;
27 use C4::Output;
28 use C4::Dates qw/format_date/;
29 use CGI;
30 use C4::Members;
31 use C4::Branch;
32 use C4::Accounts;
33
34 my $input=new CGI;
35
36
37 my ($template, $loggedinuser, $cookie)
38     = get_template_and_user({template_name => "members/boraccount.tmpl",
39                             query => $input,
40                             type => "intranet",
41                             authnotrequired => 0,
42                             flagsrequired => {borrowers => 1, updatecharges => 1},
43                             debug => 1,
44                             });
45
46 my $borrowernumber=$input->param('borrowernumber');
47 #get borrower details
48 my $data=GetMember($borrowernumber,'borrowernumber');
49
50 if ( $input->param('action') eq 'reverse' ) {
51   ReversePayment( $borrowernumber, $input->param('accountno') );
52 }
53
54 if ( $data->{'category_type'} eq 'C') {
55    my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
56    my $cnt = scalar(@$catcodes);
57    $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
58    $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
59 }
60
61 #get account details
62 my ($total,$accts,$numaccts)=GetMemberAccountRecords($borrowernumber);
63 my $totalcredit;
64 if($total <= 0){
65         $totalcredit = 1;
66 }
67 my @accountrows; # this is for the tmpl-loop
68
69 my $toggle;
70 for (my $i=0;$i<$numaccts;$i++){
71     if($i%2){
72             $toggle = 0;
73     } else {
74             $toggle = 1;
75     }
76     $accts->[$i]{'toggle'} = $toggle;
77     $accts->[$i]{'amount'}+=0.00;
78     if($accts->[$i]{'amount'} <= 0){
79         $accts->[$i]{'amountcredit'} = 1;
80     }
81     $accts->[$i]{'amountoutstanding'}+=0.00;
82     if($accts->[$i]{'amountoutstanding'} <= 0){
83         $accts->[$i]{'amountoutstandingcredit'} = 1;
84     }
85     my %row = ( 'date'              => format_date($accts->[$i]{'date'}),
86                 'amountcredit' => $accts->[$i]{'amountcredit'},
87                 'amountoutstandingcredit' => $accts->[$i]{'amountoutstandingcredit'},
88                 'toggle' => $accts->[$i]{'toggle'},
89                 'description'       => $accts->[$i]{'description'},
90                                 'itemnumber'       => $accts->[$i]{'itemnumber'},
91                                 'biblionumber'       => $accts->[$i]{'biblionumber'},
92                 'amount'            => sprintf("%.2f",$accts->[$i]{'amount'}),
93                 'amountoutstanding' => sprintf("%.2f",$accts->[$i]{'amountoutstanding'}),
94                 'accountno' => $accts->[$i]{'accountno'},
95                 'payment' => ( $accts->[$i]{'accounttype'} eq 'Pay' ),
96                 
97                 );
98     
99     if ($accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU'){
100         $row{'printtitle'}=1;
101         $row{'title'} = $accts->[$i]{'title'};
102     }
103     
104     push(@accountrows, \%row);
105 }
106
107 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
108
109 my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
110 $template->param( picture => 1 ) if $picture;
111
112 $template->param(
113     finesview           => 1,
114     firstname           => $data->{'firstname'},
115     surname             => $data->{'surname'},
116     borrowernumber      => $borrowernumber,
117     cardnumber          => $data->{'cardnumber'},
118     categorycode        => $data->{'categorycode'},
119     category_type       => $data->{'category_type'},
120  #   category_description => $data->{'description'},
121     categoryname                 => $data->{'description'},
122     address             => $data->{'address'},
123     address2            => $data->{'address2'},
124     city                => $data->{'city'},
125     zipcode             => $data->{'zipcode'},
126     country             => $data->{'country'},
127     phone               => $data->{'phone'},
128     email               => $data->{'email'},
129     branchcode          => $data->{'branchcode'},
130         branchname                      => GetBranchName($data->{'branchcode'}),
131     total               => sprintf("%.2f",$total),
132     totalcredit         => $totalcredit,
133         is_child        => ($data->{'category_type'} eq 'C'),
134     accounts            => \@accountrows );
135
136 output_html_with_http_headers $input, $cookie, $template->output;