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')) ;
35 unless ($query->cookie('branch')) {
36 $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
38 unless ($query->cookie('printer')) {
39 $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
42 $env{'branchcode'}=$branch;
43 $env{'printer'}=$printer;
44 $env{'queue'}=$printer;
46 my @datearr = localtime(time());
47 my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", $datearr[3]);
53 # if there is a list of find borrowers....
54 my $findborrower = $query->param('findborrower');
56 my ($borrowers, $flags) = findborrower(\%env, $findborrower);
57 my @borrowers=@$borrowers;
58 if ($#borrowers == -1) {
59 $query->param('findborrower', '');
60 $message = "No borrower matched '$findborrower'";
61 } elsif ($#borrowers == 0) {
62 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
63 $query->param('barcode','');
65 $borrowerslist = \@borrowers;
69 my $borrowernumber = $query->param('borrnumber');
71 # get the currently issued books......
74 if ($borrowernumber) {
75 ($borrower, $flags) = getpatroninformation(\%env,$borrowernumber,0);
78 # get the responses to any questions.....
80 foreach (sort $query->param) {
81 if ($_ =~ /response-(\d*)/) {
82 $responses{$1} = $query->param($_);
85 if (my $qnumber = $query->param('questionnumber')) {
86 $responses{$qnumber} = $query->param('answer');
90 # if the barcode is set
91 my $barcode = $query->param('barcode');
92 my ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer);
94 my $year=$query->param('year');
95 my $month=$query->param('month');
96 my $day=$query->param('day');
100 $barcode = cuecatbarcodedecode($barcode);
101 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
103 unless ($invalidduedate) {
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=6>Error Issuing Book</font></th></tr>
123 <tr><td><font color=red size=6>$rejected</font></td></tr>
131 if ($borrowerslist) {
132 $selectborrower = <<"EOF";
133 <form method=get action=/cgi-bin/koha/circ/issues.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";
157 <table border=0 cellpadding=5 width=90%><tr>
158 <td align="left"><FONT SIZE=6><em>Circulation: Issues</em></FONT><br>
159 <b>Branch:</b> $branches->{$branch}->{'branchname'}  
160 <b>Printer:</b> $printers->{$printer}->{'printername'} <br>
161 <a href=selectbranchprinter.pl>Change Settings</a></td>
162 <td align="right" valign="top">
163 <FONT SIZE=2 face="arial, helvetica">
164 <a href=circulation.pl>Next Borrower</a> ||
165 <a href=returns.pl>Returns</a> ||
166 <a href=branchtransfers.pl>Transfers</a></font><p>
168 <input type=hidden name=branch value=$branch>
169 <input type=hidden name=printer value=$printer>
175 my $cardnumberinput = << "EOF";
176 <form method=get action=/cgi-bin/koha/circ/issues.pl>
177 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
178 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
179 <font color=black><b>Enter borrower card number<br> or partial last name</b></font></td></tr>
180 <tr><td><input name=findborrower></td></tr>
182 <input type=hidden name=branch value=$branch>
183 <input type=hidden name=printer value=$printer>
187 my $responsesform = '';
188 foreach (keys %responses) {
189 $responsesform.="<input type=hidden name=response-$_ value=$responses{$_}>\n";
193 my $stickyduedate=$query->param('stickyduedate');
194 $questionform = <<"EOF";
195 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
196 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
197 <font color=black><b>Issuing Question</b></font></th></tr>
198 <tr><td><table border=0 cellpadding=10><tr><td>
199 Attempting to issue $iteminformation->{'title'}
200 by $iteminformation->{'author'} to $borrower->{'firstname'} $borrower->{'surname'}.
203 </td></tr></table></td></tr>
204 <tr><td align=center>
208 <input type=hidden name=borrnumber value=$borrowernumber>
209 <input type=hidden name=barcode value=$barcode>
210 <input type=hidden name=questionnumber value=$questionnumber>
211 <input type=hidden name=day value=$day>
212 <input type=hidden name=month value=$month>
213 <input type=hidden name=year value=$year>
214 <input type=hidden name=stickyduedate value=$stickyduedate>
215 <input type=hidden name=branch value=$branch>
216 <input type=hidden name=printer value=$printer>
218 <input type=hidden name=answer value=Y>
219 <input type=submit value=Yes>
224 <input type=hidden name=borrnumber value=$borrowernumber>
225 <input type=hidden name=barcode value=$barcode>
226 <input type=hidden name=questionnumber value=$questionnumber>
227 <input type=hidden name=day value=$day>
228 <input type=hidden name=month value=$month>
229 <input type=hidden name=year value=$year>
230 <input type=hidden name=stickyduedate value=$stickyduedate>
231 <input type=hidden name=branch value=$branch>
232 <input type=hidden name=printer value=$printer>
234 <input type=hidden name=answer value=N>
235 <input type=submit value=No>
248 # Barcode entry box, with hidden inputs attached....
251 my $monthoptions = '';
252 my $yearoptions = '';
253 for (my $i=1; $i<32; $i++) {
255 if (($query->param('stickyduedate')) && ($day==$i)) {
256 $selected='selected';
258 $dayoptions.="<option value=$i $selected>$i";
260 foreach (('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')) {
262 if (($query->param('stickyduedate')) && ($month==$counter)) {
263 $selected='selected';
265 $monthoptions.="<option value=$counter $selected>$_";
268 for (my $i=$datearr[5]+1900; $i<$datearr[5]+1905; $i++) {
270 if (($query->param('stickyduedate')) && ($year==$i)) {
271 $selected='selected';
273 $yearoptions.="<option value=$i $selected>$i";
276 ($query->param('stickyduedate')) && ($selected='checked');
279 my $barcodeentrytext = <<"EOF";
280 <form method=post action=/cgi-bin/koha/circ/issues.pl>
281 <table border=1 cellpadding=5>
283 <td align=center valign=top>
284 <table border=0 cellspacing=0 cellpadding=5>
285 <tr><th align=center background=$backgroundimage>
286 <font color=black><b>Enter Book Barcode</b></font></th></tr>
287 <tr><td align=center>
289 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td><td><input type=submit value=Issue></td></tr>
290 <tr><td colspan=3 align=center>
291 <table border=0 cellpadding=0 cellspacing=0>
293 <select name=day><option value=0>Day$dayoptions</select>
295 <select name=month><option value=0>Month$monthoptions</select>
297 <select name=year><option value=0>Year$yearoptions</select>
300 <input type=checkbox name=stickyduedate $selected> Sticky Due Date
303 <input type=hidden name=borrnumber value=$borrowernumber>
304 <input type=hidden name=branch value=$branch>
305 <input type=hidden name=printer value=$printer>
312 # collect the messages and put into message table....
315 $messagetable = << "EOF";
316 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
317 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
318 <tr><td> $message </td></tr></table>
324 # make the issued books table.....
329 my $issueslist = getissues($borrower);
332 foreach my $it (sort keys %$issueslist) {
333 my $dd = $issueslist->{$it}->{'date_due'};
334 my $issuedate = $issueslist->{$it}->{'timestamp'};
335 $issuedate = substr($issuedate, 0, 8);
337 my $bookissue = $issueslist->{$it};
339 my $datedue = $bookissue->{'date_due'};
340 #convert to nz style dates
341 #this should be set with some kinda config variable
342 my @tempdate=split(/-/,$dd);
343 $dd="$tempdate[2]/$tempdate[1]/$tempdate[0]";
345 if ($datedue < $todaysdate) {
346 $dd="<font color=red>$dd</font>\n";
348 if ($todaysdate == $issuedate) {
349 ($tcolor eq $linecolor1) ? ($tcolor=$linecolor2) : ($tcolor=$linecolor1);
350 $todaysissues .=<< "EOF";
351 <tr><td bgcolor=$tcolor align=center>$dd</td>
352 <td bgcolor=$tcolor align=center>
353 <a href=/cgi-bin/koha/detail.pl?bib=$bookissue->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$bookissue->{'barcode'}</a></td>
354 <td bgcolor=$tcolor>$bookissue->{'title'}</td>
355 <td bgcolor=$tcolor>$bookissue->{'author'}</td>
356 <td bgcolor=$tcolor align=center>$bookissue->{'dewey'} $bookissue->{'subclass'}</td></tr>
359 ($pcolor eq $linecolor1) ? ($pcolor=$linecolor2) : ($pcolor=$linecolor1);
360 $previssues .= << "EOF";
361 <tr><td bgcolor=$pcolor align=center>$dd</td>
362 <td bgcolor=$pcolor align=center>
363 <a href=/cgi-bin/koha/detail.pl?bib=$bookissue->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$bookissue->{'barcode'}</a></td>
364 <td bgcolor=$pcolor>$bookissue->{'title'}</td>
365 <td bgcolor=$pcolor>$bookissue->{'author'}</td>
366 <td bgcolor=$pcolor align=center>$bookissue->{'dewey'} $bookissue->{'subclass'}</td></tr>
372 my $issuedbookstable;
374 $issuedbookstable .= <<"EOF";
375 <table border=1 cellpadding=5 cellspacing=0 width=80%>
376 <tr><th colspan=5 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>
377 <b>Todays Issues</b></font></th></tr>
378 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Class</th></tr>
384 $issuedbookstable .= <<"EOF";
385 <table border=1 cellpadding=5 cellspacing=0 width=80%>
386 <tr><th colspan=5 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>
387 <b>Previous Issues</b></font></th></tr>
388 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Class</th></tr>
398 # actually print the page!
401 if ($branchcookie && $printercookie) {
402 print $query->header(-type=>'text/html',-expires=>'now', -cookie=>[$branchcookie,$printercookie]);
404 print $query->header();
408 print startmenu('circulation');
423 if ($borrowerslist) {
424 print $selectborrower;
426 print $cardnumberinput;
433 my ($patrontable, $flaginfotable) = patrontable($borrower);
435 print $flaginfotable;
436 print $barcodeentrytext;
437 print "<p clear=all>";
438 print $issuedbookstable;
444 print endmenu('circulation');
448 ####################################################################
449 # Extra subroutines,,,
451 sub cuecatbarcodedecode {
454 my @fields = split(/\./,$barcode);
455 my @results = map(decode($_), @fields[1..$#fields]);
464 my ($year, $month, $day) = @_;
467 if (($year eq 0) && ($month eq 0) && ($year eq 0)) {
470 if (($year eq 0) || ($month eq 0) || ($year eq 0)) {
471 $invalidduedate="Invalid Due Date Specified. Book was not issued.<p>\n";
473 if (($day>30) && (($month==4) || ($month==6) || ($month==9) || ($month==11))) {
474 $invalidduedate = "Invalid Due Date Specified. Book was not issued. Only 30 days in $month month.<p>\n";
475 } elsif (($day > 29) && ($month == 2)) {
476 $invalidduedate="Invalid Due Date Specified. Book was not issued. Never that many days in February!<p>\n";
477 } elsif (($month == 2) && ($day > 28) && (($year%4) && ((!($year%100) || ($year%400))))) {
478 $invalidduedate="Invalid Due Date Specified. Book was not issued. $year is not a leap year.<p>\n";
480 $date="$year-$month-$day";
484 return ($date, $invalidduedate);
490 my $flags = $borrower->{'flags'};
491 my $flaginfotable='';
495 foreach $flag (sort keys %$flags) {
496 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
497 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
498 if ($flags->{$flag}->{'noissues'}) {
499 if ($flag eq 'CHARGES') {
500 $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";
502 $flaginfotext.="<tr><td valign=top><font color=red>$flag</font></td><td bgcolor=$color>$flags->{$flag}->{'message'}</td></tr>\n";
505 if ($flag eq 'CHARGES') {
506 $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";
507 } elsif ($flag eq 'WAITING') {
509 my $items=$flags->{$flag}->{'itemlist'};
510 foreach my $item (@$items) {
511 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
512 $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";
514 $flaginfotext.="<tr><td valign=top>$flag</td><td>$itemswaiting</td></tr>\n";
515 } elsif ($flag eq 'ODUES') {
516 my $items=$flags->{$flag}->{'itemlist'};
517 my $itemswaiting="<table border=1 cellspacing=0 cellpadding=2>\n";
518 my $currentcolor=$color;
520 my $color=$currentcolor;
521 foreach my $item (@$items) {
522 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
523 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
524 $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";
527 $itemswaiting.="</table>\n";
528 if ($query->param('module') ne 'returns'){
529 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}, See below</td></tr>\n";
531 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
534 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
538 ($flaginfotext) && ($flaginfotext="<tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2><b>Flags</b></td></tr>$flaginfotext\n");
539 $flaginfotext.="</table>";
540 my $patrontable= << "EOF";
542 <table border=1 cellpadding=5 cellspacing=0 align=right>
543 <tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2><font color=black><b>Patron Information</b></font></td></tr>
545 <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>
547 return($patrontable, $flaginfotext);