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;
34 use C4::Interface::CGI::Output;
41 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
43 template_name => "circ/returns.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.....
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 );
122 if ( $tobranchcd ne $branch ) {
124 itemtitle => $iteminfo->{'title'},
125 iteminfo => $iteminfo->{'author'},
126 branchname => $branchname,
139 my $barcode = $query->param('barcode');
141 # actually return book and prepare item table.....
145 $barcode = cuecatbarcodedecode($barcode);
146 ( $returned, $messages, $iteminformation, $borrower ) =
147 returnbook( $barcode, $branch );
149 $returneditems{0} = $barcode;
150 $riborrowernumber{0} = $borrower->{'borrowernumber'};
151 $riduedate{0} = $iteminformation->{'date_due'};
155 $input{barcode} = $barcode;
156 $input{duedate} = $riduedate{0};
157 $input{bornum} = $riborrowernumber{0};
158 push ( @inputloop, \%input );
160 elsif ( !$messages->{'BadBarcode'} ) {
164 $input{barcode} = $barcode;
167 $returneditems{0} = $barcode;
169 if ( $messages->{'wthdrawn'} ) {
170 $input{withdrawn} = 1;
171 $input{bornum} = "Item Cancelled";
172 $riborrowernumber{0} = 'Item Cancelled';
175 $input{bornum} = " ";
176 $riborrowernumber{0} = ' ';
178 push ( @inputloop, \%input );
181 returned => $returned,
182 itemtitle => $iteminformation->{'title'},
184 # itembc => $iteminformation->{'barcode'},
185 # itemdatedue => $iteminformation->{'datedue'},
186 itemauthor => $iteminformation->{'author'}
189 $template->param( inputloop => \@inputloop );
195 if ( $messages->{'ResFound'} ) {
196 my $res = $messages->{'ResFound'};
197 my $branchname = $branches->{ $res->{'branchcode'} }->{'branchname'};
198 my ($borr) = getpatroninformation( \%env, $res->{'borrowernumber'}, 0 );
200 $borr->{'surname'} . " " . $borr->{'title'} . " " . $borr->{'firstname'};
201 my ($iteminfo) = getiteminformation( \%env, 0, $barcode );
203 if ( $res->{'ResFound'} eq "Waiting" ) {
207 borfirstname => $borr->{'firstname'},
208 borsurname => $borr->{'surname'},
209 bortitle => $borr->{'title'},
210 borphone => $borr->{'phone'},
211 borstraddress => $borr->{'streetaddress'},
212 borcity => $borr->{'city'},
213 borzip => $borr->{'zipcode'},
214 bornum => $res->{'borrowernumber'},
215 borcnum => $borr->{'cardnumber'},
216 branchname => $branches->{ $res->{'branchcode'} }->{'branchname'},
218 itemnumber => $res->{'itemnumber'},
219 itemtitle => $iteminfo->{'title'},
220 itemauthor => $iteminfo->{'author'},
221 itembarcode => $iteminfo->{'barcode'},
222 itemtype => $iteminfo->{'itemtype'},
223 itembiblionumber => $iteminfo->{'biblionumber'}
227 if ( $res->{'ResFound'} eq "Reserved" ) {
228 my @da = localtime( time() );
230 sprintf( "%0.2d", ( $da[3] + 1 ) ) . "/"
231 . sprintf( "%0.2d", ( $da[4] + 1 ) ) . "/"
235 branchname => $branches->{ $res->{'branchcode'} }->{'branchname'},
237 today => $todaysdate,
238 itemnumber => $res->{'itemnumber'},
239 itemtitle => $iteminfo->{'title'},
240 itemauthor => $iteminfo->{'author'},
241 itembarcode => $iteminfo->{'barcode'},
242 itemtype => $iteminfo->{'itemtype'},
243 itembiblionumber => $iteminfo->{'biblionumber'},
244 borsurname => $borr->{'surname'},
245 bortitle => $borr->{'title'},
246 borfirstname => $borr->{'firstname'},
247 bornum => $res->{'borrowernumber'},
248 borcnum => $borr->{'cardnumber'},
249 borphone => $borr->{'phone'},
250 borstraddress => $borr->{'streetaddress'},
251 borsub => $borr->{'suburb'},
252 borcity => $borr->{'city'},
253 borzip => $borr->{'zipcode'},
254 boremail => $borr->{'emailadress'},
262 foreach my $code ( keys %$messages ) {
266 my $exit_required_p = 0;
267 if ( $code eq 'BadBarcode' ) {
268 $err{badbarcode} = 1;
269 $err{msg} = $messages->{'BadBarcode'};
271 elsif ( $code eq 'NotIssued' ) {
273 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
275 elsif ( $code eq 'WasLost' ) {
278 elsif ( $code eq 'ResFound' ) {
279 ; # FIXME... anything to do here?
281 elsif ( $code eq 'WasReturned' ) {
282 ; # FIXME... anything to do here?
284 elsif ( $code eq 'WasTransfered' ) {
285 ; # FIXME... anything to do here?
287 elsif ( $code eq 'wthdrawn' ) {
289 $exit_required_p = 1;
291 elsif ( ( $code eq 'IsPermanent' ) && ( not $messages->{'ResFound'} ) ) {
292 if ( $messages->{'IsPermanent'} ne $branch ) {
293 $err{ispermanent} = 1;
295 $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
299 die "Unknown error code $code"; # XXX
302 push ( @errmsgloop, \%err );
304 last if $exit_required_p;
306 $template->param( errmsgloop => \@errmsgloop );
310 my $flags = $borrower->{'flags'};
314 foreach my $flag ( sort keys %$flags ) {
316 ( $color eq $linecolor1 )
317 ? ( $color = $linecolor2 )
318 : ( $color = $linecolor1 );
319 unless ($flagset) { $flagset = 1; }
320 $flaginfo{color} = $color;
321 $flaginfo{redfont} = ( $flags->{$flag}->{'noissues'} );
322 $flaginfo{flag} = $flag;
323 if ( $flag eq 'CHARGES' ) {
324 $flaginfo{msg} = $flag;
325 $flaginfo{charges} = 1;
327 elsif ( $flag eq 'WAITING' ) {
328 $flaginfo{msg} = $flag;
329 $flaginfo{waiting} = 1;
331 my $items = $flags->{$flag}->{'itemlist'};
332 foreach my $item (@$items) {
333 my ($iteminformation) =
334 getiteminformation( \%env, $item->{'itemnumber'}, 0 );
336 $waitingitem{biblionum} = $iteminformation->{'biblionumber'};
337 $waitingitem{barcode} = $iteminformation->{'barcode'};
338 $waitingitem{title} = $iteminformation->{'title'};
339 $waitingitem{brname} =
340 $branches->{ $iteminformation->{'holdingbranch'} }->{
342 push ( @waitingitemloop, \%waitingitem );
344 $flaginfo{itemloop} = \@waitingitemloop;
346 elsif ( $flag eq 'ODUES' ) {
347 my $items = $flags->{$flag}->{'itemlist'};
349 foreach my $item ( sort { $a->{'date_due'} cmp $b->{'date_due'} }
352 my ($iteminformation) =
353 getiteminformation( \%env, $item->{'itemnumber'}, 0 );
355 $overdueitem{duedate} = $item->{'date_due'};
356 $overdueitem{biblionum} = $iteminformation->{'biblionumber'};
357 $overdueitem{barcode} = $iteminformation->{'barcode'};
358 $overdueitem{title} = $iteminformation->{'title'};
359 $overdueitem{brname} =
360 $branches->{ $iteminformation->{'holdingbranch'} }->{
362 push ( @itemloop, \%overdueitem );
364 $flaginfo{itemloop} = \@itemloop;
365 $flaginfo{overdue} = 1;
368 $flaginfo{other} = 1;
369 $flaginfo{msg} = $flags->{$flag}->{'message'};
371 push ( @flagloop, \%flaginfo );
375 flagloop => \@flagloop,
376 ribornum => $borrower->{'borrowernumber'},
377 riborcnum => $borrower->{'cardnumber'},
378 riborsurname => $borrower->{'surname'},
379 ribortitle => $borrower->{'title'},
380 riborfirstname => $borrower->{'firstname'}
386 #set up so only the last 8 returned items display (make for faster loading pages)
389 foreach ( sort { $a <=> $b } keys %returneditems ) {
392 ( $color eq $linecolor1 )
393 ? ( $color = $linecolor2 )
394 : ( $color = $linecolor1 );
396 my $barcode = $returneditems{$_};
397 my $duedate = $riduedate{$_};
401 my @tempdate = split ( /-/, $duedate );
402 $ri{year}=$tempdate[0];
403 $ri{month}=$tempdate[1];
404 $ri{day}=$tempdate[2];
405 my $duedatenz = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
406 my @datearr = localtime( time() );
409 . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
410 . sprintf( "%0.2d", $datearr[3] );
411 $ri{duedate}=$duedate;
413 getpatroninformation( \%env, $riborrowernumber{$_}, 0 );
414 $ri{bornum} = $borrower->{'borrowernumber'};
415 $ri{borcnum} = $borrower->{'cardnumber'};
416 $ri{borfirstname} = $borrower->{'firstname'};
417 $ri{borsurname} = $borrower->{'surname'};
418 $ri{bortitle} = $borrower->{'title'};
421 $ri{bornum} = $riborrowernumber{$_};
424 my ($iteminformation) = getiteminformation( \%env, 0, $barcode );
426 $ri{itembiblionumber} = $iteminformation->{'biblionumber'};
427 $ri{itemtitle} = $iteminformation->{'title'};
428 $ri{itemauthor} = $iteminformation->{'author'};
429 $ri{itemtype} = $iteminformation->{'itemtype'};
430 $ri{barcode} = $barcode;
436 push ( @riloop, \%ri );
438 $template->param( riloop => \@riloop );
441 genbrname => $branches->{$branch}->{'branchname'},
442 genprname => $printers->{$printer}->{'printername'},
445 errmsgloop => \@errmsgloop
448 # actually print the page!
449 output_html_with_http_headers $query, $cookie, $template->output;
451 sub cuecatbarcodedecode {
454 my @fields = split ( /\./, $barcode );
455 my @results = map( decode($_), @fields[ 1 .. $#fields ] );
456 if ( $#results == 2 ) {