6 use C4::Overdues qw( CalcFine );
8 use Koha::DateUtils qw( dt_from_string );
10 use Test::More tests => 5;
12 my $schema = Koha::Database->new->schema;
13 $schema->storage->txn_begin;
14 my $dbh = C4::Context->dbh;
16 $dbh->do(q|DELETE FROM circulation_rules|);
18 my $issuingrule = Koha::CirculationRules->set_rules(
20 categorycode => undef,
27 chargeperiod_charge_at => 0,
34 ok( $issuingrule, 'Issuing rule created' );
36 my $period_start = dt_from_string('2000-01-01');
37 my $period_end = dt_from_string('2000-01-05');
39 my ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end );
40 is( $fine, 0, '4 days overdue, charge period 7 days, charge at end of interval gives fine of $0' );
42 $period_end = dt_from_string('2000-01-10');
43 ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end );
44 is( $fine, 1, '9 days overdue, charge period 7 days, charge at end of interval gives fine of $1' );
46 # Test charging fine at the *beginning* of each charge period
47 $issuingrule = Koha::CirculationRules->set_rules(
49 categorycode => undef,
53 chargeperiod_charge_at => 1,
58 $period_end = dt_from_string('2000-01-05');
59 ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end );
60 is( $fine, 1, '4 days overdue, charge period 7 days, charge at start of interval gives fine of $1' );
62 $period_end = dt_from_string('2000-01-10');
63 ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end );
64 is( $fine, 2, '9 days overdue, charge period 7 days, charge at start of interval gives fine of $2' );