Bug 17599: Move C4::Circulation::GetIssuingRule to Koha::IssuingRules->get_effective_issuing_rule
This is a POC, I have not tested it yet. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
36280356c1
commit
6edbd47a44
|
|
@ -43,6 +43,7 @@ use Koha::Account;
|
|||
use Koha::AuthorisedValues;
|
||||
use Koha::DateUtils;
|
||||
use Koha::Calendar;
|
||||
use Koha::IssuingRules;
|
||||
use Koha::Items;
|
||||
use Koha::Patrons;
|
||||
use Koha::Patron::Debarments;
|
||||
|
|
@ -89,7 +90,6 @@ BEGIN {
|
|||
&GetItemIssue
|
||||
&GetItemIssues
|
||||
&GetIssuingCharges
|
||||
&GetIssuingRule
|
||||
&GetBranchBorrowerCircRule
|
||||
&GetBranchItemRule
|
||||
&GetBiblioIssues
|
||||
|
|
@ -397,12 +397,12 @@ sub TooMany {
|
|||
|
||||
# given branch, patron category, and item type, determine
|
||||
# applicable issuing rule
|
||||
my $issuing_rule = GetIssuingRule($cat_borrower, $type, $branch);
|
||||
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $cat_borrower, itemtype => $type, branchcode => $branch });
|
||||
|
||||
# if a rule is found and has a loan limit set, count
|
||||
# how many loans the patron already has that meet that
|
||||
# rule
|
||||
if (defined($issuing_rule) and defined($issuing_rule->{'maxissueqty'})) {
|
||||
if (defined($issuing_rule) and defined($issuing_rule->maxissueqty)) {
|
||||
my @bind_params;
|
||||
my $count_query = q|
|
||||
SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
|
||||
|
|
@ -410,7 +410,7 @@ sub TooMany {
|
|||
JOIN items USING (itemnumber)
|
||||
|;
|
||||
|
||||
my $rule_itemtype = $issuing_rule->{itemtype};
|
||||
my $rule_itemtype = $issuing_rule->itemtype;
|
||||
if ($rule_itemtype eq "*") {
|
||||
# matching rule has the default item type, so count only
|
||||
# those existing loans that don't fall under a more
|
||||
|
|
@ -431,8 +431,8 @@ sub TooMany {
|
|||
AND itemtype <> '*'
|
||||
) ";
|
||||
}
|
||||
push @bind_params, $issuing_rule->{branchcode};
|
||||
push @bind_params, $issuing_rule->{categorycode};
|
||||
push @bind_params, $issuing_rule->branchcode;
|
||||
push @bind_params, $issuing_rule->categorycode;
|
||||
push @bind_params, $cat_borrower;
|
||||
} else {
|
||||
# rule has specific item type, so count loans of that
|
||||
|
|
@ -448,7 +448,7 @@ sub TooMany {
|
|||
|
||||
$count_query .= " AND borrowernumber = ? ";
|
||||
push @bind_params, $borrower->{'borrowernumber'};
|
||||
my $rule_branch = $issuing_rule->{branchcode};
|
||||
my $rule_branch = $issuing_rule->branchcode;
|
||||
if ($rule_branch ne "*") {
|
||||
if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
|
||||
$count_query .= " AND issues.branchcode = ? ";
|
||||
|
|
@ -463,8 +463,8 @@ sub TooMany {
|
|||
|
||||
my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
|
||||
|
||||
my $max_checkouts_allowed = $issuing_rule->{maxissueqty};
|
||||
my $max_onsite_checkouts_allowed = $issuing_rule->{maxonsiteissueqty};
|
||||
my $max_checkouts_allowed = $issuing_rule->maxissueqty;
|
||||
my $max_onsite_checkouts_allowed = $issuing_rule->maxonsiteissueqty;
|
||||
|
||||
if ( $onsite_checkout ) {
|
||||
if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) {
|
||||
|
|
@ -1333,8 +1333,8 @@ sub AddIssue {
|
|||
|
||||
# If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
|
||||
unless ($auto_renew) {
|
||||
my $issuingrule = GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branch );
|
||||
$auto_renew = $issuingrule->{auto_renew};
|
||||
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrower->{categorycode}, itemtype => $item->{itype}, branchcode => $branch });
|
||||
$auto_renew = $issuing_rule->auto_renew if $issuing_rule;
|
||||
}
|
||||
|
||||
# Record in the database the fact that the book was issued.
|
||||
|
|
@ -1533,72 +1533,17 @@ Get the Hard Due Date and it's comparison for an itemtype, a borrower type and a
|
|||
sub GetHardDueDate {
|
||||
my ( $borrowertype, $itemtype, $branchcode ) = @_;
|
||||
|
||||
my $rule = GetIssuingRule( $borrowertype, $itemtype, $branchcode );
|
||||
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrowertype, itemtype => $itemtype, branchcode => $branchcode });
|
||||
|
||||
if ( defined( $rule ) ) {
|
||||
if ( $rule->{hardduedate} ) {
|
||||
return (dt_from_string($rule->{hardduedate}, 'iso'),$rule->{hardduedatecompare});
|
||||
if ( defined( $issuing_rule ) ) {
|
||||
if ( $issuing_rule->hardduedate ) {
|
||||
return (dt_from_string($issuing_rule->hardduedate, 'iso'),$issuing_rule->hardduedatecompare);
|
||||
} else {
|
||||
return (undef, undef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
=head2 GetIssuingRule
|
||||
|
||||
my $irule = &GetIssuingRule($borrowertype,$itemtype,branchcode)
|
||||
|
||||
FIXME - This is a copy-paste of GetLoanLength
|
||||
as a stop-gap. Do not wish to change API for GetLoanLength
|
||||
this close to release.
|
||||
|
||||
Get the issuing rule for an itemtype, a borrower type and a branch
|
||||
Returns a hashref from the issuingrules table.
|
||||
|
||||
=cut
|
||||
|
||||
sub GetIssuingRule {
|
||||
my ( $borrowertype, $itemtype, $branchcode ) = @_;
|
||||
my $dbh = C4::Context->dbh;
|
||||
my $sth = $dbh->prepare( "select * from issuingrules where categorycode=? and itemtype=? and branchcode=?" );
|
||||
my $irule;
|
||||
|
||||
$sth->execute( $borrowertype, $itemtype, $branchcode );
|
||||
$irule = $sth->fetchrow_hashref;
|
||||
return $irule if defined($irule) ;
|
||||
|
||||
$sth->execute( $borrowertype, "*", $branchcode );
|
||||
$irule = $sth->fetchrow_hashref;
|
||||
return $irule if defined($irule) ;
|
||||
|
||||
$sth->execute( "*", $itemtype, $branchcode );
|
||||
$irule = $sth->fetchrow_hashref;
|
||||
return $irule if defined($irule) ;
|
||||
|
||||
$sth->execute( "*", "*", $branchcode );
|
||||
$irule = $sth->fetchrow_hashref;
|
||||
return $irule if defined($irule) ;
|
||||
|
||||
$sth->execute( $borrowertype, $itemtype, "*" );
|
||||
$irule = $sth->fetchrow_hashref;
|
||||
return $irule if defined($irule) ;
|
||||
|
||||
$sth->execute( $borrowertype, "*", "*" );
|
||||
$irule = $sth->fetchrow_hashref;
|
||||
return $irule if defined($irule) ;
|
||||
|
||||
$sth->execute( "*", $itemtype, "*" );
|
||||
$irule = $sth->fetchrow_hashref;
|
||||
return $irule if defined($irule) ;
|
||||
|
||||
$sth->execute( "*", "*", "*" );
|
||||
$irule = $sth->fetchrow_hashref;
|
||||
return $irule if defined($irule) ;
|
||||
|
||||
# if no rule matches,
|
||||
return;
|
||||
}
|
||||
|
||||
=head2 GetBranchBorrowerCircRule
|
||||
|
||||
my $branch_cat_rule = GetBranchBorrowerCircRule($branchcode, $categorycode);
|
||||
|
|
@ -2240,10 +2185,9 @@ sub _debar_user_on_return {
|
|||
my $branchcode = _GetCircControlBranch( $item, $borrower );
|
||||
|
||||
my $circcontrol = C4::Context->preference('CircControl');
|
||||
my $issuingrule =
|
||||
GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
|
||||
my $finedays = $issuingrule->{finedays};
|
||||
my $unit = $issuingrule->{lengthunit};
|
||||
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrower->{categorycode}, itemtype => $item->{itype}, branchcode => $branchcode });
|
||||
my $finedays = $issuing_rule ? $issuing_rule->finedays : undef;
|
||||
my $unit = $issuing_rule ? $issuing_rule->lengthunit : undef;
|
||||
my $chargeable_units = C4::Overdues::get_chargeable_units($unit, $dt_due, $dt_today, $branchcode);
|
||||
|
||||
if ($finedays) {
|
||||
|
|
@ -2254,7 +2198,7 @@ sub _debar_user_on_return {
|
|||
|
||||
# grace period is measured in the same units as the loan
|
||||
my $grace =
|
||||
DateTime::Duration->new( $unit => $issuingrule->{firstremind} );
|
||||
DateTime::Duration->new( $unit => $issuing_rule->firstremind );
|
||||
|
||||
my $deltadays = DateTime::Duration->new(
|
||||
days => $chargeable_units
|
||||
|
|
@ -2264,7 +2208,7 @@ sub _debar_user_on_return {
|
|||
|
||||
# If the max suspension days is < than the suspension days
|
||||
# the suspension days is limited to this maximum period.
|
||||
my $max_sd = $issuingrule->{maxsuspensiondays};
|
||||
my $max_sd = $issuing_rule->maxsuspensiondays;
|
||||
if ( defined $max_sd ) {
|
||||
$max_sd = DateTime::Duration->new( days => $max_sd );
|
||||
$suspension_days = $max_sd
|
||||
|
|
@ -2836,11 +2780,10 @@ sub CanBookBeRenewed {
|
|||
return ( 1, undef ) if $override_limit;
|
||||
|
||||
my $branchcode = _GetCircControlBranch( $item, $borrower );
|
||||
my $issuingrule =
|
||||
GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
|
||||
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrower->{categorycode}, itemtype => $item->{itype}, branchcode => $branchcode });
|
||||
|
||||
return ( 0, "too_many" )
|
||||
if $issuingrule->{renewalsallowed} <= $itemissue->{renewals};
|
||||
if not $issuing_rule or $issuing_rule->renewalsallowed <= $itemissue->{renewals};
|
||||
|
||||
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
|
||||
my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
|
||||
|
|
@ -2855,14 +2798,14 @@ sub CanBookBeRenewed {
|
|||
}
|
||||
|
||||
if ( $itemissue->{auto_renew}
|
||||
and defined $issuingrule->{no_auto_renewal_after}
|
||||
and $issuingrule->{no_auto_renewal_after} ne "" ) {
|
||||
and defined $issuing_rule->no_auto_renewal_after
|
||||
and $issuing_rule->no_auto_renewal_after ne "" ) {
|
||||
|
||||
# Get issue_date and add no_auto_renewal_after
|
||||
# If this is greater than today, it's too late for renewal.
|
||||
my $maximum_renewal_date = dt_from_string($itemissue->{issuedate});
|
||||
$maximum_renewal_date->add(
|
||||
$issuingrule->{lengthunit} => $issuingrule->{no_auto_renewal_after}
|
||||
$issuing_rule->lengthunit => $issuing_rule->no_auto_renewal_after
|
||||
);
|
||||
my $now = dt_from_string;
|
||||
if ( $now >= $maximum_renewal_date ) {
|
||||
|
|
@ -2870,19 +2813,19 @@ sub CanBookBeRenewed {
|
|||
}
|
||||
}
|
||||
|
||||
if ( defined $issuingrule->{norenewalbefore}
|
||||
and $issuingrule->{norenewalbefore} ne "" )
|
||||
if ( defined $issuing_rule->norenewalbefore
|
||||
and $issuing_rule->norenewalbefore ne "" )
|
||||
{
|
||||
|
||||
# Calculate soonest renewal by subtracting 'No renewal before' from due date
|
||||
my $soonestrenewal =
|
||||
$itemissue->{date_due}->clone()
|
||||
->subtract(
|
||||
$issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} );
|
||||
$issuing_rule->lengthunit => $issuing_rule->norenewalbefore );
|
||||
|
||||
# Depending on syspref reset the exact time, only check the date
|
||||
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
|
||||
and $issuingrule->{lengthunit} eq 'days' )
|
||||
and $issuing_rule->lengthunit eq 'days' )
|
||||
{
|
||||
$soonestrenewal->truncate( to => 'day' );
|
||||
}
|
||||
|
|
@ -3078,10 +3021,10 @@ sub GetRenewCount {
|
|||
$renewcount = $data->{'renewals'} if $data->{'renewals'};
|
||||
# $item and $borrower should be calculated
|
||||
my $branchcode = _GetCircControlBranch($item, $borrower);
|
||||
|
||||
my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode);
|
||||
|
||||
$renewsallowed = $issuingrule->{'renewalsallowed'};
|
||||
|
||||
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrower->{categorycode}, itemtype => $item->{itype}, branchcode => $branchcode });
|
||||
|
||||
$renewsallowed = $issuing_rule ? $issuing_rule->renewalsallowed : undef; # FIXME Just replace undef with 0 to get what we expected. But what about the side-effects? TODO LATER
|
||||
$renewsleft = $renewsallowed - $renewcount;
|
||||
if($renewsleft < 0){ $renewsleft = 0; }
|
||||
return ( $renewcount, $renewsallowed, $renewsleft );
|
||||
|
|
@ -3119,21 +3062,21 @@ sub GetSoonestRenewDate {
|
|||
or return;
|
||||
|
||||
my $branchcode = _GetCircControlBranch( $item, $borrower );
|
||||
my $issuingrule =
|
||||
GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
|
||||
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrower->{categorycode}, itemtype => $item->{itype}, branchcode => $branchcode });
|
||||
|
||||
my $now = dt_from_string;
|
||||
return $now unless $issuing_rule;
|
||||
|
||||
if ( defined $issuingrule->{norenewalbefore}
|
||||
and $issuingrule->{norenewalbefore} ne "" )
|
||||
if ( defined $issuing_rule->norenewalbefore
|
||||
and $issuing_rule->norenewalbefore ne "" )
|
||||
{
|
||||
my $soonestrenewal =
|
||||
$itemissue->{date_due}->clone()
|
||||
->subtract(
|
||||
$issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} );
|
||||
$issuing_rule->lengthunit => $issuing_rule->norenewalbefore );
|
||||
|
||||
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
|
||||
and $issuingrule->{lengthunit} eq 'days' )
|
||||
and $issuing_rule->lengthunit eq 'days' )
|
||||
{
|
||||
$soonestrenewal->truncate( to => 'day' );
|
||||
}
|
||||
|
|
@ -3174,17 +3117,15 @@ sub GetLatestAutoRenewDate {
|
|||
or return;
|
||||
|
||||
my $branchcode = _GetCircControlBranch( $item, $borrower );
|
||||
my $issuingrule =
|
||||
GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
|
||||
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrower->{categorycode}, itemtype => $item->{itype}, branchcode => $branchcode });
|
||||
|
||||
my $now = dt_from_string;
|
||||
|
||||
return if not $issuingrule->{no_auto_renewal_after}
|
||||
or $issuingrule->{no_auto_renewal_after} eq '';
|
||||
return unless $issuing_rule;
|
||||
return if not $issuing_rule->no_auto_renewal_after
|
||||
or $issuing_rule->no_auto_renewal_after eq '';
|
||||
|
||||
my $maximum_renewal_date = dt_from_string($itemissue->{issuedate});
|
||||
$maximum_renewal_date->add(
|
||||
$issuingrule->{lengthunit} => $issuingrule->{no_auto_renewal_after}
|
||||
$issuing_rule->lengthunit => $issuing_rule->no_auto_renewal_after
|
||||
);
|
||||
|
||||
return $maximum_renewal_date;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ use C4::Debug;
|
|||
use Koha::DateUtils;
|
||||
use Koha::Account::Line;
|
||||
use Koha::Account::Lines;
|
||||
use Koha::IssuingRules;
|
||||
use Koha::Libraries;
|
||||
|
||||
use vars qw(@ISA @EXPORT);
|
||||
|
|
@ -74,9 +75,6 @@ BEGIN {
|
|||
&GetIssuesIteminfo
|
||||
);
|
||||
|
||||
# &GetIssuingRules - delete.
|
||||
# use C4::Circulation::GetIssuingRule instead.
|
||||
|
||||
# subs to move to Biblio.pm
|
||||
push @EXPORT, qw(
|
||||
&GetItems
|
||||
|
|
@ -251,26 +249,28 @@ sub CalcFine {
|
|||
my $start_date = $due_dt->clone();
|
||||
# get issuingrules (fines part will be used)
|
||||
my $itemtype = $item->{itemtype} || $item->{itype};
|
||||
my $data = C4::Circulation::GetIssuingRule($bortype, $itemtype, $branchcode);
|
||||
my $fine_unit = $data->{lengthunit};
|
||||
$fine_unit ||= 'days';
|
||||
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $bortype, itemtype => $itemtype, branchcode => $branchcode });
|
||||
|
||||
return unless $issuing_rule; # If not rule exist, there is no fine
|
||||
|
||||
my $fine_unit = $issuing_rule->lengthunit || 'days';
|
||||
|
||||
my $chargeable_units = get_chargeable_units($fine_unit, $start_date, $end_date, $branchcode);
|
||||
my $units_minus_grace = $chargeable_units - $data->{firstremind};
|
||||
my $units_minus_grace = $chargeable_units - $issuing_rule->firstremind;
|
||||
my $amount = 0;
|
||||
if ( $data->{'chargeperiod'} && ( $units_minus_grace > 0 ) ) {
|
||||
if ( $issuing_rule->chargeperiod && ( $units_minus_grace > 0 ) ) {
|
||||
my $units = C4::Context->preference('FinesIncludeGracePeriod') ? $chargeable_units : $units_minus_grace;
|
||||
my $charge_periods = $units / $data->{'chargeperiod'};
|
||||
my $charge_periods = $units / $issuing_rule->chargeperiod;
|
||||
# If chargeperiod_charge_at = 1, we charge a fine at the start of each charge period
|
||||
# if chargeperiod_charge_at = 0, we charge at the end of each charge period
|
||||
$charge_periods = $data->{'chargeperiod_charge_at'} == 1 ? ceil($charge_periods) : floor($charge_periods);
|
||||
$amount = $charge_periods * $data->{'fine'};
|
||||
$charge_periods = $issuing_rule->chargeperiod_charge_at == 1 ? ceil($charge_periods) : floor($charge_periods);
|
||||
$amount = $charge_periods * $issuing_rule->fine;
|
||||
} # else { # a zero (or null) chargeperiod or negative units_minus_grace value means no charge. }
|
||||
|
||||
$amount = $data->{overduefinescap} if $data->{overduefinescap} && $amount > $data->{overduefinescap};
|
||||
$amount = $item->{replacementprice} if ( $data->{cap_fine_to_replacement_price} && $item->{replacementprice} && $amount > $item->{replacementprice} );
|
||||
$debug and warn sprintf("CalcFine returning (%s, %s, %s, %s)", $amount, $data->{'chargename'}, $units_minus_grace, $chargeable_units);
|
||||
return ($amount, $data->{'chargename'}, $units_minus_grace, $chargeable_units);
|
||||
$amount = $issuing_rule->overduefinescap if $issuing_rule->overduefinescap && $amount > $issuing_rule->overduefinescap;
|
||||
$amount = $item->{replacementprice} if ( $issuing_rule->cap_fine_to_replacement_price && $item->{replacementprice} && $amount > $item->{replacementprice} );
|
||||
$debug and warn sprintf("CalcFine returning (%s, %s, %s, %s)", $amount, $issuing_rule->chargename, $units_minus_grace, $chargeable_units);
|
||||
return ($amount, $issuing_rule->chargename, $units_minus_grace, $chargeable_units);
|
||||
# FIXME: chargename is NEVER populated anywhere.
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ use Koha::Hold;
|
|||
use Koha::Old::Hold;
|
||||
use Koha::Holds;
|
||||
use Koha::Libraries;
|
||||
use Koha::IssuingRules;
|
||||
use Koha::Items;
|
||||
use Koha::ItemTypes;
|
||||
use Koha::Patrons;
|
||||
|
|
@ -1579,8 +1580,8 @@ sub _get_itype {
|
|||
sub _OnShelfHoldsAllowed {
|
||||
my ($itype,$borrowercategory,$branchcode) = @_;
|
||||
|
||||
my $rule = C4::Circulation::GetIssuingRule($borrowercategory, $itype, $branchcode);
|
||||
return $rule->{onshelfholds};
|
||||
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrowercategory, itemtype => $itype, branchcode => $branchcode });
|
||||
return $issuing_rule ? $issuing_rule->onshelfholds : undef;
|
||||
}
|
||||
|
||||
=head2 AlterPriority
|
||||
|
|
|
|||
|
|
@ -27,11 +27,11 @@ use Koha::Database;
|
|||
|
||||
use base qw(Koha::Object);
|
||||
|
||||
use C4::Circulation qw(GetIssuingRule);
|
||||
use Koha::Items;
|
||||
use Koha::Biblioitems;
|
||||
use Koha::ArticleRequests;
|
||||
use Koha::ArticleRequest::Status;
|
||||
use Koha::IssuingRules;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -121,9 +121,10 @@ sub article_request_type_for_bib {
|
|||
my $borrowertype = $borrower->categorycode;
|
||||
my $itemtype = $self->itemtype();
|
||||
|
||||
my $rules = C4::Circulation::GetIssuingRule( $borrowertype, $itemtype );
|
||||
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrowertype, itemtype => $itemtype });
|
||||
|
||||
return $rules->{article_requests} || q{};
|
||||
return q{} unless $issuing_rule;
|
||||
return $issuing_rule->article_requests || q{}
|
||||
}
|
||||
|
||||
=head3 article_request_type_for_items
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package Koha::IssuingRules;
|
||||
|
||||
# Copyright Vaara-kirjastot 2015
|
||||
# Copyright Koha Development Team 2016
|
||||
#
|
||||
# This file is part of Koha.
|
||||
#
|
||||
|
|
@ -18,12 +19,16 @@ package Koha::IssuingRules;
|
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
use Modern::Perl;
|
||||
|
||||
use Koha::Database;
|
||||
|
||||
use Koha::IssuingRule;
|
||||
|
||||
use base qw(Koha::Objects);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Koha::IssuingRules - Koha IssuingRules object set class
|
||||
Koha::IssuingRules - Koha IssuingRule Object set class
|
||||
|
||||
=head1 API
|
||||
|
||||
|
|
@ -31,6 +36,83 @@ Koha::IssuingRules - Koha IssuingRules object set class
|
|||
|
||||
=cut
|
||||
|
||||
sub get_effective_issuing_rule {
|
||||
my ( $self, $params ) = @_;
|
||||
|
||||
my $default = '*';
|
||||
my $categorycode = $params->{categorycode};
|
||||
my $itemtype = $params->{itemtype};
|
||||
my $branchcode = $params->{branchcode};
|
||||
|
||||
my $rule = $self->find($params);
|
||||
return $rule if $rule;
|
||||
|
||||
$rule = $self->find(
|
||||
{
|
||||
categorycode => $categorycode,
|
||||
itemtype => $default,
|
||||
branchcode => $branchcode
|
||||
}
|
||||
);
|
||||
return $rule if $rule;
|
||||
|
||||
$rule = $self->find(
|
||||
{
|
||||
categorycode => $default,
|
||||
itemtype => $itemtype,
|
||||
branchcode => $branchcode
|
||||
}
|
||||
);
|
||||
return $rule if $rule;
|
||||
|
||||
$rule = $self->find(
|
||||
{
|
||||
categorycode => $default,
|
||||
itemtype => $default,
|
||||
branchcode => $branchcode
|
||||
}
|
||||
);
|
||||
return $rule if $rule;
|
||||
|
||||
$rule = $self->find(
|
||||
{
|
||||
categorycode => $categorycode,
|
||||
itemtype => $itemtype,
|
||||
branchcode => $default
|
||||
}
|
||||
);
|
||||
return $rule if $rule;
|
||||
|
||||
$rule = $self->find(
|
||||
{
|
||||
categorycode => $categorycode,
|
||||
itemtype => $default,
|
||||
branchcode => $default
|
||||
}
|
||||
);
|
||||
return $rule if $rule;
|
||||
|
||||
$rule = $self->find(
|
||||
{
|
||||
categorycode => $default,
|
||||
itemtype => $itemtype,
|
||||
branchcode => $default
|
||||
}
|
||||
);
|
||||
return $rule if $rule;
|
||||
|
||||
$rule = $self->find(
|
||||
{
|
||||
categorycode => $default,
|
||||
itemtype => $default,
|
||||
branchcode => $default
|
||||
}
|
||||
);
|
||||
return $rule if $rule;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
=head3 type
|
||||
|
||||
=cut
|
||||
|
|
@ -39,12 +121,8 @@ sub _type {
|
|||
return 'Issuingrule';
|
||||
}
|
||||
|
||||
=head3 object_class
|
||||
|
||||
=cut
|
||||
|
||||
sub object_class {
|
||||
return 'Koha::IssuingRule';
|
||||
}
|
||||
|
||||
1;
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use Carp;
|
|||
use Koha::Database;
|
||||
|
||||
use C4::Context;
|
||||
use C4::Circulation qw(GetIssuingRule);
|
||||
use Koha::IssuingRules;
|
||||
use Koha::Item::Transfer;
|
||||
use Koha::Patrons;
|
||||
use Koha::Libraries;
|
||||
|
|
@ -164,9 +164,10 @@ sub article_request_type {
|
|||
: undef;
|
||||
my $borrowertype = $borrower->categorycode;
|
||||
my $itemtype = $self->effective_itemtype();
|
||||
my $rules = C4::Circulation::GetIssuingRule( $borrowertype, $itemtype, $branchcode );
|
||||
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrowertype, itemtype => $itemtype, branchcode => $branchcode });
|
||||
|
||||
return $rules->{article_requests} || q{};
|
||||
return q{} unless $issuing_rule;
|
||||
return $issuing_rule->article_requests || q{}
|
||||
}
|
||||
|
||||
=head3 type
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ can_ok( 'C4::Circulation', qw(
|
|||
AddReturn
|
||||
GetBranchBorrowerCircRule
|
||||
GetBranchItemRule
|
||||
GetIssuingRule
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use Modern::Perl;
|
|||
use C4::Context;
|
||||
use DateTime;
|
||||
use Koha::DateUtils;
|
||||
use Koha::IssuingRules;
|
||||
use Koha::Library;
|
||||
|
||||
use Test::More tests => 10;
|
||||
|
|
@ -15,7 +16,6 @@ can_ok(
|
|||
'C4::Circulation',
|
||||
qw(
|
||||
GetHardDueDate
|
||||
GetIssuingRule
|
||||
GetLoanLength
|
||||
)
|
||||
);
|
||||
|
|
@ -143,6 +143,8 @@ my $sampleissuingrule1 = {
|
|||
opacitemholds => 'N',
|
||||
cap_fine_to_replacement_price => 0,
|
||||
holds_per_record => 1,
|
||||
article_requests => 'yes',
|
||||
no_auto_renewal_after => undef,
|
||||
};
|
||||
my $sampleissuingrule2 = {
|
||||
branchcode => $samplebranch2->{branchcode},
|
||||
|
|
@ -175,6 +177,7 @@ my $sampleissuingrule2 = {
|
|||
opacitemholds => 'Y',
|
||||
cap_fine_to_replacement_price => 0,
|
||||
holds_per_record => 1,
|
||||
article_requests => 'yes',
|
||||
};
|
||||
my $sampleissuingrule3 = {
|
||||
branchcode => $samplebranch1->{branchcode},
|
||||
|
|
@ -207,6 +210,7 @@ my $sampleissuingrule3 = {
|
|||
opacitemholds => 'F',
|
||||
cap_fine_to_replacement_price => 0,
|
||||
holds_per_record => 1,
|
||||
article_requests => 'yes',
|
||||
};
|
||||
|
||||
$query = 'INSERT INTO issuingrules (
|
||||
|
|
@ -238,8 +242,9 @@ $query = 'INSERT INTO issuingrules (
|
|||
maxsuspensiondays,
|
||||
onshelfholds,
|
||||
opacitemholds,
|
||||
cap_fine_to_replacement_price
|
||||
) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
|
||||
cap_fine_to_replacement_price,
|
||||
article_requests
|
||||
) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
|
||||
my $sth = $dbh->prepare($query);
|
||||
$sth->execute(
|
||||
$sampleissuingrule1->{branchcode},
|
||||
|
|
@ -271,6 +276,7 @@ $sth->execute(
|
|||
$sampleissuingrule1->{onshelfholds},
|
||||
$sampleissuingrule1->{opacitemholds},
|
||||
$sampleissuingrule1->{cap_fine_to_replacement_price},
|
||||
$sampleissuingrule1->{article_requests},
|
||||
);
|
||||
$sth->execute(
|
||||
$sampleissuingrule2->{branchcode},
|
||||
|
|
@ -302,6 +308,7 @@ $sth->execute(
|
|||
$sampleissuingrule2->{onshelfholds},
|
||||
$sampleissuingrule2->{opacitemholds},
|
||||
$sampleissuingrule2->{cap_fine_to_replacement_price},
|
||||
$sampleissuingrule2->{article_requests},
|
||||
);
|
||||
$sth->execute(
|
||||
$sampleissuingrule3->{branchcode},
|
||||
|
|
@ -333,13 +340,11 @@ $sth->execute(
|
|||
$sampleissuingrule3->{onshelfholds},
|
||||
$sampleissuingrule3->{opacitemholds},
|
||||
$sampleissuingrule3->{cap_fine_to_replacement_price},
|
||||
$sampleissuingrule3->{article_requests},
|
||||
);
|
||||
|
||||
is_deeply(
|
||||
GetIssuingRule(
|
||||
$samplecat->{categorycode},
|
||||
'Book', $samplebranch1->{branchcode}
|
||||
),
|
||||
Koha::IssuingRules->find({ categorycode => $samplecat->{categorycode}, itemtype => 'Book', branchcode => $samplebranch1->{branchcode} })->unblessed,
|
||||
$sampleissuingrule1,
|
||||
"GetIssuingCharge returns issuingrule1's informations"
|
||||
);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ use Test::More tests => 2;
|
|||
|
||||
use MARC::Record;
|
||||
use MARC::Field;
|
||||
use Test::MockModule;
|
||||
use C4::Context;
|
||||
|
||||
use C4::Biblio qw( AddBiblio );
|
||||
|
|
@ -29,16 +28,21 @@ local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
|
|||
my $userenv->{branch} = $branchcode;
|
||||
*C4::Context::userenv = \&Mock_userenv;
|
||||
|
||||
my $circulation_module = Test::MockModule->new('C4::Circulation');
|
||||
|
||||
# Test without maxsuspensiondays set
|
||||
$circulation_module->mock('GetIssuingRule', sub {
|
||||
return {
|
||||
firstremind => 0,
|
||||
finedays => 2,
|
||||
lengthunit => 'days',
|
||||
Koha::IssuingRules->search->delete;
|
||||
$builder->build(
|
||||
{
|
||||
source => 'Issuingrule',
|
||||
value => {
|
||||
categorycode => '*',
|
||||
itemtype => '*',
|
||||
branchcode => '*',
|
||||
firstremind => 0,
|
||||
finedays => 2,
|
||||
lengthunit => 'days',
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
my $borrowernumber = AddMember(
|
||||
firstname => 'my firstname',
|
||||
|
|
@ -82,14 +86,9 @@ is(
|
|||
DelDebarment( $debarments->[0]->{borrower_debarment_id} );
|
||||
|
||||
# Test with maxsuspensiondays = 10 days
|
||||
$circulation_module->mock('GetIssuingRule', sub {
|
||||
return {
|
||||
firstremind => 0,
|
||||
finedays => 2,
|
||||
maxsuspensiondays => 10,
|
||||
lengthunit => 'days',
|
||||
}
|
||||
});
|
||||
my $issuing_rule = Koha::IssuingRules->search->next;
|
||||
$issuing_rule->maxsuspensiondays( 10 )->store;
|
||||
|
||||
my $daysafter10 = dt_from_string->add_duration(DateTime::Duration->new(days => 10));
|
||||
AddIssue( $borrower, $barcode, $daysago20 );
|
||||
AddReturn( $barcode, $branchcode );
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ can_ok(
|
|||
AddReturn
|
||||
GetBiblioIssues
|
||||
GetIssuingCharges
|
||||
GetIssuingRule
|
||||
GetItemIssue
|
||||
GetItemIssues
|
||||
GetOpenIssue
|
||||
|
|
@ -242,7 +241,7 @@ my $issue3 = C4::Circulation::AddIssue( $borrower_1, $barcode_1 );
|
|||
@renewcount = C4::Circulation::GetRenewCount();
|
||||
is_deeply(
|
||||
\@renewcount,
|
||||
[ 0, undef, 0 ], # FIXME Need to be fixed
|
||||
[ 0, undef, 0 ], # FIXME Need to be fixed, see FIXME in GetRenewCount
|
||||
"Without issuing rules and without parameter, GetRenewCount returns renewcount = 0, renewsallowed = undef, renewsleft = 0"
|
||||
);
|
||||
@renewcount = C4::Circulation::GetRenewCount(-1);
|
||||
|
|
|
|||
|
|
@ -551,18 +551,24 @@ ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a
|
|||
my $itype = C4::Reserves::_get_itype($item);
|
||||
my $categorycode = $borrower->{categorycode};
|
||||
my $holdingbranch = $item->{holdingbranch};
|
||||
my $rule = C4::Circulation::GetIssuingRule($categorycode, $itype, $holdingbranch);
|
||||
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
|
||||
{
|
||||
categorycode => $categorycode,
|
||||
itemtype => $itype,
|
||||
branchcode => $holdingbranch
|
||||
}
|
||||
);
|
||||
|
||||
$dbh->do(
|
||||
"UPDATE issuingrules SET onshelfholds = 1 WHERE categorycode = ? AND itemtype= ? and branchcode = ?",
|
||||
undef,
|
||||
$rule->{categorycode}, $rule->{itemtype}, $rule->{branchcode}
|
||||
$issuing_rule->categorycode, $issuing_rule->itemtype, $issuing_rule->branchcode
|
||||
);
|
||||
ok( C4::Reserves::OnShelfHoldsAllowed($item, $borrower), "OnShelfHoldsAllowed() allowed" );
|
||||
$dbh->do(
|
||||
"UPDATE issuingrules SET onshelfholds = 0 WHERE categorycode = ? AND itemtype= ? and branchcode = ?",
|
||||
undef,
|
||||
$rule->{categorycode}, $rule->{itemtype}, $rule->{branchcode}
|
||||
$issuing_rule->categorycode, $issuing_rule->itemtype, $issuing_rule->branchcode
|
||||
);
|
||||
ok( !C4::Reserves::OnShelfHoldsAllowed($item, $borrower), "OnShelfHoldsAllowed() disallowed" );
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue