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