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')) ;
34 # Some code to handle the error if there is no branch or printer setting.....
37 $env{'branchcode'}=$branch;
38 $env{'printer'}=$printer;
39 $env{'queue'}=$printer;
41 # Set up the item stack ....
46 foreach ($query->param) {
47 (next) unless (/ri-(\d*)/);
49 (next) if ($counter>20);
50 my $barcode=$query->param("ri-$counter");
51 my $duedate=$query->param("dd-$counter");
52 my $borrowernumber=$query->param("bn-$counter");
55 $barcode = cuecatbarcodedecode($barcode);
56 $returneditems{$counter}=$barcode;
57 $riduedate{$counter}=$duedate;
58 $riborrowernumber{$counter}=$borrowernumber;
59 $ritext.="<input type=hidden name=ri-$counter value=$barcode>\n";
60 $ritext.="<input type=hidden name=dd-$counter value=$duedate>\n";
61 $ritext.="<input type=hidden name=bn-$counter value=$borrowernumber>\n";
68 # actually return book (SQL CALL) and prepare item table.....
69 if (my $barcode = $query->param('barcode')) {
71 $barcode = cuecatbarcodedecode($barcode);
72 ($returned, $messages, $iteminformation, $borrower) = returnbook($barcode, $branch);
74 $returneditems{0} = $barcode;
75 $riborrowernumber{0} = $borrower->{'borrowernumber'};
76 $riduedate{0} = $iteminformation->{'date_due'};
77 $ritext.= "<input type=hidden name=ri-0 value=$barcode>\n";
78 $ritext.= "<input type=hidden name=dd-0 value=$iteminformation->{'date_due'}>\n";
79 $ritext.= "<input type=hidden name=bn-0 value=$borrower->{'borrowernumber'}>\n";
83 ##################################################################################
88 <table border=0 cellpadding=5 width=90%><tr>
89 <td align="left"><FONT SIZE=6><em>Circulation: Returns</em></FONT><br>
90 <b>Branch:</b> $branches->{$branch}->{'branchname'}  
91 <b>Printer:</b> $printers->{$printer}->{'printername'}<br>
92 <a href=selectbranchprinter.pl>Change Settings</a>
95 <FONT SIZE=2 face="arial, helvetica">
96 <a href=circulation.pl>Next Borrower</a> ||
97 <a href=returns.pl>Returns</a> ||
98 <a href=branchtransfers.pl>Transfers</a></font><p>
100 <input type=hidden name=branch value=$branch>
101 <input type=hidden name=printer value=$printer>
106 if ($iteminformation) {
107 $itemtable = <<"EOF";
108 <table border=1 cellpadding=5 cellspacing=0>
109 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
110 <font color=black>Returned Item Information</font></th></tr>
112 Title: $iteminformation->{'title'}<br>
113 <!--Hlt decided they dont want these showing, uncoment the html to make it work
115 Author: $iteminformation->{'author'}<br>
116 Barcode: <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}
117 &type=intra onClick="openWindow(this, 'Item', 480, 640)">$iteminformation->{'barcode'}</a><br>
118 Date Due: $iteminformation->{'date_due'}-->
125 # Barcode entry box, with hidden inputs attached....
126 my $barcodeentrytext = << "EOF";
127 <form method=post action=/cgi-bin/koha/circ/returns.pl>
128 <table border=1 cellpadding=5 cellspacing=0 align=left>
129 <tr><td colspan=2 bgcolor=$headerbackgroundcolor align=center background=$backgroundimage>
130 <font color=black><b>Enter Book Barcode</b></font></td></tr>
131 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td></tr>
133 <input type=hidden name=branch value=$branch>
134 <input type=hidden name=printer value=$printer>
139 my $reservefoundtext;
140 if ($messages->{'ResFound'}) {
141 my $resrec = $messages->{'ResFound'};
142 my ($borr) = getpatroninformation(\%env, $resrec->{'borrowernumber'}, 0);
143 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
144 my $number = "<a href=/cgi-bin/koha/moremember.pl?bornum=$borr->{'borrowernumber'} onClick='openWindow(this,'Member', 480, 640)'>$borr->{'cardnumber'}</a>";
145 my $branch = $branches->{$resrec->{'branchcode'}}->{'branchname'};
146 my $reservetext = "<font size='+2' color='red'>RESERVED</font><font size='+2'> for collection by <br>$name ($number) at $branch </font>";
147 $reservefoundtext = <<"EOF";
148 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
149 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Reserve Found</font></th></tr>
150 <tr><td> $reservetext </td></tr></table>
154 # collect the messages and put into message table....
156 foreach my $code (keys %$messages) {
157 if ($code eq 'BadBarcode'){
158 $messagetext .= "<font color='red' size='+2'> No Item with barcode: $messages->{'BadBarcode'} </font> <br>";
160 if ($code eq 'NotIssued'){
161 my $braname = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
162 $messagetext .= "<font color='red' size='+2'> Item is not Issued, cannot be returned. </font> <br>";
164 if ($code eq 'WasLost'){
165 $messagetext .= "<font color='red' size='+2'> Item was lost, now found. </font> <br>";
167 if (($code eq 'IsPermanent') && (not $messages->{'ResFound'})) {
168 if ($messages->{'IsPermanent'} ne $branch) {
169 $messagetext .= "<font color='red' size='+2'> Item is part of permanent collection, please return to $branches->{$messages->{'IsPermanent'}}->{'branchname'} </font> <br>";
173 $messagetext = substr($messagetext, 0, -4);
177 $messagetable = << "EOF";
178 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
179 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
180 <tr><td> $messagetext </td></tr></table>
188 my $patrontable = << "EOF";
189 <table border=1 cellpadding=5 cellspacing=0 align=right>
190 <tr><td colspan=2 bgcolor=$headerbackgroundcolor background=$backgroundimage>
191 <font color=black><b>Patron Information</b></font></td></tr>
193 <a href=/cgi-bin/koha/moremember.pl?bornum=$borrower->{'borrowernumber'}
194 onClick="openWindow(this,'Member', 480, 640)">$borrower->{'cardnumber'}</a>
195 $borrower->{'surname'}, $borrower->{'title'} $borrower->{'firstname'}<br>
198 my $flags = $borrower->{'flags'};
202 foreach $flag (sort keys %$flags) {
203 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
204 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
205 if ($flags->{$flag}->{'noissues'}) {
206 if ($flag eq 'CHARGES') {
207 $flaginfotext.= <<"EOF";
208 <tr><td valign=top><font color=red>$flag</font></td>
209 <td bgcolor=$color><b>$flags->{$flag}->{'message'}</b>
210 <a href=/cgi-bin/koha/pay.pl?bornum=$borrower->{'borrowernumber'}
211 onClick=\"openWindow(this, 'Payment', 480,640)\">Payment</a></td></tr>
214 $flaginfotext.= <<"EOF";
215 <tr><td valign=top><font color=red>$flag</font></td>
216 <td bgcolor=$color>$flags->{$flag}->{'message'}</td></tr>
220 if ($flag eq 'CHARGES') {
221 $flaginfotext .= << "EOF";
222 <tr><td valign=top>$flag</td>
223 <td> $flags->{$flag}->{'message'} <a href=/cgi-bin/koha/pay.pl?bornum=$borrower->{'borrowernumber'}
224 onClick=\"openWindow(this, 'Payment', 480,640)\">Payment</a></td></tr>
226 } elsif ($flag eq 'WAITING') {
228 my $items = $flags->{$flag}->{'itemlist'};
229 foreach my $item (@$items) {
230 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
231 $itemswaiting .= <<"EOF";
232 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra
233 onClick=\"openWindow(this, 'Item', 480, 640)\">$iteminformation->{'barcode'}</a>
234 $iteminformation->{'title'} ($branches->{$iteminformation->{'holdingbranch'}}->{'branchname'})<br>
237 $flaginfotext.="<tr><td valign=top>$flag</td><td>$itemswaiting</td></tr>\n";
238 } elsif ($flag eq 'ODUES') {
239 my $items = $flags->{$flag}->{'itemlist'};
240 $flaginfotext .= <<"EOF";
241 <tr><td bgcolor=$color><font color=red>$flag</font></td>
242 <td bgcolor=$color>Patron has Overdue books</td></tr>
245 $flaginfotext .= "<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
250 $flaginfotext = << "EOF";
251 <table border=1 cellpadding=5 cellspacing=0> <tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2><b>Flags</b></td></tr>
256 $borrowertable = << "EOF";
257 <table border=0 cellpadding=5>
259 <td valign=top>$patrontable</td>
260 <td valign=top>$flaginfotext</td>
266 # the returned items.....
267 my $returneditemstable = << "EOF";
269 <table border=1 cellpadding=5 cellspacing=0 align=left>
270 <tr><th colspan=6 bgcolor=$headerbackgroundcolor background=$backgroundimage>
271 <font color=black>Returned Items</font></th></tr>
272 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Type</th><th>Borrower</th></tr>
276 #set up so only the lat 8 returned items display (make for faster loading pages)
278 foreach (sort {$a <=> $b} keys %returneditems) {
280 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
281 my $barcode = $returneditems{$_};
282 my $duedate = $riduedate{$_};
283 my @datearr = localtime(time());
285 # convert to nz date format
286 my @tempdate = split(/-/,$duedate);
287 $duedate = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
290 = (1900+$datearr[5]).'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
291 my $overduetext = "$duedate";
292 ($overduetext="<font color=red>$duedate</font>") if ($duedate lt $todaysdate);
293 ($duedate) || ($overduetext = "<img src=/images/blackdot.gif>");
294 my $borrowernumber = $riborrowernumber{$_};
295 my ($borrower) = getpatroninformation(\%env,$borrowernumber,0);
296 my ($iteminformation) = getiteminformation(\%env, 0, $barcode);;
297 $returneditemstable .= << "EOF";
298 <tr><td bgcolor=$color>$overduetext</td>
299 <td bgcolor=$color align=center>
300 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$barcode</a></td>
301 <td bgcolor=$color>$iteminformation->{'title'}</td>
302 <td bgcolor=$color>$iteminformation->{'author'}</td>
303 <td bgcolor=$color align=center>$iteminformation->{'itemtype'}</td>
305 <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>
312 $returneditemstable .= "</table>\n";
315 # actually print the page!
316 print $query->header();
318 print startmenu('circulation');
322 print $reservefoundtext;
324 print $barcodeentrytext;
331 print $borrowertable;
333 (print $returneditemstable) if (%returneditems);
335 print endmenu('circulation');
338 sub cuecatbarcodedecode {
341 my @fields = split(/\./,$barcode);
342 my @results = map(decode($_), @fields[1..$#fields]);