3 # Please use 8-character tabs for this file (indents are every 4 characters)
5 #written 8/5/2002 by Finlay
6 #script to execute issuing 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;
44 my ($template, $loggedinuser, $cookie) = get_template_and_user
46 template_name => 'circ/circulation.tmpl',
50 flagsrequired => { circulate => 1 },
52 my $branches = getbranches();
53 my $printers = getprinters();
54 my $branch = getbranch($query, $branches);
55 my $printer = getprinter($query, $printers);
57 my $findborrower = $query->param('findborrower');
58 my $borrowernumber = $query->param('borrnumber');
59 my $print=$query->param('print');
60 my $barcode = $query->param('barcode');
61 my $year=$query->param('year');
62 my $month=$query->param('month');
63 my $day=$query->param('day');
64 my $stickyduedate=$query->param('stickyduedate');
65 my $issueconfirmed = $query->param('issueconfirmed');
71 if ($query->param('setcookies')) {
72 $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
73 $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
76 my %env; # env is used as an "environment" variable. Could be dropped probably...
77 $env{'branchcode'}=$branch;
78 $env{'printer'}=$printer;
79 $env{'queue'}=$printer;
81 my @datearr = localtime(time());
82 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
83 my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", ($datearr[3]));
85 # get the borrower information.....
87 if ($borrowernumber) {
88 $borrower = getpatroninformation(\%env,$borrowernumber,0);
94 # STEP 2 : FIND BORROWER
95 # if there is a list of find borrowers....
99 my ($count,$borrowers)=BornameSearch(\%env,$findborrower,'web');
100 my @borrowers=@$borrowers;
101 if ($#borrowers == -1) {
102 $query->param('findborrower', '');
103 } elsif ($#borrowers == 0) {
104 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
105 $query->param('barcode','');
107 $borrowerslist = \@borrowers;
116 # check and see if we should print
117 # if ($barcode eq '' && $print eq 'maybe'){
120 # if ($print eq 'yes' && $borrowernumber ne ''){
121 # printslip(\%env,$borrowernumber);
122 # $query->param('borrnumber','');
123 # $borrowernumber='';
127 $barcode = cuecatbarcodedecode($barcode);
128 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
129 if ($issueconfirmed) {
131 issuebook(\%env, $borrower, $barcode, $datedue);
133 # unless ($invalidduedate) {
134 my ($error, $question) = canbookbeissued(\%env, $borrower, $barcode, $year, $month, $day);
137 foreach my $impossible (keys %$error) {
138 $template->param($impossible => $$error{$impossible},
142 foreach my $needsconfirmation (keys %$question) {
143 $template->param($needsconfirmation => $$question{$needsconfirmation},
144 NEEDSCONFIRMATION => 1);
147 if ($noerror && ($noquestion || $issueconfirmed)) {
149 issuebook(\%env, $borrower, $barcode, $datedue);
156 # reload the borrower info for the sake of reseting the flags.....
157 if ($borrowernumber) {
158 $borrower = getpatroninformation(\%env,$borrowernumber,0);
162 ##################################################################################
165 # make the issued books table.....
172 # get each issue of the borrower & separate them in todayissues & previous issues
175 my $issueslist = getissues($borrower);
176 # split in 2 arrays for today & previous
177 foreach my $it (keys %$issueslist) {
178 my $issuedate = $issueslist->{$it}->{'timestamp'};
179 $issuedate = substr($issuedate, 0, 8);
180 if ($todaysdate == $issuedate) {
181 push @todaysissues, $issueslist->{$it};
183 push @previousissues, $issueslist->{$it};
188 # parses today & build Template array
189 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
190 my $dd = $book->{'date_due'};
191 my $datedue = $book->{'date_due'};
192 $dd=format_date($dd);
194 if ($datedue < $todaysdate) {
201 $book->{'tcolor'}=$togglecolor;
207 if ($book->{'author'} eq ''){
208 $book->{'author'}=' ';
210 push @realtodayissues,$book;
213 # parses previous & build Template array
214 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
215 my $dd = $book->{'date_due'};
216 my $datedue = $book->{'date_due'};
217 $dd=format_date($dd);
221 if ($datedue < $todaysdate) {
226 $book->{'tcolor'}=$togglecolor;
234 $book->{'tcolor'}=$pcolor;
235 if ($book->{'author'} eq ''){
236 $book->{'author'}=' ';
238 push @realprevissues,$book
245 my $CGIselectborrower;
246 if ($borrowerslist) {
247 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
248 push @values,$_->{'borrowernumber'};
249 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})";
251 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
259 my ($patrontable, $flaginfotable) = patrontable($borrower);
260 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'};
261 my @temp=split(/\$/,$amountold);
264 findborrower => $findborrower,
265 borrower => $borrower,
266 borrowernumber => $borrowernumber,
269 branchname => $branches->{$branch}->{'branchname'},
270 printername => $printers->{$printer}->{'printername'},
271 # title => $iteminformation->{'title'},
272 # author => $iteminformation->{'author'},
273 firstname => $borrower->{'firstname'},
274 surname => $borrower->{'surname'},
275 categorycode => $borrower->{'categorycode'},
276 streetaddress => $borrower->{'streetaddress'},
277 city => $borrower->{'city'},
278 phone => $borrower->{'phone'},
279 cardnumber => $borrower->{'cardnumber'},
280 amountold => $amountold,
282 stickyduedate => $stickyduedate,
283 CGIselectborrower => $CGIselectborrower,
284 todayissues => \@realtodayissues,
285 previssues => \@realprevissues,
287 # set return date if stickyduedate
288 if ($stickyduedate) {
289 my $t_year = "year".$year;
290 my $t_month = "month".$month;
291 my $t_day = "day".$day;
301 $cookie=[$cookie, $branchcookie, $printercookie];
304 output_html_with_http_headers $query, $cookie, $template->output;
306 ####################################################################
307 # Extra subroutines,,,
309 sub cuecatbarcodedecode {
312 my @fields = split(/\./,$barcode);
313 my @results = map(decode($_), @fields[1..$#fields]);
324 my $flags = $borrower->{'flags'};
325 my $flaginfotable='';
327 #my $flaginfotext='';
330 foreach $flag (sort keys %$flags) {
331 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
332 if ($flags->{$flag}->{'noissues'}) {
342 if ($flag eq 'LOST'){
347 if ($flag eq 'DBARRED'){
352 if ($flag eq 'CHARGES') {
355 chargesmsg => $flags->{'CHARGES'}->{'message'}
359 if ($flag eq 'CHARGES') {
362 chargesmsg => $flags->{'CHARGES'}->{'message'}
365 if ($flag eq 'WAITING') {
366 my $items=$flags->{$flag}->{'itemlist'};
368 foreach my $item (@$items) {
369 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
370 $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
371 push @itemswaiting, $iteminformation;
375 waitingmsg => $flags->{'WAITING'}->{'message'},
376 itemswaiting => \@itemswaiting,
379 if ($flag eq 'ODUES') {
382 oduesmsg => $flags->{'ODUES'}->{'message'}
385 my $items=$flags->{$flag}->{'itemlist'};
386 my $currentcolor=$color;
388 my $color=$currentcolor;
390 foreach my $item (@$items) {
391 # ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
392 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
393 push @itemswaiting, $iteminformation;
396 if ($query->param('module') ne 'returns'){
397 $template->param( nonreturns => 'true' );
400 if ($flag eq 'NOTES') {
403 notesmsg => $flags->{'NOTES'}->{'message'}
408 return($patrontable, $flaginfotext);