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();
24 my $branch = $query->param("branch");
25 my $printer = $query->param("printer");
27 ($branch) || ($branch=$query->cookie('branch')) ;
28 ($printer) || ($printer=$query->cookie('printer')) ;
31 # Some code to handle the error if there is no branch or printer setting.....
34 $env{'branchcode'}=$branch;
35 $env{'printer'}=$printer;
36 $env{'queue'}=$printer;
38 # Set up the item stack ....
43 foreach ($query->param) {
44 (next) unless (/ri-(\d*)/);
46 (next) if ($counter>20);
47 my $barcode=$query->param("ri-$counter");
48 my $duedate=$query->param("dd-$counter");
49 my $borrowernumber=$query->param("bn-$counter");
52 $barcode = cuecatbarcodedecode($barcode);
53 $returneditems{$counter}=$barcode;
54 $riduedate{$counter}=$duedate;
55 $riborrowernumber{$counter}=$borrowernumber;
56 $ritext.="<input type=hidden name=ri-$counter value=$barcode>\n";
57 $ritext.="<input type=hidden name=dd-$counter value=$duedate>\n";
58 $ritext.="<input type=hidden name=bn-$counter value=$borrowernumber>\n";
65 # actually return book (SQL CALL) and prepare item table.....
66 if (my $barcode = $query->param('barcode')) {
68 $barcode = cuecatbarcodedecode($barcode);
69 ($returned, $messages, $iteminformation, $borrower) = returnbook2(\%env, $barcode);
71 $returneditems{0} = $barcode;
72 $riborrowernumber{0} = $borrower->{'borrowernumber'};
73 $riduedate{0} = $iteminformation->{'date_due'};
74 $ritext.= "<input type=hidden name=ri-0 value=$barcode>\n";
75 $ritext.= "<input type=hidden name=dd-0 value=$iteminformation->{'date_due'}>\n";
76 $ritext.= "<input type=hidden name=bn-0 value=$borrower->{'borrowernumber'}>\n";
80 ##################################################################################
85 <FONT SIZE=2 face="arial, helvetica">
86 <a href=circulationold.pl?module=issues&branch=$branch&printer=$printer&print>Next Borrower</a> ||
87 <a href=returns.pl>Returns</a> ||
88 <a href=branchtransfers.pl>Transfers</a></font></p>
89 <FONT SIZE=6><em>Circulation: Returns</em></FONT>
94 if ($iteminformation) {
96 <table border=1 cellpadding=5 cellspacing=0>
97 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
98 <font color=black>Returned Item Information</font></th></tr>
100 Title: $iteminformation->{'title'}<br>
101 <!--Hlt decided they dont want these showing, uncoment the html to make it work
103 Author: $iteminformation->{'author'}<br>
104 Barcode: <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}
105 &type=intra onClick="openWindow(this, 'Item', 480, 640)">$iteminformation->{'barcode'}</a><br>
106 Date Due: $iteminformation->{'date_due'}-->
113 # Barcode entry box, with hidden inputs attached....
114 my $barcodeentrytext= << "EOF";
115 <form method=post action=/cgi-bin/koha/circ/returns.pl>
116 <table border=1 cellpadding=5 cellspacing=0 align=left>
117 <tr><td colspan=2 bgcolor=$headerbackgroundcolor align=center background=$backgroundimage>
118 <font color=black><b>Enter Book Barcode</b></font></td></tr>
119 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td></tr>
121 <input type=hidden name=branch value=$branch>
122 <input type=hidden name=printer value=$printer>
127 # collect the messages and put into message table....
131 foreach (@$messages) {
132 $messagetext .= "$_<br>";
134 $messagetext = substr($messagetext, 0, -4);
136 $messagetable = << "EOF";
137 <table border=1 cellpadding=5 cellspacing=0>
138 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>Messages</font></th></tr>
151 my $patrontable = << "EOF";
152 <table border=1 cellpadding=5 cellspacing=0 align=right>
153 <tr><td colspan=2 bgcolor=$headerbackgroundcolor background=$backgroundimage>
154 <font color=black><b>Patron Information</b></font></td></tr>
156 <a href=/cgi-bin/koha/moremember.pl?bornum=$borrower->{'borrowernumber'}
157 onClick="openWindow(this,'Member', 480, 640)">$borrower->{'cardnumber'}</a>
158 $borrower->{'surname'}, $borrower->{'title'} $borrower->{'firstname'}<br>
161 my $flags = $borrower->{'flags'};
165 foreach $flag (sort keys %$flags) {
166 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
167 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
168 if ($flags->{$flag}->{'noissues'}) {
169 if ($flag eq 'CHARGES') {
170 $flaginfotext.= <<"EOF";
171 <tr><td valign=top><font color=red>$flag</font></td>
172 <td bgcolor=$color><b>$flags->{$flag}->{'message'}</b>
173 <a href=/cgi-bin/koha/pay.pl?bornum=$borrower->{'borrowernumber'}
174 onClick=\"openWindow(this, 'Payment', 480,640)\">Payment</a></td></tr>
177 $flaginfotext.= <<"EOF";
178 <tr><td valign=top><font color=red>$flag</font></td>
179 <td bgcolor=$color>$flags->{$flag}->{'message'}</td></tr>
183 if ($flag eq 'CHARGES') {
184 $flaginfotext .= << "EOF";
185 <tr><td valign=top>$flag</td>
186 <td> $flags->{$flag}->{'message'} <a href=/cgi-bin/koha/pay.pl?bornum=$borrower->{'borrowernumber'}
187 onClick=\"openWindow(this, 'Payment', 480,640)\">Payment</a></td></tr>
189 } elsif ($flag eq 'WAITING') {
191 my $items = $flags->{$flag}->{'itemlist'};
192 foreach my $item (@$items) {
193 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
194 $itemswaiting .= <<"EOF";
195 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra
196 onClick=\"openWindow(this, 'Item', 480, 640)\">$iteminformation->{'barcode'}</a>
197 $iteminformation->{'title'} ($branches->{$iteminformation->{'holdingbranch'}}->{'branchname'})<br>
200 $flaginfotext.="<tr><td valign=top>$flag</td><td>$itemswaiting</td></tr>\n";
201 } elsif ($flag eq 'ODUES') {
202 my $items = $flags->{$flag}->{'itemlist'};
203 $flaginfotext .= <<"EOF";
204 <tr><td bgcolor=$color><font color=red>$flag</font></td>
205 <td bgcolor=$color>Patron has Overdue books</td></tr>
208 $flaginfotext .= "<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
213 $flaginfotext = << "EOF";
214 <table border=1 cellpadding=5 cellspacing=0> <tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2><b>Flags</b></td></tr>
219 $borrowertable = << "EOF";
220 <table border=0 cellpadding=5>
222 <td valign=top>$patrontable</td>
223 <td valign=top>$flaginfotext</td>
229 # the returned items.....
230 my $returneditemstable = << "EOF";
232 <table border=1 cellpadding=5 cellspacing=0 align=left>
233 <tr><th colspan=6 bgcolor=$headerbackgroundcolor background=$backgroundimage>
234 <font color=black>Returned Items</font></th></tr>
235 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Type</th><th>Borrower</th></tr>
239 #set up so only the lat 8 returned items display (make for faster loading pages)
241 foreach (sort {$a <=> $b} keys %returneditems) {
243 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
244 my $barcode = $returneditems{$_};
245 my $duedate = $riduedate{$_};
246 my @datearr = localtime(time());
248 # convert to nz date format
249 my @tempdate = split(/-/,$duedate);
250 $duedate = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
253 = (1900+$datearr[5]).'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
254 my $overduetext = "$duedate";
255 ($overduetext="<font color=red>$duedate</font>") if ($duedate lt $todaysdate);
256 ($duedate) || ($overduetext = "<img src=/images/blackdot.gif>");
257 my $borrowernumber = $riborrowernumber{$_};
258 my ($borrower) = getpatroninformation(\%env,$borrowernumber,0);
259 my ($iteminformation) = getiteminformation(\%env, 0, $barcode);;
260 $returneditemstable .= << "EOF";
261 <tr><td bgcolor=$color>$overduetext</td>
262 <td bgcolor=$color align=center>
263 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$barcode</a></td>
264 <td bgcolor=$color>$iteminformation->{'title'}</td>
265 <td bgcolor=$color>$iteminformation->{'author'}</td>
266 <td bgcolor=$color align=center>$iteminformation->{'itemtype'}</td>
268 <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>
275 $returneditemstable .= "</table>\n";
278 # actually print the page!
281 print $query->header();
283 print startmenu('circulation');
287 # my $flags = $borrower->{'flags'};
288 # foreach my $key (keys %$flags) {
289 # print "$key : $flags->{$key} <br> ";
292 print $barcodeentrytext;
298 print $borrowertable;
300 (print $returneditemstable) if (%returneditems);
302 print endmenu('circulation');
305 sub cuecatbarcodedecode {
308 my @fields = split(/\./,$barcode);
309 my @results = map(decode($_), @fields[1..$#fields]);