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...
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);
110 my ($od,$issue,$fines)=borrdata2(\%env,$borrowernumber);
111 $template->param(overduecount => $od,
112 issuecount => $issue,
113 finetotal => $fines);
122 # check and see if we should print
123 # if ($barcode eq '' && $print eq 'maybe'){
126 # if ($print eq 'yes' && $borrowernumber ne ''){
127 # printslip(\%env,$borrowernumber);
128 # $query->param('borrnumber','');
129 # $borrowernumber='';
133 $barcode = cuecatbarcodedecode($barcode);
134 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
135 if ($issueconfirmed) {
136 issuebook(\%env, $borrower, $barcode, $datedue);
138 my ($error, $question) = canbookbeissued(\%env, $borrower, $barcode, $year, $month, $day);
141 foreach my $impossible (keys %$error) {
142 $template->param($impossible => $$error{$impossible},
146 foreach my $needsconfirmation (keys %$question) {
147 $template->param($needsconfirmation => $$question{$needsconfirmation},
148 NEEDSCONFIRMATION => 1);
151 if ($noerror && ($noquestion || $issueconfirmed)) {
152 issuebook(\%env, $borrower, $barcode, $datedue);
157 # reload the borrower info for the sake of reseting the flags.....
158 if ($borrowernumber) {
159 $borrower = getpatroninformation(\%env,$borrowernumber,0);
163 ##################################################################################
166 # make the issued books table.....
173 # get each issue of the borrower & separate them in todayissues & previous issues
176 my $issueslist = getissues($borrower);
177 # split in 2 arrays for today & previous
178 foreach my $it (keys %$issueslist) {
179 my $issuedate = $issueslist->{$it}->{'timestamp'};
180 $issuedate = substr($issuedate, 0, 8);
181 if ($todaysdate == $issuedate) {
182 push @todaysissues, $issueslist->{$it};
184 push @previousissues, $issueslist->{$it};
189 # parses today & build Template array
190 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
191 my $dd = $book->{'date_due'};
192 my $datedue = $book->{'date_due'};
193 $dd=format_date($dd);
195 if ($datedue < $todaysdate) {
202 $book->{'tcolor'}=$togglecolor;
208 if ($book->{'author'} eq ''){
209 $book->{'author'}=' ';
211 push @realtodayissues,$book;
214 # parses previous & build Template array
215 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
216 my $dd = $book->{'date_due'};
217 my $datedue = $book->{'date_due'};
218 $dd=format_date($dd);
222 if ($datedue < $todaysdate) {
227 $book->{'tcolor'}=$togglecolor;
235 $book->{'tcolor'}=$pcolor;
236 if ($book->{'author'} eq ''){
237 $book->{'author'}=' ';
239 push @realprevissues,$book
246 my $CGIselectborrower;
247 if ($borrowerslist) {
248 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
249 push @values,$_->{'borrowernumber'};
250 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})";
252 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
260 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'};
261 my @temp=split(/\$/,$amountold);
264 findborrower => $findborrower,
265 borrower => $borrower,
266 borrowernumber => $borrowernumber,
269 branchname => $branches->{$branch}->{'branchname'},
270 printername => $printers->{$printer}->{'printername'},
271 firstname => $borrower->{'firstname'},
272 surname => $borrower->{'surname'},
273 categorycode => $borrower->{'categorycode'},
274 streetaddress => $borrower->{'streetaddress'},
275 city => $borrower->{'city'},
276 phone => $borrower->{'phone'},
277 cardnumber => $borrower->{'cardnumber'},
278 amountold => $amountold,
280 stickyduedate => $stickyduedate,
281 CGIselectborrower => $CGIselectborrower,
282 todayissues => \@realtodayissues,
283 previssues => \@realprevissues,
285 # set return date if stickyduedate
286 if ($stickyduedate) {
287 my $t_year = "year".$year;
288 my $t_month = "month".$month;
289 my $t_day = "day".$day;
299 $cookie=[$cookie, $branchcookie, $printercookie];
302 output_html_with_http_headers $query, $cookie, $template->output;
304 ####################################################################
305 # Extra subroutines,,,
307 sub cuecatbarcodedecode {
310 my @fields = split(/\./,$barcode);
311 my @results = map(decode($_), @fields[1..$#fields]);