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