|
Lines 216-221
our $RULE_KINDS = {
Link Here
|
| 216 |
holds_pickup_period => { |
216 |
holds_pickup_period => { |
| 217 |
scope => [ 'branchcode', 'categorycode', 'itemtype' ], |
217 |
scope => [ 'branchcode', 'categorycode', 'itemtype' ], |
| 218 |
}, |
218 |
}, |
|
|
219 |
has_priority => { |
| 220 |
scope => [ 'branchcode', 'categorycode' ], |
| 221 |
}, |
| 219 |
# Not included (deprecated?): |
222 |
# Not included (deprecated?): |
| 220 |
# * accountsent |
223 |
# * accountsent |
| 221 |
# * reservecharge |
224 |
# * reservecharge |
|
Lines 248-258
sub get_effective_rule {
Link Here
|
| 248 |
$params->{categorycode} //= undef; |
251 |
$params->{categorycode} //= undef; |
| 249 |
$params->{branchcode} //= undef; |
252 |
$params->{branchcode} //= undef; |
| 250 |
$params->{itemtype} //= undef; |
253 |
$params->{itemtype} //= undef; |
|
|
254 |
$params->{has_priority} //= undef; |
| 251 |
|
255 |
|
| 252 |
my $rule_name = $params->{rule_name}; |
256 |
my $rule_name = $params->{rule_name}; |
| 253 |
my $categorycode = $params->{categorycode}; |
257 |
my $categorycode = $params->{categorycode}; |
| 254 |
my $itemtype = $params->{itemtype}; |
258 |
my $itemtype = $params->{itemtype}; |
| 255 |
my $branchcode = $params->{branchcode}; |
259 |
my $branchcode = $params->{branchcode}; |
|
|
260 |
my $has_priority = $params->{has_priority}; |
| 256 |
|
261 |
|
| 257 |
Koha::Exceptions::MissingParameter->throw( |
262 |
Koha::Exceptions::MissingParameter->throw( |
| 258 |
"Required parameter 'rule_name' missing") |
263 |
"Required parameter 'rule_name' missing") |
|
Lines 271-276
sub get_effective_rule {
Link Here
|
| 271 |
$search_params->{categorycode} = defined $categorycode ? [ $categorycode, undef ] : undef; |
276 |
$search_params->{categorycode} = defined $categorycode ? [ $categorycode, undef ] : undef; |
| 272 |
$search_params->{itemtype} = defined $itemtype ? [ $itemtype, undef ] : undef; |
277 |
$search_params->{itemtype} = defined $itemtype ? [ $itemtype, undef ] : undef; |
| 273 |
$search_params->{branchcode} = defined $branchcode ? [ $branchcode, undef ] : undef; |
278 |
$search_params->{branchcode} = defined $branchcode ? [ $branchcode, undef ] : undef; |
|
|
279 |
$search_params->{has_priority} = defined $has_priority ? $has_priority : 0; |
| 274 |
|
280 |
|
| 275 |
my $rule = $self->search( |
281 |
my $rule = $self->search( |
| 276 |
$search_params, |
282 |
$search_params, |
|
Lines 308-317
sub get_effective_rule_value {
Link Here
|
| 308 |
my $categorycode = $params->{categorycode}; |
314 |
my $categorycode = $params->{categorycode}; |
| 309 |
my $itemtype = $params->{itemtype}; |
315 |
my $itemtype = $params->{itemtype}; |
| 310 |
my $branchcode = $params->{branchcode}; |
316 |
my $branchcode = $params->{branchcode}; |
| 311 |
|
317 |
my $has_priority = $params->{has_priority}; |
| 312 |
my $memory_cache = Koha::Cache::Memory::Lite->get_instance; |
318 |
my $memory_cache = Koha::Cache::Memory::Lite->get_instance; |
| 313 |
my $cache_key = sprintf "CircRules:%s:%s:%s:%s", $rule_name // q{}, |
319 |
my $cache_key = sprintf "CircRules:%s:%s:%s:%s", $rule_name // q{}, |
| 314 |
$categorycode // q{}, $branchcode // q{}, $itemtype // q{}; |
320 |
$categorycode // q{}, $branchcode // q{}, $itemtype // q{} ,$has_priority // q{}; |
| 315 |
|
321 |
|
| 316 |
my $cached = $memory_cache->get_from_cache($cache_key); |
322 |
my $cached = $memory_cache->get_from_cache($cache_key); |
| 317 |
return $cached if $cached; |
323 |
return $cached if $cached; |
|
Lines 334-339
sub get_effective_rules {
Link Here
|
| 334 |
my $categorycode = $params->{categorycode}; |
340 |
my $categorycode = $params->{categorycode}; |
| 335 |
my $itemtype = $params->{itemtype}; |
341 |
my $itemtype = $params->{itemtype}; |
| 336 |
my $branchcode = $params->{branchcode}; |
342 |
my $branchcode = $params->{branchcode}; |
|
|
343 |
my $has_priority = $params->{has_priority}; |
| 337 |
|
344 |
|
| 338 |
my $r; |
345 |
my $r; |
| 339 |
foreach my $rule (@$rules) { |
346 |
foreach my $rule (@$rules) { |
|
Lines 343-348
sub get_effective_rules {
Link Here
|
| 343 |
categorycode => $categorycode, |
350 |
categorycode => $categorycode, |
| 344 |
itemtype => $itemtype, |
351 |
itemtype => $itemtype, |
| 345 |
branchcode => $branchcode, |
352 |
branchcode => $branchcode, |
|
|
353 |
has_priority => $has_priority, |
| 346 |
} |
354 |
} |
| 347 |
); |
355 |
); |
| 348 |
|
356 |
|
|
Lines 386-391
sub set_rule {
Link Here
|
| 386 |
my $itemtype = $params->{itemtype}; |
394 |
my $itemtype = $params->{itemtype}; |
| 387 |
my $rule_name = $params->{rule_name}; |
395 |
my $rule_name = $params->{rule_name}; |
| 388 |
my $rule_value = $params->{rule_value}; |
396 |
my $rule_value = $params->{rule_value}; |
|
|
397 |
my $has_priority = $params->{has_priority}; |
| 398 |
|
| 389 |
my $can_be_blank = defined $kind_info->{can_be_blank} ? $kind_info->{can_be_blank} : 1; |
399 |
my $can_be_blank = defined $kind_info->{can_be_blank} ? $kind_info->{can_be_blank} : 1; |
| 390 |
$rule_value = undef if defined $rule_value && $rule_value eq "" && !$can_be_blank; |
400 |
$rule_value = undef if defined $rule_value && $rule_value eq "" && !$can_be_blank; |
| 391 |
my $is_monetary = defined $kind_info->{is_monetary} ? $kind_info->{is_monetary} : 0; |
401 |
my $is_monetary = defined $kind_info->{is_monetary} ? $kind_info->{is_monetary} : 0; |
|
Lines 407-412
sub set_rule {
Link Here
|
| 407 |
if ($rule) { |
417 |
if ($rule) { |
| 408 |
if ( defined $rule_value ) { |
418 |
if ( defined $rule_value ) { |
| 409 |
$rule->rule_value($rule_value); |
419 |
$rule->rule_value($rule_value); |
|
|
420 |
$rule->has_priority($has_priority); |
| 410 |
$rule->update(); |
421 |
$rule->update(); |
| 411 |
} |
422 |
} |
| 412 |
else { |
423 |
else { |
|
Lines 422-427
sub set_rule {
Link Here
|
| 422 |
itemtype => $itemtype, |
433 |
itemtype => $itemtype, |
| 423 |
rule_name => $rule_name, |
434 |
rule_name => $rule_name, |
| 424 |
rule_value => $rule_value, |
435 |
rule_value => $rule_value, |
|
|
436 |
has_priority => $has_priority, |
| 425 |
} |
437 |
} |
| 426 |
); |
438 |
); |
| 427 |
$rule->store(); |
439 |
$rule->store(); |
|
Lines 444-453
sub set_rules {
Link Here
|
| 444 |
my ( $self, $params ) = @_; |
456 |
my ( $self, $params ) = @_; |
| 445 |
|
457 |
|
| 446 |
my %set_params; |
458 |
my %set_params; |
| 447 |
$set_params{branchcode} = $params->{branchcode} if exists $params->{branchcode}; |
459 |
$set_params{branchcode} = $params->{branchcode} |
| 448 |
$set_params{categorycode} = $params->{categorycode} if exists $params->{categorycode}; |
460 |
if exists $params->{branchcode}; |
|
|
461 |
$set_params{categorycode} = $params->{categorycode} |
| 462 |
if exists $params->{categorycode}; |
| 449 |
$set_params{itemtype} = $params->{itemtype} if exists $params->{itemtype}; |
463 |
$set_params{itemtype} = $params->{itemtype} if exists $params->{itemtype}; |
| 450 |
my $rules = $params->{rules}; |
464 |
$set_params{has_priority} = $params->{has_priority} |
|
|
465 |
if exists $params->{has_priority}; |
| 466 |
my $rules = $params->{rules}; |
| 467 |
|
| 451 |
|
468 |
|
| 452 |
my $rule_objects = []; |
469 |
my $rule_objects = []; |
| 453 |
while ( my ( $rule_name, $rule_value ) = each %$rules ) { |
470 |
while ( my ( $rule_name, $rule_value ) = each %$rules ) { |