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

(-)a/C4/Circulation.pm (-54 / +71 lines)
Lines 389-398 sub TooMany { Link Here
389
 
389
 
390
    # given branch, patron category, and item type, determine
390
    # given branch, patron category, and item type, determine
391
    # applicable issuing rule
391
    # applicable issuing rule
392
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
392
    my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule(
393
        {   categorycode => $cat_borrower,
393
        {
394
            categorycode => $cat_borrower,
395
            itemtype     => $type,
396
            branchcode   => $branch,
397
            rule_name    => 'maxissueqty',
398
        }
399
    );
400
    my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule(
401
        {
402
            categorycode => $cat_borrower,
394
            itemtype     => $type,
403
            itemtype     => $type,
395
            branchcode   => $branch
404
            branchcode   => $branch,
405
            rule_name    => 'maxonsiteissueqty',
396
        }
406
        }
397
    );
407
    );
398
408
Lines 400-406 sub TooMany { Link Here
400
    # if a rule is found and has a loan limit set, count
410
    # if a rule is found and has a loan limit set, count
401
    # how many loans the patron already has that meet that
411
    # how many loans the patron already has that meet that
402
    # rule
412
    # rule
403
    if (defined($issuing_rule) and defined($issuing_rule->maxissueqty)) {
413
    if (defined($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) {
404
        my @bind_params;
414
        my @bind_params;
405
        my $count_query = q|
415
        my $count_query = q|
406
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
416
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
Lines 408-414 sub TooMany { Link Here
408
            JOIN items USING (itemnumber)
418
            JOIN items USING (itemnumber)
409
        |;
419
        |;
410
420
411
        my $rule_itemtype = $issuing_rule->itemtype;
421
        my $rule_itemtype = $maxissueqty_rule->itemtype;
412
        if ($rule_itemtype eq "*") {
422
        if ($rule_itemtype eq "*") {
413
            # matching rule has the default item type, so count only
423
            # matching rule has the default item type, so count only
414
            # those existing loans that don't fall under a more
424
            # those existing loans that don't fall under a more
Lines 429-436 sub TooMany { Link Here
429
                                    AND   itemtype <> '*'
439
                                    AND   itemtype <> '*'
430
                                  ) ";
440
                                  ) ";
431
            }
441
            }
432
            push @bind_params, $issuing_rule->branchcode;
442
            push @bind_params, $maxissueqty_rule->branchcode;
433
            push @bind_params, $issuing_rule->categorycode;
443
            push @bind_params, $maxissueqty_rule->categorycode;
434
            push @bind_params, $cat_borrower;
444
            push @bind_params, $cat_borrower;
435
        } else {
445
        } else {
436
            # rule has specific item type, so count loans of that
446
            # rule has specific item type, so count loans of that
Lines 446-452 sub TooMany { Link Here
446
456
447
        $count_query .= " AND borrowernumber = ? ";
457
        $count_query .= " AND borrowernumber = ? ";
448
        push @bind_params, $borrower->{'borrowernumber'};
458
        push @bind_params, $borrower->{'borrowernumber'};
449
        my $rule_branch = $issuing_rule->branchcode;
459
        my $rule_branch = $maxissueqty_rule->branchcode;
450
        if ($rule_branch ne "*") {
460
        if ($rule_branch ne "*") {
451
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
461
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
452
                $count_query .= " AND issues.branchcode = ? ";
462
                $count_query .= " AND issues.branchcode = ? ";
Lines 461-468 sub TooMany { Link Here
461
471
462
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
472
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
463
473
464
        my $max_checkouts_allowed = $issuing_rule->maxissueqty;
474
        my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : 0;
465
        my $max_onsite_checkouts_allowed = $issuing_rule->maxonsiteissueqty;
475
        my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : 0;
466
476
467
        if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
477
        if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
468
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
478
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
Lines 547-553 sub TooMany { Link Here
547
        }
557
        }
548
    }
558
    }
549
559
550
    if ( not defined( $issuing_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) {
560
    if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) {
551
        return { reason => 'NO_RULE_DEFINED', max_allowed => 0 };
561
        return { reason => 'NO_RULE_DEFINED', max_allowed => 0 };
552
    }
562
    }
553
563
Lines 1585-1598 maxonsiteissueqty - maximum of on-site checkouts that a Link Here
1585
patron of the given category can have at the given
1595
patron of the given category can have at the given
1586
branch.  If the value is undef, no limit.
1596
branch.  If the value is undef, no limit.
1587
1597
1588
This will first check for a specific branch and
1598
This will check for different branch/category combinations in the following order:
1589
category match from branch_borrower_circ_rules. 
1599
branch and category
1590
1600
branch only
1591
If no rule is found, it will then check default_branch_circ_rules
1601
category only
1592
(same branch, default category).  If no rule is found,
1602
default branch and category
1593
it will then check default_borrower_circ_rules (default 
1594
branch, same category), then failing that, default_circ_rules
1595
(default branch, default category).
1596
1603
1597
If no rule has been found in the database, it will default to
1604
If no rule has been found in the database, it will default to
1598
the buillt in rule:
1605
the buillt in rule:
Lines 1609-1652 wildcards. Link Here
1609
sub GetBranchBorrowerCircRule {
1616
sub GetBranchBorrowerCircRule {
1610
    my ( $branchcode, $categorycode ) = @_;
1617
    my ( $branchcode, $categorycode ) = @_;
1611
1618
1612
    my $rules;
1619
    # Set search prededences
1613
    my $dbh = C4::Context->dbh();
1620
    my @params = (
1614
    $rules = $dbh->selectrow_hashref( q|
1621
        {
1615
        SELECT maxissueqty, maxonsiteissueqty
1622
            branchcode   => $branchcode,
1616
        FROM branch_borrower_circ_rules
1623
            categorycode => $categorycode,
1617
        WHERE branchcode = ?
1624
            itemtype     => undef,
1618
        AND   categorycode = ?
1625
        },
1619
    |, {}, $branchcode, $categorycode ) ;
1626
        {
1620
    return $rules if $rules;
1627
            branchcode   => $branchcode,
1621
1628
            categorycode => undef,
1622
    # try same branch, default borrower category
1629
            itemtype     => undef,
1623
    $rules = $dbh->selectrow_hashref( q|
1630
        },
1624
        SELECT maxissueqty, maxonsiteissueqty
1631
        {
1625
        FROM default_branch_circ_rules
1632
            branchcode   => undef,
1626
        WHERE branchcode = ?
1633
            categorycode => $categorycode,
1627
    |, {}, $branchcode ) ;
1634
            itemtype     => undef,
1628
    return $rules if $rules;
1635
        },
1629
1636
        {
1630
    # try default branch, same borrower category
1637
            branchcode   => undef,
1631
    $rules = $dbh->selectrow_hashref( q|
1638
            categorycode => undef,
1632
        SELECT maxissueqty, maxonsiteissueqty
1639
            itemtype     => undef,
1633
        FROM default_borrower_circ_rules
1640
        },
1634
        WHERE categorycode = ?
1641
    );
1635
    |, {}, $categorycode ) ;
1636
    return $rules if $rules;
1637
1638
    # try default branch, default borrower category
1639
    $rules = $dbh->selectrow_hashref( q|
1640
        SELECT maxissueqty, maxonsiteissueqty
1641
        FROM default_circ_rules
1642
    |, {} );
1643
    return $rules if $rules;
1644
1642
1645
    # built-in default circulation rule
1643
    # Initialize default values
1646
    return {
1644
    my $rules = {
1647
        maxissueqty => undef,
1645
        maxissueqty       => undef,
1648
        maxonsiteissueqty => undef,
1646
        maxonsiteissueqty => undef,
1649
    };
1647
    };
1648
1649
    # Search for rules!
1650
    foreach my $rule_name (qw( maxissueqty maxonsiteissueqty )) {
1651
        foreach my $params (@params) {
1652
            my $rule = Koha::CirculationRules->search(
1653
                {
1654
                    rule_name => $rule_name,
1655
                    %$params,
1656
                }
1657
            )->next();
1658
1659
            if ( $rule ) {
1660
                $rules->{$rule_name} = $rule->rule_value;
1661
                last;
1662
            }
1663
        }
1664
    }
1665
1666
    return $rules;
1650
}
1667
}
1651
1668
1652
=head2 GetBranchItemRule
1669
=head2 GetBranchItemRule
(-)a/Koha/CirculationRules.pm (-4 / +8 lines)
Lines 145-161 sub set_rules { Link Here
145
    my $itemtype     = $params->{itemtype};
145
    my $itemtype     = $params->{itemtype};
146
    my $rules        = $params->{rules};
146
    my $rules        = $params->{rules};
147
147
148
    foreach my $rule (@$rules) {
148
    my $rule_objects = [];
149
        Koha::CirculationRules->set_rule(
149
    while ( my ( $rule_name, $rule_value ) = each %$rules ) {
150
        my $rule_object = Koha::CirculationRules->set_rule(
150
            {
151
            {
151
                branchcode   => $branchcode,
152
                branchcode   => $branchcode,
152
                categorycode => $categorycode,
153
                categorycode => $categorycode,
153
                itemtype     => $itemtype,
154
                itemtype     => $itemtype,
154
                rule_name    => $rule->{rule_name},
155
                rule_name    => $rule_name,
155
                rule_value   => $rule->{rule_value},
156
                rule_value   => $rule_value,
156
            }
157
            }
157
        );
158
        );
159
        push( @$rule_objects, $rule_object );
158
    }
160
    }
161
162
    return $rule_objects;
159
}
163
}
160
164
161
=head3 type
165
=head3 type
(-)a/admin/smart-rules.pl (-163 / +86 lines)
Lines 91-118 elsif ($op eq 'delete-branch-cat') { Link Here
91
        if ($categorycode eq "*") {
91
        if ($categorycode eq "*") {
92
            my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
92
            my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
93
            $sth_delete->execute();
93
            $sth_delete->execute();
94
        } else {
95
            my $sth_delete = $dbh->prepare("DELETE FROM default_borrower_circ_rules
96
                                            WHERE categorycode = ?");
97
            $sth_delete->execute($categorycode);
98
        }
94
        }
99
    } elsif ($categorycode eq "*") {
95
    } elsif ($categorycode eq "*") {
100
        my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
96
        my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
101
                                        WHERE branchcode = ?");
97
                                        WHERE branchcode = ?");
102
        $sth_delete->execute($branch);
98
        $sth_delete->execute($branch);
103
    } else {
104
        my $sth_delete = $dbh->prepare("DELETE FROM branch_borrower_circ_rules
105
                                        WHERE branchcode = ?
106
                                        AND categorycode = ?");
107
        $sth_delete->execute($branch, $categorycode);
108
    }
99
    }
109
    Koha::CirculationRules->set_rule(
100
    Koha::CirculationRules->set_rules(
110
        {
101
        {
111
            branchcode   => $branch,
102
            categorycode => $categorycode eq '*' ? undef : $categorycode,
112
            categorycode => $categorycode,
103
            branchcode   => $branch eq '*'       ? undef : $branch,
113
            itemtype     => undef,
104
            itemtype     => undef,
114
            rule_name    => 'max_holds',
105
            rules        => {
115
            rule_value   => undef,
106
                max_holds         => undef,
107
                maxissueqty       => undef,
108
                maxonsiteissueqty => undef,
109
            }
116
        }
110
        }
117
    );
111
    );
118
}
112
}
Lines 199-206 elsif ($op eq 'add') { Link Here
199
        firstremind                   => $firstremind,
193
        firstremind                   => $firstremind,
200
        chargeperiod                  => $chargeperiod,
194
        chargeperiod                  => $chargeperiod,
201
        chargeperiod_charge_at        => $chargeperiod_charge_at,
195
        chargeperiod_charge_at        => $chargeperiod_charge_at,
202
        maxissueqty                   => $maxissueqty,
203
        maxonsiteissueqty             => $maxonsiteissueqty,
204
        renewalsallowed               => $renewalsallowed,
196
        renewalsallowed               => $renewalsallowed,
205
        renewalperiod                 => $renewalperiod,
197
        renewalperiod                 => $renewalperiod,
206
        norenewalbefore               => $norenewalbefore,
198
        norenewalbefore               => $norenewalbefore,
Lines 230-235 elsif ($op eq 'add') { Link Here
230
        Koha::IssuingRule->new()->set($params)->store();
222
        Koha::IssuingRule->new()->set($params)->store();
231
    }
223
    }
232
224
225
    Koha::CirculationRules->set_rules(
226
        {
227
            categorycode => $bor,
228
            itemtype     => $itemtype,
229
            branchcode   => $br,
230
            rules        => {
231
                maxissueqty       => $maxissueqty,
232
                maxonsiteissueqty => $maxonsiteissueqty,
233
            }
234
        }
235
    );
236
233
}
237
}
234
elsif ($op eq "set-branch-defaults") {
238
elsif ($op eq "set-branch-defaults") {
235
    my $categorycode  = $input->param('categorycode');
239
    my $categorycode  = $input->param('categorycode');
Lines 252-286 elsif ($op eq "set-branch-defaults") { Link Here
252
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
256
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
253
                                        FROM default_circ_rules");
257
                                        FROM default_circ_rules");
254
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
258
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
255
                                        (maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
259
                                        (holdallowed, hold_fulfillment_policy, returnbranch)
256
                                        VALUES (?, ?, ?, ?, ?)");
260
                                        VALUES (?, ?, ?)");
257
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
261
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
258
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
262
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
259
263
260
        $sth_search->execute();
264
        $sth_search->execute();
261
        my $res = $sth_search->fetchrow_hashref();
265
        my $res = $sth_search->fetchrow_hashref();
262
        if ($res->{total}) {
266
        if ($res->{total}) {
263
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
267
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
264
        } else {
268
        } else {
265
            $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
269
            $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
266
        }
270
        }
271
272
        Koha::CirculationRules->set_rules(
273
            {
274
                categorycode => undef,
275
                itemtype     => undef,
276
                branchcode   => undef,
277
                rules        => {
278
                    maxissueqty       => $maxissueqty,
279
                    maxonsiteissueqty => $maxonsiteissueqty,
280
                }
281
            }
282
        );
267
    } else {
283
    } else {
268
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
284
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
269
                                        FROM default_branch_circ_rules
285
                                        FROM default_branch_circ_rules
270
                                        WHERE branchcode = ?");
286
                                        WHERE branchcode = ?");
271
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
287
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
272
                                        (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
288
                                        (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
273
                                        VALUES (?, ?, ?, ?, ?, ?)");
289
                                        VALUES (?, ?, ?, ?)");
274
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
290
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
275
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
291
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
276
                                        WHERE branchcode = ?");
292
                                        WHERE branchcode = ?");
277
        $sth_search->execute($branch);
293
        $sth_search->execute($branch);
278
        my $res = $sth_search->fetchrow_hashref();
294
        my $res = $sth_search->fetchrow_hashref();
279
        if ($res->{total}) {
295
        if ($res->{total}) {
280
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
296
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
281
        } else {
297
        } else {
282
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
298
            $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch);
283
        }
299
        }
300
301
        Koha::CirculationRules->set_rules(
302
            {
303
                categorycode => undef,
304
                itemtype     => undef,
305
                branchcode   => $branch,
306
                rules        => {
307
                    maxissueqty       => $maxissueqty,
308
                    maxonsiteissueqty => $maxonsiteissueqty,
309
                }
310
            }
311
        );
284
    }
312
    }
285
    Koha::CirculationRules->set_rule(
313
    Koha::CirculationRules->set_rule(
286
        {
314
        {
Lines 306-430 elsif ($op eq "add-branch-cat") { Link Here
306
334
307
    if ($branch eq "*") {
335
    if ($branch eq "*") {
308
        if ($categorycode eq "*") {
336
        if ($categorycode eq "*") {
309
            #FIXME This block is will probably be never used
337
            Koha::CirculationRules->set_rules(
310
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
311
                                            FROM default_circ_rules");
312
            my $sth_insert = $dbh->prepare(q|
313
                INSERT INTO default_circ_rules
314
                    (maxissueqty, maxonsiteissueqty)
315
                    VALUES (?, ?)
316
            |);
317
            my $sth_update = $dbh->prepare(q|
318
                UPDATE default_circ_rules
319
                SET maxissueqty = ?,
320
                    maxonsiteissueqty = ?,
321
            |);
322
323
            $sth_search->execute();
324
            my $res = $sth_search->fetchrow_hashref();
325
            if ($res->{total}) {
326
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty );
327
            } else {
328
                $sth_insert->execute( $maxissueqty, $maxonsiteissueqty );
329
            }
330
331
            Koha::CirculationRules->set_rule(
332
                {
338
                {
333
                    branchcode   => undef,
334
                    categorycode => undef,
339
                    categorycode => undef,
335
                    itemtype     => undef,
340
                    itemtype     => undef,
336
                    rule_name    => 'max_holds',
341
                    branchcode   => undef,
337
                    rule_value   => $max_holds,
342
                    rules        => {
343
                        max_holds         => $max_holds,
344
                        maxissueqty       => $maxissueqty,
345
                        maxonsiteissueqty => $maxonsiteissueqty,
346
                    }
338
                }
347
                }
339
            );
348
            );
340
        } else {
349
        } else {
341
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
350
            Koha::CirculationRules->set_rules(
342
                                            FROM default_borrower_circ_rules
343
                                            WHERE categorycode = ?");
344
            my $sth_insert = $dbh->prepare(q|
345
                INSERT INTO default_borrower_circ_rules
346
                    (categorycode, maxissueqty, maxonsiteissueqty)
347
                    VALUES ( ?, ?, ?)
348
            |);
349
            my $sth_update = $dbh->prepare(q|
350
                UPDATE default_borrower_circ_rules
351
                SET maxissueqty = ?,
352
                    maxonsiteissueqty = ?,
353
                WHERE categorycode = ?
354
            |);
355
            $sth_search->execute($categorycode);
356
            my $res = $sth_search->fetchrow_hashref();
357
            if ($res->{total}) {
358
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode );
359
            } else {
360
                $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty );
361
            }
362
363
            Koha::CirculationRules->set_rule(
364
                {
351
                {
365
                    branchcode   => undef,
352
                    branchcode   => undef,
366
                    categorycode => $categorycode,
353
                    categorycode => $categorycode,
367
                    itemtype     => undef,
354
                    itemtype     => undef,
368
                    rule_name    => 'max_holds',
355
                    rules        => {
369
                    rule_value   => $max_holds,
356
                        max_holds         => $max_holds,
357
                        maxissueqty       => $maxissueqty,
358
                        maxonsiteissueqty => $maxonsiteissueqty,
359
                    }
370
                }
360
                }
371
            );
361
            );
372
        }
362
        }
373
    } elsif ($categorycode eq "*") {
363
    } elsif ($categorycode eq "*") {
374
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
364
        Koha::CirculationRules->set_rules(
375
                                        FROM default_branch_circ_rules
376
                                        WHERE branchcode = ?");
377
        my $sth_insert = $dbh->prepare(q|
378
            INSERT INTO default_branch_circ_rules
379
            (branchcode, maxissueqty, maxonsiteissueqty)
380
            VALUES (?, ?, ?)
381
        |);
382
        my $sth_update = $dbh->prepare(q|
383
            UPDATE default_branch_circ_rules
384
            SET maxissueqty = ?,
385
                maxonsiteissueqty = ?
386
            WHERE branchcode = ?
387
        |);
388
        $sth_search->execute($branch);
389
        my $res = $sth_search->fetchrow_hashref();
390
        if ($res->{total}) {
391
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch);
392
        } else {
393
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty);
394
        }
395
    } else {
396
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
397
                                        FROM branch_borrower_circ_rules
398
                                        WHERE branchcode = ?
399
                                        AND   categorycode = ?");
400
        my $sth_insert = $dbh->prepare(q|
401
            INSERT INTO branch_borrower_circ_rules
402
            (branchcode, categorycode, maxissueqty, maxonsiteissueqty)
403
            VALUES (?, ?, ?, ?)
404
        |);
405
        my $sth_update = $dbh->prepare(q|
406
            UPDATE branch_borrower_circ_rules
407
            SET maxissueqty = ?,
408
                maxonsiteissueqty = ?
409
            WHERE branchcode = ?
410
            AND categorycode = ?
411
        |);
412
413
        $sth_search->execute($branch, $categorycode);
414
        my $res = $sth_search->fetchrow_hashref();
415
        if ($res->{total}) {
416
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch, $categorycode);
417
        } else {
418
            $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty);
419
        }
420
421
        Koha::CirculationRules->set_rule(
422
            {
365
            {
366
                categorycode => undef,
367
                itemtype     => undef,
423
                branchcode   => $branch,
368
                branchcode   => $branch,
369
                rules        => {
370
                    max_holds         => $max_holds,
371
                    maxissueqty       => $maxissueqty,
372
                    maxonsiteissueqty => $maxonsiteissueqty,
373
                }
374
            }
375
        );
376
    } else {
377
        Koha::CirculationRules->set_rules(
378
            {
424
                categorycode => $categorycode,
379
                categorycode => $categorycode,
425
                itemtype     => undef,
380
                itemtype     => undef,
426
                rule_name    => 'max_holds',
381
                branchcode   => $branch,
427
                rule_value   => $max_holds,
382
                rules        => {
383
                    max_holds         => $max_holds,
384
                    maxissueqty       => $maxissueqty,
385
                    maxonsiteissueqty => $maxonsiteissueqty,
386
                }
428
            }
387
            }
429
        );
388
        );
430
    }
389
    }
Lines 592-632 while (my $row = $sth2->fetchrow_hashref) { Link Here
592
551
593
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
552
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
594
553
595
my $sth_branch_cat;
596
if ($branch eq "*") {
597
    $sth_branch_cat = $dbh->prepare("
598
        SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode
599
        FROM default_borrower_circ_rules
600
        JOIN categories USING (categorycode)
601
602
    ");
603
    $sth_branch_cat->execute();
604
} else {
605
    $sth_branch_cat = $dbh->prepare("
606
        SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode
607
        FROM branch_borrower_circ_rules
608
        JOIN categories USING (categorycode)
609
        WHERE branch_borrower_circ_rules.branchcode = ?
610
    ");
611
    $sth_branch_cat->execute($branch);
612
}
613
614
my @branch_cat_rules = ();
615
while (my $row = $sth_branch_cat->fetchrow_hashref) {
616
    push @branch_cat_rules, $row;
617
}
618
my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humancategorycode'} } @branch_cat_rules;
619
620
# note undef maxissueqty so that template can deal with them
621
foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) {
622
    $entry->{unlimited_maxissueqty}       = 1 unless defined($entry->{maxissueqty});
623
    $entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty});
624
    $entry->{unlimited_max_holds}         = 1 unless defined($entry->{max_holds});
625
    $entry->{unlimited_holds_per_day}     = 1 unless defined($entry->{holds_per_day});
626
}
627
628
@sorted_row_loop = sort by_category_and_itemtype @row_loop;
629
630
my $sth_branch_item;
554
my $sth_branch_item;
631
if ($branch eq "*") {
555
if ($branch eq "*") {
632
    $sth_branch_item = $dbh->prepare("
556
    $sth_branch_item = $dbh->prepare("
Lines 667-673 foreach my $entry (@sorted_branch_item_rules) { Link Here
667
591
668
$template->param(show_branch_cat_rule_form => 1);
592
$template->param(show_branch_cat_rule_form => 1);
669
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules);
593
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules);
670
$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules);
671
594
672
my $sth_defaults;
595
my $sth_defaults;
673
if ($branch eq "*") {
596
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 (-35 lines)
Lines 353-397 CREATE TABLE collections_tracking ( Link Here
353
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
353
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
354
354
355
--
355
--
356
-- Table structure for table `branch_borrower_circ_rules`
357
--
358
359
DROP TABLE IF EXISTS `branch_borrower_circ_rules`;
360
CREATE TABLE `branch_borrower_circ_rules` ( -- includes default circulation rules for patron categories found under "Checkout limit by patron category"
361
  `branchcode` VARCHAR(10) NOT NULL, -- the branch this rule applies to (branches.branchcode)
362
  `categorycode` VARCHAR(10) NOT NULL, -- the patron category this rule applies to (categories.categorycode)
363
  `maxissueqty` int(4) default NULL, -- the maximum number of checkouts this patron category can have at this branch
364
  `maxonsiteissueqty` int(4) default NULL, -- the maximum number of on-site checkouts this patron category can have at this branch
365
  PRIMARY KEY (`categorycode`, `branchcode`),
366
  CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
367
    ON DELETE CASCADE ON UPDATE CASCADE,
368
  CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
369
    ON DELETE CASCADE ON UPDATE CASCADE
370
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
371
372
--
373
-- Table structure for table `default_borrower_circ_rules`
374
--
375
376
DROP TABLE IF EXISTS `default_borrower_circ_rules`;
377
CREATE TABLE `default_borrower_circ_rules` ( -- default checkout rules found under "Default checkout, hold and return policy"
378
  `categorycode` VARCHAR(10) NOT NULL, -- patron category this rul
379
  `maxissueqty` int(4) default NULL,
380
  `maxonsiteissueqty` int(4) default NULL,
381
  PRIMARY KEY (`categorycode`),
382
  CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
383
    ON DELETE CASCADE ON UPDATE CASCADE
384
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
385
386
--
387
-- Table structure for table `default_branch_circ_rules`
356
-- Table structure for table `default_branch_circ_rules`
388
--
357
--
389
358
390
DROP TABLE IF EXISTS `default_branch_circ_rules`;
359
DROP TABLE IF EXISTS `default_branch_circ_rules`;
391
CREATE TABLE `default_branch_circ_rules` (
360
CREATE TABLE `default_branch_circ_rules` (
392
  `branchcode` VARCHAR(10) NOT NULL,
361
  `branchcode` VARCHAR(10) NOT NULL,
393
  `maxissueqty` int(4) default NULL,
394
  `maxonsiteissueqty` int(4) default NULL,
395
  `holdallowed` tinyint(1) default NULL,
362
  `holdallowed` tinyint(1) default NULL,
396
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
363
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
397
  `returnbranch` varchar(15) default NULL,
364
  `returnbranch` varchar(15) default NULL,
Lines 407-414 CREATE TABLE `default_branch_circ_rules` ( Link Here
407
DROP TABLE IF EXISTS `default_circ_rules`;
374
DROP TABLE IF EXISTS `default_circ_rules`;
408
CREATE TABLE `default_circ_rules` (
375
CREATE TABLE `default_circ_rules` (
409
    `singleton` enum('singleton') NOT NULL default 'singleton',
376
    `singleton` enum('singleton') NOT NULL default 'singleton',
410
    `maxissueqty` int(4) default NULL,
411
    `maxonsiteissueqty` int(4) default NULL,
412
    `holdallowed` int(1) default NULL,
377
    `holdallowed` int(1) default NULL,
413
    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
414
    `returnbranch` varchar(15) default NULL,
379
    `returnbranch` varchar(15) default NULL,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-26 / +50 lines)
Lines 1-8 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Asset %]
2
[% USE Asset %]
3
[% USE Branches %]
3
[% USE Branches %]
4
[% USE Categories %]
4
[% USE CirculationRules %]
5
[% USE CirculationRules %]
5
[% SET footerjs = 1 %]
6
[% SET footerjs = 1 %]
7
8
[% SET branchcode = humanbranch %]
9
10
[% SET categorycodes = ['*'] %]
11
[% FOREACH pc IN patron_categories %]
12
    [% categorycodes.push( pc.id ) %]
13
[% END %]
14
6
[% INCLUDE 'doc-head-open.inc' %]
15
[% INCLUDE 'doc-head-open.inc' %]
7
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
16
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
8
[% INCLUDE 'doc-head-close.inc' %]
17
[% INCLUDE 'doc-head-close.inc' %]
Lines 126-143 Link Here
126
                                                                <a name="viewnote" data-toggle="popover" title="Note" data-content="[% rule.note | html %]" data-placement="top" data-trigger="hover">View note</a>
135
                                                                <a name="viewnote" data-toggle="popover" title="Note" data-content="[% rule.note | html %]" data-placement="top" data-trigger="hover">View note</a>
127
                                                            [% ELSE %]&nbsp;[% END %]
136
                                                            [% ELSE %]&nbsp;[% END %]
128
                                                        </td>
137
                                                        </td>
129
							<td>[% IF ( rule.unlimited_maxissueqty ) %]
138
							<td>
130
									<span>Unlimited</span>
139
                                [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxissueqty' ) %]
131
								[% ELSE %]
140
                                [% IF rule_value  %]
132
									[% rule.maxissueqty | html %]
141
                                    [% rule_value | html %]
133
								[% END %]
142
                                [% ELSE %]
134
							</td>
135
                            <td>[% IF rule.unlimited_maxonsiteissueqty %]
136
                                    <span>Unlimited</span>
143
                                    <span>Unlimited</span>
144
                                [% END %]
145
							</td>
146
							<td>
147
                                [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxonsiteissueqty' ) %]
148
                                [% IF rule_value  %]
149
                                    [% rule_value | html %]
137
                                [% ELSE %]
150
                                [% ELSE %]
138
                                    [% rule.maxonsiteissueqty | html %]
151
                                    <span>Unlimited</span>
139
                                [% END %]
152
                                [% END %]
140
                            </td>
153
							</td>
141
							<td>[% rule.issuelength | html %]</td>
154
							<td>[% rule.issuelength | html %]</td>
142
							<td>
155
							<td>
143
							    [% rule.lengthunit | html %]
156
							    [% rule.lengthunit | html %]
Lines 396-403 Link Here
396
                </tr>
409
                </tr>
397
                <tr>
410
                <tr>
398
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
411
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
399
                    <td><input type="text" name="maxissueqty" size="3" value="[% default_maxissueqty | html %]"/></td>
412
                    <td>
400
                    <td><input type="text" name="maxonsiteissueqty" size="3" value="[% default_maxonsiteissueqty | html %]"/></td>
413
                        [% SET maxissueqty  = CirculationRules.Get( branchcode, undef, undef, 'maxissueqty' ) %]
414
                        <input type="text" name="maxissueqty" size="3" value="[% maxissueqty | html %]"/>
415
                    </td>
416
                    <td>
417
                        [% SET maxonsiteissueqty  = CirculationRules.Get( branchcode, undef, undef, 'maxonsiteissueqty' ) %]
418
                        <input type="text" name="maxonsiteissueqty" size="3" value="[% maxonsiteissueqty | html %]"/>
419
                    </td>
401
                    <td>
420
                    <td>
402
                        [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %]
421
                        [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %]
403
                        <input name="max_holds" size="3" value="[% rule_value | html %]" />
422
                        <input name="max_holds" size="3" value="[% rule_value | html %]" />
Lines 513-540 Link Here
513
                    <th>Total holds allowed</th>
532
                    <th>Total holds allowed</th>
514
                    <th>&nbsp;</th>
533
                    <th>&nbsp;</th>
515
                </tr>
534
                </tr>
516
                [% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %]
535
                [% FOREACH c IN categorycodes %]
517
                    [% UNLESS ( loop.odd ) %]
536
                    [% SET maxissueqty = CirculationRules.Get( branchcode, c, undef, 'maxissueqty' ) %]
518
                    <tr class="highlight">
537
                    [% SET maxonsiteissueqty = CirculationRules.Get( branchcode, c, undef, 'maxonsiteissueqty' ) %]
519
                    [% ELSE %]
538
                    [% SET max_holds = CirculationRules.Get( branchcode, c, undef, 'max_holds' ) %]
539
540
                    [% IF maxissueqty || maxissueqty || max_holds %]
520
                    <tr>
541
                    <tr>
521
                    [% END %]
542
                        <td>
522
                        <td>[% IF ( branch_cat_rule_loo.default_humancategorycode ) %]
543
                            [% IF c == '*'%]
523
                                <em>Default</em>
544
                                <em>Default</em>
524
                            [% ELSE %]
545
                            [% ELSE %]
525
                                [% branch_cat_rule_loo.humancategorycode | html %]
546
                                [% Categories.GetName(c) | html %]
526
                            [% END %]
547
                            [% END %]
527
                        </td>
548
                        </td>
528
                        <td>[% IF ( branch_cat_rule_loo.unlimited_maxissueqty ) %]
549
                        <td>
529
                                <span>Unlimited</span>
550
                            [% IF maxissueqty  %]
551
                                [% maxissueqty | html %]
530
                            [% ELSE %]
552
                            [% ELSE %]
531
                                [% branch_cat_rule_loo.maxissueqty | html %]
553
                                <span>Unlimited</span>
532
                            [% END %]
554
                            [% END %]
533
                        </td>
555
                        </td>
534
                        <td>[% IF ( branch_cat_rule_loo.unlimited_maxonsiteissueqty ) %]
556
                        <td>
535
                                <span>Unlimited</span>
557
                            [% IF maxonsiteissueqty  %]
558
                                [% maxonsiteissueqty | html %]
536
                            [% ELSE %]
559
                            [% ELSE %]
537
                                [% branch_cat_rule_loo.maxonsiteissueqty | html %]
560
                                <span>Unlimited</span>
538
                            [% END %]
561
                            [% END %]
539
                        </td>
562
                        </td>
540
                        <td>
563
                        <td>
Lines 542-555 Link Here
542
                            [% IF rule_value.defined && rule_value != '' %]
565
                            [% IF rule_value.defined && rule_value != '' %]
543
                                [% rule_value | html %]
566
                                [% rule_value | html %]
544
                            [% ELSE %]
567
                            [% ELSE %]
545
                                Unlimited
568
                                <span>Unlimited</span>
546
                            [% END %]
569
                            [% END %]
547
                        </td>
570
                        </td>
548
571
549
                        <td class="actions">
572
                        <td class="actions">
550
                            <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 | html %]&amp;branch=[% current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
573
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% c | html %]&amp;branch=[% current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
551
                        </td>
574
                        </td>
552
                    </tr>
575
                    </tr>
576
                    [% END %]
553
                [% END %]
577
                [% END %]
554
                <tr>
578
                <tr>
555
                    <td>
579
                    <td>
(-)a/t/db_dependent/Circulation.t (-7 / +19 lines)
Lines 40-45 use Koha::Database; Link Here
40
use Koha::IssuingRules;
40
use Koha::IssuingRules;
41
use Koha::Checkouts;
41
use Koha::Checkouts;
42
use Koha::Patrons;
42
use Koha::Patrons;
43
use Koha::CirculationRules;
43
use Koha::Subscriptions;
44
use Koha::Subscriptions;
44
use Koha::Account::Lines;
45
use Koha::Account::Lines;
45
use Koha::Account::Offsets;
46
use Koha::Account::Offsets;
Lines 188-201 is( Link Here
188
189
189
# Set a simple circ policy
190
# Set a simple circ policy
190
$dbh->do('DELETE FROM issuingrules');
191
$dbh->do('DELETE FROM issuingrules');
192
Koha::CirculationRules->search()->delete();
191
$dbh->do(
193
$dbh->do(
192
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed,
194
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed,
193
                                maxissueqty, issuelength, lengthunit,
195
                                issuelength, lengthunit,
194
                                renewalsallowed, renewalperiod,
196
                                renewalsallowed, renewalperiod,
195
                                norenewalbefore, auto_renew,
197
                                norenewalbefore, auto_renew,
196
                                fine, chargeperiod)
198
                                fine, chargeperiod)
197
      VALUES (?, ?, ?, ?,
199
      VALUES (?, ?, ?, ?,
198
              ?, ?, ?,
200
              ?, ?,
199
              ?, ?,
201
              ?, ?,
200
              ?, ?,
202
              ?, ?,
201
              ?, ?
203
              ?, ?
Lines 203-209 $dbh->do( Link Here
203
    },
205
    },
204
    {},
206
    {},
205
    '*', '*', '*', 25,
207
    '*', '*', '*', 25,
206
    20, 14, 'days',
208
    14, 'days',
207
    1, 7,
209
    1, 7,
208
    undef, 0,
210
    undef, 0,
209
    .10, 1
211
    .10, 1
Lines 1007-1024 my ( $reused_itemnumber_1, $reused_itemnumber_2 ); Link Here
1007
    $dbh->do('DELETE FROM issues');
1009
    $dbh->do('DELETE FROM issues');
1008
    $dbh->do('DELETE FROM items');
1010
    $dbh->do('DELETE FROM items');
1009
    $dbh->do('DELETE FROM issuingrules');
1011
    $dbh->do('DELETE FROM issuingrules');
1012
    Koha::CirculationRules->search()->delete();
1010
    $dbh->do(
1013
    $dbh->do(
1011
        q{
1014
        q{
1012
        INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, maxissueqty, issuelength, lengthunit, renewalsallowed, renewalperiod,
1015
        INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, issuelength, lengthunit, renewalsallowed, renewalperiod,
1013
                    norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
1016
                    norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
1014
        },
1017
        },
1015
        {},
1018
        {},
1016
        '*', '*', '*', 25,
1019
        '*', '*', '*', 25,
1017
        20,  14,  'days',
1020
        14,  'days',
1018
        1,   7,
1021
        1,   7,
1019
        undef,  0,
1022
        undef,  0,
1020
        .10, 1
1023
        .10, 1
1021
    );
1024
    );
1025
    Koha::CirculationRules->set_rules(
1026
        {
1027
            categorycode => '*',
1028
            itemtype     => '*',
1029
            branchcode   => '*',
1030
            rules        => {
1031
                maxissueqty => 20
1032
            }
1033
        }
1034
    );
1022
    my $biblio = $builder->build_sample_biblio();
1035
    my $biblio = $builder->build_sample_biblio();
1023
1036
1024
    my $item_1 = $builder->build_sample_item(
1037
    my $item_1 = $builder->build_sample_item(
Lines 1604-1610 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1604
            categorycode => '*',
1617
            categorycode => '*',
1605
            itemtype     => '*',
1618
            itemtype     => '*',
1606
            branchcode   => '*',
1619
            branchcode   => '*',
1607
            maxissueqty  => 99,
1608
            issuelength  => 1,
1620
            issuelength  => 1,
1609
            firstremind  => 1,        # 1 day of grace
1621
            firstremind  => 1,        # 1 day of grace
1610
            finedays     => 2,        # 2 days of fine per day of overdue
1622
            finedays     => 2,        # 2 days of fine per day of overdue
(-)a/t/db_dependent/Circulation/Branch.t (-19 / +41 lines)
Lines 21-26 use C4::Circulation; Link Here
21
use C4::Items;
21
use C4::Items;
22
use C4::Biblio;
22
use C4::Biblio;
23
use C4::Context;
23
use C4::Context;
24
use Koha::CirculationRules;
24
25
25
use Koha::Patrons;
26
use Koha::Patrons;
26
27
Lines 53-59 $dbh->do(q|DELETE FROM categories|); Link Here
53
$dbh->do(q|DELETE FROM accountlines|);
54
$dbh->do(q|DELETE FROM accountlines|);
54
$dbh->do(q|DELETE FROM itemtypes|);
55
$dbh->do(q|DELETE FROM itemtypes|);
55
$dbh->do(q|DELETE FROM branch_item_rules|);
56
$dbh->do(q|DELETE FROM branch_item_rules|);
56
$dbh->do(q|DELETE FROM branch_borrower_circ_rules|);
57
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
57
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
58
$dbh->do(q|DELETE FROM default_circ_rules|);
58
$dbh->do(q|DELETE FROM default_circ_rules|);
59
$dbh->do(q|DELETE FROM default_branch_item_rules|);
59
$dbh->do(q|DELETE FROM default_branch_item_rules|);
Lines 152-182 is_deeply( Link Here
152
"Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined"
152
"Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined"
153
);
153
);
154
154
155
my $query = q|
155
Koha::CirculationRules->set_rules(
156
    INSERT INTO branch_borrower_circ_rules
156
    {
157
    (branchcode, categorycode, maxissueqty, maxonsiteissueqty)
157
        branchcode   => $samplebranch1->{branchcode},
158
    VALUES( ?, ?, ?, ? )
158
        categorycode => $samplecat->{categorycode},
159
|;
159
        itemtype     => undef,
160
160
        rules        => {
161
$dbh->do(
161
            maxissueqty       => 5,
162
    $query, {},
162
            maxonsiteissueqty => 6,
163
    $samplebranch1->{branchcode},
163
        }
164
    $samplecat->{categorycode}, 5, 6
164
    }
165
);
165
);
166
166
167
$query = q|
167
my $query = q|
168
    INSERT INTO default_branch_circ_rules
168
    INSERT INTO default_branch_circ_rules
169
    (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
169
    (branchcode, holdallowed, returnbranch)
170
    VALUES( ?, ?, ?, ?, ? )
170
    VALUES( ?, ?, ? )
171
|;
171
|;
172
$dbh->do( $query, {}, $samplebranch2->{branchcode},
172
$dbh->do( $query, {}, $samplebranch2->{branchcode}, 1, 'holdingbranch' );
173
    3, 2, 1, 'holdingbranch' );
173
Koha::CirculationRules->set_rules(
174
    {
175
        branchcode   => $samplebranch2->{branchcode},
176
        categorycode => undef,
177
        itemtype     => undef,
178
        rules        => {
179
            maxissueqty       => 3,
180
            maxonsiteissueqty => 2,
181
        }
182
    }
183
);
184
174
$query = q|
185
$query = q|
175
    INSERT INTO default_circ_rules
186
    INSERT INTO default_circ_rules
176
    (singleton, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
187
    (singleton, holdallowed, returnbranch)
177
    VALUES( ?, ?, ?, ?, ? )
188
    VALUES( ?, ?, ? )
178
|;
189
|;
179
$dbh->do( $query, {}, 'singleton', 4, 5, 3, 'homebranch' );
190
$dbh->do( $query, {}, 'singleton', 3, 'homebranch' );
191
Koha::CirculationRules->set_rules(
192
    {
193
        branchcode   => undef,
194
        categorycode => undef,
195
        itemtype     => undef,
196
        rules        => {
197
            maxissueqty       => 4,
198
            maxonsiteissueqty => 5,
199
        }
200
    }
201
);
180
202
181
$query =
203
$query =
182
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
204
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
(-)a/t/db_dependent/Circulation/GetHardDueDate.t (-17 / +3 lines)
Lines 116-123 my $sampleissuingrule1 = { Link Here
116
    reservecharge      => '0.000000',
116
    reservecharge      => '0.000000',
117
    restrictedtype     => 0,
117
    restrictedtype     => 0,
118
    accountsent        => 0,
118
    accountsent        => 0,
119
    maxissueqty        => 5,
120
    maxonsiteissueqty  => 4,
121
    finedays           => 0,
119
    finedays           => 0,
122
    lengthunit         => 'days',
120
    lengthunit         => 'days',
123
    renewalperiod      => 5,
121
    renewalperiod      => 5,
Lines 152-160 my $sampleissuingrule2 = { Link Here
152
    branchcode         => $samplebranch2->{branchcode},
150
    branchcode         => $samplebranch2->{branchcode},
153
    categorycode       => $samplecat->{categorycode},
151
    categorycode       => $samplecat->{categorycode},
154
    itemtype           => 'BOOK',
152
    itemtype           => 'BOOK',
155
    maxissueqty        => 2,
153
    renewalsallowed    => 'Null',
156
    maxonsiteissueqty  => 1,
157
    renewalsallowed    => 0,
158
    renewalperiod      => 2,
154
    renewalperiod      => 2,
159
    norenewalbefore    => 7,
155
    norenewalbefore    => 7,
160
    auto_renew         => 0,
156
    auto_renew         => 0,
Lines 184-192 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,
183
    renewalsallowed    => 'Null',
188
    maxonsiteissueqty  => 2,
189
    renewalsallowed    => 0,
190
    renewalperiod      => 3,
184
    renewalperiod      => 3,
191
    norenewalbefore    => 8,
185
    norenewalbefore    => 8,
192
    auto_renew         => 0,
186
    auto_renew         => 0,
Lines 217-224 $query = 'INSERT INTO issuingrules ( Link Here
217
                branchcode,
211
                branchcode,
218
                categorycode,
212
                categorycode,
219
                itemtype,
213
                itemtype,
220
                maxissueqty,
221
                maxonsiteissueqty,
222
                renewalsallowed,
214
                renewalsallowed,
223
                renewalperiod,
215
                renewalperiod,
224
                norenewalbefore,
216
                norenewalbefore,
Lines 243-256 $query = 'INSERT INTO issuingrules ( Link Here
243
                opacitemholds,
235
                opacitemholds,
244
                cap_fine_to_replacement_price,
236
                cap_fine_to_replacement_price,
245
                article_requests
237
                article_requests
246
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
238
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
247
my $sth = $dbh->prepare($query);
239
my $sth = $dbh->prepare($query);
248
$sth->execute(
240
$sth->execute(
249
    $sampleissuingrule1->{branchcode},
241
    $sampleissuingrule1->{branchcode},
250
    $sampleissuingrule1->{categorycode},
242
    $sampleissuingrule1->{categorycode},
251
    $sampleissuingrule1->{itemtype},
243
    $sampleissuingrule1->{itemtype},
252
    $sampleissuingrule1->{maxissueqty},
253
    $sampleissuingrule1->{maxonsiteissueqty},
254
    $sampleissuingrule1->{renewalsallowed},
244
    $sampleissuingrule1->{renewalsallowed},
255
    $sampleissuingrule1->{renewalperiod},
245
    $sampleissuingrule1->{renewalperiod},
256
    $sampleissuingrule1->{norenewalbefore},
246
    $sampleissuingrule1->{norenewalbefore},
Lines 280-287 $sth->execute( Link Here
280
    $sampleissuingrule2->{branchcode},
270
    $sampleissuingrule2->{branchcode},
281
    $sampleissuingrule2->{categorycode},
271
    $sampleissuingrule2->{categorycode},
282
    $sampleissuingrule2->{itemtype},
272
    $sampleissuingrule2->{itemtype},
283
    $sampleissuingrule2->{maxissueqty},
284
    $sampleissuingrule2->{maxonsiteissueqty},
285
    $sampleissuingrule2->{renewalsallowed},
273
    $sampleissuingrule2->{renewalsallowed},
286
    $sampleissuingrule2->{renewalperiod},
274
    $sampleissuingrule2->{renewalperiod},
287
    $sampleissuingrule2->{norenewalbefore},
275
    $sampleissuingrule2->{norenewalbefore},
Lines 311-318 $sth->execute( Link Here
311
    $sampleissuingrule3->{branchcode},
299
    $sampleissuingrule3->{branchcode},
312
    $sampleissuingrule3->{categorycode},
300
    $sampleissuingrule3->{categorycode},
313
    $sampleissuingrule3->{itemtype},
301
    $sampleissuingrule3->{itemtype},
314
    $sampleissuingrule3->{maxissueqty},
315
    $sampleissuingrule3->{maxonsiteissueqty},
316
    $sampleissuingrule3->{renewalsallowed},
302
    $sampleissuingrule3->{renewalsallowed},
317
    $sampleissuingrule3->{renewalperiod},
303
    $sampleissuingrule3->{renewalperiod},
318
    $sampleissuingrule3->{norenewalbefore},
304
    $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 91-104 my $issuingrule = $builder->build({ Link Here
91
        branchcode         => $branch->{branchcode},
91
        branchcode         => $branch->{branchcode},
92
        categorycode       => '*',
92
        categorycode       => '*',
93
        itemtype           => '*',
93
        itemtype           => '*',
94
        maxissueqty        => 2,
95
        maxonsiteissueqty  => 1,
96
        lengthunit         => 'days',
94
        lengthunit         => 'days',
97
        issuelength        => 5,
95
        issuelength        => 5,
98
        hardduedate        => undef,
96
        hardduedate        => undef,
99
        hardduedatecompare => 0,
97
        hardduedatecompare => 0,
100
    },
98
    },
101
});
99
});
100
Koha::CirculationRules->search()->delete();
101
Koha::CirculationRules->set_rules(
102
    {
103
        branchcode   => $branch->{branchcode},
104
        categorycode => '*',
105
        itemtype     => '*',
106
        rules        => {
107
            maxissueqty       => 2,
108
            maxonsiteissueqty => 1,
109
        }
110
    }
111
);
102
112
103
t::lib::Mocks::mock_userenv({ patron => $patron });
113
t::lib::Mocks::mock_userenv({ patron => $patron });
104
114
Lines 155-170 my $yet_another_item = $builder->build({ Link Here
155
( $impossible, undef, undef, undef ) = C4::Circulation::CanBookBeIssued( $patron, $yet_another_item->{barcode} );
165
( $impossible, undef, undef, undef ) = C4::Circulation::CanBookBeIssued( $patron, $yet_another_item->{barcode} );
156
is( $impossible->{TOO_MANY}, 'TOO_MANY_CHECKOUTS', 'Not a specific case, $delta should not be incremented' );
166
is( $impossible->{TOO_MANY}, 'TOO_MANY_CHECKOUTS', 'Not a specific case, $delta should not be incremented' );
157
167
158
$dbh->do(q|DELETE FROM issuingrules|);
168
Koha::CirculationRules->search()->delete();
159
my $borrower_circ_rule = $builder->build({
169
Koha::CirculationRules->set_rules(
160
    source => 'DefaultCircRule',
170
    {
161
    value => {
171
        branchcode   => $branch->{branchcode},
162
        branchcode         => $branch->{branchcode},
172
        categorycode => '*',
163
        categorycode       => '*',
173
        itemtype     => '*',
164
        maxissueqty        => 2,
174
        rules        => {
165
        maxonsiteissueqty  => 1,
175
            maxissueqty       => 2,
166
    },
176
            maxonsiteissueqty => 1,
167
});
177
        }
178
    }
179
);
168
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} );
180
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} );
169
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 2 - Switch is allowed' );
181
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 2 - Switch is allowed' );
170
is( exists $impossible->{TOO_MANY}, '', 'Specific case 2 - Switch is allowed' );
182
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 214-229 subtest '1 Issuingrule exist with onsiteissueqty=unlimited' => sub { Link Here
214
216
215
subtest '1 Issuingrule exist 1 1: issue is allowed' => sub {
217
subtest '1 Issuingrule exist 1 1: issue is allowed' => sub {
216
    plan tests => 4;
218
    plan tests => 4;
217
    my $issuingrule = $builder->build({
219
    Koha::CirculationRules->set_rules(
218
        source => 'Issuingrule',
220
        {
219
        value => {
221
            branchcode   => $branch->{branchcode},
220
            branchcode         => $branch->{branchcode},
222
            categorycode => $category->{categorycode},
221
            categorycode       => $category->{categorycode},
223
            itemtype     => '*',
222
            itemtype           => '*',
224
            rules        => {
223
            maxissueqty        => 1,
225
                maxissueqty       => 1,
224
            maxonsiteissueqty  => 1,
226
                maxonsiteissueqty => 1,
225
        },
227
            }
226
    });
228
        }
229
    );
227
    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
230
    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
228
    is(
231
    is(
229
        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
232
        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
Lines 253-268 subtest '1 Issuingrule exist 1 1: issue is allowed' => sub { Link Here
253
256
254
subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub {
257
subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub {
255
    plan tests => 5;
258
    plan tests => 5;
256
    my $issuingrule = $builder->build({
259
    Koha::CirculationRules->set_rules(
257
        source => 'Issuingrule',
260
        {
258
        value => {
261
            branchcode   => $branch->{branchcode},
259
            branchcode         => $branch->{branchcode},
262
            categorycode => $category->{categorycode},
260
            categorycode       => $category->{categorycode},
263
            itemtype     => '*',
261
            itemtype           => '*',
264
            rules        => {
262
            maxissueqty        => 1,
265
                maxissueqty       => 1,
263
            maxonsiteissueqty  => 1,
266
                maxonsiteissueqty => 1,
264
        },
267
            }
265
    });
268
        }
269
    );
266
270
267
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string() );
271
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string() );
268
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
272
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
Lines 308-323 subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { Link Here
308
312
309
subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub {
313
subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub {
310
    plan tests => 5;
314
    plan tests => 5;
311
    my $issuingrule = $builder->build({
315
    Koha::CirculationRules->set_rules(
312
        source => 'Issuingrule',
316
        {
313
        value => {
317
            branchcode   => $branch->{branchcode},
314
            branchcode         => $branch->{branchcode},
318
            categorycode => $category->{categorycode},
315
            categorycode       => $category->{categorycode},
319
            itemtype     => '*',
316
            itemtype           => '*',
320
            rules        => {
317
            maxissueqty        => 1,
321
                maxissueqty       => 1,
318
            maxonsiteissueqty  => 1,
322
                maxonsiteissueqty => 1,
319
        },
323
            }
320
    });
324
        }
325
    );
321
326
322
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef, { onsite_checkout => 1 } );
327
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef, { onsite_checkout => 1 } );
323
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
328
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
Lines 366-380 subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { Link Here
366
    # DefaultBorrowerCircRule, DefaultBranchCircRule, DefaultBranchItemRule ans DefaultCircRule.pm
371
    # DefaultBorrowerCircRule, DefaultBranchCircRule, DefaultBranchItemRule ans DefaultCircRule.pm
367
372
368
    plan tests => 10;
373
    plan tests => 10;
369
    my $issuingrule = $builder->build({
374
    Koha::CirculationRules->set_rules(
370
        source => 'BranchBorrowerCircRule',
375
        {
371
        value => {
376
            branchcode   => $branch->{branchcode},
372
            branchcode         => $branch->{branchcode},
377
            categorycode => $category->{categorycode},
373
            categorycode       => $category->{categorycode},
378
            itemtype     => undef,
374
            maxissueqty        => 1,
379
            rules        => {
375
            maxonsiteissueqty  => 1,
380
                maxissueqty       => 1,
376
        },
381
                maxonsiteissueqty => 1,
377
    });
382
            }
383
        }
384
    );
378
385
379
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef );
386
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef );
380
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
387
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
(-)a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t (-1 lines)
Lines 96-102 my $rule = Koha::IssuingRule->new( Link Here
96
        categorycode => '*',
96
        categorycode => '*',
97
        itemtype     => '*',
97
        itemtype     => '*',
98
        branchcode   => '*',
98
        branchcode   => '*',
99
        maxissueqty  => 99,
100
        issuelength  => 7,
99
        issuelength  => 7,
101
        lengthunit   => 8,
100
        lengthunit   => 8,
102
        reservesallowed => 99,
101
        reservesallowed => 99,
(-)a/t/db_dependent/Reserves.t (-9 / +6 lines)
Lines 188-195 $requesters{$branch_3} = Koha::Patron->new({ Link Here
188
188
189
$dbh->do('DELETE FROM issuingrules');
189
$dbh->do('DELETE FROM issuingrules');
190
$dbh->do('DELETE FROM branch_item_rules');
190
$dbh->do('DELETE FROM branch_item_rules');
191
$dbh->do('DELETE FROM branch_borrower_circ_rules');
192
$dbh->do('DELETE FROM default_borrower_circ_rules');
193
$dbh->do('DELETE FROM default_branch_item_rules');
191
$dbh->do('DELETE FROM default_branch_item_rules');
194
$dbh->do('DELETE FROM default_branch_circ_rules');
192
$dbh->do('DELETE FROM default_branch_circ_rules');
195
$dbh->do('DELETE FROM default_circ_rules');
193
$dbh->do('DELETE FROM default_circ_rules');
Lines 202-219 $dbh->do( Link Here
202
200
203
# CPL allows only its own patrons to request its items
201
# CPL allows only its own patrons to request its items
204
$dbh->do(
202
$dbh->do(
205
    q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
203
    q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch)
206
      VALUES (?, ?, ?, ?)},
204
      VALUES (?, ?, ?)},
207
    {},
205
    {},
208
    $branch_1, 10, 1, 'homebranch',
206
    $branch_1, 1, 'homebranch',
209
);
207
);
210
208
211
# ... while FPL allows anybody to request its items
209
# ... while FPL allows anybody to request its items
212
$dbh->do(
210
$dbh->do(
213
    q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
211
    q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch)
214
      VALUES (?, ?, ?, ?)},
212
      VALUES (?, ?, ?)},
215
    {},
213
    {},
216
    $branch_2, 10, 2, 'homebranch',
214
    $branch_2, 2, 'homebranch',
217
);
215
);
218
216
219
my $bibnum2 = $builder->build_sample_biblio({frameworkcode => $frameworkcode})->biblionumber;
217
my $bibnum2 = $builder->build_sample_biblio({frameworkcode => $frameworkcode})->biblionumber;
220
- 

Return to bug 18925