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 $linecolor1='#ffffcc';
54 my $linecolor2='white';
56 my $branches = getbranches();
57 my $printers = getprinters(\%env);
59 my $branch = getbranch($query, $branches);
60 my $printer = getprinter($query, $printers);
63 # Some code to handle the error if there is no branch or printer setting.....
67 $env{'branchcode'}=$branch;
68 $env{'printer'}=$printer;
69 $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");
87 $barcode = cuecatbarcodedecode($barcode);
88 ######################
89 #Are these lines still useful ?
90 $returneditems{$counter}=$barcode;
91 $riduedate{$counter}=$duedate;
92 $riborrowernumber{$counter}=$borrowernumber;
93 #######################
94 $input{counter}=$counter;
95 $input{barcode}=$barcode;
96 $input{duedate}=$duedate;
97 $input{bornum}=$borrowernumber;
98 push (@inputloop, \%input);
102 # Deal with the requests....
103 if ($query->param('resbarcode')) {
104 my $item = $query->param('itemnumber');
105 my $borrnum = $query->param('borrowernumber');
106 my $resbarcode = $query->param('resbarcode');
108 my $iteminfo = getiteminformation(\%env, $item);
109 my $tobranchcd = ReserveWaiting($item, $borrnum);
110 my $branchname = $branches->{$tobranchcd}->{'branchname'};
111 my ($borr) = getpatroninformation(\%env, $borrnum, 0);
112 my $borcnum=$borr->{'cardnumber'};
113 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
114 my $slip = $query->param('resslip');
115 printslip(\%env, $slip);
116 if ($tobranchcd ne $branch) {
117 $template->param( itemtitle => $iteminfo->{'title'},
118 iteminfo => $iteminfo->{'author'},
119 branchname => $branchname,
132 my $barcode = $query->param('barcode');
133 # actually return book and prepare item table.....
136 $barcode = cuecatbarcodedecode($barcode);
137 ($returned, $messages, $iteminformation, $borrower) = returnbook($barcode, $branch);
139 $returneditems{0} = $barcode;
140 $riborrowernumber{0} = $borrower->{'borrowernumber'};
141 $riduedate{0} = $iteminformation->{'date_due'};
145 $input{barcode}=$barcode;
146 $input{duedate}=$riduedate{0};
147 $input{bornum}=$riborrowernumber{0};
148 push (@inputloop, \%input);
149 } elsif (! $messages->{'BadBarcode'}) {
153 $input{barcode}=$barcode;
156 $returneditems{0} = $barcode;
158 if ($messages->{'wthdrawn'}) {
160 $input{bornum}="Item Cancelled";
161 $riborrowernumber{0} = 'Item Cancelled';
163 $input{bornum}=" ";
164 $riborrowernumber{0} = ' ';
166 push (@inputloop, \%input);
168 $template->param( returned => $returned,
169 itemtitle => $iteminformation->{'title'},
170 # itembc => $iteminformation->{'barcode'},
171 # itemdatedue => $iteminformation->{'datedue'},
172 itemauthor => $iteminformation->{'author'});
174 $template->param(inputloop => \@inputloop);
181 if ($messages->{'ResFound'}) {
182 my $res = $messages->{'ResFound'};
183 my $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
184 my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
185 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
186 my ($iteminfo) = getiteminformation(\%env, 0, $barcode);
188 if ($res->{'ResFound'} eq "Waiting") {
189 $template->param( found => 1,
191 bornum => $res->{'borrowernumber'},
192 borcnum => $borr->{'cardnumber'},
193 branchname => $branches->{$res->{'branchcode'}}->{'branchname'},
195 itemtitle => $iteminfo->{'title'},
196 itemauthor => $iteminfo->{'author'});
199 if ($res->{'ResFound'} eq "Reserved") {
200 my @da = localtime(time());
201 my $todaysdate = sprintf ("%0.2d", ($da[3]+1))."/".sprintf ("%0.2d", ($da[4]+1))."/".($da[5]+1900);
202 $template->param( found => 1,
203 branchname => $branches->{$res->{'branchcode'}}->{'branchname'},
205 today => $todaysdate,
206 itemnumber => $res->{'itemnumber'},
207 itemtitle => $iteminfo->{'title'},
208 itemauthor => $iteminfo->{'author'},
209 itembarcode => $iteminfo->{'barcode'},
210 itemtype => $iteminfo->{'itemtype'},
211 itembiblionumber => $iteminfo->{'biblionumber'},
212 borsurname => $borr->{'surname'},
213 bortitle => $borr->{'title'},
214 borfirstname => $borr->{'firstname'},
215 bornum => $res->{'borrowernumber'},
216 borcnum => $borr->{'cardnumber'},
217 borphone => $borr->{'phone'},
218 borstraddress => $borr->{'streetaddress'},
219 borsub => $borr->{'suburb'},
220 bortown => $borr->{'town'},
221 boremail => $borr->{'emailadress'},
229 foreach my $code (keys %$messages) {
232 my $exit_required_p = 0;
233 if ($code eq 'BadBarcode'){
235 $err{msg}= $messages->{'BadBarcode'};
236 } elsif ($code eq 'NotIssued'){
238 $err{msg}= $branches->{$messages->{'IsPermanent'}}->{'branchname'};
239 } elsif ($code eq 'WasLost'){
241 } elsif ($code eq 'ResFound'){
242 ; # FIXME... anything to do here?
243 } elsif ($code eq 'WasReturned'){
244 ; # FIXME... anything to do here?
245 } elsif ($code eq 'WasTransfered'){
246 ; # FIXME... anything to do here?
247 } elsif ($code eq 'wthdrawn'){
249 $exit_required_p = 1;
250 } elsif (($code eq 'IsPermanent') && (not $messages->{'ResFound'})) {
251 if ($messages->{'IsPermanent'} ne $branch) {
253 $err{msg}=$branches->{$messages->{'IsPermanent'}}->{'branchname'} ;
256 die "Unknown error code $code"; # XXX
259 push (@errmsgloop, \%err);
261 last if $exit_required_p;
263 $template->param(errmsgloop => \@errmsgloop);
267 my $flags = $borrower->{'flags'};
271 foreach my $flag (sort keys %$flags) {
273 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
274 unless($flagset) { $flagset=1; }
275 $flaginfo{color}=$color;
276 $flaginfo{redfont} =($flags->{$flag}->{'noissues'});
277 $flaginfo{flag}=$flag;
278 if ($flag eq 'CHARGES') {
279 $flaginfo{msg}=$flag;
280 $flaginfo{charges}=1;
281 } elsif ($flag eq 'WAITING') {
282 $flaginfo{msg}=$flag;
283 $flaginfo{waiting}=1;
285 my $items = $flags->{$flag}->{'itemlist'};
286 foreach my $item (@$items) {
287 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
289 $waitingitem{biblionum}=$iteminformation->{'biblionumber'};
290 $waitingitem{barcode}=$iteminformation->{'barcode'};
291 $waitingitem{title}=$iteminformation->{'title'};
292 $waitingitem{brname}=$branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
293 push(@waitingitemloop, \%waitingitem);
295 $flaginfo{itemloop}=\@waitingitemloop;
296 } elsif ($flag eq 'ODUES') {
297 my $items = $flags->{$flag}->{'itemlist'};
299 foreach my $item (sort {$a->{'date_due'} cmp $b->{'date_due'}} @$items) {
300 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
302 $overdueitem{duedate}=$item->{'date_due'};
303 $overdueitem{biblionum}=$iteminformation->{'biblionumber'};
304 $overdueitem{barcode}=$iteminformation->{'barcode'};
305 $overdueitem{title}=$iteminformation->{'title'};
306 $overdueitem{brname}=$branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
307 push(@itemloop, \%overdueitem);
309 $flaginfo{itemloop}=\@itemloop;
310 $flaginfo{overdue}=1;
313 $flaginfo{msg}=$flags->{$flag}->{'message'};
315 push(@flagloop, \%flaginfo);
317 $template->param( flagset => $flagset,
318 flagloop => \@flagloop,
319 ribornum => $borrower->{'borrowernumber'},
320 riborcnum => $borrower->{'cardnumber'},
321 riborsurname => $borrower->{'surname'},
322 ribortitle => $borrower->{'title'},
323 riborfirstname => $borrower->{'firstname'}
328 #set up so only the lat 8 returned items display (make for faster loading pages)
331 foreach (sort {$a <=> $b} keys %returneditems) {
334 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
336 my $barcode = $returneditems{$_};
337 my $duedate = $riduedate{$_};
341 my @tempdate = split ( /-/ , $duedate ) ;
342 my $duedatenz = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
343 my @datearr = localtime(time());
344 my $todaysdate = $datearr[5].'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
345 my ($borrower) = getpatroninformation(\%env, $riborrowernumber{$_}, 0);
346 $ri{bornum}=$borrower->{'borrowernumber'};
347 $ri{borcnum}=$borrower->{'cardnumber'};
348 $ri{borfirstname}=$borrower->{'firstname'};
349 $ri{borsurname}=$borrower->{'surname'};
350 $ri{bortitle}=$borrower->{'title'};
352 $ri{bornum}=$riborrowernumber{$_};
355 my ($iteminformation) = getiteminformation(\%env, 0, $barcode);
357 $ri{itembiblionumber}=$iteminformation->{'biblionumber'};
358 $ri{itemtitle}=$iteminformation->{'title'};
359 $ri{itemauthor}=$iteminformation->{'author'};
360 $ri{itemtype}=$iteminformation->{'itemtype'};
361 $ri{barcode}=$barcode;
368 $template->param(riloop => \@riloop);
370 $template->param( genbrname => $branches->{$branch}->{'branchname'},
371 genprname => $printers->{$printer}->{'printername'},
374 errmsgloop => \@errmsgloop
377 # actually print the page!
378 output_html_with_http_headers $query, $cookie, $template->output;
380 sub cuecatbarcodedecode {
383 my @fields = split(/\./,$barcode);
384 my @results = map(decode($_), @fields[1..$#fields]);