View | Details | Raw Unified | Return to bug 14045
Collapse All | Expand All

(-)a/C4/Circulation.pm (-37 / +34 lines)
Lines 1569-1574 maxissueqty - maximum number of loans that a Link Here
1569
patron of the given category can have at the given
1569
patron of the given category can have at the given
1570
branch.  If the value is undef, no limit.
1570
branch.  If the value is undef, no limit.
1571
1571
1572
maxonsiteissueqty - maximum of on-site checkouts that a
1573
patron of the given category can have at the given
1574
branch.  If the value is undef, no limit.
1575
1572
This will first check for a specific branch and
1576
This will first check for a specific branch and
1573
category match from branch_borrower_circ_rules. 
1577
category match from branch_borrower_circ_rules. 
1574
1578
Lines 1582-1587 If no rule has been found in the database, it will default to Link Here
1582
the buillt in rule:
1586
the buillt in rule:
1583
1587
1584
maxissueqty - undef
1588
maxissueqty - undef
1589
maxonsiteissueqty - undef
1585
1590
1586
C<$branchcode> and C<$categorycode> should contain the
1591
C<$branchcode> and C<$categorycode> should contain the
1587
literal branch code and patron category code, respectively - no
1592
literal branch code and patron category code, respectively - no
Lines 1590-1642 wildcards. Link Here
1590
=cut
1595
=cut
1591
1596
1592
sub GetBranchBorrowerCircRule {
1597
sub GetBranchBorrowerCircRule {
1593
    my $branchcode = shift;
1598
    my ( $branchcode, $categorycode ) = @_;
1594
    my $categorycode = shift;
1595
1599
1596
    my $branch_cat_query = "SELECT maxissueqty
1600
    my $rules;
1597
                            FROM branch_borrower_circ_rules
1598
                            WHERE branchcode = ?
1599
                            AND   categorycode = ?";
1600
    my $dbh = C4::Context->dbh();
1601
    my $dbh = C4::Context->dbh();
1601
    my $sth = $dbh->prepare($branch_cat_query);
1602
    $rules = $dbh->selectrow_hashref( q|
1602
    $sth->execute($branchcode, $categorycode);
1603
        SELECT maxissueqty, maxonsiteissueqty
1603
    my $result;
1604
        FROM branch_borrower_circ_rules
1604
    if ($result = $sth->fetchrow_hashref()) {
1605
        WHERE branchcode = ?
1605
        return $result;
1606
        AND   categorycode = ?
1606
    }
1607
    |, {}, $branchcode, $categorycode ) ;
1608
    return $rules if $rules;
1607
1609
1608
    # try same branch, default borrower category
1610
    # try same branch, default borrower category
1609
    my $branch_query = "SELECT maxissueqty
1611
    $rules = $dbh->selectrow_hashref( q|
1610
                        FROM default_branch_circ_rules
1612
        SELECT maxissueqty, maxonsiteissueqty
1611
                        WHERE branchcode = ?";
1613
        FROM default_branch_circ_rules
1612
    $sth = $dbh->prepare($branch_query);
1614
        WHERE branchcode = ?
1613
    $sth->execute($branchcode);
1615
    |, {}, $branchcode ) ;
1614
    if ($result = $sth->fetchrow_hashref()) {
1616
    return $rules if $rules;
1615
        return $result;
1616
    }
1617
1617
1618
    # try default branch, same borrower category
1618
    # try default branch, same borrower category
1619
    my $category_query = "SELECT maxissueqty
1619
    $rules = $dbh->selectrow_hashref( q|
1620
                          FROM default_borrower_circ_rules
1620
        SELECT maxissueqty, maxonsiteissueqty
1621
                          WHERE categorycode = ?";
1621
        FROM default_borrower_circ_rules
1622
    $sth = $dbh->prepare($category_query);
1622
        WHERE categorycode = ?
1623
    $sth->execute($categorycode);
1623
    |, {}, $categorycode ) ;
1624
    if ($result = $sth->fetchrow_hashref()) {
1624
    return $rules if $rules;
1625
        return $result;
1625
1626
    }
1627
  
1628
    # try default branch, default borrower category
1626
    # try default branch, default borrower category
1629
    my $default_query = "SELECT maxissueqty
1627
    $rules = $dbh->selectrow_hashref( q|
1630
                          FROM default_circ_rules";
1628
        SELECT maxissueqty, maxonsiteissueqty
1631
    $sth = $dbh->prepare($default_query);
1629
        FROM default_circ_rules
1632
    $sth->execute();
1630
    |, {} );
1633
    if ($result = $sth->fetchrow_hashref()) {
1631
    return $rules if $rules;
1634
        return $result;
1632
1635
    }
1636
    
1637
    # built-in default circulation rule
1633
    # built-in default circulation rule
1638
    return {
1634
    return {
1639
        maxissueqty => undef,
1635
        maxissueqty => undef,
1636
        maxonsiteissueqty => undef,
1640
    };
1637
    };
1641
}
1638
}
1642
1639
(-)a/t/db_dependent/Circulation_Branch.t (-20 / +36 lines)
Lines 7-14 use C4::Branch; Link Here
7
use C4::Circulation;
7
use C4::Circulation;
8
use C4::Items;
8
use C4::Items;
9
use C4::Context;
9
use C4::Context;
10
use Data::Dumper;
10
11
use Test::More tests => 13;
11
use Test::More tests => 14;
12
12
13
BEGIN {
13
BEGIN {
14
    use_ok('C4::Circulation');
14
    use_ok('C4::Circulation');
Lines 215-235 my $borrower_id1 = C4::Members::AddMember( Link Here
215
);
215
);
216
my $borrower_1 = C4::Members::GetMember(borrowernumber => $borrower_id1);
216
my $borrower_1 = C4::Members::GetMember(borrowernumber => $borrower_id1);
217
217
218
$query =
218
is_deeply(
219
"INSERT INTO branch_borrower_circ_rules (branchcode,categorycode,maxissueqty) VALUES( ?,?,?)";
219
    GetBranchBorrowerCircRule(),
220
    { maxissueqty => undef, maxonsiteissueqty => undef },
221
"Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined"
222
);
223
224
$query = q|
225
    INSERT INTO branch_borrower_circ_rules
226
    (branchcode, categorycode, maxissueqty, maxonsiteissueqty)
227
    VALUES( ?, ?, ?, ? )
228
|;
229
220
$dbh->do(
230
$dbh->do(
221
    $query, {},
231
    $query, {},
222
    $samplebranch1->{branchcode},
232
    $samplebranch1->{branchcode},
223
    $samplecat->{categorycode}, 5
233
    $samplecat->{categorycode}, 5, 6
224
);
234
);
225
235
226
$query =
236
$query = q|
227
"INSERT INTO default_circ_rules (singleton,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
237
    INSERT INTO default_branch_circ_rules
228
$dbh->do( $query, {}, 'singleton', 4, 3, 'homebranch' );
238
    (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
229
239
    VALUES( ?, ?, ?, ?, ? )
230
$query =
240
|;
231
"INSERT INTO default_branch_circ_rules (branchcode,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
241
$dbh->do( $query, {}, $samplebranch2->{branchcode},
232
$dbh->do( $query, {}, $samplebranch2->{branchcode}, 3, 1, 'holdingbranch' );
242
    3, 2, 1, 'holdingbranch' );
243
$query = q|
244
    INSERT INTO default_circ_rules
245
    (singleton, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
246
    VALUES( ?, ?, ?, ?, ? )
247
|;
248
$dbh->do( $query, {}, 'singleton', 4, 5, 3, 'homebranch' );
233
249
234
$query =
250
$query =
235
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
251
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
Lines 253-278 $sth->execute( Link Here
253
#Test GetBranchBorrowerCircRule
269
#Test GetBranchBorrowerCircRule
254
is_deeply(
270
is_deeply(
255
    GetBranchBorrowerCircRule(),
271
    GetBranchBorrowerCircRule(),
256
    { maxissueqty => 4 },
272
    { maxissueqty => 4, maxonsiteissueqty => 5 },
257
"Without parameter, GetBranchBorrower returns the maxissueqty of default_circ_rules"
273
"Without parameter, GetBranchBorrower returns the maxissueqty and maxonsiteissueqty of default_circ_rules"
258
);
274
);
259
is_deeply(
275
is_deeply(
260
    GetBranchBorrowerCircRule( $samplebranch2->{branchcode} ),
276
    GetBranchBorrowerCircRule( $samplebranch2->{branchcode} ),
261
    { maxissueqty => 3 },
277
    { maxissueqty => 3, maxonsiteissueqty => 2 },
262
"Without only the branchcode specified, GetBranchBorrower returns the maxissueqty corresponding"
278
"Without only the branchcode specified, GetBranchBorrower returns the maxissueqty and maxonsiteissueqty corresponding"
263
);
279
);
264
is_deeply(
280
is_deeply(
265
    GetBranchBorrowerCircRule(
281
    GetBranchBorrowerCircRule(
266
        $samplebranch1->{branchcode},
282
        $samplebranch1->{branchcode},
267
        $samplecat->{categorycode}
283
        $samplecat->{categorycode}
268
    ),
284
    ),
269
    { maxissueqty => 5 },
285
    { maxissueqty => 5, maxonsiteissueqty => 6 },
270
    "GetBranchBorrower returns the maxissueqty of the branch1 and the category1"
286
    "GetBranchBorrower returns the maxissueqty and maxonsiteissueqty of the branch1 and the category1"
271
);
287
);
272
is_deeply(
288
is_deeply(
273
    GetBranchBorrowerCircRule( -1, -1 ),
289
    GetBranchBorrowerCircRule( -1, -1 ),
274
    { maxissueqty => 4 },
290
    { maxissueqty => 4, maxonsiteissueqty => 5 },
275
"GetBranchBorrower  with wrong parameters returns tthe maxissueqty of default_circ_rules"
291
"GetBranchBorrower with wrong parameters returns the maxissueqty and maxonsiteissueqty of default_circ_rules"
276
);
292
);
277
293
278
#Test GetBranchItemRule
294
#Test GetBranchItemRule
(-)a/t/db_dependent/Circulation_Issuingrule.t (-2 / +8 lines)
Lines 113-118 my $sampleissuingrule1 = { Link Here
113
    restrictedtype     => 0,
113
    restrictedtype     => 0,
114
    accountsent        => 0,
114
    accountsent        => 0,
115
    maxissueqty        => 5,
115
    maxissueqty        => 5,
116
    maxonsiteissueqty  => 4,
116
    finedays           => 0,
117
    finedays           => 0,
117
    lengthunit         => 'Null',
118
    lengthunit         => 'Null',
118
    renewalperiod      => 5,
119
    renewalperiod      => 5,
Lines 140-145 my $sampleissuingrule2 = { Link Here
140
    categorycode       => $samplecat->{categorycode},
141
    categorycode       => $samplecat->{categorycode},
141
    itemtype           => 'BOOK',
142
    itemtype           => 'BOOK',
142
    maxissueqty        => 2,
143
    maxissueqty        => 2,
144
    maxonsiteissueqty  => 1,
143
    renewalsallowed    => 'Null',
145
    renewalsallowed    => 'Null',
144
    renewalperiod      => 2,
146
    renewalperiod      => 2,
145
    norenewalbefore    => 7,
147
    norenewalbefore    => 7,
Lines 168-173 my $sampleissuingrule3 = { Link Here
168
    categorycode       => $samplecat->{categorycode},
170
    categorycode       => $samplecat->{categorycode},
169
    itemtype           => 'DVD',
171
    itemtype           => 'DVD',
170
    maxissueqty        => 3,
172
    maxissueqty        => 3,
173
    maxonsiteissueqty  => 2,
171
    renewalsallowed    => 'Null',
174
    renewalsallowed    => 'Null',
172
    renewalperiod      => 3,
175
    renewalperiod      => 3,
173
    norenewalbefore    => 8,
176
    norenewalbefore    => 8,
Lines 196-201 $query = 'INSERT INTO issuingrules ( Link Here
196
                categorycode,
199
                categorycode,
197
                itemtype,
200
                itemtype,
198
                maxissueqty,
201
                maxissueqty,
202
                maxonsiteissueqty,
199
                renewalsallowed,
203
                renewalsallowed,
200
                renewalperiod,
204
                renewalperiod,
201
                norenewalbefore,
205
                norenewalbefore,
Lines 216-228 $query = 'INSERT INTO issuingrules ( Link Here
216
                chargename,
220
                chargename,
217
                restrictedtype,
221
                restrictedtype,
218
                maxsuspensiondays
222
                maxsuspensiondays
219
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
223
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
220
my $sth = $dbh->prepare($query);
224
my $sth = $dbh->prepare($query);
221
$sth->execute(
225
$sth->execute(
222
    $sampleissuingrule1->{branchcode},
226
    $sampleissuingrule1->{branchcode},
223
    $sampleissuingrule1->{categorycode},
227
    $sampleissuingrule1->{categorycode},
224
    $sampleissuingrule1->{itemtype},
228
    $sampleissuingrule1->{itemtype},
225
    $sampleissuingrule1->{maxissueqty},
229
    $sampleissuingrule1->{maxissueqty},
230
    $sampleissuingrule1->{maxonsiteissueqty},
226
    $sampleissuingrule1->{renewalsallowed},
231
    $sampleissuingrule1->{renewalsallowed},
227
    $sampleissuingrule1->{renewalperiod},
232
    $sampleissuingrule1->{renewalperiod},
228
    $sampleissuingrule1->{norenewalbefore},
233
    $sampleissuingrule1->{norenewalbefore},
Lines 249-254 $sth->execute( Link Here
249
    $sampleissuingrule2->{categorycode},
254
    $sampleissuingrule2->{categorycode},
250
    $sampleissuingrule2->{itemtype},
255
    $sampleissuingrule2->{itemtype},
251
    $sampleissuingrule2->{maxissueqty},
256
    $sampleissuingrule2->{maxissueqty},
257
    $sampleissuingrule2->{maxonsiteissueqty},
252
    $sampleissuingrule2->{renewalsallowed},
258
    $sampleissuingrule2->{renewalsallowed},
253
    $sampleissuingrule2->{renewalperiod},
259
    $sampleissuingrule2->{renewalperiod},
254
    $sampleissuingrule2->{norenewalbefore},
260
    $sampleissuingrule2->{norenewalbefore},
Lines 275-280 $sth->execute( Link Here
275
    $sampleissuingrule3->{categorycode},
281
    $sampleissuingrule3->{categorycode},
276
    $sampleissuingrule3->{itemtype},
282
    $sampleissuingrule3->{itemtype},
277
    $sampleissuingrule3->{maxissueqty},
283
    $sampleissuingrule3->{maxissueqty},
284
    $sampleissuingrule3->{maxonsiteissueqty},
278
    $sampleissuingrule3->{renewalsallowed},
285
    $sampleissuingrule3->{renewalsallowed},
279
    $sampleissuingrule3->{renewalperiod},
286
    $sampleissuingrule3->{renewalperiod},
280
    $sampleissuingrule3->{norenewalbefore},
287
    $sampleissuingrule3->{norenewalbefore},
281
- 

Return to bug 14045