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

(-)a/C4/Circulation.pm (-54 / +71 lines)
Lines 397-406 sub TooMany { Link Here
397
 
397
 
398
    # given branch, patron category, and item type, determine
398
    # given branch, patron category, and item type, determine
399
    # applicable issuing rule
399
    # applicable issuing rule
400
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
400
    my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule(
401
        {   categorycode => $cat_borrower,
401
        {
402
            categorycode => $cat_borrower,
403
            itemtype     => $type,
404
            branchcode   => $branch,
405
            rule_name    => 'maxissueqty',
406
        }
407
    );
408
    my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule(
409
        {
410
            categorycode => $cat_borrower,
402
            itemtype     => $type,
411
            itemtype     => $type,
403
            branchcode   => $branch
412
            branchcode   => $branch,
413
            rule_name    => 'maxonsiteissueqty',
404
        }
414
        }
405
    );
415
    );
406
416
Lines 408-414 sub TooMany { Link Here
408
    # if a rule is found and has a loan limit set, count
418
    # if a rule is found and has a loan limit set, count
409
    # how many loans the patron already has that meet that
419
    # how many loans the patron already has that meet that
410
    # rule
420
    # rule
411
    if (defined($issuing_rule) and defined($issuing_rule->maxissueqty)) {
421
    if (defined($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) {
412
        my @bind_params;
422
        my @bind_params;
413
        my $count_query = q|
423
        my $count_query = q|
414
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
424
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
Lines 416-422 sub TooMany { Link Here
416
            JOIN items USING (itemnumber)
426
            JOIN items USING (itemnumber)
417
        |;
427
        |;
418
428
419
        my $rule_itemtype = $issuing_rule->itemtype;
429
        my $rule_itemtype = $maxissueqty_rule->itemtype;
420
        if ($rule_itemtype eq "*") {
430
        if ($rule_itemtype eq "*") {
421
            # matching rule has the default item type, so count only
431
            # matching rule has the default item type, so count only
422
            # those existing loans that don't fall under a more
432
            # those existing loans that don't fall under a more
Lines 437-444 sub TooMany { Link Here
437
                                    AND   itemtype <> '*'
447
                                    AND   itemtype <> '*'
438
                                  ) ";
448
                                  ) ";
439
            }
449
            }
440
            push @bind_params, $issuing_rule->branchcode;
450
            push @bind_params, $maxissueqty_rule->branchcode;
441
            push @bind_params, $issuing_rule->categorycode;
451
            push @bind_params, $maxissueqty_rule->categorycode;
442
            push @bind_params, $cat_borrower;
452
            push @bind_params, $cat_borrower;
443
        } else {
453
        } else {
444
            # rule has specific item type, so count loans of that
454
            # rule has specific item type, so count loans of that
Lines 454-460 sub TooMany { Link Here
454
464
455
        $count_query .= " AND borrowernumber = ? ";
465
        $count_query .= " AND borrowernumber = ? ";
456
        push @bind_params, $borrower->{'borrowernumber'};
466
        push @bind_params, $borrower->{'borrowernumber'};
457
        my $rule_branch = $issuing_rule->branchcode;
467
        my $rule_branch = $maxissueqty_rule->branchcode;
458
        if ($rule_branch ne "*") {
468
        if ($rule_branch ne "*") {
459
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
469
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
460
                $count_query .= " AND issues.branchcode = ? ";
470
                $count_query .= " AND issues.branchcode = ? ";
Lines 469-476 sub TooMany { Link Here
469
479
470
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
480
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
471
481
472
        my $max_checkouts_allowed = $issuing_rule->maxissueqty;
482
        my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : 0;
473
        my $max_onsite_checkouts_allowed = $issuing_rule->maxonsiteissueqty;
483
        my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : 0;
474
484
475
        if ( $onsite_checkout ) {
485
        if ( $onsite_checkout ) {
476
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
486
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
Lines 555-561 sub TooMany { Link Here
555
        }
565
        }
556
    }
566
    }
557
567
558
    if ( not defined( $issuing_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) {
568
    if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) {
559
        return { reason => 'NO_RULE_DEFINED', max_allowed => 0 };
569
        return { reason => 'NO_RULE_DEFINED', max_allowed => 0 };
560
    }
570
    }
561
571
Lines 1579-1592 maxonsiteissueqty - maximum of on-site checkouts that a Link Here
1579
patron of the given category can have at the given
1589
patron of the given category can have at the given
1580
branch.  If the value is undef, no limit.
1590
branch.  If the value is undef, no limit.
1581
1591
1582
This will first check for a specific branch and
1592
This will check for different branch/category combinations in the following order:
1583
category match from branch_borrower_circ_rules. 
1593
branch and category
1584
1594
branch only
1585
If no rule is found, it will then check default_branch_circ_rules
1595
category only
1586
(same branch, default category).  If no rule is found,
1596
default branch and category
1587
it will then check default_borrower_circ_rules (default 
1588
branch, same category), then failing that, default_circ_rules
1589
(default branch, default category).
1590
1597
1591
If no rule has been found in the database, it will default to
1598
If no rule has been found in the database, it will default to
1592
the buillt in rule:
1599
the buillt in rule:
Lines 1603-1646 wildcards. Link Here
1603
sub GetBranchBorrowerCircRule {
1610
sub GetBranchBorrowerCircRule {
1604
    my ( $branchcode, $categorycode ) = @_;
1611
    my ( $branchcode, $categorycode ) = @_;
1605
1612
1606
    my $rules;
1613
    # Set search prededences
1607
    my $dbh = C4::Context->dbh();
1614
    my @params = (
1608
    $rules = $dbh->selectrow_hashref( q|
1615
        {
1609
        SELECT maxissueqty, maxonsiteissueqty
1616
            branchcode   => $branchcode,
1610
        FROM branch_borrower_circ_rules
1617
            categorycode => $categorycode,
1611
        WHERE branchcode = ?
1618
            itemtype     => undef,
1612
        AND   categorycode = ?
1619
        },
1613
    |, {}, $branchcode, $categorycode ) ;
1620
        {
1614
    return $rules if $rules;
1621
            branchcode   => $branchcode,
1615
1622
            categorycode => undef,
1616
    # try same branch, default borrower category
1623
            itemtype     => undef,
1617
    $rules = $dbh->selectrow_hashref( q|
1624
        },
1618
        SELECT maxissueqty, maxonsiteissueqty
1625
        {
1619
        FROM default_branch_circ_rules
1626
            branchcode   => undef,
1620
        WHERE branchcode = ?
1627
            categorycode => $categorycode,
1621
    |, {}, $branchcode ) ;
1628
            itemtype     => undef,
1622
    return $rules if $rules;
1629
        },
1623
1630
        {
1624
    # try default branch, same borrower category
1631
            branchcode   => undef,
1625
    $rules = $dbh->selectrow_hashref( q|
1632
            categorycode => undef,
1626
        SELECT maxissueqty, maxonsiteissueqty
1633
            itemtype     => undef,
1627
        FROM default_borrower_circ_rules
1634
        },
1628
        WHERE categorycode = ?
1635
    );
1629
    |, {}, $categorycode ) ;
1630
    return $rules if $rules;
1631
1632
    # try default branch, default borrower category
1633
    $rules = $dbh->selectrow_hashref( q|
1634
        SELECT maxissueqty, maxonsiteissueqty
1635
        FROM default_circ_rules
1636
    |, {} );
1637
    return $rules if $rules;
1638
1636
1639
    # built-in default circulation rule
1637
    # Initialize default values
1640
    return {
1638
    my $rules = {
1641
        maxissueqty => undef,
1639
        maxissueqty       => undef,
1642
        maxonsiteissueqty => undef,
1640
        maxonsiteissueqty => undef,
1643
    };
1641
    };
1642
1643
    # Search for rules!
1644
    foreach my $rule_name (qw( maxissueqty maxonsiteissueqty )) {
1645
        foreach my $params (@params) {
1646
            my $rule = Koha::CirculationRules->search(
1647
                {
1648
                    rule_name => $rule_name,
1649
                    %$params,
1650
                }
1651
            )->next();
1652
1653
            if ( $rule ) {
1654
                $rules->{$rule_name} = $rule->rule_value;
1655
                last;
1656
            }
1657
        }
1658
    }
1659
1660
    return $rules;
1644
}
1661
}
1645
1662
1646
=head2 GetBranchItemRule
1663
=head2 GetBranchItemRule
(-)a/Koha/CirculationRules.pm (-5 / +8 lines)
Lines 136-159 sub set_rule { Link Here
136
136
137
sub set_rules {
137
sub set_rules {
138
    my ( $self, $params ) = @_;
138
    my ( $self, $params ) = @_;
139
    warn Data::Dumper::Dumper( $params );
140
139
141
    my $branchcode   = $params->{branchcode};
140
    my $branchcode   = $params->{branchcode};
142
    my $categorycode = $params->{categorycode};
141
    my $categorycode = $params->{categorycode};
143
    my $itemtype     = $params->{itemtype};
142
    my $itemtype     = $params->{itemtype};
144
    my $rules        = $params->{rules};
143
    my $rules        = $params->{rules};
145
144
146
    foreach my $rule (@$rules) {
145
    my $rule_objects = [];
147
        Koha::CirculationRules->set_rule(
146
    while ( my ( $rule_name, $rule_value ) = each %$rules ) {
147
        my $rule_object = Koha::CirculationRules->set_rule(
148
            {
148
            {
149
                branchcode   => $branchcode,
149
                branchcode   => $branchcode,
150
                categorycode => $categorycode,
150
                categorycode => $categorycode,
151
                itemtype     => $itemtype,
151
                itemtype     => $itemtype,
152
                rule_name    => $rule->{rule_name},
152
                rule_name    => $rule_name,
153
                rule_value   => $rule->{rule_value},
153
                rule_value   => $rule_value,
154
            }
154
            }
155
        );
155
        );
156
        push( @$rule_objects, $rule_object );
156
    }
157
    }
158
159
    return $rule_objects;
157
}
160
}
158
161
159
=head3 type
162
=head3 type
(-)a/admin/smart-rules.pl (-161 / +87 lines)
Lines 80-107 elsif ($op eq 'delete-branch-cat') { Link Here
80
        if ($categorycode eq "*") {
80
        if ($categorycode eq "*") {
81
            my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
81
            my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
82
            $sth_delete->execute();
82
            $sth_delete->execute();
83
        } else {
84
            my $sth_delete = $dbh->prepare("DELETE FROM default_borrower_circ_rules
85
                                            WHERE categorycode = ?");
86
            $sth_delete->execute($categorycode);
87
        }
83
        }
88
    } elsif ($categorycode eq "*") {
84
    } elsif ($categorycode eq "*") {
89
        my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
85
        my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
90
                                        WHERE branchcode = ?");
86
                                        WHERE branchcode = ?");
91
        $sth_delete->execute($branch);
87
        $sth_delete->execute($branch);
92
    } else {
93
        my $sth_delete = $dbh->prepare("DELETE FROM branch_borrower_circ_rules
94
                                        WHERE branchcode = ?
95
                                        AND categorycode = ?");
96
        $sth_delete->execute($branch, $categorycode);
97
    }
88
    }
98
    Koha::CirculationRules->set_rule(
89
    Koha::CirculationRules->set_rules(
99
        {
90
        {
100
            branchcode   => $branch,
91
            categorycode => $categorycode eq '*' ? undef : $categorycode,
101
            categorycode => $categorycode,
92
            branchcode   => $branch eq '*'       ? undef : $branch,
102
            itemtype     => undef,
93
            itemtype     => undef,
103
            rule_name    => 'max_holds',
94
            rules        => {
104
            rule_value   => undef,
95
                max_holds         => undef,
96
                maxissueqty       => undef,
97
                maxonsiteissueqty => undef,
98
            }
105
        }
99
        }
106
    );
100
    );
107
}
101
}
Lines 182-189 elsif ($op eq 'add') { Link Here
182
        firstremind                   => $firstremind,
176
        firstremind                   => $firstremind,
183
        chargeperiod                  => $chargeperiod,
177
        chargeperiod                  => $chargeperiod,
184
        chargeperiod_charge_at        => $chargeperiod_charge_at,
178
        chargeperiod_charge_at        => $chargeperiod_charge_at,
185
        maxissueqty                   => $maxissueqty,
186
        maxonsiteissueqty             => $maxonsiteissueqty,
187
        renewalsallowed               => $renewalsallowed,
179
        renewalsallowed               => $renewalsallowed,
188
        renewalperiod                 => $renewalperiod,
180
        renewalperiod                 => $renewalperiod,
189
        norenewalbefore               => $norenewalbefore,
181
        norenewalbefore               => $norenewalbefore,
Lines 211-216 elsif ($op eq 'add') { Link Here
211
        Koha::IssuingRule->new()->set($params)->store();
203
        Koha::IssuingRule->new()->set($params)->store();
212
    }
204
    }
213
205
206
    Koha::CirculationRules->set_rules(
207
        {
208
            categorycode => $bor,
209
            itemtype     => $itemtype,
210
            branchcode   => $br,
211
            rules        => {
212
                maxissueqty       => $maxissueqty,
213
                maxonsiteissueqty => $maxonsiteissueqty,
214
            }
215
        }
216
    );
217
214
}
218
}
215
elsif ($op eq "set-branch-defaults") {
219
elsif ($op eq "set-branch-defaults") {
216
    my $categorycode  = $input->param('categorycode');
220
    my $categorycode  = $input->param('categorycode');
Lines 230-264 elsif ($op eq "set-branch-defaults") { Link Here
230
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
234
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
231
                                        FROM default_circ_rules");
235
                                        FROM default_circ_rules");
232
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
236
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
233
                                        (maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
237
                                        (holdallowed, hold_fulfillment_policy, returnbranch)
234
                                        VALUES (?, ?, ?, ?, ?)");
238
                                        VALUES (?, ?, ?)");
235
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
239
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
236
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
240
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
237
241
238
        $sth_search->execute();
242
        $sth_search->execute();
239
        my $res = $sth_search->fetchrow_hashref();
243
        my $res = $sth_search->fetchrow_hashref();
240
        if ($res->{total}) {
244
        if ($res->{total}) {
241
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
245
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
242
        } else {
246
        } else {
243
            $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
247
            $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
244
        }
248
        }
249
250
        Koha::CirculationRules->set_rules(
251
            {
252
                categorycode => undef,
253
                itemtype     => undef,
254
                branchcode   => undef,
255
                rules        => {
256
                    maxissueqty       => $maxissueqty,
257
                    maxonsiteissueqty => $maxonsiteissueqty,
258
                }
259
            }
260
        );
245
    } else {
261
    } else {
246
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
262
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
247
                                        FROM default_branch_circ_rules
263
                                        FROM default_branch_circ_rules
248
                                        WHERE branchcode = ?");
264
                                        WHERE branchcode = ?");
249
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
265
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
250
                                        (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
266
                                        (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
251
                                        VALUES (?, ?, ?, ?, ?, ?)");
267
                                        VALUES (?, ?, ?, ?)");
252
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
268
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
253
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
269
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
254
                                        WHERE branchcode = ?");
270
                                        WHERE branchcode = ?");
255
        $sth_search->execute($branch);
271
        $sth_search->execute($branch);
256
        my $res = $sth_search->fetchrow_hashref();
272
        my $res = $sth_search->fetchrow_hashref();
257
        if ($res->{total}) {
273
        if ($res->{total}) {
258
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
274
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
259
        } else {
275
        } else {
260
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
276
            $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch);
261
        }
277
        }
278
279
        Koha::CirculationRules->set_rules(
280
            {
281
                categorycode => undef,
282
                itemtype     => undef,
283
                branchcode   => $branch,
284
                rules        => {
285
                    maxissueqty       => $maxissueqty,
286
                    maxonsiteissueqty => $maxonsiteissueqty,
287
                }
288
            }
289
        );
262
    }
290
    }
263
}
291
}
264
elsif ($op eq "add-branch-cat") {
292
elsif ($op eq "add-branch-cat") {
Lines 275-398 elsif ($op eq "add-branch-cat") { Link Here
275
303
276
    if ($branch eq "*") {
304
    if ($branch eq "*") {
277
        if ($categorycode eq "*") {
305
        if ($categorycode eq "*") {
278
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
306
            Koha::CirculationRules->set_rules(
279
                                            FROM default_circ_rules");
280
            my $sth_insert = $dbh->prepare(q|
281
                INSERT INTO default_circ_rules
282
                    (maxissueqty, maxonsiteissueqty)
283
                    VALUES (?, ?, )
284
            |);
285
            my $sth_update = $dbh->prepare(q|
286
                UPDATE default_circ_rules
287
                SET maxissueqty = ?,
288
                    maxonsiteissueqty = ?
289
            |);
290
291
            $sth_search->execute();
292
            my $res = $sth_search->fetchrow_hashref();
293
            if ($res->{total}) {
294
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty );
295
            } else {
296
                $sth_insert->execute( $maxissueqty, $maxonsiteissueqty );
297
            }
298
299
            Koha::CirculationRules->set_rule(
300
                {
307
                {
301
                    branchcode   => undef,
302
                    categorycode => undef,
308
                    categorycode => undef,
303
                    itemtype     => undef,
309
                    itemtype     => undef,
304
                    rule_name    => 'max_holds',
310
                    branchcode   => undef,
305
                    rule_value   => $max_holds,
311
                    rules        => {
312
                        max_holds         => $max_holds,
313
                        maxissueqty       => $maxissueqty,
314
                        maxonsiteissueqty => $maxonsiteissueqty,
315
                    }
306
                }
316
                }
307
            );
317
            );
308
        } else {
318
        } else {
309
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
319
            Koha::CirculationRules->set_rules(
310
                                            FROM default_borrower_circ_rules
311
                                            WHERE categorycode = ?");
312
            my $sth_insert = $dbh->prepare(q|
313
                INSERT INTO default_borrower_circ_rules
314
                    (categorycode, maxissueqty, maxonsiteissueqty)
315
                    VALUES (?, ?, ?, ?)
316
            |);
317
            my $sth_update = $dbh->prepare(q|
318
                UPDATE default_borrower_circ_rules
319
                SET maxissueqty = ?,
320
                    maxonsiteissueqty = ?
321
                WHERE categorycode = ?
322
            |);
323
            $sth_search->execute($branch);
324
            my $res = $sth_search->fetchrow_hashref();
325
            if ($res->{total}) {
326
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode );
327
            } else {
328
                $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty );
329
            }
330
331
            Koha::CirculationRules->set_rule(
332
                {
320
                {
333
                    branchcode   => undef,
334
                    categorycode => $categorycode,
321
                    categorycode => $categorycode,
335
                    itemtype     => undef,
322
                    itemtype     => undef,
336
                    rule_name    => 'max_holds',
323
                    branchcode   => undef,
337
                    rule_value   => $max_holds,
324
                    rules        => {
325
                        max_holds         => $max_holds,
326
                        maxissueqty       => $maxissueqty,
327
                        maxonsiteissueqty => $maxonsiteissueqty,
328
                    }
338
                }
329
                }
339
            );
330
            );
340
        }
331
        }
341
    } elsif ($categorycode eq "*") {
332
    } elsif ($categorycode eq "*") {
342
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
333
        Koha::CirculationRules->set_rules(
343
                                        FROM default_branch_circ_rules
344
                                        WHERE branchcode = ?");
345
        my $sth_insert = $dbh->prepare(q|
346
            INSERT INTO default_branch_circ_rules
347
            (branchcode, maxissueqty, maxonsiteissueqty)
348
            VALUES (?, ?, ?)
349
        |);
350
        my $sth_update = $dbh->prepare(q|
351
            UPDATE default_branch_circ_rules
352
            SET maxissueqty = ?,
353
                maxonsiteissueqty = ?
354
            WHERE branchcode = ?
355
        |);
356
        $sth_search->execute($branch);
357
        my $res = $sth_search->fetchrow_hashref();
358
        if ($res->{total}) {
359
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch);
360
        } else {
361
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty);
362
        }
363
    } else {
364
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
365
                                        FROM branch_borrower_circ_rules
366
                                        WHERE branchcode = ?
367
                                        AND   categorycode = ?");
368
        my $sth_insert = $dbh->prepare(q|
369
            INSERT INTO branch_borrower_circ_rules
370
            (branchcode, categorycode, maxissueqty, maxonsiteissueqty)
371
            VALUES (?, ?, ?, ?)
372
        |);
373
        my $sth_update = $dbh->prepare(q|
374
            UPDATE branch_borrower_circ_rules
375
            SET maxissueqty = ?,
376
                maxonsiteissueqty = ?
377
            WHERE branchcode = ?
378
            AND categorycode = ?
379
        |);
380
381
        $sth_search->execute($branch, $categorycode);
382
        my $res = $sth_search->fetchrow_hashref();
383
        if ($res->{total}) {
384
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch, $categorycode);
385
        } else {
386
            $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty);
387
        }
388
389
        Koha::CirculationRules->set_rule(
390
            {
334
            {
335
                categorycode => undef,
336
                itemtype     => undef,
391
                branchcode   => $branch,
337
                branchcode   => $branch,
338
                rules        => {
339
                    max_holds         => $max_holds,
340
                    maxissueqty       => $maxissueqty,
341
                    maxonsiteissueqty => $maxonsiteissueqty,
342
                }
343
            }
344
        );
345
    } else {
346
        Koha::CirculationRules->set_rules(
347
            {
392
                categorycode => $categorycode,
348
                categorycode => $categorycode,
393
                itemtype     => undef,
349
                itemtype     => undef,
394
                rule_name    => 'max_holds',
350
                branchcode   => $branch,
395
                rule_value   => $max_holds,
351
                rules        => {
352
                    max_holds         => $max_holds,
353
                    maxissueqty       => $maxissueqty,
354
                    maxonsiteissueqty => $maxonsiteissueqty,
355
                }
396
            }
356
            }
397
        );
357
        );
398
    }
358
    }
Lines 560-598 while (my $row = $sth2->fetchrow_hashref) { Link Here
560
520
561
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
521
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
562
522
563
my $sth_branch_cat;
564
if ($branch eq "*") {
565
    $sth_branch_cat = $dbh->prepare("
566
        SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode
567
        FROM default_borrower_circ_rules
568
        JOIN categories USING (categorycode)
569
570
    ");
571
    $sth_branch_cat->execute();
572
} else {
573
    $sth_branch_cat = $dbh->prepare("
574
        SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode
575
        FROM branch_borrower_circ_rules
576
        JOIN categories USING (categorycode)
577
        WHERE branch_borrower_circ_rules.branchcode = ?
578
    ");
579
    $sth_branch_cat->execute($branch);
580
}
581
582
my @branch_cat_rules = ();
583
while (my $row = $sth_branch_cat->fetchrow_hashref) {
584
    push @branch_cat_rules, $row;
585
}
586
my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humancategorycode'} } @branch_cat_rules;
587
588
# note undef maxissueqty so that template can deal with them
589
foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) {
590
    $entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty});
591
    $entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty});
592
}
593
594
@sorted_row_loop = sort by_category_and_itemtype @row_loop;
595
596
my $sth_branch_item;
523
my $sth_branch_item;
597
if ($branch eq "*") {
524
if ($branch eq "*") {
598
    $sth_branch_item = $dbh->prepare("
525
    $sth_branch_item = $dbh->prepare("
Lines 633-639 foreach my $entry (@sorted_branch_item_rules) { Link Here
633
560
634
$template->param(show_branch_cat_rule_form => 1);
561
$template->param(show_branch_cat_rule_form => 1);
635
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules);
562
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules);
636
$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules);
637
563
638
my $sth_defaults;
564
my $sth_defaults;
639
if ($branch eq "*") {
565
if ($branch eq "*") {
(-)a/installer/data/mysql/atomicupdate/bug_18925.perl (+75 lines)
Line 0 Link Here
1
$DBversion = 'XXX';  # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    if ( column_exists( 'branch_borrower_circ_rules', 'maxissueqty' ) ) {
4
        $dbh->do("
5
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
6
            SELECT categorycode, branchcode, NULL, 'maxissueqty', maxissueqty
7
            FROM branch_borrower_circ_rules
8
        ");
9
        $dbh->do("
10
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
11
            SELECT categorycode, branchcode, NULL, 'maxonsiteissueqty', maxonsiteissueqty
12
            FROM branch_borrower_circ_rules
13
        ");
14
        $dbh->do("DROP TABLE branch_borrower_circ_rules");
15
    }
16
17
    if ( column_exists( 'default_borrower_circ_rules', 'maxissueqty' ) ) {
18
        $dbh->do("
19
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
20
            SELECT categorycode, NULL, NULL, 'maxissueqty', maxissueqty
21
            FROM default_borrower_circ_rules
22
        ");
23
        $dbh->do("
24
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
25
            SELECT categorycode, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty
26
            FROM default_borrower_circ_rules
27
        ");
28
        $dbh->do("DROP TABLE default_borrower_circ_rules");
29
    }
30
31
    if ( column_exists( 'default_circ_rules', 'maxissueqty' ) ) {
32
        $dbh->do("
33
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
34
            SELECT NULL, NULL, NULL, 'maxissueqty', maxissueqty
35
            FROM default_circ_rules
36
        ");
37
        $dbh->do("
38
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
39
            SELECT NULL, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty
40
            FROM default_circ_rules
41
        ");
42
        $dbh->do("ALTER TABLE default_circ_rules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty");
43
    }
44
45
    if ( column_exists( 'default_branch_circ_rules', 'maxissueqty' ) ) {
46
        $dbh->do("
47
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
48
            SELECT NULL, branchcode, NULL, 'maxissueqty', maxissueqty
49
            FROM default_branch_circ_rules
50
        ");
51
        $dbh->do("
52
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
53
            SELECT NULL, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty
54
            FROM default_branch_circ_rules
55
        ");
56
        $dbh->do("ALTER TABLE default_branch_circ_rules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty");
57
    }
58
59
    if ( column_exists( 'issuingrules', 'maxissueqty' ) ) {
60
        $dbh->do("
61
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
62
            SELECT categorycode, branchcode, itemtype, 'maxissueqty', maxissueqty
63
            FROM issuingrules
64
        ");
65
        $dbh->do("
66
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
67
            SELECT categorycode, branchcode, itemtype, 'maxonsiteissueqty', maxonsiteissueqty
68
            FROM issuingrules
69
        ");
70
        $dbh->do("ALTER TABLE issuingrules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty");
71
    }
72
73
    SetVersion( $DBversion );
74
    print "Upgrade to $DBversion done (Bug 18925 - Move maxissueqty and maxonsiteissueqty to circulation_rules)\n";
75
}
(-)a/installer/data/mysql/kohastructure.sql (-37 lines)
Lines 368-412 CREATE TABLE collections_tracking ( Link Here
368
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
368
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
369
369
370
--
370
--
371
-- Table structure for table `branch_borrower_circ_rules`
372
--
373
374
DROP TABLE IF EXISTS `branch_borrower_circ_rules`;
375
CREATE TABLE `branch_borrower_circ_rules` ( -- includes default circulation rules for patron categories found under "Checkout limit by patron category"
376
  `branchcode` VARCHAR(10) NOT NULL, -- the branch this rule applies to (branches.branchcode)
377
  `categorycode` VARCHAR(10) NOT NULL, -- the patron category this rule applies to (categories.categorycode)
378
  `maxissueqty` int(4) default NULL, -- the maximum number of checkouts this patron category can have at this branch
379
  `maxonsiteissueqty` int(4) default NULL, -- the maximum number of on-site checkouts this patron category can have at this branch
380
  PRIMARY KEY (`categorycode`, `branchcode`),
381
  CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
382
    ON DELETE CASCADE ON UPDATE CASCADE,
383
  CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
384
    ON DELETE CASCADE ON UPDATE CASCADE
385
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
386
387
--
388
-- Table structure for table `default_borrower_circ_rules`
389
--
390
391
DROP TABLE IF EXISTS `default_borrower_circ_rules`;
392
CREATE TABLE `default_borrower_circ_rules` ( -- default checkout rules found under "Default checkout, hold and return policy"
393
  `categorycode` VARCHAR(10) NOT NULL, -- patron category this rul
394
  `maxissueqty` int(4) default NULL,
395
  `maxonsiteissueqty` int(4) default NULL,
396
  PRIMARY KEY (`categorycode`),
397
  CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
398
    ON DELETE CASCADE ON UPDATE CASCADE
399
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
400
401
--
402
-- Table structure for table `default_branch_circ_rules`
371
-- Table structure for table `default_branch_circ_rules`
403
--
372
--
404
373
405
DROP TABLE IF EXISTS `default_branch_circ_rules`;
374
DROP TABLE IF EXISTS `default_branch_circ_rules`;
406
CREATE TABLE `default_branch_circ_rules` (
375
CREATE TABLE `default_branch_circ_rules` (
407
  `branchcode` VARCHAR(10) NOT NULL,
376
  `branchcode` VARCHAR(10) NOT NULL,
408
  `maxissueqty` int(4) default NULL,
409
  `maxonsiteissueqty` int(4) default NULL,
410
  `holdallowed` tinyint(1) default NULL,
377
  `holdallowed` tinyint(1) default NULL,
411
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
378
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
412
  `returnbranch` varchar(15) default NULL,
379
  `returnbranch` varchar(15) default NULL,
Lines 422-429 CREATE TABLE `default_branch_circ_rules` ( Link Here
422
DROP TABLE IF EXISTS `default_circ_rules`;
389
DROP TABLE IF EXISTS `default_circ_rules`;
423
CREATE TABLE `default_circ_rules` (
390
CREATE TABLE `default_circ_rules` (
424
    `singleton` enum('singleton') NOT NULL default 'singleton',
391
    `singleton` enum('singleton') NOT NULL default 'singleton',
425
    `maxissueqty` int(4) default NULL,
426
    `maxonsiteissueqty` int(4) default NULL,
427
    `holdallowed` int(1) default NULL,
392
    `holdallowed` int(1) default NULL,
428
    hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
393
    hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
429
    `returnbranch` varchar(15) default NULL,
394
    `returnbranch` varchar(15) default NULL,
Lines 866-873 CREATE TABLE `issuingrules` ( -- circulation and fine rules Link Here
866
  `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period
831
  `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period
867
  `accountsent` int(11) default NULL, -- not used? always NULL
832
  `accountsent` int(11) default NULL, -- not used? always NULL
868
  `chargename` varchar(100) default NULL, -- not used? always NULL
833
  `chargename` varchar(100) default NULL, -- not used? always NULL
869
  `maxissueqty` int(4) default NULL, -- total number of checkouts allowed
870
  `maxonsiteissueqty` int(4) default NULL, -- total number of on-site checkouts allowed
871
  `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit
834
  `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit
872
  `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours)
835
  `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours)
873
  `hardduedate` date default NULL, -- hard due date
836
  `hardduedate` date default NULL, -- hard due date
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-28 / +51 lines)
Lines 1-5 Link Here
1
[% USE Branches %]
1
[% USE Branches %]
2
[% USE Categories %]
2
[% USE CirculationRules %]
3
[% USE CirculationRules %]
4
5
[% SET branchcode = humanbranch %]
6
7
[% SET categorycodes = ['*'] %]
8
[% FOREACH pc IN patron_categories %]
9
    [% categorycodes.push( pc.id ) %]
10
[% END %]
11
3
[% INCLUDE 'doc-head-open.inc' %]
12
[% INCLUDE 'doc-head-open.inc' %]
4
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
13
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
5
[% INCLUDE 'doc-head-close.inc' %]
14
[% INCLUDE 'doc-head-close.inc' %]
Lines 218-235 $(document).ready(function() { Link Here
218
                                                          <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype %]&amp;categorycode=[% rule.categorycode %]&amp;branch=[% rule.current_branch %]"><i class="fa fa-trash"></i> Delete</a>
227
                                                          <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype %]&amp;categorycode=[% rule.categorycode %]&amp;branch=[% rule.current_branch %]"><i class="fa fa-trash"></i> Delete</a>
219
                                                        </td>
228
                                                        </td>
220
229
221
							<td>[% IF ( rule.unlimited_maxissueqty ) %]
230
							<td>
222
									Unlimited
231
                                [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxissueqty' ) %]
223
								[% ELSE %]
232
                                [% IF rule_value  %]
224
									[% rule.maxissueqty %]
233
                                    [% rule_value %]
225
								[% END %]
234
                                [% ELSE %]
226
							</td>
227
                            <td>[% IF rule.unlimited_maxonsiteissueqty %]
228
                                    Unlimited
235
                                    Unlimited
236
                                [% END %]
237
							</td>
238
							<td>
239
                                [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxonsiteissueqty' ) %]
240
                                [% IF rule_value  %]
241
                                    [% rule_value %]
229
                                [% ELSE %]
242
                                [% ELSE %]
230
                                    [% rule.maxonsiteissueqty %]
243
                                    Unlimited
231
                                [% END %]
244
                                [% END %]
232
                            </td>
245
							</td>
233
							<td>[% rule.issuelength %]</td>
246
							<td>[% rule.issuelength %]</td>
234
							<td>
247
							<td>
235
							    [% rule.lengthunit %]
248
							    [% rule.lengthunit %]
Lines 459-466 $(document).ready(function() { Link Here
459
                </tr>
472
                </tr>
460
                <tr>
473
                <tr>
461
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
474
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
462
                    <td><input type="text" name="maxissueqty" size="3" value="[% default_maxissueqty %]"/></td>
475
                    <td>
463
                    <td><input type="text" name="maxonsiteissueqty" size="3" value="[% default_maxonsiteissueqty %]"/></td>
476
                        [% SET maxissueqty  = CirculationRules.Get( branchcode, undef, undef, 'maxissueqty' ) %]
477
                        <input type="text" name="maxissueqty" size="3" value="[% maxissueqty %]"/>
478
                    </td>
479
                    <td>
480
                        [% SET maxonsiteissueqty  = CirculationRules.Get( branchcode, undef, undef, 'maxonsiteissueqty' ) %]
481
                        <input type="text" name="maxonsiteissueqty" size="3" value="[% maxonsiteissueqty %]"/>
482
                    </td>
464
                    <td>
483
                    <td>
465
                        <select name="holdallowed">
484
                        <select name="holdallowed">
466
                            [% IF ( default_holdallowed_any ) %]
485
                            [% IF ( default_holdallowed_any ) %]
Lines 572-614 $(document).ready(function() { Link Here
572
                    <th>Maximum total holds allowed (count)</th>
591
                    <th>Maximum total holds allowed (count)</th>
573
                    <th>&nbsp;</th>
592
                    <th>&nbsp;</th>
574
                </tr>
593
                </tr>
575
                [% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %]
594
                [% FOREACH c IN categorycodes %]
576
                    [% UNLESS ( loop.odd ) %]
595
                    [% SET maxissueqty = CirculationRules.Get( branchcode, c, undef, 'maxissueqty' ) %]
577
                    <tr class="highlight">
596
                    [% SET maxonsiteissueqty = CirculationRules.Get( branchcode, c, undef, 'maxonsiteissueqty' ) %]
578
                    [% ELSE %]
597
                    [% SET max_holds = CirculationRules.Get( branchcode, c, undef, 'max_holds' ) %]
598
599
                    [% IF maxissueqty || maxissueqty || max_holds %]
579
                    <tr>
600
                    <tr>
580
                    [% END %]
601
                        <td>
581
                        <td>[% IF ( branch_cat_rule_loo.default_humancategorycode ) %]
602
                            [% IF c == '*'%]
582
                                <em>Default</em>
603
                                <em>Default</em>
583
                            [% ELSE %]
604
                            [% ELSE %]
584
                                [% branch_cat_rule_loo.humancategorycode %]
605
                                [% Categories.GetName(c) %]
585
                            [% END %]
606
                            [% END %]
586
                        </td>
607
                        </td>
587
                        <td>[% IF ( branch_cat_rule_loo.unlimited_maxissueqty ) %]
608
                        <td>
588
                                Unlimited
609
                            [% IF maxissueqty  %]
610
                                [% maxissueqty %]
589
                            [% ELSE %]
611
                            [% ELSE %]
590
                                [% branch_cat_rule_loo.maxissueqty %]
612
                                Unlimited
591
                            [% END %]
613
                            [% END %]
592
                        </td>
614
                        </td>
593
                        <td>[% IF ( branch_cat_rule_loo.unlimited_maxonsiteissueqty ) %]
615
                        <td>
594
                                Unlimited
616
                            [% IF maxonsiteissueqty  %]
617
                                [% maxonsiteissueqty %]
595
                            [% ELSE %]
618
                            [% ELSE %]
596
                                [% branch_cat_rule_loo.maxonsiteissueqty %]
619
                                Unlimited
597
                            [% END %]
620
                            [% END %]
598
                        </td>
621
                        </td>
599
                        <td>
622
                        <td>
600
                            [% SET rule_value = CirculationRules.Get( branch_cat_rule_loo.branchcode, branch_cat_rule_loo.categorycode, branch_cat_rule_loo.itemtype, 'max_holds' ) %]
623
                            [% IF max_holds  %]
601
                            [% IF rule_value  %]
624
                                [% max_holds %]
602
                                [% rule_value %]
603
                            [% ELSE %]
625
                            [% ELSE %]
604
                                Unlimited
626
                                Unlimited
605
                            [% END %]
627
                            [% END %]
606
                        </td>
628
                        </td>
607
629
608
                        <td class="actions">
630
                        <td class="actions">
609
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% branch_cat_rule_loo.categorycode %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
631
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% c %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
610
                        </td>
632
                        </td>
611
                    </tr>
633
                    </tr>
634
                    [% END %]
612
                [% END %]
635
                [% END %]
613
                <tr>
636
                <tr>
614
                    <td>
637
                    <td>
(-)a/t/db_dependent/Circulation.t (-7 / +19 lines)
Lines 36-41 use Koha::Database; Link Here
36
use Koha::IssuingRules;
36
use Koha::IssuingRules;
37
use Koha::Checkouts;
37
use Koha::Checkouts;
38
use Koha::Patrons;
38
use Koha::Patrons;
39
use Koha::CirculationRules;
39
use Koha::Subscriptions;
40
use Koha::Subscriptions;
40
41
41
my $schema = Koha::Database->schema;
42
my $schema = Koha::Database->schema;
Lines 168-181 is( Link Here
168
169
169
# Set a simple circ policy
170
# Set a simple circ policy
170
$dbh->do('DELETE FROM issuingrules');
171
$dbh->do('DELETE FROM issuingrules');
172
Koha::CirculationRules->search()->delete();
171
$dbh->do(
173
$dbh->do(
172
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed,
174
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed,
173
                                maxissueqty, issuelength, lengthunit,
175
                                issuelength, lengthunit,
174
                                renewalsallowed, renewalperiod,
176
                                renewalsallowed, renewalperiod,
175
                                norenewalbefore, auto_renew,
177
                                norenewalbefore, auto_renew,
176
                                fine, chargeperiod)
178
                                fine, chargeperiod)
177
      VALUES (?, ?, ?, ?,
179
      VALUES (?, ?, ?, ?,
178
              ?, ?, ?,
180
              ?, ?,
179
              ?, ?,
181
              ?, ?,
180
              ?, ?,
182
              ?, ?,
181
              ?, ?
183
              ?, ?
Lines 183-189 $dbh->do( Link Here
183
    },
185
    },
184
    {},
186
    {},
185
    '*', '*', '*', 25,
187
    '*', '*', '*', 25,
186
    20, 14, 'days',
188
    14, 'days',
187
    1, 7,
189
    1, 7,
188
    undef, 0,
190
    undef, 0,
189
    .10, 1
191
    .10, 1
Lines 960-977 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
960
    $dbh->do('DELETE FROM issues');
962
    $dbh->do('DELETE FROM issues');
961
    $dbh->do('DELETE FROM items');
963
    $dbh->do('DELETE FROM items');
962
    $dbh->do('DELETE FROM issuingrules');
964
    $dbh->do('DELETE FROM issuingrules');
965
	Koha::CirculationRules->search()->delete();
963
    $dbh->do(
966
    $dbh->do(
964
        q{
967
        q{
965
        INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, maxissueqty, issuelength, lengthunit, renewalsallowed, renewalperiod,
968
        INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, issuelength, lengthunit, renewalsallowed, renewalperiod,
966
                    norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
969
                    norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
967
        },
970
        },
968
        {},
971
        {},
969
        '*', '*', '*', 25,
972
        '*', '*', '*', 25,
970
        20,  14,  'days',
973
        14,  'days',
971
        1,   7,
974
        1,   7,
972
        undef,  0,
975
        undef,  0,
973
        .10, 1
976
        .10, 1
974
    );
977
    );
978
	Koha::CirculationRules->set_rules(
979
		{
980
			categorycode => '*',
981
			itemtype     => '*',
982
			branchcode   => '*',
983
			rules        => {
984
				maxissueqty => 20
985
			}
986
		}
987
	);
975
    my $biblio = MARC::Record->new();
988
    my $biblio = MARC::Record->new();
976
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
989
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
977
990
Lines 1568-1574 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1568
            categorycode => '*',
1581
            categorycode => '*',
1569
            itemtype     => '*',
1582
            itemtype     => '*',
1570
            branchcode   => '*',
1583
            branchcode   => '*',
1571
            maxissueqty  => 99,
1572
            issuelength  => 1,
1584
            issuelength  => 1,
1573
            firstremind  => 1,        # 1 day of grace
1585
            firstremind  => 1,        # 1 day of grace
1574
            finedays     => 2,        # 2 days of fine per day of overdue
1586
            finedays     => 2,        # 2 days of fine per day of overdue
(-)a/t/db_dependent/Circulation/Branch.t (-19 / +41 lines)
Lines 22-27 use C4::Members; Link Here
22
use C4::Circulation;
22
use C4::Circulation;
23
use C4::Items;
23
use C4::Items;
24
use C4::Context;
24
use C4::Context;
25
use Koha::CirculationRules;
25
26
26
use Test::More tests => 14;
27
use Test::More tests => 14;
27
use t::lib::Mocks;
28
use t::lib::Mocks;
Lines 52-58 $dbh->do(q|DELETE FROM categories|); Link Here
52
$dbh->do(q|DELETE FROM accountlines|);
53
$dbh->do(q|DELETE FROM accountlines|);
53
$dbh->do(q|DELETE FROM itemtypes|);
54
$dbh->do(q|DELETE FROM itemtypes|);
54
$dbh->do(q|DELETE FROM branch_item_rules|);
55
$dbh->do(q|DELETE FROM branch_item_rules|);
55
$dbh->do(q|DELETE FROM branch_borrower_circ_rules|);
56
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
56
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
57
$dbh->do(q|DELETE FROM default_circ_rules|);
57
$dbh->do(q|DELETE FROM default_circ_rules|);
58
$dbh->do(q|DELETE FROM default_branch_item_rules|);
58
$dbh->do(q|DELETE FROM default_branch_item_rules|);
Lines 151-181 is_deeply( Link Here
151
"Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined"
151
"Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined"
152
);
152
);
153
153
154
my $query = q|
154
Koha::CirculationRules->set_rules(
155
    INSERT INTO branch_borrower_circ_rules
155
    {
156
    (branchcode, categorycode, maxissueqty, maxonsiteissueqty)
156
        branchcode   => $samplebranch1->{branchcode},
157
    VALUES( ?, ?, ?, ? )
157
        categorycode => $samplecat->{categorycode},
158
|;
158
        itemtype     => undef,
159
159
        rules        => {
160
$dbh->do(
160
            maxissueqty       => 5,
161
    $query, {},
161
            maxonsiteissueqty => 6,
162
    $samplebranch1->{branchcode},
162
        }
163
    $samplecat->{categorycode}, 5, 6
163
    }
164
);
164
);
165
165
166
$query = q|
166
my $query = q|
167
    INSERT INTO default_branch_circ_rules
167
    INSERT INTO default_branch_circ_rules
168
    (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
168
    (branchcode, holdallowed, returnbranch)
169
    VALUES( ?, ?, ?, ?, ? )
169
    VALUES( ?, ?, ? )
170
|;
170
|;
171
$dbh->do( $query, {}, $samplebranch2->{branchcode},
171
$dbh->do( $query, {}, $samplebranch2->{branchcode}, 1, 'holdingbranch' );
172
    3, 2, 1, 'holdingbranch' );
172
Koha::CirculationRules->set_rules(
173
    {
174
        branchcode   => $samplebranch2->{branchcode},
175
        categorycode => undef,
176
        itemtype     => undef,
177
        rules        => {
178
            maxissueqty       => 3,
179
            maxonsiteissueqty => 2,
180
        }
181
    }
182
);
183
173
$query = q|
184
$query = q|
174
    INSERT INTO default_circ_rules
185
    INSERT INTO default_circ_rules
175
    (singleton, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
186
    (singleton, holdallowed, returnbranch)
176
    VALUES( ?, ?, ?, ?, ? )
187
    VALUES( ?, ?, ? )
177
|;
188
|;
178
$dbh->do( $query, {}, 'singleton', 4, 5, 3, 'homebranch' );
189
$dbh->do( $query, {}, 'singleton', 3, 'homebranch' );
190
Koha::CirculationRules->set_rules(
191
    {
192
        branchcode   => undef,
193
        categorycode => undef,
194
        itemtype     => undef,
195
        rules        => {
196
            maxissueqty       => 4,
197
            maxonsiteissueqty => 5,
198
        }
199
    }
200
);
179
201
180
$query =
202
$query =
181
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
203
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
(-)a/t/db_dependent/Circulation/GetHardDueDate.t (-15 / +1 lines)
Lines 117-124 my $sampleissuingrule1 = { Link Here
117
    chargename         => 'Null',
117
    chargename         => 'Null',
118
    restrictedtype     => 0,
118
    restrictedtype     => 0,
119
    accountsent        => 0,
119
    accountsent        => 0,
120
    maxissueqty        => 5,
121
    maxonsiteissueqty  => 4,
122
    finedays           => 0,
120
    finedays           => 0,
123
    lengthunit         => 'days',
121
    lengthunit         => 'days',
124
    renewalperiod      => 5,
122
    renewalperiod      => 5,
Lines 151-158 my $sampleissuingrule2 = { Link Here
151
    branchcode         => $samplebranch2->{branchcode},
149
    branchcode         => $samplebranch2->{branchcode},
152
    categorycode       => $samplecat->{categorycode},
150
    categorycode       => $samplecat->{categorycode},
153
    itemtype           => 'BOOK',
151
    itemtype           => 'BOOK',
154
    maxissueqty        => 2,
155
    maxonsiteissueqty  => 1,
156
    renewalsallowed    => 'Null',
152
    renewalsallowed    => 'Null',
157
    renewalperiod      => 2,
153
    renewalperiod      => 2,
158
    norenewalbefore    => 7,
154
    norenewalbefore    => 7,
Lines 184-191 my $sampleissuingrule3 = { Link Here
184
    branchcode         => $samplebranch1->{branchcode},
180
    branchcode         => $samplebranch1->{branchcode},
185
    categorycode       => $samplecat->{categorycode},
181
    categorycode       => $samplecat->{categorycode},
186
    itemtype           => 'DVD',
182
    itemtype           => 'DVD',
187
    maxissueqty        => 3,
188
    maxonsiteissueqty  => 2,
189
    renewalsallowed    => 'Null',
183
    renewalsallowed    => 'Null',
190
    renewalperiod      => 3,
184
    renewalperiod      => 3,
191
    norenewalbefore    => 8,
185
    norenewalbefore    => 8,
Lines 218-225 $query = 'INSERT INTO issuingrules ( Link Here
218
                branchcode,
212
                branchcode,
219
                categorycode,
213
                categorycode,
220
                itemtype,
214
                itemtype,
221
                maxissueqty,
222
                maxonsiteissueqty,
223
                renewalsallowed,
215
                renewalsallowed,
224
                renewalperiod,
216
                renewalperiod,
225
                norenewalbefore,
217
                norenewalbefore,
Lines 245-258 $query = 'INSERT INTO issuingrules ( Link Here
245
                opacitemholds,
237
                opacitemholds,
246
                cap_fine_to_replacement_price,
238
                cap_fine_to_replacement_price,
247
                article_requests
239
                article_requests
248
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
240
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
249
my $sth = $dbh->prepare($query);
241
my $sth = $dbh->prepare($query);
250
$sth->execute(
242
$sth->execute(
251
    $sampleissuingrule1->{branchcode},
243
    $sampleissuingrule1->{branchcode},
252
    $sampleissuingrule1->{categorycode},
244
    $sampleissuingrule1->{categorycode},
253
    $sampleissuingrule1->{itemtype},
245
    $sampleissuingrule1->{itemtype},
254
    $sampleissuingrule1->{maxissueqty},
255
    $sampleissuingrule1->{maxonsiteissueqty},
256
    $sampleissuingrule1->{renewalsallowed},
246
    $sampleissuingrule1->{renewalsallowed},
257
    $sampleissuingrule1->{renewalperiod},
247
    $sampleissuingrule1->{renewalperiod},
258
    $sampleissuingrule1->{norenewalbefore},
248
    $sampleissuingrule1->{norenewalbefore},
Lines 283-290 $sth->execute( Link Here
283
    $sampleissuingrule2->{branchcode},
273
    $sampleissuingrule2->{branchcode},
284
    $sampleissuingrule2->{categorycode},
274
    $sampleissuingrule2->{categorycode},
285
    $sampleissuingrule2->{itemtype},
275
    $sampleissuingrule2->{itemtype},
286
    $sampleissuingrule2->{maxissueqty},
287
    $sampleissuingrule2->{maxonsiteissueqty},
288
    $sampleissuingrule2->{renewalsallowed},
276
    $sampleissuingrule2->{renewalsallowed},
289
    $sampleissuingrule2->{renewalperiod},
277
    $sampleissuingrule2->{renewalperiod},
290
    $sampleissuingrule2->{norenewalbefore},
278
    $sampleissuingrule2->{norenewalbefore},
Lines 315-322 $sth->execute( Link Here
315
    $sampleissuingrule3->{branchcode},
303
    $sampleissuingrule3->{branchcode},
316
    $sampleissuingrule3->{categorycode},
304
    $sampleissuingrule3->{categorycode},
317
    $sampleissuingrule3->{itemtype},
305
    $sampleissuingrule3->{itemtype},
318
    $sampleissuingrule3->{maxissueqty},
319
    $sampleissuingrule3->{maxonsiteissueqty},
320
    $sampleissuingrule3->{renewalsallowed},
306
    $sampleissuingrule3->{renewalsallowed},
321
    $sampleissuingrule3->{renewalperiod},
307
    $sampleissuingrule3->{renewalperiod},
322
    $sampleissuingrule3->{norenewalbefore},
308
    $sampleissuingrule3->{norenewalbefore},
(-)a/t/db_dependent/Circulation/Returns.t (-1 lines)
Lines 54-60 my $rule = Koha::IssuingRule->new( Link Here
54
        categorycode => '*',
54
        categorycode => '*',
55
        itemtype     => '*',
55
        itemtype     => '*',
56
        branchcode   => '*',
56
        branchcode   => '*',
57
        maxissueqty  => 99,
58
        issuelength  => 1,
57
        issuelength  => 1,
59
    }
58
    }
60
);
59
);
(-)a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t (-13 / +25 lines)
Lines 27-32 use C4::Context; Link Here
27
use Koha::DateUtils qw( dt_from_string );
27
use Koha::DateUtils qw( dt_from_string );
28
use Koha::Database;
28
use Koha::Database;
29
use Koha::Checkouts;
29
use Koha::Checkouts;
30
use Koha::CirculationRules;
30
31
31
use t::lib::TestBuilder;
32
use t::lib::TestBuilder;
32
use t::lib::Mocks;
33
use t::lib::Mocks;
Lines 38-44 our $dbh = C4::Context->dbh; Link Here
38
39
39
$dbh->do(q|DELETE FROM branch_item_rules|);
40
$dbh->do(q|DELETE FROM branch_item_rules|);
40
$dbh->do(q|DELETE FROM issues|);
41
$dbh->do(q|DELETE FROM issues|);
41
$dbh->do(q|DELETE FROM branch_borrower_circ_rules|);
42
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
42
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
43
$dbh->do(q|DELETE FROM default_circ_rules|);
43
$dbh->do(q|DELETE FROM default_circ_rules|);
44
$dbh->do(q|DELETE FROM default_branch_item_rules|);
44
$dbh->do(q|DELETE FROM default_branch_item_rules|);
Lines 82-93 my $issuingrule = $builder->build({ Link Here
82
        branchcode         => $branch->{branchcode},
82
        branchcode         => $branch->{branchcode},
83
        categorycode       => '*',
83
        categorycode       => '*',
84
        itemtype           => '*',
84
        itemtype           => '*',
85
        maxissueqty        => 2,
86
        maxonsiteissueqty  => 1,
87
        lengthunit         => 'days',
85
        lengthunit         => 'days',
88
        issuelength        => 5,
86
        issuelength        => 5,
89
    },
87
    },
90
});
88
});
89
Koha::CirculationRules->search()->delete();
90
Koha::CirculationRules->set_rules(
91
    {
92
        branchcode   => $branch->{branchcode},
93
        categorycode => '*',
94
        itemtype     => '*',
95
        rules        => {
96
            maxissueqty       => 2,
97
            maxonsiteissueqty => 1,
98
        }
99
    }
100
);
91
101
92
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
102
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
93
C4::Context->set_userenv($patron->{borrowernumber}, $patron->{userid}, 'usercnum', 'First name', 'Surname', $branch->{branchcode}, 'My Library', 0);
103
C4::Context->set_userenv($patron->{borrowernumber}, $patron->{userid}, 'usercnum', 'First name', 'Surname', $branch->{branchcode}, 'My Library', 0);
Lines 145-160 my $yet_another_item = $builder->build({ Link Here
145
( $impossible, undef, undef, undef ) = C4::Circulation::CanBookBeIssued( $patron, $yet_another_item->{barcode} );
155
( $impossible, undef, undef, undef ) = C4::Circulation::CanBookBeIssued( $patron, $yet_another_item->{barcode} );
146
is( $impossible->{TOO_MANY}, 'TOO_MANY_CHECKOUTS', 'Not a specific case, $delta should not be incremented' );
156
is( $impossible->{TOO_MANY}, 'TOO_MANY_CHECKOUTS', 'Not a specific case, $delta should not be incremented' );
147
157
148
$dbh->do(q|DELETE FROM issuingrules|);
158
Koha::CirculationRules->search()->delete();
149
my $borrower_circ_rule = $builder->build({
159
Koha::CirculationRules->set_rules(
150
    source => 'DefaultCircRule',
160
    {
151
    value => {
161
        branchcode   => $branch->{branchcode},
152
        branchcode         => $branch->{branchcode},
162
        categorycode => '*',
153
        categorycode       => '*',
163
        itemtype     => '*',
154
        maxissueqty        => 2,
164
        rules        => {
155
        maxonsiteissueqty  => 1,
165
            maxissueqty       => 2,
156
    },
166
            maxonsiteissueqty => 1,
157
});
167
        }
168
    }
169
);
158
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} );
170
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} );
159
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 2 - Switch is allowed' );
171
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 2 - Switch is allowed' );
160
is( exists $impossible->{TOO_MANY}, '', 'Specific case 2 - Switch is allowed' );
172
is( exists $impossible->{TOO_MANY}, '', 'Specific case 2 - Switch is allowed' );
(-)a/t/db_dependent/Circulation/TooMany.t (-49 / +56 lines)
Lines 26-31 use C4::Context; Link Here
26
26
27
use Koha::DateUtils qw( dt_from_string );
27
use Koha::DateUtils qw( dt_from_string );
28
use Koha::Database;
28
use Koha::Database;
29
use Koha::CirculationRules;
29
30
30
use t::lib::TestBuilder;
31
use t::lib::TestBuilder;
31
use t::lib::Mocks;
32
use t::lib::Mocks;
Lines 43-53 $dbh->do(q|DELETE FROM categories|); Link Here
43
$dbh->do(q|DELETE FROM accountlines|);
44
$dbh->do(q|DELETE FROM accountlines|);
44
$dbh->do(q|DELETE FROM itemtypes|);
45
$dbh->do(q|DELETE FROM itemtypes|);
45
$dbh->do(q|DELETE FROM branch_item_rules|);
46
$dbh->do(q|DELETE FROM branch_item_rules|);
46
$dbh->do(q|DELETE FROM branch_borrower_circ_rules|);
47
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
47
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
48
$dbh->do(q|DELETE FROM default_circ_rules|);
48
$dbh->do(q|DELETE FROM default_circ_rules|);
49
$dbh->do(q|DELETE FROM default_branch_item_rules|);
49
$dbh->do(q|DELETE FROM default_branch_item_rules|);
50
$dbh->do(q|DELETE FROM issuingrules|);
50
$dbh->do(q|DELETE FROM issuingrules|);
51
Koha::CirculationRules->search()->delete();
51
52
52
my $builder = t::lib::TestBuilder->new();
53
my $builder = t::lib::TestBuilder->new();
53
t::lib::Mocks::mock_preference('item-level_itypes', 1); # Assuming the item type is defined at item level
54
t::lib::Mocks::mock_preference('item-level_itypes', 1); # Assuming the item type is defined at item level
Lines 106-121 subtest 'no rules exist' => sub { Link Here
106
107
107
subtest '1 Issuingrule exist 0 0: no issue allowed' => sub {
108
subtest '1 Issuingrule exist 0 0: no issue allowed' => sub {
108
    plan tests => 4;
109
    plan tests => 4;
109
    my $issuingrule = $builder->build({
110
    Koha::CirculationRules->set_rules(
110
        source => 'Issuingrule',
111
        {
111
        value => {
112
            branchcode   => $branch->{branchcode},
112
            branchcode         => $branch->{branchcode},
113
            categorycode => $category->{categorycode},
113
            categorycode       => $category->{categorycode},
114
            itemtype     => '*',
114
            itemtype           => '*',
115
            rules        => {
115
            maxissueqty        => 0,
116
                maxissueqty       => 0,
116
            maxonsiteissueqty  => 0,
117
                maxonsiteissueqty => 0,
118
            }
117
        },
119
        },
118
    });
120
    );
119
    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
121
    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
120
    is_deeply(
122
    is_deeply(
121
        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
123
        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
Lines 161-176 subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { Link Here
161
163
162
subtest '1 Issuingrule exist 1 1: issue is allowed' => sub {
164
subtest '1 Issuingrule exist 1 1: issue is allowed' => sub {
163
    plan tests => 4;
165
    plan tests => 4;
164
    my $issuingrule = $builder->build({
166
    Koha::CirculationRules->set_rules(
165
        source => 'Issuingrule',
167
        {
166
        value => {
168
            branchcode   => $branch->{branchcode},
167
            branchcode         => $branch->{branchcode},
169
            categorycode => $category->{categorycode},
168
            categorycode       => $category->{categorycode},
170
            itemtype     => '*',
169
            itemtype           => '*',
171
            rules        => {
170
            maxissueqty        => 1,
172
                maxissueqty       => 1,
171
            maxonsiteissueqty  => 1,
173
                maxonsiteissueqty => 1,
172
        },
174
            }
173
    });
175
        }
176
    );
174
    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
177
    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
175
    is(
178
    is(
176
        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
179
        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
Lines 200-215 subtest '1 Issuingrule exist 1 1: issue is allowed' => sub { Link Here
200
203
201
subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub {
204
subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub {
202
    plan tests => 5;
205
    plan tests => 5;
203
    my $issuingrule = $builder->build({
206
    Koha::CirculationRules->set_rules(
204
        source => 'Issuingrule',
207
        {
205
        value => {
208
            branchcode   => $branch->{branchcode},
206
            branchcode         => $branch->{branchcode},
209
            categorycode => $category->{categorycode},
207
            categorycode       => $category->{categorycode},
210
            itemtype     => '*',
208
            itemtype           => '*',
211
            rules        => {
209
            maxissueqty        => 1,
212
                maxissueqty       => 1,
210
            maxonsiteissueqty  => 1,
213
                maxonsiteissueqty => 1,
211
        },
214
            }
212
    });
215
        }
216
    );
213
217
214
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string() );
218
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string() );
215
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
219
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
Lines 255-270 subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { Link Here
255
259
256
subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub {
260
subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub {
257
    plan tests => 5;
261
    plan tests => 5;
258
    my $issuingrule = $builder->build({
262
    Koha::CirculationRules->set_rules(
259
        source => 'Issuingrule',
263
        {
260
        value => {
264
            branchcode   => $branch->{branchcode},
261
            branchcode         => $branch->{branchcode},
265
            categorycode => $category->{categorycode},
262
            categorycode       => $category->{categorycode},
266
            itemtype     => '*',
263
            itemtype           => '*',
267
            rules        => {
264
            maxissueqty        => 1,
268
                maxissueqty       => 1,
265
            maxonsiteissueqty  => 1,
269
                maxonsiteissueqty => 1,
266
        },
270
            }
267
    });
271
        }
272
    );
268
273
269
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef, { onsite_checkout => 1 } );
274
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef, { onsite_checkout => 1 } );
270
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
275
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
Lines 313-327 subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { Link Here
313
    # DefaultBorrowerCircRule, DefaultBranchCircRule, DefaultBranchItemRule ans DefaultCircRule.pm
318
    # DefaultBorrowerCircRule, DefaultBranchCircRule, DefaultBranchItemRule ans DefaultCircRule.pm
314
319
315
    plan tests => 10;
320
    plan tests => 10;
316
    my $issuingrule = $builder->build({
321
    Koha::CirculationRules->set_rules(
317
        source => 'BranchBorrowerCircRule',
322
        {
318
        value => {
323
            branchcode   => $branch->{branchcode},
319
            branchcode         => $branch->{branchcode},
324
            categorycode => $category->{categorycode},
320
            categorycode       => $category->{categorycode},
325
            itemtype     => undef,
321
            maxissueqty        => 1,
326
            rules        => {
322
            maxonsiteissueqty  => 1,
327
                maxissueqty       => 1,
323
        },
328
                maxonsiteissueqty => 1,
324
    });
329
            }
330
        }
331
    );
325
332
326
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef );
333
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef );
327
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
334
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
(-)a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t (-1 lines)
Lines 92-98 my $rule = Koha::IssuingRule->new( Link Here
92
        categorycode => '*',
92
        categorycode => '*',
93
        itemtype     => '*',
93
        itemtype     => '*',
94
        branchcode   => '*',
94
        branchcode   => '*',
95
        maxissueqty  => 99,
96
        issuelength  => 7,
95
        issuelength  => 7,
97
        lengthunit   => 8,
96
        lengthunit   => 8,
98
        reservesallowed => 99,
97
        reservesallowed => 99,
(-)a/t/db_dependent/Reserves.t (-9 / +6 lines)
Lines 198-205 $requesters{$branch_3} = AddMember( Link Here
198
198
199
$dbh->do('DELETE FROM issuingrules');
199
$dbh->do('DELETE FROM issuingrules');
200
$dbh->do('DELETE FROM branch_item_rules');
200
$dbh->do('DELETE FROM branch_item_rules');
201
$dbh->do('DELETE FROM branch_borrower_circ_rules');
202
$dbh->do('DELETE FROM default_borrower_circ_rules');
203
$dbh->do('DELETE FROM default_branch_item_rules');
201
$dbh->do('DELETE FROM default_branch_item_rules');
204
$dbh->do('DELETE FROM default_branch_circ_rules');
202
$dbh->do('DELETE FROM default_branch_circ_rules');
205
$dbh->do('DELETE FROM default_circ_rules');
203
$dbh->do('DELETE FROM default_circ_rules');
Lines 212-229 $dbh->do( Link Here
212
210
213
# CPL allows only its own patrons to request its items
211
# CPL allows only its own patrons to request its items
214
$dbh->do(
212
$dbh->do(
215
    q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
213
    q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch)
216
      VALUES (?, ?, ?, ?)},
214
      VALUES (?, ?, ?)},
217
    {},
215
    {},
218
    $branch_1, 10, 1, 'homebranch',
216
    $branch_1, 1, 'homebranch',
219
);
217
);
220
218
221
# ... while FPL allows anybody to request its items
219
# ... while FPL allows anybody to request its items
222
$dbh->do(
220
$dbh->do(
223
    q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
221
    q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch)
224
      VALUES (?, ?, ?, ?)},
222
      VALUES (?, ?, ?)},
225
    {},
223
    {},
226
    $branch_2, 10, 2, 'homebranch',
224
    $branch_2, 2, 'homebranch',
227
);
225
);
228
226
229
# helper biblio for the bug 10272 regression test
227
# helper biblio for the bug 10272 regression test
230
- 

Return to bug 18925