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

(-)a/C4/Circulation.pm (-54 / +71 lines)
Lines 399-408 sub TooMany { Link Here
399
 
399
 
400
    # given branch, patron category, and item type, determine
400
    # given branch, patron category, and item type, determine
401
    # applicable issuing rule
401
    # applicable issuing rule
402
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
402
    my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule(
403
        {   categorycode => $cat_borrower,
403
        {
404
            categorycode => $cat_borrower,
405
            itemtype     => $type,
406
            branchcode   => $branch,
407
            rule_name    => 'maxissueqty',
408
        }
409
    );
410
    my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule(
411
        {
412
            categorycode => $cat_borrower,
404
            itemtype     => $type,
413
            itemtype     => $type,
405
            branchcode   => $branch
414
            branchcode   => $branch,
415
            rule_name    => 'maxonsiteissueqty',
406
        }
416
        }
407
    );
417
    );
408
418
Lines 410-416 sub TooMany { Link Here
410
    # if a rule is found and has a loan limit set, count
420
    # if a rule is found and has a loan limit set, count
411
    # how many loans the patron already has that meet that
421
    # how many loans the patron already has that meet that
412
    # rule
422
    # rule
413
    if (defined($issuing_rule) and defined($issuing_rule->maxissueqty)) {
423
    if (defined($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) {
414
        my @bind_params;
424
        my @bind_params;
415
        my $count_query = q|
425
        my $count_query = q|
416
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
426
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
Lines 418-424 sub TooMany { Link Here
418
            JOIN items USING (itemnumber)
428
            JOIN items USING (itemnumber)
419
        |;
429
        |;
420
430
421
        my $rule_itemtype = $issuing_rule->itemtype;
431
        my $rule_itemtype = $maxissueqty_rule->itemtype;
422
        if ($rule_itemtype eq "*") {
432
        if ($rule_itemtype eq "*") {
423
            # matching rule has the default item type, so count only
433
            # matching rule has the default item type, so count only
424
            # those existing loans that don't fall under a more
434
            # those existing loans that don't fall under a more
Lines 439-446 sub TooMany { Link Here
439
                                    AND   itemtype <> '*'
449
                                    AND   itemtype <> '*'
440
                                  ) ";
450
                                  ) ";
441
            }
451
            }
442
            push @bind_params, $issuing_rule->branchcode;
452
            push @bind_params, $maxissueqty_rule->branchcode;
443
            push @bind_params, $issuing_rule->categorycode;
453
            push @bind_params, $maxissueqty_rule->categorycode;
444
            push @bind_params, $cat_borrower;
454
            push @bind_params, $cat_borrower;
445
        } else {
455
        } else {
446
            # rule has specific item type, so count loans of that
456
            # rule has specific item type, so count loans of that
Lines 456-462 sub TooMany { Link Here
456
466
457
        $count_query .= " AND borrowernumber = ? ";
467
        $count_query .= " AND borrowernumber = ? ";
458
        push @bind_params, $borrower->{'borrowernumber'};
468
        push @bind_params, $borrower->{'borrowernumber'};
459
        my $rule_branch = $issuing_rule->branchcode;
469
        my $rule_branch = $maxissueqty_rule->branchcode;
460
        if ($rule_branch ne "*") {
470
        if ($rule_branch ne "*") {
461
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
471
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
462
                $count_query .= " AND issues.branchcode = ? ";
472
                $count_query .= " AND issues.branchcode = ? ";
Lines 471-478 sub TooMany { Link Here
471
481
472
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
482
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
473
483
474
        my $max_checkouts_allowed = $issuing_rule->maxissueqty;
484
        my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : 0;
475
        my $max_onsite_checkouts_allowed = $issuing_rule->maxonsiteissueqty;
485
        my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : 0;
476
486
477
        if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
487
        if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
478
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
488
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
Lines 557-563 sub TooMany { Link Here
557
        }
567
        }
558
    }
568
    }
559
569
560
    if ( not defined( $issuing_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) {
570
    if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) {
561
        return { reason => 'NO_RULE_DEFINED', max_allowed => 0 };
571
        return { reason => 'NO_RULE_DEFINED', max_allowed => 0 };
562
    }
572
    }
563
573
Lines 1589-1602 maxonsiteissueqty - maximum of on-site checkouts that a Link Here
1589
patron of the given category can have at the given
1599
patron of the given category can have at the given
1590
branch.  If the value is undef, no limit.
1600
branch.  If the value is undef, no limit.
1591
1601
1592
This will first check for a specific branch and
1602
This will check for different branch/category combinations in the following order:
1593
category match from branch_borrower_circ_rules. 
1603
branch and category
1594
1604
branch only
1595
If no rule is found, it will then check default_branch_circ_rules
1605
category only
1596
(same branch, default category).  If no rule is found,
1606
default branch and category
1597
it will then check default_borrower_circ_rules (default 
1598
branch, same category), then failing that, default_circ_rules
1599
(default branch, default category).
1600
1607
1601
If no rule has been found in the database, it will default to
1608
If no rule has been found in the database, it will default to
1602
the buillt in rule:
1609
the buillt in rule:
Lines 1613-1656 wildcards. Link Here
1613
sub GetBranchBorrowerCircRule {
1620
sub GetBranchBorrowerCircRule {
1614
    my ( $branchcode, $categorycode ) = @_;
1621
    my ( $branchcode, $categorycode ) = @_;
1615
1622
1616
    my $rules;
1623
    # Set search prededences
1617
    my $dbh = C4::Context->dbh();
1624
    my @params = (
1618
    $rules = $dbh->selectrow_hashref( q|
1625
        {
1619
        SELECT maxissueqty, maxonsiteissueqty
1626
            branchcode   => $branchcode,
1620
        FROM branch_borrower_circ_rules
1627
            categorycode => $categorycode,
1621
        WHERE branchcode = ?
1628
            itemtype     => undef,
1622
        AND   categorycode = ?
1629
        },
1623
    |, {}, $branchcode, $categorycode ) ;
1630
        {
1624
    return $rules if $rules;
1631
            branchcode   => $branchcode,
1625
1632
            categorycode => undef,
1626
    # try same branch, default borrower category
1633
            itemtype     => undef,
1627
    $rules = $dbh->selectrow_hashref( q|
1634
        },
1628
        SELECT maxissueqty, maxonsiteissueqty
1635
        {
1629
        FROM default_branch_circ_rules
1636
            branchcode   => undef,
1630
        WHERE branchcode = ?
1637
            categorycode => $categorycode,
1631
    |, {}, $branchcode ) ;
1638
            itemtype     => undef,
1632
    return $rules if $rules;
1639
        },
1633
1640
        {
1634
    # try default branch, same borrower category
1641
            branchcode   => undef,
1635
    $rules = $dbh->selectrow_hashref( q|
1642
            categorycode => undef,
1636
        SELECT maxissueqty, maxonsiteissueqty
1643
            itemtype     => undef,
1637
        FROM default_borrower_circ_rules
1644
        },
1638
        WHERE categorycode = ?
1645
    );
1639
    |, {}, $categorycode ) ;
1640
    return $rules if $rules;
1641
1642
    # try default branch, default borrower category
1643
    $rules = $dbh->selectrow_hashref( q|
1644
        SELECT maxissueqty, maxonsiteissueqty
1645
        FROM default_circ_rules
1646
    |, {} );
1647
    return $rules if $rules;
1648
1646
1649
    # built-in default circulation rule
1647
    # Initialize default values
1650
    return {
1648
    my $rules = {
1651
        maxissueqty => undef,
1649
        maxissueqty       => undef,
1652
        maxonsiteissueqty => undef,
1650
        maxonsiteissueqty => undef,
1653
    };
1651
    };
1652
1653
    # Search for rules!
1654
    foreach my $rule_name (qw( maxissueqty maxonsiteissueqty )) {
1655
        foreach my $params (@params) {
1656
            my $rule = Koha::CirculationRules->search(
1657
                {
1658
                    rule_name => $rule_name,
1659
                    %$params,
1660
                }
1661
            )->next();
1662
1663
            if ( $rule ) {
1664
                $rules->{$rule_name} = $rule->rule_value;
1665
                last;
1666
            }
1667
        }
1668
    }
1669
1670
    return $rules;
1654
}
1671
}
1655
1672
1656
=head2 GetBranchItemRule
1673
=head2 GetBranchItemRule
(-)a/Koha/CirculationRules.pm (-4 / +8 lines)
Lines 142-158 sub set_rules { Link Here
142
    my $itemtype     = $params->{itemtype};
142
    my $itemtype     = $params->{itemtype};
143
    my $rules        = $params->{rules};
143
    my $rules        = $params->{rules};
144
144
145
    foreach my $rule (@$rules) {
145
    my $rule_objects = [];
146
        Koha::CirculationRules->set_rule(
146
    while ( my ( $rule_name, $rule_value ) = each %$rules ) {
147
        my $rule_object = Koha::CirculationRules->set_rule(
147
            {
148
            {
148
                branchcode   => $branchcode,
149
                branchcode   => $branchcode,
149
                categorycode => $categorycode,
150
                categorycode => $categorycode,
150
                itemtype     => $itemtype,
151
                itemtype     => $itemtype,
151
                rule_name    => $rule->{rule_name},
152
                rule_name    => $rule_name,
152
                rule_value   => $rule->{rule_value},
153
                rule_value   => $rule_value,
153
            }
154
            }
154
        );
155
        );
156
        push( @$rule_objects, $rule_object );
155
    }
157
    }
158
159
    return $rule_objects;
156
}
160
}
157
161
158
=head3 type
162
=head3 type
(-)a/admin/smart-rules.pl (-160 / +86 lines)
Lines 87-114 elsif ($op eq 'delete-branch-cat') { Link Here
87
        if ($categorycode eq "*") {
87
        if ($categorycode eq "*") {
88
            my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
88
            my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
89
            $sth_delete->execute();
89
            $sth_delete->execute();
90
        } else {
91
            my $sth_delete = $dbh->prepare("DELETE FROM default_borrower_circ_rules
92
                                            WHERE categorycode = ?");
93
            $sth_delete->execute($categorycode);
94
        }
90
        }
95
    } elsif ($categorycode eq "*") {
91
    } elsif ($categorycode eq "*") {
96
        my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
92
        my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
97
                                        WHERE branchcode = ?");
93
                                        WHERE branchcode = ?");
98
        $sth_delete->execute($branch);
94
        $sth_delete->execute($branch);
99
    } else {
100
        my $sth_delete = $dbh->prepare("DELETE FROM branch_borrower_circ_rules
101
                                        WHERE branchcode = ?
102
                                        AND categorycode = ?");
103
        $sth_delete->execute($branch, $categorycode);
104
    }
95
    }
105
    Koha::CirculationRules->set_rule(
96
    Koha::CirculationRules->set_rules(
106
        {
97
        {
107
            branchcode   => $branch,
98
            categorycode => $categorycode eq '*' ? undef : $categorycode,
108
            categorycode => $categorycode,
99
            branchcode   => $branch eq '*'       ? undef : $branch,
109
            itemtype     => undef,
100
            itemtype     => undef,
110
            rule_name    => 'max_holds',
101
            rules        => {
111
            rule_value   => undef,
102
                max_holds         => undef,
103
                maxissueqty       => undef,
104
                maxonsiteissueqty => undef,
105
            }
112
        }
106
        }
113
    );
107
    );
114
}
108
}
Lines 189-196 elsif ($op eq 'add') { Link Here
189
        firstremind                   => $firstremind,
183
        firstremind                   => $firstremind,
190
        chargeperiod                  => $chargeperiod,
184
        chargeperiod                  => $chargeperiod,
191
        chargeperiod_charge_at        => $chargeperiod_charge_at,
185
        chargeperiod_charge_at        => $chargeperiod_charge_at,
192
        maxissueqty                   => $maxissueqty,
193
        maxonsiteissueqty             => $maxonsiteissueqty,
194
        renewalsallowed               => $renewalsallowed,
186
        renewalsallowed               => $renewalsallowed,
195
        renewalperiod                 => $renewalperiod,
187
        renewalperiod                 => $renewalperiod,
196
        norenewalbefore               => $norenewalbefore,
188
        norenewalbefore               => $norenewalbefore,
Lines 218-223 elsif ($op eq 'add') { Link Here
218
        Koha::IssuingRule->new()->set($params)->store();
210
        Koha::IssuingRule->new()->set($params)->store();
219
    }
211
    }
220
212
213
    Koha::CirculationRules->set_rules(
214
        {
215
            categorycode => $bor,
216
            itemtype     => $itemtype,
217
            branchcode   => $br,
218
            rules        => {
219
                maxissueqty       => $maxissueqty,
220
                maxonsiteissueqty => $maxonsiteissueqty,
221
            }
222
        }
223
    );
224
221
}
225
}
222
elsif ($op eq "set-branch-defaults") {
226
elsif ($op eq "set-branch-defaults") {
223
    my $categorycode  = $input->param('categorycode');
227
    my $categorycode  = $input->param('categorycode');
Lines 240-274 elsif ($op eq "set-branch-defaults") { Link Here
240
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
244
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
241
                                        FROM default_circ_rules");
245
                                        FROM default_circ_rules");
242
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
246
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
243
                                        (maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
247
                                        (holdallowed, hold_fulfillment_policy, returnbranch)
244
                                        VALUES (?, ?, ?, ?, ?)");
248
                                        VALUES (?, ?, ?)");
245
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
249
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
246
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
250
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
247
251
248
        $sth_search->execute();
252
        $sth_search->execute();
249
        my $res = $sth_search->fetchrow_hashref();
253
        my $res = $sth_search->fetchrow_hashref();
250
        if ($res->{total}) {
254
        if ($res->{total}) {
251
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
255
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
252
        } else {
256
        } else {
253
            $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
257
            $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
254
        }
258
        }
259
260
        Koha::CirculationRules->set_rules(
261
            {
262
                categorycode => undef,
263
                itemtype     => undef,
264
                branchcode   => undef,
265
                rules        => {
266
                    maxissueqty       => $maxissueqty,
267
                    maxonsiteissueqty => $maxonsiteissueqty,
268
                }
269
            }
270
        );
255
    } else {
271
    } else {
256
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
272
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
257
                                        FROM default_branch_circ_rules
273
                                        FROM default_branch_circ_rules
258
                                        WHERE branchcode = ?");
274
                                        WHERE branchcode = ?");
259
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
275
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
260
                                        (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
276
                                        (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
261
                                        VALUES (?, ?, ?, ?, ?, ?)");
277
                                        VALUES (?, ?, ?, ?)");
262
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
278
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
263
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
279
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
264
                                        WHERE branchcode = ?");
280
                                        WHERE branchcode = ?");
265
        $sth_search->execute($branch);
281
        $sth_search->execute($branch);
266
        my $res = $sth_search->fetchrow_hashref();
282
        my $res = $sth_search->fetchrow_hashref();
267
        if ($res->{total}) {
283
        if ($res->{total}) {
268
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
284
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
269
        } else {
285
        } else {
270
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
286
            $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch);
271
        }
287
        }
288
289
        Koha::CirculationRules->set_rules(
290
            {
291
                categorycode => undef,
292
                itemtype     => undef,
293
                branchcode   => $branch,
294
                rules        => {
295
                    maxissueqty       => $maxissueqty,
296
                    maxonsiteissueqty => $maxonsiteissueqty,
297
                }
298
            }
299
        );
272
    }
300
    }
273
    Koha::CirculationRules->set_rule(
301
    Koha::CirculationRules->set_rule(
274
        {
302
        {
Lines 294-417 elsif ($op eq "add-branch-cat") { Link Here
294
322
295
    if ($branch eq "*") {
323
    if ($branch eq "*") {
296
        if ($categorycode eq "*") {
324
        if ($categorycode eq "*") {
297
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
325
            Koha::CirculationRules->set_rules(
298
                                            FROM default_circ_rules");
299
            my $sth_insert = $dbh->prepare(q|
300
                INSERT INTO default_circ_rules
301
                    (maxissueqty, maxonsiteissueqty)
302
                    VALUES (?, ?, )
303
            |);
304
            my $sth_update = $dbh->prepare(q|
305
                UPDATE default_circ_rules
306
                SET maxissueqty = ?,
307
                    maxonsiteissueqty = ?
308
            |);
309
310
            $sth_search->execute();
311
            my $res = $sth_search->fetchrow_hashref();
312
            if ($res->{total}) {
313
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty );
314
            } else {
315
                $sth_insert->execute( $maxissueqty, $maxonsiteissueqty );
316
            }
317
318
            Koha::CirculationRules->set_rule(
319
                {
326
                {
320
                    branchcode   => undef,
321
                    categorycode => undef,
327
                    categorycode => undef,
322
                    itemtype     => undef,
328
                    itemtype     => undef,
323
                    rule_name    => 'max_holds',
329
                    branchcode   => undef,
324
                    rule_value   => $max_holds,
330
                    rules        => {
331
                        max_holds         => $max_holds,
332
                        maxissueqty       => $maxissueqty,
333
                        maxonsiteissueqty => $maxonsiteissueqty,
334
                    }
325
                }
335
                }
326
            );
336
            );
327
        } else {
337
        } else {
328
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
338
            Koha::CirculationRules->set_rules(
329
                                            FROM default_borrower_circ_rules
330
                                            WHERE categorycode = ?");
331
            my $sth_insert = $dbh->prepare(q|
332
                INSERT INTO default_borrower_circ_rules
333
                    (categorycode, maxissueqty, maxonsiteissueqty)
334
                    VALUES (?, ?, ?)
335
            |);
336
            my $sth_update = $dbh->prepare(q|
337
                UPDATE default_borrower_circ_rules
338
                SET maxissueqty = ?,
339
                    maxonsiteissueqty = ?
340
                WHERE categorycode = ?
341
            |);
342
            $sth_search->execute($branch);
343
            my $res = $sth_search->fetchrow_hashref();
344
            if ($res->{total}) {
345
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode );
346
            } else {
347
                $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty );
348
            }
349
350
            Koha::CirculationRules->set_rule(
351
                {
339
                {
352
                    branchcode   => '*',
340
                    branchcode   => '*',
353
                    categorycode => $categorycode,
341
                    categorycode => $categorycode,
354
                    itemtype     => undef,
342
                    itemtype     => undef,
355
                    rule_name    => 'max_holds',
343
                    rules        => {
356
                    rule_value   => $max_holds,
344
                        max_holds         => $max_holds,
345
                        maxissueqty       => $maxissueqty,
346
                        maxonsiteissueqty => $maxonsiteissueqty,
347
                    }
357
                }
348
                }
358
            );
349
            );
359
        }
350
        }
360
    } elsif ($categorycode eq "*") {
351
    } elsif ($categorycode eq "*") {
361
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
352
        Koha::CirculationRules->set_rules(
362
                                        FROM default_branch_circ_rules
363
                                        WHERE branchcode = ?");
364
        my $sth_insert = $dbh->prepare(q|
365
            INSERT INTO default_branch_circ_rules
366
            (branchcode, maxissueqty, maxonsiteissueqty)
367
            VALUES (?, ?, ?)
368
        |);
369
        my $sth_update = $dbh->prepare(q|
370
            UPDATE default_branch_circ_rules
371
            SET maxissueqty = ?,
372
                maxonsiteissueqty = ?
373
            WHERE branchcode = ?
374
        |);
375
        $sth_search->execute($branch);
376
        my $res = $sth_search->fetchrow_hashref();
377
        if ($res->{total}) {
378
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch);
379
        } else {
380
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty);
381
        }
382
    } else {
383
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
384
                                        FROM branch_borrower_circ_rules
385
                                        WHERE branchcode = ?
386
                                        AND   categorycode = ?");
387
        my $sth_insert = $dbh->prepare(q|
388
            INSERT INTO branch_borrower_circ_rules
389
            (branchcode, categorycode, maxissueqty, maxonsiteissueqty)
390
            VALUES (?, ?, ?, ?)
391
        |);
392
        my $sth_update = $dbh->prepare(q|
393
            UPDATE branch_borrower_circ_rules
394
            SET maxissueqty = ?,
395
                maxonsiteissueqty = ?
396
            WHERE branchcode = ?
397
            AND categorycode = ?
398
        |);
399
400
        $sth_search->execute($branch, $categorycode);
401
        my $res = $sth_search->fetchrow_hashref();
402
        if ($res->{total}) {
403
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch, $categorycode);
404
        } else {
405
            $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty);
406
        }
407
408
        Koha::CirculationRules->set_rule(
409
            {
353
            {
354
                categorycode => undef,
355
                itemtype     => undef,
410
                branchcode   => $branch,
356
                branchcode   => $branch,
357
                rules        => {
358
                    max_holds         => $max_holds,
359
                    maxissueqty       => $maxissueqty,
360
                    maxonsiteissueqty => $maxonsiteissueqty,
361
                }
362
            }
363
        );
364
    } else {
365
        Koha::CirculationRules->set_rules(
366
            {
411
                categorycode => $categorycode,
367
                categorycode => $categorycode,
412
                itemtype     => undef,
368
                itemtype     => undef,
413
                rule_name    => 'max_holds',
369
                branchcode   => $branch,
414
                rule_value   => $max_holds,
370
                rules        => {
371
                    max_holds         => $max_holds,
372
                    maxissueqty       => $maxissueqty,
373
                    maxonsiteissueqty => $maxonsiteissueqty,
374
                }
415
            }
375
            }
416
        );
376
        );
417
    }
377
    }
Lines 579-617 while (my $row = $sth2->fetchrow_hashref) { Link Here
579
539
580
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
540
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
581
541
582
my $sth_branch_cat;
583
if ($branch eq "*") {
584
    $sth_branch_cat = $dbh->prepare("
585
        SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode
586
        FROM default_borrower_circ_rules
587
        JOIN categories USING (categorycode)
588
589
    ");
590
    $sth_branch_cat->execute();
591
} else {
592
    $sth_branch_cat = $dbh->prepare("
593
        SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode
594
        FROM branch_borrower_circ_rules
595
        JOIN categories USING (categorycode)
596
        WHERE branch_borrower_circ_rules.branchcode = ?
597
    ");
598
    $sth_branch_cat->execute($branch);
599
}
600
601
my @branch_cat_rules = ();
602
while (my $row = $sth_branch_cat->fetchrow_hashref) {
603
    push @branch_cat_rules, $row;
604
}
605
my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humancategorycode'} } @branch_cat_rules;
606
607
# note undef maxissueqty so that template can deal with them
608
foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) {
609
    $entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty});
610
    $entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty});
611
}
612
613
@sorted_row_loop = sort by_category_and_itemtype @row_loop;
614
615
my $sth_branch_item;
542
my $sth_branch_item;
616
if ($branch eq "*") {
543
if ($branch eq "*") {
617
    $sth_branch_item = $dbh->prepare("
544
    $sth_branch_item = $dbh->prepare("
Lines 652-658 foreach my $entry (@sorted_branch_item_rules) { Link Here
652
579
653
$template->param(show_branch_cat_rule_form => 1);
580
$template->param(show_branch_cat_rule_form => 1);
654
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules);
581
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules);
655
$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules);
656
582
657
my $sth_defaults;
583
my $sth_defaults;
658
if ($branch eq "*") {
584
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 369-405 CREATE TABLE collections_tracking ( Link Here
369
  PRIMARY KEY (collections_tracking_id)
369
  PRIMARY KEY (collections_tracking_id)
370
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
370
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
371
371
372
--
373
-- Table structure for table `branch_borrower_circ_rules`
374
--
375
376
DROP TABLE IF EXISTS `branch_borrower_circ_rules`;
377
CREATE TABLE `branch_borrower_circ_rules` ( -- includes default circulation rules for patron categories found under "Checkout limit by patron category"
378
  `branchcode` VARCHAR(10) NOT NULL, -- the branch this rule applies to (branches.branchcode)
379
  `categorycode` VARCHAR(10) NOT NULL, -- the patron category this rule applies to (categories.categorycode)
380
  `maxissueqty` int(4) default NULL, -- the maximum number of checkouts this patron category can have at this branch
381
  `maxonsiteissueqty` int(4) default NULL, -- the maximum number of on-site checkouts this patron category can have at this branch
382
  PRIMARY KEY (`categorycode`, `branchcode`),
383
  CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
384
    ON DELETE CASCADE ON UPDATE CASCADE,
385
  CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
386
    ON DELETE CASCADE ON UPDATE CASCADE
387
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
388
389
--
390
-- Table structure for table `default_borrower_circ_rules`
391
--
392
393
DROP TABLE IF EXISTS `default_borrower_circ_rules`;
394
CREATE TABLE `default_borrower_circ_rules` ( -- default checkout rules found under "Default checkout, hold and return policy"
395
  `categorycode` VARCHAR(10) NOT NULL, -- patron category this rul
396
  `maxissueqty` int(4) default NULL,
397
  `maxonsiteissueqty` int(4) default NULL,
398
  PRIMARY KEY (`categorycode`),
399
  CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
400
    ON DELETE CASCADE ON UPDATE CASCADE
401
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
402
403
--
372
--
404
-- Table structure for table `default_branch_circ_rules`
373
-- Table structure for table `default_branch_circ_rules`
405
--
374
--
Lines 407-414 CREATE TABLE `default_borrower_circ_rules` ( -- default checkout rules found und Link Here
407
DROP TABLE IF EXISTS `default_branch_circ_rules`;
376
DROP TABLE IF EXISTS `default_branch_circ_rules`;
408
CREATE TABLE `default_branch_circ_rules` (
377
CREATE TABLE `default_branch_circ_rules` (
409
  `branchcode` VARCHAR(10) NOT NULL,
378
  `branchcode` VARCHAR(10) NOT NULL,
410
  `maxissueqty` int(4) default NULL,
411
  `maxonsiteissueqty` int(4) default NULL,
412
  `holdallowed` tinyint(1) default NULL,
379
  `holdallowed` tinyint(1) default NULL,
413
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
380
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
414
  `returnbranch` varchar(15) default NULL,
381
  `returnbranch` varchar(15) default NULL,
Lines 424-431 CREATE TABLE `default_branch_circ_rules` ( Link Here
424
DROP TABLE IF EXISTS `default_circ_rules`;
391
DROP TABLE IF EXISTS `default_circ_rules`;
425
CREATE TABLE `default_circ_rules` (
392
CREATE TABLE `default_circ_rules` (
426
    `singleton` enum('singleton') NOT NULL default 'singleton',
393
    `singleton` enum('singleton') NOT NULL default 'singleton',
427
    `maxissueqty` int(4) default NULL,
428
    `maxonsiteissueqty` int(4) default NULL,
429
    `holdallowed` int(1) default NULL,
394
    `holdallowed` int(1) default NULL,
430
    hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
395
    hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
431
    `returnbranch` varchar(15) default NULL,
396
    `returnbranch` varchar(15) default NULL,
Lines 870-877 CREATE TABLE `issuingrules` ( -- circulation and fine rules Link Here
870
  `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period
835
  `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period
871
  `accountsent` int(11) default NULL, -- not used? always NULL
836
  `accountsent` int(11) default NULL, -- not used? always NULL
872
  `chargename` varchar(100) default NULL, -- not used? always NULL
837
  `chargename` varchar(100) default NULL, -- not used? always NULL
873
  `maxissueqty` int(4) default NULL, -- total number of checkouts allowed
874
  `maxonsiteissueqty` int(4) default NULL, -- total number of on-site checkouts allowed
875
  `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit
838
  `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit
876
  `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours)
839
  `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours)
877
  `hardduedate` date default NULL, -- hard due date
840
  `hardduedate` date default NULL, -- hard due date
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-28 / +51 lines)
Lines 1-6 Link Here
1
[% USE Branches %]
1
[% USE Branches %]
2
[% USE Categories %]
2
[% USE CirculationRules %]
3
[% USE CirculationRules %]
3
[% SET footerjs = 1 %]
4
[% SET footerjs = 1 %]
5
6
[% SET branchcode = humanbranch %]
7
8
[% SET categorycodes = ['*'] %]
9
[% FOREACH pc IN patron_categories %]
10
    [% categorycodes.push( pc.id ) %]
11
[% END %]
12
4
[% INCLUDE 'doc-head-open.inc' %]
13
[% INCLUDE 'doc-head-open.inc' %]
5
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
14
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
6
[% INCLUDE 'doc-head-close.inc' %]
15
[% INCLUDE 'doc-head-close.inc' %]
Lines 116-133 Link Here
116
                                                          <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype %]&amp;categorycode=[% rule.categorycode %]&amp;branch=[% rule.current_branch %]"><i class="fa fa-trash"></i> Delete</a>
125
                                                          <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype %]&amp;categorycode=[% rule.categorycode %]&amp;branch=[% rule.current_branch %]"><i class="fa fa-trash"></i> Delete</a>
117
                                                        </td>
126
                                                        </td>
118
127
119
							<td>[% IF ( rule.unlimited_maxissueqty ) %]
128
							<td>
120
									Unlimited
129
                                [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxissueqty' ) %]
121
								[% ELSE %]
130
                                [% IF rule_value  %]
122
									[% rule.maxissueqty %]
131
                                    [% rule_value %]
123
								[% END %]
132
                                [% ELSE %]
124
							</td>
125
                            <td>[% IF rule.unlimited_maxonsiteissueqty %]
126
                                    Unlimited
133
                                    Unlimited
134
                                [% END %]
135
							</td>
136
							<td>
137
                                [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxonsiteissueqty' ) %]
138
                                [% IF rule_value  %]
139
                                    [% rule_value %]
127
                                [% ELSE %]
140
                                [% ELSE %]
128
                                    [% rule.maxonsiteissueqty %]
141
                                    Unlimited
129
                                [% END %]
142
                                [% END %]
130
                            </td>
143
							</td>
131
							<td>[% rule.issuelength %]</td>
144
							<td>[% rule.issuelength %]</td>
132
							<td>
145
							<td>
133
							    [% rule.lengthunit %]
146
							    [% rule.lengthunit %]
Lines 358-365 Link Here
358
                </tr>
371
                </tr>
359
                <tr>
372
                <tr>
360
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
373
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
361
                    <td><input type="text" name="maxissueqty" size="3" value="[% default_maxissueqty %]"/></td>
374
                    <td>
362
                    <td><input type="text" name="maxonsiteissueqty" size="3" value="[% default_maxonsiteissueqty %]"/></td>
375
                        [% SET maxissueqty  = CirculationRules.Get( branchcode, undef, undef, 'maxissueqty' ) %]
376
                        <input type="text" name="maxissueqty" size="3" value="[% maxissueqty %]"/>
377
                    </td>
378
                    <td>
379
                        [% SET maxonsiteissueqty  = CirculationRules.Get( branchcode, undef, undef, 'maxonsiteissueqty' ) %]
380
                        <input type="text" name="maxonsiteissueqty" size="3" value="[% maxonsiteissueqty %]"/>
381
                    </td>
363
                    <td>
382
                    <td>
364
                        [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %]
383
                        [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %]
365
                        <input name="max_holds" size="3" value="[% rule_value %]" />
384
                        <input name="max_holds" size="3" value="[% rule_value %]" />
Lines 475-517 Link Here
475
                    <th>Total holds allowed</th>
494
                    <th>Total holds allowed</th>
476
                    <th>&nbsp;</th>
495
                    <th>&nbsp;</th>
477
                </tr>
496
                </tr>
478
                [% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %]
497
                [% FOREACH c IN categorycodes %]
479
                    [% UNLESS ( loop.odd ) %]
498
                    [% SET maxissueqty = CirculationRules.Get( branchcode, c, undef, 'maxissueqty' ) %]
480
                    <tr class="highlight">
499
                    [% SET maxonsiteissueqty = CirculationRules.Get( branchcode, c, undef, 'maxonsiteissueqty' ) %]
481
                    [% ELSE %]
500
                    [% SET max_holds = CirculationRules.Get( branchcode, c, undef, 'max_holds' ) %]
501
502
                    [% IF maxissueqty || maxissueqty || max_holds %]
482
                    <tr>
503
                    <tr>
483
                    [% END %]
504
                        <td>
484
                        <td>[% IF ( branch_cat_rule_loo.default_humancategorycode ) %]
505
                            [% IF c == '*'%]
485
                                <em>Default</em>
506
                                <em>Default</em>
486
                            [% ELSE %]
507
                            [% ELSE %]
487
                                [% branch_cat_rule_loo.humancategorycode %]
508
                                [% Categories.GetName(c) %]
488
                            [% END %]
509
                            [% END %]
489
                        </td>
510
                        </td>
490
                        <td>[% IF ( branch_cat_rule_loo.unlimited_maxissueqty ) %]
511
                        <td>
491
                                Unlimited
512
                            [% IF maxissueqty  %]
513
                                [% maxissueqty %]
492
                            [% ELSE %]
514
                            [% ELSE %]
493
                                [% branch_cat_rule_loo.maxissueqty %]
515
                                Unlimited
494
                            [% END %]
516
                            [% END %]
495
                        </td>
517
                        </td>
496
                        <td>[% IF ( branch_cat_rule_loo.unlimited_maxonsiteissueqty ) %]
518
                        <td>
497
                                Unlimited
519
                            [% IF maxonsiteissueqty  %]
520
                                [% maxonsiteissueqty %]
498
                            [% ELSE %]
521
                            [% ELSE %]
499
                                [% branch_cat_rule_loo.maxonsiteissueqty %]
522
                                Unlimited
500
                            [% END %]
523
                            [% END %]
501
                        </td>
524
                        </td>
502
                        <td>
525
                        <td>
503
                            [% SET rule_value = CirculationRules.Get( branch_cat_rule_loo.branchcode, branch_cat_rule_loo.categorycode, branch_cat_rule_loo.itemtype, 'max_holds' ) %]
526
                            [% IF max_holds.defined && max_holds != ''  %]
504
                            [% IF rule_value.defined && rule_value != '' %]
527
                                [% max_holds %]
505
                                [% rule_value %]
506
                            [% ELSE %]
528
                            [% ELSE %]
507
                                Unlimited
529
                                Unlimited
508
                            [% END %]
530
                            [% END %]
509
                        </td>
531
                        </td>
510
532
511
                        <td class="actions">
533
                        <td class="actions">
512
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% branch_cat_rule_loo.categorycode %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
534
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% c %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
513
                        </td>
535
                        </td>
514
                    </tr>
536
                    </tr>
537
                    [% END %]
515
                [% END %]
538
                [% END %]
516
                <tr>
539
                <tr>
517
                    <td>
540
                    <td>
(-)a/t/db_dependent/Circulation.t (-7 / +19 lines)
Lines 36-41 use Koha::Database; Link Here
36
use Koha::IssuingRules;
36
use Koha::IssuingRules;
37
use Koha::Checkouts;
37
use Koha::Checkouts;
38
use Koha::Patrons;
38
use Koha::Patrons;
39
use Koha::CirculationRules;
39
use Koha::Subscriptions;
40
use Koha::Subscriptions;
40
use Koha::Account::Lines;
41
use Koha::Account::Lines;
41
use Koha::Account::Offsets;
42
use Koha::Account::Offsets;
Lines 180-193 is( Link Here
180
181
181
# Set a simple circ policy
182
# Set a simple circ policy
182
$dbh->do('DELETE FROM issuingrules');
183
$dbh->do('DELETE FROM issuingrules');
184
Koha::CirculationRules->search()->delete();
183
$dbh->do(
185
$dbh->do(
184
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed,
186
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed,
185
                                maxissueqty, issuelength, lengthunit,
187
                                issuelength, lengthunit,
186
                                renewalsallowed, renewalperiod,
188
                                renewalsallowed, renewalperiod,
187
                                norenewalbefore, auto_renew,
189
                                norenewalbefore, auto_renew,
188
                                fine, chargeperiod)
190
                                fine, chargeperiod)
189
      VALUES (?, ?, ?, ?,
191
      VALUES (?, ?, ?, ?,
190
              ?, ?, ?,
192
              ?, ?,
191
              ?, ?,
193
              ?, ?,
192
              ?, ?,
194
              ?, ?,
193
              ?, ?
195
              ?, ?
Lines 195-201 $dbh->do( Link Here
195
    },
197
    },
196
    {},
198
    {},
197
    '*', '*', '*', 25,
199
    '*', '*', '*', 25,
198
    20, 14, 'days',
200
    14, 'days',
199
    1, 7,
201
    1, 7,
200
    undef, 0,
202
    undef, 0,
201
    .10, 1
203
    .10, 1
Lines 1030-1047 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1030
    $dbh->do('DELETE FROM issues');
1032
    $dbh->do('DELETE FROM issues');
1031
    $dbh->do('DELETE FROM items');
1033
    $dbh->do('DELETE FROM items');
1032
    $dbh->do('DELETE FROM issuingrules');
1034
    $dbh->do('DELETE FROM issuingrules');
1035
    Koha::CirculationRules->search()->delete();
1033
    $dbh->do(
1036
    $dbh->do(
1034
        q{
1037
        q{
1035
        INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, maxissueqty, issuelength, lengthunit, renewalsallowed, renewalperiod,
1038
        INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, issuelength, lengthunit, renewalsallowed, renewalperiod,
1036
                    norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
1039
                    norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
1037
        },
1040
        },
1038
        {},
1041
        {},
1039
        '*', '*', '*', 25,
1042
        '*', '*', '*', 25,
1040
        20,  14,  'days',
1043
        14,  'days',
1041
        1,   7,
1044
        1,   7,
1042
        undef,  0,
1045
        undef,  0,
1043
        .10, 1
1046
        .10, 1
1044
    );
1047
    );
1048
    Koha::CirculationRules->set_rules(
1049
        {
1050
            categorycode => '*',
1051
            itemtype     => '*',
1052
            branchcode   => '*',
1053
            rules        => {
1054
                maxissueqty => 20
1055
            }
1056
        }
1057
    );
1045
    my ( $biblionumber, $biblioitemnumber ) = add_biblio();
1058
    my ( $biblionumber, $biblioitemnumber ) = add_biblio();
1046
1059
1047
    my $barcode1 = '1234';
1060
    my $barcode1 = '1234';
Lines 1666-1672 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1666
            categorycode => '*',
1679
            categorycode => '*',
1667
            itemtype     => '*',
1680
            itemtype     => '*',
1668
            branchcode   => '*',
1681
            branchcode   => '*',
1669
            maxissueqty  => 99,
1670
            issuelength  => 1,
1682
            issuelength  => 1,
1671
            firstremind  => 1,        # 1 day of grace
1683
            firstremind  => 1,        # 1 day of grace
1672
            finedays     => 2,        # 2 days of fine per day of overdue
1684
            finedays     => 2,        # 2 days of fine per day of overdue
(-)a/t/db_dependent/Circulation/Branch.t (-19 / +41 lines)
Lines 22-27 use C4::Members; Link Here
22
use C4::Circulation;
22
use C4::Circulation;
23
use C4::Items;
23
use C4::Items;
24
use C4::Context;
24
use C4::Context;
25
use Koha::CirculationRules;
25
26
26
use Test::More tests => 14;
27
use Test::More tests => 14;
27
use t::lib::Mocks;
28
use t::lib::Mocks;
Lines 52-58 $dbh->do(q|DELETE FROM categories|); Link Here
52
$dbh->do(q|DELETE FROM accountlines|);
53
$dbh->do(q|DELETE FROM accountlines|);
53
$dbh->do(q|DELETE FROM itemtypes|);
54
$dbh->do(q|DELETE FROM itemtypes|);
54
$dbh->do(q|DELETE FROM branch_item_rules|);
55
$dbh->do(q|DELETE FROM branch_item_rules|);
55
$dbh->do(q|DELETE FROM branch_borrower_circ_rules|);
56
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
56
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
57
$dbh->do(q|DELETE FROM default_circ_rules|);
57
$dbh->do(q|DELETE FROM default_circ_rules|);
58
$dbh->do(q|DELETE FROM default_branch_item_rules|);
58
$dbh->do(q|DELETE FROM default_branch_item_rules|);
Lines 151-181 is_deeply( Link Here
151
"Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined"
151
"Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined"
152
);
152
);
153
153
154
my $query = q|
154
Koha::CirculationRules->set_rules(
155
    INSERT INTO branch_borrower_circ_rules
155
    {
156
    (branchcode, categorycode, maxissueqty, maxonsiteissueqty)
156
        branchcode   => $samplebranch1->{branchcode},
157
    VALUES( ?, ?, ?, ? )
157
        categorycode => $samplecat->{categorycode},
158
|;
158
        itemtype     => undef,
159
159
        rules        => {
160
$dbh->do(
160
            maxissueqty       => 5,
161
    $query, {},
161
            maxonsiteissueqty => 6,
162
    $samplebranch1->{branchcode},
162
        }
163
    $samplecat->{categorycode}, 5, 6
163
    }
164
);
164
);
165
165
166
$query = q|
166
my $query = q|
167
    INSERT INTO default_branch_circ_rules
167
    INSERT INTO default_branch_circ_rules
168
    (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
168
    (branchcode, holdallowed, returnbranch)
169
    VALUES( ?, ?, ?, ?, ? )
169
    VALUES( ?, ?, ? )
170
|;
170
|;
171
$dbh->do( $query, {}, $samplebranch2->{branchcode},
171
$dbh->do( $query, {}, $samplebranch2->{branchcode}, 1, 'holdingbranch' );
172
    3, 2, 1, 'holdingbranch' );
172
Koha::CirculationRules->set_rules(
173
    {
174
        branchcode   => $samplebranch2->{branchcode},
175
        categorycode => undef,
176
        itemtype     => undef,
177
        rules        => {
178
            maxissueqty       => 3,
179
            maxonsiteissueqty => 2,
180
        }
181
    }
182
);
183
173
$query = q|
184
$query = q|
174
    INSERT INTO default_circ_rules
185
    INSERT INTO default_circ_rules
175
    (singleton, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
186
    (singleton, holdallowed, returnbranch)
176
    VALUES( ?, ?, ?, ?, ? )
187
    VALUES( ?, ?, ? )
177
|;
188
|;
178
$dbh->do( $query, {}, 'singleton', 4, 5, 3, 'homebranch' );
189
$dbh->do( $query, {}, 'singleton', 3, 'homebranch' );
190
Koha::CirculationRules->set_rules(
191
    {
192
        branchcode   => undef,
193
        categorycode => undef,
194
        itemtype     => undef,
195
        rules        => {
196
            maxissueqty       => 4,
197
            maxonsiteissueqty => 5,
198
        }
199
    }
200
);
179
201
180
$query =
202
$query =
181
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
203
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
(-)a/t/db_dependent/Circulation/GetHardDueDate.t (-15 / +1 lines)
Lines 117-124 my $sampleissuingrule1 = { Link Here
117
    chargename         => 'Null',
117
    chargename         => 'Null',
118
    restrictedtype     => 0,
118
    restrictedtype     => 0,
119
    accountsent        => 0,
119
    accountsent        => 0,
120
    maxissueqty        => 5,
121
    maxonsiteissueqty  => 4,
122
    finedays           => 0,
120
    finedays           => 0,
123
    lengthunit         => 'days',
121
    lengthunit         => 'days',
124
    renewalperiod      => 5,
122
    renewalperiod      => 5,
Lines 151-158 my $sampleissuingrule2 = { Link Here
151
    branchcode         => $samplebranch2->{branchcode},
149
    branchcode         => $samplebranch2->{branchcode},
152
    categorycode       => $samplecat->{categorycode},
150
    categorycode       => $samplecat->{categorycode},
153
    itemtype           => 'BOOK',
151
    itemtype           => 'BOOK',
154
    maxissueqty        => 2,
155
    maxonsiteissueqty  => 1,
156
    renewalsallowed    => 'Null',
152
    renewalsallowed    => 'Null',
157
    renewalperiod      => 2,
153
    renewalperiod      => 2,
158
    norenewalbefore    => 7,
154
    norenewalbefore    => 7,
Lines 184-191 my $sampleissuingrule3 = { Link Here
184
    branchcode         => $samplebranch1->{branchcode},
180
    branchcode         => $samplebranch1->{branchcode},
185
    categorycode       => $samplecat->{categorycode},
181
    categorycode       => $samplecat->{categorycode},
186
    itemtype           => 'DVD',
182
    itemtype           => 'DVD',
187
    maxissueqty        => 3,
188
    maxonsiteissueqty  => 2,
189
    renewalsallowed    => 'Null',
183
    renewalsallowed    => 'Null',
190
    renewalperiod      => 3,
184
    renewalperiod      => 3,
191
    norenewalbefore    => 8,
185
    norenewalbefore    => 8,
Lines 218-225 $query = 'INSERT INTO issuingrules ( Link Here
218
                branchcode,
212
                branchcode,
219
                categorycode,
213
                categorycode,
220
                itemtype,
214
                itemtype,
221
                maxissueqty,
222
                maxonsiteissueqty,
223
                renewalsallowed,
215
                renewalsallowed,
224
                renewalperiod,
216
                renewalperiod,
225
                norenewalbefore,
217
                norenewalbefore,
Lines 245-258 $query = 'INSERT INTO issuingrules ( Link Here
245
                opacitemholds,
237
                opacitemholds,
246
                cap_fine_to_replacement_price,
238
                cap_fine_to_replacement_price,
247
                article_requests
239
                article_requests
248
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
240
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
249
my $sth = $dbh->prepare($query);
241
my $sth = $dbh->prepare($query);
250
$sth->execute(
242
$sth->execute(
251
    $sampleissuingrule1->{branchcode},
243
    $sampleissuingrule1->{branchcode},
252
    $sampleissuingrule1->{categorycode},
244
    $sampleissuingrule1->{categorycode},
253
    $sampleissuingrule1->{itemtype},
245
    $sampleissuingrule1->{itemtype},
254
    $sampleissuingrule1->{maxissueqty},
255
    $sampleissuingrule1->{maxonsiteissueqty},
256
    $sampleissuingrule1->{renewalsallowed},
246
    $sampleissuingrule1->{renewalsallowed},
257
    $sampleissuingrule1->{renewalperiod},
247
    $sampleissuingrule1->{renewalperiod},
258
    $sampleissuingrule1->{norenewalbefore},
248
    $sampleissuingrule1->{norenewalbefore},
Lines 283-290 $sth->execute( Link Here
283
    $sampleissuingrule2->{branchcode},
273
    $sampleissuingrule2->{branchcode},
284
    $sampleissuingrule2->{categorycode},
274
    $sampleissuingrule2->{categorycode},
285
    $sampleissuingrule2->{itemtype},
275
    $sampleissuingrule2->{itemtype},
286
    $sampleissuingrule2->{maxissueqty},
287
    $sampleissuingrule2->{maxonsiteissueqty},
288
    $sampleissuingrule2->{renewalsallowed},
276
    $sampleissuingrule2->{renewalsallowed},
289
    $sampleissuingrule2->{renewalperiod},
277
    $sampleissuingrule2->{renewalperiod},
290
    $sampleissuingrule2->{norenewalbefore},
278
    $sampleissuingrule2->{norenewalbefore},
Lines 315-322 $sth->execute( Link Here
315
    $sampleissuingrule3->{branchcode},
303
    $sampleissuingrule3->{branchcode},
316
    $sampleissuingrule3->{categorycode},
304
    $sampleissuingrule3->{categorycode},
317
    $sampleissuingrule3->{itemtype},
305
    $sampleissuingrule3->{itemtype},
318
    $sampleissuingrule3->{maxissueqty},
319
    $sampleissuingrule3->{maxonsiteissueqty},
320
    $sampleissuingrule3->{renewalsallowed},
306
    $sampleissuingrule3->{renewalsallowed},
321
    $sampleissuingrule3->{renewalperiod},
307
    $sampleissuingrule3->{renewalperiod},
322
    $sampleissuingrule3->{norenewalbefore},
308
    $sampleissuingrule3->{norenewalbefore},
(-)a/t/db_dependent/Circulation/Returns.t (-1 lines)
Lines 54-60 my $rule = Koha::IssuingRule->new( Link Here
54
        categorycode => '*',
54
        categorycode => '*',
55
        itemtype     => '*',
55
        itemtype     => '*',
56
        branchcode   => '*',
56
        branchcode   => '*',
57
        maxissueqty  => 99,
58
        issuelength  => 1,
57
        issuelength  => 1,
59
    }
58
    }
60
);
59
);
(-)a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t (-13 / +25 lines)
Lines 27-32 use C4::Context; Link Here
27
use Koha::DateUtils qw( dt_from_string );
27
use Koha::DateUtils qw( dt_from_string );
28
use Koha::Database;
28
use Koha::Database;
29
use Koha::Checkouts;
29
use Koha::Checkouts;
30
use Koha::CirculationRules;
30
31
31
use t::lib::TestBuilder;
32
use t::lib::TestBuilder;
32
use t::lib::Mocks;
33
use t::lib::Mocks;
Lines 38-44 our $dbh = C4::Context->dbh; Link Here
38
39
39
$dbh->do(q|DELETE FROM branch_item_rules|);
40
$dbh->do(q|DELETE FROM branch_item_rules|);
40
$dbh->do(q|DELETE FROM issues|);
41
$dbh->do(q|DELETE FROM issues|);
41
$dbh->do(q|DELETE FROM branch_borrower_circ_rules|);
42
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
42
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
43
$dbh->do(q|DELETE FROM default_circ_rules|);
43
$dbh->do(q|DELETE FROM default_circ_rules|);
44
$dbh->do(q|DELETE FROM default_branch_item_rules|);
44
$dbh->do(q|DELETE FROM default_branch_item_rules|);
Lines 85-96 my $issuingrule = $builder->build({ Link Here
85
        branchcode         => $branch->{branchcode},
85
        branchcode         => $branch->{branchcode},
86
        categorycode       => '*',
86
        categorycode       => '*',
87
        itemtype           => '*',
87
        itemtype           => '*',
88
        maxissueqty        => 2,
89
        maxonsiteissueqty  => 1,
90
        lengthunit         => 'days',
88
        lengthunit         => 'days',
91
        issuelength        => 5,
89
        issuelength        => 5,
92
    },
90
    },
93
});
91
});
92
Koha::CirculationRules->search()->delete();
93
Koha::CirculationRules->set_rules(
94
    {
95
        branchcode   => $branch->{branchcode},
96
        categorycode => '*',
97
        itemtype     => '*',
98
        rules        => {
99
            maxissueqty       => 2,
100
            maxonsiteissueqty => 1,
101
        }
102
    }
103
);
94
104
95
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
105
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
96
C4::Context->set_userenv($patron->borrowernumber, $patron->userid, 'usercnum', 'First name', 'Surname', $branch->{branchcode}, 'My Library', 0);
106
C4::Context->set_userenv($patron->borrowernumber, $patron->userid, 'usercnum', 'First name', 'Surname', $branch->{branchcode}, 'My Library', 0);
Lines 148-163 my $yet_another_item = $builder->build({ Link Here
148
( $impossible, undef, undef, undef ) = C4::Circulation::CanBookBeIssued( $patron, $yet_another_item->{barcode} );
158
( $impossible, undef, undef, undef ) = C4::Circulation::CanBookBeIssued( $patron, $yet_another_item->{barcode} );
149
is( $impossible->{TOO_MANY}, 'TOO_MANY_CHECKOUTS', 'Not a specific case, $delta should not be incremented' );
159
is( $impossible->{TOO_MANY}, 'TOO_MANY_CHECKOUTS', 'Not a specific case, $delta should not be incremented' );
150
160
151
$dbh->do(q|DELETE FROM issuingrules|);
161
Koha::CirculationRules->search()->delete();
152
my $borrower_circ_rule = $builder->build({
162
Koha::CirculationRules->set_rules(
153
    source => 'DefaultCircRule',
163
    {
154
    value => {
164
        branchcode   => $branch->{branchcode},
155
        branchcode         => $branch->{branchcode},
165
        categorycode => '*',
156
        categorycode       => '*',
166
        itemtype     => '*',
157
        maxissueqty        => 2,
167
        rules        => {
158
        maxonsiteissueqty  => 1,
168
            maxissueqty       => 2,
159
    },
169
            maxonsiteissueqty => 1,
160
});
170
        }
171
    }
172
);
161
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} );
173
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} );
162
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 2 - Switch is allowed' );
174
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 2 - Switch is allowed' );
163
is( exists $impossible->{TOO_MANY}, '', 'Specific case 2 - Switch is allowed' );
175
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 198-205 $requesters{$branch_3} = AddMember( Link Here
198
198
199
$dbh->do('DELETE FROM issuingrules');
199
$dbh->do('DELETE FROM issuingrules');
200
$dbh->do('DELETE FROM branch_item_rules');
200
$dbh->do('DELETE FROM branch_item_rules');
201
$dbh->do('DELETE FROM branch_borrower_circ_rules');
202
$dbh->do('DELETE FROM default_borrower_circ_rules');
203
$dbh->do('DELETE FROM default_branch_item_rules');
201
$dbh->do('DELETE FROM default_branch_item_rules');
204
$dbh->do('DELETE FROM default_branch_circ_rules');
202
$dbh->do('DELETE FROM default_branch_circ_rules');
205
$dbh->do('DELETE FROM default_circ_rules');
203
$dbh->do('DELETE FROM default_circ_rules');
Lines 212-229 $dbh->do( Link Here
212
210
213
# CPL allows only its own patrons to request its items
211
# CPL allows only its own patrons to request its items
214
$dbh->do(
212
$dbh->do(
215
    q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
213
    q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch)
216
      VALUES (?, ?, ?, ?)},
214
      VALUES (?, ?, ?)},
217
    {},
215
    {},
218
    $branch_1, 10, 1, 'homebranch',
216
    $branch_1, 1, 'homebranch',
219
);
217
);
220
218
221
# ... while FPL allows anybody to request its items
219
# ... while FPL allows anybody to request its items
222
$dbh->do(
220
$dbh->do(
223
    q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
221
    q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch)
224
      VALUES (?, ?, ?, ?)},
222
      VALUES (?, ?, ?)},
225
    {},
223
    {},
226
    $branch_2, 10, 2, 'homebranch',
224
    $branch_2, 2, 'homebranch',
227
);
225
);
228
226
229
# helper biblio for the bug 10272 regression test
227
# helper biblio for the bug 10272 regression test
230
- 

Return to bug 18925