3 #written 11/3/2002 by Finlay
4 #script to execute returns of books
8 use C4::Circulation::Circ2;
15 my $headerbackgroundcolor='#99cc33';
16 my $circbackgroundcolor='#ffffcc';
17 my $circbackgroundcolor='white';
18 my $linecolor1='#ffffcc';
19 my $linecolor2='white';
20 my $backgroundimage="/images/background-mem.gif";
23 my $branches = getbranches();
24 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')) ;
34 # Some code to handle the error if there is no branch or printer setting.....
38 $env{'branchcode'}=$branch;
39 $env{'printer'}=$printer;
40 $env{'queue'}=$printer;
42 # Set up the item stack ....
47 foreach ($query->param) {
48 (next) unless (/ri-(\d*)/);
50 (next) if ($counter>20);
51 my $barcode=$query->param("ri-$counter");
52 my $duedate=$query->param("dd-$counter");
53 my $borrowernumber=$query->param("bn-$counter");
56 $barcode = cuecatbarcodedecode($barcode);
57 $returneditems{$counter}=$barcode;
58 $riduedate{$counter}=$duedate;
59 $riborrowernumber{$counter}=$borrowernumber;
60 $ritext.="<input type=hidden name=ri-$counter value=$barcode>\n";
61 $ritext.="<input type=hidden name=dd-$counter value=$duedate>\n";
62 $ritext.="<input type=hidden name=bn-$counter value=$borrowernumber>\n";
65 # Collect a few messages here...
70 # Deal with the requests....
71 if ($query->param('resbarcode')) {
72 my $item = $query->param('itemnumber');
73 my $borrnum = $query->param('borrowernumber');
74 my $resbarcode = $query->param('resbarcode');
75 my $tobranchcd = ReserveWaiting($item, $borrnum);
76 my $branchname = $branches->{$tobranchcd}->{'branchname'};
77 my ($borr) = getpatroninformation(\%env, $borrnum, 0);
78 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
79 my $number = "<a href=/cgi-bin/koha/moremember.pl?bornum=$borr->{'borrowernumber'} onClick='openWindow(this,'Member', 480, 640)'>$borr->{'cardnumber'}</a>";
80 my $slip = $query->param('resslip');
81 printslip(\%env, $slip);
82 if ($tobranchcd ne $branch) {
83 my ($transfered, $messages, $iteminfo) = transferbook($tobranchcd, $resbarcode, 1);
84 $reservetext .= <<"EOF";
85 <font color='red' size='+2'>Item marked Waiting:</font><br>
86 Item: $iteminfo->{'title'} ($iteminfo->{'author'})<br>
87 needs to be transfered to <b>$branchname</b> <br>
88 to be picked up by $name ($number).
89 <center><form method=post action='returns.pl'>
91 <input type=hidden name=barcode value=0>
92 <input type=submit value="OK">
103 my $barcode = $query->param('barcode');
104 # actually return book and prepare item table.....
107 $barcode = cuecatbarcodedecode($barcode);
108 ($returned, $messages, $iteminformation, $borrower) = returnbook($barcode, $branch);
109 $returneditems{0} = $barcode;
110 $ritext.= "<input type=hidden name=ri-0 value=$barcode>\n";
112 $riborrowernumber{0} = $borrower->{'borrowernumber'};
113 $riduedate{0} = $iteminformation->{'date_due'};
114 $ritext.= "<input type=hidden name=dd-0 value=$iteminformation->{'date_due'}>\n";
115 $ritext.= "<input type=hidden name=bn-0 value=$borrower->{'borrowernumber'}>\n";
117 $riborrowernumber{0} = 0;
119 $ritext.= "<input type=hidden name=dd-0 value=0>\n";
120 $ritext.= "<input type=hidden name=bn-0 value=0>\n";
124 ##################################################################################
128 <FONT SIZE=6><em>Circulation: Returns</em></FONT><br>
129 <b>Branch:</b> $branches->{$branch}->{'branchname'}  
130 <b>Printer:</b> $printers->{$printer}->{'printername'}<br>
131 <a href=selectbranchprinter.pl>Change Settings</a>
132 <input type=hidden name=branch value=$branch>
133 <input type=hidden name=printer value=$printer>
138 <table align="right"><tr><td>
139 <a href=circulation.pl>
140 <img src="/images/button-issues.gif" width="99" height="42" border="0" alt="Issues"></a>
141  <a href=branchtransfers.pl>
142 <img src="/images/button-transfers.gif" width="127" height="42" border="0" alt="Issues"></a>
148 if ($iteminformation) {
149 $itemtable = <<"EOF";
150 <table border=1 cellpadding=5 cellspacing=0>
151 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
152 <font color=black>Returned Item Information</font></th></tr>
154 Title: $iteminformation->{'title'}<br>
155 <!--Hlt decided they dont want these showing, uncoment the html to make it work
157 Author: $iteminformation->{'author'}<br>
158 Barcode: <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}
159 &type=intra onClick="openWindow(this, 'Item', 480, 640)">$iteminformation->{'barcode'}</a><br>
160 Date Due: $iteminformation->{'date_due'}-->
166 # Barcode entry box, with hidden inputs attached....
167 my $barcodeentrytext = << "EOF";
168 <form method=post action=/cgi-bin/koha/circ/returns.pl>
169 <table border=1 cellpadding=5 cellspacing=0>
170 <tr><td colspan=2 bgcolor=$headerbackgroundcolor align=center background=$backgroundimage>
171 <font color=black><b>Enter Book Barcode</b></font></td></tr>
172 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td></tr>
179 if ($messages->{'ResFound'}) {
180 my $res = $messages->{'ResFound'};
181 my $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
182 my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
183 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
184 my $number = "<a href=/cgi-bin/koha/moremember.pl?bornum=$borr->{'borrowernumber'} onClick='openWindow(this,'Member', 480, 640)'>$borr->{'cardnumber'}</a>";
185 my ($iteminfo) = getiteminformation(\%env, 0, $barcode);
187 if ($res->{'ResFound'} eq "Waiting") {
188 $reservetext = <<"EOF";
189 <font color='red' size='+2'>Item marked Waiting:</font><br>
190 Item $iteminfo->{'title'} ($iteminfo->{'author'}) <br>
191 is marked waiting at <b>$branchname</b> for $name ($number).
192 <center><form method=post action='returns.pl'>
194 <input type=hidden name=barcode value=0>
195 <input type=submit value="OK">
199 if ($res->{'ResFound'} eq "Reserved") {
200 my @da = localtime(time());
201 my $todaysdate = sprintf ("%0.2d", ($da[3]+1))."/".sprintf ("%0.2d", ($da[4]+1))."/".($da[5]+1900);
203 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
207 $iteminfo->{'title'} ($iteminfo->{'author'})
208 barcode: $iteminfo->{'barcode'}
209 itemtype: $iteminfo->{'itemtype'}
211 COLLECT AT: $branchname
214 $borr->{'title'} $borr->{'surname'}, $borr->{'firstname'}
215 card number: $borr->{'cardnumber'}
216 Phone: $borr->{'phone'}
217 $borr->{'streetaddress'}
220 $borr->{'emailaddress'}
222 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
226 $reservetext = <<"EOF";
227 <font color='red' size='+2'>Reserve found:</font> Item: $iteminfo->{'title'} ($iteminfo->{'author'}) <br>
228 for $name ($number) to be collected at <b>$branchname</b>.
229 <table cellpadding=5 cellspacing=0>
230 <tr><td valign="top">Change status to waiting and print
231 <a href="" onClick='alert(document.forms[0].resslip.value); return false'>slip</a>?: </td>
233 <form method=post action='returns.pl'>
235 <input type=hidden name=itemnumber value=$res->{'itemnumber'}>
236 <input type=hidden name=borrowernumber value=$res->{'borrowernumber'}>
237 <input type=hidden name=resbarcode value=$barcode>
238 <input type=hidden name=resslip value="$slip">
239 <input type=submit value="Print">
246 my $reservefoundtext;
248 $reservefoundtext = <<"EOF";
249 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
250 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Reserve Found</font></th></tr>
251 <tr><td> $reservetext </td></tr></table>
255 # collect the messages and put into message table....
256 foreach my $code (keys %$messages) {
258 if ($code eq 'BadBarcode'){
259 $messagetext .= "<font color='red' size='+2'> No Item with barcode: $messages->{'BadBarcode'} </font> <br>";
261 if ($code eq 'NotIssued'){
262 my $braname = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
263 $messagetext .= "<font color='red' size='+2'> Item not on issue. </font> <br>";
265 if ($code eq 'WasLost'){
266 $messagetext .= "<font color='red' size='+2'> Item was lost, now found. </font> <br>";
268 if ($code eq 'wthdrawm'){
269 $messagetext .= "<font color='red' size='+2'> Item Cancelled. </font> <br>";
271 if (($code eq 'IsPermanent') && (not $messages->{'ResFound'})) {
272 if ($messages->{'IsPermanent'} ne $branch) {
273 $messagetext .= "<font color='red' size='+2'> Please return to $branches->{$messages->{'IsPermanent'}}->{'branchname'} </font> <br>";
277 $messagetext = substr($messagetext, 0, -4);
281 $messagetable = << "EOF";
282 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
283 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
284 <tr><td> $messagetext </td></tr></table>
293 $borrowertable = << "EOF";
294 <table border=1 cellpadding=5 cellspacing=0>
295 <tr><td colspan=2 bgcolor=$headerbackgroundcolor background=$backgroundimage>
296 <font color=black><b>Borrower Information</b></font></td></tr>
298 <a href=/cgi-bin/koha/moremember.pl?bornum=$borrower->{'borrowernumber'}
299 onClick="openWindow(this,'Member', 480, 640)">$borrower->{'cardnumber'}</a>
300 $borrower->{'surname'}, $borrower->{'title'} $borrower->{'firstname'}<br>
303 my $flags = $borrower->{'flags'};
306 foreach my $flag (sort keys %$flags) {
307 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
308 if ($flags->{$flag}->{'noissues'}) {
309 $flag = "<font color=red>$flag</font>";
311 if ($flag eq 'CHARGES') {
312 $flaginfotext.= <<"EOF";
313 <tr><td valign=top>$flag</td>
314 <td bgcolor=$color><b>$flags->{$flag}->{'message'}</b>
315 <a href=/cgi-bin/koha/pay.pl?bornum=$borrower->{'borrowernumber'}
316 onClick="openWindow(this, 'Payment', 480,640)">Payment</a></td></tr>
318 } elsif ($flag eq 'WAITING') {
320 my $items = $flags->{$flag}->{'itemlist'};
321 foreach my $item (@$items) {
322 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
323 $itemswaiting .= <<"EOF";
324 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra
325 onClick="openWindow(this, 'Item', 480, 640)">$iteminformation->{'barcode'}</a>
326 $iteminformation->{'title'}
327 ($branches->{$iteminformation->{'holdingbranch'}}->{'branchname'})<br>
330 $flaginfotext.="<tr><td valign=top>$flag</td><td>$itemswaiting</td></tr>\n";
331 } elsif ($flag eq 'ODUES') {
332 my $itemsoverdue = '';
333 my $items = $flags->{$flag}->{'itemlist'};
334 foreach my $item (sort {$a->{'date_due'} cmp $b->{'date_due'}} @$items) {
335 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
336 $itemsoverdue .= <<"EOF";
337 <font color=red>$item->{'date_due'}</font>
338 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra
339 onClick="openWindow(this, 'Item', 480, 640)">$iteminformation->{'barcode'}</a>
340 $iteminformation->{'title'}
344 $flaginfotext .= "<tr><td valign=top>$flag</td><td>$itemsoverdue</td></tr>\n";
346 $flaginfotext.= <<"EOF";
347 <tr><td valign=top>$flag</td>
348 <td bgcolor=$color>$flags->{$flag}->{'message'}</td></tr>
353 $borrowertable .= << "EOF";
354 <tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2>
355 <b>Flags</b></td></tr>
359 $borrowertable .= "</table>";
362 # the returned items.....
363 my $returneditemstable = << "EOF";
364 <table border=1 cellpadding=5 cellspacing=0>
365 <tr><th colspan=6 bgcolor=$headerbackgroundcolor background=$backgroundimage>
366 <font color=black>Returned Items</font></th></tr>
367 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Type</th><th>Borrower</th></tr>
371 #set up so only the lat 8 returned items display (make for faster loading pages)
373 foreach (sort {$a <=> $b} keys %returneditems) {
375 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
376 my $barcode = $returneditems{$_};
377 my $duedate = $riduedate{$_};
380 my @tempdate = split ( /-/ , $duedate ) ;
381 my $duedatenz = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
382 my @datearr = localtime(time());
383 my $todaysdate = (1900+$datearr[5]).'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
384 $overduetext = "$duedatenz";
385 ($overduetext="<font color=red>$duedate</font>") if ($duedate lt $todaysdate);
386 ($duedatenz) || ($overduetext = "<img src=/images/blackdot.gif>");
388 $overduetext = "Not on loan.";
390 my $borrowernumber = $riborrowernumber{$_};
392 if ($borrowernumber) {
393 my ($borrower) = getpatroninformation(\%env,$borrowernumber,0);
394 my $borrowerinfo = "<a href=/cgi-bin/koha/moremember.pl?bornum=$borrower->{'borrowernumber'} onClick=\"openWindow(this,'Member', 480, 640)\">$borrower->{'cardnumber'}</a> $borrower->{'firstname'} $borrower->{'surname'}";
396 $borrowerinfo = "Not on loan.";
398 my ($iteminformation) = getiteminformation(\%env, 0, $barcode);;
399 $returneditemstable .= << "EOF";
400 <tr><td bgcolor=$color>$overduetext</td>
401 <td bgcolor=$color align=center>
402 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$barcode</a></td>
403 <td bgcolor=$color>$iteminformation->{'title'}</td>
404 <td bgcolor=$color>$iteminformation->{'author'}</td>
405 <td bgcolor=$color align=center>$iteminformation->{'itemtype'}</td>
407 $borrowerinfo</td></tr>
414 $returneditemstable .= "</table>\n";
417 # actually print the page!
418 print $query->header();
420 print startmenu('circulation');
425 <table cellpadding=5 cellspacing=0 width=100%>
428 if ($reservefoundtext) {
431 <td colspan=2>$reservefoundtext</td>
434 <td colspan=2>$messagetable</td>
441 <td valign=top align=left>$barcodeentrytext</td>
442 <td valign=top align=left>$messagetable</td>
449 <td valign=top align=left>$itemtable</td>
450 <td valign=top align=left>$borrowertable</td>
454 if (%returneditems) {
455 print "<tr><td colspan=2>$returneditemstable</td></tr>";
460 print endmenu('circulation');
463 sub cuecatbarcodedecode {
466 my @fields = split(/\./,$barcode);
467 my @results = map(decode($_), @fields[1..$#fields]);