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.
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
=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,
};
}
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');
);
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( ?,?,?,?)";
#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
restrictedtype => 0,
accountsent => 0,
maxissueqty => 5,
+ maxonsiteissueqty => 4,
finedays => 0,
lengthunit => 'Null',
renewalperiod => 5,
categorycode => $samplecat->{categorycode},
itemtype => 'BOOK',
maxissueqty => 2,
+ maxonsiteissueqty => 1,
renewalsallowed => 'Null',
renewalperiod => 2,
norenewalbefore => 7,
categorycode => $samplecat->{categorycode},
itemtype => 'DVD',
maxissueqty => 3,
+ maxonsiteissueqty => 2,
renewalsallowed => 'Null',
renewalperiod => 3,
norenewalbefore => 8,
categorycode,
itemtype,
maxissueqty,
+ maxonsiteissueqty,
renewalsallowed,
renewalperiod,
norenewalbefore,
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},
$sampleissuingrule2->{categorycode},
$sampleissuingrule2->{itemtype},
$sampleissuingrule2->{maxissueqty},
+ $sampleissuingrule2->{maxonsiteissueqty},
$sampleissuingrule2->{renewalsallowed},
$sampleissuingrule2->{renewalperiod},
$sampleissuingrule2->{norenewalbefore},
$sampleissuingrule3->{categorycode},
$sampleissuingrule3->{itemtype},
$sampleissuingrule3->{maxissueqty},
+ $sampleissuingrule3->{maxonsiteissueqty},
$sampleissuingrule3->{renewalsallowed},
$sampleissuingrule3->{renewalperiod},
$sampleissuingrule3->{norenewalbefore},