changed the previous issues to be listed in order of due date
[koha.git] / circ / circulation.pl
1 #!/usr/bin/perl
2
3 #written 8/5/2002 by Finlay
4 #script to execute issuing of books
5
6 use strict;
7 use CGI;
8 use C4::Circulation::Circ2;
9 use C4::Search;
10 use C4::Output;
11 use C4::Print;
12
13 my %env;
14 my $headerbackgroundcolor='#99cc33';
15 my $circbackgroundcolor='#ffffcc';
16 my $circbackgroundcolor='white';
17 my $linecolor1='#ffffcc';
18 my $linecolor2='white';
19 my $backgroundimage="/images/background-mem.gif";
20
21 my $branches = getbranches();
22 my $printers = getprinters(\%env);
23
24 my $query = new CGI;
25
26 my $branch = $query->param("branch");
27 my $printer = $query->param("printer");
28
29 ($branch) || ($branch=$query->cookie('branch')) ;
30 ($printer) || ($printer=$query->cookie('printer')) ;
31
32 #set up cookie.....
33 my $info = '';
34 my $branchcookie;
35 my $printercookie;
36 if ($query->param('setcookies')) {
37     $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
38     $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
39 }
40
41 $env{'branchcode'}=$branch;
42 $env{'printer'}=$printer;
43 $env{'queue'}=$printer;
44
45 my @datearr = localtime(time());
46 my $tday = localtime(time());
47 warn "today: $tday \n";
48 my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", ($datearr[3]));
49 #warn $todaysdate;
50
51
52 my $message;
53 my $borrowerslist;
54 # if there is a list of find borrowers....
55 my $findborrower = $query->param('findborrower');
56 if ($findborrower) {
57     my ($borrowers, $flags) = findborrower(\%env, $findborrower);
58     my @borrowers=@$borrowers;
59     if ($#borrowers == -1) {
60         $query->param('findborrower', '');
61         $message =  "No borrower matched '$findborrower'";
62     } elsif ($#borrowers == 0) {
63         $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
64         $query->param('barcode','');
65     } else {
66         $borrowerslist = \@borrowers;
67     }
68 }
69
70 my $borrowernumber = $query->param('borrnumber');    
71 my $bornum = $query->param('borrnumber');    
72 # check and see if we should print
73 my $print=$query->param('print');
74 my $barcode = $query->param('barcode');
75 if ($barcode eq ''  && $print eq 'maybe'){
76     $print = 'yes';
77 }
78 if ($print eq 'yes' && $borrowernumber ne ''){
79     printslip(\%env,$borrowernumber);    
80     $query->param('borrnumber','');
81     $borrowernumber='';
82 }
83     
84
85
86 # get the currently issued books......
87 my $borrower;
88 my $flags;
89 if ($borrowernumber) {
90     ($borrower, $flags) = getpatroninformation(\%env,$borrowernumber,0);
91 }
92
93 # get the responses to any questions.....
94 my %responses;
95 foreach (sort $query->param) {
96     if ($_ =~ /response-(\d*)/) {
97         $responses{$1} = $query->param($_);
98     }
99 }
100 if (my $qnumber = $query->param('questionnumber')) {
101     $responses{$qnumber} = $query->param('answer');
102 }
103
104
105 # if the barcode is set
106 my ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer);
107
108 my $year=$query->param('year');
109 my $month=$query->param('month');
110 my $day=$query->param('day');
111
112
113 if ($barcode) {
114     $barcode = cuecatbarcodedecode($barcode);
115     my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
116
117     unless ($invalidduedate) {
118         $env{'datedue'}=$datedue;
119         my @time=localtime(time);
120         my $date= (1900+$time[5])."-".($time[4]+1)."-".$time[3];
121         ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer, $message) 
122                      = issuebook(\%env, $borrower, $barcode, \%responses, $date);
123     }
124 }
125
126
127 ##################################################################################
128 # HTML code....
129
130
131 my $rejectedtext;
132 if ($rejected) {
133     if ($rejected == -1) {
134     } else {
135         $rejectedtext = << "EOF";
136 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
137 <tr><th><font color=black size=5>Error Issuing Book</font></th></tr>
138 <tr><td><font color=red size=5>$rejected</font></td></tr>
139 </table>
140 <br>
141 EOF
142     }
143 }
144
145 my $selectborrower;
146 if ($borrowerslist) {
147     $selectborrower = <<"EOF";
148 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
149 <input type=hidden name=branch value=$branch>
150 <input type=hidden name=printer value=$printer>
151 <table border=1 cellspacing=0 cellpadding=5 bgcolor="#dddddd">
152 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
153 <font color=black><b>Select a borrower</b></font></th></tr>\n
154 <tr><td align=center>
155 <select name=borrnumber size=7>
156 EOF
157     foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
158         $selectborrower .= <<"EOF";
159 <option value=$_->{'borrowernumber'}>$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})
160 EOF
161     }
162     $selectborrower .= <<"EOF";
163 </select><br>
164 <input type=submit>
165 </td></tr></table>
166 EOF
167 }
168
169 # title....
170 my $title = <<"EOF";
171 <table align="right"><tr><td>
172 <a href=circulation.pl?borrnumber=$borrowernumber&branch=$branch&printer=$printer&print=yes>
173 <img src="/images/button-next-borrower.gif" width="171" height="42" border="0" alt="Next Borrower"></a> &nbsp
174 <a href=returns.pl>
175 <img src="/images/button-returns.gif" width="110" height="42" border="0" alt="Returns"></a>
176 &nbsp<a href=branchtransfers.pl>
177 <img src="/images/button-transfers.gif" width="127" height="42" border="0" alt="Transfers">
178 </a>
179 </td></tr></table>
180 <FONT SIZE=6><em>Circulation: Issues</em></FONT><br>
181 <b>Branch:</b> $branches->{$branch}->{'branchname'} &nbsp 
182 <b>Printer:</b> $printers->{$printer}->{'printername'} <br>
183 <a href=selectbranchprinter.pl>Change Settings</a></td>
184 <input type=hidden name=branch value=$branch>
185 <input type=hidden name=printer value=$printer>
186 <p>
187 EOF
188
189 my $titlenoborrower = <<"EOF";
190 <table align="right"><tr><td>
191 <a href=returns.pl>
192 <img src="/images/button-returns.gif" width="110" height="42" border="0" alt="Returns"></a>
193 &nbsp<a href=branchtransfers.pl>
194 <img src="/images/button-transfers.gif" width="127" height="42" border="0" alt="Transfers">
195 </a>
196 </td></tr></table>
197 <FONT SIZE=6><em>Circulation: Issues</em></FONT><br>
198 <b>Branch:</b> $branches->{$branch}->{'branchname'} &nbsp 
199 <b>Printer:</b> $printers->{$printer}->{'printername'} <br>
200 <a href=selectbranchprinter.pl>Change Settings</a></td>
201 <input type=hidden name=branch value=$branch>
202 <input type=hidden name=printer value=$printer>
203 <p>
204 EOF
205
206
207
208 my $cardnumberinput = << "EOF";
209 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
210 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
211 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
212 <font color=black><b>Enter borrower card number<br> or partial last name</b></font></td></tr>
213 <tr><td><input name=findborrower></td></tr>
214   <input type=hidden name=branch value=$branch>
215 <input type=hidden name=printer value=$printer>
216 </table>
217 </form>
218 EOF
219
220 my $responsesform = '';
221 foreach (keys %responses) {
222     $responsesform.="<input type=hidden name=response-$_ value=$responses{$_}>\n";
223 }
224 my $questionform;
225 if ($question) {
226     my $stickyduedate=$query->param('stickyduedate');
227     $questionform = <<"EOF";
228 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
229 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
230 <font color=black><b>Issuing Question</b></font></th></tr>
231 <tr><td><table border=0 cellpadding=10><tr><td> 
232 Attempting to issue $iteminformation->{'title'} 
233 by $iteminformation->{'author'} to $borrower->{'firstname'} $borrower->{'surname'}.
234 <p>
235 $question
236 </td></tr></table></td></tr>
237 <tr><td align=center>
238 <table border=0>
239 <tr><td>
240 <form method=get>
241 <input type=hidden name=borrnumber value=$borrowernumber>
242 <input type=hidden name=barcode value=$barcode>
243 <input type=hidden name=questionnumber value=$questionnumber>
244 <input type=hidden name=day value=$day>
245 <input type=hidden name=month value=$month>
246 <input type=hidden name=year value=$year>
247 <input type=hidden name=stickyduedate value=$stickyduedate>
248 <input type=hidden name=branch value=$branch>
249 <input type=hidden name=printer value=$printer>
250 $responsesform
251 <input type=hidden name=answer value=Y>
252 <input type=submit value=Yes>
253 </form>
254 </td>
255 <td>
256 <form method=get>
257 <input type=hidden name=borrnumber value=$borrowernumber>
258 <input type=hidden name=barcode value=$barcode>
259 <input type=hidden name=questionnumber value=$questionnumber>
260 <input type=hidden name=day value=$day>
261 <input type=hidden name=month value=$month>
262 <input type=hidden name=year value=$year>
263 <input type=hidden name=stickyduedate value=$stickyduedate>
264 <input type=hidden name=branch value=$branch>
265 <input type=hidden name=printer value=$printer>
266 $responsesform
267 <input type=hidden name=answer value=N>
268 <input type=submit value=No>
269 </form>
270 </td>
271 </tr>
272 </table>
273 </td></tr>
274 </table>
275 </td></tr>
276 </table>
277 EOF
278 }
279
280
281 # Barcode entry box, with hidden inputs attached....
282 my $counter = 1;
283 my $dayoptions = '';
284 my $monthoptions = '';
285 my $yearoptions = '';
286 for (my $i=1; $i<32; $i++) {
287     my $selected='';
288     if (($query->param('stickyduedate')) && ($day==$i)) {
289         $selected='selected';
290     }
291     $dayoptions.="<option value=$i $selected>$i";
292 }
293 foreach (('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')) {
294     my $selected='';
295     if (($query->param('stickyduedate')) && ($month==$counter)) {
296         $selected='selected';
297     }
298     $monthoptions.="<option value=$counter $selected>$_";
299     $counter++;
300 }
301 for (my $i=$datearr[5]+1900; $i<$datearr[5]+1905; $i++) {
302     my $selected='';
303     if (($query->param('stickyduedate')) && ($year==$i)) {
304         $selected='selected';
305     }
306     $yearoptions.="<option value=$i $selected>$i";
307 }
308 my $selected='';
309 ($query->param('stickyduedate')) && ($selected='checked');
310
311
312 my $barcodeentrytext = <<"EOF";
313 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
314 <table border=1 cellpadding=5>
315 <tr>
316 <td align=center valign=top>
317 <table border=0 cellspacing=0 cellpadding=5>
318 <tr><th align=center background=$backgroundimage>
319 <font color=black><b>Enter Book Barcode</b></font></th></tr>
320 <tr><td align=center>
321 <table border=0>
322 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td><td><input type=submit value=Issue></td></tr>
323 <tr><td colspan=3 align=center>
324 <table border=0 cellpadding=0 cellspacing=0>
325 <tr><td>
326 <select name=day><option value=0>Day$dayoptions</select>
327 </td><td>
328 <select name=month><option value=0>Month$monthoptions</select>
329 </td><td>
330 <select name=year><option value=0>Year$yearoptions</select>
331 </td></tr>
332 </table>
333 <input type=checkbox name=stickyduedate $selected> Sticky Due Date
334 </td></tr>
335 </table>
336 <input type=hidden name=borrnumber value=$borrowernumber>
337 <input type=hidden name=branch value=$branch>
338 <input type=hidden name=printer value=$printer>
339 <input type=hidden name=print value=maybe>
340 EOF
341 if ($flags->{'CHARGES'}){
342     $barcodeentrytext.="<input type=hidden name=charges value=yes>";
343 }
344 my $amountold=$flags->{'CHARGES'}->{'message'};
345 my @temp=split(/\$/,$amountold);
346 $amountold=$temp[1];
347 $barcodeentrytext.="<input type=hidden name=oldamount value=$amountold>";
348 $barcodeentrytext.=<<"EOF";
349 </td></tr></table>
350 </td></tr></table>
351 </form>
352 EOF
353
354
355 # collect the messages and put into message table....
356 my $messagetable;
357 if ($message) {
358     $messagetable = << "EOF";
359 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
360 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
361 <tr><td> $message </td></tr></table>
362 EOF
363 }
364
365
366
367 # make the issued books table.....
368 my $todaysissues='';
369 my $previssues='';
370 if ($borrower) {
371     my @todaysissues;
372     my @previousissues;
373     my $issueslist = getissues($borrower);
374     foreach my $it (keys %$issueslist) {
375         my $issuedate = $issueslist->{$it}->{'timestamp'};
376         $issuedate = substr($issuedate, 0, 8);
377         if ($todaysdate == $issuedate) {
378             push @todaysissues, $issueslist->{$it};
379         } else {
380             push @previousissues, $issueslist->{$it};
381         }
382     }
383     my $tcolor = '';
384     my $pcolor = '';
385     foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
386         my $dd = $book->{'date_due'};
387         my $datedue = $book->{'date_due'};
388         #convert to nz style dates
389         #this should be set with some kinda config variable         
390         my @tempdate=split(/-/,$dd);
391         $dd="$tempdate[2]/$tempdate[1]/$tempdate[0]";
392         $datedue=~s/-//g;
393         if ($datedue < $todaysdate) {
394             $dd="<font color=red>$dd</font>\n";
395         }
396         ($tcolor eq $linecolor1) ? ($tcolor=$linecolor2) : ($tcolor=$linecolor1);
397         $todaysissues .=<< "EOF";
398 <tr><td bgcolor=$tcolor align=center>$dd</td>
399 <td bgcolor=$tcolor align=center>
400 <a href=/cgi-bin/koha/detail.pl?bib=$book->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$book->{'barcode'}</a></td>
401 <td bgcolor=$tcolor>$book->{'title'}</td>
402 <td bgcolor=$tcolor>$book->{'author'}</td>
403 <td bgcolor=$tcolor align=center>$book->{'dewey'} $book->{'subclass'}</td></tr>
404 EOF
405     } 
406     foreach my $book (sort {$a->{'due_date'} <=> $b->{'due_date'}} @previousissues){
407         my $dd = $book->{'date_due'};
408         my $datedue = $book->{'date_due'};
409         #convert to nz style dates
410         #this should be set with some kinda config variable         
411         my @tempdate=split(/-/,$dd);
412         $dd="$tempdate[2]/$tempdate[1]/$tempdate[0]";
413         $datedue=~s/-//g;
414         if ($datedue < $todaysdate) {
415             $dd="<font color=red>$dd</font>\n";
416         }
417         ($pcolor eq $linecolor1) ? ($pcolor=$linecolor2) : ($pcolor=$linecolor1);
418         $previssues .= << "EOF";
419 <tr><td bgcolor=$pcolor align=center>$dd</td>
420 <td bgcolor=$pcolor align=center>
421 <a href=/cgi-bin/koha/detail.pl?bib=$book->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$book->{'barcode'}</a></td>
422 <td bgcolor=$pcolor>$book->{'title'}</td>
423 <td bgcolor=$pcolor>$book->{'author'}</td>
424 <td bgcolor=$pcolor align=center>$book->{'dewey'} $book->{'subclass'}</td></tr>
425 EOF
426     }
427 }
428
429 my $issuedbookstable;
430 if ($todaysissues) {
431     $issuedbookstable .= <<"EOF";
432 <table border=1 cellpadding=5 cellspacing=0 width=80%>
433 <tr><th colspan=5 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>
434 <b>Todays Issues</b></font></th></tr>
435 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Class</th></tr>
436 $todaysissues
437 </table>
438 EOF
439 }
440 if ($previssues) {
441     $issuedbookstable .= <<"EOF";
442 <table border=1 cellpadding=5 cellspacing=0 width=80%>
443 <tr><th colspan=5 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>
444 <b>Previous Issues</b></font></th></tr>
445 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Class</th></tr>
446 $previssues
447 </table>
448 EOF
449 }
450
451
452
453
454
455 # actually print the page!
456
457
458 if ($branchcookie && $printercookie) {
459     print $query->header(-type=>'text/html',-expires=>'now', -cookie=>[$branchcookie,$printercookie]);
460 } else {
461     print $query->header();
462 }
463
464 print startpage();
465 my @inp=startmenu('circulation');
466 if ($query->param('barcode') eq '' && $query->param('charges') eq 'yes'){
467     my $count=@inp;
468      for (my $i=0;$i<$count;$i++){
469          $inp[$i]=~ s/onLoad=focusinput\(\)/onLoad=focusinput\(\)\;messenger\(\"\/cgi-bin\/koha\/pay.pl?bornum=$bornum\",700,600\)\;window1.focus\(\)/;
470      }
471 }
472
473 print @inp;
474
475
476 #print startmenu('circulation');
477 if ($borrower) {
478     print $title;
479 } else {
480     print $titlenoborrower;
481 }
482
483
484 print $info;
485
486 if ($question) {
487     print $questionform;
488 }
489
490 print $rejectedtext;
491 print $messagetable;
492
493
494 unless ($borrower) {
495     if ($borrowerslist) {
496         print $selectborrower;
497     } else {
498         print $cardnumberinput;
499     }
500 }
501
502
503
504 if ($borrower) {
505     my ($patrontable, $flaginfotable) = patrontable($borrower);
506     print $patrontable;
507     print $flaginfotable;
508     print $barcodeentrytext;
509     print "<p clear=all><br><br>";
510     print $issuedbookstable;
511 }
512
513
514
515
516 print endmenu('circulation');
517 print endpage();
518
519
520 ####################################################################
521 # Extra subroutines,,,
522
523 sub cuecatbarcodedecode {
524     my ($barcode) = @_;
525     chomp($barcode);
526     my @fields = split(/\./,$barcode);
527     my @results = map(decode($_), @fields[1..$#fields]);
528     if ($#results == 2){
529         return $results[2];
530     } else {
531         return $barcode;
532     } 
533
534
535 sub fixdate {
536     my ($year, $month, $day) = @_;
537     my $invalidduedate;
538     my $date;
539     if (($year eq 0) && ($month eq 0) && ($year eq 0)) {
540         $env{'datedue'}='';
541     } else {
542         if (($year eq 0) || ($month eq 0) || ($year eq 0)) {
543             $invalidduedate="Invalid Due Date Specified. Book was not issued.<p>\n";
544         } else {
545             if (($day>30) && (($month==4) || ($month==6) || ($month==9) || ($month==11))) {
546                 $invalidduedate = "Invalid Due Date Specified. Book was not issued. Only 30 days in $month month.<p>\n";
547             } elsif (($day > 29) && ($month == 2)) {
548                 $invalidduedate="Invalid Due Date Specified. Book was not issued.  Never that many days in February!<p>\n";
549             } elsif (($month == 2) && ($day > 28) && (($year%4) && ((!($year%100) || ($year%400))))) {
550                 $invalidduedate="Invalid Due Date Specified. Book was not issued.  $year is not a leap year.<p>\n";
551             } else {
552                 $date="$year-$month-$day";
553             }
554         }
555     }
556     return ($date, $invalidduedate);
557 }
558
559
560 sub patrontable {
561     my ($borrower) = @_;
562     my $flags = $borrower->{'flags'};
563     my $flaginfotable='';
564     my $flaginfotext='';
565     my $flag;
566     my $color='';
567     foreach $flag (sort keys %$flags) {
568         ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
569         $flags->{$flag}->{'message'}=~s/\n/<br>/g;
570         if ($flags->{$flag}->{'noissues'}) {
571             if ($flag eq 'CHARGES') {
572                 $flaginfotext.="<tr><td valign=top><font color=red>$flag</font></td><td bgcolor=$color><b>$flags->{$flag}->{'message'}</b> <a href=/cgi-bin/koha/pay.pl?bornum=$borrower->{'borrowernumber'} onClick=\"openWindow(this, 'Payment', 480,640)\">Payment</a></td></tr>\n";
573             } else {
574                 $flaginfotext.="<tr><td valign=top><font color=red>$flag</font></td><td bgcolor=$color>$flags->{$flag}->{'message'}</td></tr>\n";
575             }
576         } else {
577             if ($flag eq 'CHARGES') {
578                 $flaginfotext.="<tr><td valign=top>$flag</td><td> $flags->{$flag}->{'message'} <a href=/cgi-bin/koha/pay.pl?bornum=$borrower->{'borrowernumber'} onClick=\"openWindow(this, 'Payment', 480,640)\">Payment</a></td></tr>\n";
579             } elsif ($flag eq 'WAITING') {
580                 my $itemswaiting='';
581                 my $items=$flags->{$flag}->{'itemlist'};
582                 foreach my $item (@$items) {
583                     my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
584                     $itemswaiting.="<a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$iteminformation->{'barcode'}</a> $iteminformation->{'title'} ($branches->{$iteminformation->{'holdingbranch'}}->{'branchname'})<br>\n";
585                 }
586                 $flaginfotext.="<tr><td valign=top>$flag</td><td>$itemswaiting</td></tr>\n";
587             } elsif ($flag eq 'ODUES') {
588                 my $items=$flags->{$flag}->{'itemlist'};
589                 my $itemswaiting="<table border=1 cellspacing=0 cellpadding=2>\n";
590                 my $currentcolor=$color;
591                 {
592                     my $color=$currentcolor;
593                     foreach my $item (@$items) {
594                         ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
595                         my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
596                         $itemswaiting.="<tr><td><font color=red>$iteminformation->{'date_due'}</font></td><td bgcolor=$color><a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$iteminformation->{'barcode'}</a></td><td>$iteminformation->{'title'}</td></tr>\n";
597                     }               
598                 }
599                 $itemswaiting.="</table>\n";
600                 if ($query->param('module') ne 'returns'){
601                   $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}, See below</td></tr>\n";
602                 } else {
603                   $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n"; 
604                 }
605             } else {
606                 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
607             }
608         }
609     }
610     ($flaginfotext) && ($flaginfotext="<tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2><b>Flags</b></td></tr>$flaginfotext\n");
611     $flaginfotext.="</table>";
612     my $patrontable= << "EOF";
613 <br><p>
614     <table border=1 cellpadding=5 cellspacing=0 align=right>
615     <tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2><font color=black><b>Patron Information</b></font></td></tr>
616     <tr><td colspan=2>
617     <a href=/cgi-bin/koha/moremember.pl?bornum=$borrower->{'borrowernumber'} onClick="openWindow(this,'Member', 480, 640)">$borrower->{'cardnumber'}</a> $borrower->{'surname'}, $borrower->{'title'} $borrower->{'firstname'}<br>$borrower->{'streetaddress'} $borrower->{'city'} Cat: $borrower->{'categorycode'} </td></tr>
618 EOF
619     return($patrontable, $flaginfotext);
620 }
621
622
623
624 sub printslip {
625     my ($env,$borrowernumber)=@_;
626     my ($borrower, $flags) = getpatroninformation($env,$borrowernumber,0);
627     $env->{'todaysissues'}=1;
628     my ($borrowerissues) = currentissues($env, $borrower);
629     $env->{'nottodaysissues'}=1;
630     $env->{'todaysissues'}=0;
631     my ($borroweriss2)=currentissues($env, $borrower);
632     $env->{'nottodaysissues'}=0;
633     my $i=0;
634     my @issues;
635     foreach (sort keys %$borrowerissues) {
636         $issues[$i]=$borrowerissues->{$_};
637         my $dd=$issues[$i]->{'date_due'};
638         #convert to nz style dates
639         #this should be set with some kinda config variable
640         my @tempdate=split(/-/,$dd);
641         $issues[$i]->{'date_due'}="$tempdate[2]/$tempdate[1]/$tempdate[0]";
642         $i++;
643     }
644     foreach (sort keys %$borroweriss2) {
645         $issues[$i]=$borroweriss2->{$_};
646         my $dd=$issues[$i]->{'date_due'};
647         #convert to nz style dates
648         #this should be set with some kinda config variable
649         my @tempdate=split(/-/,$dd);
650         $issues[$i]->{'date_due'}="$tempdate[2]/$tempdate[1]/$tempdate[0]";
651         $i++;
652     }
653     remoteprint($env,\@issues,$borrower);
654 }