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

(-)a/C4/Circulation.pm (-37 / +34 lines)
Lines 1573-1578 maxissueqty - maximum number of loans that a Link Here
1573
patron of the given category can have at the given
1573
patron of the given category can have at the given
1574
branch.  If the value is undef, no limit.
1574
branch.  If the value is undef, no limit.
1575
1575
1576
maxonsiteissueqty - maximum of on-site checkouts that a
1577
patron of the given category can have at the given
1578
branch.  If the value is undef, no limit.
1579
1576
This will first check for a specific branch and
1580
This will first check for a specific branch and
1577
category match from branch_borrower_circ_rules. 
1581
category match from branch_borrower_circ_rules. 
1578
1582
Lines 1586-1591 If no rule has been found in the database, it will default to Link Here
1586
the buillt in rule:
1590
the buillt in rule:
1587
1591
1588
maxissueqty - undef
1592
maxissueqty - undef
1593
maxonsiteissueqty - undef
1589
1594
1590
C<$branchcode> and C<$categorycode> should contain the
1595
C<$branchcode> and C<$categorycode> should contain the
1591
literal branch code and patron category code, respectively - no
1596
literal branch code and patron category code, respectively - no
Lines 1594-1646 wildcards. Link Here
1594
=cut
1599
=cut
1595
1600
1596
sub GetBranchBorrowerCircRule {
1601
sub GetBranchBorrowerCircRule {
1597
    my $branchcode = shift;
1602
    my ( $branchcode, $categorycode ) = @_;
1598
    my $categorycode = shift;
1599
1603
1600
    my $branch_cat_query = "SELECT maxissueqty
1604
    my $rules;
1601
                            FROM branch_borrower_circ_rules
1602
                            WHERE branchcode = ?
1603
                            AND   categorycode = ?";
1604
    my $dbh = C4::Context->dbh();
1605
    my $dbh = C4::Context->dbh();
1605
    my $sth = $dbh->prepare($branch_cat_query);
1606
    $rules = $dbh->selectrow_hashref( q|
1606
    $sth->execute($branchcode, $categorycode);
1607
        SELECT maxissueqty, maxonsiteissueqty
1607
    my $result;
1608
        FROM branch_borrower_circ_rules
1608
    if ($result = $sth->fetchrow_hashref()) {
1609
        WHERE branchcode = ?
1609
        return $result;
1610
        AND   categorycode = ?
1610
    }
1611
    |, {}, $branchcode, $categorycode ) ;
1612
    return $rules if $rules;
1611
1613
1612
    # try same branch, default borrower category
1614
    # try same branch, default borrower category
1613
    my $branch_query = "SELECT maxissueqty
1615
    $rules = $dbh->selectrow_hashref( q|
1614
                        FROM default_branch_circ_rules
1616
        SELECT maxissueqty, maxonsiteissueqty
1615
                        WHERE branchcode = ?";
1617
        FROM default_branch_circ_rules
1616
    $sth = $dbh->prepare($branch_query);
1618
        WHERE branchcode = ?
1617
    $sth->execute($branchcode);
1619
    |, {}, $branchcode ) ;
1618
    if ($result = $sth->fetchrow_hashref()) {
1620
    return $rules if $rules;
1619
        return $result;
1620
    }
1621
1621
1622
    # try default branch, same borrower category
1622
    # try default branch, same borrower category
1623
    my $category_query = "SELECT maxissueqty
1623
    $rules = $dbh->selectrow_hashref( q|
1624
                          FROM default_borrower_circ_rules
1624
        SELECT maxissueqty, maxonsiteissueqty
1625
                          WHERE categorycode = ?";
1625
        FROM default_borrower_circ_rules
1626
    $sth = $dbh->prepare($category_query);
1626
        WHERE categorycode = ?
1627
    $sth->execute($categorycode);
1627
    |, {}, $categorycode ) ;
1628
    if ($result = $sth->fetchrow_hashref()) {
1628
    return $rules if $rules;
1629
        return $result;
1629
1630
    }
1631
  
1632
    # try default branch, default borrower category
1630
    # try default branch, default borrower category
1633
    my $default_query = "SELECT maxissueqty
1631
    $rules = $dbh->selectrow_hashref( q|
1634
                          FROM default_circ_rules";
1632
        SELECT maxissueqty, maxonsiteissueqty
1635
    $sth = $dbh->prepare($default_query);
1633
        FROM default_circ_rules
1636
    $sth->execute();
1634
    |, {} );
1637
    if ($result = $sth->fetchrow_hashref()) {
1635
    return $rules if $rules;
1638
        return $result;
1636
1639
    }
1640
    
1641
    # built-in default circulation rule
1637
    # built-in default circulation rule
1642
    return {
1638
    return {
1643
        maxissueqty => undef,
1639
        maxissueqty => undef,
1640
        maxonsiteissueqty => undef,
1644
    };
1641
    };
1645
}
1642
}
1646
1643
(-)a/t/db_dependent/Circulation_Branch.t (-19 / +34 lines)
Lines 8-14 use C4::Circulation; Link Here
8
use C4::Items;
8
use C4::Items;
9
use C4::Context;
9
use C4::Context;
10
10
11
use Test::More tests => 10;
11
use Test::More tests => 11;
12
12
13
BEGIN {
13
BEGIN {
14
    use_ok('C4::Circulation');
14
    use_ok('C4::Circulation');
Lines 160-179 $sth->execute( Link Here
160
    $sampleitemtype2->{imageurl},     $sampleitemtype2->{summary}
160
    $sampleitemtype2->{imageurl},     $sampleitemtype2->{summary}
161
);
161
);
162
162
163
$query =
163
is_deeply(
164
"INSERT INTO branch_borrower_circ_rules (branchcode,categorycode,maxissueqty) VALUES( ?,?,?)";
164
    GetBranchBorrowerCircRule(),
165
    { maxissueqty => undef, maxonsiteissueqty => undef },
166
"Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined"
167
);
168
169
$query = q|
170
    INSERT INTO branch_borrower_circ_rules
171
    (branchcode, categorycode, maxissueqty, maxonsiteissueqty)
172
    VALUES( ?, ?, ?, ?)
173
|;
165
$dbh->do(
174
$dbh->do(
166
    $query, {},
175
    $query, {},
167
    $samplebranch1->{branchcode},
176
    $samplebranch1->{branchcode},
168
    $samplecat->{categorycode}, 5
177
    $samplecat->{categorycode}, 5, 6
169
);
178
);
170
$query =
179
$query = q|
171
"INSERT INTO default_branch_circ_rules (branchcode,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
180
    INSERT INTO default_branch_circ_rules
181
    (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
182
    VALUES( ?, ?, ?, ?, ?)
183
|;
172
$dbh->do( $query, {}, $samplebranch2->{branchcode},
184
$dbh->do( $query, {}, $samplebranch2->{branchcode},
173
    3, 1, $samplebranch2->{branchcode} );
185
    3, 2, 1, $samplebranch2->{branchcode} );
174
$query =
186
$query = q|
175
"INSERT INTO default_circ_rules (singleton,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
187
    INSERT INTO default_circ_rules
176
$dbh->do( $query, {}, 'singleton', 4, 3, $samplebranch1->{branchcode} );
188
    (singleton, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
189
    VALUES( ?, ?, ?, ?, ? )
190
|;
191
$dbh->do( $query, {}, 'singleton', 4, 5, 3, $samplebranch1->{branchcode} );
177
192
178
$query =
193
$query =
179
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
194
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
Lines 192-217 $sth->execute( Link Here
192
#Test GetBranchBorrowerCircRule
207
#Test GetBranchBorrowerCircRule
193
is_deeply(
208
is_deeply(
194
    GetBranchBorrowerCircRule(),
209
    GetBranchBorrowerCircRule(),
195
    { maxissueqty => 4 },
210
    { maxissueqty => 4, maxonsiteissueqty => 5 },
196
"Without parameter, GetBranchBorrower returns the maxissueqty of default_circ_rules"
211
"Without parameter, GetBranchBorrower returns the maxissueqty and maxonsiteissueqty of default_circ_rules"
197
);
212
);
198
is_deeply(
213
is_deeply(
199
    GetBranchBorrowerCircRule( $samplebranch2->{branchcode} ),
214
    GetBranchBorrowerCircRule( $samplebranch2->{branchcode} ),
200
    { maxissueqty => 3 },
215
    { maxissueqty => 3, maxonsiteissueqty => 2 },
201
"Without only the branchcode specified, GetBranchBorrower returns the maxissueqty corresponding"
216
"Without only the branchcode specified, GetBranchBorrower returns the maxissueqty and maxonsiteissueqty corresponding"
202
);
217
);
203
is_deeply(
218
is_deeply(
204
    GetBranchBorrowerCircRule(
219
    GetBranchBorrowerCircRule(
205
        $samplebranch1->{branchcode},
220
        $samplebranch1->{branchcode},
206
        $samplecat->{categorycode}
221
        $samplecat->{categorycode}
207
    ),
222
    ),
208
    { maxissueqty => 5 },
223
    { maxissueqty => 5, maxonsiteissueqty => 6 },
209
    "GetBranchBorrower returns the maxissueqty of the branch1 and the category1"
224
    "GetBranchBorrower returns the maxissueqty and maxonsiteissueqty of the branch1 and the category1"
210
);
225
);
211
is_deeply(
226
is_deeply(
212
    GetBranchBorrowerCircRule( -1, -1 ),
227
    GetBranchBorrowerCircRule( -1, -1 ),
213
    { maxissueqty => 4 },
228
    { maxissueqty => 4, maxonsiteissueqty => 5 },
214
"GetBranchBorrower  with wrong parameters returns tthe maxissueqty of default_circ_rules"
229
"GetBranchBorrower with wrong parameters returns the maxissueqty and maxonsiteissueqty of default_circ_rules"
215
);
230
);
216
231
217
#Test GetBranchItemRule
232
#Test GetBranchItemRule
Lines 236-242 is_deeply( Link Here
236
is_deeply(
251
is_deeply(
237
    GetBranchItemRule( -1, -1 ),
252
    GetBranchItemRule( -1, -1 ),
238
    { returnbranch => $samplebranch1->{branchcode}, holdallowed => 3 },
253
    { returnbranch => $samplebranch1->{branchcode}, holdallowed => 3 },
239
    "With only one parametern GetBranchItemRule returns default values"
254
    "With only one parameter GetBranchItemRule returns default values"
240
);
255
);
241
256
242
$dbh->rollback;
257
$dbh->rollback;
(-)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