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;
45 my ($template, $loggedinuser, $cookie) = get_template_and_user
47 template_name => 'circ/circulation.tmpl',
51 flagsrequired => { circulate => 1 },
53 my $branches = getbranches();
54 my $printers = getprinters();
55 my $branch = getbranch($query, $branches);
56 my $printer = getprinter($query, $printers);
58 my $findborrower = $query->param('findborrower');
59 $findborrower =~ s|,| |g;
60 $findborrower =~ s|'| |g;
61 my $borrowernumber = $query->param('borrnumber');
62 my $print=$query->param('print') || '';
63 my $barcode = $query->param('barcode') || '';
64 my $year=$query->param('year');
65 my $month=$query->param('month');
66 my $day=$query->param('day');
67 my $stickyduedate=$query->param('stickyduedate');
68 my $issueconfirmed = $query->param('issueconfirmed');
69 my $cancelreserve = $query->param('cancelreserve');
75 if ($query->param('setcookies')) {
76 $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
77 $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
80 my %env; # FIXME env is used as an "environment" variable. Could be dropped probably...
82 $env{'branchcode'}=$branch;
83 $env{'printer'}=$printer;
84 $env{'queue'}=$printer;
86 my @datearr = localtime(time());
87 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
88 my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", ($datearr[3]));
91 # check and see if we should print
92 if ($barcode eq '' && $print eq 'maybe'){
95 if ($print eq 'yes' && $borrowernumber ne ''){
96 printslip(\%env,$borrowernumber);
97 $query->param('borrnumber','');
102 # STEP 2 : FIND BORROWER
103 # if there is a list of find borrowers....
108 my ($count,$borrowers)=BornameSearch(\%env,$findborrower,'cardnumber','web');
109 my @borrowers=@$borrowers;
110 if ($#borrowers == -1) {
111 $query->param('findborrower', '');
112 $message = "'$findborrower'";
113 } elsif ($#borrowers == 0) {
114 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
115 $query->param('barcode','');
116 $borrowernumber=$borrowers[0]->{'borrowernumber'};
118 $borrowerslist = \@borrowers;
122 # get the borrower information.....
127 if ($borrowernumber) {
128 $borrower = getpatroninformation(\%env,$borrowernumber,0);
129 my ($od,$issue,$fines)=borrdata2(\%env,$borrowernumber);
130 warn $borrower->{'expiry'};
131 my $warningdate = DateCalc($borrower->{'expiry'},"- ".C4::Context->preference('NotifyBorrowerDeparture')." days");
132 my $warning=Date_Cmp(ParseDate("today"),$warningdate);
134 #borrowercard expired
135 $template->param(warndeparture=>$warning);
137 $template->param(overduecount => $od,
138 issuecount => $issue,
139 finetotal => $fines);
140 my $htdocs = C4::Context->config('intrahtdocs');
141 $picture = "/borrowerimages/".$borrowernumber.".jpg";
142 if (-e $htdocs."$picture")
144 $template->param(picture => $picture)
157 $barcode = cuecatbarcodedecode($barcode);
158 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
159 if ($issueconfirmed) {
160 issuebook(\%env, $borrower, $barcode, $datedue,$cancelreserve);
162 my ($error, $question) = canbookbeissued(\%env, $borrower, $barcode, $year, $month, $day);
165 foreach my $impossible (keys %$error) {
166 $template->param($impossible => $$error{$impossible},
170 foreach my $needsconfirmation (keys %$question) {
171 $template->param($needsconfirmation => $$question{$needsconfirmation},
172 NEEDSCONFIRMATION => 1);
175 $template->param(day => $day,
178 if ($noerror && ($noquestion || $issueconfirmed)) {
179 issuebook(\%env, $borrower, $barcode, $datedue);
184 # reload the borrower info for the sake of reseting the flags.....
185 if ($borrowernumber) {
186 $borrower = getpatroninformation(\%env,$borrowernumber,0);
190 ##################################################################################
193 # make the issued books table.....
200 # get each issue of the borrower & separate them in todayissues & previous issues
203 my $issueslist = getissues($borrower);
204 # split in 2 arrays for today & previous
205 foreach my $it (keys %$issueslist) {
206 my $issuedate = $issueslist->{$it}->{'timestamp'};
207 $issuedate = substr($issuedate, 0, 8);
208 if ($todaysdate == $issuedate) {
209 push @todaysissues, $issueslist->{$it};
211 push @previousissues, $issueslist->{$it};
217 # parses today & build Template array
218 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
219 my $dd = $book->{'date_due'};
220 my $datedue = $book->{'date_due'};
221 $dd=format_date($dd);
223 if ($datedue < $todaysdate) {
233 $book->{'togglecolor'} = $togglecolor;
236 if ($book->{'author'} eq ''){
237 $book->{'author'}=' ';
239 push @realtodayissues,$book;
243 # parses previous & build Template array
245 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
246 my $dd = $book->{'date_due'};
247 my $datedue = $book->{'date_due'};
248 $dd=format_date($dd);
252 if ($datedue < $todaysdate) {
262 $book->{'togglecolor'} = $togglecolor;
265 if ($book->{'author'} eq ''){
266 $book->{'author'}=' ';
268 push @realprevissues,$book;
276 my $CGIselectborrower;
277 if ($borrowerslist) {
278 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
279 push @values,$_->{'borrowernumber'};
280 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'}) ... $_->{'streetaddress'} ";
282 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
290 my ($patrontable, $flaginfotable) = patrontable($borrower);
291 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'} || 0;
292 my @temp=split(/\$/,$amountold);
295 findborrower => $findborrower,
296 borrower => $borrower,
297 borrowernumber => $borrowernumber,
300 branchname => $branches->{$branch}->{'branchname'},
301 printername => $printers->{$printer}->{'printername'},
302 firstname => $borrower->{'firstname'},
303 surname => $borrower->{'surname'},
304 categorycode => $borrower->{'categorycode'},
305 streetaddress => $borrower->{'streetaddress'},
306 emailaddress => $borrower->{'emailaddress'},
307 borrowernotes => $borrower->{'borrowernotes'},
308 city => $borrower->{'city'},
309 phone => $borrower->{'phone'},
310 cardnumber => $borrower->{'cardnumber'},
311 amountold => $amountold,
313 stickyduedate => $stickyduedate,
315 CGIselectborrower => $CGIselectborrower,
316 todayissues => \@realtodayissues,
317 previssues => \@realprevissues,
319 # set return date if stickyduedate
320 if ($stickyduedate) {
321 my $t_year = "year".$year;
322 my $t_month = "month".$month;
323 my $t_day = "day".$day;
333 $cookie=[$cookie, $branchcookie, $printercookie];
336 output_html_with_http_headers $query, $cookie, $template->output;
338 ####################################################################
339 # Extra subroutines,,,
343 my $flags = $borrower->{'flags'};
344 my $flaginfotable='';
346 #my $flaginfotext='';
349 foreach $flag (sort keys %$flags) {
350 # my @itemswaiting='';
351 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
352 if ($flags->{$flag}->{'noissues'}) {
362 if ($flag eq 'LOST'){
367 if ($flag eq 'DBARRED'){
372 if ($flag eq 'CHARGES') {
375 chargesmsg => $flags->{'CHARGES'}->{'message'}
379 if ($flag eq 'CHARGES') {
383 chargesmsg => $flags->{'CHARGES'}->{'message'}
386 if ($flag eq 'WAITING') {
387 my $items=$flags->{$flag}->{'itemlist'};
389 foreach my $item (@$items) {
390 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
391 $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
392 push @itemswaiting, $iteminformation;
397 waitingmsg => $flags->{'WAITING'}->{'message'},
398 itemswaiting => \@itemswaiting,
401 if ($flag eq 'ODUES') {
405 oduesmsg => $flags->{'ODUES'}->{'message'}
408 my $items=$flags->{$flag}->{'itemlist'};
411 foreach my $item (@$items) {
412 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
413 push @itemswaiting, $iteminformation;
416 if ($query->param('module') ne 'returns'){
417 $template->param( nonreturns => 'true' );
420 if ($flag eq 'NOTES') {
424 notesmsg => $flags->{'NOTES'}->{'message'}
429 return($patrontable, $flaginfotext);
432 sub cuecatbarcodedecode {
435 my @fields = split(/\./,$barcode);
436 my @results = map(decode($_), @fields[1..$#fields]);