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; # FIXME env is used as an "environment" variable. Could be dropped probably...
78 $env{'branchcode'}=$branch;
79 $env{'printer'}=$printer;
80 $env{'queue'}=$printer;
82 my @datearr = localtime(time());
83 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
84 my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", ($datearr[3]));
88 # check and see if we should print
89 if ($barcode eq '' && $print eq 'maybe'){
92 if ($print eq 'yes' && $borrowernumber ne ''){
93 printslip(\%env,$borrowernumber);
94 $query->param('borrnumber','');
99 # STEP 2 : FIND BORROWER
100 # if there is a list of find borrowers....
104 my ($count,$borrowers)=BornameSearch(\%env,$findborrower,'web');
105 my @borrowers=@$borrowers;
106 if ($#borrowers == -1) {
107 $query->param('findborrower', '');
108 } elsif ($#borrowers == 0) {
109 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
110 $query->param('barcode','');
111 $borrowernumber=$borrowers[0]->{'borrowernumber'};
113 $borrowerslist = \@borrowers;
117 # get the borrower information.....
119 if ($borrowernumber) {
120 $borrower = getpatroninformation(\%env,$borrowernumber,0);
121 my ($od,$issue,$fines)=borrdata2(\%env,$borrowernumber);
122 $template->param(overduecount => $od,
123 issuecount => $issue,
124 finetotal => $fines);
136 $barcode = cuecatbarcodedecode($barcode);
137 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
138 if ($issueconfirmed) {
139 issuebook(\%env, $borrower, $barcode, $datedue);
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 $template->param(day => $day,
157 if ($noerror && ($noquestion || $issueconfirmed)) {
158 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 firstname => $borrower->{'firstname'},
279 surname => $borrower->{'surname'},
280 categorycode => $borrower->{'categorycode'},
281 streetaddress => $borrower->{'streetaddress'},
282 borrowernotes => $borrower->{'borrowernotes'},
283 city => $borrower->{'city'},
284 phone => $borrower->{'phone'},
285 cardnumber => $borrower->{'cardnumber'},
286 amountold => $amountold,
288 stickyduedate => $stickyduedate,
289 CGIselectborrower => $CGIselectborrower,
290 todayissues => \@realtodayissues,
291 previssues => \@realprevissues,
293 # set return date if stickyduedate
294 if ($stickyduedate) {
295 my $t_year = "year".$year;
296 my $t_month = "month".$month;
297 my $t_day = "day".$day;
307 $cookie=[$cookie, $branchcookie, $printercookie];
310 output_html_with_http_headers $query, $cookie, $template->output;
312 ####################################################################
313 # Extra subroutines,,,
317 my $flags = $borrower->{'flags'};
318 my $flaginfotable='';
320 #my $flaginfotext='';
323 foreach $flag (sort keys %$flags) {
324 # my @itemswaiting='';
325 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
326 if ($flags->{$flag}->{'noissues'}) {
335 if ($flag eq 'LOST'){
340 if ($flag eq 'DBARRED'){
345 if ($flag eq 'CHARGES') {
348 chargesmsg => $flags->{'CHARGES'}->{'message'}
352 if ($flag eq 'CHARGES') {
355 chargesmsg => $flags->{'CHARGES'}->{'message'}
358 if ($flag eq 'WAITING') {
359 my $items=$flags->{$flag}->{'itemlist'};
361 foreach my $item (@$items) {
362 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
363 $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
364 push @itemswaiting, $iteminformation;
368 waitingmsg => $flags->{'WAITING'}->{'message'},
369 itemswaiting => \@itemswaiting,
372 if ($flag eq 'ODUES') {
375 oduesmsg => $flags->{'ODUES'}->{'message'}
378 my $items=$flags->{$flag}->{'itemlist'};
381 foreach my $item (@$items) {
382 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
383 push @itemswaiting, $iteminformation;
386 if ($query->param('module') ne 'returns'){
387 $template->param( nonreturns => 'true' );
390 if ($flag eq 'NOTES') {
393 notesmsg => $flags->{'NOTES'}->{'message'}
398 return($patrontable, $flaginfotext);
401 sub cuecatbarcodedecode {
404 my @fields = split(/\./,$barcode);
405 my @results = map(decode($_), @fields[1..$#fields]);