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; # FIXME env is used as an "environment" variable. Could be dropped probably...
78 $env{'branchcode'}=$branch;
79 $env{'printer'}=$printer;
80 $env{'queue'}=$printer;
82 my @datearr = localtime(time());
83 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
84 my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", ($datearr[3]));
89 # STEP 2 : FIND BORROWER
90 # if there is a list of find borrowers....
94 my ($count,$borrowers)=BornameSearch(\%env,$findborrower,'web');
95 my @borrowers=@$borrowers;
96 if ($#borrowers == -1) {
97 $query->param('findborrower', '');
98 } elsif ($#borrowers == 0) {
99 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
100 $query->param('barcode','');
101 $borrowernumber=$borrowers[0]->{'borrowernumber'};
103 $borrowerslist = \@borrowers;
107 # get the borrower information.....
109 if ($borrowernumber) {
110 $borrower = getpatroninformation(\%env,$borrowernumber,0);
111 my ($od,$issue,$fines)=borrdata2(\%env,$borrowernumber);
112 $template->param(overduecount => $od,
113 issuecount => $issue,
114 finetotal => $fines);
123 # check and see if we should print
124 # if ($barcode eq '' && $print eq 'maybe'){
127 # if ($print eq 'yes' && $borrowernumber ne ''){
128 # printslip(\%env,$borrowernumber);
129 # $query->param('borrnumber','');
130 # $borrowernumber='';
134 $barcode = cuecatbarcodedecode($barcode);
135 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
136 if ($issueconfirmed) {
137 issuebook(\%env, $borrower, $barcode, $datedue);
139 my ($error, $question) = canbookbeissued(\%env, $borrower, $barcode, $year, $month, $day);
142 foreach my $impossible (keys %$error) {
143 $template->param($impossible => $$error{$impossible},
147 foreach my $needsconfirmation (keys %$question) {
148 $template->param($needsconfirmation => $$question{$needsconfirmation},
149 NEEDSCONFIRMATION => 1);
152 $template->param(day => $day,
155 if ($noerror && ($noquestion || $issueconfirmed)) {
156 issuebook(\%env, $borrower, $barcode, $datedue);
161 # reload the borrower info for the sake of reseting the flags.....
162 if ($borrowernumber) {
163 $borrower = getpatroninformation(\%env,$borrowernumber,0);
167 ##################################################################################
170 # make the issued books table.....
177 # get each issue of the borrower & separate them in todayissues & previous issues
180 my $issueslist = getissues($borrower);
181 # split in 2 arrays for today & previous
182 foreach my $it (keys %$issueslist) {
183 my $issuedate = $issueslist->{$it}->{'timestamp'};
184 $issuedate = substr($issuedate, 0, 8);
185 if ($todaysdate == $issuedate) {
186 push @todaysissues, $issueslist->{$it};
188 push @previousissues, $issueslist->{$it};
193 # parses today & build Template array
194 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
195 my $dd = $book->{'date_due'};
196 my $datedue = $book->{'date_due'};
197 $dd=format_date($dd);
199 if ($datedue < $todaysdate) {
206 $book->{'tcolor'}=$togglecolor;
212 if ($book->{'author'} eq ''){
213 $book->{'author'}=' ';
215 push @realtodayissues,$book;
218 # parses previous & build Template array
219 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
220 my $dd = $book->{'date_due'};
221 my $datedue = $book->{'date_due'};
222 $dd=format_date($dd);
226 if ($datedue < $todaysdate) {
231 $book->{'tcolor'}=$togglecolor;
239 $book->{'tcolor'}=$pcolor;
240 if ($book->{'author'} eq ''){
241 $book->{'author'}=' ';
243 push @realprevissues,$book
250 my $CGIselectborrower;
251 if ($borrowerslist) {
252 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
253 push @values,$_->{'borrowernumber'};
254 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})";
256 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
264 my ($patrontable, $flaginfotable) = patrontable($borrower);
265 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'};
266 my @temp=split(/\$/,$amountold);
269 findborrower => $findborrower,
270 borrower => $borrower,
271 borrowernumber => $borrowernumber,
274 branchname => $branches->{$branch}->{'branchname'},
275 printername => $printers->{$printer}->{'printername'},
276 firstname => $borrower->{'firstname'},
277 surname => $borrower->{'surname'},
278 categorycode => $borrower->{'categorycode'},
279 streetaddress => $borrower->{'streetaddress'},
280 borrowernotes => $borrower->{'borrowernotes'},
281 city => $borrower->{'city'},
282 phone => $borrower->{'phone'},
283 cardnumber => $borrower->{'cardnumber'},
284 amountold => $amountold,
286 stickyduedate => $stickyduedate,
287 CGIselectborrower => $CGIselectborrower,
288 todayissues => \@realtodayissues,
289 previssues => \@realprevissues,
291 # set return date if stickyduedate
292 if ($stickyduedate) {
293 my $t_year = "year".$year;
294 my $t_month = "month".$month;
295 my $t_day = "day".$day;
305 $cookie=[$cookie, $branchcookie, $printercookie];
308 output_html_with_http_headers $query, $cookie, $template->output;
310 ####################################################################
311 # Extra subroutines,,,
315 my $flags = $borrower->{'flags'};
316 my $flaginfotable='';
318 #my $flaginfotext='';
321 foreach $flag (sort keys %$flags) {
322 # my @itemswaiting='';
323 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
324 if ($flags->{$flag}->{'noissues'}) {
333 if ($flag eq 'LOST'){
338 if ($flag eq 'DBARRED'){
343 if ($flag eq 'CHARGES') {
346 chargesmsg => $flags->{'CHARGES'}->{'message'}
350 if ($flag eq 'CHARGES') {
353 chargesmsg => $flags->{'CHARGES'}->{'message'}
356 if ($flag eq 'WAITING') {
357 my $items=$flags->{$flag}->{'itemlist'};
359 foreach my $item (@$items) {
360 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
361 $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
362 push @itemswaiting, $iteminformation;
366 waitingmsg => $flags->{'WAITING'}->{'message'},
367 itemswaiting => \@itemswaiting,
370 if ($flag eq 'ODUES') {
373 oduesmsg => $flags->{'ODUES'}->{'message'}
376 my $items=$flags->{$flag}->{'itemlist'};
379 foreach my $item (@$items) {
380 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
381 push @itemswaiting, $iteminformation;
384 if ($query->param('module') ne 'returns'){
385 $template->param( nonreturns => 'true' );
388 if ($flag eq 'NOTES') {
391 notesmsg => $flags->{'NOTES'}->{'message'}
396 return($patrontable, $flaginfotext);
399 sub cuecatbarcodedecode {
402 my @fields = split(/\./,$barcode);
403 my @results = map(decode($_), @fields[1..$#fields]);