3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
22 script to execute returns of books
24 written 11/3/2002 by Finlay
39 use C4::Branch; # GetBranchName
40 use C4::Koha; # FIXME : is it still useful ?
45 my ( $template, $librarian, $cookie ) = get_template_and_user(
47 template_name => "circ/returns.tmpl",
51 flagsrequired => { circulate => 1 },
57 my $branches = GetBranches();
58 my $printers = GetPrinters();
60 #my $branch = C4::Context->userenv?C4::Context->userenv->{'branch'}:"";
61 my $printer = C4::Context->userenv?C4::Context->userenv->{'branchprinter'}:"";
64 # Some code to handle the error if there is no branch or printer setting.....
67 # Set up the item stack ....
72 foreach ( $query->param ) {
73 (next) unless (/ri-(\d*)/);
76 (next) if ( $counter > 20 );
77 my $barcode = $query->param("ri-$counter");
78 my $duedate = $query->param("dd-$counter");
79 my $borrowernumber = $query->param("bn-$counter");
83 $barcode = cuecatbarcodedecode($barcode);
85 ######################
86 #Are these lines still useful ?
87 $returneditems{$counter} = $barcode;
88 $riduedate{$counter} = $duedate;
89 $riborrowernumber{$counter} = $borrowernumber;
91 #######################
92 $input{counter} = $counter;
93 $input{barcode} = $barcode;
94 $input{duedate} = $duedate;
95 $input{borrowernumber} = $borrowernumber;
96 push( @inputloop, \%input );
100 # Deal with the requests....
102 if ($query->param('WT-itemNumber')){
103 updateWrongTransfer ($query->param('WT-itemNumber'),$query->param('WT-waitingAt'),$query->param('WT-From'));
107 if ( $query->param('resbarcode') ) {
108 my $item = $query->param('itemnumber');
109 my $borrowernumber = $query->param('borrowernumber');
110 my $resbarcode = $query->param('resbarcode');
111 my $diffBranchReturned = $query->param('diffBranch');
113 my $iteminfo = GetBiblioFromItemNumber($item);
116 # addin in ModReserveAffect the possibility to check if the document is expected in this library or not,
117 # if not we send a value in reserve waiting for not implementting waiting status
118 if ($diffBranchReturned) {
119 $diffBranchSend = $diffBranchReturned;
122 $diffBranchSend = undef;
125 ModReserveAffect( $item, $borrowernumber,$diffBranchSend);
126 # check if we have other reservs for this document, if we have a return send the message of transfer
127 my ( $messages, $nextreservinfo ) = GetOtherReserves($item);
129 my $branchname = GetBranchName( $messages->{'transfert'} );
130 my ($borr) = GetMemberDetails( $nextreservinfo, 0 );
131 my $borcnum = $borr->{'cardnumber'};
133 $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'};
134 my $slip = $query->param('resslip');
137 if ( $messages->{'transfert'} ) {
139 itemtitle => $iteminfo->{'title'},
140 iteminfo => $iteminfo->{'author'},
141 tobranchname => $branchname,
143 borrowernumber => $borrowernumber,
145 borfirstname => $borr->{'firstname'},
146 borsurname => $borr->{'surname'},
155 my $issueinformation;
156 my $barcode = $query->param('barcode');
158 # actually return book and prepare item table.....
161 $barcode = cuecatbarcodedecode($barcode);
165 ( $returned, $messages, $issueinformation, $borrower ) =
166 AddReturn( $barcode, C4::Context->userenv->{'branch'} );
167 # get biblio description
168 my $biblio = GetBiblioFromItemNumber($issueinformation->{'itemnumber'});
170 title => $biblio->{'title'},
171 homebranch => $biblio->{'homebranch'},
172 author => $biblio->{'author'},
173 itembarcode => $biblio->{'barcode'},
174 itemtype => $biblio->{'itemtype'},
175 ccode => $biblio->{'ccode'},
176 itembiblionumber => $biblio->{'biblionumber'},
179 $returneditems{0} = $barcode;
180 $riborrowernumber{0} = $borrower->{'borrowernumber'};
181 $riduedate{0} = $issueinformation->{'date_due'};
185 $input{barcode} = $barcode;
186 $input{duedate} = $riduedate{0};
187 $input{borrowernumber} = $riborrowernumber{0};
188 push( @inputloop, \%input );
190 # check if the branch is the same as homebranch
191 # if not, we want to put a message
192 if ( $biblio->{'homebranch'} ne C4::Context->userenv->{'branch'} ) {
193 $template->param( homebranch => $biblio->{'homebranch'} );
196 elsif ( !$messages->{'BadBarcode'} ) {
200 $input{barcode} = $barcode;
203 $returneditems{0} = $barcode;
205 if ( $messages->{'wthdrawn'} ) {
206 $input{withdrawn} = 1;
207 $input{borrowernumber} = "Item Cancelled";
208 $riborrowernumber{0} = 'Item Cancelled';
211 $input{borrowernumber} = " ";
212 $riborrowernumber{0} = ' ';
214 push( @inputloop, \%input );
217 $template->param( inputloop => \@inputloop );
223 # new op dev : we check if the document must be returned to his homebranch directly,
224 # if the document is transfered, we have warning message .
226 if ( $messages->{'WasTransfered'} ) {
234 # adding a case of wrong transfert, if the document wasn't transfered in the good library (according to branchtransfer (tobranch) BDD)
236 if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) {
239 TransferWaitingAt => $messages->{'WrongTransfer'},
240 WrongTransferItem => $messages->{'WrongTransferItem'},
243 my $reserve = $messages->{'ResFound'};
244 my $branchname = $branches->{ $reserve->{'branchcode'} }->{'branchname'};
245 my ($borr) = GetMemberDetails( $reserve->{'borrowernumber'}, 0 );
247 $borr->{'surname'} . " " . $borr->{'title'} . " " . $borr->{'firstname'};
250 wborfirstname => $borr->{'firstname'},
251 wborsurname => $borr->{'surname'},
252 wbortitle => $borr->{'title'},
253 wborphone => $borr->{'phone'},
254 wboremail => $borr->{'emailaddress'},
255 wborstraddress => $borr->{'streetaddress'},
256 wborcity => $borr->{'city'},
257 wborzip => $borr->{'zipcode'},
258 wborrowernumber => $reserve->{'borrowernumber'},
259 wborcnum => $borr->{'cardnumber'},
260 wtransfertFrom => C4::Context->userenv->{'branch'},
266 # reserve found and item arrived at the expected branch
268 if ( $messages->{'ResFound'} and not $messages->{'WrongTransfer'}) {
269 my $reserve = $messages->{'ResFound'};
270 my $branchname = $branches->{ $reserve->{'branchcode'} }->{'branchname'};
271 my ($borr) = GetMemberDetails( $reserve->{'borrowernumber'}, 0 );
272 if ( $reserve->{'ResFound'} eq "Waiting" ) {
273 if ( C4::Context->userenv->{'branch'} eq $reserve->{'branchcode'} ) {
274 $template->param( waiting => 1 );
277 $template->param( waiting => 0 );
282 name => $borr->{'surname'} . " " . $borr->{'title'} . " " . $borr->{'firstname'},
283 borfirstname => $borr->{'firstname'},
284 borsurname => $borr->{'surname'},
285 bortitle => $borr->{'title'},
286 borphone => $borr->{'phone'},
287 boremail => $borr->{'emailaddress'},
288 borstraddress => $borr->{'streetaddress'},
289 borcity => $borr->{'city'},
290 borzip => $borr->{'zipcode'},
291 borrowernumber => $reserve->{'borrowernumber'},
292 borcnum => $borr->{'cardnumber'},
293 debarred => $borr->{'debarred'},
294 gonenoaddress => $borr->{'gonenoaddress'},
295 currentbranch => $branches->{C4::Context->userenv->{'branch'}}->{'branchname'},
296 itemnumber => $reserve->{'itemnumber'},
300 if ( $reserve->{'ResFound'} eq "Reserved" ) {
301 my @da = localtime( time() );
303 sprintf( "%0.2d", ( $da[3] + 1 ) ) . "/"
304 . sprintf( "%0.2d", ( $da[4] + 1 ) ) . "/"
307 if ( C4::Context->userenv->{'branch'} eq $reserve->{'branchcode'} ) {
308 $template->param( intransit => 0 );
311 $template->param( intransit => 1 );
316 currentbranch => $branches->{C4::Context->userenv->{'branch'}}->{'branchname'},
318 $branches->{ $reserve->{'branchcode'} }->{'branchname'},
319 destbranch => $reserve->{'branchcode'},
320 transfertodo => ( C4::Context->userenv->{'branch'} eq $reserve->{'branchcode'} ? 0 : 1 ),
322 today => $todaysdate,
323 itemnumber => $reserve->{'itemnumber'},
324 borsurname => $borr->{'surname'},
325 bortitle => $borr->{'title'},
326 borfirstname => $borr->{'firstname'},
327 borrowernumber => $reserve->{'borrowernumber'},
328 borcnum => $borr->{'cardnumber'},
329 borphone => $borr->{'phone'},
330 borstraddress => $borr->{'streetaddress'},
331 borsub => $borr->{'suburb'},
332 borcity => $borr->{'city'},
333 borzip => $borr->{'zipcode'},
334 boremail => $borr->{'emailaddress'},
335 debarred => $borr->{'debarred'},
336 gonenoaddress => $borr->{'gonenoaddress'},
344 foreach my $code ( keys %$messages ) {
348 my $exit_required_p = 0;
349 if ( $code eq 'BadBarcode' ) {
350 $err{badbarcode} = 1;
351 $err{msg} = $messages->{'BadBarcode'};
353 elsif ( $code eq 'NotIssued' ) {
355 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
357 elsif ( $code eq 'WasLost' ) {
360 elsif ( $code eq 'ResFound' ) {
361 ; # FIXME... anything to do here?
363 elsif ( $code eq 'WasReturned' ) {
364 ; # FIXME... anything to do here?
366 elsif ( $code eq 'WasTransfered' ) {
367 ; # FIXME... anything to do here?
369 elsif ( $code eq 'wthdrawn' ) {
371 $exit_required_p = 1;
373 elsif ( ( $code eq 'IsPermanent' ) && ( not $messages->{'ResFound'} ) ) {
374 if ( $messages->{'IsPermanent'} ne C4::Context->userenv->{'branch'} ) {
375 $err{ispermanent} = 1;
377 $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
380 elsif ( $code eq 'WrongTransfer' ) {
381 ; # FIXME... anything to do here?
383 elsif ( $code eq 'WrongTransferItem' ) {
384 ; # FIXME... anything to do here?
387 die "Unknown error code $code"; # XXX
390 push( @errmsgloop, \%err );
392 last if $exit_required_p;
394 $template->param( errmsgloop => \@errmsgloop );
398 my $flags = $borrower->{'flags'};
401 foreach my $flag ( sort keys %$flags ) {
403 unless ($flagset) { $flagset = 1; }
404 $flaginfo{redfont} = ( $flags->{$flag}->{'noissues'} );
405 $flaginfo{flag} = $flag;
406 if ( $flag eq 'CHARGES' ) {
407 $flaginfo{msg} = $flag;
408 $flaginfo{charges} = 1;
409 $flaginfo{borrowernumber} = $borrower->{borrowernumber};
411 elsif ( $flag eq 'WAITING' ) {
412 $flaginfo{msg} = $flag;
413 $flaginfo{waiting} = 1;
415 my $items = $flags->{$flag}->{'itemlist'};
416 foreach my $item (@$items) {
418 GetBiblioFromItemNumber( $item->{'itemnumber'});
420 $waitingitem{biblionum} = $biblio->{'biblionumber'};
421 $waitingitem{barcode} = $biblio->{'barcode'};
422 $waitingitem{title} = $biblio->{'title'};
423 $waitingitem{brname} =
424 $branches->{ $biblio->{'holdingbranch'} }
426 push( @waitingitemloop, \%waitingitem );
428 $flaginfo{itemloop} = \@waitingitemloop;
430 elsif ( $flag eq 'ODUES' ) {
431 my $items = $flags->{$flag}->{'itemlist'};
433 foreach my $item ( sort { $a->{'date_due'} cmp $b->{'date_due'} }
437 GetBiblioFromItemNumber( $item->{'itemnumber'});
439 $overdueitem{duedate} = format_date( $item->{'date_due'} );
440 $overdueitem{biblionum} = $biblio->{'biblionumber'};
441 $overdueitem{barcode} = $biblio->{'barcode'};
442 $overdueitem{title} = $biblio->{'title'};
443 $overdueitem{brname} =
444 $branches->{ $biblio->{'holdingbranch'} }
446 push( @itemloop, \%overdueitem );
448 $flaginfo{itemloop} = \@itemloop;
449 $flaginfo{overdue} = 1;
452 $flaginfo{other} = 1;
453 $flaginfo{msg} = $flags->{$flag}->{'message'};
455 push( @flagloop, \%flaginfo );
459 flagloop => \@flagloop,
460 riborrowernumber => $borrower->{'borrowernumber'},
461 riborcnum => $borrower->{'cardnumber'},
462 riborsurname => $borrower->{'surname'},
463 ribortitle => $borrower->{'title'},
464 riborfirstname => $borrower->{'firstname'}
468 #set up so only the last 8 returned items display (make for faster loading pages)
471 foreach ( sort { $a <=> $b } keys %returneditems ) {
474 my $barcode = $returneditems{$_};
475 my $duedate = $riduedate{$_};
479 my @tempdate = split( /-/, $duedate );
480 $ri{year} = $tempdate[0];
481 $ri{month} = $tempdate[1];
482 $ri{day} = $tempdate[2];
483 my $duedatenz = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
484 my @datearr = localtime( time() );
487 . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
488 . sprintf( "%0.2d", $datearr[3] );
489 $ri{duedate} = format_date($duedate);
491 GetMemberDetails( $riborrowernumber{$_}, 0 );
492 $ri{borrowernumber} = $borrower->{'borrowernumber'};
493 $ri{borcnum} = $borrower->{'cardnumber'};
494 $ri{borfirstname} = $borrower->{'firstname'};
495 $ri{borsurname} = $borrower->{'surname'};
496 $ri{bortitle} = $borrower->{'title'};
499 $ri{borrowernumber} = $riborrowernumber{$_};
503 my $biblio = GetBiblioFromItemNumber(GetItemnumberFromBarcode($barcode));
504 $ri{itembiblionumber} = $biblio->{'biblionumber'};
505 $ri{itemtitle} = $biblio->{'title'};
506 $ri{itemauthor} = $biblio->{'author'};
507 $ri{itemtype} = $biblio->{'itemtype'};
508 $ri{ccode} = $biblio->{'ccode'};
509 $ri{barcode} = $barcode;
515 push( @riloop, \%ri );
517 $template->param( riloop => \@riloop );
520 genbrname => $branches->{C4::Context->userenv->{'branch'}}->{'branchname'},
521 genprname => $printers->{$printer}->{'printername'},
522 branchname => $branches->{C4::Context->userenv->{'branch'}}->{'branchname'},
524 errmsgloop => \@errmsgloop,
525 intranetcolorstylesheet =>
526 C4::Context->preference("intranetcolorstylesheet"),
527 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
528 IntranetNav => C4::Context->preference("IntranetNav"),
531 # actually print the page!
532 output_html_with_http_headers $query, $cookie, $template->output;