[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Koha-cvs] koha/C4/Circulation Fines.pm
From: |
Chris Cormack |
Subject: |
[Koha-cvs] koha/C4/Circulation Fines.pm |
Date: |
Wed, 07 Jun 2006 01:32:06 +0000 |
CVSROOT: /sources/koha
Module name: koha
Changes by: Chris Cormack <rangi> 06/06/07 01:32:06
Modified files:
C4/Circulation : Fines.pm
Log message:
Merging Katipo work
Fixing formatting of code, and adding new routines for use generating
overdue notices
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Circulation/Fines.pm?cvsroot=koha&r1=1.12&r2=1.13
Patches:
Index: Fines.pm
===================================================================
RCS file: /sources/koha/koha/C4/Circulation/Fines.pm,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- Fines.pm 26 Oct 2005 09:12:33 -0000 1.12
+++ Fines.pm 7 Jun 2006 01:32:06 -0000 1.13
@@ -1,6 +1,6 @@
package C4::Circulation::Fines;
-# $Id: Fines.pm,v 1.12 2005/10/26 09:12:33 tipaul Exp $
+# $Id: Fines.pm,v 1.13 2006/06/07 01:32:06 rangi Exp $
# Copyright 2000-2002 Katipo Communications
#
@@ -48,7 +48,8 @@
=cut
@ISA = qw(Exporter);
address@hidden = qw(&Getoverdues &CalcFine &BorType &UpdateFine
&ReplacementCost);
address@hidden = qw(&Getoverdues &CalcFine &BorType &UpdateFine &ReplacementCost
+ GetFine, ReplacementCost2);
=item Getoverdues
@@ -63,23 +64,28 @@
Koha database.
=cut
+
#'
-sub Getoverdues{
+sub Getoverdues {
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("Select * from issues where date_due < now() and
returndate is
- NULL order by borrowernumber");
+ my $sth = $dbh->prepare(
+ "Select * from issues where date_due < now() and returndate is
+ NULL order by borrowernumber"
+ );
$sth->execute;
+
# FIXME - Use push @results
- my $i=0;
+ my $i = 0;
my @results;
- while (my $data=$sth->fetchrow_hashref){
- $results[$i]=$data;
+ while ( my $data = $sth->fetchrow_hashref ) {
+ $results[$i] = $data;
$i++;
}
$sth->finish;
-# print @results;
+
+ # print @results;
# FIXME - Bogus API.
- return($i,address@hidden);
+ return ( $i, address@hidden );
}
=item CalcFine
@@ -129,9 +135,10 @@
or "Final Notice".
=cut
+
#'
sub CalcFine {
- my ($itemnumber,$bortype,$difference)address@hidden;
+ my ( $itemnumber, $bortype, $difference ) = @_;
my $dbh = C4::Context->dbh;
# Look up the categoryitem record for this book's item type and the
@@ -147,19 +154,23 @@
# firstremind, chargeperiod, accountsent, and chargename from the
# categoryitem table.
- my $sth=$dbh->prepare("Select * from
items,biblioitems,itemtypes,issuingrules where items.itemnumber=?
+ my $sth = $dbh->prepare(
+"Select * from items,biblioitems,itemtypes,issuingrules where
items.itemnumber=?
and items.biblioitemnumber=biblioitems.biblioitemnumber and
biblioitems.itemtype=itemtypes.itemtype and
categoryitem.itemtype=itemtypes.itemtype and
- categoryitem.categorycode=? and (items.itemlost <> 1 or items.itemlost is
NULL)");
-# print $query;
- $sth->execute($itemnumber,$bortype);
- my $data=$sth->fetchrow_hashref;
+ categoryitem.categorycode=? and (items.itemlost <> 1 or items.itemlost is
NULL)"
+ );
+
+ # print $query;
+ $sth->execute( $itemnumber, $bortype );
+ my $data = $sth->fetchrow_hashref;
+
# FIXME - Error-checking: the item might be lost, or there
# might not be an entry in 'categoryitem' for this item type
# or borrower type.
$sth->finish;
- my $amount=0;
+ my $amount = 0;
my $printout;
# Is it time to send out the first reminder?
@@ -174,29 +185,32 @@
# the first thing the patron gets is a second notice, but that's a
# week after the server crash, so people may not connect the two
# events.
- if ($difference == $data->{'firstremind'}){
+ if ( $difference == $data->{'firstremind'} ) {
+
# Yes. Set the fine as listed.
- $amount=$data->{'fine'};
- $printout="First Notice";
+ $amount = $data->{'fine'};
+ $printout = "First Notice";
}
# Is it time to send out a second reminder?
- my $second=$data->{'firstremind'}+$data->{'chargeperiod'};
- if ($difference == $second){
+ my $second = $data->{'firstremind'} + $data->{'chargeperiod'};
+ if ( $difference == $second ) {
+
# Yes. The fine is double.
- $amount=$data->{'fine'}*2;
- $printout="Second Notice";
+ $amount = $data->{'fine'} * 2;
+ $printout = "Second Notice";
}
# Is it time to send the account to a collection agency?
# FIXME - At least, I *think* that's what this code is doing.
- if ($difference == $data->{'accountsent'} && $data->{'fine'} > 0){
+ if ( $difference == $data->{'accountsent'} && $data->{'fine'} > 0 ) {
+
# Yes. Set the fine at 5 local monetary units.
# FIXME - This '5' shouldn't be hard-wired.
- $amount=5;
- $printout="Final Notice";
+ $amount = 5;
+ $printout = "Final Notice";
}
- return($amount,$data->{'chargename'},$printout);
+ return ( $amount, $data->{'chargename'}, $printout );
}
=item UpdateFine
@@ -224,63 +238,83 @@
accountlines table of the Koha database.
=cut
+
#'
# FIXME - This API doesn't look right: why should the caller have to
# specify both the item number and the borrower number? A book can't
# be on loan to two different people, so the item number should be
# sufficient.
sub UpdateFine {
- my ($itemnum,$bornum,$amount,$type,$due)address@hidden;
+ my ( $itemnum, $bornum, $amount, $type, $due ) = @_;
my $dbh = C4::Context->dbh;
+
# FIXME - What exactly is this query supposed to do? It looks up an
# entry in accountlines that matches the given item and borrower
# numbers, where the description contains $due, and where the
# account type has one of several values, but what does this _mean_?
# Does it look up existing fines for this item?
# FIXME - What are these various account types? ("FU", "O", "F", "M")
- my $sth=$dbh->prepare("Select * from accountlines where itemnumber=? and
+ my $sth = $dbh->prepare(
+ "Select * from accountlines where itemnumber=? and
borrowernumber=? and (accounttype='FU' or accounttype='O' or
- accounttype='F' or accounttype='M') and description like ?");
- $sth->execute($itemnum,$bornum,"%$due%");
+ accounttype='F' or accounttype='M') and description like ?"
+ );
+ $sth->execute( $itemnum, $bornum, "%$due%" );
+
+ if ( my $data = $sth->fetchrow_hashref ) {
- if (my $data=$sth->fetchrow_hashref){
# I think this if-clause deals with the case where we're updating
# an existing fine.
-# print "in accounts ...";
- if ($data->{'amount'} != $amount){
+ # print "in accounts ...";
+ if ( $data->{'amount'} != $amount ) {
-# print "updating";
- my $diff=$amount - $data->{'amount'};
- my $out=$data->{'amountoutstanding'}+$diff;
- my $sth2=$dbh->prepare("update accountlines set date=now(), amount=?,
+ # print "updating";
+ my $diff = $amount - $data->{'amount'};
+ my $out = $data->{'amountoutstanding'} + $diff;
+ my $sth2 = $dbh->prepare(
+ "update accountlines set date=now(), amount=?,
amountoutstanding=?,accounttype='FU' where
borrowernumber=? and itemnumber=?
- and (accounttype='FU' or accounttype='O') and description like ?");
-
$sth2->execute($amount,$out,$data->{'borrowernumber'},$data->{'itemnumber'},"%$due%");
+ and (accounttype='FU' or accounttype='O') and description like ?"
+ );
+ $sth2->execute( $amount, $out, $data->{'borrowernumber'},
+ $data->{'itemnumber'}, "%$due%" );
$sth2->finish;
- } else {
-# print "no update needed $data->{'amount'}"
}
- } else {
+ else {
+
+ # print "no update needed $data->{'amount'}"
+ }
+ }
+ else {
+
# I think this else-clause deals with the case where we're adding
# a new fine.
- my $sth4=$dbh->prepare("select title from biblio,items where
items.itemnumber=?
- and biblio.biblionumber=items.biblionumber");
+ my $sth4 = $dbh->prepare(
+ "select title from biblio,items where items.itemnumber=?
+ and biblio.biblionumber=items.biblionumber"
+ );
$sth4->execute($itemnum);
- my $title=$sth4->fetchrow_hashref;
+ my $title = $sth4->fetchrow_hashref;
$sth4->finish;
+
# print "not in account";
- my $sth3=$dbh->prepare("Select max(accountno) from accountlines");
+ my $sth3 = $dbh->prepare("Select max(accountno) from accountlines");
$sth3->execute;
+
# FIXME - Make $accountno a scalar.
- my @accountno=$sth3->fetchrow_array;
+ my @accountno = $sth3->fetchrow_array;
$sth3->finish;
$accountno[0]++;
- my $sth2=$dbh->prepare("Insert into accountlines
+ my $sth2 = $dbh->prepare(
+ "Insert into accountlines
(borrowernumber,itemnumber,date,amount,
description,accounttype,amountoutstanding,accountno) values
- (?,?,now(),?,?,'FU',?,?)");
- $sth2->execute($bornum,$itemnum,$amount,"$type $title->{'title'}
$due",$amount,$accountno[0]);
+ (?,?,now(),?,?,'FU',?,?)"
+ );
+ $sth2->execute( $bornum, $itemnum, $amount,
+ "$type $title->{'title'} $due",
+ $amount, $accountno[0] );
$sth2->finish;
}
$sth->finish;
@@ -298,17 +332,20 @@
category he or she belongs to.
=cut
+
#'
sub BorType {
- my ($borrowernumber)address@hidden;
+ my ($borrowernumber) = @_;
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("Select * from borrowers,categories where
+ my $sth = $dbh->prepare(
+ "Select * from borrowers,categories where
borrowernumber=? and
-borrowers.categorycode=categories.categorycode");
+borrowers.categorycode=categories.categorycode"
+ );
$sth->execute($borrowernumber);
- my $data=$sth->fetchrow_hashref;
+ my $data = $sth->fetchrow_hashref;
$sth->finish;
- return($data);
+ return ($data);
}
=item ReplacementCost
@@ -318,18 +355,48 @@
Returns the replacement cost of the item with the given item number.
=cut
+
#'
-sub ReplacementCost{
- my ($itemnum)address@hidden;
+sub ReplacementCost {
+ my ($itemnum) = @_;
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("Select replacementprice from items where
itemnumber=?");
+ my $sth =
+ $dbh->prepare("Select replacementprice from items where itemnumber=?");
$sth->execute($itemnum);
+
# FIXME - Use fetchrow_array or something.
- my $data=$sth->fetchrow_hashref;
+ my $data = $sth->fetchrow_hashref;
$sth->finish;
- return($data->{'replacementprice'});
+ return ( $data->{'replacementprice'} );
}
+sub GetFine {
+ my ( $itemnum, $bornum ) = @_;
+ my $dbh = C4::Context->dbh();
+ my $query = "SELECT sum(amountoutstanding) FROM accountlines
+ where accounttype like 'F%'
+ AND amountoutstanding > 0 AND itemnumber = ? AND borrowernumber=?";
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $itemnum, $bornum );
+ my $data = $sth->fetchrow_hashref();
+ $sth->finish();
+ $dbh->disconnect();
+ return ( $data->{'sum(amountoutstanding)'} );
+}
+
+sub ReplacementCost2 {
+ my ( $itemnum, $bornum ) = @_;
+ my $dbh = C4::Context->dbh();
+ my $query = "SELECT amountoutstanding FROM accountlines
+ where accounttype like 'L' AND amountoutstanding > 0 AND
+ itemnumber = ? AND borrowernumber= ?";
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $itemnum, $bornum );
+ my $data = $sth->fetchrow_hashref();
+ $sth->finish();
+ $dbh->disconnect();
+ return ( $data->{'amountoutstanding'} );
+}
1;
__END__
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Koha-cvs] koha/C4/Circulation Fines.pm,
Chris Cormack <=