Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
[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::Auth;
35 use C4::Context;
36 use C4::Output;
37 use C4::Interface::CGI::Output;
38 use C4::Interface::CGI::Template;
39 use CGI;
40 use C4::Search;
41 use Date::Manip;
42 use C4::Reserves2;
43 use C4::Circulation::Renewals2;
44 use C4::Circulation::Circ2;
45 use C4::Koha;
46 use HTML::Template;
47
48 my $dbh = C4::Context->dbh;
49
50 my $input = new CGI;
51
52 my ($template, $loggedinuser, $cookie)
53     = get_template_and_user({template_name => "members/moremember.tmpl",
54                              query => $input,
55                              type => "intranet",
56                              authnotrequired => 0,
57                              flagsrequired => {borrowers => 1},
58                              debug => 1,
59                              });
60
61 my $bornum=$input->param('bornum');
62
63 #start the page and read in includes
64
65 my $data=borrdata('',$bornum);
66
67 $data->{'dateenrolled'} = slashifyDate($data->{'dateenrolled'});
68 $data->{'expiry'} = slashifyDate($data->{'expiry'});
69 $data->{'dateofbirth'} = slashifyDate($data->{'dateofbirth'});
70
71 $data->{'ethnicity'} = fixEthnicity($data->{'ethnicity'});
72
73 $data->{&expand_sex_into_predicate($data->{'sex'})} = 1;
74
75 if ($data->{'categorycode'} eq 'C'){
76     my $data2=borrdata('',$data->{'guarantor'});
77     $data->{'streetaddress'}=$data2->{'streetaddress'};
78     $data->{'city'}=$data2->{'city'};
79     $data->{'physstreet'}=$data2->{'phystreet'};
80     $data->{'streetcity'}=$data2->{'streetcity'};
81     $data->{'phone'}=$data2->{'phone'};
82     $data->{'phoneday'}=$data2->{'phoneday'};
83 }
84
85
86 if ($data->{'ethnicity'} || $data->{'ethnotes'}) {
87         $template->param(printethnicityline => 1);
88 }
89
90 if ($data->{'categorycode'} ne 'C'){
91   $template->param(isguarantee => 1);
92   # FIXME
93   # It looks like the $i is only being returned to handle walking through
94   # the array, which is probably better done as a foreach loop.
95   #
96   my ($count,$guarantees)=findguarantees($data->{'borrowernumber'});
97   my @guaranteedata;
98   for (my $i=0;$i<$count;$i++){
99     push (@guaranteedata, {borrowernumber => $guarantees->[$i]->{'borrowernumber'},
100                            cardnumber => $guarantees->[$i]->{'cardnumber'}});
101   }
102   $template->param(guaranteeloop => \@guaranteedata);
103
104 } else {
105   my ($guarantor)=findguarantor($data->{'borrowernumber'});
106   unless ($guarantor->{'borrowernumber'} == 0){
107     $template->param(guarantorborrowernumber => $guarantor->{'borrowernumber'}, guarantorcardnumber => $guarantor->{'cardnumber'});
108   }
109 }
110
111 my %bor;
112 $bor{'borrowernumber'}=$bornum;
113
114 # FIXME
115 # it looks like $numaccts is a temp variable and that the
116 # for (my $i;$i<$numaccts;$i++)
117 # can be turned into a foreach loop instead
118 #
119 my ($numaccts,$accts,$total)=getboracctrecord('',\%bor);
120 #if ($numaccts > 10){
121 #  $numaccts=10;
122 #}
123 my @accountdata;
124 for (my$i=0;$i<$numaccts;$i++){
125   my $amount= $accts->[$i]{'amount'} + 0.00;
126   my $amount2= $accts->[$i]{'amountoutstanding'} + 0.00;
127   my %row = %$accts->[$i];
128   if ($amount2 != 0){
129     my $item=" &nbsp; ";
130     $row{'date'} = slashifyDate($accts->[$i]{'date'});
131
132     if ($accts->[$i]{'accounttype'} ne 'Res'){
133       #get item data
134       #$item=
135     }
136
137     # FIXME
138     # why set this variable if it's not going to be used?
139     #
140     my $env;
141     if ($accts->[$i]{'accounttype'} ne 'Res'){
142       my $iteminfo=C4::Circulation::Circ2::getiteminformation($env,$accts->[$i]->{'itemnumber'},'');
143    # FIXME, seems to me $iteminfo gets not defined
144       %row = (%row , %$iteminfo) if $iteminfo;
145     }
146   }
147   push (@accountdata, \%row);
148 }
149
150 my ($count,$issue)=borrissues($bornum);
151 my $today=ParseDate('today');
152 my @issuedata;
153 for (my $i=0;$i<$count;$i++){
154   my $datedue=ParseDate($issue->[$i]{'date_due'});
155   $issue->[$i]{'date_due'} = slashifyDate($issue->[$i]{'date_due'});
156   my %row = %{$issue->[$i]};
157   if ($datedue < $today){
158     $row{'red'}=1; #print "<font color=red>";
159   }
160   #find the charge for an item
161   # FIXME - This is expecting
162   # &C4::Circulation::Renewals2::calc_charges, but it's getting
163   # &C4::Circulation::Circ2::calc_charges, which only returns one
164   # element, so itemtype isn't being set.
165   # But &C4::Circulation::Renewals2::calc_charges doesn't appear to
166   # return the correct item type either (or a properly-formatted
167   # charge, for that matter).
168   my ($charge,$itemtype)=calc_charges(undef,$dbh,$issue->[$i]{'itemnumber'},$bornum);
169   $row{'itemtype'}=$itemtype;
170   $row{'charge'}=$charge;
171
172   #check item is not reserved
173   my ($restype,$reserves)=CheckReserves($issue->[$i]{'itemnumber'});
174   if ($restype){
175     print "<TD><a href=/cgi-bin/koha/request.pl?bib=$issue->[$i]{'biblionumber'}>On Request - no renewals</a></td></tr>";
176 #  } elsif ($issue->[$i]->{'renewals'} > 0) {
177 #      print "<TD>Previously Renewed - no renewals</td></tr>";
178   } else {
179     $row{'norenew'}=0;
180   }
181   push (@issuedata, \%row);
182 }
183
184 my ($rescount,$reserves)=FindReserves('',$bornum); #From C4::Reserves2
185
186 # FIXME
187 # does it make sense to turn this into a foreach my $i (0..$rescount)
188 # kind of loop?
189 #
190 my @reservedata;
191 for (my $i=0;$i<$rescount;$i++){
192   $reserves->[$i]{'reservedate2'} = slashifyDate($reserves->[$i]{'reservedate'});
193   my $restitle;
194   my %row = %$reserves->[$i];
195   if ($reserves->[$i]{'constrainttype'} eq 'o'){
196     $restitle=getreservetitle($reserves->[$i]{'biblionumber'},$reserves->[$i]{'borrowernumber'},$reserves->[$i]{'reservedate'},$reserves->[$i]{'timestamp'});
197     %row =  (%row , %$restitle);
198   }
199   push (@reservedata, \%row);
200 }
201
202 $template->param($data);
203 $template->param(
204                  bornum          => $bornum,
205                  accountloop     => \@accountdata,
206                  issueloop       => \@issuedata,
207                  reserveloop     => \@reservedata);
208
209 output_html_with_http_headers $input, $cookie, $template->output;