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 2237-2242 sub _debar_user_on_return { Link Here
2237
                }
2238
                }
2238
            }
2239
            }
2239
2240
2241
            if ( $issuing_rule->suspension_chargeperiod > 1 ) {
2242
                # No need to / 1 and do not consider / 0
2243
                $suspension_days = DateTime::Duration->new(
2244
                    days => floor( $suspension_days->in_units('days') / $issuing_rule->suspension_chargeperiod )
2245
                );
2246
            }
2247
2240
            my $new_debar_dt =
2248
            my $new_debar_dt =
2241
              $return_date->clone()->add_duration( $suspension_days );
2249
              $return_date->clone()->add_duration( $suspension_days );
2242
2250
(-)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 => 113;
20
use Test::More tests => 114;
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 1750-1755 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1750
    is( $debarments->[0]->{expiration}, $expected_expiration );
1750
    is( $debarments->[0]->{expiration}, $expected_expiration );
1751
};
1751
};
1752
1752
1753
subtest 'AddReturn + suspension_chargeperiod' => sub {
1754
    plan tests => 6;
1755
1756
    my $library = $builder->build( { source => 'Branch' } );
1757
    my $patron  = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } );
1758
1759
    # Add 2 items
1760
    my $biblioitem_1 = $builder->build( { source => 'Biblioitem' } );
1761
    my $item_1 = $builder->build(
1762
        {
1763
            source => 'Item',
1764
            value  => {
1765
                homebranch    => $library->{branchcode},
1766
                holdingbranch => $library->{branchcode},
1767
                notforloan    => 0,
1768
                itemlost      => 0,
1769
                withdrawn     => 0,
1770
                biblionumber  => $biblioitem_1->{biblionumber}
1771
            }
1772
        }
1773
    );
1774
1775
    # And the issuing rule
1776
    Koha::IssuingRules->search->delete;
1777
    my $rule = Koha::IssuingRule->new(
1778
        {
1779
            categorycode => '*',
1780
            itemtype     => '*',
1781
            branchcode   => '*',
1782
            maxissueqty  => 99,
1783
            issuelength  => 1,
1784
            firstremind  => 0,        # 0 day of grace
1785
            finedays     => 2,        # 2 days of fine per day of overdue
1786
            suspension_chargeperiod => 1,
1787
            lengthunit   => 'days',
1788
        }
1789
    );
1790
    $rule->store();
1791
1792
    my $five_days_ago = dt_from_string->subtract( days => 5 );
1793
    AddIssue( $patron, $item_1->{barcode}, $five_days_ago );    # Add an overdue
1794
1795
    # We want to charge 2 days every day, without grace
1796
    # With 5 days of overdue: 5 * Z
1797
    AddReturn( $item_1->{barcode}, $library->{branchcode},
1798
        undef, undef, dt_from_string );
1799
    my $debarments = Koha::Patron::Debarments::GetDebarments(
1800
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1801
    is( scalar(@$debarments), 1 );
1802
1803
    my $expected_expiration = output_pref(
1804
        {
1805
            dt         => dt_from_string->add( days => ( 5 * 2 ) / 1 ),
1806
            dateformat => 'sql',
1807
            dateonly   => 1
1808
        }
1809
    );
1810
    is( $debarments->[0]->{expiration}, $expected_expiration );
1811
    Koha::Patron::Debarments::DelUniqueDebarment(
1812
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1813
1814
    # We want to charge 2 days every 2 days, without grace
1815
    # With 5 days of overdue: (5 * 2) / 2
1816
    $rule->suspension_chargeperiod(2)->store;
1817
    AddIssue( $patron, $item_1->{barcode}, $five_days_ago );    # Add an overdue
1818
1819
    AddReturn( $item_1->{barcode}, $library->{branchcode},
1820
        undef, undef, dt_from_string );
1821
    $debarments = Koha::Patron::Debarments::GetDebarments(
1822
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1823
    is( scalar(@$debarments), 1 );
1824
1825
    $expected_expiration = output_pref(
1826
        {
1827
            dt         => dt_from_string->add( days => floor( 5 * 2 ) / 2 ),
1828
            dateformat => 'sql',
1829
            dateonly   => 1
1830
        }
1831
    );
1832
    is( $debarments->[0]->{expiration}, $expected_expiration );
1833
    Koha::Patron::Debarments::DelUniqueDebarment(
1834
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1835
1836
    # We want to charge 2 days every 3 days, with 1 day of grace
1837
    # With 5 days of overdue: ((5-1) / 3 ) * 2
1838
    $rule->suspension_chargeperiod(3)->store;
1839
    $rule->firstremind(1)->store;
1840
    AddIssue( $patron, $item_1->{barcode}, $five_days_ago );    # Add an overdue
1841
1842
    AddReturn( $item_1->{barcode}, $library->{branchcode},
1843
        undef, undef, dt_from_string );
1844
    $debarments = Koha::Patron::Debarments::GetDebarments(
1845
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1846
    is( scalar(@$debarments), 1 );
1847
1848
    $expected_expiration = output_pref(
1849
        {
1850
            dt         => dt_from_string->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) ),
1851
            dateformat => 'sql',
1852
            dateonly   => 1
1853
        }
1854
    );
1855
    is( $debarments->[0]->{expiration}, $expected_expiration );
1856
    Koha::Patron::Debarments::DelUniqueDebarment(
1857
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1858
1859
};
1860
1861
1753
subtest 'AddReturn | is_overdue' => sub {
1862
subtest 'AddReturn | is_overdue' => sub {
1754
    plan tests => 5;
1863
    plan tests => 5;
1755
1864
1756
- 

Return to bug 19804