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