Koha/t/db_dependent/Circulation/CalcFine.t
Kyle M Hall c42de7460b Bug 9129 - Add the ability to set the maximum fine for an item to its replacement price
This patch adds the ability to set the maximum fine for a given item to
its replacement price ( assuming the replacement price is set ). If
overduefinescap is also set, the fine will be the lesser of the two, if
both apply to the given overdue checkout.

To enable this new limit, create or edit your circulation rules and
check the checkbox for "Cap fines at replacement price"

Test Plan:
1) Apply this patch
2) Run updatedatabase.pl
3) Pick an item, and set it's replacement price to 3.99
4) Edit the circulation rule that would apply to this item
   and the patron you will check it out to.
5) Check out the item to the patron, and backdate the due date
   such that the fine generated would be more than 3.99
6) Enable CalculateFinesOnReturn
7) Return the item, and view the fine generated, it should be 3.99

Signed-off-by: Cindy Murdock Ames <cmurdock@ccfls.org>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
2015-12-31 15:29:36 +00:00

146 lines
3.5 KiB
Perl

#!/usr/bin/perl
use Modern::Perl;
use Test::More tests => 2;
use C4::Context;
use C4::Overdues;
use Koha::DateUtils qw( dt_from_string );
use t::lib::TestBuilder;
use t::lib::Mocks;
our $dbh = C4::Context->dbh;
$dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
$dbh->do(q|DELETE FROM issues|);
my $builder = t::lib::TestBuilder->new();
my $branch = $builder->build(
{
source => 'Branch',
}
);
my $category = $builder->build(
{
source => 'Category',
}
);
my $patron = $builder->build(
{
source => 'Borrower',
value => {
categorycode => $category->{categorycode},
branchcode => $branch->{branchcode},
},
}
);
my $biblio = $builder->build(
{
source => 'Biblio',
value => {
branchcode => $branch->{branchcode},
},
}
);
my $item = $builder->build(
{
source => 'Item',
value => {
biblionumber => $biblio->{biblionumber},
homebranch => $branch->{branchcode},
holdingbranch => $branch->{branchcode},
replacementprice => '5.00',
},
}
);
subtest 'Test basic functionality' => sub {
plan tests => 1;
my $issuingrule = $builder->build(
{
source => 'Issuingrule',
value => {
branchcode => '*',
categorycode => '*',
itemtype => '*',
fine => '1.00',
lengthunit => 'days',
finedays => 0,
firstremind => 0,
chargeperiod => 1,
overduefinescap => undef,
cap_fine_to_replacement_price => 0,
},
}
);
my $start_dt = DateTime->new(
year => 2000,
month => 01,
day => 01,
);
my $end_dt = DateTime->new(
year => 2000,
month => 01,
day => 30,
);
my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
is( $amount, 29, 'Amount is calculated correctly' );
teardown();
};
subtest 'Test cap_fine_to_replacement_price' => sub {
plan tests => 1;
my $issuingrule = $builder->build(
{
source => 'Issuingrule',
value => {
branchcode => '*',
categorycode => '*',
itemtype => '*',
fine => '1.00',
lengthunit => 'days',
finedays => 0,
firstremind => 0,
chargeperiod => 1,
overduefinescap => undef,
cap_fine_to_replacement_price => 1,
},
}
);
my $start_dt = DateTime->new(
year => 2000,
month => 01,
day => 01,
);
my $end_dt = DateTime->new(
year => 2000,
month => 01,
day => 30,
);
my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
is( $amount, '5.00', 'Amount is calculated correctly' );
teardown();
};
sub teardown {
$dbh->do(q|DELETE FROM issuingrules|);
}