|
Lines 15-20
use Koha::Patrons;
Link Here
|
| 15 |
use t::lib::TestBuilder; |
15 |
use t::lib::TestBuilder; |
| 16 |
use t::lib::Mocks; |
16 |
use t::lib::Mocks; |
| 17 |
|
17 |
|
|
|
18 |
use POSIX qw( ceil ); |
| 19 |
|
| 20 |
|
| 18 |
my $schema = Koha::Database->schema; |
21 |
my $schema = Koha::Database->schema; |
| 19 |
$schema->storage->txn_begin; |
22 |
$schema->storage->txn_begin; |
| 20 |
my $builder = t::lib::TestBuilder->new; |
23 |
my $builder = t::lib::TestBuilder->new; |
|
Lines 130-137
subtest "suspension_chargeperiod" => sub {
Link Here
|
| 130 |
my $today = dt_from_string; |
133 |
my $today = dt_from_string; |
| 131 |
my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron, $item, $last_year, $today ); |
134 |
my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron, $item, $last_year, $today ); |
| 132 |
is( $new_debar_dt->truncate( to => 'day' ), |
135 |
is( $new_debar_dt->truncate( to => 'day' ), |
| 133 |
$today->clone->add( days => 365 / 15 * 7 )->truncate( to => 'day' ) ); |
136 |
$today->clone->add( days => ceil(365 / 15 * 7) )->truncate( to => 'day' )), |
| 134 |
|
137 |
'the truncated dates are equal.' |
| 135 |
}; |
138 |
}; |
| 136 |
|
139 |
|
| 137 |
subtest "maxsuspensiondays" => sub { |
140 |
subtest "maxsuspensiondays" => sub { |
|
Lines 156-162
subtest "maxsuspensiondays" => sub {
Link Here
|
| 156 |
my $today = dt_from_string; |
159 |
my $today = dt_from_string; |
| 157 |
my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron, $item, $last_year, $today ); |
160 |
my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron, $item, $last_year, $today ); |
| 158 |
is( $new_debar_dt->truncate( to => 'day' ), |
161 |
is( $new_debar_dt->truncate( to => 'day' ), |
| 159 |
$today->clone->add( days => 333 )->truncate( to => 'day' ) ); |
162 |
$today->clone->add( days => 333 )->truncate( to => 'day' )); |
| 160 |
}; |
163 |
|
|
|
164 |
|
| 165 |
Koha::CirculationRules->set_rules( |
| 166 |
{ |
| 167 |
categorycode => undef, |
| 168 |
itemtype => undef, |
| 169 |
branchcode => undef, |
| 170 |
rules => { |
| 171 |
firstremind => 0, |
| 172 |
finedays => 2, |
| 173 |
lengthunit => 'hours', |
| 174 |
suspension_chargeperiod => 1, |
| 175 |
maxsuspensiondays => 100, |
| 176 |
} |
| 177 |
} |
| 178 |
); |
| 179 |
|
| 180 |
my $yesterday = dt_from_string->clone->subtract( days => 1 ); |
| 181 |
my $daysafter2 = dt_from_string->clone->add( days => 2 ); |
| 182 |
AddIssue( $patron, $barcode, $yesterday); |
| 183 |
AddReturn( $barcode, $branchcode ); |
| 184 |
$debarments = $patron->restrictions; |
| 185 |
$THE_debarment = $debarments->next; |
| 186 |
is( |
| 187 |
$THE_debarment->expiration, |
| 188 |
output_pref({ dt => $daysafter2, dateformat => 'iso', dateonly => 1 }), |
| 189 |
'calculate suspension with lengthunit hours.' |
| 190 |
); |
| 191 |
|
| 192 |
DelDebarment( $THE_debarment->borrower_debarment_id ); |
| 193 |
|
| 194 |
my $hoursago2 = dt_from_string->clone->subtract( hours => 2 ); |
| 195 |
AddIssue( $patron, $barcode, $hoursago2); |
| 196 |
AddReturn( $barcode, $branchcode ); |
| 197 |
$debarments = $patron->restrictions; |
| 198 |
$THE_debarment = $debarments->next; |
| 199 |
is( |
| 200 |
$THE_debarment->expiration, |
| 201 |
output_pref({ dt => $daysafter2, dateformat => 'iso', dateonly => 1 }), |
| 202 |
'calculate suspension with lengthunit hours.' |
| 203 |
); |
| 204 |
|
| 205 |
DelDebarment( $THE_debarment->borrower_debarment_id ); |
| 161 |
|
206 |
|
|
|
207 |
my $hoursafter2 = dt_from_string->clone->add( hours => 2 ); |
| 208 |
AddIssue( $patron, $barcode, $hoursafter2); |
| 209 |
AddReturn( $barcode, $branchcode ); |
| 210 |
$debarments = $patron->restrictions; |
| 211 |
$THE_debarment = $debarments->next; |
| 212 |
is_deeply( |
| 213 |
$THE_debarment, |
| 214 |
undef, |
| 215 |
'No debarment if in time' |
| 216 |
); |
| 217 |
|
| 218 |
# Add 1 day every 2 days |
| 219 |
Koha::CirculationRules->set_rules( |
| 220 |
{ |
| 221 |
categorycode => undef, |
| 222 |
itemtype => undef, |
| 223 |
branchcode => undef, |
| 224 |
rules => { |
| 225 |
firstremind => 0, |
| 226 |
finedays => 1, |
| 227 |
lengthunit => 'hours', |
| 228 |
suspension_chargeperiod => 2, |
| 229 |
maxsuspensiondays => 100, |
| 230 |
} |
| 231 |
} |
| 232 |
); |
| 233 |
|
| 234 |
# 20 days late => 20/2 * 1 => 10 days of suspension |
| 235 |
AddIssue( $patron, $barcode, $daysago20 ); |
| 236 |
AddReturn( $barcode, $branchcode ); |
| 237 |
$debarments = $patron->restrictions; |
| 238 |
$THE_debarment = $debarments->next; |
| 239 |
is( |
| 240 |
$THE_debarment->expiration, |
| 241 |
output_pref({ dt => $daysafter10, dateformat => 'iso', dateonly => 1 }), |
| 242 |
'calculate suspension with lengthunit hours.' |
| 243 |
); |
| 244 |
|
| 245 |
DelDebarment( $THE_debarment->borrower_debarment_id ); |
| 246 |
|
| 247 |
# 1 day late => ceil(1/2) * 1 => 1 day of suspension |
| 248 |
my $tomorrow = dt_from_string->clone->add( days => 1 ); |
| 249 |
AddIssue( $patron, $barcode, $yesterday); |
| 250 |
AddReturn( $barcode, $branchcode ); |
| 251 |
$debarments = $patron->restrictions; |
| 252 |
$THE_debarment = $debarments->next; |
| 253 |
is( |
| 254 |
$THE_debarment->expiration, |
| 255 |
output_pref({ dt => $tomorrow, dateformat => 'iso', dateonly => 1 }), |
| 256 |
'calculate suspension with lengthunit hours.' |
| 257 |
); |
| 258 |
|
| 259 |
DelDebarment( $THE_debarment->borrower_debarment_id ); |
| 260 |
|
| 261 |
# 2 hours late => ceil(.x/2) * 1 => 1 day of suspension |
| 262 |
AddIssue( $patron, $barcode, $hoursafter2); |
| 263 |
AddReturn( $barcode, $branchcode ); |
| 264 |
$debarments = $patron->restrictions; |
| 265 |
$THE_debarment = $debarments->next; |
| 266 |
is_deeply( |
| 267 |
$THE_debarment, |
| 268 |
undef, |
| 269 |
'No debarment if in time' |
| 270 |
); |
| 271 |
}; |
| 162 |
$schema->storage->txn_rollback; |
272 |
$schema->storage->txn_rollback; |
| 163 |
- |
|
|