#
# This file is part of Koha.
#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
use strict;
#use warnings; FIXME - Bug 2505
&AmountNotify
&UpdateFine
&GetFine
-
+ &get_chargeable_units
&CheckItemNotify
&GetOverduesForBranch
&RemoveNotifyLine
my $statement;
if ( C4::Context->preference('item-level_itypes') ) {
$statement = "
- SELECT issues.*, items.itype as itemtype, items.homebranch, items.barcode
+ SELECT issues.*, items.itype as itemtype, items.homebranch, items.barcode, items.itemlost
FROM issues
LEFT JOIN items USING (itemnumber)
WHERE date_due < NOW()
";
} else {
$statement = "
- SELECT issues.*, biblioitems.itemtype, items.itype, items.homebranch, items.barcode
+ SELECT issues.*, biblioitems.itemtype, items.itype, items.homebranch, items.barcode, items.itemlost
FROM issues
LEFT JOIN items USING (itemnumber)
LEFT JOIN biblioitems USING (biblioitemnumber)
my $fine_unit = $data->{lengthunit};
$fine_unit ||= 'days';
- my $chargeable_units = _get_chargeable_units($fine_unit, $start_date, $end_date, $branchcode);
+ my $chargeable_units = get_chargeable_units($fine_unit, $start_date, $end_date, $branchcode);
my $units_minus_grace = $chargeable_units - $data->{firstremind};
my $amount = 0;
if ($data->{'chargeperiod'} && ($units_minus_grace > 0) ) {
}
-=head2 _get_chargeable_units
+=head2 get_chargeable_units
- _get_chargeable_units($unit, $start_date_ $end_date, $branchcode);
+ get_chargeable_units($unit, $start_date_ $end_date, $branchcode);
return integer value of units between C<$start_date> and C<$end_date>, factoring in holidays for C<$branchcode>.
=cut
-sub _get_chargeable_units {
+sub get_chargeable_units {
my ($unit, $date_due, $date_returned, $branchcode) = @_;
# If the due date is later than the return date
# print "no update needed $data->{'amount'}"
}
} else {
- my $sth4 = $dbh->prepare(
- "SELECT title FROM biblio LEFT JOIN items ON biblio.biblionumber=items.biblionumber WHERE items.itemnumber=?"
- );
- $sth4->execute($itemnum);
- my $title = $sth4->fetchrow;
-
-# # print "not in account";
-# my $sth3 = $dbh->prepare("Select max(accountno) from accountlines");
-# $sth3->execute;
-#
-# # FIXME - Make $accountno a scalar.
-# my @accountno = $sth3->fetchrow_array;
-# $sth3->finish;
-# $accountno[0]++;
-# begin transaction
- my $nextaccntno = C4::Accounts::getnextacctno($borrowernumber);
- my $desc = ($type ? "$type " : '') . "$title $due"; # FIXEDME, avoid whitespace prefix on empty $type
- my $query = "INSERT INTO accountlines
- (borrowernumber,itemnumber,date,amount,description,accounttype,amountoutstanding,lastincrement,accountno)
- VALUES (?,?,now(),?,?,'FU',?,?,?)";
- my $sth2 = $dbh->prepare($query);
- $debug and print STDERR "UpdateFine query: $query\nw/ args: $borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno\n";
- $sth2->execute($borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno);
+ if ( $amount ) { # Don't add new fines with an amount of 0
+ my $sth4 = $dbh->prepare(
+ "SELECT title FROM biblio LEFT JOIN items ON biblio.biblionumber=items.biblionumber WHERE items.itemnumber=?"
+ );
+ $sth4->execute($itemnum);
+ my $title = $sth4->fetchrow;
+
+ my $nextaccntno = C4::Accounts::getnextacctno($borrowernumber);
+
+ my $desc = ( $type ? "$type " : '' ) . "$title $due"; # FIXEDME, avoid whitespace prefix on empty $type
+
+ my $query = "INSERT INTO accountlines
+ (borrowernumber,itemnumber,date,amount,description,accounttype,amountoutstanding,lastincrement,accountno)
+ VALUES (?,?,now(),?,?,'FU',?,?,?)";
+ my $sth2 = $dbh->prepare($query);
+ $debug and print STDERR "UpdateFine query: $query\nw/ args: $borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno\n";
+ $sth2->execute( $borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno );
+ }
}
# logging action
&logaction(
my $dbh = C4::Context->dbh();
my $query = q|SELECT sum(amountoutstanding) as fineamount FROM accountlines
where accounttype like 'F%'
- AND amountoutstanding > 0 AND itemnumber = ? AND borrowernumber=?|;
+ AND amountoutstanding > 0 AND borrowernumber=?|;
+ my @query_param;
+ push @query_param, $borrowernumber;
+ if (defined $itemnum )
+ {
+ $query .= " AND itemnumber=?";
+ push @query_param, $itemnum;
+ }
my $sth = $dbh->prepare($query);
- $sth->execute( $itemnum, $borrowernumber );
+ $sth->execute( @query_param );
my $fine = $sth->fetchrow_hashref();
if ($fine->{fineamount}) {
return $fine->{fineamount};
sub GetBranchcodesWithOverdueRules {
my $dbh = C4::Context->dbh;
- my $rqoverduebranches = $dbh->prepare("SELECT DISTINCT branchcode FROM overduerules WHERE delay1 IS NOT NULL AND branchcode <> '' ORDER BY branchcode");
- $rqoverduebranches->execute;
- my @branches = map { shift @$_ } @{ $rqoverduebranches->fetchall_arrayref };
- if (!$branches[0]) {
- my $availbranches = C4::Branch::GetBranches();
- @branches = keys %$availbranches;
+ my $branchcodes = $dbh->selectcol_arrayref(q|
+ SELECT DISTINCT(branchcode)
+ FROM overduerules
+ WHERE delay1 IS NOT NULL
+ ORDER BY branchcode
+ |);
+ if ( $branchcodes->[0] eq '' ) {
+ # If a default rule exists, all branches should be returned
+ my $availbranches = C4::Branch::GetBranches();
+ return keys %$availbranches;
}
- return @branches;
+ return @$branchcodes;
}
=head2 CheckItemNotify