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);
110 $returneditems{0} = $barcode;
111 $riborrowernumber{0} = $borrower->{'borrowernumber'};
112 $riduedate{0} = $iteminformation->{'date_due'};
113 $ritext.= "<input type=hidden name=ri-0 value=$barcode>\n";
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";
119 ##################################################################################
123 <FONT SIZE=6><em>Circulation: Returns</em></FONT><br>
124 <b>Branch:</b> $branches->{$branch}->{'branchname'}  
125 <b>Printer:</b> $printers->{$printer}->{'printername'}<br>
126 <a href=selectbranchprinter.pl>Change Settings</a>
127 <input type=hidden name=branch value=$branch>
128 <input type=hidden name=printer value=$printer>
133 <table align="right"><tr><td>
134 <a href=circulation.pl>
135 <img src="/images/button-issues.gif" width="99" height="42" border="0" alt="Issues"></a>
136  <a href=branchtransfers.pl>
137 <img src="/images/button-transfers.gif" width="127" height="42" border="0" alt="Issues"></a>
143 if ($iteminformation) {
144 $itemtable = <<"EOF";
145 <table border=1 cellpadding=5 cellspacing=0>
146 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
147 <font color=black>Returned Item Information</font></th></tr>
149 Title: $iteminformation->{'title'}<br>
150 <!--Hlt decided they dont want these showing, uncoment the html to make it work
152 Author: $iteminformation->{'author'}<br>
153 Barcode: <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}
154 &type=intra onClick="openWindow(this, 'Item', 480, 640)">$iteminformation->{'barcode'}</a><br>
155 Date Due: $iteminformation->{'date_due'}-->
161 # Barcode entry box, with hidden inputs attached....
162 my $barcodeentrytext = << "EOF";
163 <form method=post action=/cgi-bin/koha/circ/returns.pl>
164 <table border=1 cellpadding=5 cellspacing=0>
165 <tr><td colspan=2 bgcolor=$headerbackgroundcolor align=center background=$backgroundimage>
166 <font color=black><b>Enter Book Barcode</b></font></td></tr>
167 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td></tr>
174 if ($messages->{'ResFound'}) {
175 my $res = $messages->{'ResFound'};
176 my $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
177 my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
178 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
179 my $number = "<a href=/cgi-bin/koha/moremember.pl?bornum=$borr->{'borrowernumber'} onClick='openWindow(this,'Member', 480, 640)'>$borr->{'cardnumber'}</a>";
180 my ($iteminfo) = getiteminformation(\%env, 0, $barcode);
182 if ($res->{'ResFound'} eq "Waiting") {
183 $reservetext = <<"EOF";
184 <font color='red' size='+2'>Item marked Waiting:</font><br>
185 Item $iteminfo->{'title'} ($iteminfo->{'author'}) <br>
186 is marked waiting at <b>$branchname</b> for $name ($number).
187 <center><form method=post action='returns.pl'>
189 <input type=hidden name=barcode value=0>
190 <input type=submit value="OK">
194 if ($res->{'ResFound'} eq "Reserved") {
195 my @da = localtime(time());
196 my $todaysdate = sprintf ("%0.2d", ($da[3]+1))."/".sprintf ("%0.2d", ($da[4]+1))."/".($da[5]+1900);
198 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
202 $iteminfo->{'title'} ($iteminfo->{'author'})
203 barcode: $iteminfo->{'barcode'}
204 itemtype: $iteminfo->{'itemtype'}
206 COLLECT AT: $branchname
209 $borr->{'surname'}, $borr->{'firstname'}
210 card number: $borr->{'cardnumber'}
211 Phone: $borr->{'phone'}
212 $borr->{'streetaddress'}
215 $borr->{'emailaddress'}
217 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
220 $reservetext = <<"EOF";
221 <font color='red' size='+2'>Reserved found:</font> Item: $iteminfo->{'title'} ($iteminfo->{'author'}) <br>
223 <table cellpadding=5 cellspacing=0>
224 <tr><td valign="top">Change status to waiting and print
225 <a href="" onClick='alert(document.forms[0].resslip.value); return false'>slip</a>?: </td>
227 <form method=post action='returns.pl'>
229 <input type=hidden name=itemnumber value=$res->{'itemnumber'}>
230 <input type=hidden name=borrowernumber value=$res->{'borrowernumber'}>
231 <input type=hidden name=resbarcode value=$barcode>
232 <input type=hidden name=resslip value="$slip">
233 <input type=submit value="Print">
240 my $reservefoundtext;
242 $reservefoundtext = <<"EOF";
243 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
244 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Reserve Found</font></th></tr>
245 <tr><td> $reservetext </td></tr></table>
249 # collect the messages and put into message table....
250 foreach my $code (keys %$messages) {
251 if ($code eq 'BadBarcode'){
252 $messagetext .= "<font color='red' size='+2'> No Item with barcode: $messages->{'BadBarcode'} </font> <br>";
254 if ($code eq 'NotIssued'){
255 my $braname = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
256 $messagetext .= "<font color='red' size='+2'> Item not on issue. </font> <br>";
258 if ($code eq 'WasLost'){
259 $messagetext .= "<font color='red' size='+2'> Item was lost, now found. </font> <br>";
261 if (($code eq 'IsPermanent') && (not $messages->{'ResFound'})) {
262 if ($messages->{'IsPermanent'} ne $branch) {
263 $messagetext .= "<font color='red' size='+2'> Please return to $branches->{$messages->{'IsPermanent'}}->{'branchname'} </font> <br>";
267 $messagetext = substr($messagetext, 0, -4);
271 $messagetable = << "EOF";
272 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
273 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
274 <tr><td> $messagetext </td></tr></table>
283 $borrowertable = << "EOF";
284 <table border=1 cellpadding=5 cellspacing=0>
285 <tr><td colspan=2 bgcolor=$headerbackgroundcolor background=$backgroundimage>
286 <font color=black><b>Borrower Information</b></font></td></tr>
288 <a href=/cgi-bin/koha/moremember.pl?bornum=$borrower->{'borrowernumber'}
289 onClick="openWindow(this,'Member', 480, 640)">$borrower->{'cardnumber'}</a>
290 $borrower->{'surname'}, $borrower->{'title'} $borrower->{'firstname'}<br>
293 my $flags = $borrower->{'flags'};
296 foreach my $flag (sort keys %$flags) {
297 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
298 if ($flags->{$flag}->{'noissues'}) {
299 $flag = "<font color=red>$flag</font>";
301 if ($flag eq 'CHARGES') {
302 $flaginfotext.= <<"EOF";
303 <tr><td valign=top>$flag</td>
304 <td bgcolor=$color><b>$flags->{$flag}->{'message'}</b>
305 <a href=/cgi-bin/koha/pay.pl?bornum=$borrower->{'borrowernumber'}
306 onClick="openWindow(this, 'Payment', 480,640)">Payment</a></td></tr>
308 } elsif ($flag eq 'WAITING') {
310 my $items = $flags->{$flag}->{'itemlist'};
311 foreach my $item (@$items) {
312 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
313 $itemswaiting .= <<"EOF";
314 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra
315 onClick="openWindow(this, 'Item', 480, 640)">$iteminformation->{'barcode'}</a>
316 $iteminformation->{'title'}
317 ($branches->{$iteminformation->{'holdingbranch'}}->{'branchname'})<br>
320 $flaginfotext.="<tr><td valign=top>$flag</td><td>$itemswaiting</td></tr>\n";
321 } elsif ($flag eq 'ODUES') {
322 my $itemsoverdue = '';
323 my $items = $flags->{$flag}->{'itemlist'};
324 foreach my $item (sort {$a->{'date_due'} cmp $b->{'date_due'}} @$items) {
325 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
326 $itemsoverdue .= <<"EOF";
327 <font color=red>$item->{'date_due'}</font>
328 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra
329 onClick="openWindow(this, 'Item', 480, 640)">$iteminformation->{'barcode'}</a>
330 $iteminformation->{'title'}
334 $flaginfotext .= "<tr><td valign=top>$flag</td><td>$itemsoverdue</td></tr>\n";
336 $flaginfotext.= <<"EOF";
337 <tr><td valign=top>$flag</td>
338 <td bgcolor=$color>$flags->{$flag}->{'message'}</td></tr>
343 $borrowertable .= << "EOF";
344 <tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2>
345 <b>Flags</b></td></tr>
352 # the returned items.....
353 my $returneditemstable = << "EOF";
354 <table border=1 cellpadding=5 cellspacing=0>
355 <tr><th colspan=6 bgcolor=$headerbackgroundcolor background=$backgroundimage>
356 <font color=black>Returned Items</font></th></tr>
357 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Type</th><th>Borrower</th></tr>
361 #set up so only the lat 8 returned items display (make for faster loading pages)
363 foreach (sort {$a <=> $b} keys %returneditems) {
365 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
366 my $barcode = $returneditems{$_};
367 my $duedate = $riduedate{$_};
368 my @datearr = localtime(time());
370 # convert to nz date format
371 my @tempdate = split(/-/,$duedate);
372 my $duedatenz = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
375 = (1900+$datearr[5]).'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
376 my $overduetext = "$duedatenz";
377 ($overduetext="<font color=red>$duedate</font>") if ($duedate lt $todaysdate);
378 ($duedatenz) || ($overduetext = "<img src=/images/blackdot.gif>");
379 my $borrowernumber = $riborrowernumber{$_};
380 my ($borrower) = getpatroninformation(\%env,$borrowernumber,0);
381 my ($iteminformation) = getiteminformation(\%env, 0, $barcode);;
382 $returneditemstable .= << "EOF";
383 <tr><td bgcolor=$color>$overduetext</td>
384 <td bgcolor=$color align=center>
385 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$barcode</a></td>
386 <td bgcolor=$color>$iteminformation->{'title'}</td>
387 <td bgcolor=$color>$iteminformation->{'author'}</td>
388 <td bgcolor=$color align=center>$iteminformation->{'itemtype'}</td>
390 <a href=/cgi-bin/koha/moremember.pl?bornum=$borrower->{'borrowernumber'} onClick=\"openWindow(this,'Member', 480, 640)\">$borrower->{'cardnumber'}</a> $borrower->{'firstname'} $borrower->{'surname'}</td></tr>
397 $returneditemstable .= "</table>\n";
400 # actually print the page!
401 print $query->header();
403 print startmenu('circulation');
408 <table cellpadding=5 cellspacing=0 width=100%>
411 if ($reservefoundtext) {
414 <td colspan=2>$reservefoundtext</td>
417 <td colspan=2>$messagetable</td>
424 <td valign=top align=left>$barcodeentrytext</td>
425 <td valign=top align=left>$messagetable</td>
432 <td valign=top align=left>$itemtable</td>
433 <td valign=top align=left>$borrowertable</td>
437 if (%returneditems) {
438 print "<tr><td colspan=2>$returneditemstable</td></tr>";
443 print endmenu('circulation');
446 sub cuecatbarcodedecode {
449 my @fields = split(/\./,$barcode);
450 my @results = map(decode($_), @fields[1..$#fields]);