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};
200 # parses today & build Template array
201 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
202 my $dd = $book->{'date_due'};
203 my $datedue = $book->{'date_due'};
204 $dd=format_date($dd);
206 if ($datedue < $todaysdate) {
216 $book->{'togglecolor'} = $togglecolor;
219 if ($book->{'author'} eq ''){
220 $book->{'author'}=' ';
222 push @realtodayissues,$book;
226 # parses previous & build Template array
228 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
229 my $dd = $book->{'date_due'};
230 my $datedue = $book->{'date_due'};
231 $dd=format_date($dd);
235 if ($datedue < $todaysdate) {
245 $book->{'togglecolor'} = $togglecolor;
248 if ($book->{'author'} eq ''){
249 $book->{'author'}=' ';
251 push @realprevissues,$book;
259 my $CGIselectborrower;
260 if ($borrowerslist) {
261 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
262 push @values,$_->{'borrowernumber'};
263 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'}) ... $_->{'streetaddress'} ";
265 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
273 my ($patrontable, $flaginfotable) = patrontable($borrower);
274 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'};
275 my @temp=split(/\$/,$amountold);
278 findborrower => $findborrower,
279 borrower => $borrower,
280 borrowernumber => $borrowernumber,
283 branchname => $branches->{$branch}->{'branchname'},
284 printername => $printers->{$printer}->{'printername'},
285 firstname => $borrower->{'firstname'},
286 surname => $borrower->{'surname'},
287 categorycode => $borrower->{'categorycode'},
288 streetaddress => $borrower->{'streetaddress'},
289 emailaddress => $borrower->{'emailaddress'},
290 borrowernotes => $borrower->{'borrowernotes'},
291 city => $borrower->{'city'},
292 phone => $borrower->{'phone'},
293 cardnumber => $borrower->{'cardnumber'},
294 amountold => $amountold,
296 stickyduedate => $stickyduedate,
298 CGIselectborrower => $CGIselectborrower,
299 todayissues => \@realtodayissues,
300 previssues => \@realprevissues,
302 # set return date if stickyduedate
303 if ($stickyduedate) {
304 my $t_year = "year".$year;
305 my $t_month = "month".$month;
306 my $t_day = "day".$day;
316 $cookie=[$cookie, $branchcookie, $printercookie];
319 output_html_with_http_headers $query, $cookie, $template->output;
321 ####################################################################
322 # Extra subroutines,,,
326 my $flags = $borrower->{'flags'};
327 my $flaginfotable='';
329 #my $flaginfotext='';
332 foreach $flag (sort keys %$flags) {
333 # my @itemswaiting='';
334 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
335 if ($flags->{$flag}->{'noissues'}) {
345 if ($flag eq 'LOST'){
350 if ($flag eq 'DBARRED'){
355 if ($flag eq 'CHARGES') {
358 chargesmsg => $flags->{'CHARGES'}->{'message'}
362 if ($flag eq 'CHARGES') {
366 chargesmsg => $flags->{'CHARGES'}->{'message'}
369 if ($flag eq 'WAITING') {
370 my $items=$flags->{$flag}->{'itemlist'};
372 foreach my $item (@$items) {
373 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
374 $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
375 push @itemswaiting, $iteminformation;
380 waitingmsg => $flags->{'WAITING'}->{'message'},
381 itemswaiting => \@itemswaiting,
384 if ($flag eq 'ODUES') {
388 oduesmsg => $flags->{'ODUES'}->{'message'}
391 my $items=$flags->{$flag}->{'itemlist'};
394 foreach my $item (@$items) {
395 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
396 push @itemswaiting, $iteminformation;
399 if ($query->param('module') ne 'returns'){
400 $template->param( nonreturns => 'true' );
403 if ($flag eq 'NOTES') {
407 notesmsg => $flags->{'NOTES'}->{'message'}
412 return($patrontable, $flaginfotext);
415 sub cuecatbarcodedecode {
418 my @fields = split(/\./,$barcode);
419 my @results = map(decode($_), @fields[1..$#fields]);