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::Circ3;
34 use C4::Interface::CGI::Output;
41 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
43 template_name => "circ/resreturns.tmpl",
47 flagsrequired => { circulate => 1 },
54 my $headerbackgroundcolor = '#99cc33';
55 my $linecolor1 = '#ffffcc';
56 my $linecolor2 = 'white';
58 my $branches = getbranches();
59 my $printers = getprinters( \%env );
61 # my $branch = getbranch( $query, $branches );
62 my $printer = getprinter( $query, $printers );
65 # Some code to handle the error if there is no branch or printer setting.....
67 my $branch=C4::Context->preference("defaultBranch");
68 $env{'branchcode'} = $branch;
69 $env{'printer'} = $printer;
70 $env{'queue'} = $printer;
72 # Set up the item stack ....
77 foreach ( $query->param ) {
78 (next) unless (/ri-(\d*)/);
81 (next) if ( $counter > 20 );
82 my $barcode = $query->param("ri-$counter");
83 my $duedate = $query->param("dd-$counter");
84 my $borrowernumber = $query->param("bn-$counter");
88 $barcode = cuecatbarcodedecode($barcode);
90 ######################
91 #Are these lines still useful ?
92 $returneditems{$counter} = $barcode;
93 $riduedate{$counter} = $duedate;
94 $riborrowernumber{$counter} = $borrowernumber;
96 #######################
97 $input{counter} = $counter;
98 $input{barcode} = $barcode;
99 $input{duedate} = $duedate;
100 $input{bornum} = $borrowernumber;
101 push ( @inputloop, \%input );
105 # Deal with the requests....
106 if ( $query->param('resbarcode') ) {
107 my $item = $query->param('itemnumber');
108 my $borrnum = $query->param('borrowernumber');
109 my $resbarcode = $query->param('resbarcode');
112 my $iteminfo = getiteminformation( \%env, $item );
113 my $tobranchcd = ReserveWaiting( $item, $borrnum );
114 my $branchname = $branches->{$tobranchcd}->{'branchname'};
115 my ($borr) = getpatroninformation( \%env, $borrnum, 0 );
116 my $borcnum = $borr->{'cardnumber'};
118 $borr->{'surname'} . " " . $borr->{'title'} . " " . $borr->{'firstname'};
119 my $slip = $query->param('resslip');
120 printslip( \%env, $slip ); #removed by paul
122 if ( $tobranchcd ne $branch ) {
124 itemtitle => $iteminfo->{'title'},
125 iteminfo => $iteminfo->{'author'},
126 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'} ) {
162 if ( $messages->{'NotIssued'} ) {
163 my $dbh = C4::Context->dbh;
164 my $sth=$dbh->prepare("select date_due from issues where itemnumber=? and isnull(returndate)");
165 $sth->execute($iteminformation->{'itemnumber'});
166 my ($date_due) = $sth->fetchrow;
170 print $query->redirect("/cgi-bin/koha/circ/returns.pl?barcode=$barcode");
176 $input{barcode} = $barcode;
179 $returneditems{0} = $barcode;
181 if ( $messages->{'wthdrawn'} ) {
182 $input{withdrawn} = 1;
183 $input{bornum} = "Item Cancelled";
184 $riborrowernumber{0} = 'Item Cancelled';
187 $input{bornum} = " ";
188 $riborrowernumber{0} = ' ';
190 push ( @inputloop, \%input );
193 returned => $returned,
194 itemtitle => $iteminformation->{'title'},
196 # itembc => $iteminformation->{'barcode'},
197 # itemdatedue => $iteminformation->{'date_due'},
198 itemauthor => $iteminformation->{'author'}
201 $template->param( inputloop => \@inputloop );
207 if ( $messages->{'ResFound'} ) {
208 my $res = $messages->{'ResFound'};
209 my $branchname = $branches->{ $res->{'branchcode'} }->{'branchname'};
210 my ($borr) = getpatroninformation( \%env, $res->{'borrowernumber'}, 0 );
212 $borr->{'surname'} . " " . $borr->{'title'} . " " . $borr->{'firstname'};
213 my ($iteminfo) = getiteminformation( \%env, 0, $barcode );
215 if ( $res->{'ResFound'} eq "Waiting" ) {
219 borfirstname => $borr->{'firstname'},
220 borsurname => $borr->{'surname'},
221 bortitle => $borr->{'title'},
222 borphone => $borr->{'phone'},
223 borstraddress => $borr->{'streetaddress'},
224 borcity => $borr->{'city'},
225 borzip => $borr->{'zipcode'},
226 bornum => $res->{'borrowernumber'},
227 borcnum => $borr->{'cardnumber'},
228 branchname => $branches->{ $res->{'branchcode'} }->{'branchname'},
230 itemnumber => $res->{'itemnumber'},
231 itemtitle => $iteminfo->{'title'},
232 itemauthor => $iteminfo->{'author'},
233 itembarcode => $iteminfo->{'barcode'},
234 itemtype => $iteminfo->{'itemtype'},
235 itembiblionumber => $iteminfo->{'biblionumber'}
239 if ( $res->{'ResFound'} eq "Reserved" ) {
240 my @da = localtime( time() );
242 sprintf( "%0.2d", ( $da[3] + 1 ) ) . "/"
243 . sprintf( "%0.2d", ( $da[4] + 1 ) ) . "/"
247 branchname => $branches->{ $res->{'branchcode'} }->{'branchname'},
249 today => $todaysdate,
250 itemnumber => $res->{'itemnumber'},
251 itemtitle => $iteminfo->{'title'},
252 itemauthor => $iteminfo->{'author'},
253 itembarcode => $iteminfo->{'barcode'},
254 itemtype => $iteminfo->{'itemtype'},
255 itembiblionumber => $iteminfo->{'biblionumber'},
256 borsurname => $borr->{'surname'},
257 bortitle => $borr->{'title'},
258 borfirstname => $borr->{'firstname'},
259 bornum => $res->{'borrowernumber'},
260 borcnum => $borr->{'cardnumber'},
261 borphone => $borr->{'phone'},
262 borstraddress => $borr->{'streetaddress'},
263 borsub => $borr->{'suburb'},
264 borcity => $borr->{'city'},
265 borzip => $borr->{'zipcode'},
266 boremail => $borr->{'emailadress'},
274 foreach my $code ( keys %$messages ) {
278 my $exit_required_p = 0;
279 if ( $code eq 'BadBarcode' ) {
280 $err{badbarcode} = 1;
281 $err{msg} = $messages->{'BadBarcode'};
283 elsif ( $code eq 'NotIssued' ) {
285 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
287 elsif ( $code eq 'WasLost' ) {
290 elsif ( $code eq 'ResFound' ) {
291 ; # FIXME... anything to do here?
293 elsif ( $code eq 'WasReturned' ) {
294 ; # FIXME... anything to do here?
296 elsif ( $code eq 'WasTransfered' ) {
297 ; # FIXME... anything to do here?
299 elsif ( $code eq 'wthdrawn' ) {
301 $exit_required_p = 1;
303 elsif ( ( $code eq 'IsPermanent' ) && ( not $messages->{'ResFound'} ) ) {
304 if ( $messages->{'IsPermanent'} ne $branch ) {
305 $err{ispermanent} = 1;
307 $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
311 die "Unknown error code $code"; # XXX
314 push ( @errmsgloop, \%err );
316 last if $exit_required_p;
318 $template->param( errmsgloop => \@errmsgloop );
322 my $flags = $borrower->{'flags'};
326 foreach my $flag ( sort keys %$flags ) {
328 ( $color eq $linecolor1 )
329 ? ( $color = $linecolor2 )
330 : ( $color = $linecolor1 );
331 unless ($flagset) { $flagset = 1; }
332 $flaginfo{color} = $color;
333 $flaginfo{redfont} = ( $flags->{$flag}->{'noissues'} );
334 $flaginfo{flag} = $flag;
335 if ( $flag eq 'CHARGES' ) {
336 $flaginfo{msg} = $flag;
337 $flaginfo{charges} = 1;
338 $flaginfo{bornum} = $borrower->{borrowernumber};
340 elsif ( $flag eq 'WAITING' ) {
341 $flaginfo{msg} = $flag;
342 $flaginfo{waiting} = 1;
344 my $items = $flags->{$flag}->{'itemlist'};
345 foreach my $item (@$items) {
346 my ($iteminformation) =
347 getiteminformation( \%env, $item->{'itemnumber'}, 0 );
349 $waitingitem{biblionum} = $iteminformation->{'biblionumber'};
350 $waitingitem{barcode} = $iteminformation->{'barcode'};
351 $waitingitem{title} = $iteminformation->{'title'};
352 $waitingitem{brname} =
353 $branches->{ $iteminformation->{'holdingbranch'} }->{
355 push ( @waitingitemloop, \%waitingitem );
357 $flaginfo{itemloop} = \@waitingitemloop;
359 elsif ( $flag eq 'ODUES' ) {
360 my $items = $flags->{$flag}->{'itemlist'};
362 foreach my $item ( sort { $a->{'date_due'} cmp $b->{'date_due'} }
365 my ($iteminformation) =
366 getiteminformation( \%env, $item->{'itemnumber'}, 0 );
368 $overdueitem{duedate} = $item->{'date_due'};
369 $overdueitem{biblionum} = $iteminformation->{'biblionumber'};
370 $overdueitem{barcode} = $iteminformation->{'barcode'};
371 $overdueitem{title} = $iteminformation->{'title'};
372 $overdueitem{brname} =
373 $branches->{ $iteminformation->{'holdingbranch'} }->{
375 push ( @itemloop, \%overdueitem );
377 $flaginfo{itemloop} = \@itemloop;
378 $flaginfo{overdue} = 1;
381 $flaginfo{other} = 1;
382 $flaginfo{msg} = $flags->{$flag}->{'message'};
384 push ( @flagloop, \%flaginfo );
388 flagloop => \@flagloop,
389 ribornum => $borrower->{'borrowernumber'},
390 riborcnum => $borrower->{'cardnumber'},
391 riborsurname => $borrower->{'surname'},
392 ribortitle => $borrower->{'title'},
393 riborfirstname => $borrower->{'firstname'}
399 #set up so only the last 8 returned items display (make for faster loading pages)
402 foreach ( sort { $a <=> $b } keys %returneditems ) {
405 ( $color eq $linecolor1 )
406 ? ( $color = $linecolor2 )
407 : ( $color = $linecolor1 );
409 my $barcode = $returneditems{$_};
410 my $duedate = $riduedate{$_};
414 my @tempdate = split ( /-/, $duedate );
415 $ri{year}=$tempdate[0];
416 $ri{month}=$tempdate[1];
417 $ri{day}=$tempdate[2];
418 my $duedatenz = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
419 my @datearr = localtime( time() );
422 . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
423 . sprintf( "%0.2d", $datearr[3] );
424 $ri{duedate}=$duedate;
425 my ($borrower) = getpatroninformation( \%env, $riborrowernumber{$_}, 0 );
426 $ri{bornum} = $borrower->{'borrowernumber'};
427 $ri{borcnum} = $borrower->{'cardnumber'};
428 $ri{borfirstname} = $borrower->{'firstname'};
429 $ri{borsurname} = $borrower->{'surname'};
430 $ri{bortitle} = $borrower->{'title'};
433 $ri{bornum} = $riborrowernumber{$_};
436 my ($iteminformation) =C4::Circulation::Circ2::getiteminformation( \%env, 0, $barcode );
438 $ri{itembiblionumber} = $iteminformation->{'biblionumber'};
439 $ri{itemtitle} = $iteminformation->{'title'};
440 $ri{itemauthor} = $iteminformation->{'author'};
441 $ri{itemtype} = $iteminformation->{'itemtype'};
442 $ri{barcode} = $barcode;
448 push ( @riloop, \%ri );
450 $template->param( riloop => \@riloop );
453 genbrname => $branches->{$branch}->{'branchname'},
454 genprname => $printers->{$printer}->{'printername'},
457 errmsgloop => \@errmsgloop
460 # actually print the page!
461 output_html_with_http_headers $query, $cookie, $template->output;
463 sub cuecatbarcodedecode {
466 my @fields = split ( /\./, $barcode );
467 my @results = map( decode($_), @fields[ 1 .. $#fields ] );
468 if ( $#results == 2 ) {