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
10 # Copyright 2000-2002 Katipo Communications
12 # This file is part of Koha.
14 # Koha is free software; you can redistribute it and/or modify it under the
15 # terms of the GNU General Public License as published by the Free Software
16 # Foundation; either version 2 of the License, or (at your option) any later
19 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
20 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
21 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License along with
24 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
25 # Suite 330, Boston, MA 02111-1307 USA
29 use C4::Circulation::Circ2;
35 use C4::Interface::CGI::Output;
41 my ($template, $borrowernumber, $cookie)
42 = get_template_and_user({template_name => "circ/returns.tmpl",
46 flagsrequired => {circulate => 1},
52 my $headerbackgroundcolor='#99cc33';
53 my $circbackgroundcolor='#ffffcc';
54 my $circbackgroundcolor='white';
55 my $linecolor1='#ffffcc';
56 my $linecolor2='white';
57 my $backgroundimage="/images/background-mem.gif";
59 my $branches = getbranches();
60 my $printers = getprinters(\%env);
62 my $branch = getbranch($query, $branches);
63 my $printer = getprinter($query, $printers);
66 # 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;
75 # Set up the item stack ....
80 foreach ($query->param) {
81 (next) unless (/ri-(\d*)/);
84 (next) if ($counter>20);
85 my $barcode=$query->param("ri-$counter");
86 my $duedate=$query->param("dd-$counter");
87 my $borrowernumber=$query->param("bn-$counter");
90 $barcode = cuecatbarcodedecode($barcode);
91 ######################
92 #Are these lines still useful ?
93 $returneditems{$counter}=$barcode;
94 $riduedate{$counter}=$duedate;
95 $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');
111 my $iteminfo = getiteminformation(\%env, $item);
112 my $tobranchcd = ReserveWaiting($item, $borrnum);
113 my $branchname = $branches->{$tobranchcd}->{'branchname'};
114 my ($borr) = getpatroninformation(\%env, $borrnum, 0);
115 my $borcnum=$borr->{'cardnumber'};
116 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
117 my $slip = $query->param('resslip');
118 printslip(\%env, $slip);
119 if ($tobranchcd ne $branch) {
120 $template->param( itemtitle => $iteminfo->{'title'},
121 iteminfo => $iteminfo->{'author'},
122 branchname => $branchname,
135 my $barcode = $query->param('barcode');
136 # actually return book and prepare item table.....
139 $barcode = cuecatbarcodedecode($barcode);
140 ($returned, $messages, $iteminformation, $borrower) = returnbook($barcode, $branch);
142 $returneditems{0} = $barcode;
143 $riborrowernumber{0} = $borrower->{'borrowernumber'};
144 $riduedate{0} = $iteminformation->{'date_due'};
148 $input{barcode}=$barcode;
149 $input{duedate}=$riduedate{0};
150 $input{bornum}=$riborrowernumber{0};
151 push (@inputloop, \%input);
152 } elsif (! $messages->{'BadBarcode'}) {
156 $input{barcode}=$barcode;
159 $returneditems{0} = $barcode;
161 if ($messages->{'wthdrawn'}) {
163 $input{bornum}="Item Cancelled";
164 $riborrowernumber{0} = 'Item Cancelled';
166 $input{bornum}=" ";
167 $riborrowernumber{0} = ' ';
169 push (@inputloop, \%input);
171 $template->param( returned => $returned,
172 itemtitle => $iteminformation->{'title'},
173 # itembc => $iteminformation->{'barcode'},
174 # itemdatedue => $iteminformation->{'datedue'},
175 itemauthor => $iteminformation->{'author'});
177 $template->param(inputloop => \@inputloop);
184 if ($messages->{'ResFound'}) {
185 my $res = $messages->{'ResFound'};
186 my $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
187 my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
188 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
189 my ($iteminfo) = getiteminformation(\%env, 0, $barcode);
191 if ($res->{'ResFound'} eq "Waiting") {
192 $template->param( found => 1,
194 bornum => $res->{'borrowernumber'},
195 borcnum => $borr->{'cardnumber'},
196 branchname => $branches->{$res->{'branchcode'}}->{'branchname'},
198 itemtitle => $iteminfo->{'title'},
199 itemauthor => $iteminfo->{'author'});
202 if ($res->{'ResFound'} eq "Reserved") {
203 my @da = localtime(time());
204 my $todaysdate = sprintf ("%0.2d", ($da[3]+1))."/".sprintf ("%0.2d", ($da[4]+1))."/".($da[5]+1900);
205 $template->param( found => 1,
206 branchname => $branches->{$res->{'branchcode'}}->{'branchname'},
208 today => $todaysdate,
209 itemnum => $res->{'itemnumber'},
210 itemtitle => $iteminfo->{'title'},
211 itemauthor => $iteminfo->{'author'},
212 itembarcode => $iteminfo->{'barcode'},
213 itemtype => $iteminfo->{'itemtype'},
214 itembiblionumber => $iteminfo->{'biblionumber'},
215 borsurname => $borr->{'surname'},
216 bortitle => $borr->{'title'},
217 borfirstname => $borr->{'firstname'},
218 bornum => $res->{'borrowernumber'},
219 borcnum => $borr->{'cardnumber'},
220 borphone => $borr->{'phone'},
221 borstraddress => $borr->{'streetaddress'},
222 borsub => $borr->{'suburb'},
223 bortown => $borr->{'town'},
224 boremail => $borr->{'emailadress'},
232 foreach my $code (keys %$messages) {
235 my $exit_required_p = 0;
236 if ($code eq 'BadBarcode'){
238 $err{msg}= $messages->{'BadBarcode'};
239 } elsif ($code eq 'NotIssued'){
241 $err{msg}= $branches->{$messages->{'IsPermanent'}}->{'branchname'};
242 } elsif ($code eq 'WasLost'){
244 } elsif ($code eq 'WasReturned'){
245 ; # FIXME... anything to do here?
246 } elsif ($code eq 'WasTransfered'){
247 ; # FIXME... anything to do here?
248 } elsif ($code eq 'wthdrawn'){
250 $exit_required_p = 1;
251 } elsif (($code eq 'IsPermanent') && (not $messages->{'ResFound'})) {
252 if ($messages->{'IsPermanent'} ne $branch) {
254 $err{msg}=$branches->{$messages->{'IsPermanent'}}->{'branchname'} ;
257 die "Unknown error code $code"; # XXX
259 push (@errmsgloop, \%err);
260 last if $exit_required_p;
262 $template->param(errmsgloop => \@errmsgloop);
266 my $flags = $borrower->{'flags'};
270 foreach my $flag (sort keys %$flags) {
272 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
273 unless($flagset) { $flagset=1; }
274 $flaginfo{color}=$color;
275 $flaginfo{redfont} =($flags->{$flag}->{'noissues'});
276 $flaginfo{flag}=$flag;
277 if ($flag eq 'CHARGES') {
278 $flaginfo{msg}=$flag;
279 $flaginfo{charges}=1;
280 } elsif ($flag eq 'WAITING') {
281 $flaginfo{msg}=$flag;
282 $flaginfo{waiting}=1;
284 my $items = $flags->{$flag}->{'itemlist'};
285 foreach my $item (@$items) {
286 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
288 $waitingitem{biblionum}=$iteminformation->{'biblionumber'};
289 $waitingitem{barcode}=$iteminformation->{'barcode'};
290 $waitingitem{title}=$iteminformation->{'title'};
291 $waitingitem{brname}=$branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
292 push(@waitingitemloop, \%waitingitem);
294 $flaginfo{itemloop}=\@waitingitemloop;
295 } elsif ($flag eq 'ODUES') {
296 my $items = $flags->{$flag}->{'itemlist'};
298 foreach my $item (sort {$a->{'date_due'} cmp $b->{'date_due'}} @$items) {
299 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
301 $overdueitem{duedate}=$item->{'date_due'};
302 $overdueitem{biblionum}=$iteminformation->{'biblionumber'};
303 $overdueitem{barcode}=$iteminformation->{'barcode'};
304 $overdueitem{title}=$iteminformation->{'title'};
305 $overdueitem{brname}=$branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
306 push(@itemloop, \%overdueitem);
308 $flaginfo{itemloop}=\@itemloop;
309 $flaginfo{overdue}=1;
312 $flaginfo{msg}=$flags->{$flag}->{'message'};
314 push(@flagloop, \%flaginfo);
316 $template->param( flagset => $flagset,
317 flagloop => \@flagloop,
318 ribornum => $borrower->{'borrowernumber'},
319 riborcnum => $borrower->{'cardnumber'},
320 riborsurname => $borrower->{'surname'},
321 ribortitle => $borrower->{'title'},
322 riborfirstname => $borrower->{'firstname'}
327 #set up so only the lat 8 returned items display (make for faster loading pages)
330 foreach (sort {$a <=> $b} keys %returneditems) {
333 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
335 my $barcode = $returneditems{$_};
336 my $duedate = $riduedate{$_};
340 my @tempdate = split ( /-/ , $duedate ) ;
341 my $duedatenz = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
342 my @datearr = localtime(time());
343 my $todaysdate = $datearr[5].'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
344 my ($borrower) = getpatroninformation(\%env, $riborrowernumber{$_}, 0);
345 $ri{bornum}=$borrower->{'borrowernumber'};
346 $ri{borcnum}=$borrower->{'cardnumber'};
347 $ri{borfirstname}=$borrower->{'firstname'};
348 $ri{borsurname}=$borrower->{'surname'};
349 $ri{bortitle}=$borrower->{'title'};
351 $ri{bornum}=$riborrowernumber{$_};
354 my ($iteminformation) = getiteminformation(\%env, 0, $barcode);
356 $ri{itembiblionumber}=$iteminformation->{'biblionumber'};
357 $ri{itemtitle}=$iteminformation->{'title'};
358 $ri{itemauthor}=$iteminformation->{'author'};
359 $ri{itemtype}=$iteminformation->{'itemtype'};
360 $ri{barcode}=$barcode;
367 $template->param(riloop => \@riloop);
369 $template->param( genbrname => $branches->{$branch}->{'branchname'},
370 genprname => $printers->{$printer}->{'printername'},
373 hdrbckgdcolor => $headerbackgroundcolor,
374 bckgdimg => $backgroundimage,
375 errmsgloop => \@errmsgloop
378 # actually print the page!
379 output_html_with_http_headers $query, $cookie, $template->output;
381 sub cuecatbarcodedecode {
384 my @fields = split(/\./,$barcode);
385 my @results = map(decode($_), @fields[1..$#fields]);