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>
use Koha::AuthorisedValues;
use Koha::DateUtils;
use Koha::Calendar;
+use Koha::IssuingRules;
use Koha::Items;
use Koha::Patrons;
use Koha::Patron::Debarments;
&GetItemIssue
&GetItemIssues
&GetIssuingCharges
- &GetIssuingRule
&GetBranchBorrowerCircRule
&GetBranchItemRule
&GetBiblioIssues
# 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
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
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
$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 = ? ";
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 ) {
# 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.
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);
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) {
# 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
# 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
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');
}
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 ) {
}
}
- 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' );
}
$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 );
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' );
}
or return;
my $branchcode = _GetCircControlBranch( $item, $borrower );
- my $issuingrule =
- GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
-
- my $now = dt_from_string;
+ my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrower->{categorycode}, itemtype => $item->{itype}, branchcode => $branchcode });
- 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;
use Koha::DateUtils;
use Koha::Account::Line;
use Koha::Account::Lines;
+use Koha::IssuingRules;
use Koha::Libraries;
use vars qw(@ISA @EXPORT);
&GetIssuesIteminfo
);
- # &GetIssuingRules - delete.
- # use C4::Circulation::GetIssuingRule instead.
-
# subs to move to Biblio.pm
push @EXPORT, qw(
&GetItems
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.
}
use Koha::Old::Hold;
use Koha::Holds;
use Koha::Libraries;
+use Koha::IssuingRules;
use Koha::Items;
use Koha::ItemTypes;
use Koha::Patrons;
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
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
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
package Koha::IssuingRules;
# Copyright Vaara-kirjastot 2015
+# Copyright Koha Development Team 2016
#
# This file is part of Koha.
#
# 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
=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
return 'Issuingrule';
}
-=head3 object_class
-
-=cut
-
sub object_class {
return 'Koha::IssuingRule';
}
-1;
\ No newline at end of file
+1;
use Koha::Database;
use C4::Context;
-use C4::Circulation qw(GetIssuingRule);
+use Koha::IssuingRules;
use Koha::Item::Transfer;
use Koha::Patrons;
use Koha::Libraries;
: 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
AddReturn
GetBranchBorrowerCircRule
GetBranchItemRule
- GetIssuingRule
)
);
use C4::Context;
use DateTime;
use Koha::DateUtils;
+use Koha::IssuingRules;
use Koha::Library;
use Test::More tests => 10;
'C4::Circulation',
qw(
GetHardDueDate
- GetIssuingRule
GetLoanLength
)
);
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},
opacitemholds => 'Y',
cap_fine_to_replacement_price => 0,
holds_per_record => 1,
+ article_requests => 'yes',
};
my $sampleissuingrule3 = {
branchcode => $samplebranch1->{branchcode},
opacitemholds => 'F',
cap_fine_to_replacement_price => 0,
holds_per_record => 1,
+ article_requests => 'yes',
};
$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},
$sampleissuingrule1->{onshelfholds},
$sampleissuingrule1->{opacitemholds},
$sampleissuingrule1->{cap_fine_to_replacement_price},
+ $sampleissuingrule1->{article_requests},
);
$sth->execute(
$sampleissuingrule2->{branchcode},
$sampleissuingrule2->{onshelfholds},
$sampleissuingrule2->{opacitemholds},
$sampleissuingrule2->{cap_fine_to_replacement_price},
+ $sampleissuingrule2->{article_requests},
);
$sth->execute(
$sampleissuingrule3->{branchcode},
$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"
);
use MARC::Record;
use MARC::Field;
-use Test::MockModule;
use C4::Context;
use C4::Biblio qw( AddBiblio );
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',
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 );
AddReturn
GetBiblioIssues
GetIssuingCharges
- GetIssuingRule
GetItemIssue
GetItemIssues
GetOpenIssue
@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);
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" );