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');
70 # get the currently issued books......
73 if ($borrowernumber) {
74 ($borrower, $flags) = getpatroninformation(\%env,$borrowernumber,0);
77 # get the responses to any questions.....
79 foreach (sort $query->param) {
80 if ($_ =~ /response-(\d*)/) {
81 $responses{$1} = $query->param($_);
84 if (my $qnumber = $query->param('questionnumber')) {
85 $responses{$qnumber} = $query->param('answer');
89 # if the barcode is set
90 my $barcode = $query->param('barcode');
91 my ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer);
93 my $year=$query->param('year');
94 my $month=$query->param('month');
95 my $day=$query->param('day');
99 $barcode = cuecatbarcodedecode($barcode);
100 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
102 unless ($invalidduedate) {
103 $env{'datedue'}=$datedue;
104 my @time=localtime(time);
105 my $date= (1900+$time[5])."-".($time[4]+1)."-".$time[3];
106 ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer, $message)
107 = issuebook(\%env, $borrower, $barcode, \%responses, $date);
112 ##################################################################################
118 if ($rejected == -1) {
120 $rejectedtext = << "EOF";
121 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
122 <tr><th><font color=black size=5>Error Issuing Book</font></th></tr>
123 <tr><td><font color=red size=5>$rejected</font></td></tr>
131 if ($borrowerslist) {
132 $selectborrower = <<"EOF";
133 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
134 <input type=hidden name=branch value=$branch>
135 <input type=hidden name=printer value=$printer>
136 <table border=1 cellspacing=0 cellpadding=5 bgcolor="#dddddd">
137 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
138 <font color=black><b>Select a borrower</b></font></th></tr>\n
139 <tr><td align=center>
140 <select name=borrnumber size=7>
142 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
143 $selectborrower .= <<"EOF";
144 <option value=$_->{'borrowernumber'}>$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})
147 $selectborrower .= <<"EOF";
156 <table align="right"><tr><td>
157 <a href=circulation.pl>
158 <img src="/images/button-next-borrower.gif" width="171" height="42" border="0" alt="Next Borrower"></a>  
160 <img src="/images/button-returns.gif" width="110" height="42" border="0" alt="Returns"></a>
161  <a href=branchtransfers.pl>
162 <img src="/images/button-transfers.gif" width="127" height="42" border="0" alt="Transfers">
165 <FONT SIZE=6><em>Circulation: Issues</em></FONT><br>
166 <b>Branch:</b> $branches->{$branch}->{'branchname'}  
167 <b>Printer:</b> $printers->{$printer}->{'printername'} <br>
168 <a href=selectbranchprinter.pl>Change Settings</a></td>
169 <input type=hidden name=branch value=$branch>
170 <input type=hidden name=printer value=$printer>
176 my $cardnumberinput = << "EOF";
177 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
178 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
179 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
180 <font color=black><b>Enter borrower card number<br> or partial last name</b></font></td></tr>
181 <tr><td><input name=findborrower></td></tr>
186 my $responsesform = '';
187 foreach (keys %responses) {
188 $responsesform.="<input type=hidden name=response-$_ value=$responses{$_}>\n";
192 my $stickyduedate=$query->param('stickyduedate');
193 $questionform = <<"EOF";
194 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
195 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
196 <font color=black><b>Issuing Question</b></font></th></tr>
197 <tr><td><table border=0 cellpadding=10><tr><td>
198 Attempting to issue $iteminformation->{'title'}
199 by $iteminformation->{'author'} to $borrower->{'firstname'} $borrower->{'surname'}.
202 </td></tr></table></td></tr>
203 <tr><td align=center>
207 <input type=hidden name=borrnumber value=$borrowernumber>
208 <input type=hidden name=barcode value=$barcode>
209 <input type=hidden name=questionnumber value=$questionnumber>
210 <input type=hidden name=day value=$day>
211 <input type=hidden name=month value=$month>
212 <input type=hidden name=year value=$year>
213 <input type=hidden name=stickyduedate value=$stickyduedate>
214 <input type=hidden name=branch value=$branch>
215 <input type=hidden name=printer value=$printer>
217 <input type=hidden name=answer value=Y>
218 <input type=submit value=Yes>
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=N>
234 <input type=submit value=No>
247 # Barcode entry box, with hidden inputs attached....
250 my $monthoptions = '';
251 my $yearoptions = '';
252 for (my $i=1; $i<32; $i++) {
254 if (($query->param('stickyduedate')) && ($day==$i)) {
255 $selected='selected';
257 $dayoptions.="<option value=$i $selected>$i";
259 foreach (('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')) {
261 if (($query->param('stickyduedate')) && ($month==$counter)) {
262 $selected='selected';
264 $monthoptions.="<option value=$counter $selected>$_";
267 for (my $i=$datearr[5]+1900; $i<$datearr[5]+1905; $i++) {
269 if (($query->param('stickyduedate')) && ($year==$i)) {
270 $selected='selected';
272 $yearoptions.="<option value=$i $selected>$i";
275 ($query->param('stickyduedate')) && ($selected='checked');
278 my $barcodeentrytext = <<"EOF";
279 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
280 <table border=1 cellpadding=5>
282 <td align=center valign=top>
283 <table border=0 cellspacing=0 cellpadding=5>
284 <tr><th align=center background=$backgroundimage>
285 <font color=black><b>Enter Book Barcode</b></font></th></tr>
286 <tr><td align=center>
288 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td><td><input type=submit value=Issue></td></tr>
289 <tr><td colspan=3 align=center>
290 <table border=0 cellpadding=0 cellspacing=0>
292 <select name=day><option value=0>Day$dayoptions</select>
294 <select name=month><option value=0>Month$monthoptions</select>
296 <select name=year><option value=0>Year$yearoptions</select>
299 <input type=checkbox name=stickyduedate $selected> Sticky Due Date
302 <input type=hidden name=borrnumber value=$borrowernumber>
303 <input type=hidden name=branch value=$branch>
304 <input type=hidden name=printer value=$printer>
311 # collect the messages and put into message table....
314 $messagetable = << "EOF";
315 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
316 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
317 <tr><td> $message </td></tr></table>
323 # make the issued books table.....
327 my $issueslist = getissues($borrower);
330 foreach my $it (sort keys %$issueslist) {
331 my $dd = $issueslist->{$it}->{'date_due'};
332 my $issuedate = $issueslist->{$it}->{'timestamp'};
333 $issuedate = substr($issuedate, 0, 8);
335 my $bookissue = $issueslist->{$it};
337 my $datedue = $bookissue->{'date_due'};
338 #convert to nz style dates
339 #this should be set with some kinda config variable
340 my @tempdate=split(/-/,$dd);
341 $dd="$tempdate[2]/$tempdate[1]/$tempdate[0]";
343 if ($datedue < $todaysdate) {
344 $dd="<font color=red>$dd</font>\n";
346 if ($todaysdate == $issuedate) {
347 ($tcolor eq $linecolor1) ? ($tcolor=$linecolor2) : ($tcolor=$linecolor1);
348 $todaysissues .=<< "EOF";
349 <tr><td bgcolor=$tcolor align=center>$dd</td>
350 <td bgcolor=$tcolor align=center>
351 <a href=/cgi-bin/koha/detail.pl?bib=$bookissue->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$bookissue->{'barcode'}</a></td>
352 <td bgcolor=$tcolor>$bookissue->{'title'}</td>
353 <td bgcolor=$tcolor>$bookissue->{'author'}</td>
354 <td bgcolor=$tcolor align=center>$bookissue->{'dewey'} $bookissue->{'subclass'}</td></tr>
357 ($pcolor eq $linecolor1) ? ($pcolor=$linecolor2) : ($pcolor=$linecolor1);
358 $previssues .= << "EOF";
359 <tr><td bgcolor=$pcolor align=center>$dd</td>
360 <td bgcolor=$pcolor align=center>
361 <a href=/cgi-bin/koha/detail.pl?bib=$bookissue->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$bookissue->{'barcode'}</a></td>
362 <td bgcolor=$pcolor>$bookissue->{'title'}</td>
363 <td bgcolor=$pcolor>$bookissue->{'author'}</td>
364 <td bgcolor=$pcolor align=center>$bookissue->{'dewey'} $bookissue->{'subclass'}</td></tr>
370 my $issuedbookstable;
372 $issuedbookstable .= <<"EOF";
373 <table border=1 cellpadding=5 cellspacing=0 width=80%>
374 <tr><th colspan=5 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>
375 <b>Todays Issues</b></font></th></tr>
376 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Class</th></tr>
382 $issuedbookstable .= <<"EOF";
383 <table border=1 cellpadding=5 cellspacing=0 width=80%>
384 <tr><th colspan=5 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>
385 <b>Previous Issues</b></font></th></tr>
386 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Class</th></tr>
396 # actually print the page!
399 if ($branchcookie && $printercookie) {
400 print $query->header(-type=>'text/html',-expires=>'now', -cookie=>[$branchcookie,$printercookie]);
402 print $query->header();
406 print startmenu('circulation');
421 if ($borrowerslist) {
422 print $selectborrower;
424 print $cardnumberinput;
431 my ($patrontable, $flaginfotable) = patrontable($borrower);
433 print $flaginfotable;
434 print $barcodeentrytext;
435 print "<p clear=all><br><br>";
436 print $issuedbookstable;
442 print endmenu('circulation');
446 ####################################################################
447 # Extra subroutines,,,
449 sub cuecatbarcodedecode {
452 my @fields = split(/\./,$barcode);
453 my @results = map(decode($_), @fields[1..$#fields]);
462 my ($year, $month, $day) = @_;
465 if (($year eq 0) && ($month eq 0) && ($year eq 0)) {
468 if (($year eq 0) || ($month eq 0) || ($year eq 0)) {
469 $invalidduedate="Invalid Due Date Specified. Book was not issued.<p>\n";
471 if (($day>30) && (($month==4) || ($month==6) || ($month==9) || ($month==11))) {
472 $invalidduedate = "Invalid Due Date Specified. Book was not issued. Only 30 days in $month month.<p>\n";
473 } elsif (($day > 29) && ($month == 2)) {
474 $invalidduedate="Invalid Due Date Specified. Book was not issued. Never that many days in February!<p>\n";
475 } elsif (($month == 2) && ($day > 28) && (($year%4) && ((!($year%100) || ($year%400))))) {
476 $invalidduedate="Invalid Due Date Specified. Book was not issued. $year is not a leap year.<p>\n";
478 $date="$year-$month-$day";
482 return ($date, $invalidduedate);
488 my $flags = $borrower->{'flags'};
489 my $flaginfotable='';
493 foreach $flag (sort keys %$flags) {
494 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
495 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
496 if ($flags->{$flag}->{'noissues'}) {
497 if ($flag eq 'CHARGES') {
498 $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";
500 $flaginfotext.="<tr><td valign=top><font color=red>$flag</font></td><td bgcolor=$color>$flags->{$flag}->{'message'}</td></tr>\n";
503 if ($flag eq 'CHARGES') {
504 $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";
505 } elsif ($flag eq 'WAITING') {
507 my $items=$flags->{$flag}->{'itemlist'};
508 foreach my $item (@$items) {
509 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
510 $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";
512 $flaginfotext.="<tr><td valign=top>$flag</td><td>$itemswaiting</td></tr>\n";
513 } elsif ($flag eq 'ODUES') {
514 my $items=$flags->{$flag}->{'itemlist'};
515 my $itemswaiting="<table border=1 cellspacing=0 cellpadding=2>\n";
516 my $currentcolor=$color;
518 my $color=$currentcolor;
519 foreach my $item (@$items) {
520 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
521 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
522 $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";
525 $itemswaiting.="</table>\n";
526 if ($query->param('module') ne 'returns'){
527 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}, See below</td></tr>\n";
529 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
532 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
536 ($flaginfotext) && ($flaginfotext="<tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2><b>Flags</b></td></tr>$flaginfotext\n");
537 $flaginfotext.="</table>";
538 my $patrontable= << "EOF";
540 <table border=1 cellpadding=5 cellspacing=0 align=right>
541 <tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2><font color=black><b>Patron Information</b></font></td></tr>
543 <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>
545 return($patrontable, $flaginfotext);