# given branch, patron category, and item type, determine
# applicable issuing rule
- my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
- { categorycode => $cat_borrower,
+ my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule(
+ {
+ categorycode => $cat_borrower,
+ itemtype => $type,
+ branchcode => $branch,
+ rule_name => 'maxissueqty',
+ }
+ );
+ my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule(
+ {
+ categorycode => $cat_borrower,
itemtype => $type,
- branchcode => $branch
+ branchcode => $branch,
+ rule_name => 'maxonsiteissueqty',
}
);
# 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($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) {
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 = $maxissueqty_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, $maxissueqty_rule->branchcode;
+ push @bind_params, $maxissueqty_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 = $maxissueqty_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 = $maxissueqty_rule ? $maxissueqty_rule->rule_value : 0;
+ my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : 0;
if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) {
# Now count total loans against the limit for the branch
my $branch_borrower_circ_rule = GetBranchBorrowerCircRule($branch, $cat_borrower);
- if (defined($branch_borrower_circ_rule->{maxissueqty})) {
+ if (defined($branch_borrower_circ_rule->{patron_maxissueqty}) and $branch_borrower_circ_rule->{patron_maxissueqty} ne '') {
my @bind_params = ();
my $branch_count_query = q|
SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
push @bind_params, $branch;
}
my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $branch_count_query, {}, @bind_params );
- my $max_checkouts_allowed = $branch_borrower_circ_rule->{maxissueqty};
- my $max_onsite_checkouts_allowed = $branch_borrower_circ_rule->{maxonsiteissueqty};
+ my $max_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxissueqty};
+ my $max_onsite_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxonsiteissueqty};
- if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
+ if ( $onsite_checkout and $max_onsite_checkouts_allowed ne '' ) {
if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) {
return {
reason => 'TOO_MANY_ONSITE_CHECKOUTS',
}
}
- if ( not defined( $issuing_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) {
+ if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{patron_maxissueqty}) ) {
return { reason => 'NO_RULE_DEFINED', max_allowed => 0 };
}
auto_renew => $auto_renew ? 1 : 0,
};
- $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } );
+ $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
if ($issue) {
$issue->set($issue_attributes)->store;
}
branch and patron category, regardless of item type.
The return value is a hashref containing the following key:
-maxissueqty - maximum number of loans that a
+patron_maxissueqty - maximum number of loans that a
patron of the given category can have at the given
branch. If the value is undef, no limit.
-maxonsiteissueqty - maximum of on-site checkouts that a
+patron_maxonsiteissueqty - maximum of on-site checkouts that a
patron of the given category can have at the given
branch. If the value is undef, no limit.
-This will first check for a specific branch and
-category match from branch_borrower_circ_rules.
-
-If no rule is found, it will then check default_branch_circ_rules
-(same branch, default category). If no rule is found,
-it will then check default_borrower_circ_rules (default
-branch, same category), then failing that, default_circ_rules
-(default branch, default category).
+This will check for different branch/category combinations in the following order:
+branch and category
+branch only
+category only
+default branch and category
If no rule has been found in the database, it will default to
the buillt in rule:
-maxissueqty - undef
-maxonsiteissueqty - undef
+patron_maxissueqty - undef
+patron_maxonsiteissueqty - undef
C<$branchcode> and C<$categorycode> should contain the
literal branch code and patron category code, respectively - no
sub GetBranchBorrowerCircRule {
my ( $branchcode, $categorycode ) = @_;
- my $rules;
- my $dbh = C4::Context->dbh();
- $rules = $dbh->selectrow_hashref( q|
- SELECT maxissueqty, maxonsiteissueqty
- FROM branch_borrower_circ_rules
- WHERE branchcode = ?
- AND categorycode = ?
- |, {}, $branchcode, $categorycode ) ;
- return $rules if $rules;
-
- # try same branch, default borrower category
- $rules = $dbh->selectrow_hashref( q|
- SELECT maxissueqty, maxonsiteissueqty
- FROM default_branch_circ_rules
- WHERE branchcode = ?
- |, {}, $branchcode ) ;
- return $rules if $rules;
-
- # try default branch, same borrower category
- $rules = $dbh->selectrow_hashref( q|
- SELECT maxissueqty, maxonsiteissueqty
- FROM default_borrower_circ_rules
- WHERE categorycode = ?
- |, {}, $categorycode ) ;
- return $rules if $rules;
-
- # try default branch, default borrower category
- $rules = $dbh->selectrow_hashref( q|
- SELECT maxissueqty, maxonsiteissueqty
- FROM default_circ_rules
- |, {} );
- return $rules if $rules;
-
- # built-in default circulation rule
- return {
- maxissueqty => undef,
- maxonsiteissueqty => undef,
+ # Initialize default values
+ my $rules = {
+ patron_maxissueqty => undef,
+ patron_maxonsiteissueqty => undef,
};
+
+ # Search for rules!
+ foreach my $rule_name (qw( patron_maxissueqty patron_maxonsiteissueqty )) {
+ my $rule = Koha::CirculationRules->get_effective_rule(
+ {
+ categorycode => $categorycode,
+ itemtype => undef,
+ branchcode => $branchcode,
+ rule_name => $rule_name,
+ }
+ );
+
+ $rules->{$rule_name} = $rule->rule_value if defined $rule;
+ }
+
+ return $rules;
}
=head2 GetBranchItemRule
branchcode => $branchcode,
description => 'Renewal of Rental Item '
. $biblio->title
- . " $item->barcode",
+ . " " . $item->barcode,
}
)->store();
}
# FIXME What if checkout does not exist?
- my $nextaccntno = C4::Accounts::getnextacctno( $checkout->borrowernumber );
-
- my $manager_id = 0;
- $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
-
- my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
-
- my $accountline = Koha::Account::Line->new(
+ my $account = Koha::Account->new({ patron_id => $checkout->borrowernumber });
+ my $accountline = $account->add_debit(
{
- borrowernumber => $checkout->borrowernumber,
- itemnumber => $checkout->itemnumber,
- issue_id => $checkout->issue_id,
- accountno => $nextaccntno,
- amount => $charge,
- amountoutstanding => $charge,
- manager_id => $manager_id,
- branchcode => $branchcode,
- description => 'Rental',
- accounttype => 'Rent',
- date => \'NOW()',
+ amount => $charge,
+ description => 'Rental',
+ note => undef,
+ user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
+ library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
+ type => 'rent',
+ item_id => $checkout->itemnumber,
+ issue_id => $checkout->issue_id,
}
- )->store();
-
- Koha::Account::Offset->new(
- {
- debit_id => $accountline->id,
- type => 'Rental Fee',
- amount => $charge,
- }
- )->store();
+ );
}
=head2 GetTransfers