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 $findborrower =~ s|,| |g;
59 $findborrower =~ s|'| |g;
60 my $borrowernumber = $query->param('borrnumber');
61 my $print=$query->param('print');
62 my $barcode = $query->param('barcode');
63 my $year=$query->param('year');
64 my $month=$query->param('month');
65 my $day=$query->param('day');
66 my $stickyduedate=$query->param('stickyduedate');
67 my $issueconfirmed = $query->param('issueconfirmed');
73 if ($query->param('setcookies')) {
74 $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
75 $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
78 my %env; # FIXME env is used as an "environment" variable. Could be dropped probably...
80 $env{'branchcode'}=$branch;
81 $env{'printer'}=$printer;
82 $env{'queue'}=$printer;
84 my @datearr = localtime(time());
85 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
86 my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", ($datearr[3]));
90 # check and see if we should print
91 if ($barcode eq '' && $print eq 'maybe'){
94 if ($print eq 'yes' && $borrowernumber ne ''){
95 printslip(\%env,$borrowernumber);
96 $query->param('borrnumber','');
101 # STEP 2 : FIND BORROWER
102 # if there is a list of find borrowers....
106 my ($count,$borrowers)=BornameSearch(\%env,$findborrower,'web');
107 my @borrowers=@$borrowers;
108 if ($#borrowers == -1) {
109 $query->param('findborrower', '');
110 } elsif ($#borrowers == 0) {
111 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
112 $query->param('barcode','');
113 $borrowernumber=$borrowers[0]->{'borrowernumber'};
115 $borrowerslist = \@borrowers;
119 # get the borrower information.....
121 if ($borrowernumber) {
122 $borrower = getpatroninformation(\%env,$borrowernumber,0);
123 my ($od,$issue,$fines)=borrdata2(\%env,$borrowernumber);
124 $template->param(overduecount => $od,
125 issuecount => $issue,
126 finetotal => $fines);
138 $barcode = cuecatbarcodedecode($barcode);
139 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
140 if ($issueconfirmed) {
141 issuebook(\%env, $borrower, $barcode, $datedue);
143 my ($error, $question) = canbookbeissued(\%env, $borrower, $barcode, $year, $month, $day);
146 foreach my $impossible (keys %$error) {
147 $template->param($impossible => $$error{$impossible},
151 foreach my $needsconfirmation (keys %$question) {
152 $template->param($needsconfirmation => $$question{$needsconfirmation},
153 NEEDSCONFIRMATION => 1);
156 $template->param(day => $day,
159 if ($noerror && ($noquestion || $issueconfirmed)) {
160 issuebook(\%env, $borrower, $barcode, $datedue);
165 # reload the borrower info for the sake of reseting the flags.....
166 if ($borrowernumber) {
167 $borrower = getpatroninformation(\%env,$borrowernumber,0);
171 ##################################################################################
174 # make the issued books table.....
181 # get each issue of the borrower & separate them in todayissues & previous issues
184 my $issueslist = getissues($borrower);
185 # split in 2 arrays for today & previous
186 foreach my $it (keys %$issueslist) {
187 my $issuedate = $issueslist->{$it}->{'timestamp'};
188 $issuedate = substr($issuedate, 0, 8);
189 if ($todaysdate == $issuedate) {
190 push @todaysissues, $issueslist->{$it};
192 push @previousissues, $issueslist->{$it};
197 # parses today & build Template array
198 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
199 my $dd = $book->{'date_due'};
200 my $datedue = $book->{'date_due'};
201 $dd=format_date($dd);
203 if ($datedue < $todaysdate) {
210 $book->{'tcolor'}=$togglecolor;
216 if ($book->{'author'} eq ''){
217 $book->{'author'}=' ';
219 push @realtodayissues,$book;
222 # parses previous & build Template array
223 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
224 my $dd = $book->{'date_due'};
225 my $datedue = $book->{'date_due'};
226 $dd=format_date($dd);
230 if ($datedue < $todaysdate) {
235 $book->{'tcolor'}=$togglecolor;
243 $book->{'tcolor'}=$pcolor;
244 if ($book->{'author'} eq ''){
245 $book->{'author'}=' ';
247 push @realprevissues,$book
254 my $CGIselectborrower;
255 if ($borrowerslist) {
256 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
257 push @values,$_->{'borrowernumber'};
258 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})";
260 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
268 my ($patrontable, $flaginfotable) = patrontable($borrower);
269 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'};
270 my @temp=split(/\$/,$amountold);
273 findborrower => $findborrower,
274 borrower => $borrower,
275 borrowernumber => $borrowernumber,
278 branchname => $branches->{$branch}->{'branchname'},
279 printername => $printers->{$printer}->{'printername'},
280 firstname => $borrower->{'firstname'},
281 surname => $borrower->{'surname'},
282 categorycode => $borrower->{'categorycode'},
283 streetaddress => $borrower->{'streetaddress'},
284 borrowernotes => $borrower->{'borrowernotes'},
285 city => $borrower->{'city'},
286 phone => $borrower->{'phone'},
287 cardnumber => $borrower->{'cardnumber'},
288 amountold => $amountold,
290 stickyduedate => $stickyduedate,
291 CGIselectborrower => $CGIselectborrower,
292 todayissues => \@realtodayissues,
293 previssues => \@realprevissues,
295 # set return date if stickyduedate
296 if ($stickyduedate) {
297 my $t_year = "year".$year;
298 my $t_month = "month".$month;
299 my $t_day = "day".$day;
309 $cookie=[$cookie, $branchcookie, $printercookie];
312 output_html_with_http_headers $query, $cookie, $template->output;
314 ####################################################################
315 # Extra subroutines,,,
319 my $flags = $borrower->{'flags'};
320 my $flaginfotable='';
322 #my $flaginfotext='';
325 foreach $flag (sort keys %$flags) {
326 # my @itemswaiting='';
327 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
328 if ($flags->{$flag}->{'noissues'}) {
337 if ($flag eq 'LOST'){
342 if ($flag eq 'DBARRED'){
347 if ($flag eq 'CHARGES') {
350 chargesmsg => $flags->{'CHARGES'}->{'message'}
354 if ($flag eq 'CHARGES') {
357 chargesmsg => $flags->{'CHARGES'}->{'message'}
360 if ($flag eq 'WAITING') {
361 my $items=$flags->{$flag}->{'itemlist'};
363 foreach my $item (@$items) {
364 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
365 $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
366 push @itemswaiting, $iteminformation;
370 waitingmsg => $flags->{'WAITING'}->{'message'},
371 itemswaiting => \@itemswaiting,
374 if ($flag eq 'ODUES') {
377 oduesmsg => $flags->{'ODUES'}->{'message'}
380 my $items=$flags->{$flag}->{'itemlist'};
383 foreach my $item (@$items) {
384 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
385 push @itemswaiting, $iteminformation;
388 if ($query->param('module') ne 'returns'){
389 $template->param( nonreturns => 'true' );
392 if ($flag eq 'NOTES') {
395 notesmsg => $flags->{'NOTES'}->{'message'}
400 return($patrontable, $flaginfotext);
403 sub cuecatbarcodedecode {
406 my @fields = split(/\./,$barcode);
407 my @results = map(decode($_), @fields[1..$#fields]);