10 use Test::More tests => 5;
13 my $dbh = C4::Context->dbh;
14 my $schema = Koha::Database->new()->schema();
16 $dbh->{RaiseError} = 1;
17 $dbh->{AutoCommit} = 0;
19 $dbh->do(q|DELETE FROM issuingrules|);
21 my $issuingrule = $schema->resultset('Issuingrule')->create(
29 chargeperiod_charge_at => 0,
35 ok( $issuingrule, 'Issuing rule created' );
37 my $period_start = dt_from_string('2000-01-01');
38 my $period_end = dt_from_string('2000-01-05');
40 my ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end );
41 is( $fine, 0, '4 days overdue, charge period 7 days, charge at end of interval gives fine of $0' );
43 $period_end = dt_from_string('2000-01-10');
44 ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end );
45 is( $fine, 1, '9 days overdue, charge period 7 days, charge at end of interval gives fine of $1' );
47 # Test charging fine at the *beginning* of each charge period
48 $issuingrule->update( { chargeperiod_charge_at => 1 } );
50 $period_end = dt_from_string('2000-01-05');
51 ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end );
52 is( $fine, 1, '4 days overdue, charge period 7 days, charge at start of interval gives fine of $1' );
54 $period_end = dt_from_string('2000-01-10');
55 ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end );
56 is( $fine, 2, '9 days overdue, charge period 7 days, charge at start of interval gives fine of $2' );