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);
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) {
138 issuebook(\%env, $borrower, $barcode, $datedue);
140 # unless ($invalidduedate) {
141 my ($error, $question) = canbookbeissued(\%env, $borrower, $barcode, $year, $month, $day);
144 foreach my $impossible (keys %$error) {
145 $template->param($impossible => $$error{$impossible},
149 foreach my $needsconfirmation (keys %$question) {
150 $template->param($needsconfirmation => $$question{$needsconfirmation},
151 NEEDSCONFIRMATION => 1);
154 if ($noerror && ($noquestion || $issueconfirmed)) {
156 issuebook(\%env, $borrower, $barcode, $datedue);
163 # reload the borrower info for the sake of reseting the flags.....
164 if ($borrowernumber) {
165 $borrower = getpatroninformation(\%env,$borrowernumber,0);
169 ##################################################################################
172 # make the issued books table.....
179 # get each issue of the borrower & separate them in todayissues & previous issues
182 my $issueslist = getissues($borrower);
183 # split in 2 arrays for today & previous
184 foreach my $it (keys %$issueslist) {
185 my $issuedate = $issueslist->{$it}->{'timestamp'};
186 $issuedate = substr($issuedate, 0, 8);
187 if ($todaysdate == $issuedate) {
188 push @todaysissues, $issueslist->{$it};
190 push @previousissues, $issueslist->{$it};
195 # parses today & build Template array
196 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
197 my $dd = $book->{'date_due'};
198 my $datedue = $book->{'date_due'};
199 $dd=format_date($dd);
201 if ($datedue < $todaysdate) {
208 $book->{'tcolor'}=$togglecolor;
214 if ($book->{'author'} eq ''){
215 $book->{'author'}=' ';
217 push @realtodayissues,$book;
220 # parses previous & build Template array
221 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
222 my $dd = $book->{'date_due'};
223 my $datedue = $book->{'date_due'};
224 $dd=format_date($dd);
228 if ($datedue < $todaysdate) {
233 $book->{'tcolor'}=$togglecolor;
241 $book->{'tcolor'}=$pcolor;
242 if ($book->{'author'} eq ''){
243 $book->{'author'}=' ';
245 push @realprevissues,$book
252 my $CGIselectborrower;
253 if ($borrowerslist) {
254 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
255 push @values,$_->{'borrowernumber'};
256 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})";
258 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
266 my ($patrontable, $flaginfotable) = patrontable($borrower);
267 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'};
268 my @temp=split(/\$/,$amountold);
271 findborrower => $findborrower,
272 borrower => $borrower,
273 borrowernumber => $borrowernumber,
276 branchname => $branches->{$branch}->{'branchname'},
277 printername => $printers->{$printer}->{'printername'},
278 # title => $iteminformation->{'title'},
279 # author => $iteminformation->{'author'},
280 firstname => $borrower->{'firstname'},
281 surname => $borrower->{'surname'},
282 categorycode => $borrower->{'categorycode'},
283 streetaddress => $borrower->{'streetaddress'},
284 city => $borrower->{'city'},
285 phone => $borrower->{'phone'},
286 cardnumber => $borrower->{'cardnumber'},
287 amountold => $amountold,
289 stickyduedate => $stickyduedate,
290 CGIselectborrower => $CGIselectborrower,
291 todayissues => \@realtodayissues,
292 previssues => \@realprevissues,
294 # set return date if stickyduedate
295 if ($stickyduedate) {
296 my $t_year = "year".$year;
297 my $t_month = "month".$month;
298 my $t_day = "day".$day;
308 $cookie=[$cookie, $branchcookie, $printercookie];
311 output_html_with_http_headers $query, $cookie, $template->output;
313 ####################################################################
314 # Extra subroutines,,,
316 sub cuecatbarcodedecode {
319 my @fields = split(/\./,$barcode);
320 my @results = map(decode($_), @fields[1..$#fields]);
331 my $flags = $borrower->{'flags'};
332 my $flaginfotable='';
334 #my $flaginfotext='';
337 foreach $flag (sort keys %$flags) {
338 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
339 if ($flags->{$flag}->{'noissues'}) {
349 if ($flag eq 'LOST'){
354 if ($flag eq 'DBARRED'){
359 if ($flag eq 'CHARGES') {
362 chargesmsg => $flags->{'CHARGES'}->{'message'}
366 if ($flag eq 'CHARGES') {
369 chargesmsg => $flags->{'CHARGES'}->{'message'}
372 if ($flag eq 'WAITING') {
373 my $items=$flags->{$flag}->{'itemlist'};
375 foreach my $item (@$items) {
376 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
377 $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
378 push @itemswaiting, $iteminformation;
382 waitingmsg => $flags->{'WAITING'}->{'message'},
383 itemswaiting => \@itemswaiting,
386 if ($flag eq 'ODUES') {
389 oduesmsg => $flags->{'ODUES'}->{'message'}
392 my $items=$flags->{$flag}->{'itemlist'};
393 my $currentcolor=$color;
395 my $color=$currentcolor;
397 foreach my $item (@$items) {
398 # ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
399 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
400 push @itemswaiting, $iteminformation;
403 if ($query->param('module') ne 'returns'){
404 $template->param( nonreturns => 'true' );
407 if ($flag eq 'NOTES') {
410 notesmsg => $flags->{'NOTES'}->{'message'}
415 return($patrontable, $flaginfotext);