Bug 22087: Add missing filters
[koha.git] / t / db_dependent / Fines.t
blob76cc0638a95918ad91669591de0a712f7302581d
1 #!/usr/bin/perl
3 use Modern::Perl;
5 use C4::Context;
6 use C4::Overdues;
7 use Koha::Database;
8 use Koha::DateUtils;
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,
21 itemtype => undef,
22 branchcode => undef,
23 rules => {
24 fine => 1,
25 finedays => 0,
26 chargeperiod => 7,
27 chargeperiod_charge_at => 0,
28 lengthunit => 'days',
29 issuelength => 1,
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,
50 itemtype => undef,
51 branchcode => undef,
52 rules => {
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' );