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

(-)a/C4/Circulation.pm (-37 / +34 lines)
Lines 1564-1569 maxissueqty - maximum number of loans that a Link Here
1564
patron of the given category can have at the given
1564
patron of the given category can have at the given
1565
branch.  If the value is undef, no limit.
1565
branch.  If the value is undef, no limit.
1566
1566
1567
maxonsiteissueqty - maximum of on-site checkouts that a
1568
patron of the given category can have at the given
1569
branch.  If the value is undef, no limit.
1570
1567
This will first check for a specific branch and
1571
This will first check for a specific branch and
1568
category match from branch_borrower_circ_rules. 
1572
category match from branch_borrower_circ_rules. 
1569
1573
Lines 1577-1582 If no rule has been found in the database, it will default to Link Here
1577
the buillt in rule:
1581
the buillt in rule:
1578
1582
1579
maxissueqty - undef
1583
maxissueqty - undef
1584
maxonsiteissueqty - undef
1580
1585
1581
C<$branchcode> and C<$categorycode> should contain the
1586
C<$branchcode> and C<$categorycode> should contain the
1582
literal branch code and patron category code, respectively - no
1587
literal branch code and patron category code, respectively - no
Lines 1585-1637 wildcards. Link Here
1585
=cut
1590
=cut
1586
1591
1587
sub GetBranchBorrowerCircRule {
1592
sub GetBranchBorrowerCircRule {
1588
    my $branchcode = shift;
1593
    my ( $branchcode, $categorycode ) = @_;
1589
    my $categorycode = shift;
1590
1594
1591
    my $branch_cat_query = "SELECT maxissueqty
1595
    my $rules;
1592
                            FROM branch_borrower_circ_rules
1593
                            WHERE branchcode = ?
1594
                            AND   categorycode = ?";
1595
    my $dbh = C4::Context->dbh();
1596
    my $dbh = C4::Context->dbh();
1596
    my $sth = $dbh->prepare($branch_cat_query);
1597
    $rules = $dbh->selectrow_hashref( q|
1597
    $sth->execute($branchcode, $categorycode);
1598
        SELECT maxissueqty, maxonsiteissueqty
1598
    my $result;
1599
        FROM branch_borrower_circ_rules
1599
    if ($result = $sth->fetchrow_hashref()) {
1600
        WHERE branchcode = ?
1600
        return $result;
1601
        AND   categorycode = ?
1601
    }
1602
    |, {}, $branchcode, $categorycode ) ;
1603
    return $rules if $rules;
1602
1604
1603
    # try same branch, default borrower category
1605
    # try same branch, default borrower category
1604
    my $branch_query = "SELECT maxissueqty
1606
    $rules = $dbh->selectrow_hashref( q|
1605
                        FROM default_branch_circ_rules
1607
        SELECT maxissueqty, maxonsiteissueqty
1606
                        WHERE branchcode = ?";
1608
        FROM default_branch_circ_rules
1607
    $sth = $dbh->prepare($branch_query);
1609
        WHERE branchcode = ?
1608
    $sth->execute($branchcode);
1610
    |, {}, $branchcode ) ;
1609
    if ($result = $sth->fetchrow_hashref()) {
1611
    return $rules if $rules;
1610
        return $result;
1611
    }
1612
1612
1613
    # try default branch, same borrower category
1613
    # try default branch, same borrower category
1614
    my $category_query = "SELECT maxissueqty
1614
    $rules = $dbh->selectrow_hashref( q|
1615
                          FROM default_borrower_circ_rules
1615
        SELECT maxissueqty, maxonsiteissueqty
1616
                          WHERE categorycode = ?";
1616
        FROM default_borrower_circ_rules
1617
    $sth = $dbh->prepare($category_query);
1617
        WHERE categorycode = ?
1618
    $sth->execute($categorycode);
1618
    |, {}, $categorycode ) ;
1619
    if ($result = $sth->fetchrow_hashref()) {
1619
    return $rules if $rules;
1620
        return $result;
1620
1621
    }
1622
  
1623
    # try default branch, default borrower category
1621
    # try default branch, default borrower category
1624
    my $default_query = "SELECT maxissueqty
1622
    $rules = $dbh->selectrow_hashref( q|
1625
                          FROM default_circ_rules";
1623
        SELECT maxissueqty, maxonsiteissueqty
1626
    $sth = $dbh->prepare($default_query);
1624
        FROM default_circ_rules
1627
    $sth->execute();
1625
    |, {} );
1628
    if ($result = $sth->fetchrow_hashref()) {
1626
    return $rules if $rules;
1629
        return $result;
1627
1630
    }
1631
    
1632
    # built-in default circulation rule
1628
    # built-in default circulation rule
1633
    return {
1629
    return {
1634
        maxissueqty => undef,
1630
        maxissueqty => undef,
1631
        maxonsiteissueqty => undef,
1635
    };
1632
    };
1636
}
1633
}
1637
1634
(-)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