Lines 221-226
our $RULE_KINDS = {
Link Here
|
221 |
}, |
221 |
}, |
222 |
bookings_trail_period => { |
222 |
bookings_trail_period => { |
223 |
scope => [ 'branchcode', 'itemtype' ], |
223 |
scope => [ 'branchcode', 'itemtype' ], |
|
|
224 |
has_priority => { |
225 |
scope => [ 'branchcode', 'categorycode' ], |
224 |
}, |
226 |
}, |
225 |
# Not included (deprecated?): |
227 |
# Not included (deprecated?): |
226 |
# * accountsent |
228 |
# * accountsent |
Lines 254-259
sub get_effective_rule {
Link Here
|
254 |
$params->{categorycode} //= undef; |
256 |
$params->{categorycode} //= undef; |
255 |
$params->{branchcode} //= undef; |
257 |
$params->{branchcode} //= undef; |
256 |
$params->{itemtype} //= undef; |
258 |
$params->{itemtype} //= undef; |
|
|
259 |
$params->{has_priority} //= undef; |
257 |
|
260 |
|
258 |
my $rule_name = $params->{rule_name}; |
261 |
my $rule_name = $params->{rule_name}; |
259 |
my $categorycode = $params->{categorycode}; |
262 |
my $categorycode = $params->{categorycode}; |
Lines 286-292
sub get_effective_rule {
Link Here
|
286 |
} |
289 |
} |
287 |
)->single; |
290 |
)->single; |
288 |
|
291 |
|
289 |
return $rule; |
292 |
$search_params->{has_priority} = 1; |
|
|
293 |
|
294 |
my $priority_rule = $self->search( |
295 |
$search_params, |
296 |
{ |
297 |
order_by => $order_by, |
298 |
rows => 1, |
299 |
} |
300 |
)->single; |
301 |
|
302 |
return defined $priority_rule ? $priority_rule : $rule; |
290 |
} |
303 |
} |
291 |
|
304 |
|
292 |
=head3 get_effective_rule_value |
305 |
=head3 get_effective_rule_value |
Lines 314-323
sub get_effective_rule_value {
Link Here
|
314 |
my $categorycode = $params->{categorycode}; |
327 |
my $categorycode = $params->{categorycode}; |
315 |
my $itemtype = $params->{itemtype}; |
328 |
my $itemtype = $params->{itemtype}; |
316 |
my $branchcode = $params->{branchcode}; |
329 |
my $branchcode = $params->{branchcode}; |
|
|
330 |
my $has_priority = $params->{has_priority}; |
317 |
|
331 |
|
318 |
my $memory_cache = Koha::Cache::Memory::Lite->get_instance; |
332 |
my $memory_cache = Koha::Cache::Memory::Lite->get_instance; |
319 |
my $cache_key = sprintf "CircRules:%s:%s:%s:%s", $rule_name // q{}, |
333 |
my $cache_key = sprintf "CircRules:%s:%s:%s:%s", $rule_name // q{}, |
320 |
$categorycode // q{}, $branchcode // q{}, $itemtype // q{}; |
334 |
$categorycode // q{}, $branchcode // q{}, $itemtype // q{} ,$has_priority // q{}; |
321 |
|
335 |
|
322 |
my $cached = $memory_cache->get_from_cache($cache_key); |
336 |
my $cached = $memory_cache->get_from_cache($cache_key); |
323 |
return $cached if $cached; |
337 |
return $cached if $cached; |
Lines 340-345
sub get_effective_rules {
Link Here
|
340 |
my $categorycode = $params->{categorycode}; |
354 |
my $categorycode = $params->{categorycode}; |
341 |
my $itemtype = $params->{itemtype}; |
355 |
my $itemtype = $params->{itemtype}; |
342 |
my $branchcode = $params->{branchcode}; |
356 |
my $branchcode = $params->{branchcode}; |
|
|
357 |
my $has_priority = $params->{has_priority}; |
343 |
|
358 |
|
344 |
my $r; |
359 |
my $r; |
345 |
foreach my $rule (@$rules) { |
360 |
foreach my $rule (@$rules) { |
Lines 349-354
sub get_effective_rules {
Link Here
|
349 |
categorycode => $categorycode, |
364 |
categorycode => $categorycode, |
350 |
itemtype => $itemtype, |
365 |
itemtype => $itemtype, |
351 |
branchcode => $branchcode, |
366 |
branchcode => $branchcode, |
|
|
367 |
has_priority => $has_priority, |
352 |
} |
368 |
} |
353 |
); |
369 |
); |
354 |
|
370 |
|
Lines 392-397
sub set_rule {
Link Here
|
392 |
my $itemtype = $params->{itemtype}; |
408 |
my $itemtype = $params->{itemtype}; |
393 |
my $rule_name = $params->{rule_name}; |
409 |
my $rule_name = $params->{rule_name}; |
394 |
my $rule_value = $params->{rule_value}; |
410 |
my $rule_value = $params->{rule_value}; |
|
|
411 |
my $has_priority = $params->{has_priority}; |
412 |
|
395 |
my $can_be_blank = defined $kind_info->{can_be_blank} ? $kind_info->{can_be_blank} : 1; |
413 |
my $can_be_blank = defined $kind_info->{can_be_blank} ? $kind_info->{can_be_blank} : 1; |
396 |
$rule_value = undef if defined $rule_value && $rule_value eq "" && !$can_be_blank; |
414 |
$rule_value = undef if defined $rule_value && $rule_value eq "" && !$can_be_blank; |
397 |
my $is_monetary = defined $kind_info->{is_monetary} ? $kind_info->{is_monetary} : 0; |
415 |
my $is_monetary = defined $kind_info->{is_monetary} ? $kind_info->{is_monetary} : 0; |
Lines 407-412
sub set_rule {
Link Here
|
407 |
branchcode => $branchcode, |
425 |
branchcode => $branchcode, |
408 |
categorycode => $categorycode, |
426 |
categorycode => $categorycode, |
409 |
itemtype => $itemtype, |
427 |
itemtype => $itemtype, |
|
|
428 |
has_priority => $has_priority |
410 |
} |
429 |
} |
411 |
)->next(); |
430 |
)->next(); |
412 |
|
431 |
|
Lines 428-433
sub set_rule {
Link Here
|
428 |
itemtype => $itemtype, |
447 |
itemtype => $itemtype, |
429 |
rule_name => $rule_name, |
448 |
rule_name => $rule_name, |
430 |
rule_value => $rule_value, |
449 |
rule_value => $rule_value, |
|
|
450 |
has_priority => $has_priority, |
431 |
} |
451 |
} |
432 |
); |
452 |
); |
433 |
$rule->store(); |
453 |
$rule->store(); |
Lines 453-459
sub set_rules {
Link Here
|
453 |
$set_params{branchcode} = $params->{branchcode} if exists $params->{branchcode}; |
473 |
$set_params{branchcode} = $params->{branchcode} if exists $params->{branchcode}; |
454 |
$set_params{categorycode} = $params->{categorycode} if exists $params->{categorycode}; |
474 |
$set_params{categorycode} = $params->{categorycode} if exists $params->{categorycode}; |
455 |
$set_params{itemtype} = $params->{itemtype} if exists $params->{itemtype}; |
475 |
$set_params{itemtype} = $params->{itemtype} if exists $params->{itemtype}; |
456 |
my $rules = $params->{rules}; |
476 |
$set_params{has_priority} = $params->{has_priority} if exists $params->{has_priority}; |
|
|
477 |
my $rules = $params->{rules}; |
478 |
|
457 |
|
479 |
|
458 |
my $rule_objects = []; |
480 |
my $rule_objects = []; |
459 |
while ( my ( $rule_name, $rule_value ) = each %$rules ) { |
481 |
while ( my ( $rule_name, $rule_value ) = each %$rules ) { |