View | Details | Raw Unified | Return to bug 19804
Collapse All | Expand All

(-)a/C4/Circulation.pm (+8 lines)
Lines 22-27 package C4::Circulation; Link Here
22
use strict;
22
use strict;
23
#use warnings; FIXME - Bug 2505
23
#use warnings; FIXME - Bug 2505
24
use DateTime;
24
use DateTime;
25
use POSIX qw( floor );
25
use Koha::DateUtils;
26
use Koha::DateUtils;
26
use C4::Context;
27
use C4::Context;
27
use C4::Stats;
28
use C4::Stats;
Lines 2272-2277 sub _debar_user_on_return { Link Here
2272
                }
2273
                }
2273
            }
2274
            }
2274
2275
2276
            if ( $issuing_rule->suspension_chargeperiod > 1 ) {
2277
                # No need to / 1 and do not consider / 0
2278
                $suspension_days = DateTime::Duration->new(
2279
                    days => floor( $suspension_days->in_units('days') / $issuing_rule->suspension_chargeperiod )
2280
                );
2281
            }
2282
2275
            my $new_debar_dt =
2283
            my $new_debar_dt =
2276
              $return_date->clone()->add_duration( $suspension_days );
2284
              $return_date->clone()->add_duration( $suspension_days );
2277
2285
(-)a/t/db_dependent/Circulation.t (-3 / +111 lines)
Lines 17-26 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 112;
20
use Test::More tests => 113;
21
21
22
use DateTime;
22
use DateTime;
23
23
use POSIX qw( floor );
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
26
26
Lines 1704-1709 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1704
    is( $debarments->[0]->{expiration}, $expected_expiration );
1704
    is( $debarments->[0]->{expiration}, $expected_expiration );
1705
};
1705
};
1706
1706
1707
subtest 'AddReturn + suspension_chargeperiod' => sub {
1708
    plan tests => 6;
1709
1710
    my $library = $builder->build( { source => 'Branch' } );
1711
    my $patron  = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } );
1712
1713
    # Add 2 items
1714
    my $biblioitem_1 = $builder->build( { source => 'Biblioitem' } );
1715
    my $item_1 = $builder->build(
1716
        {
1717
            source => 'Item',
1718
            value  => {
1719
                homebranch    => $library->{branchcode},
1720
                holdingbranch => $library->{branchcode},
1721
                notforloan    => 0,
1722
                itemlost      => 0,
1723
                withdrawn     => 0,
1724
                biblionumber  => $biblioitem_1->{biblionumber}
1725
            }
1726
        }
1727
    );
1728
1729
    # And the issuing rule
1730
    Koha::IssuingRules->search->delete;
1731
    my $rule = Koha::IssuingRule->new(
1732
        {
1733
            categorycode => '*',
1734
            itemtype     => '*',
1735
            branchcode   => '*',
1736
            maxissueqty  => 99,
1737
            issuelength  => 1,
1738
            firstremind  => 0,        # 0 day of grace
1739
            finedays     => 2,        # 2 days of fine per day of overdue
1740
            suspension_chargeperiod => 1,
1741
            lengthunit   => 'days',
1742
        }
1743
    );
1744
    $rule->store();
1745
1746
    my $five_days_ago = dt_from_string->subtract( days => 5 );
1747
    AddIssue( $patron, $item_1->{barcode}, $five_days_ago );    # Add an overdue
1748
1749
    # We want to charge 2 days every day, without grace
1750
    # With 5 days of overdue: 5 * Z
1751
    AddReturn( $item_1->{barcode}, $library->{branchcode},
1752
        undef, undef, dt_from_string );
1753
    my $debarments = Koha::Patron::Debarments::GetDebarments(
1754
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1755
    is( scalar(@$debarments), 1 );
1756
1757
    my $expected_expiration = output_pref(
1758
        {
1759
            dt         => dt_from_string->add( days => ( 5 * 2 ) / 1 ),
1760
            dateformat => 'sql',
1761
            dateonly   => 1
1762
        }
1763
    );
1764
    is( $debarments->[0]->{expiration}, $expected_expiration );
1765
    Koha::Patron::Debarments::DelUniqueDebarment(
1766
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1767
1768
    # We want to charge 2 days every 2 days, without grace
1769
    # With 5 days of overdue: (5 * 2) / 2
1770
    $rule->suspension_chargeperiod(2)->store;
1771
    AddIssue( $patron, $item_1->{barcode}, $five_days_ago );    # Add an overdue
1772
1773
    AddReturn( $item_1->{barcode}, $library->{branchcode},
1774
        undef, undef, dt_from_string );
1775
    $debarments = Koha::Patron::Debarments::GetDebarments(
1776
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1777
    is( scalar(@$debarments), 1 );
1778
1779
    $expected_expiration = output_pref(
1780
        {
1781
            dt         => dt_from_string->add( days => floor( 5 * 2 ) / 2 ),
1782
            dateformat => 'sql',
1783
            dateonly   => 1
1784
        }
1785
    );
1786
    is( $debarments->[0]->{expiration}, $expected_expiration );
1787
    Koha::Patron::Debarments::DelUniqueDebarment(
1788
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1789
1790
    # We want to charge 2 days every 3 days, with 1 day of grace
1791
    # With 5 days of overdue: ((5-1) / 3 ) * 2
1792
    $rule->suspension_chargeperiod(3)->store;
1793
    $rule->firstremind(1)->store;
1794
    AddIssue( $patron, $item_1->{barcode}, $five_days_ago );    # Add an overdue
1795
1796
    AddReturn( $item_1->{barcode}, $library->{branchcode},
1797
        undef, undef, dt_from_string );
1798
    $debarments = Koha::Patron::Debarments::GetDebarments(
1799
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1800
    is( scalar(@$debarments), 1 );
1801
1802
    $expected_expiration = output_pref(
1803
        {
1804
            dt         => dt_from_string->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) ),
1805
            dateformat => 'sql',
1806
            dateonly   => 1
1807
        }
1808
    );
1809
    is( $debarments->[0]->{expiration}, $expected_expiration );
1810
    Koha::Patron::Debarments::DelUniqueDebarment(
1811
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1812
1813
};
1814
1815
1707
subtest 'AddReturn | is_overdue' => sub {
1816
subtest 'AddReturn | is_overdue' => sub {
1708
    plan tests => 5;
1817
    plan tests => 5;
1709
1818
1710
- 

Return to bug 19804