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');
68 my $cancelreserve = $query->param('cancelreserve');
74 if ($query->param('setcookies')) {
75 $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
76 $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
79 my %env; # FIXME env is used as an "environment" variable. Could be dropped probably...
81 $env{'branchcode'}=$branch;
82 $env{'printer'}=$printer;
83 $env{'queue'}=$printer;
85 my @datearr = localtime(time());
86 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
87 my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", ($datearr[3]));
91 # check and see if we should print
92 if ($barcode eq '' && $print eq 'maybe'){
95 if ($print eq 'yes' && $borrowernumber ne ''){
96 printslip(\%env,$borrowernumber);
97 $query->param('borrnumber','');
102 # STEP 2 : FIND BORROWER
103 # if there is a list of find borrowers....
107 my ($count,$borrowers)=BornameSearch(\%env,$findborrower,'web');
108 my @borrowers=@$borrowers;
109 if ($#borrowers == -1) {
110 $query->param('findborrower', '');
111 } elsif ($#borrowers == 0) {
112 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
113 $query->param('barcode','');
114 $borrowernumber=$borrowers[0]->{'borrowernumber'};
116 $borrowerslist = \@borrowers;
120 # get the borrower information.....
122 if ($borrowernumber) {
123 $borrower = getpatroninformation(\%env,$borrowernumber,0);
124 my ($od,$issue,$fines)=borrdata2(\%env,$borrowernumber);
125 $template->param(overduecount => $od,
126 issuecount => $issue,
127 finetotal => $fines);
139 $barcode = cuecatbarcodedecode($barcode);
140 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
141 if ($issueconfirmed) {
142 issuebook(\%env, $borrower, $barcode, $datedue,$cancelreserve);
144 my ($error, $question) = canbookbeissued(\%env, $borrower, $barcode, $year, $month, $day);
147 foreach my $impossible (keys %$error) {
148 $template->param($impossible => $$error{$impossible},
152 foreach my $needsconfirmation (keys %$question) {
153 $template->param($needsconfirmation => $$question{$needsconfirmation},
154 NEEDSCONFIRMATION => 1);
157 $template->param(day => $day,
160 if ($noerror && ($noquestion || $issueconfirmed)) {
161 issuebook(\%env, $borrower, $barcode, $datedue);
166 # reload the borrower info for the sake of reseting the flags.....
167 if ($borrowernumber) {
168 $borrower = getpatroninformation(\%env,$borrowernumber,0);
172 ##################################################################################
175 # make the issued books table.....
182 # get each issue of the borrower & separate them in todayissues & previous issues
185 my $issueslist = getissues($borrower);
186 # split in 2 arrays for today & previous
187 foreach my $it (keys %$issueslist) {
188 my $issuedate = $issueslist->{$it}->{'timestamp'};
189 $issuedate = substr($issuedate, 0, 8);
190 if ($todaysdate == $issuedate) {
191 push @todaysissues, $issueslist->{$it};
193 push @previousissues, $issueslist->{$it};
198 # parses today & build Template array
199 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
200 my $dd = $book->{'date_due'};
201 my $datedue = $book->{'date_due'};
202 $dd=format_date($dd);
204 if ($datedue < $todaysdate) {
211 $book->{'tcolor'}=$togglecolor;
217 if ($book->{'author'} eq ''){
218 $book->{'author'}=' ';
220 push @realtodayissues,$book;
223 # parses previous & build Template array
224 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
225 my $dd = $book->{'date_due'};
226 my $datedue = $book->{'date_due'};
227 $dd=format_date($dd);
231 if ($datedue < $todaysdate) {
236 $book->{'tcolor'}=$togglecolor;
244 $book->{'tcolor'}=$pcolor;
245 if ($book->{'author'} eq ''){
246 $book->{'author'}=' ';
248 push @realprevissues,$book
255 my $CGIselectborrower;
256 if ($borrowerslist) {
257 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
258 push @values,$_->{'borrowernumber'};
259 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})";
261 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
269 my ($patrontable, $flaginfotable) = patrontable($borrower);
270 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'};
271 my @temp=split(/\$/,$amountold);
274 findborrower => $findborrower,
275 borrower => $borrower,
276 borrowernumber => $borrowernumber,
279 branchname => $branches->{$branch}->{'branchname'},
280 printername => $printers->{$printer}->{'printername'},
281 firstname => $borrower->{'firstname'},
282 surname => $borrower->{'surname'},
283 categorycode => $borrower->{'categorycode'},
284 streetaddress => $borrower->{'streetaddress'},
285 emailaddress => $borrower->{'emailaddress'},
286 borrowernotes => $borrower->{'borrowernotes'},
287 city => $borrower->{'city'},
288 phone => $borrower->{'phone'},
289 cardnumber => $borrower->{'cardnumber'},
290 amountold => $amountold,
292 stickyduedate => $stickyduedate,
293 CGIselectborrower => $CGIselectborrower,
294 todayissues => \@realtodayissues,
295 previssues => \@realprevissues,
297 # set return date if stickyduedate
298 if ($stickyduedate) {
299 my $t_year = "year".$year;
300 my $t_month = "month".$month;
301 my $t_day = "day".$day;
311 $cookie=[$cookie, $branchcookie, $printercookie];
314 output_html_with_http_headers $query, $cookie, $template->output;
316 ####################################################################
317 # Extra subroutines,,,
321 my $flags = $borrower->{'flags'};
322 my $flaginfotable='';
324 #my $flaginfotext='';
327 foreach $flag (sort keys %$flags) {
328 # my @itemswaiting='';
329 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
330 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'};
385 foreach my $item (@$items) {
386 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
387 push @itemswaiting, $iteminformation;
390 if ($query->param('module') ne 'returns'){
391 $template->param( nonreturns => 'true' );
394 if ($flag eq 'NOTES') {
397 notesmsg => $flags->{'NOTES'}->{'message'}
402 return($patrontable, $flaginfotext);
405 sub cuecatbarcodedecode {
408 my @fields = split(/\./,$barcode);
409 my @results = map(decode($_), @fields[1..$#fields]);