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