3 #written 11/3/2002 by Finlay
4 #script to execute returns of books
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
26 use C4::Circulation::Circ2;
37 my ($template, $borrowernumber, $cookie)
38 = get_template_and_user({template_name => "circ/returns.tmpl",
42 flagsrequired => {parameters => 1},
48 my $headerbackgroundcolor='#99cc33';
49 my $circbackgroundcolor='#ffffcc';
50 my $circbackgroundcolor='white';
51 my $linecolor1='#ffffcc';
52 my $linecolor2='white';
53 my $backgroundimage="/images/background-mem.gif";
55 my $branches = getbranches();
56 my $printers = getprinters(\%env);
58 my $branch = $query->param("branch");
59 my $printer = $query->param("printer");
61 ($branch) || ($branch=$query->cookie('branch')) ;
62 ($printer) || ($printer=$query->cookie('printer')) ;
64 my $genbrname=$branches->{$branch}->{'branchname'};
65 my $genprname=$printers->{$printer}->{'printer'};
68 # Some code to handle the error if there is no branch or printer setting.....
72 $env{'branchcode'}=$branch;
73 $env{'printer'}=$printer;
74 $env{'queue'}=$printer;
77 # Set up the item stack ....
82 foreach ($query->param) {
83 (next) unless (/ri-(\d*)/);
86 (next) if ($counter>20);
87 my $barcode=$query->param("ri-$counter");
88 my $duedate=$query->param("dd-$counter");
89 my $borrowernumber=$query->param("bn-$counter");
92 $barcode = cuecatbarcodedecode($barcode);
93 ######################
94 #Are these lines still useful ?
95 $returneditems{$counter}=$barcode;
96 $riduedate{$counter}=$duedate;
97 $riborrowernumber{$counter}=$borrowernumber;
98 #######################
99 $input{counter}=$counter;
100 $input{barcode}=$barcode;
101 $input{duedate}=$duedate;
102 $input{bornum}=$borrowernumber;
103 push (@inputloop, \%input);
107 # Deal with the requests....
108 if ($query->param('resbarcode')) {
109 my $item = $query->param('itemnumber');
110 my $borrnum = $query->param('borrowernumber');
111 my $resbarcode = $query->param('resbarcode');
113 my $iteminfo = getiteminformation(\%env, $item);
114 my $tobranchcd = ReserveWaiting($item, $borrnum);
115 my $branchname = $branches->{$tobranchcd}->{'branchname'};
116 my ($borr) = getpatroninformation(\%env, $borrnum, 0);
117 my $borcnum=$borr->{'cardnumber'};
118 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
119 my $slip = $query->param('resslip');
120 printslip(\%env, $slip);
121 if ($tobranchcd ne $branch) {
122 $template->param( itemtitle => $iteminfo->{'title'},
123 iteminfo => $iteminfo->{'author'},
124 branchname => $branchname,
137 my $barcode = $query->param('barcode');
138 # actually return book and prepare item table.....
141 $barcode = cuecatbarcodedecode($barcode);
142 ($returned, $messages, $iteminformation, $borrower) = returnbook($barcode, $branch);
144 $returneditems{0} = $barcode;
145 $riborrowernumber{0} = $borrower->{'borrowernumber'};
146 $riduedate{0} = $iteminformation->{'date_due'};
150 $input{barcode}=$barcode;
151 $input{duedate}=$riduedate{0};
152 $input{bornum}=$riborrowernumber{0};
153 push (@inputloop, \%input);
154 } elsif (! $messages->{'BadBarcode'}) {
158 $input{barcode}=$barcode;
161 $returneditems{0} = $barcode;
163 if ($messages->{'wthdrawn'}) {
165 $input{bornum}="Item Cancelled";
166 $riborrowernumber{0} = 'Item Cancelled';
168 $input{bornum}=" ";
169 $riborrowernumber{0} = ' ';
171 push (@inputloop, \%input);
173 $template->param( returned => $returned,
174 itemtitle => $iteminformation->{'title'},
175 # itembc => $iteminformation->{'barcode'},
176 # itemdatedue => $iteminformation->{'datedue'},
177 itemauthor => $iteminformation->{'author'});
179 $template->param(inputloop => \@inputloop);
186 if ($messages->{'ResFound'}) {
187 my $res = $messages->{'ResFound'};
188 my $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
189 my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
190 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
191 my ($iteminfo) = getiteminformation(\%env, 0, $barcode);
193 if ($res->{'ResFound'} eq "Waiting") {
194 $template->param( found => 1,
196 bornum => $res->{'borrowernumber'},
197 borcnum => $borr->{'cardnumber'},
198 branchname => $branches->{$res->{'branchcode'}}->{'branchname'},
200 itemtitle => $iteminfo->{'title'},
201 itemauthor => $iteminfo->{'author'});
204 if ($res->{'ResFound'} eq "Reserved") {
205 my @da = localtime(time());
206 my $todaysdate = sprintf ("%0.2d", ($da[3]+1))."/".sprintf ("%0.2d", ($da[4]+1))."/".($da[5]+1900);
207 $template->param( found => 1,
208 branchname => $branches->{$res->{'branchcode'}}->{'branchname'},
210 today => $todaysdate,
211 itemnum => $res->{'itemnumber'},
212 itemtitle => $iteminfo->{'title'},
213 itemauthor => $iteminfo->{'author'},
214 itembarcode => $iteminfo->{'barcode'},
215 itemtype => $iteminfo->{'itemtype'},
216 itembiblionumber => $iteminfo->{'biblionumber'},
217 borsurname => $borr->{'surname'},
218 bortitle => $borr->{'title'},
219 borfirstname => $borr->{'firstname'},
220 bornum => $res->{'borrowernumber'},
221 borcnum => $borr->{'cardnumber'},
222 borphone => $borr->{'phone'},
223 borstraddress => $borr->{'streetaddress'},
224 borsub => $borr->{'suburb'},
225 bortown => $borr->{'town'},
226 boremail => $borr->{'emailadress'},
234 foreach my $code (keys %$messages) {
237 if ($code eq 'BadBarcode'){
239 $err{msg}= $messages->{'BadBarcode'};
241 if ($code eq 'NotIssued'){
243 $err{msg}= $branches->{$messages->{'IsPermanent'}}->{'branchname'};
245 if ($code eq 'WasLost'){
248 if ($code eq 'wthdrawn'){
252 if (($code eq 'IsPermanent') && (not $messages->{'ResFound'})) {
253 if ($messages->{'IsPermanent'} ne $branch) {
255 $err{msg}=$branches->{$messages->{'IsPermanent'}}->{'branchname'} ;
258 push (@errmsgloop, \%err);
260 $template->param(errmsgloop => \@errmsgloop);
264 my $flags = $borrower->{'flags'};
268 foreach my $flag (sort keys %$flags) {
270 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
271 unless($flagset) { $flagset=1; }
272 $flaginfo{color}=$color;
273 $flaginfo{redfont} =($flags->{$flag}->{'noissues'});
274 $flaginfo{flag}=$flag;
275 if ($flag eq 'CHARGES') {
276 $flaginfo{msg}=$flag;
277 $flaginfo{charges}=1;
278 } elsif ($flag eq 'WAITING') {
279 $flaginfo{msg}=$flag;
280 $flaginfo{waiting}=1;
282 my $items = $flags->{$flag}->{'itemlist'};
283 foreach my $item (@$items) {
284 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
286 $waitingitem{biblionum}=$iteminformation->{'biblionumber'};
287 $waitingitem{barcode}=$iteminformation->{'barcode'};
288 $waitingitem{title}=$iteminformation->{'title'};
289 $waitingitem{brname}=$branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
290 push(@waitingitemloop, \%waitingitem);
292 $flaginfo{itemloop}=\@waitingitemloop;
293 } elsif ($flag eq 'ODUES') {
294 my $items = $flags->{$flag}->{'itemlist'};
296 foreach my $item (sort {$a->{'date_due'} cmp $b->{'date_due'}} @$items) {
297 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
299 $overdueitem{duedate}=$item->{'date_due'};
300 $overdueitem{biblionum}=$iteminformation->{'biblionumber'};
301 $overdueitem{barcode}=$iteminformation->{'barcode'};
302 $overdueitem{title}=$iteminformation->{'title'};
303 $overdueitem{brname}=$branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
304 push(@itemloop, \%overdueitem);
306 $flaginfo{itemloop}=\@itemloop;
307 $flaginfo{overdue}=1;
310 $flaginfo{msg}=$flags->{$flag}->{'message'};
312 push(@flagloop, \%flaginfo);
314 $template->param( flagset => $flagset,
315 flagloop => \@flagloop,
316 ribornum => $borrower->{'borrowernumber'},
317 riborcnum => $borrower->{'cardnumber'},
318 riborsurname => $borrower->{'surname'},
319 ribortitle => $borrower->{'title'},
320 riborfirstname => $borrower->{'firstname'}
325 #set up so only the lat 8 returned items display (make for faster loading pages)
328 foreach (sort {$a <=> $b} keys %returneditems) {
331 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
333 my $barcode = $returneditems{$_};
334 my $duedate = $riduedate{$_};
338 my @tempdate = split ( /-/ , $duedate ) ;
339 my $duedatenz = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
340 my @datearr = localtime(time());
341 my $todaysdate = $datearr[5].'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
342 my ($borrower) = getpatroninformation(\%env, $riborrowernumber{$_}, 0);
343 $ri{bornum}=$borrower->{'borrowernumber'};
344 $ri{borcnum}=$borrower->{'cardnumber'};
345 $ri{borfirstname}=$borrower->{'firstname'};
346 $ri{borsurname}=$borrower->{'surname'};
347 $ri{bortitle}=$borrower->{'title'};
349 $ri{bornum}=$riborrowernumber{$_};
352 my ($iteminformation) = getiteminformation(\%env, 0, $barcode);
354 $ri{itembiblionumber}=$iteminformation->{'biblionumber'};
355 $ri{itemtitle}=$iteminformation->{'title'};
356 $ri{itemauthor}=$iteminformation->{'author'};
357 $ri{itemtype}=$iteminformation->{'itemtype'};
358 $ri{barcode}=$barcode;
365 $template->param(riloop => \@riloop);
367 $template->param( genbrname => $genbrname,
368 genprname => $genprname,
371 hdrbckgdcolor => $headerbackgroundcolor,
372 bckgdimg => $backgroundimage,
373 errmsgloop => \@errmsgloop
376 # actually print the page!
377 print $query->header(), $template->output;
379 sub cuecatbarcodedecode {
382 my @fields = split(/\./,$barcode);
383 my @results = map(decode($_), @fields[1..$#fields]);