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 $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]));
54 # if there is a list of find borrowers....
55 my $findborrower = $query->param('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','');
66 $borrowerslist = \@borrowers;
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'){
78 if ($print eq 'yes' && $borrowernumber ne ''){
79 printslip(\%env,$borrowernumber);
80 $query->param('borrnumber','');
86 # get the currently issued books......
89 if ($borrowernumber) {
90 ($borrower, $flags) = getpatroninformation(\%env,$borrowernumber,0);
93 # get the responses to any questions.....
95 foreach (sort $query->param) {
96 if ($_ =~ /response-(\d*)/) {
97 $responses{$1} = $query->param($_);
100 if (my $qnumber = $query->param('questionnumber')) {
101 $responses{$qnumber} = $query->param('answer');
105 # if the barcode is set
106 my ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer);
108 my $year=$query->param('year');
109 my $month=$query->param('month');
110 my $day=$query->param('day');
114 $barcode = cuecatbarcodedecode($barcode);
115 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
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);
127 ##################################################################################
133 if ($rejected == -1) {
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>
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>
157 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
158 $selectborrower .= <<"EOF";
159 <option value=$_->{'borrowernumber'}>$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})
162 $selectborrower .= <<"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>  
175 <img src="/images/button-returns.gif" width="110" height="42" border="0" alt="Returns"></a>
176  <a href=branchtransfers.pl>
177 <img src="/images/button-transfers.gif" width="127" height="42" border="0" alt="Transfers">
180 <FONT SIZE=6><em>Circulation: Issues</em></FONT><br>
181 <b>Branch:</b> $branches->{$branch}->{'branchname'}  
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>
189 my $titlenoborrower = <<"EOF";
190 <table align="right"><tr><td>
192 <img src="/images/button-returns.gif" width="110" height="42" border="0" alt="Returns"></a>
193  <a href=branchtransfers.pl>
194 <img src="/images/button-transfers.gif" width="127" height="42" border="0" alt="Transfers">
197 <FONT SIZE=6><em>Circulation: Issues</em></FONT><br>
198 <b>Branch:</b> $branches->{$branch}->{'branchname'}  
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>
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>
220 my $responsesform = '';
221 foreach (keys %responses) {
222 $responsesform.="<input type=hidden name=response-$_ value=$responses{$_}>\n";
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'}.
236 </td></tr></table></td></tr>
237 <tr><td align=center>
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>
251 <input type=hidden name=answer value=Y>
252 <input type=submit value=Yes>
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>
267 <input type=hidden name=answer value=N>
268 <input type=submit value=No>
281 # Barcode entry box, with hidden inputs attached....
284 my $monthoptions = '';
285 my $yearoptions = '';
286 for (my $i=1; $i<32; $i++) {
288 if (($query->param('stickyduedate')) && ($day==$i)) {
289 $selected='selected';
291 $dayoptions.="<option value=$i $selected>$i";
293 foreach (('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')) {
295 if (($query->param('stickyduedate')) && ($month==$counter)) {
296 $selected='selected';
298 $monthoptions.="<option value=$counter $selected>$_";
301 for (my $i=$datearr[5]+1900; $i<$datearr[5]+1905; $i++) {
303 if (($query->param('stickyduedate')) && ($year==$i)) {
304 $selected='selected';
306 $yearoptions.="<option value=$i $selected>$i";
309 ($query->param('stickyduedate')) && ($selected='checked');
312 my $barcodeentrytext = <<"EOF";
313 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
314 <table border=1 cellpadding=5>
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>
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>
326 <select name=day><option value=0>Day$dayoptions</select>
328 <select name=month><option value=0>Month$monthoptions</select>
330 <select name=year><option value=0>Year$yearoptions</select>
333 <input type=checkbox name=stickyduedate $selected> Sticky Due Date
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>
341 if ($flags->{'CHARGES'}){
342 $barcodeentrytext.="<input type=hidden name=charges value=yes>";
344 my $amountold=$flags->{'CHARGES'}->{'message'};
345 my @temp=split(/\$/,$amountold);
347 $barcodeentrytext.="<input type=hidden name=oldamount value=$amountold>";
348 $barcodeentrytext.=<<"EOF";
355 # collect the messages and put into message table....
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>
367 # make the issued books table.....
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};
380 push @previousissues, $issueslist->{$it};
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]";
393 if ($datedue < $todaysdate) {
394 $dd="<font color=red>$dd</font>\n";
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>
406 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @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]";
414 if ($datedue < $todaysdate) {
415 $dd="<font color=red>$dd</font>\n";
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>
429 my $issuedbookstable;
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>
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>
455 # actually print the page!
458 if ($branchcookie && $printercookie) {
459 print $query->header(-type=>'text/html',-expires=>'now', -cookie=>[$branchcookie,$printercookie]);
461 print $query->header();
465 my @inp=startmenu('circulation');
466 if ($query->param('barcode') eq '' && $query->param('charges') eq 'yes'){
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\(\)/;
476 #print startmenu('circulation');
480 print $titlenoborrower;
495 if ($borrowerslist) {
496 print $selectborrower;
498 print $cardnumberinput;
505 my ($patrontable, $flaginfotable) = patrontable($borrower);
507 print $flaginfotable;
508 print $barcodeentrytext;
509 print "<p clear=all><br><br>";
510 print $issuedbookstable;
516 print endmenu('circulation');
520 ####################################################################
521 # Extra subroutines,,,
523 sub cuecatbarcodedecode {
526 my @fields = split(/\./,$barcode);
527 my @results = map(decode($_), @fields[1..$#fields]);
536 my ($year, $month, $day) = @_;
539 if (($year eq 0) && ($month eq 0) && ($year eq 0)) {
542 if (($year eq 0) || ($month eq 0) || ($year eq 0)) {
543 $invalidduedate="Invalid Due Date Specified. Book was not issued.<p>\n";
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";
552 $date="$year-$month-$day";
556 return ($date, $invalidduedate);
562 my $flags = $borrower->{'flags'};
563 my $flaginfotable='';
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";
574 $flaginfotext.="<tr><td valign=top><font color=red>$flag</font></td><td bgcolor=$color>$flags->{$flag}->{'message'}</td></tr>\n";
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') {
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";
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;
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";
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";
603 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
606 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
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";
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>
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>
619 return($patrontable, $flaginfotext);
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;
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]";
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]";
653 remoteprint($env,\@issues,$borrower);