2 # Please use 8-character tabs for this file (indents are every 4 characters)
4 #written 8/5/2002 by Finlay
5 #script to execute issuing of books
8 # Copyright 2000-2002 Katipo Communications
10 # This file is part of Koha.
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA 02111-1307 USA
27 use C4::Circulation::Circ2;
33 use C4::Interface::CGI::Output;
43 my ($template, $loggedinuser, $cookie) = get_template_and_user
45 template_name => 'circ/circulation.tmpl',
49 flagsrequired => { circulate => 1 },
51 my $branches = getbranches();
52 my $printers = getprinters();
53 my $branch = getbranch($query, $branches);
54 my $printer = getprinter($query, $printers);
56 my $findborrower = $query->param('findborrower');
57 my $borrowernumber = $query->param('borrnumber');
58 my $print=$query->param('print');
59 my $barcode = $query->param('barcode');
60 my $year=$query->param('year');
61 my $month=$query->param('month');
62 my $day=$query->param('day');
63 my $stickyduedate=$query->param('stickyduedate');
64 my $issueconfirmed = $query->param('issueconfirmed');
70 if ($query->param('setcookies')) {
71 $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
72 $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
75 my %env; # env is used as an "environment" variable. Could be dropped probably...
76 $env{'branchcode'}=$branch;
77 $env{'printer'}=$printer;
78 $env{'queue'}=$printer;
80 my @datearr = localtime(time());
81 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
82 my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", ($datearr[3]));
84 # get the borrower information.....
86 if ($borrowernumber) {
87 $borrower = getpatroninformation(\%env,$borrowernumber,0);
93 # STEP 2 : FIND BORROWER
94 # if there is a list of find borrowers....
98 my ($count,$borrowers)=BornameSearch(\%env,$findborrower,'web');
99 my @borrowers=@$borrowers;
100 if ($#borrowers == -1) {
101 $query->param('findborrower', '');
102 } elsif ($#borrowers == 0) {
103 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
104 $query->param('barcode','');
106 $borrowerslist = \@borrowers;
115 # check and see if we should print
116 # if ($barcode eq '' && $print eq 'maybe'){
119 # if ($print eq 'yes' && $borrowernumber ne ''){
120 # printslip(\%env,$borrowernumber);
121 # $query->param('borrnumber','');
122 # $borrowernumber='';
126 $barcode = cuecatbarcodedecode($barcode);
127 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
128 # unless ($invalidduedate) {
129 my ($error, $question) = canbookbeissued(\%env, $borrower, $barcode, $year, $month, $day);
132 foreach my $impossible (keys %$error) {
133 warn "Impossible : $impossible : ";#.%$error->{$impossible};
134 $template->param($impossible => 1,
138 foreach my $needsconfirmation (keys %$question) {
139 warn "needsconfirmation : $needsconfirmation : "; #.%$error->{$needsconfirmation};
140 $template->param($needsconfirmation => 1,
141 NEEDSCONFIRMATION => 1);
144 if ($noerror && ($noquestion || $issueconfirmed)) {
146 # issuebook(\%env, $borrower, $barcode, $datedue);
152 # reload the borrower info for the sake of reseting the flags.....
153 if ($borrowernumber) {
154 $borrower = getpatroninformation(\%env,$borrowernumber,0);
158 ##################################################################################
161 # make the issued books table.....
168 # get each issue of the borrower & separate them in todayissues & previous issues
171 my $issueslist = getissues($borrower);
172 # split in 2 arrays for today & previous
173 foreach my $it (keys %$issueslist) {
174 my $issuedate = $issueslist->{$it}->{'timestamp'};
175 $issuedate = substr($issuedate, 0, 8);
176 if ($todaysdate == $issuedate) {
177 push @todaysissues, $issueslist->{$it};
179 push @previousissues, $issueslist->{$it};
184 # parses today & build Template array
185 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
186 my $dd = $book->{'date_due'};
187 my $datedue = $book->{'date_due'};
188 $dd=format_date($dd);
190 if ($datedue < $todaysdate) {
197 $book->{'tcolor'}=$togglecolor;
203 if ($book->{'author'} eq ''){
204 $book->{'author'}=' ';
206 push @realtodayissues,$book;
209 # parses previous & build Template array
210 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
211 my $dd = $book->{'date_due'};
212 my $datedue = $book->{'date_due'};
213 $dd=format_date($dd);
217 if ($datedue < $todaysdate) {
222 $book->{'tcolor'}=$togglecolor;
230 $book->{'tcolor'}=$pcolor;
231 if ($book->{'author'} eq ''){
232 $book->{'author'}=' ';
234 push @realprevissues,$book
241 my $CGIselectborrower;
242 if ($borrowerslist) {
243 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
244 push @values,$_->{'borrowernumber'};
245 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})";
247 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
255 my ($patrontable, $flaginfotable) = patrontable($borrower);
256 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'};
257 my @temp=split(/\$/,$amountold);
260 findborrower => $findborrower,
261 borrower => $borrower,
262 borrowernumber => $borrowernumber,
265 branchname => $branches->{$branch}->{'branchname'},
266 printername => $printers->{$printer}->{'printername'},
267 # title => $iteminformation->{'title'},
268 # author => $iteminformation->{'author'},
269 firstname => $borrower->{'firstname'},
270 surname => $borrower->{'surname'},
271 categorycode => $borrower->{'categorycode'},
272 streetaddress => $borrower->{'streetaddress'},
273 city => $borrower->{'city'},
274 phone => $borrower->{'phone'},
275 cardnumber => $borrower->{'cardnumber'},
276 amountold => $amountold,
278 stickyduedate => $stickyduedate,
279 CGIselectborrower => $CGIselectborrower,
280 todayissues => \@realtodayissues,
281 previssues => \@realprevissues,
283 # set return date if stickyduedate
284 if ($stickyduedate) {
285 my $t_year = "year".$year;
286 my $t_month = "month".$month;
287 my $t_day = "day".$day;
297 $cookie=[$cookie, $branchcookie, $printercookie];
300 output_html_with_http_headers $query, $cookie, $template->output;
302 ####################################################################
303 # Extra subroutines,,,
305 sub cuecatbarcodedecode {
308 my @fields = split(/\./,$barcode);
309 my @results = map(decode($_), @fields[1..$#fields]);
320 my $flags = $borrower->{'flags'};
321 my $flaginfotable='';
323 #my $flaginfotext='';
326 foreach $flag (sort keys %$flags) {
327 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
328 if ($flags->{$flag}->{'noissues'}) {
338 if ($flag eq 'LOST'){
343 if ($flag eq 'DBARRED'){
348 if ($flag eq 'CHARGES') {
351 chargesmsg => $flags->{'CHARGES'}->{'message'}
355 if ($flag eq 'CHARGES') {
358 chargesmsg => $flags->{'CHARGES'}->{'message'}
361 if ($flag eq 'WAITING') {
362 my $items=$flags->{$flag}->{'itemlist'};
364 foreach my $item (@$items) {
365 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
366 $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
367 push @itemswaiting, $iteminformation;
371 waitingmsg => $flags->{'WAITING'}->{'message'},
372 itemswaiting => \@itemswaiting,
375 if ($flag eq 'ODUES') {
378 oduesmsg => $flags->{'ODUES'}->{'message'}
381 my $items=$flags->{$flag}->{'itemlist'};
382 my $currentcolor=$color;
384 my $color=$currentcolor;
386 foreach my $item (@$items) {
387 # ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
388 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
389 push @itemswaiting, $iteminformation;
392 if ($query->param('module') ne 'returns'){
393 $template->param( nonreturns => 'true' );
396 if ($flag eq 'NOTES') {
399 notesmsg => $flags->{'NOTES'}->{'message'}
404 return($patrontable, $flaginfotext);