3 #written 8/5/2002 by Finlay
4 #script to execute issuing of books
8 use C4::Circulation::Circ2;
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";
21 my $branches = getbranches();
22 my $printers = getprinters(\%env);
26 my $branch = $query->param("branch");
27 my $printer = $query->param("printer");
29 ($branch) || ($branch=$query->cookie('branch')) ;
30 ($printer) || ($printer=$query->cookie('printer')) ;
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');
41 $env{'branchcode'}=$branch;
42 $env{'printer'}=$printer;
43 $env{'queue'}=$printer;
45 my @datearr = localtime(time());
46 my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", $datearr[3]);
52 # if there is a list of find borrowers....
53 my $findborrower = $query->param('findborrower');
55 my ($borrowers, $flags) = findborrower(\%env, $findborrower);
56 my @borrowers=@$borrowers;
57 if ($#borrowers == -1) {
58 $query->param('findborrower', '');
59 $message = "No borrower matched '$findborrower'";
60 } elsif ($#borrowers == 0) {
61 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
62 $query->param('barcode','');
64 $borrowerslist = \@borrowers;
68 my $borrowernumber = $query->param('borrnumber');
69 my $bornum = $query->param('borrnumber');
70 # check and see if we should print
71 my $print=$query->param('print');
72 my $barcode = $query->param('barcode');
73 if ($barcode eq '' && $print eq 'maybe'){
76 if ($print eq 'yes' && $borrowernumber ne ''){
77 printslip(\%env,$borrowernumber);
78 $query->param('borrnumber','');
84 # get the currently issued books......
87 if ($borrowernumber) {
88 ($borrower, $flags) = getpatroninformation(\%env,$borrowernumber,0);
91 # get the responses to any questions.....
93 foreach (sort $query->param) {
94 if ($_ =~ /response-(\d*)/) {
95 $responses{$1} = $query->param($_);
98 if (my $qnumber = $query->param('questionnumber')) {
99 $responses{$qnumber} = $query->param('answer');
103 # if the barcode is set
105 my ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer);
107 my $year=$query->param('year');
108 my $month=$query->param('month');
109 my $day=$query->param('day');
113 $barcode = cuecatbarcodedecode($barcode);
114 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
116 unless ($invalidduedate) {
117 $env{'datedue'}=$datedue;
118 my @time=localtime(time);
119 my $date= (1900+$time[5])."-".($time[4]+1)."-".$time[3];
120 ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer, $message)
121 = issuebook(\%env, $borrower, $barcode, \%responses, $date);
126 ##################################################################################
132 if ($rejected == -1) {
134 $rejectedtext = << "EOF";
135 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
136 <tr><th><font color=black size=5>Error Issuing Book</font></th></tr>
137 <tr><td><font color=red size=5>$rejected</font></td></tr>
145 if ($borrowerslist) {
146 $selectborrower = <<"EOF";
147 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
148 <input type=hidden name=branch value=$branch>
149 <input type=hidden name=printer value=$printer>
150 <table border=1 cellspacing=0 cellpadding=5 bgcolor="#dddddd">
151 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
152 <font color=black><b>Select a borrower</b></font></th></tr>\n
153 <tr><td align=center>
154 <select name=borrnumber size=7>
156 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
157 $selectborrower .= <<"EOF";
158 <option value=$_->{'borrowernumber'}>$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})
161 $selectborrower .= <<"EOF";
170 <table align="right"><tr><td>
171 <a href=circulation.pl?borrnumber=$borrowernumber&branch=$branch&printer=$printer&print=yes>
172 <img src="/images/button-next-borrower.gif" width="171" height="42" border="0" alt="Next Borrower"></a>  
174 <img src="/images/button-returns.gif" width="110" height="42" border="0" alt="Returns"></a>
175  <a href=branchtransfers.pl>
176 <img src="/images/button-transfers.gif" width="127" height="42" border="0" alt="Transfers">
179 <FONT SIZE=6><em>Circulation: Issues</em></FONT><br>
180 <b>Branch:</b> $branches->{$branch}->{'branchname'}  
181 <b>Printer:</b> $printers->{$printer}->{'printername'} <br>
182 <a href=selectbranchprinter.pl>Change Settings</a></td>
183 <input type=hidden name=branch value=$branch>
184 <input type=hidden name=printer value=$printer>
190 my $cardnumberinput = << "EOF";
191 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
192 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
193 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
194 <font color=black><b>Enter borrower card number<br> or partial last name</b></font></td></tr>
195 <tr><td><input name=findborrower></td></tr>
196 <input type=hidden name=branch value=$branch>
197 <input type=hidden name=printer value=$printer>
202 my $responsesform = '';
203 foreach (keys %responses) {
204 $responsesform.="<input type=hidden name=response-$_ value=$responses{$_}>\n";
208 my $stickyduedate=$query->param('stickyduedate');
209 $questionform = <<"EOF";
210 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
211 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
212 <font color=black><b>Issuing Question</b></font></th></tr>
213 <tr><td><table border=0 cellpadding=10><tr><td>
214 Attempting to issue $iteminformation->{'title'}
215 by $iteminformation->{'author'} to $borrower->{'firstname'} $borrower->{'surname'}.
218 </td></tr></table></td></tr>
219 <tr><td align=center>
223 <input type=hidden name=borrnumber value=$borrowernumber>
224 <input type=hidden name=barcode value=$barcode>
225 <input type=hidden name=questionnumber value=$questionnumber>
226 <input type=hidden name=day value=$day>
227 <input type=hidden name=month value=$month>
228 <input type=hidden name=year value=$year>
229 <input type=hidden name=stickyduedate value=$stickyduedate>
230 <input type=hidden name=branch value=$branch>
231 <input type=hidden name=printer value=$printer>
233 <input type=hidden name=answer value=Y>
234 <input type=submit value=Yes>
239 <input type=hidden name=borrnumber value=$borrowernumber>
240 <input type=hidden name=barcode value=$barcode>
241 <input type=hidden name=questionnumber value=$questionnumber>
242 <input type=hidden name=day value=$day>
243 <input type=hidden name=month value=$month>
244 <input type=hidden name=year value=$year>
245 <input type=hidden name=stickyduedate value=$stickyduedate>
246 <input type=hidden name=branch value=$branch>
247 <input type=hidden name=printer value=$printer>
249 <input type=hidden name=answer value=N>
250 <input type=submit value=No>
263 # Barcode entry box, with hidden inputs attached....
266 my $monthoptions = '';
267 my $yearoptions = '';
268 for (my $i=1; $i<32; $i++) {
270 if (($query->param('stickyduedate')) && ($day==$i)) {
271 $selected='selected';
273 $dayoptions.="<option value=$i $selected>$i";
275 foreach (('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')) {
277 if (($query->param('stickyduedate')) && ($month==$counter)) {
278 $selected='selected';
280 $monthoptions.="<option value=$counter $selected>$_";
283 for (my $i=$datearr[5]+1900; $i<$datearr[5]+1905; $i++) {
285 if (($query->param('stickyduedate')) && ($year==$i)) {
286 $selected='selected';
288 $yearoptions.="<option value=$i $selected>$i";
291 ($query->param('stickyduedate')) && ($selected='checked');
294 my $barcodeentrytext = <<"EOF";
295 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
296 <table border=1 cellpadding=5>
298 <td align=center valign=top>
299 <table border=0 cellspacing=0 cellpadding=5>
300 <tr><th align=center background=$backgroundimage>
301 <font color=black><b>Enter Book Barcode</b></font></th></tr>
302 <tr><td align=center>
304 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td><td><input type=submit value=Issue></td></tr>
305 <tr><td colspan=3 align=center>
306 <table border=0 cellpadding=0 cellspacing=0>
308 <select name=day><option value=0>Day$dayoptions</select>
310 <select name=month><option value=0>Month$monthoptions</select>
312 <select name=year><option value=0>Year$yearoptions</select>
315 <input type=checkbox name=stickyduedate $selected> Sticky Due Date
318 <input type=hidden name=borrnumber value=$borrowernumber>
319 <input type=hidden name=branch value=$branch>
320 <input type=hidden name=printer value=$printer>
321 <input type=hidden name=print value=maybe>
323 if ($flags->{'CHARGES'}){
324 $barcodeentrytext.="<input type=hidden name=charges value=yes>";
326 my $amountold=$flags->{'CHARGES'}->{'message'};
327 my @temp=split(/\$/,$amountold);
329 $barcodeentrytext.="<input type=hidden name=oldamount value=$amountold>";
330 $barcodeentrytext.=<<"EOF";
337 # collect the messages and put into message table....
340 $messagetable = << "EOF";
341 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
342 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
343 <tr><td> $message </td></tr></table>
349 # make the issued books table.....
353 my $issueslist = getissues($borrower);
356 foreach my $it (sort keys %$issueslist) {
357 my $dd = $issueslist->{$it}->{'date_due'};
358 my $issuedate = $issueslist->{$it}->{'timestamp'};
359 $issuedate = substr($issuedate, 0, 8);
361 my $bookissue = $issueslist->{$it};
363 my $datedue = $bookissue->{'date_due'};
364 #convert to nz style dates
365 #this should be set with some kinda config variable
366 my @tempdate=split(/-/,$dd);
367 $dd="$tempdate[2]/$tempdate[1]/$tempdate[0]";
369 if ($datedue < $todaysdate) {
370 $dd="<font color=red>$dd</font>\n";
372 if ($todaysdate == $issuedate) {
373 ($tcolor eq $linecolor1) ? ($tcolor=$linecolor2) : ($tcolor=$linecolor1);
374 $todaysissues .=<< "EOF";
375 <tr><td bgcolor=$tcolor align=center>$dd</td>
376 <td bgcolor=$tcolor align=center>
377 <a href=/cgi-bin/koha/detail.pl?bib=$bookissue->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$bookissue->{'barcode'}</a></td>
378 <td bgcolor=$tcolor>$bookissue->{'title'}</td>
379 <td bgcolor=$tcolor>$bookissue->{'author'}</td>
380 <td bgcolor=$tcolor align=center>$bookissue->{'dewey'} $bookissue->{'subclass'}</td></tr>
383 ($pcolor eq $linecolor1) ? ($pcolor=$linecolor2) : ($pcolor=$linecolor1);
384 $previssues .= << "EOF";
385 <tr><td bgcolor=$pcolor align=center>$dd</td>
386 <td bgcolor=$pcolor align=center>
387 <a href=/cgi-bin/koha/detail.pl?bib=$bookissue->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$bookissue->{'barcode'}</a></td>
388 <td bgcolor=$pcolor>$bookissue->{'title'}</td>
389 <td bgcolor=$pcolor>$bookissue->{'author'}</td>
390 <td bgcolor=$pcolor align=center>$bookissue->{'dewey'} $bookissue->{'subclass'}</td></tr>
396 my $issuedbookstable;
398 $issuedbookstable .= <<"EOF";
399 <table border=1 cellpadding=5 cellspacing=0 width=80%>
400 <tr><th colspan=5 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>
401 <b>Todays Issues</b></font></th></tr>
402 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Class</th></tr>
408 $issuedbookstable .= <<"EOF";
409 <table border=1 cellpadding=5 cellspacing=0 width=80%>
410 <tr><th colspan=5 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>
411 <b>Previous Issues</b></font></th></tr>
412 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Class</th></tr>
422 # actually print the page!
425 if ($branchcookie && $printercookie) {
426 print $query->header(-type=>'text/html',-expires=>'now', -cookie=>[$branchcookie,$printercookie]);
428 print $query->header();
432 my @inp=startmenu('circulation');
433 if ($query->param('barcode') eq '' && $query->param('charges') eq 'yes'){
435 for (my $i=0;$i<$count;$i++){
436 $inp[$i]=~ s/onLoad=focusinput\(\)/onLoad=focusinput\(\)\;messenger\(\"\/cgi-bin\/koha\/pay.pl?bornum=$bornum\"\)\;window1.focus\(\)/;
442 <script language="javascript" type="text/javascript">
444 function messenger(url){
445 window1=window.open(url,"window1","height=700,width=600,left=150,top=50,350,screenY=50");
453 #print startmenu('circulation');
469 if ($borrowerslist) {
470 print $selectborrower;
472 print $cardnumberinput;
479 my ($patrontable, $flaginfotable) = patrontable($borrower);
481 print $flaginfotable;
482 print $barcodeentrytext;
483 print "<p clear=all><br><br>";
484 print $issuedbookstable;
490 print endmenu('circulation');
494 ####################################################################
495 # Extra subroutines,,,
497 sub cuecatbarcodedecode {
500 my @fields = split(/\./,$barcode);
501 my @results = map(decode($_), @fields[1..$#fields]);
510 my ($year, $month, $day) = @_;
513 if (($year eq 0) && ($month eq 0) && ($year eq 0)) {
516 if (($year eq 0) || ($month eq 0) || ($year eq 0)) {
517 $invalidduedate="Invalid Due Date Specified. Book was not issued.<p>\n";
519 if (($day>30) && (($month==4) || ($month==6) || ($month==9) || ($month==11))) {
520 $invalidduedate = "Invalid Due Date Specified. Book was not issued. Only 30 days in $month month.<p>\n";
521 } elsif (($day > 29) && ($month == 2)) {
522 $invalidduedate="Invalid Due Date Specified. Book was not issued. Never that many days in February!<p>\n";
523 } elsif (($month == 2) && ($day > 28) && (($year%4) && ((!($year%100) || ($year%400))))) {
524 $invalidduedate="Invalid Due Date Specified. Book was not issued. $year is not a leap year.<p>\n";
526 $date="$year-$month-$day";
530 return ($date, $invalidduedate);
536 my $flags = $borrower->{'flags'};
537 my $flaginfotable='';
541 foreach $flag (sort keys %$flags) {
542 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
543 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
544 if ($flags->{$flag}->{'noissues'}) {
545 if ($flag eq 'CHARGES') {
546 $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";
548 $flaginfotext.="<tr><td valign=top><font color=red>$flag</font></td><td bgcolor=$color>$flags->{$flag}->{'message'}</td></tr>\n";
551 if ($flag eq 'CHARGES') {
552 $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";
553 } elsif ($flag eq 'WAITING') {
555 my $items=$flags->{$flag}->{'itemlist'};
556 foreach my $item (@$items) {
557 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
558 $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";
560 $flaginfotext.="<tr><td valign=top>$flag</td><td>$itemswaiting</td></tr>\n";
561 } elsif ($flag eq 'ODUES') {
562 my $items=$flags->{$flag}->{'itemlist'};
563 my $itemswaiting="<table border=1 cellspacing=0 cellpadding=2>\n";
564 my $currentcolor=$color;
566 my $color=$currentcolor;
567 foreach my $item (@$items) {
568 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
569 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
570 $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";
573 $itemswaiting.="</table>\n";
574 if ($query->param('module') ne 'returns'){
575 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}, See below</td></tr>\n";
577 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
580 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
584 ($flaginfotext) && ($flaginfotext="<tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2><b>Flags</b></td></tr>$flaginfotext\n");
585 $flaginfotext.="</table>";
586 my $patrontable= << "EOF";
588 <table border=1 cellpadding=5 cellspacing=0 align=right>
589 <tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2><font color=black><b>Patron Information</b></font></td></tr>
591 <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>
593 return($patrontable, $flaginfotext);
599 my ($env,$borrowernumber)=@_;
600 my ($borrower, $flags) = getpatroninformation($env,$borrowernumber,0);
601 $env->{'todaysissues'}=1;
602 my ($borrowerissues) = currentissues($env, $borrower);
603 $env->{'nottodaysissues'}=1;
604 $env->{'todaysissues'}=0;
605 my ($borroweriss2)=currentissues($env, $borrower);
606 $env->{'nottodaysissues'}=0;
609 foreach (sort keys %$borrowerissues) {
610 $issues[$i]=$borrowerissues->{$_};
611 my $dd=$issues[$i]->{'date_due'};
612 #convert to nz style dates
613 #this should be set with some kinda config variable
614 my @tempdate=split(/-/,$dd);
615 $issues[$i]->{'date_due'}="$tempdate[2]/$tempdate[1]/$tempdate[0]";
618 foreach (sort keys %$borroweriss2) {
619 $issues[$i]=$borroweriss2->{$_};
620 my $dd=$issues[$i]->{'date_due'};
621 #convert to nz style dates
622 #this should be set with some kinda config variable
623 my @tempdate=split(/-/,$dd);
624 $issues[$i]->{'date_due'}="$tempdate[2]/$tempdate[1]/$tempdate[0]";
627 remoteprint($env,\@issues,$borrower);