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

(-)a/C4/Circulation.pm (-54 / +71 lines)
Lines 386-395 sub TooMany { Link Here
386
 
386
 
387
    # given branch, patron category, and item type, determine
387
    # given branch, patron category, and item type, determine
388
    # applicable issuing rule
388
    # applicable issuing rule
389
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
389
    my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule(
390
        {   categorycode => $cat_borrower,
390
        {
391
            categorycode => $cat_borrower,
392
            itemtype     => $type,
393
            branchcode   => $branch,
394
            rule_name    => 'maxissueqty',
395
        }
396
    );
397
    my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule(
398
        {
399
            categorycode => $cat_borrower,
391
            itemtype     => $type,
400
            itemtype     => $type,
392
            branchcode   => $branch
401
            branchcode   => $branch,
402
            rule_name    => 'maxonsiteissueqty',
393
        }
403
        }
394
    );
404
    );
395
405
Lines 397-403 sub TooMany { Link Here
397
    # if a rule is found and has a loan limit set, count
407
    # if a rule is found and has a loan limit set, count
398
    # how many loans the patron already has that meet that
408
    # how many loans the patron already has that meet that
399
    # rule
409
    # rule
400
    if (defined($issuing_rule) and defined($issuing_rule->maxissueqty)) {
410
    if (defined($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) {
401
        my @bind_params;
411
        my @bind_params;
402
        my $count_query = q|
412
        my $count_query = q|
403
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
413
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
Lines 405-411 sub TooMany { Link Here
405
            JOIN items USING (itemnumber)
415
            JOIN items USING (itemnumber)
406
        |;
416
        |;
407
417
408
        my $rule_itemtype = $issuing_rule->itemtype;
418
        my $rule_itemtype = $maxissueqty_rule->itemtype;
409
        if ($rule_itemtype eq "*") {
419
        if ($rule_itemtype eq "*") {
410
            # matching rule has the default item type, so count only
420
            # matching rule has the default item type, so count only
411
            # those existing loans that don't fall under a more
421
            # those existing loans that don't fall under a more
Lines 426-433 sub TooMany { Link Here
426
                                    AND   itemtype <> '*'
436
                                    AND   itemtype <> '*'
427
                                  ) ";
437
                                  ) ";
428
            }
438
            }
429
            push @bind_params, $issuing_rule->branchcode;
439
            push @bind_params, $maxissueqty_rule->branchcode;
430
            push @bind_params, $issuing_rule->categorycode;
440
            push @bind_params, $maxissueqty_rule->categorycode;
431
            push @bind_params, $cat_borrower;
441
            push @bind_params, $cat_borrower;
432
        } else {
442
        } else {
433
            # rule has specific item type, so count loans of that
443
            # rule has specific item type, so count loans of that
Lines 443-449 sub TooMany { Link Here
443
453
444
        $count_query .= " AND borrowernumber = ? ";
454
        $count_query .= " AND borrowernumber = ? ";
445
        push @bind_params, $borrower->{'borrowernumber'};
455
        push @bind_params, $borrower->{'borrowernumber'};
446
        my $rule_branch = $issuing_rule->branchcode;
456
        my $rule_branch = $maxissueqty_rule->branchcode;
447
        if ($rule_branch ne "*") {
457
        if ($rule_branch ne "*") {
448
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
458
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
449
                $count_query .= " AND issues.branchcode = ? ";
459
                $count_query .= " AND issues.branchcode = ? ";
Lines 458-465 sub TooMany { Link Here
458
468
459
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
469
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
460
470
461
        my $max_checkouts_allowed = $issuing_rule->maxissueqty;
471
        my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : 0;
462
        my $max_onsite_checkouts_allowed = $issuing_rule->maxonsiteissueqty;
472
        my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : 0;
463
473
464
        if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
474
        if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
465
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
475
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
Lines 544-550 sub TooMany { Link Here
544
        }
554
        }
545
    }
555
    }
546
556
547
    if ( not defined( $issuing_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) {
557
    if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) {
548
        return { reason => 'NO_RULE_DEFINED', max_allowed => 0 };
558
        return { reason => 'NO_RULE_DEFINED', max_allowed => 0 };
549
    }
559
    }
550
560
Lines 1570-1583 maxonsiteissueqty - maximum of on-site checkouts that a Link Here
1570
patron of the given category can have at the given
1580
patron of the given category can have at the given
1571
branch.  If the value is undef, no limit.
1581
branch.  If the value is undef, no limit.
1572
1582
1573
This will first check for a specific branch and
1583
This will check for different branch/category combinations in the following order:
1574
category match from branch_borrower_circ_rules. 
1584
branch and category
1575
1585
branch only
1576
If no rule is found, it will then check default_branch_circ_rules
1586
category only
1577
(same branch, default category).  If no rule is found,
1587
default branch and category
1578
it will then check default_borrower_circ_rules (default 
1579
branch, same category), then failing that, default_circ_rules
1580
(default branch, default category).
1581
1588
1582
If no rule has been found in the database, it will default to
1589
If no rule has been found in the database, it will default to
1583
the buillt in rule:
1590
the buillt in rule:
Lines 1594-1637 wildcards. Link Here
1594
sub GetBranchBorrowerCircRule {
1601
sub GetBranchBorrowerCircRule {
1595
    my ( $branchcode, $categorycode ) = @_;
1602
    my ( $branchcode, $categorycode ) = @_;
1596
1603
1597
    my $rules;
1604
    # Set search prededences
1598
    my $dbh = C4::Context->dbh();
1605
    my @params = (
1599
    $rules = $dbh->selectrow_hashref( q|
1606
        {
1600
        SELECT maxissueqty, maxonsiteissueqty
1607
            branchcode   => $branchcode,
1601
        FROM branch_borrower_circ_rules
1608
            categorycode => $categorycode,
1602
        WHERE branchcode = ?
1609
            itemtype     => undef,
1603
        AND   categorycode = ?
1610
        },
1604
    |, {}, $branchcode, $categorycode ) ;
1611
        {
1605
    return $rules if $rules;
1612
            branchcode   => $branchcode,
1606
1613
            categorycode => undef,
1607
    # try same branch, default borrower category
1614
            itemtype     => undef,
1608
    $rules = $dbh->selectrow_hashref( q|
1615
        },
1609
        SELECT maxissueqty, maxonsiteissueqty
1616
        {
1610
        FROM default_branch_circ_rules
1617
            branchcode   => undef,
1611
        WHERE branchcode = ?
1618
            categorycode => $categorycode,
1612
    |, {}, $branchcode ) ;
1619
            itemtype     => undef,
1613
    return $rules if $rules;
1620
        },
1614
1621
        {
1615
    # try default branch, same borrower category
1622
            branchcode   => undef,
1616
    $rules = $dbh->selectrow_hashref( q|
1623
            categorycode => undef,
1617
        SELECT maxissueqty, maxonsiteissueqty
1624
            itemtype     => undef,
1618
        FROM default_borrower_circ_rules
1625
        },
1619
        WHERE categorycode = ?
1626
    );
1620
    |, {}, $categorycode ) ;
1621
    return $rules if $rules;
1622
1623
    # try default branch, default borrower category
1624
    $rules = $dbh->selectrow_hashref( q|
1625
        SELECT maxissueqty, maxonsiteissueqty
1626
        FROM default_circ_rules
1627
    |, {} );
1628
    return $rules if $rules;
1629
1627
1630
    # built-in default circulation rule
1628
    # Initialize default values
1631
    return {
1629
    my $rules = {
1632
        maxissueqty => undef,
1630
        maxissueqty       => undef,
1633
        maxonsiteissueqty => undef,
1631
        maxonsiteissueqty => undef,
1634
    };
1632
    };
1633
1634
    # Search for rules!
1635
    foreach my $rule_name (qw( maxissueqty maxonsiteissueqty )) {
1636
        foreach my $params (@params) {
1637
            my $rule = Koha::CirculationRules->search(
1638
                {
1639
                    rule_name => $rule_name,
1640
                    %$params,
1641
                }
1642
            )->next();
1643
1644
            if ( $rule ) {
1645
                $rules->{$rule_name} = $rule->rule_value;
1646
                last;
1647
            }
1648
        }
1649
    }
1650
1651
    return $rules;
1635
}
1652
}
1636
1653
1637
=head2 GetBranchItemRule
1654
=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 79-106 elsif ($op eq 'delete-branch-cat') { Link Here
79
        if ($categorycode eq "*") {
79
        if ($categorycode eq "*") {
80
            my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
80
            my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
81
            $sth_delete->execute();
81
            $sth_delete->execute();
82
        } else {
83
            my $sth_delete = $dbh->prepare("DELETE FROM default_borrower_circ_rules
84
                                            WHERE categorycode = ?");
85
            $sth_delete->execute($categorycode);
86
        }
82
        }
87
    } elsif ($categorycode eq "*") {
83
    } elsif ($categorycode eq "*") {
88
        my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
84
        my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
89
                                        WHERE branchcode = ?");
85
                                        WHERE branchcode = ?");
90
        $sth_delete->execute($branch);
86
        $sth_delete->execute($branch);
91
    } else {
92
        my $sth_delete = $dbh->prepare("DELETE FROM branch_borrower_circ_rules
93
                                        WHERE branchcode = ?
94
                                        AND categorycode = ?");
95
        $sth_delete->execute($branch, $categorycode);
96
    }
87
    }
97
    Koha::CirculationRules->set_rule(
88
    Koha::CirculationRules->set_rules(
98
        {
89
        {
99
            branchcode   => $branch,
90
            categorycode => $categorycode eq '*' ? undef : $categorycode,
100
            categorycode => $categorycode,
91
            branchcode   => $branch eq '*'       ? undef : $branch,
101
            itemtype     => undef,
92
            itemtype     => undef,
102
            rule_name    => 'max_holds',
93
            rules        => {
103
            rule_value   => undef,
94
                max_holds         => undef,
95
                maxissueqty       => undef,
96
                maxonsiteissueqty => undef,
97
            }
104
        }
98
        }
105
    );
99
    );
106
}
100
}
Lines 181-188 elsif ($op eq 'add') { Link Here
181
        firstremind                   => $firstremind,
175
        firstremind                   => $firstremind,
182
        chargeperiod                  => $chargeperiod,
176
        chargeperiod                  => $chargeperiod,
183
        chargeperiod_charge_at        => $chargeperiod_charge_at,
177
        chargeperiod_charge_at        => $chargeperiod_charge_at,
184
        maxissueqty                   => $maxissueqty,
185
        maxonsiteissueqty             => $maxonsiteissueqty,
186
        renewalsallowed               => $renewalsallowed,
178
        renewalsallowed               => $renewalsallowed,
187
        renewalperiod                 => $renewalperiod,
179
        renewalperiod                 => $renewalperiod,
188
        norenewalbefore               => $norenewalbefore,
180
        norenewalbefore               => $norenewalbefore,
Lines 210-215 elsif ($op eq 'add') { Link Here
210
        Koha::IssuingRule->new()->set($params)->store();
202
        Koha::IssuingRule->new()->set($params)->store();
211
    }
203
    }
212
204
205
    Koha::CirculationRules->set_rules(
206
        {
207
            categorycode => $bor,
208
            itemtype     => $itemtype,
209
            branchcode   => $br,
210
            rules        => {
211
                maxissueqty       => $maxissueqty,
212
                maxonsiteissueqty => $maxonsiteissueqty,
213
            }
214
        }
215
    );
216
213
}
217
}
214
elsif ($op eq "set-branch-defaults") {
218
elsif ($op eq "set-branch-defaults") {
215
    my $categorycode  = $input->param('categorycode');
219
    my $categorycode  = $input->param('categorycode');
Lines 232-266 elsif ($op eq "set-branch-defaults") { Link Here
232
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
236
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
233
                                        FROM default_circ_rules");
237
                                        FROM default_circ_rules");
234
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
238
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
235
                                        (maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
239
                                        (holdallowed, hold_fulfillment_policy, returnbranch)
236
                                        VALUES (?, ?, ?, ?, ?)");
240
                                        VALUES (?, ?, ?)");
237
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
241
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
238
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
242
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
239
243
240
        $sth_search->execute();
244
        $sth_search->execute();
241
        my $res = $sth_search->fetchrow_hashref();
245
        my $res = $sth_search->fetchrow_hashref();
242
        if ($res->{total}) {
246
        if ($res->{total}) {
243
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
247
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
244
        } else {
248
        } else {
245
            $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
249
            $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
246
        }
250
        }
251
252
        Koha::CirculationRules->set_rules(
253
            {
254
                categorycode => undef,
255
                itemtype     => undef,
256
                branchcode   => undef,
257
                rules        => {
258
                    maxissueqty       => $maxissueqty,
259
                    maxonsiteissueqty => $maxonsiteissueqty,
260
                }
261
            }
262
        );
247
    } else {
263
    } else {
248
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
264
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
249
                                        FROM default_branch_circ_rules
265
                                        FROM default_branch_circ_rules
250
                                        WHERE branchcode = ?");
266
                                        WHERE branchcode = ?");
251
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
267
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
252
                                        (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
268
                                        (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
253
                                        VALUES (?, ?, ?, ?, ?, ?)");
269
                                        VALUES (?, ?, ?, ?)");
254
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
270
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
255
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
271
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
256
                                        WHERE branchcode = ?");
272
                                        WHERE branchcode = ?");
257
        $sth_search->execute($branch);
273
        $sth_search->execute($branch);
258
        my $res = $sth_search->fetchrow_hashref();
274
        my $res = $sth_search->fetchrow_hashref();
259
        if ($res->{total}) {
275
        if ($res->{total}) {
260
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
276
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
261
        } else {
277
        } else {
262
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
278
            $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch);
263
        }
279
        }
280
281
        Koha::CirculationRules->set_rules(
282
            {
283
                categorycode => undef,
284
                itemtype     => undef,
285
                branchcode   => $branch,
286
                rules        => {
287
                    maxissueqty       => $maxissueqty,
288
                    maxonsiteissueqty => $maxonsiteissueqty,
289
                }
290
            }
291
        );
264
    }
292
    }
265
    Koha::CirculationRules->set_rule(
293
    Koha::CirculationRules->set_rule(
266
        {
294
        {
Lines 285-408 elsif ($op eq "add-branch-cat") { Link Here
285
313
286
    if ($branch eq "*") {
314
    if ($branch eq "*") {
287
        if ($categorycode eq "*") {
315
        if ($categorycode eq "*") {
288
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
316
            Koha::CirculationRules->set_rules(
289
                                            FROM default_circ_rules");
290
            my $sth_insert = $dbh->prepare(q|
291
                INSERT INTO default_circ_rules
292
                    (maxissueqty, maxonsiteissueqty)
293
                    VALUES (?, ?)
294
            |);
295
            my $sth_update = $dbh->prepare(q|
296
                UPDATE default_circ_rules
297
                SET maxissueqty = ?,
298
                    maxonsiteissueqty = ?
299
            |);
300
301
            $sth_search->execute();
302
            my $res = $sth_search->fetchrow_hashref();
303
            if ($res->{total}) {
304
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty );
305
            } else {
306
                $sth_insert->execute( $maxissueqty, $maxonsiteissueqty );
307
            }
308
309
            Koha::CirculationRules->set_rule(
310
                {
317
                {
311
                    branchcode   => undef,
312
                    categorycode => undef,
318
                    categorycode => undef,
313
                    itemtype     => undef,
319
                    itemtype     => undef,
314
                    rule_name    => 'max_holds',
320
                    branchcode   => undef,
315
                    rule_value   => $max_holds,
321
                    rules        => {
322
                        max_holds         => $max_holds,
323
                        maxissueqty       => $maxissueqty,
324
                        maxonsiteissueqty => $maxonsiteissueqty,
325
                    }
316
                }
326
                }
317
            );
327
            );
318
        } else {
328
        } else {
319
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
329
            Koha::CirculationRules->set_rules(
320
                                            FROM default_borrower_circ_rules
321
                                            WHERE categorycode = ?");
322
            my $sth_insert = $dbh->prepare(q|
323
                INSERT INTO default_borrower_circ_rules
324
                    (categorycode, maxissueqty, maxonsiteissueqty)
325
                    VALUES (?, ?, ?)
326
            |);
327
            my $sth_update = $dbh->prepare(q|
328
                UPDATE default_borrower_circ_rules
329
                SET maxissueqty = ?,
330
                    maxonsiteissueqty = ?
331
                WHERE categorycode = ?
332
            |);
333
            $sth_search->execute($categorycode);
334
            my $res = $sth_search->fetchrow_hashref();
335
            if ($res->{total}) {
336
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode );
337
            } else {
338
                $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty );
339
            }
340
341
            Koha::CirculationRules->set_rule(
342
                {
330
                {
343
                    branchcode   => '*',
331
                    branchcode   => '*',
344
                    categorycode => $categorycode,
332
                    categorycode => $categorycode,
345
                    itemtype     => undef,
333
                    itemtype     => undef,
346
                    rule_name    => 'max_holds',
334
                    rules        => {
347
                    rule_value   => $max_holds,
335
                        max_holds         => $max_holds,
336
                        maxissueqty       => $maxissueqty,
337
                        maxonsiteissueqty => $maxonsiteissueqty,
338
                    }
348
                }
339
                }
349
            );
340
            );
350
        }
341
        }
351
    } elsif ($categorycode eq "*") {
342
    } elsif ($categorycode eq "*") {
352
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
343
        Koha::CirculationRules->set_rules(
353
                                        FROM default_branch_circ_rules
354
                                        WHERE branchcode = ?");
355
        my $sth_insert = $dbh->prepare(q|
356
            INSERT INTO default_branch_circ_rules
357
            (branchcode, maxissueqty, maxonsiteissueqty)
358
            VALUES (?, ?, ?)
359
        |);
360
        my $sth_update = $dbh->prepare(q|
361
            UPDATE default_branch_circ_rules
362
            SET maxissueqty = ?,
363
                maxonsiteissueqty = ?
364
            WHERE branchcode = ?
365
        |);
366
        $sth_search->execute($branch);
367
        my $res = $sth_search->fetchrow_hashref();
368
        if ($res->{total}) {
369
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch);
370
        } else {
371
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty);
372
        }
373
    } else {
374
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
375
                                        FROM branch_borrower_circ_rules
376
                                        WHERE branchcode = ?
377
                                        AND   categorycode = ?");
378
        my $sth_insert = $dbh->prepare(q|
379
            INSERT INTO branch_borrower_circ_rules
380
            (branchcode, categorycode, maxissueqty, maxonsiteissueqty)
381
            VALUES (?, ?, ?, ?)
382
        |);
383
        my $sth_update = $dbh->prepare(q|
384
            UPDATE branch_borrower_circ_rules
385
            SET maxissueqty = ?,
386
                maxonsiteissueqty = ?
387
            WHERE branchcode = ?
388
            AND categorycode = ?
389
        |);
390
391
        $sth_search->execute($branch, $categorycode);
392
        my $res = $sth_search->fetchrow_hashref();
393
        if ($res->{total}) {
394
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch, $categorycode);
395
        } else {
396
            $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty);
397
        }
398
399
        Koha::CirculationRules->set_rule(
400
            {
344
            {
345
                categorycode => undef,
346
                itemtype     => undef,
401
                branchcode   => $branch,
347
                branchcode   => $branch,
348
                rules        => {
349
                    max_holds         => $max_holds,
350
                    maxissueqty       => $maxissueqty,
351
                    maxonsiteissueqty => $maxonsiteissueqty,
352
                }
353
            }
354
        );
355
    } else {
356
        Koha::CirculationRules->set_rules(
357
            {
402
                categorycode => $categorycode,
358
                categorycode => $categorycode,
403
                itemtype     => undef,
359
                itemtype     => undef,
404
                rule_name    => 'max_holds',
360
                branchcode   => $branch,
405
                rule_value   => $max_holds,
361
                rules        => {
362
                    max_holds         => $max_holds,
363
                    maxissueqty       => $maxissueqty,
364
                    maxonsiteissueqty => $maxonsiteissueqty,
365
                }
406
            }
366
            }
407
        );
367
        );
408
    }
368
    }
Lines 570-608 while (my $row = $sth2->fetchrow_hashref) { Link Here
570
530
571
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
531
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
572
532
573
my $sth_branch_cat;
574
if ($branch eq "*") {
575
    $sth_branch_cat = $dbh->prepare("
576
        SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode
577
        FROM default_borrower_circ_rules
578
        JOIN categories USING (categorycode)
579
580
    ");
581
    $sth_branch_cat->execute();
582
} else {
583
    $sth_branch_cat = $dbh->prepare("
584
        SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode
585
        FROM branch_borrower_circ_rules
586
        JOIN categories USING (categorycode)
587
        WHERE branch_borrower_circ_rules.branchcode = ?
588
    ");
589
    $sth_branch_cat->execute($branch);
590
}
591
592
my @branch_cat_rules = ();
593
while (my $row = $sth_branch_cat->fetchrow_hashref) {
594
    push @branch_cat_rules, $row;
595
}
596
my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humancategorycode'} } @branch_cat_rules;
597
598
# note undef maxissueqty so that template can deal with them
599
foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) {
600
    $entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty});
601
    $entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty});
602
}
603
604
@sorted_row_loop = sort by_category_and_itemtype @row_loop;
605
606
my $sth_branch_item;
533
my $sth_branch_item;
607
if ($branch eq "*") {
534
if ($branch eq "*") {
608
    $sth_branch_item = $dbh->prepare("
535
    $sth_branch_item = $dbh->prepare("
Lines 643-649 foreach my $entry (@sorted_branch_item_rules) { Link Here
643
570
644
$template->param(show_branch_cat_rule_form => 1);
571
$template->param(show_branch_cat_rule_form => 1);
645
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules);
572
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules);
646
$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules);
647
573
648
my $sth_defaults;
574
my $sth_defaults;
649
if ($branch eq "*") {
575
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 339-375 CREATE TABLE collections_tracking ( Link Here
339
  PRIMARY KEY (collections_tracking_id)
339
  PRIMARY KEY (collections_tracking_id)
340
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
340
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
341
341
342
--
343
-- Table structure for table `branch_borrower_circ_rules`
344
--
345
346
DROP TABLE IF EXISTS `branch_borrower_circ_rules`;
347
CREATE TABLE `branch_borrower_circ_rules` ( -- includes default circulation rules for patron categories found under "Checkout limit by patron category"
348
  `branchcode` VARCHAR(10) NOT NULL, -- the branch this rule applies to (branches.branchcode)
349
  `categorycode` VARCHAR(10) NOT NULL, -- the patron category this rule applies to (categories.categorycode)
350
  `maxissueqty` int(4) default NULL, -- the maximum number of checkouts this patron category can have at this branch
351
  `maxonsiteissueqty` int(4) default NULL, -- the maximum number of on-site checkouts this patron category can have at this branch
352
  PRIMARY KEY (`categorycode`, `branchcode`),
353
  CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
354
    ON DELETE CASCADE ON UPDATE CASCADE,
355
  CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
356
    ON DELETE CASCADE ON UPDATE CASCADE
357
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
358
359
--
360
-- Table structure for table `default_borrower_circ_rules`
361
--
362
363
DROP TABLE IF EXISTS `default_borrower_circ_rules`;
364
CREATE TABLE `default_borrower_circ_rules` ( -- default checkout rules found under "Default checkout, hold and return policy"
365
  `categorycode` VARCHAR(10) NOT NULL, -- patron category this rul
366
  `maxissueqty` int(4) default NULL,
367
  `maxonsiteissueqty` int(4) default NULL,
368
  PRIMARY KEY (`categorycode`),
369
  CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
370
    ON DELETE CASCADE ON UPDATE CASCADE
371
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
372
373
--
342
--
374
-- Table structure for table `default_branch_circ_rules`
343
-- Table structure for table `default_branch_circ_rules`
375
--
344
--
Lines 377-384 CREATE TABLE `default_borrower_circ_rules` ( -- default checkout rules found und Link Here
377
DROP TABLE IF EXISTS `default_branch_circ_rules`;
346
DROP TABLE IF EXISTS `default_branch_circ_rules`;
378
CREATE TABLE `default_branch_circ_rules` (
347
CREATE TABLE `default_branch_circ_rules` (
379
  `branchcode` VARCHAR(10) NOT NULL,
348
  `branchcode` VARCHAR(10) NOT NULL,
380
  `maxissueqty` int(4) default NULL,
381
  `maxonsiteissueqty` int(4) default NULL,
382
  `holdallowed` tinyint(1) default NULL,
349
  `holdallowed` tinyint(1) default NULL,
383
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
350
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
384
  `returnbranch` varchar(15) default NULL,
351
  `returnbranch` varchar(15) default NULL,
Lines 394-401 CREATE TABLE `default_branch_circ_rules` ( Link Here
394
DROP TABLE IF EXISTS `default_circ_rules`;
361
DROP TABLE IF EXISTS `default_circ_rules`;
395
CREATE TABLE `default_circ_rules` (
362
CREATE TABLE `default_circ_rules` (
396
    `singleton` enum('singleton') NOT NULL default 'singleton',
363
    `singleton` enum('singleton') NOT NULL default 'singleton',
397
    `maxissueqty` int(4) default NULL,
398
    `maxonsiteissueqty` int(4) default NULL,
399
    `holdallowed` int(1) default NULL,
364
    `holdallowed` int(1) default NULL,
400
    hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
365
    hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
401
    `returnbranch` varchar(15) default NULL,
366
    `returnbranch` varchar(15) default NULL,
Lines 841-848 CREATE TABLE `issuingrules` ( -- circulation and fine rules Link Here
841
  `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period
806
  `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period
842
  `accountsent` int(11) default NULL, -- not used? always NULL
807
  `accountsent` int(11) default NULL, -- not used? always NULL
843
  `chargename` varchar(100) default NULL, -- not used? always NULL
808
  `chargename` varchar(100) default NULL, -- not used? always NULL
844
  `maxissueqty` int(4) default NULL, -- total number of checkouts allowed
845
  `maxonsiteissueqty` int(4) default NULL, -- total number of on-site checkouts allowed
846
  `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit
809
  `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit
847
  `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours)
810
  `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours)
848
  `hardduedate` date default NULL, -- hard due date
811
  `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 114-131 Link Here
114
                                                          <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>
123
                                                          <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>
115
                                                        </td>
124
                                                        </td>
116
125
117
							<td>[% IF ( rule.unlimited_maxissueqty ) %]
126
							<td>
118
									Unlimited
127
                                [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxissueqty' ) %]
119
								[% ELSE %]
128
                                [% IF rule_value  %]
120
									[% rule.maxissueqty %]
129
                                    [% rule_value %]
121
								[% END %]
130
                                [% ELSE %]
122
							</td>
123
                            <td>[% IF rule.unlimited_maxonsiteissueqty %]
124
                                    Unlimited
131
                                    Unlimited
132
                                [% END %]
133
							</td>
134
							<td>
135
                                [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxonsiteissueqty' ) %]
136
                                [% IF rule_value  %]
137
                                    [% rule_value %]
125
                                [% ELSE %]
138
                                [% ELSE %]
126
                                    [% rule.maxonsiteissueqty %]
139
                                    Unlimited
127
                                [% END %]
140
                                [% END %]
128
                            </td>
141
							</td>
129
							<td>[% rule.issuelength %]</td>
142
							<td>[% rule.issuelength %]</td>
130
							<td>
143
							<td>
131
							    [% rule.lengthunit %]
144
							    [% rule.lengthunit %]
Lines 356-363 Link Here
356
                </tr>
369
                </tr>
357
                <tr>
370
                <tr>
358
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
371
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
359
                    <td><input type="text" name="maxissueqty" size="3" value="[% default_maxissueqty %]"/></td>
372
                    <td>
360
                    <td><input type="text" name="maxonsiteissueqty" size="3" value="[% default_maxonsiteissueqty %]"/></td>
373
                        [% SET maxissueqty  = CirculationRules.Get( branchcode, undef, undef, 'maxissueqty' ) %]
374
                        <input type="text" name="maxissueqty" size="3" value="[% maxissueqty %]"/>
375
                    </td>
376
                    <td>
377
                        [% SET maxonsiteissueqty  = CirculationRules.Get( branchcode, undef, undef, 'maxonsiteissueqty' ) %]
378
                        <input type="text" name="maxonsiteissueqty" size="3" value="[% maxonsiteissueqty %]"/>
379
                    </td>
361
                    <td>
380
                    <td>
362
                        [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %]
381
                        [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %]
363
                        <input name="max_holds" size="3" value="[% rule_value %]" />
382
                        <input name="max_holds" size="3" value="[% rule_value %]" />
Lines 472-514 Link Here
472
                    <th>Total current on-site checkouts allowed</th>
491
                    <th>Total current on-site checkouts allowed</th>
473
                    <th>&nbsp;</th>
492
                    <th>&nbsp;</th>
474
                </tr>
493
                </tr>
475
                [% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %]
494
                [% FOREACH c IN categorycodes %]
476
                    [% UNLESS ( loop.odd ) %]
495
                    [% SET maxissueqty = CirculationRules.Get( branchcode, c, undef, 'maxissueqty' ) %]
477
                    <tr class="highlight">
496
                    [% SET maxonsiteissueqty = CirculationRules.Get( branchcode, c, undef, 'maxonsiteissueqty' ) %]
478
                    [% ELSE %]
497
                    [% SET max_holds = CirculationRules.Get( branchcode, c, undef, 'max_holds' ) %]
498
499
                    [% IF maxissueqty || maxissueqty || max_holds %]
479
                    <tr>
500
                    <tr>
480
                    [% END %]
501
                        <td>
481
                        <td>[% IF ( branch_cat_rule_loo.default_humancategorycode ) %]
502
                            [% IF c == '*'%]
482
                                <em>Default</em>
503
                                <em>Default</em>
483
                            [% ELSE %]
504
                            [% ELSE %]
484
                                [% branch_cat_rule_loo.humancategorycode %]
505
                                [% Categories.GetName(c) %]
485
                            [% END %]
506
                            [% END %]
486
                        </td>
507
                        </td>
487
                        <td>[% IF ( branch_cat_rule_loo.unlimited_maxissueqty ) %]
508
                        <td>
488
                                Unlimited
509
                            [% IF maxissueqty  %]
510
                                [% maxissueqty %]
489
                            [% ELSE %]
511
                            [% ELSE %]
490
                                [% branch_cat_rule_loo.maxissueqty %]
512
                                Unlimited
491
                            [% END %]
513
                            [% END %]
492
                        </td>
514
                        </td>
493
                        <td>[% IF ( branch_cat_rule_loo.unlimited_maxonsiteissueqty ) %]
515
                        <td>
494
                                Unlimited
516
                            [% IF maxonsiteissueqty  %]
517
                                [% maxonsiteissueqty %]
495
                            [% ELSE %]
518
                            [% ELSE %]
496
                                [% branch_cat_rule_loo.maxonsiteissueqty %]
519
                                Unlimited
497
                            [% END %]
520
                            [% END %]
498
                        </td>
521
                        </td>
499
                        <td>
522
                        <td>
500
                            [% SET rule_value = CirculationRules.Get( branch_cat_rule_loo.branchcode, branch_cat_rule_loo.categorycode, branch_cat_rule_loo.itemtype, 'max_holds' ) %]
523
                            [% IF max_holds.defined && max_holds != ''  %]
501
                            [% IF rule_value.defined && rule_value != '' %]
524
                                [% max_holds %]
502
                                [% rule_value %]
503
                            [% ELSE %]
525
                            [% ELSE %]
504
                                Unlimited
526
                                Unlimited
505
                            [% END %]
527
                            [% END %]
506
                        </td>
528
                        </td>
507
529
508
                        <td class="actions">
530
                        <td class="actions">
509
                            <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>
531
                            <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>
510
                        </td>
532
                        </td>
511
                    </tr>
533
                    </tr>
534
                    [% END %]
512
                [% END %]
535
                [% END %]
513
                <tr>
536
                <tr>
514
                    <td>
537
                    <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 (-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 151-159 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,
152
    renewalsallowed    => 'Null',
155
    maxonsiteissueqty  => 1,
156
    renewalsallowed    => 0,
157
    renewalperiod      => 2,
153
    renewalperiod      => 2,
158
    norenewalbefore    => 7,
154
    norenewalbefore    => 7,
159
    auto_renew         => 0,
155
    auto_renew         => 0,
Lines 184-192 my $sampleissuingrule3 = { Link Here
184
    branchcode         => $samplebranch1->{branchcode},
180
    branchcode         => $samplebranch1->{branchcode},
185
    categorycode       => $samplecat->{categorycode},
181
    categorycode       => $samplecat->{categorycode},
186
    itemtype           => 'DVD',
182
    itemtype           => 'DVD',
187
    maxissueqty        => 3,
183
    renewalsallowed    => 'Null',
188
    maxonsiteissueqty  => 2,
189
    renewalsallowed    => 0,
190
    renewalperiod      => 3,
184
    renewalperiod      => 3,
191
    norenewalbefore    => 8,
185
    norenewalbefore    => 8,
192
    auto_renew         => 0,
186
    auto_renew         => 0,
Lines 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