2 # WARNING: This file contains mixed-sized tabs! (some 4-character, some 8)
3 # WARNING: Currently, 4-character tabs seem to be dominant
4 # WARNING: But there are still lots of 8-character tabs
6 #written 11/3/2002 by Finlay
7 #script to execute returns of books
9 # Copyright 2000-2002 Katipo Communications
11 # This file is part of Koha.
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA 02111-1307 USA
28 use C4::Circulation::Circ2;
35 use C4::Interface::CGI::Output;
42 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
44 template_name => "circ/returns.tmpl",
48 flagsrequired => { circulate => 1 },
55 my $headerbackgroundcolor = '#99cc33';
56 my $linecolor1 = '#ffffcc';
57 my $linecolor2 = 'white';
59 my $branches = getbranches();
60 my $printers = getprinters( \%env );
62 my $branch = getbranch( $query, $branches );
63 my $printer = getprinter( $query, $printers );
66 # Some code to handle the error if there is no branch or printer setting.....
69 $env{'branchcode'} = $branch;
70 $env{'printer'} = $printer;
71 $env{'queue'} = $printer;
73 # Set up the item stack ....
78 foreach ( $query->param ) {
79 (next) unless (/ri-(\d*)/);
82 (next) if ( $counter > 20 );
83 my $barcode = $query->param("ri-$counter");
84 my $duedate = $query->param("dd-$counter");
85 my $borrowernumber = $query->param("bn-$counter");
89 $barcode = cuecatbarcodedecode($barcode);
91 ######################
92 #Are these lines still useful ?
93 $returneditems{$counter} = $barcode;
94 $riduedate{$counter} = $duedate;
95 $riborrowernumber{$counter} = $borrowernumber;
97 #######################
98 $input{counter} = $counter;
99 $input{barcode} = $barcode;
100 $input{duedate} = $duedate;
101 $input{bornum} = $borrowernumber;
102 push ( @inputloop, \%input );
106 # Deal with the requests....
107 if ( $query->param('resbarcode') ) {
108 my $item = $query->param('itemnumber');
109 my $borrnum = $query->param('borrowernumber');
110 my $resbarcode = $query->param('resbarcode');
113 my $iteminfo = getiteminformation( \%env, $item );
114 my $tobranchcd = ReserveWaiting( $item, $borrnum );
115 my $branchname = $branches->{$tobranchcd}->{'branchname'};
116 my ($borr) = getpatroninformation( \%env, $borrnum, 0 );
117 my $borcnum = $borr->{'cardnumber'};
119 $borr->{'surname'} . " " . $borr->{'title'} . " " . $borr->{'firstname'};
120 my $slip = $query->param('resslip');
121 # printslip( \%env, $slip ); #removed by paul
123 if ( $tobranchcd ne $branch ) {
125 itemtitle => $iteminfo->{'title'},
126 iteminfo => $iteminfo->{'author'},
127 branchname => $branchname,
140 my $barcode = $query->param('barcode');
142 # actually return book and prepare item table.....
146 $barcode = cuecatbarcodedecode($barcode);
147 ( $returned, $messages, $iteminformation, $borrower ) =
148 returnbook( $barcode, $branch );
150 $returneditems{0} = $barcode;
151 $riborrowernumber{0} = $borrower->{'borrowernumber'};
152 $riduedate{0} = $iteminformation->{'date_due'};
156 $input{barcode} = $barcode;
157 $input{duedate} = $riduedate{0};
158 $input{bornum} = $riborrowernumber{0};
159 push ( @inputloop, \%input );
161 elsif ( !$messages->{'BadBarcode'} ) {
165 $input{barcode} = $barcode;
168 $returneditems{0} = $barcode;
170 if ( $messages->{'wthdrawn'} ) {
171 $input{withdrawn} = 1;
172 $input{bornum} = "Item Cancelled";
173 $riborrowernumber{0} = 'Item Cancelled';
176 $input{bornum} = " ";
177 $riborrowernumber{0} = ' ';
179 push ( @inputloop, \%input );
182 returned => $returned,
183 itemtitle => $iteminformation->{'title'},
185 # itembc => $iteminformation->{'barcode'},
186 # itemdatedue => $iteminformation->{'datedue'},
187 itemauthor => $iteminformation->{'author'}
190 $template->param( inputloop => \@inputloop );
196 if ( $messages->{'ResFound'} ) {
197 my $res = $messages->{'ResFound'};
198 my $branchname = $branches->{ $res->{'branchcode'} }->{'branchname'};
199 my ($borr) = getpatroninformation( \%env, $res->{'borrowernumber'}, 0 );
201 $borr->{'surname'} . " " . $borr->{'title'} . " " . $borr->{'firstname'};
202 my ($iteminfo) = getiteminformation( \%env, 0, $barcode );
204 if ( $res->{'ResFound'} eq "Waiting" ) {
205 if($branch eq $res->{'branchcode'}){
206 $template->param(intransit => 0);
208 $template->param(intransit => 1);
214 borfirstname => $borr->{'firstname'},
215 borsurname => $borr->{'surname'},
216 bortitle => $borr->{'title'},
217 borphone => $borr->{'phone'},
218 boremail => $borr->{'emailaddress'},
219 borstraddress => $borr->{'streetaddress'},
220 borcity => $borr->{'city'},
221 borzip => $borr->{'zipcode'},
222 bornum => $res->{'borrowernumber'},
223 borcnum => $borr->{'cardnumber'},
224 debarred => $borr->{'debarred'},
225 gonenoaddress => $borr->{'gonenoaddress'},
226 currentbranch => $branches->{ $branch }->{'branchname'},
227 branchname => $branches->{ $res->{'branchcode'} }->{'branchname'},
229 itemnumber => $res->{'itemnumber'},
230 itemtitle => $iteminfo->{'title'},
231 itemauthor => $iteminfo->{'author'},
232 itembarcode => $iteminfo->{'barcode'},
233 itemtype => $iteminfo->{'itemtype'},
234 itembiblionumber => $iteminfo->{'biblionumber'}
238 if ( $res->{'ResFound'} eq "Reserved" ) {
239 my @da = localtime( time() );
241 sprintf( "%0.2d", ( $da[3] + 1 ) ) . "/"
242 . sprintf( "%0.2d", ( $da[4] + 1 ) ) . "/"
245 if($branch eq $res->{'branchcode'}){
246 $template->param(intransit => 0);
248 $template->param(intransit => 1);
253 currentbranch => $branches->{ $branch }->{'branchname'},
254 branchname => $branches->{ $res->{'branchcode'} }->{'branchname'},
256 today => $todaysdate,
257 itemnumber => $res->{'itemnumber'},
258 itemtitle => $iteminfo->{'title'},
259 itemauthor => $iteminfo->{'author'},
260 itembarcode => $iteminfo->{'barcode'},
261 itemtype => $iteminfo->{'itemtype'},
262 itembiblionumber => $iteminfo->{'biblionumber'},
263 borsurname => $borr->{'surname'},
264 bortitle => $borr->{'title'},
265 borfirstname => $borr->{'firstname'},
266 bornum => $res->{'borrowernumber'},
267 borcnum => $borr->{'cardnumber'},
268 borphone => $borr->{'phone'},
269 borstraddress => $borr->{'streetaddress'},
270 borsub => $borr->{'suburb'},
271 borcity => $borr->{'city'},
272 borzip => $borr->{'zipcode'},
273 boremail => $borr->{'emailaddress'},
274 debarred => $borr->{'debarred'},
275 gonenoaddress => $borr->{'gonenoaddress'},
283 foreach my $code ( keys %$messages ) {
287 my $exit_required_p = 0;
288 if ( $code eq 'BadBarcode' ) {
289 $err{badbarcode} = 1;
290 $err{msg} = $messages->{'BadBarcode'};
292 elsif ( $code eq 'NotIssued' ) {
294 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
296 elsif ( $code eq 'WasLost' ) {
299 elsif ( $code eq 'ResFound' ) {
300 ; # FIXME... anything to do here?
302 elsif ( $code eq 'WasReturned' ) {
303 ; # FIXME... anything to do here?
305 elsif ( $code eq 'WasTransfered' ) {
306 ; # FIXME... anything to do here?
308 elsif ( $code eq 'wthdrawn' ) {
310 $exit_required_p = 1;
312 elsif ( ( $code eq 'IsPermanent' ) && ( not $messages->{'ResFound'} ) ) {
313 if ( $messages->{'IsPermanent'} ne $branch ) {
314 $err{ispermanent} = 1;
316 $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
320 die "Unknown error code $code"; # XXX
323 push ( @errmsgloop, \%err );
325 last if $exit_required_p;
327 $template->param( errmsgloop => \@errmsgloop );
331 my $flags = $borrower->{'flags'};
335 foreach my $flag ( sort keys %$flags ) {
337 ( $color eq $linecolor1 )
338 ? ( $color = $linecolor2 )
339 : ( $color = $linecolor1 );
340 unless ($flagset) { $flagset = 1; }
341 $flaginfo{color} = $color;
342 $flaginfo{redfont} = ( $flags->{$flag}->{'noissues'} );
343 $flaginfo{flag} = $flag;
344 if ( $flag eq 'CHARGES' ) {
345 $flaginfo{msg} = $flag;
346 $flaginfo{charges} = 1;
347 $flaginfo{bornum} = $borrower->{borrowernumber};
349 elsif ( $flag eq 'WAITING' ) {
350 $flaginfo{msg} = $flag;
351 $flaginfo{waiting} = 1;
353 my $items = $flags->{$flag}->{'itemlist'};
354 foreach my $item (@$items) {
355 my ($iteminformation) =
356 getiteminformation( \%env, $item->{'itemnumber'}, 0 );
358 $waitingitem{biblionum} = $iteminformation->{'biblionumber'};
359 $waitingitem{barcode} = $iteminformation->{'barcode'};
360 $waitingitem{title} = $iteminformation->{'title'};
361 $waitingitem{brname} =
362 $branches->{ $iteminformation->{'holdingbranch'} }->{
364 push ( @waitingitemloop, \%waitingitem );
366 $flaginfo{itemloop} = \@waitingitemloop;
368 elsif ( $flag eq 'ODUES' ) {
369 my $items = $flags->{$flag}->{'itemlist'};
371 foreach my $item ( sort { $a->{'date_due'} cmp $b->{'date_due'} }
374 my ($iteminformation) =
375 getiteminformation( \%env, $item->{'itemnumber'}, 0 );
377 $overdueitem{duedate} = format_date($item->{'date_due'});
378 $overdueitem{biblionum} = $iteminformation->{'biblionumber'};
379 $overdueitem{barcode} = $iteminformation->{'barcode'};
380 $overdueitem{title} = $iteminformation->{'title'};
381 $overdueitem{brname} =
382 $branches->{ $iteminformation->{'holdingbranch'} }->{
384 push ( @itemloop, \%overdueitem );
386 $flaginfo{itemloop} = \@itemloop;
387 $flaginfo{overdue} = 1;
390 $flaginfo{other} = 1;
391 $flaginfo{msg} = $flags->{$flag}->{'message'};
393 push ( @flagloop, \%flaginfo );
397 flagloop => \@flagloop,
398 ribornum => $borrower->{'borrowernumber'},
399 riborcnum => $borrower->{'cardnumber'},
400 riborsurname => $borrower->{'surname'},
401 ribortitle => $borrower->{'title'},
402 riborfirstname => $borrower->{'firstname'}
408 #set up so only the last 8 returned items display (make for faster loading pages)
411 foreach ( sort { $a <=> $b } keys %returneditems ) {
414 ( $color eq $linecolor1 )
415 ? ( $color = $linecolor2 )
416 : ( $color = $linecolor1 );
418 my $barcode = $returneditems{$_};
419 my $duedate = $riduedate{$_};
423 my @tempdate = split ( /-/, $duedate );
424 $ri{year}=$tempdate[0];
425 $ri{month}=$tempdate[1];
426 $ri{day}=$tempdate[2];
427 my $duedatenz = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
428 my @datearr = localtime( time() );
431 . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
432 . sprintf( "%0.2d", $datearr[3] );
433 $ri{duedate}=format_date($duedate);
435 getpatroninformation( \%env, $riborrowernumber{$_}, 0 );
436 $ri{bornum} = $borrower->{'borrowernumber'};
437 $ri{borcnum} = $borrower->{'cardnumber'};
438 $ri{borfirstname} = $borrower->{'firstname'};
439 $ri{borsurname} = $borrower->{'surname'};
440 $ri{bortitle} = $borrower->{'title'};
443 $ri{bornum} = $riborrowernumber{$_};
446 my ($iteminformation) = getiteminformation( \%env, 0, $barcode );
448 $ri{itembiblionumber} = $iteminformation->{'biblionumber'};
449 $ri{itemtitle} = $iteminformation->{'title'};
450 $ri{itemauthor} = $iteminformation->{'author'};
451 $ri{itemtype} = $iteminformation->{'itemtype'};
452 $ri{barcode} = $barcode;
458 push ( @riloop, \%ri );
460 $template->param( riloop => \@riloop );
463 genbrname => $branches->{$branch}->{'branchname'},
464 genprname => $printers->{$printer}->{'printername'},
467 errmsgloop => \@errmsgloop
470 # actually print the page!
471 output_html_with_http_headers $query, $cookie, $template->output;
473 sub cuecatbarcodedecode {
476 my @fields = split ( /\./, $barcode );
477 my @results = map( decode($_), @fields[ 1 .. $#fields ] );
478 if ( $#results == 2 ) {