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

(-)a/C4/Circulation.pm (-54 / +71 lines)
Lines 387-396 sub TooMany { Link Here
387
 
387
 
388
    # given branch, patron category, and item type, determine
388
    # given branch, patron category, and item type, determine
389
    # applicable issuing rule
389
    # applicable issuing rule
390
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
390
    my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule(
391
        {   categorycode => $cat_borrower,
391
        {
392
            categorycode => $cat_borrower,
393
            itemtype     => $type,
394
            branchcode   => $branch,
395
            rule_name    => 'maxissueqty',
396
        }
397
    );
398
    my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule(
399
        {
400
            categorycode => $cat_borrower,
392
            itemtype     => $type,
401
            itemtype     => $type,
393
            branchcode   => $branch
402
            branchcode   => $branch,
403
            rule_name    => 'maxonsiteissueqty',
394
        }
404
        }
395
    );
405
    );
396
406
Lines 398-404 sub TooMany { Link Here
398
    # if a rule is found and has a loan limit set, count
408
    # if a rule is found and has a loan limit set, count
399
    # how many loans the patron already has that meet that
409
    # how many loans the patron already has that meet that
400
    # rule
410
    # rule
401
    if (defined($issuing_rule) and defined($issuing_rule->maxissueqty)) {
411
    if (defined($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) {
402
        my @bind_params;
412
        my @bind_params;
403
        my $count_query = q|
413
        my $count_query = q|
404
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
414
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
Lines 406-412 sub TooMany { Link Here
406
            JOIN items USING (itemnumber)
416
            JOIN items USING (itemnumber)
407
        |;
417
        |;
408
418
409
        my $rule_itemtype = $issuing_rule->itemtype;
419
        my $rule_itemtype = $maxissueqty_rule->itemtype;
410
        if ($rule_itemtype eq "*") {
420
        if ($rule_itemtype eq "*") {
411
            # matching rule has the default item type, so count only
421
            # matching rule has the default item type, so count only
412
            # those existing loans that don't fall under a more
422
            # those existing loans that don't fall under a more
Lines 427-434 sub TooMany { Link Here
427
                                    AND   itemtype <> '*'
437
                                    AND   itemtype <> '*'
428
                                  ) ";
438
                                  ) ";
429
            }
439
            }
430
            push @bind_params, $issuing_rule->branchcode;
440
            push @bind_params, $maxissueqty_rule->branchcode;
431
            push @bind_params, $issuing_rule->categorycode;
441
            push @bind_params, $maxissueqty_rule->categorycode;
432
            push @bind_params, $cat_borrower;
442
            push @bind_params, $cat_borrower;
433
        } else {
443
        } else {
434
            # rule has specific item type, so count loans of that
444
            # rule has specific item type, so count loans of that
Lines 444-450 sub TooMany { Link Here
444
454
445
        $count_query .= " AND borrowernumber = ? ";
455
        $count_query .= " AND borrowernumber = ? ";
446
        push @bind_params, $borrower->{'borrowernumber'};
456
        push @bind_params, $borrower->{'borrowernumber'};
447
        my $rule_branch = $issuing_rule->branchcode;
457
        my $rule_branch = $maxissueqty_rule->branchcode;
448
        if ($rule_branch ne "*") {
458
        if ($rule_branch ne "*") {
449
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
459
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
450
                $count_query .= " AND issues.branchcode = ? ";
460
                $count_query .= " AND issues.branchcode = ? ";
Lines 459-466 sub TooMany { Link Here
459
469
460
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
470
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
461
471
462
        my $max_checkouts_allowed = $issuing_rule->maxissueqty;
472
        my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : 0;
463
        my $max_onsite_checkouts_allowed = $issuing_rule->maxonsiteissueqty;
473
        my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : 0;
464
474
465
        if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
475
        if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
466
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
476
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
Lines 545-551 sub TooMany { Link Here
545
        }
555
        }
546
    }
556
    }
547
557
548
    if ( not defined( $issuing_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) {
558
    if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) {
549
        return { reason => 'NO_RULE_DEFINED', max_allowed => 0 };
559
        return { reason => 'NO_RULE_DEFINED', max_allowed => 0 };
550
    }
560
    }
551
561
Lines 1573-1586 maxonsiteissueqty - maximum of on-site checkouts that a Link Here
1573
patron of the given category can have at the given
1583
patron of the given category can have at the given
1574
branch.  If the value is undef, no limit.
1584
branch.  If the value is undef, no limit.
1575
1585
1576
This will first check for a specific branch and
1586
This will check for different branch/category combinations in the following order:
1577
category match from branch_borrower_circ_rules. 
1587
branch and category
1578
1588
branch only
1579
If no rule is found, it will then check default_branch_circ_rules
1589
category only
1580
(same branch, default category).  If no rule is found,
1590
default branch and category
1581
it will then check default_borrower_circ_rules (default 
1582
branch, same category), then failing that, default_circ_rules
1583
(default branch, default category).
1584
1591
1585
If no rule has been found in the database, it will default to
1592
If no rule has been found in the database, it will default to
1586
the buillt in rule:
1593
the buillt in rule:
Lines 1597-1640 wildcards. Link Here
1597
sub GetBranchBorrowerCircRule {
1604
sub GetBranchBorrowerCircRule {
1598
    my ( $branchcode, $categorycode ) = @_;
1605
    my ( $branchcode, $categorycode ) = @_;
1599
1606
1600
    my $rules;
1607
    # Set search prededences
1601
    my $dbh = C4::Context->dbh();
1608
    my @params = (
1602
    $rules = $dbh->selectrow_hashref( q|
1609
        {
1603
        SELECT maxissueqty, maxonsiteissueqty
1610
            branchcode   => $branchcode,
1604
        FROM branch_borrower_circ_rules
1611
            categorycode => $categorycode,
1605
        WHERE branchcode = ?
1612
            itemtype     => undef,
1606
        AND   categorycode = ?
1613
        },
1607
    |, {}, $branchcode, $categorycode ) ;
1614
        {
1608
    return $rules if $rules;
1615
            branchcode   => $branchcode,
1609
1616
            categorycode => undef,
1610
    # try same branch, default borrower category
1617
            itemtype     => undef,
1611
    $rules = $dbh->selectrow_hashref( q|
1618
        },
1612
        SELECT maxissueqty, maxonsiteissueqty
1619
        {
1613
        FROM default_branch_circ_rules
1620
            branchcode   => undef,
1614
        WHERE branchcode = ?
1621
            categorycode => $categorycode,
1615
    |, {}, $branchcode ) ;
1622
            itemtype     => undef,
1616
    return $rules if $rules;
1623
        },
1617
1624
        {
1618
    # try default branch, same borrower category
1625
            branchcode   => undef,
1619
    $rules = $dbh->selectrow_hashref( q|
1626
            categorycode => undef,
1620
        SELECT maxissueqty, maxonsiteissueqty
1627
            itemtype     => undef,
1621
        FROM default_borrower_circ_rules
1628
        },
1622
        WHERE categorycode = ?
1629
    );
1623
    |, {}, $categorycode ) ;
1624
    return $rules if $rules;
1625
1626
    # try default branch, default borrower category
1627
    $rules = $dbh->selectrow_hashref( q|
1628
        SELECT maxissueqty, maxonsiteissueqty
1629
        FROM default_circ_rules
1630
    |, {} );
1631
    return $rules if $rules;
1632
1630
1633
    # built-in default circulation rule
1631
    # Initialize default values
1634
    return {
1632
    my $rules = {
1635
        maxissueqty => undef,
1633
        maxissueqty       => undef,
1636
        maxonsiteissueqty => undef,
1634
        maxonsiteissueqty => undef,
1637
    };
1635
    };
1636
1637
    # Search for rules!
1638
    foreach my $rule_name (qw( maxissueqty maxonsiteissueqty )) {
1639
        foreach my $params (@params) {
1640
            my $rule = Koha::CirculationRules->search(
1641
                {
1642
                    rule_name => $rule_name,
1643
                    %$params,
1644
                }
1645
            )->next();
1646
1647
            if ( $rule ) {
1648
                $rules->{$rule_name} = $rule->rule_value;
1649
                last;
1650
            }
1651
        }
1652
    }
1653
1654
    return $rules;
1638
}
1655
}
1639
1656
1640
=head2 GetBranchItemRule
1657
=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 198-205 elsif ($op eq 'add') { Link Here
198
        firstremind                   => $firstremind,
192
        firstremind                   => $firstremind,
199
        chargeperiod                  => $chargeperiod,
193
        chargeperiod                  => $chargeperiod,
200
        chargeperiod_charge_at        => $chargeperiod_charge_at,
194
        chargeperiod_charge_at        => $chargeperiod_charge_at,
201
        maxissueqty                   => $maxissueqty,
202
        maxonsiteissueqty             => $maxonsiteissueqty,
203
        renewalsallowed               => $renewalsallowed,
195
        renewalsallowed               => $renewalsallowed,
204
        renewalperiod                 => $renewalperiod,
196
        renewalperiod                 => $renewalperiod,
205
        norenewalbefore               => $norenewalbefore,
197
        norenewalbefore               => $norenewalbefore,
Lines 228-233 elsif ($op eq 'add') { Link Here
228
        Koha::IssuingRule->new()->set($params)->store();
220
        Koha::IssuingRule->new()->set($params)->store();
229
    }
221
    }
230
222
223
    Koha::CirculationRules->set_rules(
224
        {
225
            categorycode => $bor,
226
            itemtype     => $itemtype,
227
            branchcode   => $br,
228
            rules        => {
229
                maxissueqty       => $maxissueqty,
230
                maxonsiteissueqty => $maxonsiteissueqty,
231
            }
232
        }
233
    );
234
231
}
235
}
232
elsif ($op eq "set-branch-defaults") {
236
elsif ($op eq "set-branch-defaults") {
233
    my $categorycode  = $input->param('categorycode');
237
    my $categorycode  = $input->param('categorycode');
Lines 250-284 elsif ($op eq "set-branch-defaults") { Link Here
250
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
254
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
251
                                        FROM default_circ_rules");
255
                                        FROM default_circ_rules");
252
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
256
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
253
                                        (maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
257
                                        (holdallowed, hold_fulfillment_policy, returnbranch)
254
                                        VALUES (?, ?, ?, ?, ?)");
258
                                        VALUES (?, ?, ?)");
255
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
259
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
256
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
260
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
257
261
258
        $sth_search->execute();
262
        $sth_search->execute();
259
        my $res = $sth_search->fetchrow_hashref();
263
        my $res = $sth_search->fetchrow_hashref();
260
        if ($res->{total}) {
264
        if ($res->{total}) {
261
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
265
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
262
        } else {
266
        } else {
263
            $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
267
            $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
264
        }
268
        }
269
270
        Koha::CirculationRules->set_rules(
271
            {
272
                categorycode => undef,
273
                itemtype     => undef,
274
                branchcode   => undef,
275
                rules        => {
276
                    maxissueqty       => $maxissueqty,
277
                    maxonsiteissueqty => $maxonsiteissueqty,
278
                }
279
            }
280
        );
265
    } else {
281
    } else {
266
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
282
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
267
                                        FROM default_branch_circ_rules
283
                                        FROM default_branch_circ_rules
268
                                        WHERE branchcode = ?");
284
                                        WHERE branchcode = ?");
269
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
285
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
270
                                        (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
286
                                        (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
271
                                        VALUES (?, ?, ?, ?, ?, ?)");
287
                                        VALUES (?, ?, ?, ?)");
272
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
288
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
273
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
289
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
274
                                        WHERE branchcode = ?");
290
                                        WHERE branchcode = ?");
275
        $sth_search->execute($branch);
291
        $sth_search->execute($branch);
276
        my $res = $sth_search->fetchrow_hashref();
292
        my $res = $sth_search->fetchrow_hashref();
277
        if ($res->{total}) {
293
        if ($res->{total}) {
278
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
294
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
279
        } else {
295
        } else {
280
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
296
            $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch);
281
        }
297
        }
298
299
        Koha::CirculationRules->set_rules(
300
            {
301
                categorycode => undef,
302
                itemtype     => undef,
303
                branchcode   => $branch,
304
                rules        => {
305
                    maxissueqty       => $maxissueqty,
306
                    maxonsiteissueqty => $maxonsiteissueqty,
307
                }
308
            }
309
        );
282
    }
310
    }
283
    Koha::CirculationRules->set_rule(
311
    Koha::CirculationRules->set_rule(
284
        {
312
        {
Lines 304-428 elsif ($op eq "add-branch-cat") { Link Here
304
332
305
    if ($branch eq "*") {
333
    if ($branch eq "*") {
306
        if ($categorycode eq "*") {
334
        if ($categorycode eq "*") {
307
            #FIXME This block is will probably be never used
335
            Koha::CirculationRules->set_rules(
308
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
309
                                            FROM default_circ_rules");
310
            my $sth_insert = $dbh->prepare(q|
311
                INSERT INTO default_circ_rules
312
                    (maxissueqty, maxonsiteissueqty)
313
                    VALUES (?, ?)
314
            |);
315
            my $sth_update = $dbh->prepare(q|
316
                UPDATE default_circ_rules
317
                SET maxissueqty = ?,
318
                    maxonsiteissueqty = ?,
319
            |);
320
321
            $sth_search->execute();
322
            my $res = $sth_search->fetchrow_hashref();
323
            if ($res->{total}) {
324
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty );
325
            } else {
326
                $sth_insert->execute( $maxissueqty, $maxonsiteissueqty );
327
            }
328
329
            Koha::CirculationRules->set_rule(
330
                {
336
                {
331
                    branchcode   => undef,
332
                    categorycode => undef,
337
                    categorycode => undef,
333
                    itemtype     => undef,
338
                    itemtype     => undef,
334
                    rule_name    => 'max_holds',
339
                    branchcode   => undef,
335
                    rule_value   => $max_holds,
340
                    rules        => {
341
                        max_holds         => $max_holds,
342
                        maxissueqty       => $maxissueqty,
343
                        maxonsiteissueqty => $maxonsiteissueqty,
344
                    }
336
                }
345
                }
337
            );
346
            );
338
        } else {
347
        } else {
339
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
348
            Koha::CirculationRules->set_rules(
340
                                            FROM default_borrower_circ_rules
341
                                            WHERE categorycode = ?");
342
            my $sth_insert = $dbh->prepare(q|
343
                INSERT INTO default_borrower_circ_rules
344
                    (categorycode, maxissueqty, maxonsiteissueqty)
345
                    VALUES ( ?, ?, ?)
346
            |);
347
            my $sth_update = $dbh->prepare(q|
348
                UPDATE default_borrower_circ_rules
349
                SET maxissueqty = ?,
350
                    maxonsiteissueqty = ?,
351
                WHERE categorycode = ?
352
            |);
353
            $sth_search->execute($categorycode);
354
            my $res = $sth_search->fetchrow_hashref();
355
            if ($res->{total}) {
356
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode );
357
            } else {
358
                $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty );
359
            }
360
361
            Koha::CirculationRules->set_rule(
362
                {
349
                {
363
                    branchcode   => undef,
350
                    branchcode   => undef,
364
                    categorycode => $categorycode,
351
                    categorycode => $categorycode,
365
                    itemtype     => undef,
352
                    itemtype     => undef,
366
                    rule_name    => 'max_holds',
353
                    rules        => {
367
                    rule_value   => $max_holds,
354
                        max_holds         => $max_holds,
355
                        maxissueqty       => $maxissueqty,
356
                        maxonsiteissueqty => $maxonsiteissueqty,
357
                    }
368
                }
358
                }
369
            );
359
            );
370
        }
360
        }
371
    } elsif ($categorycode eq "*") {
361
    } elsif ($categorycode eq "*") {
372
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
362
        Koha::CirculationRules->set_rules(
373
                                        FROM default_branch_circ_rules
374
                                        WHERE branchcode = ?");
375
        my $sth_insert = $dbh->prepare(q|
376
            INSERT INTO default_branch_circ_rules
377
            (branchcode, maxissueqty, maxonsiteissueqty)
378
            VALUES (?, ?, ?)
379
        |);
380
        my $sth_update = $dbh->prepare(q|
381
            UPDATE default_branch_circ_rules
382
            SET maxissueqty = ?,
383
                maxonsiteissueqty = ?
384
            WHERE branchcode = ?
385
        |);
386
        $sth_search->execute($branch);
387
        my $res = $sth_search->fetchrow_hashref();
388
        if ($res->{total}) {
389
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch);
390
        } else {
391
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty);
392
        }
393
    } else {
394
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
395
                                        FROM branch_borrower_circ_rules
396
                                        WHERE branchcode = ?
397
                                        AND   categorycode = ?");
398
        my $sth_insert = $dbh->prepare(q|
399
            INSERT INTO branch_borrower_circ_rules
400
            (branchcode, categorycode, maxissueqty, maxonsiteissueqty)
401
            VALUES (?, ?, ?, ?)
402
        |);
403
        my $sth_update = $dbh->prepare(q|
404
            UPDATE branch_borrower_circ_rules
405
            SET maxissueqty = ?,
406
                maxonsiteissueqty = ?
407
            WHERE branchcode = ?
408
            AND categorycode = ?
409
        |);
410
411
        $sth_search->execute($branch, $categorycode);
412
        my $res = $sth_search->fetchrow_hashref();
413
        if ($res->{total}) {
414
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch, $categorycode);
415
        } else {
416
            $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty);
417
        }
418
419
        Koha::CirculationRules->set_rule(
420
            {
363
            {
364
                categorycode => undef,
365
                itemtype     => undef,
421
                branchcode   => $branch,
366
                branchcode   => $branch,
367
                rules        => {
368
                    max_holds         => $max_holds,
369
                    maxissueqty       => $maxissueqty,
370
                    maxonsiteissueqty => $maxonsiteissueqty,
371
                }
372
            }
373
        );
374
    } else {
375
        Koha::CirculationRules->set_rules(
376
            {
422
                categorycode => $categorycode,
377
                categorycode => $categorycode,
423
                itemtype     => undef,
378
                itemtype     => undef,
424
                rule_name    => 'max_holds',
379
                branchcode   => $branch,
425
                rule_value   => $max_holds,
380
                rules        => {
381
                    max_holds         => $max_holds,
382
                    maxissueqty       => $maxissueqty,
383
                    maxonsiteissueqty => $maxonsiteissueqty,
384
                }
426
            }
385
            }
427
        );
386
        );
428
    }
387
    }
Lines 590-630 while (my $row = $sth2->fetchrow_hashref) { Link Here
590
549
591
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
550
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
592
551
593
my $sth_branch_cat;
594
if ($branch eq "*") {
595
    $sth_branch_cat = $dbh->prepare("
596
        SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode
597
        FROM default_borrower_circ_rules
598
        JOIN categories USING (categorycode)
599
600
    ");
601
    $sth_branch_cat->execute();
602
} else {
603
    $sth_branch_cat = $dbh->prepare("
604
        SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode
605
        FROM branch_borrower_circ_rules
606
        JOIN categories USING (categorycode)
607
        WHERE branch_borrower_circ_rules.branchcode = ?
608
    ");
609
    $sth_branch_cat->execute($branch);
610
}
611
612
my @branch_cat_rules = ();
613
while (my $row = $sth_branch_cat->fetchrow_hashref) {
614
    push @branch_cat_rules, $row;
615
}
616
my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humancategorycode'} } @branch_cat_rules;
617
618
# note undef maxissueqty so that template can deal with them
619
foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) {
620
    $entry->{unlimited_maxissueqty}       = 1 unless defined($entry->{maxissueqty});
621
    $entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty});
622
    $entry->{unlimited_max_holds}         = 1 unless defined($entry->{max_holds});
623
    $entry->{unlimited_holds_per_day}     = 1 unless defined($entry->{holds_per_day});
624
}
625
626
@sorted_row_loop = sort by_category_and_itemtype @row_loop;
627
628
my $sth_branch_item;
552
my $sth_branch_item;
629
if ($branch eq "*") {
553
if ($branch eq "*") {
630
    $sth_branch_item = $dbh->prepare("
554
    $sth_branch_item = $dbh->prepare("
Lines 665-671 foreach my $entry (@sorted_branch_item_rules) { Link Here
665
589
666
$template->param(show_branch_cat_rule_form => 1);
590
$template->param(show_branch_cat_rule_form => 1);
667
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules);
591
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules);
668
$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules);
669
592
670
my $sth_defaults;
593
my $sth_defaults;
671
if ($branch eq "*") {
594
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 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,
Lines 856-863 CREATE TABLE `issuingrules` ( -- circulation and fine rules Link Here
856
  `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period
821
  `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period
857
  `accountsent` int(11) default NULL, -- not used? always NULL
822
  `accountsent` int(11) default NULL, -- not used? always NULL
858
  `chargename` varchar(100) default NULL, -- not used? always NULL
823
  `chargename` varchar(100) default NULL, -- not used? always NULL
859
  `maxissueqty` int(4) default NULL, -- total number of checkouts allowed
860
  `maxonsiteissueqty` int(4) default NULL, -- total number of on-site checkouts allowed
861
  `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit
824
  `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit
862
  `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours)
825
  `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours)
863
  `hardduedate` date default NULL, -- hard due date
826
  `hardduedate` date default NULL, -- hard due date
(-)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 120-137 Link Here
120
                                                          <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype | html %]&amp;categorycode=[% rule.categorycode | html %]&amp;branch=[% rule.current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
129
                                                          <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype | html %]&amp;categorycode=[% rule.categorycode | html %]&amp;branch=[% rule.current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
121
                                                        </td>
130
                                                        </td>
122
131
123
							<td>[% IF ( rule.unlimited_maxissueqty ) %]
132
							<td>
124
									<span>Unlimited</span>
133
                                [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxissueqty' ) %]
125
								[% ELSE %]
134
                                [% IF rule_value  %]
126
									[% rule.maxissueqty | html %]
135
                                    [% rule_value | html %]
127
								[% END %]
136
                                [% ELSE %]
128
							</td>
129
                            <td>[% IF rule.unlimited_maxonsiteissueqty %]
130
                                    <span>Unlimited</span>
137
                                    <span>Unlimited</span>
138
                                [% END %]
139
							</td>
140
							<td>
141
                                [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxonsiteissueqty' ) %]
142
                                [% IF rule_value  %]
143
                                    [% rule_value | html %]
131
                                [% ELSE %]
144
                                [% ELSE %]
132
                                    [% rule.maxonsiteissueqty | html %]
145
                                    <span>Unlimited</span>
133
                                [% END %]
146
                                [% END %]
134
                            </td>
147
							</td>
135
							<td>[% rule.issuelength | html %]</td>
148
							<td>[% rule.issuelength | html %]</td>
136
							<td>
149
							<td>
137
							    [% rule.lengthunit | html %]
150
							    [% rule.lengthunit | html %]
Lines 388-395 Link Here
388
                </tr>
401
                </tr>
389
                <tr>
402
                <tr>
390
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
403
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
391
                    <td><input type="text" name="maxissueqty" size="3" value="[% default_maxissueqty | html %]"/></td>
404
                    <td>
392
                    <td><input type="text" name="maxonsiteissueqty" size="3" value="[% default_maxonsiteissueqty | html %]"/></td>
405
                        [% SET maxissueqty  = CirculationRules.Get( branchcode, undef, undef, 'maxissueqty' ) %]
406
                        <input type="text" name="maxissueqty" size="3" value="[% maxissueqty | html %]"/>
407
                    </td>
408
                    <td>
409
                        [% SET maxonsiteissueqty  = CirculationRules.Get( branchcode, undef, undef, 'maxonsiteissueqty' ) %]
410
                        <input type="text" name="maxonsiteissueqty" size="3" value="[% maxonsiteissueqty | html %]"/>
411
                    </td>
393
                    <td>
412
                    <td>
394
                        [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %]
413
                        [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %]
395
                        <input name="max_holds" size="3" value="[% rule_value | html %]" />
414
                        <input name="max_holds" size="3" value="[% rule_value | html %]" />
Lines 505-532 Link Here
505
                    <th>Total holds allowed</th>
524
                    <th>Total holds allowed</th>
506
                    <th>&nbsp;</th>
525
                    <th>&nbsp;</th>
507
                </tr>
526
                </tr>
508
                [% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %]
527
                [% FOREACH c IN categorycodes %]
509
                    [% UNLESS ( loop.odd ) %]
528
                    [% SET maxissueqty = CirculationRules.Get( branchcode, c, undef, 'maxissueqty' ) %]
510
                    <tr class="highlight">
529
                    [% SET maxonsiteissueqty = CirculationRules.Get( branchcode, c, undef, 'maxonsiteissueqty' ) %]
511
                    [% ELSE %]
530
                    [% SET max_holds = CirculationRules.Get( branchcode, c, undef, 'max_holds' ) %]
531
532
                    [% IF maxissueqty || maxissueqty || max_holds %]
512
                    <tr>
533
                    <tr>
513
                    [% END %]
534
                        <td>
514
                        <td>[% IF ( branch_cat_rule_loo.default_humancategorycode ) %]
535
                            [% IF c == '*'%]
515
                                <em>Default</em>
536
                                <em>Default</em>
516
                            [% ELSE %]
537
                            [% ELSE %]
517
                                [% branch_cat_rule_loo.humancategorycode | html %]
538
                                [% Categories.GetName(c) | html %]
518
                            [% END %]
539
                            [% END %]
519
                        </td>
540
                        </td>
520
                        <td>[% IF ( branch_cat_rule_loo.unlimited_maxissueqty ) %]
541
                        <td>
521
                                <span>Unlimited</span>
542
                            [% IF maxissueqty  %]
543
                                [% maxissueqty | html %]
522
                            [% ELSE %]
544
                            [% ELSE %]
523
                                [% branch_cat_rule_loo.maxissueqty | html %]
545
                                <span>Unlimited</span>
524
                            [% END %]
546
                            [% END %]
525
                        </td>
547
                        </td>
526
                        <td>[% IF ( branch_cat_rule_loo.unlimited_maxonsiteissueqty ) %]
548
                        <td>
527
                                <span>Unlimited</span>
549
                            [% IF maxonsiteissueqty  %]
550
                                [% maxonsiteissueqty | html %]
528
                            [% ELSE %]
551
                            [% ELSE %]
529
                                [% branch_cat_rule_loo.maxonsiteissueqty | html %]
552
                                <span>Unlimited</span>
530
                            [% END %]
553
                            [% END %]
531
                        </td>
554
                        </td>
532
                        <td>
555
                        <td>
Lines 534-547 Link Here
534
                            [% IF rule_value.defined && rule_value != '' %]
557
                            [% IF rule_value.defined && rule_value != '' %]
535
                                [% rule_value | html %]
558
                                [% rule_value | html %]
536
                            [% ELSE %]
559
                            [% ELSE %]
537
                                Unlimited
560
                                <span>Unlimited</span>
538
                            [% END %]
561
                            [% END %]
539
                        </td>
562
                        </td>
540
563
541
                        <td class="actions">
564
                        <td class="actions">
542
                            <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>
565
                            <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>
543
                        </td>
566
                        </td>
544
                    </tr>
567
                    </tr>
568
                    [% END %]
545
                [% END %]
569
                [% END %]
546
                <tr>
570
                <tr>
547
                    <td>
571
                    <td>
(-)a/t/db_dependent/Circulation.t (-7 / +19 lines)
Lines 37-42 use Koha::Database; Link Here
37
use Koha::IssuingRules;
37
use Koha::IssuingRules;
38
use Koha::Checkouts;
38
use Koha::Checkouts;
39
use Koha::Patrons;
39
use Koha::Patrons;
40
use Koha::CirculationRules;
40
use Koha::Subscriptions;
41
use Koha::Subscriptions;
41
use Koha::Account::Lines;
42
use Koha::Account::Lines;
42
use Koha::Account::Offsets;
43
use Koha::Account::Offsets;
Lines 186-199 is( Link Here
186
187
187
# Set a simple circ policy
188
# Set a simple circ policy
188
$dbh->do('DELETE FROM issuingrules');
189
$dbh->do('DELETE FROM issuingrules');
190
Koha::CirculationRules->search()->delete();
189
$dbh->do(
191
$dbh->do(
190
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed,
192
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed,
191
                                maxissueqty, issuelength, lengthunit,
193
                                issuelength, lengthunit,
192
                                renewalsallowed, renewalperiod,
194
                                renewalsallowed, renewalperiod,
193
                                norenewalbefore, auto_renew,
195
                                norenewalbefore, auto_renew,
194
                                fine, chargeperiod)
196
                                fine, chargeperiod)
195
      VALUES (?, ?, ?, ?,
197
      VALUES (?, ?, ?, ?,
196
              ?, ?, ?,
198
              ?, ?,
197
              ?, ?,
199
              ?, ?,
198
              ?, ?,
200
              ?, ?,
199
              ?, ?
201
              ?, ?
Lines 201-207 $dbh->do( Link Here
201
    },
203
    },
202
    {},
204
    {},
203
    '*', '*', '*', 25,
205
    '*', '*', '*', 25,
204
    20, 14, 'days',
206
    14, 'days',
205
    1, 7,
207
    1, 7,
206
    undef, 0,
208
    undef, 0,
207
    .10, 1
209
    .10, 1
Lines 1039-1056 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1039
    $dbh->do('DELETE FROM issues');
1041
    $dbh->do('DELETE FROM issues');
1040
    $dbh->do('DELETE FROM items');
1042
    $dbh->do('DELETE FROM items');
1041
    $dbh->do('DELETE FROM issuingrules');
1043
    $dbh->do('DELETE FROM issuingrules');
1044
    Koha::CirculationRules->search()->delete();
1042
    $dbh->do(
1045
    $dbh->do(
1043
        q{
1046
        q{
1044
        INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, maxissueqty, issuelength, lengthunit, renewalsallowed, renewalperiod,
1047
        INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, issuelength, lengthunit, renewalsallowed, renewalperiod,
1045
                    norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
1048
                    norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
1046
        },
1049
        },
1047
        {},
1050
        {},
1048
        '*', '*', '*', 25,
1051
        '*', '*', '*', 25,
1049
        20,  14,  'days',
1052
        14,  'days',
1050
        1,   7,
1053
        1,   7,
1051
        undef,  0,
1054
        undef,  0,
1052
        .10, 1
1055
        .10, 1
1053
    );
1056
    );
1057
    Koha::CirculationRules->set_rules(
1058
        {
1059
            categorycode => '*',
1060
            itemtype     => '*',
1061
            branchcode   => '*',
1062
            rules        => {
1063
                maxissueqty => 20
1064
            }
1065
        }
1066
    );
1054
    my ( $biblionumber, $biblioitemnumber ) = add_biblio();
1067
    my ( $biblionumber, $biblioitemnumber ) = add_biblio();
1055
1068
1056
    my $barcode1 = '1234';
1069
    my $barcode1 = '1234';
Lines 1657-1663 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1657
            categorycode => '*',
1670
            categorycode => '*',
1658
            itemtype     => '*',
1671
            itemtype     => '*',
1659
            branchcode   => '*',
1672
            branchcode   => '*',
1660
            maxissueqty  => 99,
1661
            issuelength  => 1,
1673
            issuelength  => 1,
1662
            firstremind  => 1,        # 1 day of grace
1674
            firstremind  => 1,        # 1 day of grace
1663
            finedays     => 2,        # 2 days of fine per day of overdue
1675
            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 117-124 my $sampleissuingrule1 = { Link Here
117
    chargename         => undef,
117
    chargename         => undef,
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 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 185-193 my $sampleissuingrule3 = { Link Here
185
    branchcode         => $samplebranch1->{branchcode},
181
    branchcode         => $samplebranch1->{branchcode},
186
    categorycode       => $samplecat->{categorycode},
182
    categorycode       => $samplecat->{categorycode},
187
    itemtype           => 'DVD',
183
    itemtype           => 'DVD',
188
    maxissueqty        => 3,
184
    renewalsallowed    => 'Null',
189
    maxonsiteissueqty  => 2,
190
    renewalsallowed    => 0,
191
    renewalperiod      => 3,
185
    renewalperiod      => 3,
192
    norenewalbefore    => 8,
186
    norenewalbefore    => 8,
193
    auto_renew         => 0,
187
    auto_renew         => 0,
Lines 219-226 $query = 'INSERT INTO issuingrules ( Link Here
219
                branchcode,
213
                branchcode,
220
                categorycode,
214
                categorycode,
221
                itemtype,
215
                itemtype,
222
                maxissueqty,
223
                maxonsiteissueqty,
224
                renewalsallowed,
216
                renewalsallowed,
225
                renewalperiod,
217
                renewalperiod,
226
                norenewalbefore,
218
                norenewalbefore,
Lines 246-259 $query = 'INSERT INTO issuingrules ( Link Here
246
                opacitemholds,
238
                opacitemholds,
247
                cap_fine_to_replacement_price,
239
                cap_fine_to_replacement_price,
248
                article_requests
240
                article_requests
249
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
241
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
250
my $sth = $dbh->prepare($query);
242
my $sth = $dbh->prepare($query);
251
$sth->execute(
243
$sth->execute(
252
    $sampleissuingrule1->{branchcode},
244
    $sampleissuingrule1->{branchcode},
253
    $sampleissuingrule1->{categorycode},
245
    $sampleissuingrule1->{categorycode},
254
    $sampleissuingrule1->{itemtype},
246
    $sampleissuingrule1->{itemtype},
255
    $sampleissuingrule1->{maxissueqty},
256
    $sampleissuingrule1->{maxonsiteissueqty},
257
    $sampleissuingrule1->{renewalsallowed},
247
    $sampleissuingrule1->{renewalsallowed},
258
    $sampleissuingrule1->{renewalperiod},
248
    $sampleissuingrule1->{renewalperiod},
259
    $sampleissuingrule1->{norenewalbefore},
249
    $sampleissuingrule1->{norenewalbefore},
Lines 284-291 $sth->execute( Link Here
284
    $sampleissuingrule2->{branchcode},
274
    $sampleissuingrule2->{branchcode},
285
    $sampleissuingrule2->{categorycode},
275
    $sampleissuingrule2->{categorycode},
286
    $sampleissuingrule2->{itemtype},
276
    $sampleissuingrule2->{itemtype},
287
    $sampleissuingrule2->{maxissueqty},
288
    $sampleissuingrule2->{maxonsiteissueqty},
289
    $sampleissuingrule2->{renewalsallowed},
277
    $sampleissuingrule2->{renewalsallowed},
290
    $sampleissuingrule2->{renewalperiod},
278
    $sampleissuingrule2->{renewalperiod},
291
    $sampleissuingrule2->{norenewalbefore},
279
    $sampleissuingrule2->{norenewalbefore},
Lines 316-323 $sth->execute( Link Here
316
    $sampleissuingrule3->{branchcode},
304
    $sampleissuingrule3->{branchcode},
317
    $sampleissuingrule3->{categorycode},
305
    $sampleissuingrule3->{categorycode},
318
    $sampleissuingrule3->{itemtype},
306
    $sampleissuingrule3->{itemtype},
319
    $sampleissuingrule3->{maxissueqty},
320
    $sampleissuingrule3->{maxonsiteissueqty},
321
    $sampleissuingrule3->{renewalsallowed},
307
    $sampleissuingrule3->{renewalsallowed},
322
    $sampleissuingrule3->{renewalperiod},
308
    $sampleissuingrule3->{renewalperiod},
323
    $sampleissuingrule3->{norenewalbefore},
309
    $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
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
113
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
104
C4::Context->set_userenv($patron->borrowernumber, $patron->userid, 'usercnum', 'First name', 'Surname', $branch->{branchcode}, 'My Library', 0);
114
C4::Context->set_userenv($patron->borrowernumber, $patron->userid, 'usercnum', 'First name', 'Surname', $branch->{branchcode}, 'My Library', 0);
Lines 156-171 my $yet_another_item = $builder->build({ Link Here
156
( $impossible, undef, undef, undef ) = C4::Circulation::CanBookBeIssued( $patron, $yet_another_item->{barcode} );
166
( $impossible, undef, undef, undef ) = C4::Circulation::CanBookBeIssued( $patron, $yet_another_item->{barcode} );
157
is( $impossible->{TOO_MANY}, 'TOO_MANY_CHECKOUTS', 'Not a specific case, $delta should not be incremented' );
167
is( $impossible->{TOO_MANY}, 'TOO_MANY_CHECKOUTS', 'Not a specific case, $delta should not be incremented' );
158
168
159
$dbh->do(q|DELETE FROM issuingrules|);
169
Koha::CirculationRules->search()->delete();
160
my $borrower_circ_rule = $builder->build({
170
Koha::CirculationRules->set_rules(
161
    source => 'DefaultCircRule',
171
    {
162
    value => {
172
        branchcode   => $branch->{branchcode},
163
        branchcode         => $branch->{branchcode},
173
        categorycode => '*',
164
        categorycode       => '*',
174
        itemtype     => '*',
165
        maxissueqty        => 2,
175
        rules        => {
166
        maxonsiteissueqty  => 1,
176
            maxissueqty       => 2,
167
    },
177
            maxonsiteissueqty => 1,
168
});
178
        }
179
    }
180
);
169
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} );
181
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} );
170
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 2 - Switch is allowed' );
182
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 2 - Switch is allowed' );
171
is( exists $impossible->{TOO_MANY}, '', 'Specific case 2 - Switch is allowed' );
183
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 98-104 my $rule = Koha::IssuingRule->new( Link Here
98
        categorycode => '*',
98
        categorycode => '*',
99
        itemtype     => '*',
99
        itemtype     => '*',
100
        branchcode   => '*',
100
        branchcode   => '*',
101
        maxissueqty  => 99,
102
        issuelength  => 7,
101
        issuelength  => 7,
103
        lengthunit   => 8,
102
        lengthunit   => 8,
104
        reservesallowed => 99,
103
        reservesallowed => 99,
(-)a/t/db_dependent/Reserves.t (-9 / +6 lines)
Lines 201-208 $requesters{$branch_3} = Koha::Patron->new({ Link Here
201
201
202
$dbh->do('DELETE FROM issuingrules');
202
$dbh->do('DELETE FROM issuingrules');
203
$dbh->do('DELETE FROM branch_item_rules');
203
$dbh->do('DELETE FROM branch_item_rules');
204
$dbh->do('DELETE FROM branch_borrower_circ_rules');
205
$dbh->do('DELETE FROM default_borrower_circ_rules');
206
$dbh->do('DELETE FROM default_branch_item_rules');
204
$dbh->do('DELETE FROM default_branch_item_rules');
207
$dbh->do('DELETE FROM default_branch_circ_rules');
205
$dbh->do('DELETE FROM default_branch_circ_rules');
208
$dbh->do('DELETE FROM default_circ_rules');
206
$dbh->do('DELETE FROM default_circ_rules');
Lines 215-232 $dbh->do( Link Here
215
213
216
# CPL allows only its own patrons to request its items
214
# CPL allows only its own patrons to request its items
217
$dbh->do(
215
$dbh->do(
218
    q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
216
    q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch)
219
      VALUES (?, ?, ?, ?)},
217
      VALUES (?, ?, ?)},
220
    {},
218
    {},
221
    $branch_1, 10, 1, 'homebranch',
219
    $branch_1, 1, 'homebranch',
222
);
220
);
223
221
224
# ... while FPL allows anybody to request its items
222
# ... while FPL allows anybody to request its items
225
$dbh->do(
223
$dbh->do(
226
    q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
224
    q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch)
227
      VALUES (?, ?, ?, ?)},
225
      VALUES (?, ?, ?)},
228
    {},
226
    {},
229
    $branch_2, 10, 2, 'homebranch',
227
    $branch_2, 2, 'homebranch',
230
);
228
);
231
229
232
# helper biblio for the bug 10272 regression test
230
# helper biblio for the bug 10272 regression test
233
- 

Return to bug 18925