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 $findborrower =~ s|,| |g;
59 $findborrower =~ s|'| |g;
60 my $borrowernumber = $query->param('borrnumber');
61 my $print=$query->param('print');
62 my $barcode = $query->param('barcode');
63 my $year=$query->param('year');
64 my $month=$query->param('month');
65 my $day=$query->param('day');
66 my $stickyduedate=$query->param('stickyduedate');
67 my $issueconfirmed = $query->param('issueconfirmed');
68 my $cancelreserve = $query->param('cancelreserve');
74 if ($query->param('setcookies')) {
75 $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
76 $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
79 my %env; # FIXME env is used as an "environment" variable. Could be dropped probably...
81 $env{'branchcode'}=$branch;
82 $env{'printer'}=$printer;
83 $env{'queue'}=$printer;
85 my @datearr = localtime(time());
86 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
87 my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", ($datearr[3]));
90 # check and see if we should print
91 if ($barcode eq '' && $print eq 'maybe'){
94 if ($print eq 'yes' && $borrowernumber ne ''){
95 printslip(\%env,$borrowernumber);
96 $query->param('borrnumber','');
101 # STEP 2 : FIND BORROWER
102 # if there is a list of find borrowers....
107 my ($count,$borrowers)=BornameSearch(\%env,$findborrower,'cardnumber','web');
108 my @borrowers=@$borrowers;
109 if ($#borrowers == -1) {
110 $query->param('findborrower', '');
111 $message = "'$findborrower'";
112 } elsif ($#borrowers == 0) {
113 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
114 $query->param('barcode','');
115 $borrowernumber=$borrowers[0]->{'borrowernumber'};
117 $borrowerslist = \@borrowers;
121 # get the borrower information.....
123 if ($borrowernumber) {
124 $borrower = getpatroninformation(\%env,$borrowernumber,0);
125 my ($od,$issue,$fines)=borrdata2(\%env,$borrowernumber);
126 $template->param(overduecount => $od,
127 issuecount => $issue,
128 finetotal => $fines);
140 $barcode = cuecatbarcodedecode($barcode);
141 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
142 if ($issueconfirmed) {
143 issuebook(\%env, $borrower, $barcode, $datedue,$cancelreserve);
145 my ($error, $question) = canbookbeissued(\%env, $borrower, $barcode, $year, $month, $day);
148 foreach my $impossible (keys %$error) {
149 $template->param($impossible => $$error{$impossible},
153 foreach my $needsconfirmation (keys %$question) {
154 $template->param($needsconfirmation => $$question{$needsconfirmation},
155 NEEDSCONFIRMATION => 1);
158 $template->param(day => $day,
161 if ($noerror && ($noquestion || $issueconfirmed)) {
162 issuebook(\%env, $borrower, $barcode, $datedue);
167 # reload the borrower info for the sake of reseting the flags.....
168 if ($borrowernumber) {
169 $borrower = getpatroninformation(\%env,$borrowernumber,0);
173 ##################################################################################
176 # make the issued books table.....
183 # get each issue of the borrower & separate them in todayissues & previous issues
186 my $issueslist = getissues($borrower);
187 # split in 2 arrays for today & previous
188 foreach my $it (keys %$issueslist) {
189 my $issuedate = $issueslist->{$it}->{'timestamp'};
190 $issuedate = substr($issuedate, 0, 8);
191 if ($todaysdate == $issuedate) {
192 push @todaysissues, $issueslist->{$it};
194 push @previousissues, $issueslist->{$it};
199 # parses today & build Template array
200 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
201 my $dd = $book->{'date_due'};
202 my $datedue = $book->{'date_due'};
203 $dd=format_date($dd);
205 if ($datedue < $todaysdate) {
212 $book->{'tcolor'}=$togglecolor;
218 if ($book->{'author'} eq ''){
219 $book->{'author'}=' ';
221 push @realtodayissues,$book;
224 # parses previous & build Template array
225 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
226 my $dd = $book->{'date_due'};
227 my $datedue = $book->{'date_due'};
228 $dd=format_date($dd);
232 if ($datedue < $todaysdate) {
237 $book->{'tcolor'}=$togglecolor;
245 $book->{'tcolor'}=$pcolor;
246 if ($book->{'author'} eq ''){
247 $book->{'author'}=' ';
249 push @realprevissues,$book
256 my $CGIselectborrower;
257 if ($borrowerslist) {
258 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
259 push @values,$_->{'borrowernumber'};
260 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'}) ... $_->{'streetaddress'} ";
262 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
270 my ($patrontable, $flaginfotable) = patrontable($borrower);
271 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'};
272 my @temp=split(/\$/,$amountold);
275 findborrower => $findborrower,
276 borrower => $borrower,
277 borrowernumber => $borrowernumber,
280 branchname => $branches->{$branch}->{'branchname'},
281 printername => $printers->{$printer}->{'printername'},
282 firstname => $borrower->{'firstname'},
283 surname => $borrower->{'surname'},
284 categorycode => $borrower->{'categorycode'},
285 streetaddress => $borrower->{'streetaddress'},
286 emailaddress => $borrower->{'emailaddress'},
287 borrowernotes => $borrower->{'borrowernotes'},
288 city => $borrower->{'city'},
289 phone => $borrower->{'phone'},
290 cardnumber => $borrower->{'cardnumber'},
291 amountold => $amountold,
293 stickyduedate => $stickyduedate,
295 CGIselectborrower => $CGIselectborrower,
296 todayissues => \@realtodayissues,
297 previssues => \@realprevissues,
299 # set return date if stickyduedate
300 if ($stickyduedate) {
301 my $t_year = "year".$year;
302 my $t_month = "month".$month;
303 my $t_day = "day".$day;
313 $cookie=[$cookie, $branchcookie, $printercookie];
316 output_html_with_http_headers $query, $cookie, $template->output;
318 ####################################################################
319 # Extra subroutines,,,
323 my $flags = $borrower->{'flags'};
324 my $flaginfotable='';
326 #my $flaginfotext='';
329 foreach $flag (sort keys %$flags) {
330 # my @itemswaiting='';
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') {
363 chargesmsg => $flags->{'CHARGES'}->{'message'}
366 if ($flag eq 'WAITING') {
367 my $items=$flags->{$flag}->{'itemlist'};
369 foreach my $item (@$items) {
370 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
371 $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
372 push @itemswaiting, $iteminformation;
377 waitingmsg => $flags->{'WAITING'}->{'message'},
378 itemswaiting => \@itemswaiting,
381 if ($flag eq 'ODUES') {
385 oduesmsg => $flags->{'ODUES'}->{'message'}
388 my $items=$flags->{$flag}->{'itemlist'};
391 foreach my $item (@$items) {
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') {
404 notesmsg => $flags->{'NOTES'}->{'message'}
409 return($patrontable, $flaginfotext);
412 sub cuecatbarcodedecode {
415 my @fields = split(/\./,$barcode);
416 my @results = map(decode($_), @fields[1..$#fields]);