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');
93 my $tobranchcd = ReserveWaiting
($item, $borrnum);
94 my $branchname = $branches->{$tobranchcd}->{'branchname'};
95 my ($borr) = getpatroninformation
(\
%env, $borrnum, 0);
96 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
97 my $number = "<a href=/cgi-bin/koha/moremember.pl?bornum=$borr->{'borrowernumber'} onClick='openWindow(this,'Member', 480, 640)'>$borr->{'cardnumber'}</a>";
98 my $slip = $query->param('resslip');
99 printslip
(\
%env, $slip);
100 if ($tobranchcd ne $branch) {
101 my ($transfered, $messages, $iteminfo) = transferbook
($tobranchcd, $resbarcode, 1);
102 $reservetext .= <<"EOF";
103 <font color='red' size='+2'>Item marked Waiting:</font><br>
104 Item: $iteminfo->{'title'} ($iteminfo->{'author'})<br>
105 needs to be transfered to <b>$branchname</b> <br>
106 to be picked up by $name ($number).
107 <center><form method=post action='returns.pl'>
109 <input type=hidden name=barcode value=0>
110 <input type=submit value="OK">
121 my $barcode = $query->param('barcode');
122 # actually return book and prepare item table.....
125 $barcode = cuecatbarcodedecode
($barcode);
126 ($returned, $messages, $iteminformation, $borrower) = returnbook
($barcode, $branch);
127 $returneditems{0} = $barcode;
128 $ritext.= "<input type=hidden name=ri-0 value=$barcode>\n";
130 $riborrowernumber{0} = $borrower->{'borrowernumber'};
131 $riduedate{0} = $iteminformation->{'date_due'};
132 $ritext.= "<input type=hidden name=dd-0 value=$iteminformation->{'date_due'}>\n";
133 $ritext.= "<input type=hidden name=bn-0 value=$borrower->{'borrowernumber'}>\n";
135 $riborrowernumber{0} = 0;
137 $ritext.= "<input type=hidden name=dd-0 value=0>\n";
138 $ritext.= "<input type=hidden name=bn-0 value=0>\n";
142 ##################################################################################
146 <FONT SIZE=6><em>Circulation: Returns</em></FONT><br>
147 <b>Branch:</b> $branches->{$branch}->{'branchname'}  
148 <b>Printer:</b> $printers->{$printer}->{'printername'}<br>
149 <a href=selectbranchprinter.pl>Change Settings</a>
150 <input type=hidden name=branch value=$branch>
151 <input type=hidden name=printer value=$printer>
156 <table align="right"><tr><td>
157 <a href=circulation.pl>
158 <img src="/images/button-issues.gif" width="99" height="42" border="0" alt="Issues"></a>
159  <a href=branchtransfers.pl><img src="/images/button-transfers.gif" width="127" height="42" border="0" alt="Issues"></a>
165 if ($iteminformation) {
166 $itemtable = <<"EOF";
167 <table border=1 cellpadding=5 cellspacing=0>
168 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
169 <font color=black>Returned Item Information</font></th></tr>
171 Title: $iteminformation->{'title'}<br>
172 <!--Hlt decided they dont want these showing, uncoment the html to make it work
174 Author: $iteminformation->{'author'}<br>
175 Barcode: <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}
176 &type=intra onClick="openWindow(this, 'Item', 480, 640)">$iteminformation->{'barcode'}</a><br>
177 Date Due: $iteminformation->{'date_due'}-->
183 # Barcode entry box, with hidden inputs attached....
184 my $barcodeentrytext = << "EOF";
185 <form method
=post action
=/cgi-bin/koha
/circ/returns
.pl
>
186 <table border
=1 cellpadding
=5 cellspacing
=0>
187 <tr
><td colspan
=2 bgcolor
=$headerbackgroundcolor align
=center background
=$backgroundimage>
188 <font color
=black
><b
>Enter Book Barcode
</b></font
></td></tr
>
189 <tr
><td
>Item Barcode
:</td><td><input name=barcode size=10></td
></tr
>
196 if ($messages->{'ResFound'}) {
197 my $res = $messages->{'ResFound'};
198 my $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
199 my ($borr) = getpatroninformation
(\
%env, $res->{'borrowernumber'}, 0);
200 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
201 my $number = "<a href=/cgi-bin/koha/moremember.pl?bornum=$borr->{'borrowernumber'} onClick='openWindow(this,'Member', 480, 640)'>$borr->{'cardnumber'}</a>";
202 my ($iteminfo) = getiteminformation
(\
%env, 0, $barcode);
204 if ($res->{'ResFound'} eq "Waiting") {
205 $reservetext = <<"EOF";
206 <font color='red' size='+2'>Item marked Waiting:</font><br>
207 Item $iteminfo->{'title'} ($iteminfo->{'author'}) <br>
208 is marked waiting at <b>$branchname</b> for $name ($number).
209 <center><form method=post action='returns.pl'>
211 <input type=hidden name=barcode value=0>
212 <input type=submit value="OK">
216 if ($res->{'ResFound'} eq "Reserved") {
217 my @da = localtime(time());
218 my $todaysdate = sprintf ("%0.2d", ($da[3]+1))."/".sprintf ("%0.2d", ($da[4]+1))."/".($da[5]+1900);
220 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
224 $iteminfo->{'title'} ($iteminfo->{'author'})
225 barcode: $iteminfo->{'barcode'}
226 itemtype: $iteminfo->{'itemtype'}
228 COLLECT AT: $branchname
231 $borr->{'title'} $borr->{'surname'}, $borr->{'firstname'}
232 card number: $borr->{'cardnumber'}
233 Phone: $borr->{'phone'}
234 $borr->{'streetaddress'}
237 $borr->{'emailaddress'}
239 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
243 $reservetext = <<"EOF";
244 <font color='red' size='+2'>Reserve found:</font> Item: $iteminfo->{'title'} ($iteminfo->{'author'}) <br>
245 for $name ($number) to be collected at <b>$branchname</b>.
246 <table cellpadding=5 cellspacing=0>
247 <tr><td valign="top">Change status to waiting and print
248 <a href="" onClick='alert(document.forms[0].resslip.value); return false'>slip</a>?: </td>
250 <form method=post action='returns.pl'>
252 <input type=hidden name=itemnumber value=$res->{'itemnumber'}>
253 <input type=hidden name=borrowernumber value=$res->{'borrowernumber'}>
254 <input type=hidden name=resbarcode value=$barcode>
255 <input type=hidden name=resslip value="$slip">
256 <input type=submit value="Print">
263 my $reservefoundtext;
265 $reservefoundtext = <<"EOF";
266 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
267 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Reserve Found</font></th></tr>
268 <tr><td> $reservetext </td></tr></table>
272 # collect the messages and put into message table....
273 foreach my $code (keys %$messages) {
275 if ($code eq 'BadBarcode'){
276 $messagetext .= "<font color='red' size='+2'> No Item with barcode: $messages->{'BadBarcode'} </font> <br>";
278 if ($code eq 'NotIssued'){
279 my $braname = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
280 $messagetext .= "<font color='red' size='+2'> Item not on issue. </font> <br>";
282 if ($code eq 'WasLost'){
283 $messagetext .= "<font color='red' size='+2'> Item was lost, now found. </font> <br>";
285 if ($code eq 'wthdrawm'){
286 $messagetext .= "<font color='red' size='+2'> Item Cancelled. </font> <br>";
288 if (($code eq 'IsPermanent') && (not $messages->{'ResFound'})) {
289 if ($messages->{'IsPermanent'} ne $branch) {
290 $messagetext .= "<font color='red' size='+2'> Please return to $branches->{$messages->{'IsPermanent'}}->{'branchname'} </font> <br>";
294 $messagetext = substr($messagetext, 0, -4);
298 $messagetable = << "EOF";
299 <table border
=1 cellpadding
=5 cellspacing
=0 bgcolor
='#dddddd'>
300 <tr
><th bgcolor
=$headerbackgroundcolor background
=$backgroundimage><font
>Messages
</font></th
></tr
>
301 <tr
><td
> $messagetext </td></tr
></table
>
310 $borrowertable = << "EOF";
311 <table border
=1 cellpadding
=5 cellspacing
=0>
312 <tr
><td colspan
=2 bgcolor
=$headerbackgroundcolor background
=$backgroundimage>
313 <font color
=black
><b
>Borrower Information
</b></font
></td></tr
>
315 <a href
=/cgi-bin/koha
/moremember
.pl?bornum
=$borrower->{'borrowernumber'}
316 onClick
="openWindow(this,'Member', 480, 640)">$borrower->{'cardnumber'}</a
>
317 $borrower->{'surname'}, $borrower->{'title'} $borrower->{'firstname'}<br
>
320 my $flags = $borrower->{'flags'};
323 foreach my $flag (sort keys %$flags) {
324 ($color eq $linecolor1) ?
($color=$linecolor2) : ($color=$linecolor1);
325 if ($flags->{$flag}->{'noissues'}) {
326 $flag = "<font color=red>$flag</font>";
328 if ($flag eq 'CHARGES') {
329 $flaginfotext.= <<"EOF";
330 <tr><td valign=top>$flag</td>
331 <td bgcolor=$color><b>$flags->{$flag}->{'message'}</b>
332 <a href=/cgi-bin/koha/pay.pl?bornum=$borrower->{'borrowernumber'}
333 onClick="openWindow(this, 'Payment', 480,640)">Payment</a></td></tr>
335 } elsif ($flag eq 'WAITING') {
337 my $items = $flags->{$flag}->{'itemlist'};
338 foreach my $item (@
$items) {
339 my ($iteminformation) = getiteminformation
(\
%env, $item->{'itemnumber'}, 0);
340 $itemswaiting .= <<"EOF";
341 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra
342 onClick="openWindow(this, 'Item', 480, 640)">$iteminformation->{'barcode'}</a>
343 $iteminformation->{'title'}
344 ($branches->{$iteminformation->{'holdingbranch'}}->{'branchname'})<br>
347 $flaginfotext.="<tr><td valign=top>$flag</td><td>$itemswaiting</td></tr>\n";
348 } elsif ($flag eq 'ODUES') {
349 my $itemsoverdue = '';
350 my $items = $flags->{$flag}->{'itemlist'};
351 foreach my $item (sort {$a->{'date_due'} cmp $b->{'date_due'}} @
$items) {
352 my ($iteminformation) = getiteminformation
(\
%env, $item->{'itemnumber'}, 0);
353 $itemsoverdue .= <<"EOF";
354 <font color=red>$item->{'date_due'}</font>
355 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra
356 onClick="openWindow(this, 'Item', 480, 640)">$iteminformation->{'barcode'}</a>
357 $iteminformation->{'title'}
361 $flaginfotext .= "<tr><td valign=top>$flag</td><td>$itemsoverdue</td></tr>\n";
363 $flaginfotext.= <<"EOF";
364 <tr><td valign=top>$flag</td>
365 <td bgcolor=$color>$flags->{$flag}->{'message'}</td></tr>
370 $borrowertable .= << "EOF";
371 <tr
><td bgcolor
=$headerbackgroundcolor background
=$backgroundimage colspan
=2>
372 <b
>Flags
</b></td
></tr
>
376 $borrowertable .= "</table>";
379 # the returned items.....
380 my $returneditemstable = << "EOF";
381 <table border
=1 cellpadding
=5 cellspacing
=0>
382 <tr
><th colspan
=6 bgcolor
=$headerbackgroundcolor background
=$backgroundimage>
383 <font color
=black
>Returned Items
</font></th
></tr
>
384 <tr
><th
>Due Date
</th><th>Bar Code</th
><th
>Title
</th><th>Author</th
><th
>Type
</th><th>Borrower</th
></tr
>
388 #set up so only the lat 8 returned items display (make for faster loading pages)
390 foreach (sort {$a <=> $b} keys %returneditems) {
392 ($color eq $linecolor1) ?
($color=$linecolor2) : ($color=$linecolor1);
393 my $barcode = $returneditems{$_};
394 my $duedate = $riduedate{$_};
397 my @tempdate = split ( /-/ , $duedate ) ;
398 my $duedatenz = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
399 my @datearr = localtime(time());
400 my $todaysdate = (1900+$datearr[5]).'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
401 $overduetext = "$duedatenz";
402 ($overduetext="<font color=red>$duedate</font>") if ($duedate lt $todaysdate);
403 ($duedatenz) || ($overduetext = "<img src=/images/blackdot.gif>");
405 $overduetext = "Not on loan.";
407 my $borrowernumber = $riborrowernumber{$_};
409 if ($borrowernumber) {
410 my ($borrower) = getpatroninformation
(\
%env,$borrowernumber,0);
411 $borrowerinfo = "<a href=/cgi-bin/koha/moremember.pl?bornum=$borrower->{'borrowernumber'} onClick=\"openWindow(this,'Member', 480, 640)\">$borrower->{'cardnumber'}</a> $borrower->{'firstname'} $borrower->{'surname'}";
413 $borrowerinfo = "Not on loan.";
415 my ($iteminformation) = getiteminformation
(\
%env, 0, $barcode);;
416 $returneditemstable .= << "EOF";
417 <tr
><td bgcolor
=$color>$overduetext</td
>
418 <td bgcolor
=$color align
=center
>
419 <a href
=/cgi-bin/koha
/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$barcode</a></td
>
420 <td bgcolor
=$color>$iteminformation->{'title'}</td
>
421 <td bgcolor
=$color>$iteminformation->{'author'}</td
>
422 <td bgcolor
=$color align
=center
>$iteminformation->{'itemtype'}</td
>
424 $borrowerinfo</td></tr
>
431 $returneditemstable .= "</table>\n";
434 # actually print the page!
435 print $query->header();
437 print startmenu
('circulation');
442 <table cellpadding=5 cellspacing=0 width=100%>
445 if ($reservefoundtext) {
448 <td colspan=2>$reservefoundtext</td>
451 <td colspan=2>$messagetable</td>
458 <td valign=top align=left>$barcodeentrytext</td>
459 <td valign=top align=left>$messagetable</td>
466 <td valign=top align=left>$itemtable</td>
467 <td valign=top align=left>$borrowertable</td>
471 if (%returneditems) {
472 print "<tr><td colspan=2>$returneditemstable</td></tr>";
477 print endmenu
('circulation');
480 sub cuecatbarcodedecode
{
483 my @fields = split(/\./,$barcode);
484 my @results = map(decode
($_), @fields[1..$#fields]);