Lines 24-30
use POSIX qw( floor );
Link Here
|
24 |
use t::lib::Mocks; |
24 |
use t::lib::Mocks; |
25 |
use t::lib::TestBuilder; |
25 |
use t::lib::TestBuilder; |
26 |
|
26 |
|
27 |
use C4::Calendar; |
|
|
28 |
use C4::Circulation; |
27 |
use C4::Circulation; |
29 |
use C4::Biblio; |
28 |
use C4::Biblio; |
30 |
use C4::Items; |
29 |
use C4::Items; |
Lines 34-39
use C4::Reserves;
Link Here
|
34 |
use C4::Overdues qw(UpdateFine CalcFine); |
33 |
use C4::Overdues qw(UpdateFine CalcFine); |
35 |
use Koha::DateUtils; |
34 |
use Koha::DateUtils; |
36 |
use Koha::Database; |
35 |
use Koha::Database; |
|
|
36 |
use Koha::DiscreteCalendar; |
37 |
use Koha::IssuingRules; |
37 |
use Koha::IssuingRules; |
38 |
use Koha::Checkouts; |
38 |
use Koha::Checkouts; |
39 |
use Koha::Patrons; |
39 |
use Koha::Patrons; |
Lines 1802-1817
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1802 |
); |
1802 |
); |
1803 |
$rule->store(); |
1803 |
$rule->store(); |
1804 |
|
1804 |
|
1805 |
my $five_days_ago = dt_from_string->subtract( days => 5 ); |
1805 |
my $in_five_days = dt_from_string->add( days => 5 ); |
1806 |
# We want to charge 2 days every day, without grace |
1806 |
# We want to charge 2 days every day, without grace |
1807 |
# With 5 days of overdue: 5 * Z |
1807 |
# With 5 days of overdue: 5 * Z |
1808 |
my $expected_expiration = dt_from_string->add( days => ( 5 * 2 ) / 1 ); |
1808 |
my $expected_expiration = dt_from_string->add( days => 5 + ( 5 * 2 ) / 1 ); |
1809 |
test_debarment_on_checkout( |
1809 |
test_debarment_on_checkout( |
1810 |
{ |
1810 |
{ |
1811 |
item => $item_1, |
1811 |
item => $item_1, |
1812 |
library => $library, |
1812 |
library => $library, |
1813 |
patron => $patron, |
1813 |
patron => $patron, |
1814 |
due_date => $five_days_ago, |
1814 |
return_date => $in_five_days, |
1815 |
expiration_date => $expected_expiration, |
1815 |
expiration_date => $expected_expiration, |
1816 |
} |
1816 |
} |
1817 |
); |
1817 |
); |
Lines 1819-1831
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1819 |
# We want to charge 2 days every 2 days, without grace |
1819 |
# We want to charge 2 days every 2 days, without grace |
1820 |
# With 5 days of overdue: (5 * 2) / 2 |
1820 |
# With 5 days of overdue: (5 * 2) / 2 |
1821 |
$rule->suspension_chargeperiod(2)->store; |
1821 |
$rule->suspension_chargeperiod(2)->store; |
1822 |
$expected_expiration = dt_from_string->add( days => floor( 5 * 2 ) / 2 ); |
1822 |
$expected_expiration = dt_from_string->add( days => 5 + floor( 5 * 2 ) / 2 ); |
1823 |
test_debarment_on_checkout( |
1823 |
test_debarment_on_checkout( |
1824 |
{ |
1824 |
{ |
1825 |
item => $item_1, |
1825 |
item => $item_1, |
1826 |
library => $library, |
1826 |
library => $library, |
1827 |
patron => $patron, |
1827 |
patron => $patron, |
1828 |
due_date => $five_days_ago, |
1828 |
return_date => $in_five_days, |
1829 |
expiration_date => $expected_expiration, |
1829 |
expiration_date => $expected_expiration, |
1830 |
} |
1830 |
} |
1831 |
); |
1831 |
); |
Lines 1834-1846
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1834 |
# With 5 days of overdue: ((5-1) / 3 ) * 2 |
1834 |
# With 5 days of overdue: ((5-1) / 3 ) * 2 |
1835 |
$rule->suspension_chargeperiod(3)->store; |
1835 |
$rule->suspension_chargeperiod(3)->store; |
1836 |
$rule->firstremind(1)->store; |
1836 |
$rule->firstremind(1)->store; |
1837 |
$expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) ); |
1837 |
$expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 1 ) / 3 ) * 2 ) ); |
1838 |
test_debarment_on_checkout( |
1838 |
test_debarment_on_checkout( |
1839 |
{ |
1839 |
{ |
1840 |
item => $item_1, |
1840 |
item => $item_1, |
1841 |
library => $library, |
1841 |
library => $library, |
1842 |
patron => $patron, |
1842 |
patron => $patron, |
1843 |
due_date => $five_days_ago, |
1843 |
return_date => $in_five_days, |
1844 |
expiration_date => $expected_expiration, |
1844 |
expiration_date => $expected_expiration, |
1845 |
} |
1845 |
} |
1846 |
); |
1846 |
); |
Lines 1853-1917
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1853 |
t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed'); |
1853 |
t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed'); |
1854 |
|
1854 |
|
1855 |
# Adding a holiday 2 days ago |
1855 |
# Adding a holiday 2 days ago |
1856 |
my $calendar = C4::Calendar->new(branchcode => $library->{branchcode}); |
1856 |
my $calendar = Koha::DiscreteCalendar->new( { branchcode => $library->{branchcode} } ); |
1857 |
my $two_days_ago = dt_from_string->subtract( days => 2 ); |
1857 |
my $in_two_days = dt_from_string->add( days => 2 ); |
1858 |
$calendar->insert_single_holiday( |
1858 |
$calendar->edit_holiday( { |
1859 |
day => $two_days_ago->day, |
1859 |
title => 'holidayTest+2d', |
1860 |
month => $two_days_ago->month, |
1860 |
holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},, |
1861 |
year => $two_days_ago->year, |
1861 |
start_date => $in_two_days, |
1862 |
title => 'holidayTest-2d', |
1862 |
end_date => $in_two_days, |
1863 |
description => 'holidayDesc 2 days ago' |
1863 |
} ); |
1864 |
); |
|
|
1865 |
# With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday) |
1864 |
# With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday) |
1866 |
$expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) ); |
1865 |
$expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) ); |
1867 |
test_debarment_on_checkout( |
1866 |
test_debarment_on_checkout( |
1868 |
{ |
1867 |
{ |
1869 |
item => $item_1, |
1868 |
item => $item_1, |
1870 |
library => $library, |
1869 |
library => $library, |
1871 |
patron => $patron, |
1870 |
patron => $patron, |
1872 |
due_date => $five_days_ago, |
1871 |
return_date => $in_five_days, |
1873 |
expiration_date => $expected_expiration, |
1872 |
expiration_date => $expected_expiration, |
1874 |
} |
1873 |
} |
1875 |
); |
1874 |
); |
1876 |
|
1875 |
|
1877 |
# Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped |
1876 |
# Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped |
1878 |
my $two_days_ahead = dt_from_string->add( days => 2 ); |
1877 |
my $in_seven_days = dt_from_string->add( days => 7 ); |
1879 |
$calendar->insert_single_holiday( |
1878 |
$calendar->edit_holiday( { |
1880 |
day => $two_days_ahead->day, |
1879 |
title => 'holidayTest+7d', |
1881 |
month => $two_days_ahead->month, |
1880 |
holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, |
1882 |
year => $two_days_ahead->year, |
1881 |
start_date => $in_seven_days, |
1883 |
title => 'holidayTest+2d', |
1882 |
end_date => $in_seven_days, |
1884 |
description => 'holidayDesc 2 days ahead' |
1883 |
} ); |
1885 |
); |
|
|
1886 |
|
1884 |
|
1887 |
# Same as above, but we should skip D+2 |
1885 |
# Same as above, but we should skip D+2 |
1888 |
$expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 ); |
1886 |
$expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 ); |
1889 |
test_debarment_on_checkout( |
1887 |
test_debarment_on_checkout( |
1890 |
{ |
1888 |
{ |
1891 |
item => $item_1, |
1889 |
item => $item_1, |
1892 |
library => $library, |
1890 |
library => $library, |
1893 |
patron => $patron, |
1891 |
patron => $patron, |
1894 |
due_date => $five_days_ago, |
1892 |
return_date => $in_five_days, |
1895 |
expiration_date => $expected_expiration, |
1893 |
expiration_date => $expected_expiration, |
1896 |
} |
1894 |
} |
1897 |
); |
1895 |
); |
1898 |
|
1896 |
|
1899 |
# Adding another holiday, day of expiration date |
1897 |
# Adding another holiday, day of expiration date |
1900 |
my $expected_expiration_dt = dt_from_string($expected_expiration); |
1898 |
my $expected_expiration_dt = dt_from_string($expected_expiration); |
1901 |
$calendar->insert_single_holiday( |
1899 |
$calendar->edit_holiday( { |
1902 |
day => $expected_expiration_dt->day, |
1900 |
title => 'holidayTest+expected_expiration', |
1903 |
month => $expected_expiration_dt->month, |
1901 |
holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, |
1904 |
year => $expected_expiration_dt->year, |
1902 |
start_date => $expected_expiration_dt, |
1905 |
title => 'holidayTest_exp', |
1903 |
end_date => $expected_expiration_dt, |
1906 |
description => 'holidayDesc on expiration date' |
1904 |
} ); |
1907 |
); |
1905 |
|
1908 |
# Expiration date will be the day after |
1906 |
# Expiration date will be the day after |
1909 |
test_debarment_on_checkout( |
1907 |
test_debarment_on_checkout( |
1910 |
{ |
1908 |
{ |
1911 |
item => $item_1, |
1909 |
item => $item_1, |
1912 |
library => $library, |
1910 |
library => $library, |
1913 |
patron => $patron, |
1911 |
patron => $patron, |
1914 |
due_date => $five_days_ago, |
1912 |
return_date => $in_five_days, |
1915 |
expiration_date => $expected_expiration_dt->clone->add( days => 1 ), |
1913 |
expiration_date => $expected_expiration_dt->clone->add( days => 1 ), |
1916 |
} |
1914 |
} |
1917 |
); |
1915 |
); |
Lines 1922-1928
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1922 |
library => $library, |
1920 |
library => $library, |
1923 |
patron => $patron, |
1921 |
patron => $patron, |
1924 |
return_date => dt_from_string->add(days => 5), |
1922 |
return_date => dt_from_string->add(days => 5), |
1925 |
expiration_date => dt_from_string->add(days => 5 + (5 * 2 - 1) ), |
1923 |
expiration_date => dt_from_string->add(days => 5 + (5 * 2 - 1) + 1 ), # We add an extra +1 because of the holiday |
1926 |
} |
1924 |
} |
1927 |
); |
1925 |
); |
1928 |
}; |
1926 |
}; |
1929 |
- |
|
|