Bug 14045: Make GetBranchBorrowerCircRule return maxonsiteissueqty
GetBranchBorrowerCircRule should return the value for maxissueqty and maxonsiteissueqty. It's what this patch does. Signed-off-by: Nicolas Legrand <nicolas.legrand@bulac.fr> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
eda4070f2b
commit
f1a1eb05df
|
|
@ -1569,6 +1569,10 @@ 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 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.
|
||||
|
||||
|
|
@ -1582,6 +1586,7 @@ If no rule has been found in the database, it will default to
|
|||
the buillt in rule:
|
||||
|
||||
maxissueqty - undef
|
||||
maxonsiteissueqty - undef
|
||||
|
||||
C<$branchcode> and C<$categorycode> should contain the
|
||||
literal branch code and patron category code, respectively - no
|
||||
|
|
@ -1590,53 +1595,45 @@ wildcards.
|
|||
=cut
|
||||
|
||||
sub GetBranchBorrowerCircRule {
|
||||
my $branchcode = shift;
|
||||
my $categorycode = shift;
|
||||
my ( $branchcode, $categorycode ) = @_;
|
||||
|
||||
my $branch_cat_query = "SELECT maxissueqty
|
||||
FROM branch_borrower_circ_rules
|
||||
WHERE branchcode = ?
|
||||
AND categorycode = ?";
|
||||
my $rules;
|
||||
my $dbh = C4::Context->dbh();
|
||||
my $sth = $dbh->prepare($branch_cat_query);
|
||||
$sth->execute($branchcode, $categorycode);
|
||||
my $result;
|
||||
if ($result = $sth->fetchrow_hashref()) {
|
||||
return $result;
|
||||
}
|
||||
$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
|
||||
my $branch_query = "SELECT maxissueqty
|
||||
FROM default_branch_circ_rules
|
||||
WHERE branchcode = ?";
|
||||
$sth = $dbh->prepare($branch_query);
|
||||
$sth->execute($branchcode);
|
||||
if ($result = $sth->fetchrow_hashref()) {
|
||||
return $result;
|
||||
}
|
||||
$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
|
||||
my $category_query = "SELECT maxissueqty
|
||||
FROM default_borrower_circ_rules
|
||||
WHERE categorycode = ?";
|
||||
$sth = $dbh->prepare($category_query);
|
||||
$sth->execute($categorycode);
|
||||
if ($result = $sth->fetchrow_hashref()) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$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
|
||||
my $default_query = "SELECT maxissueqty
|
||||
FROM default_circ_rules";
|
||||
$sth = $dbh->prepare($default_query);
|
||||
$sth->execute();
|
||||
if ($result = $sth->fetchrow_hashref()) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ use C4::Branch;
|
|||
use C4::Circulation;
|
||||
use C4::Items;
|
||||
use C4::Context;
|
||||
use Data::Dumper;
|
||||
use Test::More tests => 13;
|
||||
|
||||
use Test::More tests => 14;
|
||||
|
||||
BEGIN {
|
||||
use_ok('C4::Circulation');
|
||||
|
|
@ -215,21 +215,37 @@ my $borrower_id1 = C4::Members::AddMember(
|
|||
);
|
||||
my $borrower_1 = C4::Members::GetMember(borrowernumber => $borrower_id1);
|
||||
|
||||
$query =
|
||||
"INSERT INTO branch_borrower_circ_rules (branchcode,categorycode,maxissueqty) VALUES( ?,?,?)";
|
||||
is_deeply(
|
||||
GetBranchBorrowerCircRule(),
|
||||
{ maxissueqty => undef, maxonsiteissueqty => undef },
|
||||
"Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined"
|
||||
);
|
||||
|
||||
$query = q|
|
||||
INSERT INTO branch_borrower_circ_rules
|
||||
(branchcode, categorycode, maxissueqty, maxonsiteissueqty)
|
||||
VALUES( ?, ?, ?, ? )
|
||||
|;
|
||||
|
||||
$dbh->do(
|
||||
$query, {},
|
||||
$samplebranch1->{branchcode},
|
||||
$samplecat->{categorycode}, 5
|
||||
$samplecat->{categorycode}, 5, 6
|
||||
);
|
||||
|
||||
$query =
|
||||
"INSERT INTO default_circ_rules (singleton,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
|
||||
$dbh->do( $query, {}, 'singleton', 4, 3, 'homebranch' );
|
||||
|
||||
$query =
|
||||
"INSERT INTO default_branch_circ_rules (branchcode,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
|
||||
$dbh->do( $query, {}, $samplebranch2->{branchcode}, 3, 1, 'holdingbranch' );
|
||||
$query = q|
|
||||
INSERT INTO default_branch_circ_rules
|
||||
(branchcode, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
|
||||
VALUES( ?, ?, ?, ?, ? )
|
||||
|;
|
||||
$dbh->do( $query, {}, $samplebranch2->{branchcode},
|
||||
3, 2, 1, 'holdingbranch' );
|
||||
$query = q|
|
||||
INSERT INTO default_circ_rules
|
||||
(singleton, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
|
||||
VALUES( ?, ?, ?, ?, ? )
|
||||
|;
|
||||
$dbh->do( $query, {}, 'singleton', 4, 5, 3, 'homebranch' );
|
||||
|
||||
$query =
|
||||
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
|
||||
|
|
@ -253,26 +269,26 @@ $sth->execute(
|
|||
#Test GetBranchBorrowerCircRule
|
||||
is_deeply(
|
||||
GetBranchBorrowerCircRule(),
|
||||
{ maxissueqty => 4 },
|
||||
"Without parameter, GetBranchBorrower returns the maxissueqty of default_circ_rules"
|
||||
{ maxissueqty => 4, maxonsiteissueqty => 5 },
|
||||
"Without parameter, GetBranchBorrower returns the maxissueqty and maxonsiteissueqty of default_circ_rules"
|
||||
);
|
||||
is_deeply(
|
||||
GetBranchBorrowerCircRule( $samplebranch2->{branchcode} ),
|
||||
{ maxissueqty => 3 },
|
||||
"Without only the branchcode specified, GetBranchBorrower returns the maxissueqty corresponding"
|
||||
{ maxissueqty => 3, maxonsiteissueqty => 2 },
|
||||
"Without only the branchcode specified, GetBranchBorrower returns the maxissueqty and maxonsiteissueqty corresponding"
|
||||
);
|
||||
is_deeply(
|
||||
GetBranchBorrowerCircRule(
|
||||
$samplebranch1->{branchcode},
|
||||
$samplecat->{categorycode}
|
||||
),
|
||||
{ maxissueqty => 5 },
|
||||
"GetBranchBorrower returns the maxissueqty of the branch1 and the category1"
|
||||
{ maxissueqty => 5, maxonsiteissueqty => 6 },
|
||||
"GetBranchBorrower returns the maxissueqty and maxonsiteissueqty of the branch1 and the category1"
|
||||
);
|
||||
is_deeply(
|
||||
GetBranchBorrowerCircRule( -1, -1 ),
|
||||
{ maxissueqty => 4 },
|
||||
"GetBranchBorrower with wrong parameters returns tthe maxissueqty of default_circ_rules"
|
||||
{ maxissueqty => 4, maxonsiteissueqty => 5 },
|
||||
"GetBranchBorrower with wrong parameters returns the maxissueqty and maxonsiteissueqty of default_circ_rules"
|
||||
);
|
||||
|
||||
#Test GetBranchItemRule
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@ my $sampleissuingrule1 = {
|
|||
restrictedtype => 0,
|
||||
accountsent => 0,
|
||||
maxissueqty => 5,
|
||||
maxonsiteissueqty => 4,
|
||||
finedays => 0,
|
||||
lengthunit => 'Null',
|
||||
renewalperiod => 5,
|
||||
|
|
@ -140,6 +141,7 @@ my $sampleissuingrule2 = {
|
|||
categorycode => $samplecat->{categorycode},
|
||||
itemtype => 'BOOK',
|
||||
maxissueqty => 2,
|
||||
maxonsiteissueqty => 1,
|
||||
renewalsallowed => 'Null',
|
||||
renewalperiod => 2,
|
||||
norenewalbefore => 7,
|
||||
|
|
@ -168,6 +170,7 @@ my $sampleissuingrule3 = {
|
|||
categorycode => $samplecat->{categorycode},
|
||||
itemtype => 'DVD',
|
||||
maxissueqty => 3,
|
||||
maxonsiteissueqty => 2,
|
||||
renewalsallowed => 'Null',
|
||||
renewalperiod => 3,
|
||||
norenewalbefore => 8,
|
||||
|
|
@ -196,6 +199,7 @@ $query = 'INSERT INTO issuingrules (
|
|||
categorycode,
|
||||
itemtype,
|
||||
maxissueqty,
|
||||
maxonsiteissueqty,
|
||||
renewalsallowed,
|
||||
renewalperiod,
|
||||
norenewalbefore,
|
||||
|
|
@ -216,13 +220,14 @@ $query = 'INSERT INTO issuingrules (
|
|||
chargename,
|
||||
restrictedtype,
|
||||
maxsuspensiondays
|
||||
) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
|
||||
) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
|
||||
my $sth = $dbh->prepare($query);
|
||||
$sth->execute(
|
||||
$sampleissuingrule1->{branchcode},
|
||||
$sampleissuingrule1->{categorycode},
|
||||
$sampleissuingrule1->{itemtype},
|
||||
$sampleissuingrule1->{maxissueqty},
|
||||
$sampleissuingrule1->{maxonsiteissueqty},
|
||||
$sampleissuingrule1->{renewalsallowed},
|
||||
$sampleissuingrule1->{renewalperiod},
|
||||
$sampleissuingrule1->{norenewalbefore},
|
||||
|
|
@ -249,6 +254,7 @@ $sth->execute(
|
|||
$sampleissuingrule2->{categorycode},
|
||||
$sampleissuingrule2->{itemtype},
|
||||
$sampleissuingrule2->{maxissueqty},
|
||||
$sampleissuingrule2->{maxonsiteissueqty},
|
||||
$sampleissuingrule2->{renewalsallowed},
|
||||
$sampleissuingrule2->{renewalperiod},
|
||||
$sampleissuingrule2->{norenewalbefore},
|
||||
|
|
@ -275,6 +281,7 @@ $sth->execute(
|
|||
$sampleissuingrule3->{categorycode},
|
||||
$sampleissuingrule3->{itemtype},
|
||||
$sampleissuingrule3->{maxissueqty},
|
||||
$sampleissuingrule3->{maxonsiteissueqty},
|
||||
$sampleissuingrule3->{renewalsallowed},
|
||||
$sampleissuingrule3->{renewalperiod},
|
||||
$sampleissuingrule3->{norenewalbefore},
|
||||
|
|
|
|||
Loading…
Reference in New Issue