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 # unless ($invalidduedate) {
130 my ($error, $question) = canbookbeissued(\%env, $borrower, $barcode, $year, $month, $day);
133 foreach my $impossible (keys %$error) {
134 warn "Impossible : $impossible : ";#.%$error->{$impossible};
135 $template->param($impossible => 1,
139 foreach my $needsconfirmation (keys %$question) {
140 warn "needsconfirmation : $needsconfirmation : "; #.%$error->{$needsconfirmation};
141 $template->param($needsconfirmation => 1,
142 NEEDSCONFIRMATION => 1);
145 if ($noerror && ($noquestion || $issueconfirmed)) {
147 # issuebook(\%env, $borrower, $barcode, $datedue);
153 # reload the borrower info for the sake of reseting the flags.....
154 if ($borrowernumber) {
155 $borrower = getpatroninformation(\%env,$borrowernumber,0);
159 ##################################################################################
162 # make the issued books table.....
169 # get each issue of the borrower & separate them in todayissues & previous issues
172 my $issueslist = getissues($borrower);
173 # split in 2 arrays for today & previous
174 foreach my $it (keys %$issueslist) {
175 my $issuedate = $issueslist->{$it}->{'timestamp'};
176 $issuedate = substr($issuedate, 0, 8);
177 if ($todaysdate == $issuedate) {
178 push @todaysissues, $issueslist->{$it};
180 push @previousissues, $issueslist->{$it};
185 # parses today & build Template array
186 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
187 my $dd = $book->{'date_due'};
188 my $datedue = $book->{'date_due'};
189 $dd=format_date($dd);
191 if ($datedue < $todaysdate) {
198 $book->{'tcolor'}=$togglecolor;
204 if ($book->{'author'} eq ''){
205 $book->{'author'}=' ';
207 push @realtodayissues,$book;
210 # parses previous & build Template array
211 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
212 my $dd = $book->{'date_due'};
213 my $datedue = $book->{'date_due'};
214 $dd=format_date($dd);
218 if ($datedue < $todaysdate) {
223 $book->{'tcolor'}=$togglecolor;
231 $book->{'tcolor'}=$pcolor;
232 if ($book->{'author'} eq ''){
233 $book->{'author'}=' ';
235 push @realprevissues,$book
242 my $CGIselectborrower;
243 if ($borrowerslist) {
244 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
245 push @values,$_->{'borrowernumber'};
246 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})";
248 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
256 my ($patrontable, $flaginfotable) = patrontable($borrower);
257 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'};
258 my @temp=split(/\$/,$amountold);
261 findborrower => $findborrower,
262 borrower => $borrower,
263 borrowernumber => $borrowernumber,
266 branchname => $branches->{$branch}->{'branchname'},
267 printername => $printers->{$printer}->{'printername'},
268 # title => $iteminformation->{'title'},
269 # author => $iteminformation->{'author'},
270 firstname => $borrower->{'firstname'},
271 surname => $borrower->{'surname'},
272 categorycode => $borrower->{'categorycode'},
273 streetaddress => $borrower->{'streetaddress'},
274 city => $borrower->{'city'},
275 phone => $borrower->{'phone'},
276 cardnumber => $borrower->{'cardnumber'},
277 amountold => $amountold,
279 stickyduedate => $stickyduedate,
280 CGIselectborrower => $CGIselectborrower,
281 todayissues => \@realtodayissues,
282 previssues => \@realprevissues,
284 # set return date if stickyduedate
285 if ($stickyduedate) {
286 my $t_year = "year".$year;
287 my $t_month = "month".$month;
288 my $t_day = "day".$day;
298 $cookie=[$cookie, $branchcookie, $printercookie];
301 output_html_with_http_headers $query, $cookie, $template->output;
303 ####################################################################
304 # Extra subroutines,,,
306 sub cuecatbarcodedecode {
309 my @fields = split(/\./,$barcode);
310 my @results = map(decode($_), @fields[1..$#fields]);
321 my $flags = $borrower->{'flags'};
322 my $flaginfotable='';
324 #my $flaginfotext='';
327 foreach $flag (sort keys %$flags) {
328 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
329 if ($flags->{$flag}->{'noissues'}) {
339 if ($flag eq 'LOST'){
344 if ($flag eq 'DBARRED'){
349 if ($flag eq 'CHARGES') {
352 chargesmsg => $flags->{'CHARGES'}->{'message'}
356 if ($flag eq 'CHARGES') {
359 chargesmsg => $flags->{'CHARGES'}->{'message'}
362 if ($flag eq 'WAITING') {
363 my $items=$flags->{$flag}->{'itemlist'};
365 foreach my $item (@$items) {
366 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
367 $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
368 push @itemswaiting, $iteminformation;
372 waitingmsg => $flags->{'WAITING'}->{'message'},
373 itemswaiting => \@itemswaiting,
376 if ($flag eq 'ODUES') {
379 oduesmsg => $flags->{'ODUES'}->{'message'}
382 my $items=$flags->{$flag}->{'itemlist'};
383 my $currentcolor=$color;
385 my $color=$currentcolor;
387 foreach my $item (@$items) {
388 # ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
389 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
390 push @itemswaiting, $iteminformation;
393 if ($query->param('module') ne 'returns'){
394 $template->param( nonreturns => 'true' );
397 if ($flag eq 'NOTES') {
400 notesmsg => $flags->{'NOTES'}->{'message'}
405 return($patrontable, $flaginfotext);