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;
43 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
45 template_name => "circ/returns.tmpl",
49 flagsrequired => { circulate => 1 },
56 my $headerbackgroundcolor = '#99cc33';
57 my $linecolor1 = '#ffffcc';
58 my $linecolor2 = 'white';
60 my $branches = GetBranches('IS');
61 my $printers = getprinters( \%env );
63 my $branch = C4::Context->userenv->{'branch'};
64 my $printer = C4::Context->userenv->{'branchprinter'};
67 # Some code to handle the error if there is no branch or printer setting.....
70 $env{'branchcode'} = $branch;
71 $env{'printer'} = $printer;
72 $env{'queue'} = $printer;
74 # Set up the item stack ....
79 foreach ( $query->param ) {
80 (next) unless (/ri-(\d*)/);
83 (next) if ( $counter > 20 );
84 my $barcode = $query->param("ri-$counter");
85 my $duedate = $query->param("dd-$counter");
86 my $borrowernumber = $query->param("bn-$counter");
90 $barcode = cuecatbarcodedecode($barcode);
92 ######################
93 #Are these lines still useful ?
94 $returneditems{$counter} = $barcode;
95 $riduedate{$counter} = $duedate;
96 $riborrowernumber{$counter} = $borrowernumber;
98 #######################
99 $input{counter} = $counter;
100 $input{barcode} = $barcode;
101 $input{duedate} = $duedate;
102 $input{bornum} = $borrowernumber;
103 push ( @inputloop, \%input );
107 # Deal with the requests....
108 if ( $query->param('resbarcode') ) {
109 my $item = $query->param('itemnumber');
110 my $borrnum = $query->param('borrowernumber');
111 my $resbarcode = $query->param('resbarcode');
114 my $iteminfo = getiteminformation( \%env, $item );
115 my $tobranchcd = ReserveWaiting( $item, $borrnum );
116 # if($iteminfo->{'holdingbranch'} ne $branch){
117 # UpdateHoldingbranch($branch,$item);
119 # check if we have other reservs for this document, if we have a return send the message of transfer
120 my ($messages,$nextreservinfo) = OtherReserves($item);
121 # my $branchname = $branches->{$tobranchcd}->{'branchname'}; - not sure if this line + $tobranchcd line do the same thing
122 # as the $messages{'transfert'} code
123 my $branchname = getbranchname($messages->{'transfert'});
124 my ($borr) = getpatroninformation( \%env, $nextreservinfo, 0 );
125 my $borcnum = $borr->{'cardnumber'};
127 $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'};
128 my $slip = $query->param('resslip');
129 printreserve( \%env, $branchname, $borr, $iteminfo );
130 # if ( $tobranchcd ne $branch ) { - not sure if line below is doing the same
131 if ( $messages->{'transfert'} ) {
132 # add the transfer routine
133 # C4::Circulation::Circ2::dotransfer($item,$iteminfo->{'holdingbranch'},$tobranchcd);
135 itemtitle => $iteminfo->{'title'},
136 iteminfo => $iteminfo->{'author'},
137 tobranchname => $branchname,
141 borfirstname => $borr->{'firstname'},
142 borsurname => $borr->{'surname'},
153 my $barcode = $query->param('barcode');
155 # actually return book and prepare item table.....
158 $barcode = cuecatbarcodedecode($barcode);
159 ( $returned, $messages, $iteminformation, $borrower ) =
160 returnbook( $barcode, $branch );
162 $returneditems{0} = $barcode;
163 $riborrowernumber{0} = $borrower->{'borrowernumber'};
164 $riduedate{0} = $iteminformation->{'date_due'};
168 $input{barcode} = $barcode;
169 $input{duedate} = $riduedate{0};
170 $input{bornum} = $riborrowernumber{0};
171 push ( @inputloop, \%input );
172 # check if the branch is the same as homebranch
173 # if not, we want to put a message
174 if ($iteminformation->{'homebranch'} ne $branch){
175 $template->param( homebranch =>$iteminformation->{'homebranch'});
178 elsif ( !$messages->{'BadBarcode'} ) {
182 $input{barcode} = $barcode;
185 $returneditems{0} = $barcode;
187 if ( $messages->{'wthdrawn'} ) {
188 $input{withdrawn} = 1;
189 $input{bornum} = "Item Cancelled";
190 $riborrowernumber{0} = 'Item Cancelled';
193 $input{bornum} = " ";
194 $riborrowernumber{0} = ' ';
196 push ( @inputloop, \%input );
199 returned => $returned,
200 itemtitle => $iteminformation->{'title'},
202 # itembc => $iteminformation->{'barcode'},
203 # itemdatedue => $iteminformation->{'datedue'},
204 itemauthor => $iteminformation->{'author'}
207 $template->param( inputloop => \@inputloop );
213 # new op dev : we check if the document must be returned to his homebranch directly,
214 # if the document is transfered, we have warning message .
216 if ( $messages->{'WasTransfered'} ) {
217 # my $res = $messages->{'ResFound'};
218 # my $branchname = $branches->{ $res->{'branchcode'} }->{'branchname'};
219 # my ($borr) = getpatroninformation( \%env, $res->{'borrowernumber'}, 0 );
221 # $borr->{'surname'} . " " . $borr->{'title'} . " " . $borr->{'firstname'};
222 my ($iteminfo) = getiteminformation( \%env, 0, $barcode );
224 # if ( $res->{'ResFound'} eq "Waiting" ) {
225 # if($branch eq $res->{'branchcode'}){
226 # $template->param(intransit => 0);
228 # $template->param(intransit => 1);
234 itemhomebranch => $branches->{$iteminfo->{'homebranch'} }->{'branchname'}
239 if ( $messages->{'ResFound'} ) {
240 my $res = $messages->{'ResFound'};
241 my $branchname = $branches->{ $res->{'branchcode'} }->{'branchname'};
242 my ($borr) = getpatroninformation( \%env, $res->{'borrowernumber'}, 0 );
244 $borr->{'surname'} . " " . $borr->{'title'} . " " . $borr->{'firstname'};
245 my ($iteminfo) = getiteminformation( \%env, 0, $barcode );
247 if ( $res->{'ResFound'} eq "Waiting" ) {
248 if($branch eq $res->{'branchcode'}){
249 $template->param(intransit => 0);
251 $template->param(intransit => 1);
257 borfirstname => $borr->{'firstname'},
258 borsurname => $borr->{'surname'},
259 bortitle => $borr->{'title'},
260 borphone => $borr->{'phone'},
261 boremail => $borr->{'emailaddress'},
262 borstraddress => $borr->{'streetaddress'},
263 borcity => $borr->{'city'},
264 borzip => $borr->{'zipcode'},
265 bornum => $res->{'borrowernumber'},
266 borcnum => $borr->{'cardnumber'},
267 debarred => $borr->{'debarred'},
268 gonenoaddress => $borr->{'gonenoaddress'},
269 currentbranch => $branches->{ $branch }->{'branchname'},
270 tobranchname => $branches->{ $res->{'branchcode'} }->{'branchname'},
272 itemnumber => $res->{'itemnumber'},
273 itemtitle => $iteminfo->{'title'},
274 itemauthor => $iteminfo->{'author'},
275 itembarcode => $iteminfo->{'barcode'},
276 itemtype => $iteminfo->{'itemtype'},
277 itembiblionumber => $iteminfo->{'biblionumber'}
281 if ( $res->{'ResFound'} eq "Reserved" ) {
282 my @da = localtime( time() );
284 sprintf( "%0.2d", ( $da[3] + 1 ) ) . "/"
285 . sprintf( "%0.2d", ( $da[4] + 1 ) ) . "/"
288 if($branch eq $res->{'branchcode'}){
289 $template->param(intransit => 0);
291 $template->param(intransit => 1);
296 currentbranch => $branches->{ $branch }->{'branchname'},
298 branchname => $branches->{ $res->{'branchcode'} }->{'branchname'},
300 today => $todaysdate,
301 itemnumber => $res->{'itemnumber'},
302 itemtitle => $iteminfo->{'title'},
303 itemauthor => $iteminfo->{'author'},
304 itembarcode => $iteminfo->{'barcode'},
305 itemtype => $iteminfo->{'itemtype'},
306 itembiblionumber => $iteminfo->{'biblionumber'},
307 borsurname => $borr->{'surname'},
308 bortitle => $borr->{'title'},
309 borfirstname => $borr->{'firstname'},
310 bornum => $res->{'borrowernumber'},
311 borcnum => $borr->{'cardnumber'},
312 borphone => $borr->{'phone'},
313 borstraddress => $borr->{'streetaddress'},
314 borsub => $borr->{'suburb'},
315 borcity => $borr->{'city'},
316 borzip => $borr->{'zipcode'},
317 boremail => $borr->{'emailaddress'},
318 debarred => $borr->{'debarred'},
319 gonenoaddress => $borr->{'gonenoaddress'},
327 foreach my $code ( keys %$messages ) {
331 my $exit_required_p = 0;
332 if ( $code eq 'BadBarcode' ) {
333 $err{badbarcode} = 1;
334 $err{msg} = $messages->{'BadBarcode'};
336 elsif ( $code eq 'NotIssued' ) {
338 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
340 elsif ( $code eq 'WasLost' ) {
343 elsif ( $code eq 'ResFound' ) {
344 ; # FIXME... anything to do here?
346 elsif ( $code eq 'WasReturned' ) {
347 ; # FIXME... anything to do here?
349 elsif ( $code eq 'WasTransfered' ) {
350 ; # FIXME... anything to do here?
352 elsif ( $code eq 'wthdrawn' ) {
354 $exit_required_p = 1;
356 elsif ( ( $code eq 'IsPermanent' ) && ( not $messages->{'ResFound'} ) ) {
357 if ( $messages->{'IsPermanent'} ne $branch ) {
358 $err{ispermanent} = 1;
360 $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
364 die "Unknown error code $code"; # XXX
367 push ( @errmsgloop, \%err );
369 last if $exit_required_p;
371 $template->param( errmsgloop => \@errmsgloop );
375 my $flags = $borrower->{'flags'};
379 foreach my $flag ( sort keys %$flags ) {
381 ( $color eq $linecolor1 )
382 ? ( $color = $linecolor2 )
383 : ( $color = $linecolor1 );
384 unless ($flagset) { $flagset = 1; }
385 $flaginfo{color} = $color;
386 $flaginfo{redfont} = ( $flags->{$flag}->{'noissues'} );
387 $flaginfo{flag} = $flag;
388 if ( $flag eq 'CHARGES' ) {
389 $flaginfo{msg} = $flag;
390 $flaginfo{charges} = 1;
391 $flaginfo{bornum} = $borrower->{borrowernumber};
393 elsif ( $flag eq 'WAITING' ) {
394 $flaginfo{msg} = $flag;
395 $flaginfo{waiting} = 1;
397 my $items = $flags->{$flag}->{'itemlist'};
398 foreach my $item (@$items) {
399 my ($iteminformation) =
400 getiteminformation( \%env, $item->{'itemnumber'}, 0 );
402 $waitingitem{biblionum} = $iteminformation->{'biblionumber'};
403 $waitingitem{barcode} = $iteminformation->{'barcode'};
404 $waitingitem{title} = $iteminformation->{'title'};
405 $waitingitem{brname} =
406 $branches->{ $iteminformation->{'holdingbranch'} }->{
408 push ( @waitingitemloop, \%waitingitem );
410 $flaginfo{itemloop} = \@waitingitemloop;
412 elsif ( $flag eq 'ODUES' ) {
413 my $items = $flags->{$flag}->{'itemlist'};
415 foreach my $item ( sort { $a->{'date_due'} cmp $b->{'date_due'} }
418 my ($iteminformation) =
419 getiteminformation( \%env, $item->{'itemnumber'}, 0 );
421 $overdueitem{duedate} = format_date($item->{'date_due'});
422 $overdueitem{biblionum} = $iteminformation->{'biblionumber'};
423 $overdueitem{barcode} = $iteminformation->{'barcode'};
424 $overdueitem{title} = $iteminformation->{'title'};
425 $overdueitem{brname} =
426 $branches->{ $iteminformation->{'holdingbranch'} }->{
428 push ( @itemloop, \%overdueitem );
430 $flaginfo{itemloop} = \@itemloop;
431 $flaginfo{overdue} = 1;
434 $flaginfo{other} = 1;
435 $flaginfo{msg} = $flags->{$flag}->{'message'};
437 push ( @flagloop, \%flaginfo );
441 flagloop => \@flagloop,
442 ribornum => $borrower->{'borrowernumber'},
443 riborcnum => $borrower->{'cardnumber'},
444 riborsurname => $borrower->{'surname'},
445 ribortitle => $borrower->{'title'},
446 riborfirstname => $borrower->{'firstname'}
452 #set up so only the last 8 returned items display (make for faster loading pages)
455 foreach ( sort { $a <=> $b } keys %returneditems ) {
458 ( $color eq $linecolor1 )
459 ? ( $color = $linecolor2 )
460 : ( $color = $linecolor1 );
462 my $barcode = $returneditems{$_};
463 my $duedate = $riduedate{$_};
467 my @tempdate = split ( /-/, $duedate );
468 $ri{year}=$tempdate[0];
469 $ri{month}=$tempdate[1];
470 $ri{day}=$tempdate[2];
471 my $duedatenz = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
472 my @datearr = localtime( time() );
475 . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
476 . sprintf( "%0.2d", $datearr[3] );
477 $ri{duedate}=format_date($duedate);
479 getpatroninformation( \%env, $riborrowernumber{$_}, 0 );
480 $ri{bornum} = $borrower->{'borrowernumber'};
481 $ri{borcnum} = $borrower->{'cardnumber'};
482 $ri{borfirstname} = $borrower->{'firstname'};
483 $ri{borsurname} = $borrower->{'surname'};
484 $ri{bortitle} = $borrower->{'title'};
487 $ri{bornum} = $riborrowernumber{$_};
490 my ($iteminformation) = getiteminformation( \%env, 0, $barcode );
492 $ri{itembiblionumber} = $iteminformation->{'biblionumber'};
493 $ri{itemtitle} = $iteminformation->{'title'};
494 $ri{itemauthor} = $iteminformation->{'author'};
495 $ri{itemtype} = $iteminformation->{'itemtype'};
496 $ri{barcode} = $barcode;
502 push ( @riloop, \%ri );
504 $template->param( riloop => \@riloop );
507 genbrname => $branches->{$branch}->{'branchname'},
508 genprname => $printers->{$printer}->{'printername'},
509 branchname => $branches->{$branch}->{'branchname'},
511 errmsgloop => \@errmsgloop,
512 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
513 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
514 IntranetNav => C4::Context->preference("IntranetNav"),
517 # actually print the page!
518 output_html_with_http_headers $query, $cookie, $template->output;
520 sub cuecatbarcodedecode {
523 my @fields = split ( /\./, $barcode );
524 my @results = map( decode($_), @fields[ 1 .. $#fields ] );
525 if ( $#results == 2 ) {
535 my ($itemnumber) = @_;
536 my $dbh=C4::Context->dbh();
537 my $query = "UPDATE items SET holdingbranch='TRA' WHERE itemnumber = ?";
538 my $sth=$dbh->prepare($query);
539 $sth->execute($itemnumber);
544 my ($itemnumber) = @_;
545 my $dbh=C4::Context->dbh();
546 my $query = "UPDATE items SET holdingbranch='TRA' WHERE itemnumber = ?";
547 my $sth=$dbh->prepare($query);
548 $sth->execute($itemnumber);