2 #this code has been modified (slightly) by Trendsetters (originally from circulation.pl)
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
40 #my ($loggedinuser, $sessioncookie, $sessionID) = checkauth
41 # ($query, 0, { circulate => 1 });
43 my ($template, $loggedinuser, $cookie) = get_template_and_user
45 #Begin code modified by Christina Lee
46 template_name => 'sco/receipt.tmpl',
50 flagsrequired => { borrow => 1 },
51 # End Code Modified by Christina Lee
54 #Begin code by Christina Lee--Sets variable $borr equal to loggedinuser's data
55 my ($borr, $flags) = getpatroninformation(undef, $loggedinuser);
56 # End code by Christina Lee
59 my $linecolor1='#339999';
60 my $linecolor2='white';
62 my $branches = getbranches();
63 my $printers = getprinters(\%env);
65 my $branch = "APL"; #getbranch($query, $branches);
66 my $printer = getprinter($query, $printers);
72 if ($query->param('setcookies')) {
73 $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
74 $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
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]));
86 ################# Start code modified by Christina Lee###########################
87 # get borrower information ....
88 #my ($borr, $flags) = getpatroninformation(undef, $loggedinusername);
92 #$template->param(BORROWER_INFO => \@bordat);
97 ######################End code modified by christina Lee############################
101 # if there is a list of find borrowers....
102 my $findborrower = $query->param('findborrower');
104 my ($count,$borrowers)=BornameSearch(\%env,$findborrower,'web');
105 my @borrowers=@$borrowers;
106 if ($#borrowers == -1) {
107 $query->param('findborrower', '');
108 $message = "'$findborrower'";
109 } elsif ($#borrowers == 0) {
110 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
111 $query->param('barcode','');
113 $borrowerslist = \@borrowers;
118 my $borrowernumber = $query->param('borrnumber');
119 my $bornum = $query->param('borrnumber');
120 # check and see if we should print
121 my $print=$query->param('print');
122 my $barcode = $query->param('barcode');
123 if ($barcode eq '' && $print eq 'maybe'){
126 if ($print eq 'yes' && $borrowernumber ne ''){
127 printslip(\%env,$borrowernumber);
128 $query->param('borrnumber','');
132 # get the borrower information.....
135 if ($borrowernumber) {
136 ($borrower, $flags) = getpatroninformation(\%env,$borrowernumber,0);
139 # get the responses to any questions.....
141 foreach (sort $query->param) {
142 if ($_ =~ /response-(\d*)/) {
143 $responses{$1} = $query->param($_);
146 if (my $qnumber = $query->param('questionnumber')) {
147 $responses{$qnumber} = $query->param('answer');
152 my ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer);
153 #Begin code edited by Christina Lee
154 #my $barc = 123456789;
155 my $barc = cuecatbarcodedecode($barcode);
158 (my $year, my $month, my $day) = set_duedate($barc);
159 #End code edited by Christina Lee
161 # if the barcode is set
163 $barcode = cuecatbarcodedecode($barcode);
167 #note: edit code here --Christina Lee
168 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
169 unless ($invalidduedate) {
170 $env{'datedue'}=$datedue;
171 my @time=localtime(time);
172 my $date= (1900+$time[5])."-".($time[4]+1)."-".$time[3];
173 ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer, $message)
174 = issuebook(\%env, $borr, $barcode, \%responses, $date);
178 # reload the borrower info for the sake of reseting the flags.....
179 if ($borrowernumber) {
180 ($borrower, $flags) = getpatroninformation(\%env,$borrowernumber,0);
183 ##################################################################################
188 foreach (keys %responses) {
189 # $responsesform.="<input type=hidden name=response-$_ value=$responses{$_}>\n";
190 $responseform{'name'}=$_;
191 $responseform{'value'}=$responses{$_};
192 push @responsearray,\%responseform;
197 $stickyduedate=$query->param('stickyduedate');
201 # Barcode entry box, with hidden inputs attached....
203 # FIXME - How can we move this HTML into the template? Can we create
204 # arrays of the months, dates, etc and use <TMPL_LOOP> in the template to
205 # output the data that's getting built here?
208 my $monthoptions = '';
209 my $yearoptions = '';
210 for (my $i=1; $i<32; $i++) {
212 if (($query->param('stickyduedate')) && ($day==$i)) {
213 $selected='selected';
215 $dayoptions.="<option value=$i $selected>$i";
217 foreach (('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')) {
219 if (($query->param('stickyduedate')) && ($month==$counter)) {
220 $selected='selected';
222 $monthoptions.="<option value=$counter $selected>$_";
225 for (my $i=$datearr[5]+1900; $i<$datearr[5]+1905; $i++) {
227 if (($query->param('stickyduedate')) && ($year==$i)) {
228 $selected='selected';
230 $yearoptions.="<option value=$i $selected>$i";
233 ($query->param('stickyduedate')) && ($selected='checked');
236 # make the issued books table.....
243 # Begin code altered by christina Lee
245 ($borr, $flags,$hash) = getpatroninformation(\%env,$loggedinuser,0);
246 # End code altered by Christina Lee
247 $allowborrow= $hash->{'borrow'};
250 # Begin code altered by Christina Lee
251 my $issueslist = getissues($borr);
252 # End code altered by Christina Lee
253 foreach my $it (keys %$issueslist) {
254 my $issuedate = $issueslist->{$it}->{'timestamp'};
255 $issuedate = substr($issuedate, 0, 8);
256 if ($todaysdate == $issuedate) {
257 push @todaysissues, $issueslist->{$it};
259 push @previousissues, $issueslist->{$it};
265 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
266 my $dd = $book->{'date_due'};
268 my $datedue = $book->{'date_due'};
269 $dd=format_date($dd);
271 if ($datedue < $todaysdate) {
275 ($tcolor eq $linecolor1) ? ($tcolor=$linecolor2) : ($tcolor=$linecolor1);
278 $book->{'tcolor'}=$tcolor;
279 if ($book->{'author'} eq ''){
280 $book->{'author'}=' ';
282 push @realtodayissues,$book;
286 # FIXME - For small and private libraries, it'd be nice if this
287 # table included a "Return" link next to each book, so that you
288 # don't have to remember the book's bar code and type it in on the
291 # This is in the template now, so its possible for a small library to make that link in their
294 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
295 my $dd = $book->{'date_due'};
298 my $datedue = $book->{'date_due'};
299 $dd=format_date($dd);
303 if ($datedue < $todaysdate) {
307 ($pcolor eq $linecolor1) ? ($pcolor=$linecolor2) : ($pcolor=$linecolor1);
310 $book->{'tcolor'}=$pcolor;
311 if ($book->{'author'} eq ''){
312 $book->{'author'}=' ';
314 push @realprevissues,$book
320 my $CGIselectborrower;
321 if ($borrowerslist) {
322 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
323 push @values,$_->{'borrowernumber'};
324 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})";
326 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
334 my ($patrontable, $flaginfotable) = patrontable($borrower);
335 my $amountold=$flags->{'CHARGES'}->{'message'};
336 my @temp=split(/\$/,$amountold);
339 findborrower => $findborrower,
340 borrower => $borrower,
341 borrowernumber => $borrowernumber,
344 branchname => $branches->{$branch}->{'branchname'},
345 printername => $printers->{$printer}->{'printername'},
346 allowborrow =>$allowborrow,
348 question => $question,
349 title => $iteminformation->{'title'},
350 author => $iteminformation->{'author'},
351 #Begin code by Christina Lee
352 firstname => $borr->{'firstname'},
353 surname => $borr->{'surname'},
354 categorycode => $borr->{'categorycode'},
355 streetaddress => $borr->{'streetaddress'},
356 city => $borr->{'city'},
357 phone => $borr->{'phone'},
358 cardnumber => $borr->{'cardnumber'},
359 #End code by Christina Lee
360 question => $question,
362 questionnumber => $questionnumber,
363 dayoptions => $dayoptions,
364 monthoptions => $monthoptions,
365 yearoptions => $yearoptions,
366 stickyduedate => $stickyduedate,
367 rejected => $rejected,
369 CGIselectborrower => $CGIselectborrower,
370 amountold => $amountold,
371 todayissues => \@realtodayissues,
372 previssues => \@realprevissues,
373 responseloop => \@responsearray,
381 $cookie=[$cookie, $branchcookie, $printercookie];
384 output_html_with_http_headers $query, $cookie, $template->output;
386 ####################################################################
387 # Extra subroutines,,,
389 sub cuecatbarcodedecode {
392 my @fields = split(/\./,$barcode);
393 my @results = map(decode($_), @fields[1..$#fields]);
402 my ($year, $month, $day) = @_;
405 if (($year eq 0) && ($month eq 0) && ($year eq 0)) {
409 # FIXME - Can we set two flags here, one that says 'invalidduedate', so that
410 # the template can check for it, and then one for a particular message?
411 # Ex: <TMPL_IF NAME="invalidduedate"> <TMPL_IF NAME="daysinFeb">
412 # Invalid Due Date Specified. Book was not issued. Never that many days
413 # in February! </TMPL_IF> </TMPL_IF>
415 if (($year eq 0) || ($month eq 0) || ($year eq 0)) {
416 $invalidduedate="Invalid Due Date Specified. Book was not issued.<p>\n";
418 if (($day>30) && (($month==4) || ($month==6) || ($month==9) || ($month==11))) {
419 $invalidduedate = "Invalid Due Date Specified. Book was not issued. Only 30 days in $month month.<p>\n";
420 } elsif (($day > 29) && ($month == 2)) {
421 $invalidduedate="Invalid Due Date Specified. Book was not issued. Never that many days in February!<p>\n";
422 } elsif (($month == 2) && ($day > 28) && (($year%4) && ((!($year%100) || ($year%400))))) {
423 $invalidduedate="Invalid Due Date Specified. Book was not issued. $year is not a leap year.<p>\n";
425 $date="$year-$month-$day";
429 return ($date, $invalidduedate);
435 my $flags = $borrower->{'flags'};
436 my $flaginfotable='';
438 #my $flaginfotext='';
441 foreach $flag (sort keys %$flags) {
443 # my @itemswaiting='';
444 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
445 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
446 if ($flags->{$flag}->{'noissues'}) {
456 if ($flag eq 'LOST'){
461 if ($flag eq 'DBARRED'){
466 if ($flag eq 'CHARGES') {
469 chargesmsg => $flags->{'CHARGES'}->{'message'}
473 if ($flag eq 'CHARGES') {
476 chargesmsg => $flags->{'CHARGES'}->{'message'}
479 if ($flag eq 'WAITING') {
480 my $items=$flags->{$flag}->{'itemlist'};
482 foreach my $item (@$items) {
483 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
484 $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
485 push @itemswaiting, $iteminformation;
489 waitingmsg => $flags->{'WAITING'}->{'message'},
490 itemswaiting => \@itemswaiting,
493 if ($flag eq 'ODUES') {
496 oduesmsg => $flags->{'ODUES'}->{'message'}
499 my $items=$flags->{$flag}->{'itemlist'};
500 my $currentcolor=$color;
502 my $color=$currentcolor;
504 foreach my $item (@$items) {
505 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
506 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
507 push @itemswaiting, $iteminformation;
510 if ($query->param('module') ne 'returns'){
511 $template->param( nonreturns => 'true' );
514 if ($flag eq 'NOTES') {
517 notesmsg => $flags->{'NOTES'}->{'message'}
522 return($patrontable, $flaginfotext);
526 # FIXME - This clashes with &C4::Print::printslip
528 my ($env,$borrowernumber)=@_;
529 my ($borrower, $flags) = getpatroninformation($env,$borrowernumber,0);
530 $env->{'todaysissues'}=1;
531 my ($borrowerissues) = currentissues($env, $borrower);
532 $env->{'nottodaysissues'}=1;
533 $env->{'todaysissues'}=0;
534 my ($borroweriss2)=currentissues($env, $borrower);
535 $env->{'nottodaysissues'}=0;
538 foreach (sort {$a <=> $b} keys %$borrowerissues) {
539 $issues[$i]=$borrowerissues->{$_};
540 my $dd=$issues[$i]->{'date_due'};
541 #convert to nz style dates
542 #this should be set with some kinda config variable
543 my @tempdate=split(/-/,$dd);
544 $issues[$i]->{'date_due'}="$tempdate[2]/$tempdate[1]/$tempdate[0]";
547 foreach (sort {$a <=> $b} keys %$borroweriss2) {
548 $issues[$i]=$borroweriss2->{$_};
549 my $dd=$issues[$i]->{'date_due'};
550 #convert to nz style dates
551 #this should be set with some kinda config variable
552 my @tempdate=split(/-/,$dd);
553 $issues[$i]->{'date_due'}="$tempdate[2]/$tempdate[1]/$tempdate[0]";
556 remoteprint($env,\@issues,$borrower);
559 # Begin code added by Christina Lee
564 my $dbh = C4::Context->dbh;
565 my $sth = $dbh->prepare ("select loanlength from biblioitems, biblio,itemtypes, items where barcode = ? and biblio.biblionumber = biblioitems.biblionumber and biblioitems.biblionumber = items.biblionumber and biblioitems.itemtype=itemtypes.itemtype;");
566 $sth->execute($barc);
567 while (my @val = $sth->fetchrow_array())
569 $loanlength = @val[0];
571 (my $s, my $min, my $hr, my $mday, my $mo, my $year, my $wday, my $yday) = localtime(time + $loanlength * 86400);
573 #adjust month and date for output
577 return ($year, $mo, $mday);
584 my $dbh = C4::Context->dbh;
589 # End code added by Christina Lee