bugfix
[koha.git] / moremember.pl
1 #!/usr/bin/perl
2
3 # script to do a borrower enquiry/bring up borrower details etc
4 # Displays all the details about a borrower
5 # written 20/12/99 by chris@katipo.co.nz
6 # last modified 21/1/2000 by chris@katipo.co.nz
7 # modified 31/1/2001 by chris@katipo.co.nz 
8 #   to not allow items on request to be renewed
9 #
10 # needs html removed and to use the C4::Output more, but its tricky
11 #
12
13
14 # Copyright 2000-2002 Katipo Communications
15 #
16 # This file is part of Koha.
17 #
18 # Koha is free software; you can redistribute it and/or modify it under the
19 # terms of the GNU General Public License as published by the Free Software
20 # Foundation; either version 2 of the License, or (at your option) any later
21 # version.
22 #
23 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
24 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
25 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
26 #
27 # You should have received a copy of the GNU General Public License along with
28 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
29 # Suite 330, Boston, MA  02111-1307 USA
30
31 use strict;
32 use C4::Output;
33 use CGI;
34 use C4::Search;
35 use Date::Manip;
36 use C4::Reserves2;
37 use C4::Circulation::Renewals2;
38 use C4::Circulation::Circ2;
39 use C4::Koha;
40 use C4::Database;
41 use HTML::Template;
42
43 my $dbh=C4Connect;
44
45 my $input = new CGI;
46
47 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
48 my %tmpldata = pathtotemplate ( template => 'moremember.tmpl', theme => $theme );
49 my $template = HTML::Template->new(filename => $tmpldata{'path'}, die_on_bad_params => 0);
50
51 my $bornum=$input->param('bornum');
52
53 #start the page and read in includes
54
55 my $data=borrdata('',$bornum);
56
57 $data->{'dateenrolled'} = slashifyDate($data->{'dateenrolled'});
58 $data->{'expiry'} = slashifyDate($data->{'expiry'});
59 $data->{'dateofbirth'} = slashifyDate($data->{'dateofbirth'});
60
61 $data->{'ethnicity'} = fixEthnicity($data->{'ethnicity'});
62
63 if ($data->{'categorycode'} eq 'C'){
64     my $data2=borrdata('',$data->{'guarantor'});
65     $data->{'streetaddress'}=$data2->{'streetaddress'};
66     $data->{'city'}=$data2->{'city'};
67     $data->{'physstreet'}=$data2->{'phystreet'};
68     $data->{'streetcity'}=$data2->{'streetcity'};
69     $data->{'phone'}=$data2->{'phone'};
70     $data->{'phoneday'}=$data2->{'phoneday'};
71 }
72
73
74 if ($data->{'ethnicity'} || $data->{'ethnotes'}) {
75         $template->param(printethnicityline => 1);
76 }
77
78 if ($data->{'categorycode'} ne 'C'){
79   $template->param(isguarantee => 1);
80   # FIXME
81   # It looks like the $i is only being returned to handle walking through
82   # the array, which is probably better done as a foreach loop.
83   #
84   my ($count,$guarantees)=findguarantees($data->{'borrowernumber'});
85   my @guaranteedata;
86   for (my $i=0;$i<$count;$i++){
87     push (@guaranteedata, {borrowernumber => $guarantees->[$i]->{'borrowernumber'},
88                            cardnumber => $guarantees->[$i]->{'cardnumber'}});
89   }
90   $template->param(guaranteeloop => \@guaranteedata);
91   
92 } else {
93   my ($guarantor)=findguarantor($data->{'borrowernumber'});
94   unless ($guarantor->{'borrowernumber'} == 0){
95     $template->param(guarantorborrowernumber => $guarantor->{'borrowernumber'}, guarantorcardnumber => $guarantor->{'cardnumber'});
96   }
97 }
98
99 my %bor;
100 $bor{'borrowernumber'}=$bornum;
101
102 # FIXME
103 # it looks like $numaccts is a temp variable and that the 
104 # for (my $i;$i<$numaccts;$i+++) 
105 # can be turned into a foreach loop instead
106 #
107 my ($numaccts,$accts,$total)=getboracctrecord('',\%bor);
108 #if ($numaccts > 10){
109 #  $numaccts=10;
110 #}
111 my @accountdata;
112 for (my$i=0;$i<$numaccts;$i++){
113   my $amount= $accts->[$i]{'amount'} + 0.00;
114   my $amount2= $accts->[$i]{'amountoutstanding'} + 0.00;
115   my %row = %$accts->[$i];
116   if ($amount2 != 0){
117     my $item=" &nbsp; ";  
118     $row{'date'} = slashifyDate($accts->[$i]{'date'});
119
120     if ($accts->[$i]{'accounttype'} ne 'Res'){
121       #get item data
122       #$item=
123     }
124
125     # FIXME
126     # why set this variable if it's not going to be used?
127     #
128     my $env;
129     if ($accts->[$i]{'accounttype'} ne 'Res'){
130       my $iteminfo=C4::Circulation::Circ2::getiteminformation($env,$accts->[$i]->{'itemnumber'},'');
131    # FIXME, seems to me $iteminfo gets not defined
132       %row = (%row , %$iteminfo) if $iteminfo;
133     }
134   }
135   push (@accountdata, \%row);
136 }
137
138 my ($count,$issue)=borrissues($bornum);
139 my $today=ParseDate('today');
140 my @issuedata;
141 for (my $i=0;$i<$count;$i++){
142   my $datedue=ParseDate($issue->[$i]{'date_due'});
143   $issue->[$i]{'date_due'} = slashifyDate($issue->[$i]{'date_due'});
144   my %row = %$issue->[$i];
145   if ($datedue < $today){  
146     $row{'red'}=1; #print "<font color=red>";
147   }
148   #find the charge for an item
149   my ($charge,$itemtype)=calc_charges(undef,$dbh,$issue->[$i]{'itemnumber'},$bornum);
150   $row{'itemtype'}=$itemtype;
151   $row{'charge'}=$charge;
152
153   #check item is not reserved
154   my ($restype,$reserves)=CheckReserves($issue->[$i]{'itemnumber'});
155   if ($restype){
156     print "<TD><a href=/cgi-bin/koha/request.pl?bib=$issue->[$i]{'biblionumber'}>On Request - no renewals</a></td></tr>";
157 #  } elsif ($issue->[$i]->{'renewals'} > 0) {
158 #      print "<TD>Previously Renewed - no renewals</td></tr>";
159   } else {
160     $row{'norenew'}=0;
161   }
162   push (@issuedata, \%row);
163 }
164
165 my ($rescount,$reserves)=FindReserves('',$bornum); #From C4::Reserves2
166
167 # FIXME
168 # does it make sense to turn this into a foreach my $i (0..$rescount) 
169 # kind of loop? 
170 #
171 my @reservedata;
172 for (my $i=0;$i<$rescount;$i++){
173   $reserves->[$i]{'reservedate2'} = slashifyDate($reserves->[$i]{'reservedate'});
174   my $restitle;
175   my %row = %$reserves->[$i];
176   if ($reserves->[$i]{'constrainttype'} eq 'o'){
177     $restitle=getreservetitle($reserves->[$i]{'biblionumber'},$reserves->[$i]{'borrowernumber'},$reserves->[$i]{'reservedate'},$reserves->[$i]{'timestamp'});
178     %row =  (%row , %$restitle);
179   }
180   push (@reservedata, \%row);
181 }
182
183 $dbh->disconnect;
184
185 $template->param($data);
186 $template->param(startmenumember => join('', startmenu('member')),
187                  endmenumember   => join('', endmenu('member')),
188                  bornum          => $bornum,
189                  accountloop     => \@accountdata,
190                  issueloop       => \@issuedata,
191                  reserveloop     => \@reservedata);
192
193 print "Content-Type: text/html\n\n", $template->output;