From d389b68e6d53f541d98ac80e33aa9b0cc5a4bb84 Mon Sep 17 00:00:00 2001 From: tonnesen Date: Thu, 25 Jan 2001 00:01:34 +0000 Subject: [PATCH] Refined Returns module. Added ability to select branch and printer. Fixed charges for rental items. --- C4/Circulation/Circ2.pm | 85 ++++++++++++- circ/circulation.pl | 265 ++++++++++++++++++++++++++++++++-------- 2 files changed, 295 insertions(+), 55 deletions(-) diff --git a/C4/Circulation/Circ2.pm b/C4/Circulation/Circ2.pm index a544d2e72e..1dc21055c1 100755 --- a/C4/Circulation/Circ2.pm +++ b/C4/Circulation/Circ2.pm @@ -23,7 +23,7 @@ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 0.01; @ISA = qw(Exporter); -@EXPORT = qw(&getpatroninformation ¤tissues &getiteminformation &findborrower &issuebook &returnbook); +@EXPORT = qw(&getbranches &getprinters &getpatroninformation ¤tissues &getiteminformation &findborrower &issuebook &returnbook); %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], # your exported package globals go here, @@ -80,7 +80,7 @@ sub getprinters { my $sth=$dbh->prepare("select * from printers"); $sth->execute; while (my $printer=$sth->fetchrow_hashref) { - $printers{$printer->{'printername'}}=$printer; + $printers{$printer->{'printqueue'}}=$printer; } return (\%printers); } @@ -184,6 +184,11 @@ sub issuebook { $rejected="Patron's card has been reported lost."; last SWITCH; } + my $amount = checkaccount($env,$patroninformation->{'borrowernumber'}, $dbh); + if ($amount>5) { + $rejected=sprintf "Patron owes \$%.02f.", $amount; + last SWITCH; + } if ($iteminformation->{'notforloan'} == 1) { $rejected="Item not for loan."; last SWITCH; @@ -214,6 +219,12 @@ sub issuebook { $defaultanswer='Y'; last SWITCH; } elsif ($responses->{4} eq 'Y') { + my $charge=calc_charges($env, $dbh, $iteminformation->{'itemnumber'}, $patroninformation->{'borrowernumber'}); + if ($charge > 0) { + createcharge($env, $dbh, $iteminformation->{'itemnumber'}, $patroninformation->{'borrowernumber'}, $charge); + $iteminformation->{'charge'}=$charge; + } + &UpdateStats($env,$env->{'branchcode'},'renew',$charge,'',$iteminformation->{'itemnumber'},$iteminformation->{'itemtype'}); renewbook($env,$dbh, $patroninformation->{'borrowernumber'}, $iteminformation->{'itemnumber'}); $noissue=1; } else { @@ -289,9 +300,19 @@ sub issuebook { $sth=$dbh->prepare("update items set issues=$iteminformation->{'issues'} where itemnumber=$iteminformation->{'itemnumber'}"); $sth->execute; $sth->finish; + my $charge=calc_charges($env, $dbh, $iteminformation->{'itemnumber'}, $patroninformation->{'borrowernumber'}); + if ($charge > 0) { + createcharge($env, $dbh, $iteminformation->{'itemnumber'}, $patroninformation->{'borrowernumber'}, $charge); + $iteminformation->{'charge'}=$charge; + } + &UpdateStats($env,$env->{'branchcode'},'issue',$charge,'',$iteminformation->{'itemnumber'},$iteminformation->{'itemtype'}); + } + my $message=''; + if ($iteminformation->{'charge'}) { + $message=sprintf "Rental charge of \$%.02f applies.", $iteminformation->{'charge'}; } $dbh->disconnect; - return ($iteminformation, $dateduef, $rejected, $question, $questionnumber, $defaultanswer); + return ($iteminformation, $dateduef, $rejected, $question, $questionnumber, $defaultanswer, $message); } @@ -384,7 +405,7 @@ sub patronflags { my $amount = checkaccount($env,$patroninformation->{'borrowernumber'}, $dbh); if ($amount>0) { my %flaginfo; - $flaginfo{'message'}='Patron owes $amount'; + $flaginfo{'message'}=sprintf "Patron owes \$%.02f", $amount; if ($amount>5) { $flaginfo{'noissues'}=1; } @@ -404,7 +425,7 @@ sub patronflags { } if ($patroninformation->{'borrowernotes'}) { my %flaginfo; - $flaginfo{'message'}="Note: $patroninformation->{'borrowernotes'}"; + $flaginfo{'message'}="$patroninformation->{'borrowernotes'}"; $flags{'NOTES'}=\%flaginfo; } my ($odues, $itemsoverdue) = checkoverdues($env,$patroninformation->{'borrowernumber'},$dbh); @@ -628,6 +649,7 @@ sub renewbook { # Stolen from Renewals.pm # mark book as renewed my ($env,$dbh,$bornum,$itemno,$datedue)=@_; + $datedue=$env->{'datedue'}; if ($datedue eq "" ) { my $loanlength=21; my $query= "Select * from biblioitems,items,itemtypes @@ -665,5 +687,58 @@ sub renewbook { return($odatedue); } +sub calc_charges { +# Stolen from Issues.pm +# calculate charges due + my ($env, $dbh, $itemno, $bornum)=@_; + my $charge=0; + my $item_type; + my $q1 = "select itemtypes.itemtype,rentalcharge from items,biblioitems,itemtypes where (items.itemnumber ='$itemno') and (biblioitems.biblioitemnumber = items.biblioitemnumber) and (biblioitems.itemtype = itemtypes.itemtype)"; + my $sth1= $dbh->prepare($q1); + $sth1->execute; + if (my $data1=$sth1->fetchrow_hashref) { + $item_type = $data1->{'itemtype'}; + $charge = $data1->{'rentalcharge'}; + my $q2 = "select rentaldiscount from borrowers,categoryitem + where (borrowers.borrowernumber = '$bornum') + and (borrowers.categorycode = categoryitem.categorycode) + and (categoryitem.itemtype = '$item_type')"; + my $sth2=$dbh->prepare($q2); + $sth2->execute; + if (my $data2=$sth2->fetchrow_hashref) { + my $discount = $data2->{'rentaldiscount'}; + $charge = ($charge *(100 - $discount)) / 100; + } + $sth2->{'finish'}; + } + $sth1->finish; + return ($charge); +} + +sub createcharge { +#Stolen from Issues.pm + my ($env,$dbh,$itemno,$bornum,$charge) = @_; + my $nextaccntno = getnextacctno($env,$bornum,$dbh); + my $query = "insert into accountlines (borrowernumber,itemnumber,accountno,date,amount, description,accounttype,amountoutstanding) values ($bornum,$itemno,$nextaccntno,now(),$charge,'Rental','Rent',$charge)"; + my $sth = $dbh->prepare($query); + $sth->execute; + $sth->finish; +} + + +sub getnextacctno { +# Stolen from Accounts.pm + my ($env,$bornumber,$dbh)=@_; + my $nextaccntno = 1; + my $query = "select * from accountlines where (borrowernumber = '$bornumber') order by accountno desc"; + my $sth = $dbh->prepare($query); + $sth->execute; + if (my $accdata=$sth->fetchrow_hashref){ + $nextaccntno = $accdata->{'accountno'} + 1; + } + $sth->finish; + return($nextaccntno); +} + END { } # module clean-up code here (global destructor) diff --git a/circ/circulation.pl b/circ/circulation.pl index 754cf46dfc..a838c7be75 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -10,55 +10,157 @@ my %env; my $query=new CGI; print $query->header; print startpage(); -print startmenu('catalogue'); +print startmenu('circulation'); +my $branches=getbranches(\%env); +my $printers=getprinters(\%env); +my $branch=$query->param('branch'); +my $printer=$query->param('printer'); +$env{'branchcode'}=$branch; +$env{'printer'}=$printer; +my $branchname=''; +my $printername=''; +if ($branch && $printer) { + $branchname=$branches->{$branch}->{'branchname'}; + $printername=$printers->{$printer}->{'printername'}; +} print << "EOF";
-Issues | -Returns -
+

+ + + + + + + +
$branchname
+ + + +
$printername
+
+
+EOF + + + +if ($printer && $branch) { + + SWITCH: { + if ($query->param('module') eq 'issues') { issues(); last SWITCH; } + if ($query->param('module') eq 'returns') { returns(); last SWITCH; } + issues(); + } +} else { + my $branchcount=0; + my $printercount=0; + my $branchoptions; + my $printeroptions; + foreach (keys %$branches) { + (next) unless ($_); + $branchcount++; + $branchoptions.="

+ + +
+ $branchform + + $printerform +
+ +
+EOF } -print endmenu(); +print endmenu('circulation'); print endpage(); sub default { print << "EOF"; -Issues -Returns +Issues +Returns EOF } sub returns { + print << "EOF"; +
+ + + +
Returns
Enter Book Barcode
Item Barcode:
+ + + +
+EOF if (my $barcode=$query->param('barcode')) { print "Returning $barcode
\n"; my ($iteminformation, $borrower, $messages, $overduecharge) = returnbook(\%env, $barcode); + my $itemtable=<<"EOF"; + + + +
Item Information
+Title: $iteminformation->{'title'}
+Author: $iteminformation->{'author'}
+Barcode: $iteminformation->{'barcode'} +
+EOF if ($borrower) { - print "Borrowed by $borrower->{'title'} $borrower->{'firstname'} $borrower->{'surname'}

\n"; + my ($patrontable, $flaginfotext) = patrontable($borrower); + print "
$patrontable$flaginfotext
$itemtable

\n"; } else { print "Not loaned out.\n"; } } - print << "EOF"; -

- - - -
Enter Book Barcode
Item Barcode:
- -
-EOF } sub issues { if (my $borrnumber=$query->param('borrnumber')) { + my ($borrower, $flags) = getpatroninformation(\%env,$borrnumber,0); my ($borrower, $flags) = getpatroninformation(\%env,$borrnumber,0); my $year=$query->param('year'); my $month=$query->param('month'); @@ -97,11 +199,17 @@ sub issues { $responses{$qnumber}=$query->param('answer'); } unless ($invalidduedate) { - my ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer) = issuebook(\%env, $borrower, $barcode, \%responses); + my ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer, $message) = issuebook(\%env, $borrower, $barcode, \%responses); if ($rejected) { if ($rejected == -1) { } else { - print "Error issuing book: $rejected
\n"; + print << "EOF" + + + +
Error Issuing Book
$rejected
+
+EOF } } my $responsesform=''; @@ -114,10 +222,14 @@ sub issues { \n"; + $flaginfotext.="\n"; } else { - $flaginfotext.="\n"; + $flaginfotext.="\n"; } } if ($flaginfotext) { - $flaginfotext="
Issuing Question
+ + +
Attempting to issue $iteminformation->{'title'} by $iteminformation->{'author'} to $borrower->{'firstname'} $borrower->{'surname'}. -
+

$question

+
@@ -131,6 +243,8 @@ sub issues { + + $responsesform @@ -146,6 +260,8 @@ sub issues { + + $responsesform @@ -158,6 +274,15 @@ sub issues { EOF return; } + if ($message) { + print << "EOF"; +
+ + +
Message
$message
+

+EOF + } } } my $issueid=$query->param('issueid'); @@ -173,13 +298,13 @@ EOF } $flags->{$flag}->{'message'}=~s/\n/
/g; if ($flags->{$flag}->{'noissues'}) { - $flaginfotext.="

$flag$flags->{$flag}->{'message'}
$flag$flags->{$flag}->{'message'}
$flag$flags->{$flag}->{'message'}
$flag$flags->{$flag}->{'message'}
$flaginfotext
Patron Flags
\n"; + $flaginfotext="$flaginfotext
Patron Flags
\n"; } $env{'nottodaysissues'}=1; my ($borrowerissues) = currentissues(\%env, $borrower); @@ -213,7 +338,7 @@ EOF $dayoptions.="