3 #written 11/3/2002 by Finlay
4 #script to execute returns 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";
22 my $branches = getbranches();
23 my $printers = getprinters(\%env);
25 my $branch = $query->param("branch");
26 my $printer = $query->param("printer");
28 ($branch) || ($branch=$query->cookie('branch')) ;
29 ($printer) || ($printer=$query->cookie('printer')) ;
31 my $request=$query->param('request');
35 # Some code to handle the error if there is no branch or printer setting.....
39 $env{'branchcode'}=$branch;
40 $env{'printer'}=$printer;
41 $env{'queue'}=$printer;
43 # Set up the item stack ....
48 foreach ($query->param) {
49 (next) unless (/ri-(\d*)/);
51 (next) if ($counter>20);
52 my $barcode=$query->param("ri-$counter");
53 my $duedate=$query->param("dd-$counter");
54 my $borrowernumber=$query->param("bn-$counter");
57 $barcode = cuecatbarcodedecode($barcode);
58 $returneditems{$counter}=$barcode;
59 $riduedate{$counter}=$duedate;
60 $riborrowernumber{$counter}=$borrowernumber;
61 $ritext.="<input type=hidden name=ri-$counter value=$barcode>\n";
62 $ritext.="<input type=hidden name=dd-$counter value=$duedate>\n";
63 $ritext.="<input type=hidden name=bn-$counter value=$borrowernumber>\n";
66 # Collect a few messages here...
70 # Deal with the requests....
71 if ($request eq "KillWaiting") {
72 my $item = $query->param('itemnumber');
73 my $borrnum = $query->param('borrowernumber');
74 CancelReserve(0, $item, $borrnum);
75 $messagetext .= "Reserve Cancelled<br>";
77 if ($request eq "SetWaiting") {
78 my $item = $query->param('itemnumber');
79 my $borrnum = $query->param('borrowernumber');
80 my $barcode2 = $query->param('barcode2');
81 my $tobranchcd = ReserveWaiting($item, $borrnum);
82 my ($transfered, $messages, $iteminfo) = transferbook($tobranchcd, $barcode2, 1);
83 $messagetext .= "Item should now be waiting at branch: <b>$branches->{$tobranchcd}->{'branchname'}</b><br>";
85 if ($request eq 'KillReserved'){
86 my $biblio = $query->param('biblionumber');
87 my $borrnum = $query->param('borrowernumber');
88 CancelReserve($biblio, 0, $borrnum);
89 $messagetext .= "Reserve Cancelled<br>";
98 my $barcode = $query->param('barcode');
99 # actually return book (SQL CALL) and prepare item table.....
102 $barcode = cuecatbarcodedecode($barcode);
103 ($returned, $messages, $iteminformation, $borrower) = returnbook($barcode, $branch);
105 $returneditems{0} = $barcode;
106 $riborrowernumber{0} = $borrower->{'borrowernumber'};
107 $riduedate{0} = $iteminformation->{'date_due'};
108 $ritext.= "<input type=hidden name=ri-0 value=$barcode>\n";
109 $ritext.= "<input type=hidden name=dd-0 value=$iteminformation->{'date_due'}>\n";
110 $ritext.= "<input type=hidden name=bn-0 value=$borrower->{'borrowernumber'}>\n";
114 ##################################################################################
119 <table border=0 cellpadding=5 width=90%><tr>
120 <td align="left"><FONT SIZE=6><em>Circulation: Returns</em></FONT><br>
121 <b>Branch:</b> $branches->{$branch}->{'branchname'}  
122 <b>Printer:</b> $printers->{$printer}->{'printername'}<br>
123 <a href=selectbranchprinter.pl>Change Settings</a>
125 <td align="right" valign="top">
126 <FONT SIZE=2 face="arial, helvetica">
127 <a href=circulation.pl>Next Borrower</a> ||
128 <a href=returns.pl>Returns</a> ||
129 <a href=branchtransfers.pl>Transfers</a></font><p>
131 <input type=hidden name=branch value=$branch>
132 <input type=hidden name=printer value=$printer>
137 if ($iteminformation) {
138 $itemtable = <<"EOF";
139 <table border=1 cellpadding=5 cellspacing=0>
140 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
141 <font color=black>Returned Item Information</font></th></tr>
143 Title: $iteminformation->{'title'}<br>
144 <!--Hlt decided they dont want these showing, uncoment the html to make it work
146 Author: $iteminformation->{'author'}<br>
147 Barcode: <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}
148 &type=intra onClick="openWindow(this, 'Item', 480, 640)">$iteminformation->{'barcode'}</a><br>
149 Date Due: $iteminformation->{'date_due'}-->
156 # Barcode entry box, with hidden inputs attached....
157 my $barcodeentrytext = << "EOF";
158 <form method=post action=/cgi-bin/koha/circ/returns.pl>
159 <table border=1 cellpadding=5 cellspacing=0 align=left>
160 <tr><td colspan=2 bgcolor=$headerbackgroundcolor align=center background=$backgroundimage>
161 <font color=black><b>Enter Book Barcode</b></font></td></tr>
162 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td></tr>
166 <img src="/images/holder.gif" width=24 height=50 align=left>
170 my $reservefoundtext;
171 if ($messages->{'ResFound'}) {
172 my $res = $messages->{'ResFound'};
174 my $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
175 my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
176 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
177 my $number = "<a href=/cgi-bin/koha/moremember.pl?bornum=$borr->{'borrowernumber'} onClick='openWindow(this,'Member', 480, 640)'>$borr->{'cardnumber'}</a>";
178 if ($res->{'ResFound'} eq "Waiting") {
179 $reservetext = <<"EOF";
180 <font color='red' size='+2'>Item marked Waiting:</font><br>
181 Item is marked waiting at <b>$branchname</b> for $name ($number).<br>
182 <table border=1 cellpadding=5 cellspacing=0>
183 <tr><td>Cancel reservation: </td>
185 <form method=post action='returns.pl'>
187 <input type=hidden name=itemnumber value=$res->{'itemnumber'}>
188 <input type=hidden name=borrowernumber value=$res->{'borrowernumber'}>
189 <input type=hidden name=request value='KillWaiting'>
190 <input type=hidden name=barcode value=0>
191 <input type=submit value="Cancel">
194 <tr><td>Back to returns: </td>
196 <form method=post action='returns.pl'>
198 <input type=hidden name=barcode value=0>
199 <input type=submit value="OK">
204 if ($res->{'ResFound'} eq "Reserved") {
205 $reservetext = <<"EOF";
206 <font color='red' size='+2'>Reserved:</font> reserve found for $name ($number).
207 <table border=1 cellpadding=5 cellspacing=0>
208 <tr><td>Set reserve to waiting and transfer book to <b>$branchname </b>: </td>
210 <form method=post action='returns.pl'>
212 <input type=hidden name=itemnumber value=$res->{'itemnumber'}>
213 <input type=hidden name=borrowernumber value=$res->{'borrowernumber'}>
214 <input type=hidden name=barcode2 value=$barcode>
215 <input type=hidden name=request value='SetWaiting'>
216 <input type=submit value="Waiting">
219 <tr><td>Cancel reservation: </td>
221 <form method=post action='returns.pl'>
223 <input type=hidden name=biblionumber value=$res->{'biblionumber'}>
224 <input type=hidden name=borrowernumber value=$res->{'borrowernumber'}>
225 <input type=hidden name=barcode value=0>
226 <input type=hidden name=request value='KillReserved'>
227 <input type=submit value="Cancel">
229 </td></tr><tr><td>Back to returns: </td>
231 <form method=post action='returns.pl'>
232 <input type=hidden name=barcode value=0>
234 <input type=submit value="OK">
239 $reservefoundtext = <<"EOF";
240 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
241 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Reserve Found</font></th></tr>
242 <tr><td> $reservetext </td></tr></table>
243 <img src="/images/holder.gif" width=24 height=24>
247 # collect the messages and put into message table....
248 foreach my $code (keys %$messages) {
249 if ($code eq 'BadBarcode'){
250 $messagetext .= "<font color='red' size='+2'> No Item with barcode: $messages->{'BadBarcode'} </font> <br>";
252 if ($code eq 'NotIssued'){
253 my $braname = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
254 $messagetext .= "<font color='red' size='+2'> Item is not Issued, cannot be returned. </font> <br>";
256 if ($code eq 'WasLost'){
257 $messagetext .= "<font color='red' size='+2'> Item was lost, now found. </font> <br>";
259 if (($code eq 'IsPermanent') && (not $messages->{'ResFound'})) {
260 if ($messages->{'IsPermanent'} ne $branch) {
261 $messagetext .= "<font color='red' size='+2'> Item is part of permanent collection, please return to $branches->{$messages->{'IsPermanent'}}->{'branchname'} </font> <br>";
265 $messagetext = substr($messagetext, 0, -4);
269 $messagetable = << "EOF";
270 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
271 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
272 <tr><td> $messagetext </td></tr></table>
280 my $patrontable = << "EOF";
281 <table border=1 cellpadding=5 cellspacing=0 align=right>
282 <tr><td colspan=2 bgcolor=$headerbackgroundcolor background=$backgroundimage>
283 <font color=black><b>Patron Information</b></font></td></tr>
285 <a href=/cgi-bin/koha/moremember.pl?bornum=$borrower->{'borrowernumber'}
286 onClick="openWindow(this,'Member', 480, 640)">$borrower->{'cardnumber'}</a>
287 $borrower->{'surname'}, $borrower->{'title'} $borrower->{'firstname'}<br>
290 my $flags = $borrower->{'flags'};
294 foreach $flag (sort keys %$flags) {
295 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
296 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
297 if ($flags->{$flag}->{'noissues'}) {
298 if ($flag eq 'CHARGES') {
299 $flaginfotext.= <<"EOF";
300 <tr><td valign=top><font color=red>$flag</font></td>
301 <td bgcolor=$color><b>$flags->{$flag}->{'message'}</b>
302 <a href=/cgi-bin/koha/pay.pl?bornum=$borrower->{'borrowernumber'}
303 onClick=\"openWindow(this, 'Payment', 480,640)\">Payment</a></td></tr>
306 $flaginfotext.= <<"EOF";
307 <tr><td valign=top><font color=red>$flag</font></td>
308 <td bgcolor=$color>$flags->{$flag}->{'message'}</td></tr>
312 if ($flag eq 'CHARGES') {
313 $flaginfotext .= << "EOF";
314 <tr><td valign=top>$flag</td>
315 <td> $flags->{$flag}->{'message'} <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'} ($branches->{$iteminformation->{'holdingbranch'}}->{'branchname'})<br>
329 $flaginfotext.="<tr><td valign=top>$flag</td><td>$itemswaiting</td></tr>\n";
330 } elsif ($flag eq 'ODUES') {
331 my $items = $flags->{$flag}->{'itemlist'};
332 $flaginfotext .= <<"EOF";
333 <tr><td bgcolor=$color><font color=red>$flag</font></td>
334 <td bgcolor=$color>Patron has Overdue books</td></tr>
337 $flaginfotext .= "<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
342 $flaginfotext = << "EOF";
343 <table border=1 cellpadding=5 cellspacing=0> <tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2><b>Flags</b></td></tr>
348 $borrowertable = << "EOF";
349 <table border=0 cellpadding=5>
351 <td valign=top>$patrontable</td>
352 <td valign=top>$flaginfotext</td>
358 # the returned items.....
359 my $returneditemstable = << "EOF";
361 <table border=1 cellpadding=5 cellspacing=0 align=left>
362 <tr><th colspan=6 bgcolor=$headerbackgroundcolor background=$backgroundimage>
363 <font color=black>Returned Items</font></th></tr>
364 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Type</th><th>Borrower</th></tr>
368 #set up so only the lat 8 returned items display (make for faster loading pages)
370 foreach (sort {$a <=> $b} keys %returneditems) {
372 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
373 my $barcode = $returneditems{$_};
374 my $duedate = $riduedate{$_};
375 my @datearr = localtime(time());
377 # convert to nz date format
378 my @tempdate = split(/-/,$duedate);
379 $duedate = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
382 = (1900+$datearr[5]).'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
383 my $overduetext = "$duedate";
384 ($overduetext="<font color=red>$duedate</font>") if ($duedate lt $todaysdate);
385 ($duedate) || ($overduetext = "<img src=/images/blackdot.gif>");
386 my $borrowernumber = $riborrowernumber{$_};
387 my ($borrower) = getpatroninformation(\%env,$borrowernumber,0);
388 my ($iteminformation) = getiteminformation(\%env, 0, $barcode);;
389 $returneditemstable .= << "EOF";
390 <tr><td bgcolor=$color>$overduetext</td>
391 <td bgcolor=$color align=center>
392 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$barcode</a></td>
393 <td bgcolor=$color>$iteminformation->{'title'}</td>
394 <td bgcolor=$color>$iteminformation->{'author'}</td>
395 <td bgcolor=$color align=center>$iteminformation->{'itemtype'}</td>
397 <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>
404 $returneditemstable .= "</table>\n";
407 # actually print the page!
408 print $query->header();
410 print startmenu('circulation');
414 if ($reservefoundtext) {
415 print $reservefoundtext;
417 print $barcodeentrytext;
424 print $borrowertable;
426 (print $returneditemstable) if (%returneditems);
428 print endmenu('circulation');
431 sub cuecatbarcodedecode {
434 my @fields = split(/\./,$barcode);
435 my @results = map(decode($_), @fields[1..$#fields]);