fixed the Findgroupreserves bug. Now calls CheckReserves instead
[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 use strict;
14 use C4::Output;
15 use CGI;
16 use C4::Search;
17 use Date::Manip;
18 use C4::Reserves2;
19 use C4::Circulation::Renewals2;
20 use C4::Circulation::Circ2;
21 use C4::Koha;
22 use C4::Auth;
23
24 my $input = new CGI;
25 my $flagsrequired;
26 $flagsrequired->{borrowers}=1;
27 my ($loggedinuser, $cookie, $sessionID) = checkauth($input, 0, $flagsrequired);
28 my $bornum=$input->param('bornum');
29
30
31 print $input->header;
32
33 #start the page and read in includes
34 print startpage();
35 print startmenu('member');
36 my $data=borrdata('',$bornum);
37
38
39 $data->{'dateenrolled'} = slashifyDate($data->{'dateenrolled'});
40 $data->{'expiry'} = slashifyDate($data->{'expiry'});
41 $data->{'dateofbirth'} = slashifyDate($data->{'dateofbirth'});
42
43 $data->{'ethnicity'} = fixEthnicity($data->{'ethnicity'});
44
45 print <<printend
46 <FONT SIZE=6><em>$data->{'firstname'} $data->{'surname'}</em></FONT><P>
47 <p>
48 <form action=/cgi-bin/koha/jmemberentry.pl method=post>
49 <TABLE  CELLSPACING=0  CELLPADDING=5 border=1 align=left width=270>
50 <TR VALIGN=TOP>
51 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>MEMBERSHIP RECORD</TD></TR>
52 <tr VALIGN=TOP  >       
53 <TD>
54 <p align=right><INPUT TYPE="image" name="submit"  VALUE="add-child" height=42  WIDTH=120 BORDER=0 src="/images/add-child.gif">          
55 <input type=hidden name=type value=Add>
56 <input type=hidden name=bornum value=$data->{'borrowernumber'}>
57 </form>
58 </P><br>
59 <FONT SIZE=2  face="arial, helvetica">$data->{'title'} $data->{'othernames'}  $data->{'surname'} ($data->{'firstname'}, $data->{'initials'})<p>
60
61 Card Number: $data->{'cardnumber'}<BR>
62 printend
63 ;
64 if ($data->{'categorycode'} eq 'C'){
65     my $data2=borrdata('',$data->{'guarantor'});
66     $data->{'streetaddress'}=$data2->{'streetaddress'};
67     $data->{'city'}=$data2->{'city'};
68     $data->{'physstreet'}=$data2->{'phystreet'};
69     $data->{'streetcity'}=$data2->{'streetcity'};
70     $data->{'phone'}=$data2->{'phone'};
71     $data->{'phoneday'}=$data2->{'phoneday'};
72 }
73 my $ethnicityline='';
74 if ($data->{'ethnicity'} || $data->{'ethnotes'}) {
75         $ethnicityline="Ethnicity: $data->{'ethnicity'}, $data->{'ethnotes'}<br>";
76 }
77 print <<printend
78 Postal Address: $data->{'streetaddress'}, $data->{'city'}<BR>
79 Home Address: $data->{'physstreet'}, $data->{'streetcity'}<BR>
80 Phone (Home): $data->{'phone'}<BR>
81 Phone (Daytime): $data->{'phoneday'}<BR>
82 Fax: $data->{'faxnumber'}<BR>
83 E-mail: <a href="mailto:$data->{'emailaddress'}">$data->{'emailaddress'}</a><br>
84 Textmessaging:$data->{'textmessaging'}<p>
85 Membership Number: $data->{'borrowernumber'}<BR>
86 Membership: $data->{'categorycode'}<BR>
87 Area: $data->{'area'}<BR>
88 Fee:$30/year, Paid<BR>
89 Joined: $data->{'dateenrolled'},  Expires: $data->{'expiry'} <BR>
90 Joining Branch: $data->{'homebranch'}<P>
91 $ethnicityline
92 DoB: $data->{'dateofbirth'}<BR>
93 Sex: $data->{'sex'}<P>
94
95 Alternative Contact:$data->{'contactname'}<BR>
96 Phone: $data->{'altphone'}<BR>
97 Relationship: $data->{'altrelationship'}<BR>
98 Notes: $data->{'altnotes'}<P>
99 printend
100 ;
101
102 if ($data->{'categorycode'} ne 'C'){
103   print " Guarantees:";
104   # FIXME
105   # It looks like the $i is only being returned to handle walking through
106   # the array, which is probably better done as a foreach loop.
107   #
108   my ($count,$guarantees)=findguarantees($data->{'borrowernumber'});
109   for (my $i=0;$i<$count;$i++){
110     print "<A HREF=\"/cgi-bin/koha/moremember.pl?bornum=$guarantees->[$i]->{'borrowernumber'}\">$guarantees->[$i]->{'cardnumber'}</a><br>";
111   }
112 } else {
113   print "Guarantor:";
114   my ($guarantor)=findguarantor($data->{'borrowernumber'});
115   if ($guarantor->{'borrowernumber'} == 0){
116       print "no guarantor<br>";
117   } else {
118     print "<A HREF=\"/cgi-bin/koha/moremember.pl?bornum=$guarantor->{'borrowernumber'}\">$guarantor->{'cardnumber'}</a><br>";
119   }
120 }
121 print <<printend
122
123
124 <P>
125
126 General Notes: <!--<A HREF="popbox.html" onclick="messenger(200,250,'Form that lets you add to and delete notes.'); return false">-->
127 $data->{'borrowernotes'}<!--</a>-->
128 <p align=right>
129 <form action=/cgi-bin/koha/memberentry.pl method=post>
130 <input type=hidden name=bornum value=$bornum>
131 <INPUT TYPE="image" name="modify"  VALUE="modify" height=42  WIDTH=93 BORDER=0 src="/images/modify-mem.gif"> 
132
133 <INPUT TYPE="image" name="delete"  VALUE="delete" height=42  WIDTH=93 BORDER=0 src="/images/delete-mem.gif"> 
134
135 <p>
136 <INPUT TYPE="image" name="password"  VALUE="password" height=42  WIDTH=154 BORDER=0 src="/images/password-mem.gif"> 
137 </p>
138 <a href=member-flags.pl?member=$bornum>Modify User Flags</a>
139
140 </TD>
141 </TR>
142 </TABLE>
143 </FORM>
144 <img src="/images/holder.gif" width=16 height=800 align=left>
145 <TABLE  CELLSPACING=0  CELLPADDING=5 border=1 >
146 <TR VALIGN=TOP>
147 <td  bgcolor="99cc33" background="/images/background-mem.gif" colspan=4><B>FINES & CHARGES</TD></TR>
148 printend
149 ;
150 my %bor;
151 $bor{'borrowernumber'}=$bornum;
152
153 # FIXME
154 # it looks like $numaccts is a temp variable and that the 
155 # for (my $i;$i<$numaccts;$i+++) 
156 # can be turned into a foreach loop instead
157 #
158 my ($numaccts,$accts,$total)=getboracctrecord('',\%bor);
159 #if ($numaccts > 10){
160 #  $numaccts=10;
161 #}
162 for (my$i=0;$i<$numaccts;$i++){
163 #if ($accts->[$i]{'accounttype'} ne 'Pay'){
164   my $amount= $accts->[$i]{'amount'} + 0.00;
165     my $amount2= $accts->[$i]{'amountoutstanding'} + 0.00;
166   if ($amount2 != 0){
167     print "<tr VALIGN=TOP  >";
168     my $item=" &nbsp; ";
169     
170     $accts->[$i]{'date'} = slashifyDate($accts->[$i]{'date'});
171
172     if ($accts->[$i]{'accounttype'} ne 'Res'){
173     #get item data
174     #$item=
175     }
176     print "<td>$accts->[$i]{'date'}</td>";
177 #  print "<TD>$accts->[$i]{'accounttype'}</td>";
178     print "<TD>";
179
180     # FIXME
181     # why set this variable if it's not going to be used?
182     #
183     my $env;
184     if ($accts->[$i]{'accounttype'} ne 'Res'){
185       my $iteminfo=C4::Circulation::Circ2::getiteminformation($env,$accts->[$i]->{'itemnumber'},'');
186       print "<a href=/cgi-bin/koha/moredetail.pl?itemnumber=$accts->[$i]->{'itemnumber'}&bib=$iteminfo->{'biblionumber'}&bi=$iteminfo->{'biblioitemnumber'}>$accts->[$i]->{'description'} $accts->[$i]{'title'}</a>";
187     }
188     print "</td>
189     <TD>$amount</td><td>$amount2</td>
190     </tr>";
191   }
192 }
193 print <<printend
194
195 <tr VALIGN=TOP  >
196 <TD colspan=3 align=right>
197 <nobr>
198 <a href=/cgi-bin/koha/boraccount.pl?bornum=$bornum><img height=42  WIDTH=187 BORDER=0 src="/images/view-account.gif"></a>
199 <a href=/cgi-bin/koha/pay.pl?bornum=$bornum><img height=42  WIDTH=187 BORDER=0 src="/images/pay-fines.gif"></a></nobr>
200 </td>
201
202 </tr>
203
204
205 </table>
206
207 <p>
208 <form action="renewscript.pl" method=post>
209 <input type=hidden name=bornum value=$bornum>
210 <TABLE  CELLSPACING=0  CELLPADDING=5 border=1 >
211
212 <TR VALIGN=TOP>
213
214 <td  bgcolor="99cc33" background="/images/background-mem.gif" colspan=6><B>ITEMS CURRENTLY ON ISSUE</b></TD>
215 </TR>
216
217 <TR VALIGN=TOP>
218 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Title</b></TD>
219 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Due</b></TD>
220 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Itemtype</b></TD>
221 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Charge</b></TD>
222 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Renew</b></TD>
223 </TR>
224 printend
225 ;
226 my ($count,$issue)=borrissues($bornum);
227 my $today=ParseDate('today');
228 for (my $i=0;$i<$count;$i++){
229   print "<tr VALIGN=TOP  >
230   <TD>";
231     my $datedue=ParseDate($issue->[$i]{'date_due'});
232
233   $issue->[$i]{'date_due'} = slashifyDate($issue->[$i]{'date_due'});
234
235   if ($datedue < $today){  
236     print "<font color=red>";
237   }
238   print "$issue->[$i]{'title'} 
239   <a href=/cgi-bin/koha/moredetail.pl?item=$issue->[$i]->{'itemnumber'}&bib=$issue->[$i]->{'biblionumber'}&bi=$issue->[$i]->{'biblioitemnumber'}>
240   $issue->[$i]{'barcode'}</a></td>
241   <TD>$issue->[$i]{'date_due'}</td>";
242   #find the charge for an item
243   warn "calling calc_charges\n";
244   my ($charge,$itemtype)=calc_charges(undef,undef,$issue->[$i]{'itemnumber'},$bornum);
245   print "<TD>$itemtype</td>";
246   print "<TD>$charge</td>";
247
248 #  if ($datedue < $today){
249 #    print "<td>Overdue</td>";
250 #  } else {
251 #    print "<td> &nbsp; </td>";
252 #  }
253   #check item is not reserved
254   my ($rescount,$reserves)=CheckReserves($issue->[$i]{'itemnumber'});
255   if ($rescount >0){
256     print "<TD><a href=/cgi-bin/koha/request.pl?bib=$issue->[$i]{'biblionumber'}>On Request - no renewals</a></td></tr>";
257 #  } elsif ($issue->[$i]->{'renewals'} > 0) {
258 #      print "<TD>Previously Renewed - no renewals</td></tr>";
259   } else {
260     print "<TD>";
261   
262     print "<input type=radio name=\"renew_item_$issue->[$i]{'itemnumber'}\" value=y>Y
263     <input type=radio name=\"renew_item_$issue->[$i]{'itemnumber'}\" value=n>N</td>
264     </tr>
265     ";
266   }
267 }
268 print <<printend
269
270 <tr VALIGN=TOP  >
271 <TD colspan=5 align=right>
272 <INPUT TYPE="image" name="submit"  VALUE="update" height=42  WIDTH=187 BORDER=0 src="/images/update-renewals.gif">
273 </td>
274 </form>
275 </tr>
276
277
278 </table>
279
280
281 <P>
282
283 <TABLE  CELLSPACING=0  CELLPADDING=5 border=1 >
284
285 <TR VALIGN=TOP>
286
287 <td  bgcolor="99cc33" background="/images/background-mem.gif" colspan=5><B>ITEMS REQUESTED</b></TD>
288 </TR>
289
290 <TR VALIGN=TOP>
291
292 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Title</b></TD>
293 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Requested</b></TD>
294
295
296 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Charge</b></TD>
297
298 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Remove</b></TD>
299 </TR>
300 <form action=/cgi-bin/koha/modrequest.pl method=post>
301 <input type=hidden name=from value=borrower>
302 printend
303 ;
304
305 my ($rescount,$reserves)=FindReserves('',$bornum); #From C4::Reserves2
306
307 # FIXME
308 # does it make sense to turn this into a foreach my $i (0..$rescount) 
309 # kind of loop? 
310 #
311 for (my $i=0;$i<$rescount;$i++){
312   $reserves->[$i]{'reservedate'} = slashifyDate($reserves->[$i]{'reservedate'});
313
314   print "<tr VALIGN=TOP  >
315   <TD><a href=\"/cgi-bin/koha/request.pl?bib=$reserves->[$i]{'biblionumber'}\">$reserves->[$i]{'btitle'}</a></td>
316   <TD>$reserves->[$i]{'reservedate'}</td>
317   <input type=hidden name=biblio value=$reserves->[$i]{'biblionumber'}>
318   <input type=hidden name=borrower value=$bornum>
319   <TD></td>
320   <TD><select name=\"rank-request\">
321   <option value=n>No
322   <option value=del>Yes
323   </select>
324   </tr>
325   ";
326 }
327 print <<printend
328
329 <tr VALIGN=TOP  >
330 <TD colspan=5 align=right>
331 <INPUT TYPE="image" name="submit"  VALUE="update" height=42  WIDTH=187 BORDER=0 src="/images/cancel-requests.gif"></td>
332 </tr>
333 </table>
334 </form>
335 <p align=right>
336 <a href=/cgi-bin/koha/readingrec.pl?bornum=$bornum><img height=42  WIDTH=187 BORDER=0 src="/images/reading-record.gif"></a>
337 </p>
338 printend
339 ;
340
341
342 print endmenu('member');
343 print endpage();
344
345