2 # Please use 8-character tabs for this file (indents are 4 spaces)
4 #written 11/3/2002 by Finlay
5 #script to execute returns of books
8 # Copyright 2000-2002 Katipo Communications
10 # This file is part of Koha.
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA 02111-1307 USA
27 use C4::Circulation::Circ2;
33 use C4::Interface::CGI::Output;
39 my ($template, $borrowernumber, $cookie)
40 = get_template_and_user({template_name => "circ/returns.tmpl",
44 flagsrequired => {parameters => 1},
50 my $headerbackgroundcolor='#99cc33';
51 my $circbackgroundcolor='#ffffcc';
52 my $circbackgroundcolor='white';
53 my $linecolor1='#ffffcc';
54 my $linecolor2='white';
55 my $backgroundimage="/images/background-mem.gif";
57 my $branches = getbranches();
58 my $printers = getprinters(\%env);
60 my $branch = getbranch($query, $branches);
61 my $printer = getprinter($query, $printers);
64 # 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;
73 # Set up the item stack ....
78 foreach ($query->param) {
79 (next) unless (/ri-(\d*)/);
82 (next) if ($counter>20);
83 my $barcode=$query->param("ri-$counter");
84 my $duedate=$query->param("dd-$counter");
85 my $borrowernumber=$query->param("bn-$counter");
88 $barcode = cuecatbarcodedecode($barcode);
89 ######################
90 #Are these lines still useful ?
91 $returneditems{$counter}=$barcode;
92 $riduedate{$counter}=$duedate;
93 $riborrowernumber{$counter}=$borrowernumber;
94 #######################
95 $input{counter}=$counter;
96 $input{barcode}=$barcode;
97 $input{duedate}=$duedate;
98 $input{bornum}=$borrowernumber;
99 push (@inputloop, \%input);
103 # Deal with the requests....
104 if ($query->param('resbarcode')) {
105 my $item = $query->param('itemnumber');
106 my $borrnum = $query->param('borrowernumber');
107 my $resbarcode = $query->param('resbarcode');
109 my $iteminfo = getiteminformation(\%env, $item);
110 my $tobranchcd = ReserveWaiting($item, $borrnum);
111 my $branchname = $branches->{$tobranchcd}->{'branchname'};
112 my ($borr) = getpatroninformation(\%env, $borrnum, 0);
113 my $borcnum=$borr->{'cardnumber'};
114 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
115 my $slip = $query->param('resslip');
116 printslip(\%env, $slip);
117 if ($tobranchcd ne $branch) {
118 $template->param( itemtitle => $iteminfo->{'title'},
119 iteminfo => $iteminfo->{'author'},
120 branchname => $branchname,
133 my $barcode = $query->param('barcode');
134 # actually return book and prepare item table.....
137 $barcode = cuecatbarcodedecode($barcode);
138 ($returned, $messages, $iteminformation, $borrower) = returnbook($barcode, $branch);
140 $returneditems{0} = $barcode;
141 $riborrowernumber{0} = $borrower->{'borrowernumber'};
142 $riduedate{0} = $iteminformation->{'date_due'};
146 $input{barcode}=$barcode;
147 $input{duedate}=$riduedate{0};
148 $input{bornum}=$riborrowernumber{0};
149 push (@inputloop, \%input);
150 } elsif (! $messages->{'BadBarcode'}) {
154 $input{barcode}=$barcode;
157 $returneditems{0} = $barcode;
159 if ($messages->{'wthdrawn'}) {
161 $input{bornum}="Item Cancelled";
162 $riborrowernumber{0} = 'Item Cancelled';
164 $input{bornum}=" ";
165 $riborrowernumber{0} = ' ';
167 push (@inputloop, \%input);
169 $template->param( returned => $returned,
170 itemtitle => $iteminformation->{'title'},
171 # itembc => $iteminformation->{'barcode'},
172 # itemdatedue => $iteminformation->{'datedue'},
173 itemauthor => $iteminformation->{'author'});
175 $template->param(inputloop => \@inputloop);
182 if ($messages->{'ResFound'}) {
183 my $res = $messages->{'ResFound'};
184 my $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
185 my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
186 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
187 my ($iteminfo) = getiteminformation(\%env, 0, $barcode);
189 if ($res->{'ResFound'} eq "Waiting") {
190 $template->param( found => 1,
192 bornum => $res->{'borrowernumber'},
193 borcnum => $borr->{'cardnumber'},
194 branchname => $branches->{$res->{'branchcode'}}->{'branchname'},
196 itemtitle => $iteminfo->{'title'},
197 itemauthor => $iteminfo->{'author'});
200 if ($res->{'ResFound'} eq "Reserved") {
201 my @da = localtime(time());
202 my $todaysdate = sprintf ("%0.2d", ($da[3]+1))."/".sprintf ("%0.2d", ($da[4]+1))."/".($da[5]+1900);
203 $template->param( found => 1,
204 branchname => $branches->{$res->{'branchcode'}}->{'branchname'},
206 today => $todaysdate,
207 itemnum => $res->{'itemnumber'},
208 itemtitle => $iteminfo->{'title'},
209 itemauthor => $iteminfo->{'author'},
210 itembarcode => $iteminfo->{'barcode'},
211 itemtype => $iteminfo->{'itemtype'},
212 itembiblionumber => $iteminfo->{'biblionumber'},
213 borsurname => $borr->{'surname'},
214 bortitle => $borr->{'title'},
215 borfirstname => $borr->{'firstname'},
216 bornum => $res->{'borrowernumber'},
217 borcnum => $borr->{'cardnumber'},
218 borphone => $borr->{'phone'},
219 borstraddress => $borr->{'streetaddress'},
220 borsub => $borr->{'suburb'},
221 bortown => $borr->{'town'},
222 boremail => $borr->{'emailadress'},
230 foreach my $code (keys %$messages) {
233 if ($code eq 'BadBarcode'){
235 $err{msg}= $messages->{'BadBarcode'};
237 if ($code eq 'NotIssued'){
239 $err{msg}= $branches->{$messages->{'IsPermanent'}}->{'branchname'};
241 if ($code eq 'WasLost'){
244 if ($code eq 'wthdrawn'){
248 if (($code eq 'IsPermanent') && (not $messages->{'ResFound'})) {
249 if ($messages->{'IsPermanent'} ne $branch) {
251 $err{msg}=$branches->{$messages->{'IsPermanent'}}->{'branchname'} ;
254 push (@errmsgloop, \%err);
256 $template->param(errmsgloop => \@errmsgloop);
260 my $flags = $borrower->{'flags'};
264 foreach my $flag (sort keys %$flags) {
266 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
267 unless($flagset) { $flagset=1; }
268 $flaginfo{color}=$color;
269 $flaginfo{redfont} =($flags->{$flag}->{'noissues'});
270 $flaginfo{flag}=$flag;
271 if ($flag eq 'CHARGES') {
272 $flaginfo{msg}=$flag;
273 $flaginfo{charges}=1;
274 } elsif ($flag eq 'WAITING') {
275 $flaginfo{msg}=$flag;
276 $flaginfo{waiting}=1;
278 my $items = $flags->{$flag}->{'itemlist'};
279 foreach my $item (@$items) {
280 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
282 $waitingitem{biblionum}=$iteminformation->{'biblionumber'};
283 $waitingitem{barcode}=$iteminformation->{'barcode'};
284 $waitingitem{title}=$iteminformation->{'title'};
285 $waitingitem{brname}=$branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
286 push(@waitingitemloop, \%waitingitem);
288 $flaginfo{itemloop}=\@waitingitemloop;
289 } elsif ($flag eq 'ODUES') {
290 my $items = $flags->{$flag}->{'itemlist'};
292 foreach my $item (sort {$a->{'date_due'} cmp $b->{'date_due'}} @$items) {
293 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
295 $overdueitem{duedate}=$item->{'date_due'};
296 $overdueitem{biblionum}=$iteminformation->{'biblionumber'};
297 $overdueitem{barcode}=$iteminformation->{'barcode'};
298 $overdueitem{title}=$iteminformation->{'title'};
299 $overdueitem{brname}=$branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
300 push(@itemloop, \%overdueitem);
302 $flaginfo{itemloop}=\@itemloop;
303 $flaginfo{overdue}=1;
306 $flaginfo{msg}=$flags->{$flag}->{'message'};
308 push(@flagloop, \%flaginfo);
310 $template->param( flagset => $flagset,
311 flagloop => \@flagloop,
312 ribornum => $borrower->{'borrowernumber'},
313 riborcnum => $borrower->{'cardnumber'},
314 riborsurname => $borrower->{'surname'},
315 ribortitle => $borrower->{'title'},
316 riborfirstname => $borrower->{'firstname'}
321 #set up so only the lat 8 returned items display (make for faster loading pages)
324 foreach (sort {$a <=> $b} keys %returneditems) {
327 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
329 my $barcode = $returneditems{$_};
330 my $duedate = $riduedate{$_};
334 my @tempdate = split ( /-/ , $duedate ) ;
335 my $duedatenz = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
336 my @datearr = localtime(time());
337 my $todaysdate = $datearr[5].'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
338 my ($borrower) = getpatroninformation(\%env, $riborrowernumber{$_}, 0);
339 $ri{bornum}=$borrower->{'borrowernumber'};
340 $ri{borcnum}=$borrower->{'cardnumber'};
341 $ri{borfirstname}=$borrower->{'firstname'};
342 $ri{borsurname}=$borrower->{'surname'};
343 $ri{bortitle}=$borrower->{'title'};
345 $ri{bornum}=$riborrowernumber{$_};
348 my ($iteminformation) = getiteminformation(\%env, 0, $barcode);
350 $ri{itembiblionumber}=$iteminformation->{'biblionumber'};
351 $ri{itemtitle}=$iteminformation->{'title'};
352 $ri{itemauthor}=$iteminformation->{'author'};
353 $ri{itemtype}=$iteminformation->{'itemtype'};
354 $ri{barcode}=$barcode;
361 $template->param(riloop => \@riloop);
363 $template->param( genbrname => $branches->{$branch}->{'branchname'},
364 genprname => $printers->{$printer}->{'printername'},
367 hdrbckgdcolor => $headerbackgroundcolor,
368 bckgdimg => $backgroundimage,
369 errmsgloop => \@errmsgloop
372 # actually print the page!
373 output_html_with_http_headers $query, $cookie, $template->output;
375 sub cuecatbarcodedecode {
378 my @fields = split(/\./,$barcode);
379 my @results = map(decode($_), @fields[1..$#fields]);