MT 1059 : Records merging
[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 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 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
36 my $input=new CGI;
37
38
39 my ($template, $loggedinuser, $cookie)
40     = get_template_and_user({template_name => "members/boraccount.tmpl",
41                             query => $input,
42                             type => "intranet",
43                             authnotrequired => 0,
44                             flagsrequired => {borrowers => 1, updatecharges => 1},
45                             debug => 1,
46                             });
47
48 my $borrowernumber=$input->param('borrowernumber');
49 my $action = $input->param('action') || '';
50
51 #get borrower details
52 my $data=GetMember('borrowernumber' => $borrowernumber);
53
54 if ( $action eq 'reverse' ) {
55   ReversePayment( $borrowernumber, $input->param('accountno') );
56 }
57
58 if ( $data->{'category_type'} eq 'C') {
59    my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
60    my $cnt = scalar(@$catcodes);
61    $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
62    $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
63 }
64
65 #get account details
66 my ($total,$accts,$numaccts)=GetMemberAccountRecords($borrowernumber);
67 my $totalcredit;
68 if($total <= 0){
69         $totalcredit = 1;
70 }
71 my @accountrows; # this is for the tmpl-loop
72
73 my $toggle;
74 for (my $i=0;$i<$numaccts;$i++){
75     if($i%2){
76             $toggle = 0;
77     } else {
78             $toggle = 1;
79     }
80     $accts->[$i]{'toggle'} = $toggle;
81     $accts->[$i]{'amount'}+=0.00;
82     if($accts->[$i]{'amount'} <= 0){
83         $accts->[$i]{'amountcredit'} = 1;
84     }
85     $accts->[$i]{'amountoutstanding'}+=0.00;
86     if($accts->[$i]{'amountoutstanding'} <= 0){
87         $accts->[$i]{'amountoutstandingcredit'} = 1;
88     }
89     my %row = ( 'date'              => format_date($accts->[$i]{'date'}),
90                 'amountcredit' => $accts->[$i]{'amountcredit'},
91                 'amountoutstandingcredit' => $accts->[$i]{'amountoutstandingcredit'},
92                 'toggle' => $accts->[$i]{'toggle'},
93                 'description'       => $accts->[$i]{'description'},
94                                 'itemnumber'       => $accts->[$i]{'itemnumber'},
95                                 'biblionumber'       => $accts->[$i]{'biblionumber'},
96                 'amount'            => sprintf("%.2f",$accts->[$i]{'amount'}),
97                 'amountoutstanding' => sprintf("%.2f",$accts->[$i]{'amountoutstanding'}),
98                 'accountno' => $accts->[$i]{'accountno'},
99                 'payment' => ( $accts->[$i]{'accounttype'} eq 'Pay' ),
100                 
101                 );
102     
103     if ($accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU'){
104         $row{'printtitle'}=1;
105         $row{'title'} = $accts->[$i]{'title'};
106     }
107     
108     push(@accountrows, \%row);
109 }
110
111 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
112
113 my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
114 $template->param( picture => 1 ) if $picture;
115
116 $template->param(
117     finesview           => 1,
118     firstname           => $data->{'firstname'},
119     surname             => $data->{'surname'},
120     borrowernumber      => $borrowernumber,
121     cardnumber          => $data->{'cardnumber'},
122     categorycode        => $data->{'categorycode'},
123     category_type       => $data->{'category_type'},
124  #   category_description => $data->{'description'},
125     categoryname                 => $data->{'description'},
126     address             => $data->{'address'},
127     address2            => $data->{'address2'},
128     city                => $data->{'city'},
129     zipcode             => $data->{'zipcode'},
130     country             => $data->{'country'},
131     phone               => $data->{'phone'},
132     email               => $data->{'email'},
133     branchcode          => $data->{'branchcode'},
134         branchname                      => GetBranchName($data->{'branchcode'}),
135     total               => sprintf("%.2f",$total),
136     totalcredit         => $totalcredit,
137         is_child        => ($data->{'category_type'} eq 'C'),
138     accounts            => \@accountrows );
139
140 output_html_with_http_headers $input, $cookie, $template->output;