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]));
88 # STEP 2 : FIND BORROWER
89 # if there is a list of find borrowers....
93 my ($count,$borrowers)=BornameSearch(\%env,$findborrower,'web');
94 my @borrowers=@$borrowers;
95 if ($#borrowers == -1) {
96 $query->param('findborrower', '');
97 } elsif ($#borrowers == 0) {
98 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
99 $query->param('barcode','');
100 $borrowernumber=$borrowers[0]->{'borrowernumber'};
102 $borrowerslist = \@borrowers;
106 # get the borrower information.....
108 if ($borrowernumber) {
109 $borrower = getpatroninformation(\%env,$borrowernumber,0);
118 # check and see if we should print
119 # if ($barcode eq '' && $print eq 'maybe'){
122 # if ($print eq 'yes' && $borrowernumber ne ''){
123 # printslip(\%env,$borrowernumber);
124 # $query->param('borrnumber','');
125 # $borrowernumber='';
129 $barcode = cuecatbarcodedecode($barcode);
130 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
131 if ($issueconfirmed) {
133 issuebook(\%env, $borrower, $barcode, $datedue);
135 # unless ($invalidduedate) {
136 my ($error, $question) = canbookbeissued(\%env, $borrower, $barcode, $year, $month, $day);
139 foreach my $impossible (keys %$error) {
140 $template->param($impossible => $$error{$impossible},
144 foreach my $needsconfirmation (keys %$question) {
145 $template->param($needsconfirmation => $$question{$needsconfirmation},
146 NEEDSCONFIRMATION => 1);
149 if ($noerror && ($noquestion || $issueconfirmed)) {
151 issuebook(\%env, $borrower, $barcode, $datedue);
158 # reload the borrower info for the sake of reseting the flags.....
159 if ($borrowernumber) {
160 $borrower = getpatroninformation(\%env,$borrowernumber,0);
164 ##################################################################################
167 # make the issued books table.....
174 # get each issue of the borrower & separate them in todayissues & previous issues
177 my $issueslist = getissues($borrower);
178 # split in 2 arrays for today & previous
179 foreach my $it (keys %$issueslist) {
180 my $issuedate = $issueslist->{$it}->{'timestamp'};
181 $issuedate = substr($issuedate, 0, 8);
182 if ($todaysdate == $issuedate) {
183 push @todaysissues, $issueslist->{$it};
185 push @previousissues, $issueslist->{$it};
190 # parses today & build Template array
191 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
192 my $dd = $book->{'date_due'};
193 my $datedue = $book->{'date_due'};
194 $dd=format_date($dd);
196 if ($datedue < $todaysdate) {
203 $book->{'tcolor'}=$togglecolor;
209 if ($book->{'author'} eq ''){
210 $book->{'author'}=' ';
212 push @realtodayissues,$book;
215 # parses previous & build Template array
216 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
217 my $dd = $book->{'date_due'};
218 my $datedue = $book->{'date_due'};
219 $dd=format_date($dd);
223 if ($datedue < $todaysdate) {
228 $book->{'tcolor'}=$togglecolor;
236 $book->{'tcolor'}=$pcolor;
237 if ($book->{'author'} eq ''){
238 $book->{'author'}=' ';
240 push @realprevissues,$book
247 my $CGIselectborrower;
248 if ($borrowerslist) {
249 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
250 push @values,$_->{'borrowernumber'};
251 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})";
253 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
261 my ($patrontable, $flaginfotable) = patrontable($borrower);
262 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'};
263 my @temp=split(/\$/,$amountold);
266 findborrower => $findborrower,
267 borrower => $borrower,
268 borrowernumber => $borrowernumber,
271 branchname => $branches->{$branch}->{'branchname'},
272 printername => $printers->{$printer}->{'printername'},
273 # title => $iteminformation->{'title'},
274 # author => $iteminformation->{'author'},
275 firstname => $borrower->{'firstname'},
276 surname => $borrower->{'surname'},
277 categorycode => $borrower->{'categorycode'},
278 streetaddress => $borrower->{'streetaddress'},
279 city => $borrower->{'city'},
280 phone => $borrower->{'phone'},
281 cardnumber => $borrower->{'cardnumber'},
282 amountold => $amountold,
284 stickyduedate => $stickyduedate,
285 CGIselectborrower => $CGIselectborrower,
286 todayissues => \@realtodayissues,
287 previssues => \@realprevissues,
289 # set return date if stickyduedate
290 if ($stickyduedate) {
291 my $t_year = "year".$year;
292 my $t_month = "month".$month;
293 my $t_day = "day".$day;
303 $cookie=[$cookie, $branchcookie, $printercookie];
306 output_html_with_http_headers $query, $cookie, $template->output;
308 ####################################################################
309 # Extra subroutines,,,
311 sub cuecatbarcodedecode {
314 my @fields = split(/\./,$barcode);
315 my @results = map(decode($_), @fields[1..$#fields]);
326 my $flags = $borrower->{'flags'};
327 my $flaginfotable='';
329 #my $flaginfotext='';
332 foreach $flag (sort keys %$flags) {
333 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
334 if ($flags->{$flag}->{'noissues'}) {
344 if ($flag eq 'LOST'){
349 if ($flag eq 'DBARRED'){
354 if ($flag eq 'CHARGES') {
357 chargesmsg => $flags->{'CHARGES'}->{'message'}
361 if ($flag eq 'CHARGES') {
364 chargesmsg => $flags->{'CHARGES'}->{'message'}
367 if ($flag eq 'WAITING') {
368 my $items=$flags->{$flag}->{'itemlist'};
370 foreach my $item (@$items) {
371 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
372 $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
373 push @itemswaiting, $iteminformation;
377 waitingmsg => $flags->{'WAITING'}->{'message'},
378 itemswaiting => \@itemswaiting,
381 if ($flag eq 'ODUES') {
384 oduesmsg => $flags->{'ODUES'}->{'message'}
387 my $items=$flags->{$flag}->{'itemlist'};
388 my $currentcolor=$color;
390 my $color=$currentcolor;
392 foreach my $item (@$items) {
393 # ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
394 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
395 push @itemswaiting, $iteminformation;
398 if ($query->param('module') ne 'returns'){
399 $template->param( nonreturns => 'true' );
402 if ($flag eq 'NOTES') {
405 notesmsg => $flags->{'NOTES'}->{'message'}
410 return($patrontable, $flaginfotext);