# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
-use Carp qw(croak);
+use Carp qw( croak );
use Koha::Exceptions;
use Koha::CirculationRule;
+use Koha::Caches;
+use Koha::Cache::Memory::Lite;
use base qw(Koha::Objects);
-use constant GUESSED_ITEMTYPES_KEY => 'Koha_IssuingRules_last_guess';
+use constant GUESSED_ITEMTYPES_KEY => 'Koha_CirculationRules_last_guess';
=head1 NAME
=cut
our $RULE_KINDS = {
- refund => {
+ lostreturn => {
scope => [ 'branchcode' ],
},
holdallowed => {
scope => [ 'branchcode', 'itemtype' ],
+ can_be_blank => 0,
},
hold_fulfillment_policy => {
scope => [ 'branchcode', 'itemtype' ],
+ can_be_blank => 0,
},
returnbranch => {
scope => [ 'branchcode', 'itemtype' ],
+ can_be_blank => 0,
},
article_requests => {
scope => [ 'branchcode', 'categorycode', 'itemtype' ],
},
+ article_request_fee => {
+ scope => [ 'branchcode', 'categorycode' ],
+ },
+ open_article_requests_limit => {
+ scope => [ 'branchcode', 'categorycode' ],
+ },
+
auto_renew => {
scope => [ 'branchcode', 'categorycode', 'itemtype' ],
},
hardduedatecompare => {
scope => [ 'branchcode', 'categorycode', 'itemtype' ],
},
+ waiting_hold_cancellation => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ can_be_blank => 0,
+ },
holds_per_day => {
scope => [ 'branchcode', 'categorycode', 'itemtype' ],
},
renewalsallowed => {
scope => [ 'branchcode', 'categorycode', 'itemtype' ],
},
+ unseen_renewals_allowed => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
rentaldiscount => {
scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ can_be_blank => 0,
},
reservesallowed => {
scope => [ 'branchcode', 'categorycode', 'itemtype' ],
note => { # This is not really a rule. Maybe we will want to separate this later.
scope => [ 'branchcode', 'categorycode', 'itemtype' ],
},
+ decreaseloanholds => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ recalls_allowed => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ recalls_per_record => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ on_shelf_recalls => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ recall_due_date_interval => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ recall_overdue_fine => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ recall_shelf_time => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
# Not included (deprecated?):
# * accountsent
# * reservecharge
=head3 get_effective_rule
+ my $effective_rule = Koha::CirculationRules->get_effective_rule(
+ {
+ rule_name => $name,
+ categorycode => $categorycode,
+ itemtype => $itemtype,
+ branchcode => $branchcode
+ }
+ );
+
+Return the effective rule object for the rule associated with the criteria passed.
+
+
=cut
sub get_effective_rule {
return $rule;
}
+=head3 get_effective_rule_value
+
+ my $effective_rule_value = Koha::CirculationRules->get_effective_rule_value(
+ {
+ rule_name => $name,
+ categorycode => $categorycode,
+ itemtype => $itemtype,
+ branchcode => $branchcode
+ }
+ );
+
+Return the effective value for the rule associated with the criteria passed.
+
+This is a cached method so should be used in preference to get_effective_rule where possible
+to aid performance.
+
+=cut
+
+sub get_effective_rule_value {
+ my ( $self, $params ) = @_;
+
+ my $rule_name = $params->{rule_name};
+ my $categorycode = $params->{categorycode};
+ my $itemtype = $params->{itemtype};
+ my $branchcode = $params->{branchcode};
+
+ my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
+ my $cache_key = sprintf "CircRules:%s:%s:%s:%s", $rule_name // q{},
+ $categorycode // q{}, $branchcode // q{}, $itemtype // q{};
+
+ my $cached = $memory_cache->get_from_cache($cache_key);
+ return $cached if $cached;
+
+ my $rule = $self->get_effective_rule($params);
+
+ my $value= $rule ? $rule->rule_value : undef;
+ $memory_cache->set_in_cache( $cache_key, $value );
+ return $value;
+}
+
=head3 get_effective_rules
=cut
my $r;
foreach my $rule (@$rules) {
- my $effective_rule = $self->get_effective_rule(
+ my $effective_rule = $self->get_effective_rule_value(
{
rule_name => $rule,
categorycode => $categorycode,
}
);
- $r->{$rule} = $effective_rule->rule_value if $effective_rule;
+ $r->{$rule} = $effective_rule if defined $effective_rule;
}
return $r;
my $itemtype = $params->{itemtype};
my $rule_name = $params->{rule_name};
my $rule_value = $params->{rule_value};
+ my $can_be_blank = defined $kind_info->{can_be_blank} ? $kind_info->{can_be_blank} : 1;
+ $rule_value = undef if defined $rule_value && $rule_value eq "" && !$can_be_blank;
for my $v ( $branchcode, $categorycode, $itemtype ) {
$v = undef if $v and $v eq '*';
}
}
+ my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
+ for my $k ( $memory_cache->all_keys ) {
+ $memory_cache->clear_from_cache($k) if $k =~ m{^CircRules:};
+ }
+
return $rule;
}
=head3 get_lostreturn_policy
- my $refund = Koha::CirculationRules->get_lostreturn_policy( { return_branch => $return_branch, item => $item } );
+ my $lostrefund_policy = Koha::CirculationRules->get_lostreturn_policy( { return_branch => $return_branch, item => $item } );
+
+Return values are:
+
+=over 2
+
+=item '0' - Do not refund
+
+=item 'refund' - Refund the lost item charge
+
+=item 'restore' - Refund the lost item charge and restore the original overdue fine
+
+=item 'charge' - Refund the lost item charge and charge a new overdue fine
+
+=back
=cut
my $behaviour = C4::Context->preference( 'RefundLostOnReturnControl' ) // 'CheckinLibrary';
my $behaviour_mapping = {
- CheckinLibrary => $params->{'return_branch'},
- ItemHomeBranch => $item->homebranch,
+ CheckinLibrary => $params->{'return_branch'} // $item->homebranch,
+ ItemHomeBranch => $item->homebranch,
ItemHoldingBranch => $item->holdingbranch
};
my $rule = Koha::CirculationRules->get_effective_rule(
{
branchcode => $branch,
- rule_name => 'refund',
+ rule_name => 'lostreturn',
}
);
- return $rule ? $rule->rule_value : 1;
+ return $rule ? $rule->rule_value : 'refund';
}
=head3 article_requestable_rules
return $res;
}
-=head3 get_daysmode_effective_value
+=head3 get_effective_daysmode
Return the value for daysmode defined in the circulation rules.
If not defined (or empty string), the value of the system preference useDaysMode is returned