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 $template->param(day => $day,
154 if ($noerror && ($noquestion || $issueconfirmed)) {
155 issuebook(\%env, $borrower, $barcode, $datedue);
160 # reload the borrower info for the sake of reseting the flags.....
161 if ($borrowernumber) {
162 $borrower = getpatroninformation(\%env,$borrowernumber,0);
166 ##################################################################################
169 # make the issued books table.....
176 # get each issue of the borrower & separate them in todayissues & previous issues
179 my $issueslist = getissues($borrower);
180 # split in 2 arrays for today & previous
181 foreach my $it (keys %$issueslist) {
182 my $issuedate = $issueslist->{$it}->{'timestamp'};
183 $issuedate = substr($issuedate, 0, 8);
184 if ($todaysdate == $issuedate) {
185 push @todaysissues, $issueslist->{$it};
187 push @previousissues, $issueslist->{$it};
192 # parses today & build Template array
193 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
194 my $dd = $book->{'date_due'};
195 my $datedue = $book->{'date_due'};
196 $dd=format_date($dd);
198 if ($datedue < $todaysdate) {
205 $book->{'tcolor'}=$togglecolor;
211 if ($book->{'author'} eq ''){
212 $book->{'author'}=' ';
214 push @realtodayissues,$book;
217 # parses previous & build Template array
218 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
219 my $dd = $book->{'date_due'};
220 my $datedue = $book->{'date_due'};
221 $dd=format_date($dd);
225 if ($datedue < $todaysdate) {
230 $book->{'tcolor'}=$togglecolor;
238 $book->{'tcolor'}=$pcolor;
239 if ($book->{'author'} eq ''){
240 $book->{'author'}=' ';
242 push @realprevissues,$book
249 my $CGIselectborrower;
250 if ($borrowerslist) {
251 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
252 push @values,$_->{'borrowernumber'};
253 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})";
255 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
263 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'};
264 my @temp=split(/\$/,$amountold);
267 findborrower => $findborrower,
268 borrower => $borrower,
269 borrowernumber => $borrowernumber,
272 branchname => $branches->{$branch}->{'branchname'},
273 printername => $printers->{$printer}->{'printername'},
274 firstname => $borrower->{'firstname'},
275 surname => $borrower->{'surname'},
276 categorycode => $borrower->{'categorycode'},
277 streetaddress => $borrower->{'streetaddress'},
278 borrowernotes => $borrower->{'borrowernotes'},
279 city => $borrower->{'city'},
280 phone => $borrower->{'phone'},
281 cardnumber => $borrower->{'cardnumber'},
282 amountold => $amountold,
284 stickyduedate => $stickyduedate,
285 CGIselectborrower => $CGIselectborrower,
286 todayissues => \@realtodayissues,
287 previssues => \@realprevissues,
289 # set return date if stickyduedate
290 if ($stickyduedate) {
291 my $t_year = "year".$year;
292 my $t_month = "month".$month;
293 my $t_day = "day".$day;
303 $cookie=[$cookie, $branchcookie, $printercookie];
306 output_html_with_http_headers $query, $cookie, $template->output;
308 ####################################################################
309 # Extra subroutines,,,
311 sub cuecatbarcodedecode {
314 my @fields = split(/\./,$barcode);
315 my @results = map(decode($_), @fields[1..$#fields]);