3 #written 11/3/2002 by Finlay
4 #script to execute returns of books
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
26 use C4::Circulation::Circ2;
33 my $headerbackgroundcolor='#99cc33';
34 my $circbackgroundcolor='#ffffcc';
35 my $circbackgroundcolor='white';
36 my $linecolor1='#ffffcc';
37 my $linecolor2='white';
38 my $backgroundimage="/images/background-mem.gif";
41 my $branches = getbranches();
42 my $printers = getprinters(\%env);
44 my $branch = $query->param("branch");
45 my $printer = $query->param("printer");
47 ($branch) || ($branch=$query->cookie('branch')) ;
48 ($printer) || ($printer=$query->cookie('printer')) ;
52 # Some code to handle the error if there is no branch or printer setting.....
56 $env{'branchcode'}=$branch;
57 $env{'printer'}=$printer;
58 $env{'queue'}=$printer;
60 # Set up the item stack ....
65 foreach ($query->param) {
66 (next) unless (/ri-(\d*)/);
68 (next) if ($counter>20);
69 my $barcode=$query->param("ri-$counter");
70 my $duedate=$query->param("dd-$counter");
71 my $borrowernumber=$query->param("bn-$counter");
74 $barcode = cuecatbarcodedecode($barcode);
75 $returneditems{$counter}=$barcode;
76 $riduedate{$counter}=$duedate;
77 $riborrowernumber{$counter}=$borrowernumber;
78 $ritext.="<input type=hidden name=ri-$counter value=$barcode>\n";
79 $ritext.="<input type=hidden name=dd-$counter value=$duedate>\n";
80 $ritext.="<input type=hidden name=bn-$counter value=$borrowernumber>\n";
83 # Collect a few messages here...
88 # Deal with the requests....
89 if ($query->param('resbarcode')) {
90 my $item = $query->param('itemnumber');
91 my $borrnum = $query->param('borrowernumber');
92 my $resbarcode = $query->param('resbarcode');
94 my $iteminfo = getiteminformation(\%env, $item);
95 my $tobranchcd = ReserveWaiting($item, $borrnum);
96 my $branchname = $branches->{$tobranchcd}->{'branchname'};
97 my ($borr) = getpatroninformation(\%env, $borrnum, 0);
98 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
99 my $number = "<a href=/cgi-bin/koha/moremember.pl?bornum=$borr->{'borrowernumber'} onClick='openWindow(this,'Member', 480, 640)'>$borr->{'cardnumber'}</a>";
100 my $slip = $query->param('resslip');
101 printslip(\%env, $slip);
102 if ($tobranchcd ne $branch) {
103 # my ($transfered, $messages, $iteminfo) = transferbook($tobranchcd, $resbarcode, 1);
104 $reservetext .= <<"EOF";
105 <font color='red' size='+2'>Item marked Waiting:</font><br>
106 Item: $iteminfo->{'title'} ($iteminfo->{'author'})<br>
107 needs to be transfered to <b>$branchname</b> <br>
108 to be picked up by $name ($number).
109 <center><form method=post action='returns.pl'>
111 <input type=hidden name=barcode value=0>
112 <input type=submit value="OK">
123 my $barcode = $query->param('barcode');
124 # actually return book and prepare item table.....
127 $barcode = cuecatbarcodedecode($barcode);
128 ($returned, $messages, $iteminformation, $borrower) = returnbook($barcode, $branch);
129 $ritext.= "<input type=hidden name=ri-0 value=$barcode>\n";
131 $returneditems{0} = $barcode;
132 $riborrowernumber{0} = $borrower->{'borrowernumber'};
133 $riduedate{0} = $iteminformation->{'date_due'};
134 $ritext.= "<input type=hidden name=dd-0 value=$iteminformation->{'date_due'}>\n";
135 $ritext.= "<input type=hidden name=bn-0 value=$borrower->{'borrowernumber'}>\n";
136 } elsif (! $messages->{'BadBarcode'}) {
137 $returneditems{0} = $barcode;
139 $ritext.= "<input type=hidden name=dd-0 value=0>\n";
140 if ($messages->{'wthdrawn'}) {
141 $ritext.= "<input type=hidden name=bn-0 value='Item Cancelled'>\n";
142 $riborrowernumber{0} = 'Item Cancelled';
144 $ritext.= "<input type=hidden name=bn-0 value=' '>\n";
145 $riborrowernumber{0} = ' ';
150 ##################################################################################
154 <FONT SIZE=6><em>Circulation: Returns</em></FONT><br>
155 <b>Branch:</b> $branches->{$branch}->{'branchname'}  
156 <b>Printer:</b> $printers->{$printer}->{'printername'}<br>
157 <a href=selectbranchprinter.pl>Change Settings</a>
158 <input type=hidden name=branch value=$branch>
159 <input type=hidden name=printer value=$printer>
164 <table align="right"><tr><td>
165 <a href=circulation.pl>
166 <img src="/images/button-issues.gif" width="99" height="42" border="0" alt="Issues"></a>
167  <a href=branchtransfers.pl><img src="/images/button-transfers.gif" width="127" height="42" border="0" alt="Issues"></a>
173 if ($iteminformation) {
174 $itemtable = <<"EOF";
175 <table border=1 cellpadding=5 cellspacing=0>
176 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
177 <font color=black>Returned Item Information</font></th></tr>
179 Title: $iteminformation->{'title'}<br>
180 <!--Hlt decided they dont want these showing, uncoment the html to make it work
182 Author: $iteminformation->{'author'}<br>
183 Barcode: <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}
184 &type=intra onClick="openWindow(this, 'Item', 480, 640)">$iteminformation->{'barcode'}</a><br>
185 Date Due: $iteminformation->{'date_due'}-->
191 # Barcode entry box, with hidden inputs attached....
192 my $barcodeentrytext = << "EOF";
193 <form method=post action=/cgi-bin/koha/circ/returns.pl>
194 <table border=1 cellpadding=5 cellspacing=0>
195 <tr><td colspan=2 bgcolor=$headerbackgroundcolor align=center background=$backgroundimage>
196 <font color=black><b>Enter Book Barcode</b></font></td></tr>
197 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td></tr>
204 if ($messages->{'ResFound'}) {
205 my $res = $messages->{'ResFound'};
206 my $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
207 my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
208 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
209 my $number = "<a href=/cgi-bin/koha/moremember.pl?bornum=$borr->{'borrowernumber'} onClick='openWindow(this,'Member', 480, 640)'>$borr->{'cardnumber'}</a>";
210 my ($iteminfo) = getiteminformation(\%env, 0, $barcode);
212 if ($res->{'ResFound'} eq "Waiting") {
213 $reservetext = <<"EOF";
214 <font color='red' size='+2'>Item marked Waiting:</font><br>
215 Item $iteminfo->{'title'} ($iteminfo->{'author'}) <br>
216 is marked waiting at <b>$branchname</b> for $name ($number).
217 <center><form method=post action='returns.pl'>
219 <input type=hidden name=barcode value=0>
220 <input type=submit value="OK">
224 if ($res->{'ResFound'} eq "Reserved") {
225 my @da = localtime(time());
226 my $todaysdate = sprintf ("%0.2d", ($da[3]+1))."/".sprintf ("%0.2d", ($da[4]+1))."/".($da[5]+1900);
228 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
232 $iteminfo->{'title'} ($iteminfo->{'author'})
233 barcode: $iteminfo->{'barcode'}
234 itemtype: $iteminfo->{'itemtype'}
236 COLLECT AT: $branchname
239 $borr->{'title'} $borr->{'firstname'} $borr->{'surname'}
240 card number: $borr->{'cardnumber'}
241 Phone: $borr->{'phone'}
242 $borr->{'streetaddress'}
245 $borr->{'emailaddress'}
247 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
251 $reservetext = <<"EOF";
252 <font color='red' size='+2'>Reserve found:</font> Item: $iteminfo->{'title'} ($iteminfo->{'author'}) <a href=/cgi-bin/koha/detail.pl?bib=$iteminfo->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$barcode</a> <br>
253 for $name ($number) to be collected at <b>$branchname</b>.
254 <table cellpadding=5 cellspacing=0>
255 <tr><td valign="top">Change status to waiting and print
256 <a href="" onClick='alert(document.forms[0].resslip.value); return false'>slip</a>?: </td>
258 <form method=post action='returns.pl'>
260 <input type=hidden name=itemnumber value=$res->{'itemnumber'}>
261 <input type=hidden name=borrowernumber value=$res->{'borrowernumber'}>
262 <input type=hidden name=resbarcode value=$barcode>
263 <input type=hidden name=resslip value="$slip">
264 <input type=submit value="Print">
271 my $reservefoundtext;
273 $reservefoundtext = <<"EOF";
274 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
275 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Reserve Found</font></th></tr>
276 <tr><td> $reservetext </td></tr></table>
280 # collect the messages and put into message table....
281 foreach my $code (keys %$messages) {
283 if ($code eq 'BadBarcode'){
284 $messagetext .= "<font color='red' size='+2'> No Item with barcode: $messages->{'BadBarcode'} </font> <br>";
286 if ($code eq 'NotIssued'){
287 my $braname = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
288 $messagetext .= "<font color='red' size='+2'> Item not on issue. </font> <br>";
290 if ($code eq 'WasLost'){
291 $messagetext .= "<font color='red' size='+2'> Item was lost, now found. </font> <br>";
293 if ($code eq 'wthdrawn'){
294 $messagetext = "<font color='red' size='+2'> Item Cancelled. </font> <br>";
297 if (($code eq 'IsPermanent') && (not $messages->{'ResFound'})) {
298 if ($messages->{'IsPermanent'} ne $branch) {
299 $messagetext .= "<font color='red' size='+2'> Please return to $branches->{$messages->{'IsPermanent'}}->{'branchname'} </font> <br>";
303 $messagetext = substr($messagetext, 0, -4);
307 $messagetable = << "EOF";
308 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
309 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
310 <tr><td> $messagetext </td></tr></table>
319 $borrowertable = << "EOF";
320 <table border=1 cellpadding=5 cellspacing=0>
321 <tr><td colspan=2 bgcolor=$headerbackgroundcolor background=$backgroundimage>
322 <font color=black><b>Borrower Information</b></font></td></tr>
324 <a href=/cgi-bin/koha/moremember.pl?bornum=$borrower->{'borrowernumber'}
325 onClick="openWindow(this,'Member', 480, 640)">$borrower->{'cardnumber'}</a>
326 $borrower->{'surname'}, $borrower->{'title'} $borrower->{'firstname'}<br>
329 my $flags = $borrower->{'flags'};
332 foreach my $flag (sort keys %$flags) {
333 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
334 if ($flags->{$flag}->{'noissues'}) {
335 $flag = "<font color=red>$flag</font>";
337 if ($flag eq 'CHARGES') {
338 $flaginfotext.= <<"EOF";
339 <tr><td valign=top>$flag</td>
340 <td bgcolor=$color><b>$flags->{$flag}->{'message'}</b>
341 <a href=/cgi-bin/koha/pay.pl?bornum=$borrower->{'borrowernumber'}
342 onClick="openWindow(this, 'Payment', 480,640)">Payment</a></td></tr>
344 } elsif ($flag eq 'WAITING') {
346 my $items = $flags->{$flag}->{'itemlist'};
347 foreach my $item (@$items) {
348 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
349 $itemswaiting .= <<"EOF";
350 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra
351 onClick="openWindow(this, 'Item', 480, 640)">$iteminformation->{'barcode'}</a>
352 $iteminformation->{'title'}
353 ($branches->{$iteminformation->{'holdingbranch'}}->{'branchname'})<br>
356 $flaginfotext.="<tr><td valign=top>$flag</td><td>$itemswaiting</td></tr>\n";
357 } elsif ($flag eq 'ODUES') {
358 my $itemsoverdue = '';
359 my $items = $flags->{$flag}->{'itemlist'};
360 foreach my $item (sort {$a->{'date_due'} cmp $b->{'date_due'}} @$items) {
361 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
362 $itemsoverdue .= <<"EOF";
363 <font color=red>$item->{'date_due'}</font>
364 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra
365 onClick="openWindow(this, 'Item', 480, 640)">$iteminformation->{'barcode'}</a>
366 $iteminformation->{'title'}
370 $flaginfotext .= "<tr><td valign=top>$flag</td><td>$itemsoverdue</td></tr>\n";
372 $flaginfotext.= <<"EOF";
373 <tr><td valign=top>$flag</td>
374 <td bgcolor=$color>$flags->{$flag}->{'message'}</td></tr>
379 $borrowertable .= << "EOF";
380 <tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2>
381 <b>Flags</b></td></tr>
385 $borrowertable .= "</table>";
388 # the returned items.....
389 my $returneditemstable = << "EOF";
390 <table border=1 cellpadding=5 cellspacing=0>
391 <tr><th colspan=6 bgcolor=$headerbackgroundcolor background=$backgroundimage>
392 <font color=black>Returned Items</font></th></tr>
393 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Type</th><th>Borrower</th></tr>
397 #set up so only the lat 8 returned items display (make for faster loading pages)
399 foreach (sort {$a <=> $b} keys %returneditems) {
401 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
402 my $barcode = $returneditems{$_};
403 my $duedate = $riduedate{$_};
407 my @tempdate = split ( /-/ , $duedate ) ;
408 my $duedatenz = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
409 my @datearr = localtime(time());
410 my $todaysdate = (1900+$datearr[5]).'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
411 $overduetext = "$duedatenz";
412 ($overduetext="<font color=red>$duedate</font>") if ($duedate lt $todaysdate);
413 ($duedatenz) || ($overduetext = "<img src=/images/blackdot.gif>");
414 my ($borrower) = getpatroninformation(\%env, $riborrowernumber{$_}, 0);
415 $borrowerinfo = "<a href=/cgi-bin/koha/moremember.pl?bornum=$borrower->{'borrowernumber'} onClick=\"openWindow(this,'Member', 480, 640)\">$borrower->{'cardnumber'}</a> $borrower->{'firstname'} $borrower->{'surname'}";
417 $overduetext = "Not on Issue.";
418 $borrowerinfo = $riborrowernumber{$_};
420 my ($iteminformation) = getiteminformation(\%env, 0, $barcode);;
421 $returneditemstable .= << "EOF";
422 <tr><td bgcolor=$color>$overduetext</td>
423 <td bgcolor=$color align=center>
424 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$barcode</a></td>
425 <td bgcolor=$color>$iteminformation->{'title'}</td>
426 <td bgcolor=$color>$iteminformation->{'author'}</td>
427 <td bgcolor=$color align=center>$iteminformation->{'itemtype'}</td>
429 $borrowerinfo</td></tr>
436 $returneditemstable .= "</table>\n";
439 # actually print the page!
440 print $query->header();
442 print startmenu('circulation');
446 # foreach my $key (keys %$messages) {
447 # print "$key : $messages->{$key}<br>";
456 <table cellpadding=5 cellspacing=0 width=100%>
459 if ($reservefoundtext) {
462 <td colspan=2>$reservefoundtext</td>
465 <td colspan=2>$messagetable</td>
472 <td valign=top align=left>$barcodeentrytext</td>
473 <td valign=top align=left>$messagetable</td>
480 <td valign=top align=left>$itemtable</td>
481 <td valign=top align=left>$borrowertable</td>
485 if (%returneditems) {
486 print "<tr><td colspan=2>$returneditemstable</td></tr>";
491 print endmenu('circulation');
494 sub cuecatbarcodedecode {
497 my @fields = split(/\./,$barcode);
498 my @results = map(decode($_), @fields[1..$#fields]);