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>
188 my $titlenoborrower = <<"EOF";
189 <table align="right"><tr><td>
191 <img src="/images/button-returns.gif" width="110" height="42" border="0" alt="Returns"></a>
192  <a href=branchtransfers.pl>
193 <img src="/images/button-transfers.gif" width="127" height="42" border="0" alt="Transfers">
196 <FONT SIZE=6><em>Circulation: Issues</em></FONT><br>
197 <b>Branch:</b> $branches->{$branch}->{'branchname'}  
198 <b>Printer:</b> $printers->{$printer}->{'printername'} <br>
199 <a href=selectbranchprinter.pl>Change Settings</a></td>
200 <input type=hidden name=branch value=$branch>
201 <input type=hidden name=printer value=$printer>
207 my $cardnumberinput = << "EOF";
208 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
209 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
210 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
211 <font color=black><b>Enter borrower card number<br> or partial last name</b></font></td></tr>
212 <tr><td><input name=findborrower></td></tr>
213 <input type=hidden name=branch value=$branch>
214 <input type=hidden name=printer value=$printer>
219 my $responsesform = '';
220 foreach (keys %responses) {
221 $responsesform.="<input type=hidden name=response-$_ value=$responses{$_}>\n";
225 my $stickyduedate=$query->param('stickyduedate');
226 $questionform = <<"EOF";
227 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
228 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
229 <font color=black><b>Issuing Question</b></font></th></tr>
230 <tr><td><table border=0 cellpadding=10><tr><td>
231 Attempting to issue $iteminformation->{'title'}
232 by $iteminformation->{'author'} to $borrower->{'firstname'} $borrower->{'surname'}.
235 </td></tr></table></td></tr>
236 <tr><td align=center>
240 <input type=hidden name=borrnumber value=$borrowernumber>
241 <input type=hidden name=barcode value=$barcode>
242 <input type=hidden name=questionnumber value=$questionnumber>
243 <input type=hidden name=day value=$day>
244 <input type=hidden name=month value=$month>
245 <input type=hidden name=year value=$year>
246 <input type=hidden name=stickyduedate value=$stickyduedate>
247 <input type=hidden name=branch value=$branch>
248 <input type=hidden name=printer value=$printer>
250 <input type=hidden name=answer value=Y>
251 <input type=submit value=Yes>
256 <input type=hidden name=borrnumber value=$borrowernumber>
257 <input type=hidden name=barcode value=$barcode>
258 <input type=hidden name=questionnumber value=$questionnumber>
259 <input type=hidden name=day value=$day>
260 <input type=hidden name=month value=$month>
261 <input type=hidden name=year value=$year>
262 <input type=hidden name=stickyduedate value=$stickyduedate>
263 <input type=hidden name=branch value=$branch>
264 <input type=hidden name=printer value=$printer>
266 <input type=hidden name=answer value=N>
267 <input type=submit value=No>
280 # Barcode entry box, with hidden inputs attached....
283 my $monthoptions = '';
284 my $yearoptions = '';
285 for (my $i=1; $i<32; $i++) {
287 if (($query->param('stickyduedate')) && ($day==$i)) {
288 $selected='selected';
290 $dayoptions.="<option value=$i $selected>$i";
292 foreach (('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')) {
294 if (($query->param('stickyduedate')) && ($month==$counter)) {
295 $selected='selected';
297 $monthoptions.="<option value=$counter $selected>$_";
300 for (my $i=$datearr[5]+1900; $i<$datearr[5]+1905; $i++) {
302 if (($query->param('stickyduedate')) && ($year==$i)) {
303 $selected='selected';
305 $yearoptions.="<option value=$i $selected>$i";
308 ($query->param('stickyduedate')) && ($selected='checked');
311 my $barcodeentrytext = <<"EOF";
312 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
313 <table border=1 cellpadding=5>
315 <td align=center valign=top>
316 <table border=0 cellspacing=0 cellpadding=5>
317 <tr><th align=center background=$backgroundimage>
318 <font color=black><b>Enter Book Barcode</b></font></th></tr>
319 <tr><td align=center>
321 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td><td><input type=submit value=Issue></td></tr>
322 <tr><td colspan=3 align=center>
323 <table border=0 cellpadding=0 cellspacing=0>
325 <select name=day><option value=0>Day$dayoptions</select>
327 <select name=month><option value=0>Month$monthoptions</select>
329 <select name=year><option value=0>Year$yearoptions</select>
332 <input type=checkbox name=stickyduedate $selected> Sticky Due Date
335 <input type=hidden name=borrnumber value=$borrowernumber>
336 <input type=hidden name=branch value=$branch>
337 <input type=hidden name=printer value=$printer>
338 <input type=hidden name=print value=maybe>
340 if ($flags->{'CHARGES'}){
341 $barcodeentrytext.="<input type=hidden name=charges value=yes>";
343 my $amountold=$flags->{'CHARGES'}->{'message'};
344 my @temp=split(/\$/,$amountold);
346 $barcodeentrytext.="<input type=hidden name=oldamount value=$amountold>";
347 $barcodeentrytext.=<<"EOF";
354 # collect the messages and put into message table....
357 $messagetable = << "EOF";
358 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
359 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
360 <tr><td> $message </td></tr></table>
366 # make the issued books table.....
370 my $issueslist = getissues($borrower);
373 foreach my $it (sort keys %$issueslist) {
374 my $dd = $issueslist->{$it}->{'date_due'};
375 my $issuedate = $issueslist->{$it}->{'timestamp'};
376 $issuedate = substr($issuedate, 0, 8);
378 my $bookissue = $issueslist->{$it};
380 my $datedue = $bookissue->{'date_due'};
381 #convert to nz style dates
382 #this should be set with some kinda config variable
383 my @tempdate=split(/-/,$dd);
384 $dd="$tempdate[2]/$tempdate[1]/$tempdate[0]";
386 if ($datedue < $todaysdate) {
387 $dd="<font color=red>$dd</font>\n";
389 if ($todaysdate == $issuedate) {
390 ($tcolor eq $linecolor1) ? ($tcolor=$linecolor2) : ($tcolor=$linecolor1);
391 $todaysissues .=<< "EOF";
392 <tr><td bgcolor=$tcolor align=center>$dd</td>
393 <td bgcolor=$tcolor align=center>
394 <a href=/cgi-bin/koha/detail.pl?bib=$bookissue->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$bookissue->{'barcode'}</a></td>
395 <td bgcolor=$tcolor>$bookissue->{'title'}</td>
396 <td bgcolor=$tcolor>$bookissue->{'author'}</td>
397 <td bgcolor=$tcolor align=center>$bookissue->{'dewey'} $bookissue->{'subclass'}</td></tr>
400 ($pcolor eq $linecolor1) ? ($pcolor=$linecolor2) : ($pcolor=$linecolor1);
401 $previssues .= << "EOF";
402 <tr><td bgcolor=$pcolor align=center>$dd</td>
403 <td bgcolor=$pcolor align=center>
404 <a href=/cgi-bin/koha/detail.pl?bib=$bookissue->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$bookissue->{'barcode'}</a></td>
405 <td bgcolor=$pcolor>$bookissue->{'title'}</td>
406 <td bgcolor=$pcolor>$bookissue->{'author'}</td>
407 <td bgcolor=$pcolor align=center>$bookissue->{'dewey'} $bookissue->{'subclass'}</td></tr>
413 my $issuedbookstable;
415 $issuedbookstable .= <<"EOF";
416 <table border=1 cellpadding=5 cellspacing=0 width=80%>
417 <tr><th colspan=5 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>
418 <b>Todays Issues</b></font></th></tr>
419 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Class</th></tr>
425 $issuedbookstable .= <<"EOF";
426 <table border=1 cellpadding=5 cellspacing=0 width=80%>
427 <tr><th colspan=5 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>
428 <b>Previous Issues</b></font></th></tr>
429 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Class</th></tr>
439 # actually print the page!
442 if ($branchcookie && $printercookie) {
443 print $query->header(-type=>'text/html',-expires=>'now', -cookie=>[$branchcookie,$printercookie]);
445 print $query->header();
449 my @inp=startmenu('circulation');
450 if ($query->param('barcode') eq '' && $query->param('charges') eq 'yes'){
452 for (my $i=0;$i<$count;$i++){
453 $inp[$i]=~ s/onLoad=focusinput\(\)/onLoad=focusinput\(\)\;messenger\(\"\/cgi-bin\/koha\/pay.pl?bornum=$bornum\"\)\;window1.focus\(\)/;
459 <script language="javascript" type="text/javascript">
461 function messenger(url){
462 window1=window.open(url,"window1","height=700,width=600,left=150,top=50,350,screenY=50");
470 #print startmenu('circulation');
474 print $titlenoborrower;
489 if ($borrowerslist) {
490 print $selectborrower;
492 print $cardnumberinput;
499 my ($patrontable, $flaginfotable) = patrontable($borrower);
501 print $flaginfotable;
502 print $barcodeentrytext;
503 print "<p clear=all><br><br>";
504 print $issuedbookstable;
510 print endmenu('circulation');
514 ####################################################################
515 # Extra subroutines,,,
517 sub cuecatbarcodedecode {
520 my @fields = split(/\./,$barcode);
521 my @results = map(decode($_), @fields[1..$#fields]);
530 my ($year, $month, $day) = @_;
533 if (($year eq 0) && ($month eq 0) && ($year eq 0)) {
536 if (($year eq 0) || ($month eq 0) || ($year eq 0)) {
537 $invalidduedate="Invalid Due Date Specified. Book was not issued.<p>\n";
539 if (($day>30) && (($month==4) || ($month==6) || ($month==9) || ($month==11))) {
540 $invalidduedate = "Invalid Due Date Specified. Book was not issued. Only 30 days in $month month.<p>\n";
541 } elsif (($day > 29) && ($month == 2)) {
542 $invalidduedate="Invalid Due Date Specified. Book was not issued. Never that many days in February!<p>\n";
543 } elsif (($month == 2) && ($day > 28) && (($year%4) && ((!($year%100) || ($year%400))))) {
544 $invalidduedate="Invalid Due Date Specified. Book was not issued. $year is not a leap year.<p>\n";
546 $date="$year-$month-$day";
550 return ($date, $invalidduedate);
556 my $flags = $borrower->{'flags'};
557 my $flaginfotable='';
561 foreach $flag (sort keys %$flags) {
562 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
563 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
564 if ($flags->{$flag}->{'noissues'}) {
565 if ($flag eq 'CHARGES') {
566 $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";
568 $flaginfotext.="<tr><td valign=top><font color=red>$flag</font></td><td bgcolor=$color>$flags->{$flag}->{'message'}</td></tr>\n";
571 if ($flag eq 'CHARGES') {
572 $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";
573 } elsif ($flag eq 'WAITING') {
575 my $items=$flags->{$flag}->{'itemlist'};
576 foreach my $item (@$items) {
577 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
578 $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";
580 $flaginfotext.="<tr><td valign=top>$flag</td><td>$itemswaiting</td></tr>\n";
581 } elsif ($flag eq 'ODUES') {
582 my $items=$flags->{$flag}->{'itemlist'};
583 my $itemswaiting="<table border=1 cellspacing=0 cellpadding=2>\n";
584 my $currentcolor=$color;
586 my $color=$currentcolor;
587 foreach my $item (@$items) {
588 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
589 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
590 $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";
593 $itemswaiting.="</table>\n";
594 if ($query->param('module') ne 'returns'){
595 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}, See below</td></tr>\n";
597 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
600 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
604 ($flaginfotext) && ($flaginfotext="<tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2><b>Flags</b></td></tr>$flaginfotext\n");
605 $flaginfotext.="</table>";
606 my $patrontable= << "EOF";
608 <table border=1 cellpadding=5 cellspacing=0 align=right>
609 <tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2><font color=black><b>Patron Information</b></font></td></tr>
611 <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>
613 return($patrontable, $flaginfotext);
619 my ($env,$borrowernumber)=@_;
620 my ($borrower, $flags) = getpatroninformation($env,$borrowernumber,0);
621 $env->{'todaysissues'}=1;
622 my ($borrowerissues) = currentissues($env, $borrower);
623 $env->{'nottodaysissues'}=1;
624 $env->{'todaysissues'}=0;
625 my ($borroweriss2)=currentissues($env, $borrower);
626 $env->{'nottodaysissues'}=0;
629 foreach (sort keys %$borrowerissues) {
630 $issues[$i]=$borrowerissues->{$_};
631 my $dd=$issues[$i]->{'date_due'};
632 #convert to nz style dates
633 #this should be set with some kinda config variable
634 my @tempdate=split(/-/,$dd);
635 $issues[$i]->{'date_due'}="$tempdate[2]/$tempdate[1]/$tempdate[0]";
638 foreach (sort keys %$borroweriss2) {
639 $issues[$i]=$borroweriss2->{$_};
640 my $dd=$issues[$i]->{'date_due'};
641 #convert to nz style dates
642 #this should be set with some kinda config variable
643 my @tempdate=split(/-/,$dd);
644 $issues[$i]->{'date_due'}="$tempdate[2]/$tempdate[1]/$tempdate[0]";
647 remoteprint($env,\@issues,$borrower);