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 = C4::Context->userenv->{'branch'};
63 my $printer = C4::Context->userenv->{'branchprinter'};
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 # if($iteminfo->{'holdingbranch'} ne $branch){
115 # UpdateHoldingbranch($branch,$item);
117 # check if we have other reservs for this document, if we have a return send the message of transfer
118 my ($messages,$nextreservinfo) = OtherReserves($item);
119 my $branchname = getbranchname($messages->{'transfert'});
120 my ($borr) = getpatroninformation( \%env, $nextreservinfo, 0 );
121 my $borcnum = $borr->{'cardnumber'};
123 $borr->{'surname'} . " " . $borr->{'title'} . " " . $borr->{'firstname'};
124 my $slip = $query->param('resslip');
125 # printslip( \%env, $slip ); #removed by paul
127 if ( $messages->{'transfert'} ) {
128 # add the transfer routine
129 # C4::Circulation::Circ2::dotransfer($item,$iteminfo->{'holdingbranch'},$tobranchcd);
131 itemtitle => $iteminfo->{'title'},
132 iteminfo => $iteminfo->{'author'},
133 branchname => $branchname,
137 borfirstname => $borr->{'firstname'},
138 borsurname => $borr->{'surname'},
148 my $barcode = $query->param('barcode');
150 # actually return book and prepare item table.....
153 $barcode = cuecatbarcodedecode($barcode);
154 ( $returned, $messages, $iteminformation, $borrower ) =
155 returnbook( $barcode, $branch );
157 $returneditems{0} = $barcode;
158 $riborrowernumber{0} = $borrower->{'borrowernumber'};
159 $riduedate{0} = $iteminformation->{'date_due'};
163 $input{barcode} = $barcode;
164 $input{duedate} = $riduedate{0};
165 $input{bornum} = $riborrowernumber{0};
166 push ( @inputloop, \%input );
168 elsif ( !$messages->{'BadBarcode'} ) {
172 $input{barcode} = $barcode;
175 $returneditems{0} = $barcode;
177 if ( $messages->{'wthdrawn'} ) {
178 $input{withdrawn} = 1;
179 $input{bornum} = "Item Cancelled";
180 $riborrowernumber{0} = 'Item Cancelled';
183 $input{bornum} = " ";
184 $riborrowernumber{0} = ' ';
186 push ( @inputloop, \%input );
189 returned => $returned,
190 itemtitle => $iteminformation->{'title'},
192 # itembc => $iteminformation->{'barcode'},
193 # itemdatedue => $iteminformation->{'datedue'},
194 itemauthor => $iteminformation->{'author'}
197 $template->param( inputloop => \@inputloop );
203 # new op dev : we check if the document must be returned to his homebranch directly,
204 # if the document is transfered, we have warning message .
206 if ( $messages->{'WasTransfered'} ) {
207 # my $res = $messages->{'ResFound'};
208 # my $branchname = $branches->{ $res->{'branchcode'} }->{'branchname'};
209 # my ($borr) = getpatroninformation( \%env, $res->{'borrowernumber'}, 0 );
211 # $borr->{'surname'} . " " . $borr->{'title'} . " " . $borr->{'firstname'};
212 my ($iteminfo) = getiteminformation( \%env, 0, $barcode );
214 # if ( $res->{'ResFound'} eq "Waiting" ) {
215 # if($branch eq $res->{'branchcode'}){
216 # $template->param(intransit => 0);
218 # $template->param(intransit => 1);
224 itemhomebranch => $branches->{$iteminfo->{'homebranch'} }->{'branchname'}
229 if ( $messages->{'ResFound'} ) {
230 my $res = $messages->{'ResFound'};
231 my $branchname = $branches->{ $res->{'branchcode'} }->{'branchname'};
232 my ($borr) = getpatroninformation( \%env, $res->{'borrowernumber'}, 0 );
234 $borr->{'surname'} . " " . $borr->{'title'} . " " . $borr->{'firstname'};
235 my ($iteminfo) = getiteminformation( \%env, 0, $barcode );
237 if ( $res->{'ResFound'} eq "Waiting" ) {
238 if($branch eq $res->{'branchcode'}){
239 $template->param(intransit => 0);
241 $template->param(intransit => 1);
247 borfirstname => $borr->{'firstname'},
248 borsurname => $borr->{'surname'},
249 bortitle => $borr->{'title'},
250 borphone => $borr->{'phone'},
251 boremail => $borr->{'emailaddress'},
252 borstraddress => $borr->{'streetaddress'},
253 borcity => $borr->{'city'},
254 borzip => $borr->{'zipcode'},
255 bornum => $res->{'borrowernumber'},
256 borcnum => $borr->{'cardnumber'},
257 debarred => $borr->{'debarred'},
258 gonenoaddress => $borr->{'gonenoaddress'},
259 currentbranch => $branches->{ $branch }->{'branchname'},
260 branchname => $branches->{ $res->{'branchcode'} }->{'branchname'},
262 itemnumber => $res->{'itemnumber'},
263 itemtitle => $iteminfo->{'title'},
264 itemauthor => $iteminfo->{'author'},
265 itembarcode => $iteminfo->{'barcode'},
266 itemtype => $iteminfo->{'itemtype'},
267 itembiblionumber => $iteminfo->{'biblionumber'}
271 if ( $res->{'ResFound'} eq "Reserved" ) {
272 my @da = localtime( time() );
274 sprintf( "%0.2d", ( $da[3] + 1 ) ) . "/"
275 . sprintf( "%0.2d", ( $da[4] + 1 ) ) . "/"
278 if($branch eq $res->{'branchcode'}){
279 $template->param(intransit => 0);
281 $template->param(intransit => 1);
286 currentbranch => $branches->{ $branch }->{'branchname'},
287 branchname => $branches->{ $res->{'branchcode'} }->{'branchname'},
289 today => $todaysdate,
290 itemnumber => $res->{'itemnumber'},
291 itemtitle => $iteminfo->{'title'},
292 itemauthor => $iteminfo->{'author'},
293 itembarcode => $iteminfo->{'barcode'},
294 itemtype => $iteminfo->{'itemtype'},
295 itembiblionumber => $iteminfo->{'biblionumber'},
296 borsurname => $borr->{'surname'},
297 bortitle => $borr->{'title'},
298 borfirstname => $borr->{'firstname'},
299 bornum => $res->{'borrowernumber'},
300 borcnum => $borr->{'cardnumber'},
301 borphone => $borr->{'phone'},
302 borstraddress => $borr->{'streetaddress'},
303 borsub => $borr->{'suburb'},
304 borcity => $borr->{'city'},
305 borzip => $borr->{'zipcode'},
306 boremail => $borr->{'emailaddress'},
307 debarred => $borr->{'debarred'},
308 gonenoaddress => $borr->{'gonenoaddress'},
316 foreach my $code ( keys %$messages ) {
320 my $exit_required_p = 0;
321 if ( $code eq 'BadBarcode' ) {
322 $err{badbarcode} = 1;
323 $err{msg} = $messages->{'BadBarcode'};
325 elsif ( $code eq 'NotIssued' ) {
327 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
329 elsif ( $code eq 'WasLost' ) {
332 elsif ( $code eq 'ResFound' ) {
333 ; # FIXME... anything to do here?
335 elsif ( $code eq 'WasReturned' ) {
336 ; # FIXME... anything to do here?
338 elsif ( $code eq 'WasTransfered' ) {
339 ; # FIXME... anything to do here?
341 elsif ( $code eq 'wthdrawn' ) {
343 $exit_required_p = 1;
345 elsif ( ( $code eq 'IsPermanent' ) && ( not $messages->{'ResFound'} ) ) {
346 if ( $messages->{'IsPermanent'} ne $branch ) {
347 $err{ispermanent} = 1;
349 $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
353 die "Unknown error code $code"; # XXX
356 push ( @errmsgloop, \%err );
358 last if $exit_required_p;
360 $template->param( errmsgloop => \@errmsgloop );
364 my $flags = $borrower->{'flags'};
368 foreach my $flag ( sort keys %$flags ) {
370 ( $color eq $linecolor1 )
371 ? ( $color = $linecolor2 )
372 : ( $color = $linecolor1 );
373 unless ($flagset) { $flagset = 1; }
374 $flaginfo{color} = $color;
375 $flaginfo{redfont} = ( $flags->{$flag}->{'noissues'} );
376 $flaginfo{flag} = $flag;
377 if ( $flag eq 'CHARGES' ) {
378 $flaginfo{msg} = $flag;
379 $flaginfo{charges} = 1;
380 $flaginfo{bornum} = $borrower->{borrowernumber};
382 elsif ( $flag eq 'WAITING' ) {
383 $flaginfo{msg} = $flag;
384 $flaginfo{waiting} = 1;
386 my $items = $flags->{$flag}->{'itemlist'};
387 foreach my $item (@$items) {
388 my ($iteminformation) =
389 getiteminformation( \%env, $item->{'itemnumber'}, 0 );
391 $waitingitem{biblionum} = $iteminformation->{'biblionumber'};
392 $waitingitem{barcode} = $iteminformation->{'barcode'};
393 $waitingitem{title} = $iteminformation->{'title'};
394 $waitingitem{brname} =
395 $branches->{ $iteminformation->{'holdingbranch'} }->{
397 push ( @waitingitemloop, \%waitingitem );
399 $flaginfo{itemloop} = \@waitingitemloop;
401 elsif ( $flag eq 'ODUES' ) {
402 my $items = $flags->{$flag}->{'itemlist'};
404 foreach my $item ( sort { $a->{'date_due'} cmp $b->{'date_due'} }
407 my ($iteminformation) =
408 getiteminformation( \%env, $item->{'itemnumber'}, 0 );
410 $overdueitem{duedate} = format_date($item->{'date_due'});
411 $overdueitem{biblionum} = $iteminformation->{'biblionumber'};
412 $overdueitem{barcode} = $iteminformation->{'barcode'};
413 $overdueitem{title} = $iteminformation->{'title'};
414 $overdueitem{brname} =
415 $branches->{ $iteminformation->{'holdingbranch'} }->{
417 push ( @itemloop, \%overdueitem );
419 $flaginfo{itemloop} = \@itemloop;
420 $flaginfo{overdue} = 1;
423 $flaginfo{other} = 1;
424 $flaginfo{msg} = $flags->{$flag}->{'message'};
426 push ( @flagloop, \%flaginfo );
430 flagloop => \@flagloop,
431 ribornum => $borrower->{'borrowernumber'},
432 riborcnum => $borrower->{'cardnumber'},
433 riborsurname => $borrower->{'surname'},
434 ribortitle => $borrower->{'title'},
435 riborfirstname => $borrower->{'firstname'}
441 #set up so only the last 8 returned items display (make for faster loading pages)
444 foreach ( sort { $a <=> $b } keys %returneditems ) {
447 ( $color eq $linecolor1 )
448 ? ( $color = $linecolor2 )
449 : ( $color = $linecolor1 );
451 my $barcode = $returneditems{$_};
452 my $duedate = $riduedate{$_};
456 my @tempdate = split ( /-/, $duedate );
457 $ri{year}=$tempdate[0];
458 $ri{month}=$tempdate[1];
459 $ri{day}=$tempdate[2];
460 my $duedatenz = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
461 my @datearr = localtime( time() );
464 . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
465 . sprintf( "%0.2d", $datearr[3] );
466 $ri{duedate}=format_date($duedate);
468 getpatroninformation( \%env, $riborrowernumber{$_}, 0 );
469 $ri{bornum} = $borrower->{'borrowernumber'};
470 $ri{borcnum} = $borrower->{'cardnumber'};
471 $ri{borfirstname} = $borrower->{'firstname'};
472 $ri{borsurname} = $borrower->{'surname'};
473 $ri{bortitle} = $borrower->{'title'};
476 $ri{bornum} = $riborrowernumber{$_};
479 my ($iteminformation) = getiteminformation( \%env, 0, $barcode );
481 $ri{itembiblionumber} = $iteminformation->{'biblionumber'};
482 $ri{itemtitle} = $iteminformation->{'title'};
483 $ri{itemauthor} = $iteminformation->{'author'};
484 $ri{itemtype} = $iteminformation->{'itemtype'};
485 $ri{barcode} = $barcode;
491 push ( @riloop, \%ri );
493 $template->param( riloop => \@riloop );
496 genbrname => $branches->{$branch}->{'branchname'},
497 genprname => $printers->{$printer}->{'printername'},
500 errmsgloop => \@errmsgloop
503 # actually print the page!
504 output_html_with_http_headers $query, $cookie, $template->output;
506 sub cuecatbarcodedecode {
509 my @fields = split ( /\./, $barcode );
510 my @results = map( decode($_), @fields[ 1 .. $#fields ] );
511 if ( $#results == 2 ) {