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

(-)a/C4/Circulation.pm (-54 / +71 lines)
Lines 387-396 sub TooMany { Link Here
387
 
387
 
388
    # given branch, patron category, and item type, determine
388
    # given branch, patron category, and item type, determine
389
    # applicable issuing rule
389
    # applicable issuing rule
390
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
390
    my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule(
391
        {   categorycode => $cat_borrower,
391
        {
392
            categorycode => $cat_borrower,
393
            itemtype     => $type,
394
            branchcode   => $branch,
395
            rule_name    => 'maxissueqty',
396
        }
397
    );
398
    my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule(
399
        {
400
            categorycode => $cat_borrower,
392
            itemtype     => $type,
401
            itemtype     => $type,
393
            branchcode   => $branch
402
            branchcode   => $branch,
403
            rule_name    => 'maxonsiteissueqty',
394
        }
404
        }
395
    );
405
    );
396
406
Lines 398-404 sub TooMany { Link Here
398
    # if a rule is found and has a loan limit set, count
408
    # if a rule is found and has a loan limit set, count
399
    # how many loans the patron already has that meet that
409
    # how many loans the patron already has that meet that
400
    # rule
410
    # rule
401
    if (defined($issuing_rule) and defined($issuing_rule->maxissueqty)) {
411
    if (defined($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) {
402
        my @bind_params;
412
        my @bind_params;
403
        my $count_query = q|
413
        my $count_query = q|
404
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
414
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
Lines 406-412 sub TooMany { Link Here
406
            JOIN items USING (itemnumber)
416
            JOIN items USING (itemnumber)
407
        |;
417
        |;
408
418
409
        my $rule_itemtype = $issuing_rule->itemtype;
419
        my $rule_itemtype = $maxissueqty_rule->itemtype;
410
        if ($rule_itemtype eq "*") {
420
        if ($rule_itemtype eq "*") {
411
            # matching rule has the default item type, so count only
421
            # matching rule has the default item type, so count only
412
            # those existing loans that don't fall under a more
422
            # those existing loans that don't fall under a more
Lines 427-434 sub TooMany { Link Here
427
                                    AND   itemtype <> '*'
437
                                    AND   itemtype <> '*'
428
                                  ) ";
438
                                  ) ";
429
            }
439
            }
430
            push @bind_params, $issuing_rule->branchcode;
440
            push @bind_params, $maxissueqty_rule->branchcode;
431
            push @bind_params, $issuing_rule->categorycode;
441
            push @bind_params, $maxissueqty_rule->categorycode;
432
            push @bind_params, $cat_borrower;
442
            push @bind_params, $cat_borrower;
433
        } else {
443
        } else {
434
            # rule has specific item type, so count loans of that
444
            # rule has specific item type, so count loans of that
Lines 444-450 sub TooMany { Link Here
444
454
445
        $count_query .= " AND borrowernumber = ? ";
455
        $count_query .= " AND borrowernumber = ? ";
446
        push @bind_params, $borrower->{'borrowernumber'};
456
        push @bind_params, $borrower->{'borrowernumber'};
447
        my $rule_branch = $issuing_rule->branchcode;
457
        my $rule_branch = $maxissueqty_rule->branchcode;
448
        if ($rule_branch ne "*") {
458
        if ($rule_branch ne "*") {
449
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
459
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
450
                $count_query .= " AND issues.branchcode = ? ";
460
                $count_query .= " AND issues.branchcode = ? ";
Lines 459-466 sub TooMany { Link Here
459
469
460
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
470
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
461
471
462
        my $max_checkouts_allowed = $issuing_rule->maxissueqty;
472
        my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : 0;
463
        my $max_onsite_checkouts_allowed = $issuing_rule->maxonsiteissueqty;
473
        my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : 0;
464
474
465
        if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
475
        if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
466
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
476
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
Lines 545-551 sub TooMany { Link Here
545
        }
555
        }
546
    }
556
    }
547
557
548
    if ( not defined( $issuing_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) {
558
    if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) {
549
        return { reason => 'NO_RULE_DEFINED', max_allowed => 0 };
559
        return { reason => 'NO_RULE_DEFINED', max_allowed => 0 };
550
    }
560
    }
551
561
Lines 1573-1586 maxonsiteissueqty - maximum of on-site checkouts that a Link Here
1573
patron of the given category can have at the given
1583
patron of the given category can have at the given
1574
branch.  If the value is undef, no limit.
1584
branch.  If the value is undef, no limit.
1575
1585
1576
This will first check for a specific branch and
1586
This will check for different branch/category combinations in the following order:
1577
category match from branch_borrower_circ_rules. 
1587
branch and category
1578
1588
branch only
1579
If no rule is found, it will then check default_branch_circ_rules
1589
category only
1580
(same branch, default category).  If no rule is found,
1590
default branch and category
1581
it will then check default_borrower_circ_rules (default 
1582
branch, same category), then failing that, default_circ_rules
1583
(default branch, default category).
1584
1591
1585
If no rule has been found in the database, it will default to
1592
If no rule has been found in the database, it will default to
1586
the buillt in rule:
1593
the buillt in rule:
Lines 1597-1640 wildcards. Link Here
1597
sub GetBranchBorrowerCircRule {
1604
sub GetBranchBorrowerCircRule {
1598
    my ( $branchcode, $categorycode ) = @_;
1605
    my ( $branchcode, $categorycode ) = @_;
1599
1606
1600
    my $rules;
1607
    # Set search prededences
1601
    my $dbh = C4::Context->dbh();
1608
    my @params = (
1602
    $rules = $dbh->selectrow_hashref( q|
1609
        {
1603
        SELECT maxissueqty, maxonsiteissueqty
1610
            branchcode   => $branchcode,
1604
        FROM branch_borrower_circ_rules
1611
            categorycode => $categorycode,
1605
        WHERE branchcode = ?
1612
            itemtype     => undef,
1606
        AND   categorycode = ?
1613
        },
1607
    |, {}, $branchcode, $categorycode ) ;
1614
        {
1608
    return $rules if $rules;
1615
            branchcode   => $branchcode,
1609
1616
            categorycode => undef,
1610
    # try same branch, default borrower category
1617
            itemtype     => undef,
1611
    $rules = $dbh->selectrow_hashref( q|
1618
        },
1612
        SELECT maxissueqty, maxonsiteissueqty
1619
        {
1613
        FROM default_branch_circ_rules
1620
            branchcode   => undef,
1614
        WHERE branchcode = ?
1621
            categorycode => $categorycode,
1615
    |, {}, $branchcode ) ;
1622
            itemtype     => undef,
1616
    return $rules if $rules;
1623
        },
1617
1624
        {
1618
    # try default branch, same borrower category
1625
            branchcode   => undef,
1619
    $rules = $dbh->selectrow_hashref( q|
1626
            categorycode => undef,
1620
        SELECT maxissueqty, maxonsiteissueqty
1627
            itemtype     => undef,
1621
        FROM default_borrower_circ_rules
1628
        },
1622
        WHERE categorycode = ?
1629
    );
1623
    |, {}, $categorycode ) ;
1624
    return $rules if $rules;
1625
1626
    # try default branch, default borrower category
1627
    $rules = $dbh->selectrow_hashref( q|
1628
        SELECT maxissueqty, maxonsiteissueqty
1629
        FROM default_circ_rules
1630
    |, {} );
1631
    return $rules if $rules;
1632
1630
1633
    # built-in default circulation rule
1631
    # Initialize default values
1634
    return {
1632
    my $rules = {
1635
        maxissueqty => undef,
1633
        maxissueqty       => undef,
1636
        maxonsiteissueqty => undef,
1634
        maxonsiteissueqty => undef,
1637
    };
1635
    };
1636
1637
    # Search for rules!
1638
    foreach my $rule_name (qw( maxissueqty maxonsiteissueqty )) {
1639
        foreach my $params (@params) {
1640
            my $rule = Koha::CirculationRules->search(
1641
                {
1642
                    rule_name => $rule_name,
1643
                    %$params,
1644
                }
1645
            )->next();
1646
1647
            if ( $rule ) {
1648
                $rules->{$rule_name} = $rule->rule_value;
1649
                last;
1650
            }
1651
        }
1652
    }
1653
1654
    return $rules;
1638
}
1655
}
1639
1656
1640
=head2 GetBranchItemRule
1657
=head2 GetBranchItemRule
(-)a/Koha/CirculationRules.pm (-4 / +8 lines)
Lines 145-161 sub set_rules { Link Here
145
    my $itemtype     = $params->{itemtype};
145
    my $itemtype     = $params->{itemtype};
146
    my $rules        = $params->{rules};
146
    my $rules        = $params->{rules};
147
147
148
    foreach my $rule (@$rules) {
148
    my $rule_objects = [];
149
        Koha::CirculationRules->set_rule(
149
    while ( my ( $rule_name, $rule_value ) = each %$rules ) {
150
        my $rule_object = Koha::CirculationRules->set_rule(
150
            {
151
            {
151
                branchcode   => $branchcode,
152
                branchcode   => $branchcode,
152
                categorycode => $categorycode,
153
                categorycode => $categorycode,
153
                itemtype     => $itemtype,
154
                itemtype     => $itemtype,
154
                rule_name    => $rule->{rule_name},
155
                rule_name    => $rule_name,
155
                rule_value   => $rule->{rule_value},
156
                rule_value   => $rule_value,
156
            }
157
            }
157
        );
158
        );
159
        push( @$rule_objects, $rule_object );
158
    }
160
    }
161
162
    return $rule_objects;
159
}
163
}
160
164
161
=head3 type
165
=head3 type
(-)a/admin/smart-rules.pl (-163 / +86 lines)
Lines 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 183-190 elsif ($op eq 'add') { Link Here
183
        firstremind                   => $firstremind,
177
        firstremind                   => $firstremind,
184
        chargeperiod                  => $chargeperiod,
178
        chargeperiod                  => $chargeperiod,
185
        chargeperiod_charge_at        => $chargeperiod_charge_at,
179
        chargeperiod_charge_at        => $chargeperiod_charge_at,
186
        maxissueqty                   => $maxissueqty,
187
        maxonsiteissueqty             => $maxonsiteissueqty,
188
        renewalsallowed               => $renewalsallowed,
180
        renewalsallowed               => $renewalsallowed,
189
        renewalperiod                 => $renewalperiod,
181
        renewalperiod                 => $renewalperiod,
190
        norenewalbefore               => $norenewalbefore,
182
        norenewalbefore               => $norenewalbefore,
Lines 212-217 elsif ($op eq 'add') { Link Here
212
        Koha::IssuingRule->new()->set($params)->store();
204
        Koha::IssuingRule->new()->set($params)->store();
213
    }
205
    }
214
206
207
    Koha::CirculationRules->set_rules(
208
        {
209
            categorycode => $bor,
210
            itemtype     => $itemtype,
211
            branchcode   => $br,
212
            rules        => {
213
                maxissueqty       => $maxissueqty,
214
                maxonsiteissueqty => $maxonsiteissueqty,
215
            }
216
        }
217
    );
218
215
}
219
}
216
elsif ($op eq "set-branch-defaults") {
220
elsif ($op eq "set-branch-defaults") {
217
    my $categorycode  = $input->param('categorycode');
221
    my $categorycode  = $input->param('categorycode');
Lines 234-268 elsif ($op eq "set-branch-defaults") { Link Here
234
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
238
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
235
                                        FROM default_circ_rules");
239
                                        FROM default_circ_rules");
236
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
240
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
237
                                        (maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
241
                                        (holdallowed, hold_fulfillment_policy, returnbranch)
238
                                        VALUES (?, ?, ?, ?, ?)");
242
                                        VALUES (?, ?, ?)");
239
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
243
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
240
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
244
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
241
245
242
        $sth_search->execute();
246
        $sth_search->execute();
243
        my $res = $sth_search->fetchrow_hashref();
247
        my $res = $sth_search->fetchrow_hashref();
244
        if ($res->{total}) {
248
        if ($res->{total}) {
245
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
249
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
246
        } else {
250
        } else {
247
            $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
251
            $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
248
        }
252
        }
253
254
        Koha::CirculationRules->set_rules(
255
            {
256
                categorycode => undef,
257
                itemtype     => undef,
258
                branchcode   => undef,
259
                rules        => {
260
                    maxissueqty       => $maxissueqty,
261
                    maxonsiteissueqty => $maxonsiteissueqty,
262
                }
263
            }
264
        );
249
    } else {
265
    } else {
250
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
266
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
251
                                        FROM default_branch_circ_rules
267
                                        FROM default_branch_circ_rules
252
                                        WHERE branchcode = ?");
268
                                        WHERE branchcode = ?");
253
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
269
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
254
                                        (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
270
                                        (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
255
                                        VALUES (?, ?, ?, ?, ?, ?)");
271
                                        VALUES (?, ?, ?, ?)");
256
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
272
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
257
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
273
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
258
                                        WHERE branchcode = ?");
274
                                        WHERE branchcode = ?");
259
        $sth_search->execute($branch);
275
        $sth_search->execute($branch);
260
        my $res = $sth_search->fetchrow_hashref();
276
        my $res = $sth_search->fetchrow_hashref();
261
        if ($res->{total}) {
277
        if ($res->{total}) {
262
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
278
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
263
        } else {
279
        } else {
264
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
280
            $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch);
265
        }
281
        }
282
283
        Koha::CirculationRules->set_rules(
284
            {
285
                categorycode => undef,
286
                itemtype     => undef,
287
                branchcode   => $branch,
288
                rules        => {
289
                    maxissueqty       => $maxissueqty,
290
                    maxonsiteissueqty => $maxonsiteissueqty,
291
                }
292
            }
293
        );
266
    }
294
    }
267
    Koha::CirculationRules->set_rule(
295
    Koha::CirculationRules->set_rule(
268
        {
296
        {
Lines 288-413 elsif ($op eq "add-branch-cat") { Link Here
288
316
289
    if ($branch eq "*") {
317
    if ($branch eq "*") {
290
        if ($categorycode eq "*") {
318
        if ($categorycode eq "*") {
291
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
319
            Koha::CirculationRules->set_rules(
292
                                            FROM default_circ_rules");
293
            my $sth_insert = $dbh->prepare(q|
294
                INSERT INTO default_circ_rules
295
                    (maxissueqty, maxonsiteissueqty, max_holds)
296
                    VALUES (?, ?, ?)
297
            |);
298
            my $sth_update = $dbh->prepare(q|
299
                UPDATE default_circ_rules
300
                SET maxissueqty = ?,
301
                    maxonsiteissueqty = ?,
302
                    max_holds = ?
303
            |);
304
305
            $sth_search->execute();
306
            my $res = $sth_search->fetchrow_hashref();
307
            if ($res->{total}) {
308
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty );
309
            } else {
310
                $sth_insert->execute( $maxissueqty, $maxonsiteissueqty );
311
            }
312
313
            Koha::CirculationRules->set_rule(
314
                {
320
                {
315
                    branchcode   => undef,
316
                    categorycode => undef,
321
                    categorycode => undef,
317
                    itemtype     => undef,
322
                    itemtype     => undef,
318
                    rule_name    => 'max_holds',
323
                    branchcode   => undef,
319
                    rule_value   => $max_holds,
324
                    rules        => {
325
                        max_holds         => $max_holds,
326
                        maxissueqty       => $maxissueqty,
327
                        maxonsiteissueqty => $maxonsiteissueqty,
328
                    }
320
                }
329
                }
321
            );
330
            );
322
        } else {
331
        } else {
323
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
332
            Koha::CirculationRules->set_rules(
324
                                            FROM default_borrower_circ_rules
325
                                            WHERE categorycode = ?");
326
            my $sth_insert = $dbh->prepare(q|
327
                INSERT INTO default_borrower_circ_rules
328
                    (categorycode, maxissueqty, maxonsiteissueqty)
329
                    VALUES ( ?, ?, ?)
330
            |);
331
            my $sth_update = $dbh->prepare(q|
332
                UPDATE default_borrower_circ_rules
333
                SET maxissueqty = ?,
334
                    maxonsiteissueqty = ?,
335
                WHERE categorycode = ?
336
            |);
337
            $sth_search->execute($categorycode);
338
            my $res = $sth_search->fetchrow_hashref();
339
            if ($res->{total}) {
340
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode );
341
            } else {
342
                $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty );
343
            }
344
345
            Koha::CirculationRules->set_rule(
346
                {
333
                {
347
                    branchcode   => undef,
334
                    branchcode   => undef,
348
                    categorycode => $categorycode,
335
                    categorycode => $categorycode,
349
                    itemtype     => undef,
336
                    itemtype     => undef,
350
                    rule_name    => 'max_holds',
337
                    rules        => {
351
                    rule_value   => $max_holds,
338
                        max_holds         => $max_holds,
339
                        maxissueqty       => $maxissueqty,
340
                        maxonsiteissueqty => $maxonsiteissueqty,
341
                    }
352
                }
342
                }
353
            );
343
            );
354
        }
344
        }
355
    } elsif ($categorycode eq "*") {
345
    } elsif ($categorycode eq "*") {
356
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
346
        Koha::CirculationRules->set_rules(
357
                                        FROM default_branch_circ_rules
358
                                        WHERE branchcode = ?");
359
        my $sth_insert = $dbh->prepare(q|
360
            INSERT INTO default_branch_circ_rules
361
            (branchcode, maxissueqty, maxonsiteissueqty)
362
            VALUES (?, ?, ?)
363
        |);
364
        my $sth_update = $dbh->prepare(q|
365
            UPDATE default_branch_circ_rules
366
            SET maxissueqty = ?,
367
                maxonsiteissueqty = ?
368
            WHERE branchcode = ?
369
        |);
370
        $sth_search->execute($branch);
371
        my $res = $sth_search->fetchrow_hashref();
372
        if ($res->{total}) {
373
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch);
374
        } else {
375
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty);
376
        }
377
    } else {
378
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
379
                                        FROM branch_borrower_circ_rules
380
                                        WHERE branchcode = ?
381
                                        AND   categorycode = ?");
382
        my $sth_insert = $dbh->prepare(q|
383
            INSERT INTO branch_borrower_circ_rules
384
            (branchcode, categorycode, maxissueqty, maxonsiteissueqty, max_holds)
385
            VALUES (?, ?, ?, ?, ?)
386
        |);
387
        my $sth_update = $dbh->prepare(q|
388
            UPDATE branch_borrower_circ_rules
389
            SET maxissueqty = ?,
390
                maxonsiteissueqty = ?
391
                max_holds = ?
392
            WHERE branchcode = ?
393
            AND categorycode = ?
394
        |);
395
396
        $sth_search->execute($branch, $categorycode);
397
        my $res = $sth_search->fetchrow_hashref();
398
        if ($res->{total}) {
399
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $max_holds, $branch, $categorycode);
400
        } else {
401
            $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty, $max_holds);
402
        }
403
404
        Koha::CirculationRules->set_rule(
405
            {
347
            {
348
                categorycode => undef,
349
                itemtype     => undef,
406
                branchcode   => $branch,
350
                branchcode   => $branch,
351
                rules        => {
352
                    max_holds         => $max_holds,
353
                    maxissueqty       => $maxissueqty,
354
                    maxonsiteissueqty => $maxonsiteissueqty,
355
                }
356
            }
357
        );
358
    } else {
359
        Koha::CirculationRules->set_rules(
360
            {
407
                categorycode => $categorycode,
361
                categorycode => $categorycode,
408
                itemtype     => undef,
362
                itemtype     => undef,
409
                rule_name    => 'max_holds',
363
                branchcode   => $branch,
410
                rule_value   => $max_holds,
364
                rules        => {
365
                    max_holds         => $max_holds,
366
                    maxissueqty       => $maxissueqty,
367
                    maxonsiteissueqty => $maxonsiteissueqty,
368
                }
411
            }
369
            }
412
        );
370
        );
413
    }
371
    }
Lines 575-614 while (my $row = $sth2->fetchrow_hashref) { Link Here
575
533
576
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
534
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
577
535
578
my $sth_branch_cat;
579
if ($branch eq "*") {
580
    $sth_branch_cat = $dbh->prepare("
581
        SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode
582
        FROM default_borrower_circ_rules
583
        JOIN categories USING (categorycode)
584
585
    ");
586
    $sth_branch_cat->execute();
587
} else {
588
    $sth_branch_cat = $dbh->prepare("
589
        SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode
590
        FROM branch_borrower_circ_rules
591
        JOIN categories USING (categorycode)
592
        WHERE branch_borrower_circ_rules.branchcode = ?
593
    ");
594
    $sth_branch_cat->execute($branch);
595
}
596
597
my @branch_cat_rules = ();
598
while (my $row = $sth_branch_cat->fetchrow_hashref) {
599
    push @branch_cat_rules, $row;
600
}
601
my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humancategorycode'} } @branch_cat_rules;
602
603
# note undef maxissueqty so that template can deal with them
604
foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) {
605
    $entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty});
606
    $entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty});
607
    $entry->{unlimited_max_holds} = 1 unless defined($entry->{max_holds});
608
}
609
610
@sorted_row_loop = sort by_category_and_itemtype @row_loop;
611
612
my $sth_branch_item;
536
my $sth_branch_item;
613
if ($branch eq "*") {
537
if ($branch eq "*") {
614
    $sth_branch_item = $dbh->prepare("
538
    $sth_branch_item = $dbh->prepare("
Lines 649-655 foreach my $entry (@sorted_branch_item_rules) { Link Here
649
573
650
$template->param(show_branch_cat_rule_form => 1);
574
$template->param(show_branch_cat_rule_form => 1);
651
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules);
575
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules);
652
$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules);
653
576
654
my $sth_defaults;
577
my $sth_defaults;
655
if ($branch eq "*") {
578
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 340-384 CREATE TABLE collections_tracking ( Link Here
340
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
340
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
341
341
342
--
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
--
374
-- Table structure for table `default_branch_circ_rules`
343
-- Table structure for table `default_branch_circ_rules`
375
--
344
--
376
345
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 843-850 CREATE TABLE `issuingrules` ( -- circulation and fine rules Link Here
843
  `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period
808
  `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period
844
  `accountsent` int(11) default NULL, -- not used? always NULL
809
  `accountsent` int(11) default NULL, -- not used? always NULL
845
  `chargename` varchar(100) default NULL, -- not used? always NULL
810
  `chargename` varchar(100) default NULL, -- not used? always NULL
846
  `maxissueqty` int(4) default NULL, -- total number of checkouts allowed
847
  `maxonsiteissueqty` int(4) default NULL, -- total number of on-site checkouts allowed
848
  `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit
811
  `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit
849
  `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours)
812
  `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours)
850
  `hardduedate` date default NULL, -- hard due date
813
  `hardduedate` date default NULL, -- hard due date
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-26 / +50 lines)
Lines 1-7 Link Here
1
[% USE Asset %]
1
[% USE Asset %]
2
[% USE Branches %]
2
[% USE Branches %]
3
[% USE Categories %]
3
[% USE CirculationRules %]
4
[% USE CirculationRules %]
4
[% SET footerjs = 1 %]
5
[% SET footerjs = 1 %]
6
7
[% SET branchcode = humanbranch %]
8
9
[% SET categorycodes = ['*'] %]
10
[% FOREACH pc IN patron_categories %]
11
    [% categorycodes.push( pc.id ) %]
12
[% END %]
13
5
[% INCLUDE 'doc-head-open.inc' %]
14
[% INCLUDE 'doc-head-open.inc' %]
6
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
15
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
7
[% INCLUDE 'doc-head-close.inc' %]
16
[% 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
									<span>Unlimited</span>
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
                                    <span>Unlimited</span>
133
                                    <span>Unlimited</span>
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 376-383 Link Here
376
                </tr>
389
                </tr>
377
                <tr>
390
                <tr>
378
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
391
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
379
                    <td><input type="text" name="maxissueqty" size="3" value="[% default_maxissueqty %]"/></td>
392
                    <td>
380
                    <td><input type="text" name="maxonsiteissueqty" size="3" value="[% default_maxonsiteissueqty %]"/></td>
393
                        [% SET maxissueqty  = CirculationRules.Get( branchcode, undef, undef, 'maxissueqty' ) %]
394
                        <input type="text" name="maxissueqty" size="3" value="[% maxissueqty %]"/>
395
                    </td>
396
                    <td>
397
                        [% SET maxonsiteissueqty  = CirculationRules.Get( branchcode, undef, undef, 'maxonsiteissueqty' ) %]
398
                        <input type="text" name="maxonsiteissueqty" size="3" value="[% maxonsiteissueqty %]"/>
399
                    </td>
381
                    <td>
400
                    <td>
382
                        [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %]
401
                        [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %]
383
                        <input name="max_holds" size="3" value="[% rule_value %]" />
402
                        <input name="max_holds" size="3" value="[% rule_value %]" />
Lines 493-520 Link Here
493
                    <th>Total holds allowed</th>
512
                    <th>Total holds allowed</th>
494
                    <th>&nbsp;</th>
513
                    <th>&nbsp;</th>
495
                </tr>
514
                </tr>
496
                [% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %]
515
                [% FOREACH c IN categorycodes %]
497
                    [% UNLESS ( loop.odd ) %]
516
                    [% SET maxissueqty = CirculationRules.Get( branchcode, c, undef, 'maxissueqty' ) %]
498
                    <tr class="highlight">
517
                    [% SET maxonsiteissueqty = CirculationRules.Get( branchcode, c, undef, 'maxonsiteissueqty' ) %]
499
                    [% ELSE %]
518
                    [% SET max_holds = CirculationRules.Get( branchcode, c, undef, 'max_holds' ) %]
519
520
                    [% IF maxissueqty || maxissueqty || max_holds %]
500
                    <tr>
521
                    <tr>
501
                    [% END %]
522
                        <td>
502
                        <td>[% IF ( branch_cat_rule_loo.default_humancategorycode ) %]
523
                            [% IF c == '*'%]
503
                                <em>Default</em>
524
                                <em>Default</em>
504
                            [% ELSE %]
525
                            [% ELSE %]
505
                                [% branch_cat_rule_loo.humancategorycode %]
526
                                [% Categories.GetName(c) %]
506
                            [% END %]
527
                            [% END %]
507
                        </td>
528
                        </td>
508
                        <td>[% IF ( branch_cat_rule_loo.unlimited_maxissueqty ) %]
529
                        <td>
509
                                <span>Unlimited</span>
530
                            [% IF maxissueqty  %]
531
                                [% maxissueqty %]
510
                            [% ELSE %]
532
                            [% ELSE %]
511
                                [% branch_cat_rule_loo.maxissueqty %]
533
                                <span>Unlimited</span>
512
                            [% END %]
534
                            [% END %]
513
                        </td>
535
                        </td>
514
                        <td>[% IF ( branch_cat_rule_loo.unlimited_maxonsiteissueqty ) %]
536
                        <td>
515
                                <span>Unlimited</span>
537
                            [% IF maxonsiteissueqty  %]
538
                                [% maxonsiteissueqty %]
516
                            [% ELSE %]
539
                            [% ELSE %]
517
                                [% branch_cat_rule_loo.maxonsiteissueqty %]
540
                                <span>Unlimited</span>
518
                            [% END %]
541
                            [% END %]
519
                        </td>
542
                        </td>
520
                        <td>
543
                        <td>
Lines 522-535 Link Here
522
                            [% IF rule_value.defined && rule_value != '' %]
545
                            [% IF rule_value.defined && rule_value != '' %]
523
                                [% rule_value %]
546
                                [% rule_value %]
524
                            [% ELSE %]
547
                            [% ELSE %]
525
                                Unlimited
548
                                <span>Unlimited</span>
526
                            [% END %]
549
                            [% END %]
527
                        </td>
550
                        </td>
528
551
529
                        <td class="actions">
552
                        <td class="actions">
530
                            <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>
553
                            <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>
531
                        </td>
554
                        </td>
532
                    </tr>
555
                    </tr>
556
                    [% END %]
533
                [% END %]
557
                [% END %]
534
                <tr>
558
                <tr>
535
                    <td>
559
                    <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 185-198 is( Link Here
185
186
186
# Set a simple circ policy
187
# Set a simple circ policy
187
$dbh->do('DELETE FROM issuingrules');
188
$dbh->do('DELETE FROM issuingrules');
189
Koha::CirculationRules->search()->delete();
188
$dbh->do(
190
$dbh->do(
189
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed,
191
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed,
190
                                maxissueqty, issuelength, lengthunit,
192
                                issuelength, lengthunit,
191
                                renewalsallowed, renewalperiod,
193
                                renewalsallowed, renewalperiod,
192
                                norenewalbefore, auto_renew,
194
                                norenewalbefore, auto_renew,
193
                                fine, chargeperiod)
195
                                fine, chargeperiod)
194
      VALUES (?, ?, ?, ?,
196
      VALUES (?, ?, ?, ?,
195
              ?, ?, ?,
197
              ?, ?,
196
              ?, ?,
198
              ?, ?,
197
              ?, ?,
199
              ?, ?,
198
              ?, ?
200
              ?, ?
Lines 200-206 $dbh->do( Link Here
200
    },
202
    },
201
    {},
203
    {},
202
    '*', '*', '*', 25,
204
    '*', '*', '*', 25,
203
    20, 14, 'days',
205
    14, 'days',
204
    1, 7,
206
    1, 7,
205
    undef, 0,
207
    undef, 0,
206
    .10, 1
208
    .10, 1
Lines 1038-1055 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1038
    $dbh->do('DELETE FROM issues');
1040
    $dbh->do('DELETE FROM issues');
1039
    $dbh->do('DELETE FROM items');
1041
    $dbh->do('DELETE FROM items');
1040
    $dbh->do('DELETE FROM issuingrules');
1042
    $dbh->do('DELETE FROM issuingrules');
1043
    Koha::CirculationRules->search()->delete();
1041
    $dbh->do(
1044
    $dbh->do(
1042
        q{
1045
        q{
1043
        INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, maxissueqty, issuelength, lengthunit, renewalsallowed, renewalperiod,
1046
        INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, issuelength, lengthunit, renewalsallowed, renewalperiod,
1044
                    norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
1047
                    norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
1045
        },
1048
        },
1046
        {},
1049
        {},
1047
        '*', '*', '*', 25,
1050
        '*', '*', '*', 25,
1048
        20,  14,  'days',
1051
        14,  'days',
1049
        1,   7,
1052
        1,   7,
1050
        undef,  0,
1053
        undef,  0,
1051
        .10, 1
1054
        .10, 1
1052
    );
1055
    );
1056
    Koha::CirculationRules->set_rules(
1057
        {
1058
            categorycode => '*',
1059
            itemtype     => '*',
1060
            branchcode   => '*',
1061
            rules        => {
1062
                maxissueqty => 20
1063
            }
1064
        }
1065
    );
1053
    my ( $biblionumber, $biblioitemnumber ) = add_biblio();
1066
    my ( $biblionumber, $biblioitemnumber ) = add_biblio();
1054
1067
1055
    my $barcode1 = '1234';
1068
    my $barcode1 = '1234';
Lines 1656-1662 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1656
            categorycode => '*',
1669
            categorycode => '*',
1657
            itemtype     => '*',
1670
            itemtype     => '*',
1658
            branchcode   => '*',
1671
            branchcode   => '*',
1659
            maxissueqty  => 99,
1660
            issuelength  => 1,
1672
            issuelength  => 1,
1661
            firstremind  => 1,        # 1 day of grace
1673
            firstremind  => 1,        # 1 day of grace
1662
            finedays     => 2,        # 2 days of fine per day of overdue
1674
            finedays     => 2,        # 2 days of fine per day of overdue
(-)a/t/db_dependent/Circulation/Branch.t (-19 / +41 lines)
Lines 21-26 use C4::Biblio; Link Here
21
use C4::Circulation;
21
use C4::Circulation;
22
use C4::Items;
22
use C4::Items;
23
use C4::Context;
23
use C4::Context;
24
use Koha::CirculationRules;
24
25
25
use Koha::Patrons;
26
use Koha::Patrons;
26
27
Lines 53-59 $dbh->do(q|DELETE FROM categories|); Link Here
53
$dbh->do(q|DELETE FROM accountlines|);
54
$dbh->do(q|DELETE FROM accountlines|);
54
$dbh->do(q|DELETE FROM itemtypes|);
55
$dbh->do(q|DELETE FROM itemtypes|);
55
$dbh->do(q|DELETE FROM branch_item_rules|);
56
$dbh->do(q|DELETE FROM branch_item_rules|);
56
$dbh->do(q|DELETE FROM branch_borrower_circ_rules|);
57
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
57
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
58
$dbh->do(q|DELETE FROM default_circ_rules|);
58
$dbh->do(q|DELETE FROM default_circ_rules|);
59
$dbh->do(q|DELETE FROM default_branch_item_rules|);
59
$dbh->do(q|DELETE FROM default_branch_item_rules|);
Lines 152-182 is_deeply( Link Here
152
"Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined"
152
"Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined"
153
);
153
);
154
154
155
my $query = q|
155
Koha::CirculationRules->set_rules(
156
    INSERT INTO branch_borrower_circ_rules
156
    {
157
    (branchcode, categorycode, maxissueqty, maxonsiteissueqty)
157
        branchcode   => $samplebranch1->{branchcode},
158
    VALUES( ?, ?, ?, ? )
158
        categorycode => $samplecat->{categorycode},
159
|;
159
        itemtype     => undef,
160
160
        rules        => {
161
$dbh->do(
161
            maxissueqty       => 5,
162
    $query, {},
162
            maxonsiteissueqty => 6,
163
    $samplebranch1->{branchcode},
163
        }
164
    $samplecat->{categorycode}, 5, 6
164
    }
165
);
165
);
166
166
167
$query = q|
167
my $query = q|
168
    INSERT INTO default_branch_circ_rules
168
    INSERT INTO default_branch_circ_rules
169
    (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
169
    (branchcode, holdallowed, returnbranch)
170
    VALUES( ?, ?, ?, ?, ? )
170
    VALUES( ?, ?, ? )
171
|;
171
|;
172
$dbh->do( $query, {}, $samplebranch2->{branchcode},
172
$dbh->do( $query, {}, $samplebranch2->{branchcode}, 1, 'holdingbranch' );
173
    3, 2, 1, 'holdingbranch' );
173
Koha::CirculationRules->set_rules(
174
    {
175
        branchcode   => $samplebranch2->{branchcode},
176
        categorycode => undef,
177
        itemtype     => undef,
178
        rules        => {
179
            maxissueqty       => 3,
180
            maxonsiteissueqty => 2,
181
        }
182
    }
183
);
184
174
$query = q|
185
$query = q|
175
    INSERT INTO default_circ_rules
186
    INSERT INTO default_circ_rules
176
    (singleton, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
187
    (singleton, holdallowed, returnbranch)
177
    VALUES( ?, ?, ?, ?, ? )
188
    VALUES( ?, ?, ? )
178
|;
189
|;
179
$dbh->do( $query, {}, 'singleton', 4, 5, 3, 'homebranch' );
190
$dbh->do( $query, {}, 'singleton', 3, 'homebranch' );
191
Koha::CirculationRules->set_rules(
192
    {
193
        branchcode   => undef,
194
        categorycode => undef,
195
        itemtype     => undef,
196
        rules        => {
197
            maxissueqty       => 4,
198
            maxonsiteissueqty => 5,
199
        }
200
    }
201
);
180
202
181
$query =
203
$query =
182
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
204
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
(-)a/t/db_dependent/Circulation/GetHardDueDate.t (-17 / +3 lines)
Lines 117-124 my $sampleissuingrule1 = { Link Here
117
    chargename         => undef,
117
    chargename         => undef,
118
    restrictedtype     => 0,
118
    restrictedtype     => 0,
119
    accountsent        => 0,
119
    accountsent        => 0,
120
    maxissueqty        => 5,
121
    maxonsiteissueqty  => 4,
122
    finedays           => 0,
120
    finedays           => 0,
123
    lengthunit         => 'days',
121
    lengthunit         => 'days',
124
    renewalperiod      => 5,
122
    renewalperiod      => 5,
Lines 152-160 my $sampleissuingrule2 = { Link Here
152
    branchcode         => $samplebranch2->{branchcode},
150
    branchcode         => $samplebranch2->{branchcode},
153
    categorycode       => $samplecat->{categorycode},
151
    categorycode       => $samplecat->{categorycode},
154
    itemtype           => 'BOOK',
152
    itemtype           => 'BOOK',
155
    maxissueqty        => 2,
153
    renewalsallowed    => 'Null',
156
    maxonsiteissueqty  => 1,
157
    renewalsallowed    => 0,
158
    renewalperiod      => 2,
154
    renewalperiod      => 2,
159
    norenewalbefore    => 7,
155
    norenewalbefore    => 7,
160
    auto_renew         => 0,
156
    auto_renew         => 0,
Lines 185-193 my $sampleissuingrule3 = { Link Here
185
    branchcode         => $samplebranch1->{branchcode},
181
    branchcode         => $samplebranch1->{branchcode},
186
    categorycode       => $samplecat->{categorycode},
182
    categorycode       => $samplecat->{categorycode},
187
    itemtype           => 'DVD',
183
    itemtype           => 'DVD',
188
    maxissueqty        => 3,
184
    renewalsallowed    => 'Null',
189
    maxonsiteissueqty  => 2,
190
    renewalsallowed    => 0,
191
    renewalperiod      => 3,
185
    renewalperiod      => 3,
192
    norenewalbefore    => 8,
186
    norenewalbefore    => 8,
193
    auto_renew         => 0,
187
    auto_renew         => 0,
Lines 219-226 $query = 'INSERT INTO issuingrules ( Link Here
219
                branchcode,
213
                branchcode,
220
                categorycode,
214
                categorycode,
221
                itemtype,
215
                itemtype,
222
                maxissueqty,
223
                maxonsiteissueqty,
224
                renewalsallowed,
216
                renewalsallowed,
225
                renewalperiod,
217
                renewalperiod,
226
                norenewalbefore,
218
                norenewalbefore,
Lines 246-259 $query = 'INSERT INTO issuingrules ( Link Here
246
                opacitemholds,
238
                opacitemholds,
247
                cap_fine_to_replacement_price,
239
                cap_fine_to_replacement_price,
248
                article_requests
240
                article_requests
249
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
241
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
250
my $sth = $dbh->prepare($query);
242
my $sth = $dbh->prepare($query);
251
$sth->execute(
243
$sth->execute(
252
    $sampleissuingrule1->{branchcode},
244
    $sampleissuingrule1->{branchcode},
253
    $sampleissuingrule1->{categorycode},
245
    $sampleissuingrule1->{categorycode},
254
    $sampleissuingrule1->{itemtype},
246
    $sampleissuingrule1->{itemtype},
255
    $sampleissuingrule1->{maxissueqty},
256
    $sampleissuingrule1->{maxonsiteissueqty},
257
    $sampleissuingrule1->{renewalsallowed},
247
    $sampleissuingrule1->{renewalsallowed},
258
    $sampleissuingrule1->{renewalperiod},
248
    $sampleissuingrule1->{renewalperiod},
259
    $sampleissuingrule1->{norenewalbefore},
249
    $sampleissuingrule1->{norenewalbefore},
Lines 284-291 $sth->execute( Link Here
284
    $sampleissuingrule2->{branchcode},
274
    $sampleissuingrule2->{branchcode},
285
    $sampleissuingrule2->{categorycode},
275
    $sampleissuingrule2->{categorycode},
286
    $sampleissuingrule2->{itemtype},
276
    $sampleissuingrule2->{itemtype},
287
    $sampleissuingrule2->{maxissueqty},
288
    $sampleissuingrule2->{maxonsiteissueqty},
289
    $sampleissuingrule2->{renewalsallowed},
277
    $sampleissuingrule2->{renewalsallowed},
290
    $sampleissuingrule2->{renewalperiod},
278
    $sampleissuingrule2->{renewalperiod},
291
    $sampleissuingrule2->{norenewalbefore},
279
    $sampleissuingrule2->{norenewalbefore},
Lines 316-323 $sth->execute( Link Here
316
    $sampleissuingrule3->{branchcode},
304
    $sampleissuingrule3->{branchcode},
317
    $sampleissuingrule3->{categorycode},
305
    $sampleissuingrule3->{categorycode},
318
    $sampleissuingrule3->{itemtype},
306
    $sampleissuingrule3->{itemtype},
319
    $sampleissuingrule3->{maxissueqty},
320
    $sampleissuingrule3->{maxonsiteissueqty},
321
    $sampleissuingrule3->{renewalsallowed},
307
    $sampleissuingrule3->{renewalsallowed},
322
    $sampleissuingrule3->{renewalperiod},
308
    $sampleissuingrule3->{renewalperiod},
323
    $sampleissuingrule3->{norenewalbefore},
309
    $sampleissuingrule3->{norenewalbefore},
(-)a/t/db_dependent/Circulation/Returns.t (-1 lines)
Lines 54-60 my $rule = Koha::IssuingRule->new( Link Here
54
        categorycode => '*',
54
        categorycode => '*',
55
        itemtype     => '*',
55
        itemtype     => '*',
56
        branchcode   => '*',
56
        branchcode   => '*',
57
        maxissueqty  => 99,
58
        issuelength  => 1,
57
        issuelength  => 1,
59
    }
58
    }
60
);
59
);
(-)a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t (-13 / +25 lines)
Lines 27-32 use C4::Context; Link Here
27
use Koha::DateUtils qw( dt_from_string );
27
use Koha::DateUtils qw( dt_from_string );
28
use Koha::Database;
28
use Koha::Database;
29
use Koha::Checkouts;
29
use Koha::Checkouts;
30
use Koha::CirculationRules;
30
31
31
use t::lib::TestBuilder;
32
use t::lib::TestBuilder;
32
use t::lib::Mocks;
33
use t::lib::Mocks;
Lines 38-44 our $dbh = C4::Context->dbh; Link Here
38
39
39
$dbh->do(q|DELETE FROM branch_item_rules|);
40
$dbh->do(q|DELETE FROM branch_item_rules|);
40
$dbh->do(q|DELETE FROM issues|);
41
$dbh->do(q|DELETE FROM issues|);
41
$dbh->do(q|DELETE FROM branch_borrower_circ_rules|);
42
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
42
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
43
$dbh->do(q|DELETE FROM default_circ_rules|);
43
$dbh->do(q|DELETE FROM default_circ_rules|);
44
$dbh->do(q|DELETE FROM default_branch_item_rules|);
44
$dbh->do(q|DELETE FROM default_branch_item_rules|);
Lines 91-102 my $issuingrule = $builder->build({ Link Here
91
        branchcode         => $branch->{branchcode},
91
        branchcode         => $branch->{branchcode},
92
        categorycode       => '*',
92
        categorycode       => '*',
93
        itemtype           => '*',
93
        itemtype           => '*',
94
        maxissueqty        => 2,
95
        maxonsiteissueqty  => 1,
96
        lengthunit         => 'days',
94
        lengthunit         => 'days',
97
        issuelength        => 5,
95
        issuelength        => 5,
98
    },
96
    },
99
});
97
});
98
Koha::CirculationRules->search()->delete();
99
Koha::CirculationRules->set_rules(
100
    {
101
        branchcode   => $branch->{branchcode},
102
        categorycode => '*',
103
        itemtype     => '*',
104
        rules        => {
105
            maxissueqty       => 2,
106
            maxonsiteissueqty => 1,
107
        }
108
    }
109
);
100
110
101
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
111
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
102
C4::Context->set_userenv($patron->borrowernumber, $patron->userid, 'usercnum', 'First name', 'Surname', $branch->{branchcode}, 'My Library', 0);
112
C4::Context->set_userenv($patron->borrowernumber, $patron->userid, 'usercnum', 'First name', 'Surname', $branch->{branchcode}, 'My Library', 0);
Lines 154-169 my $yet_another_item = $builder->build({ Link Here
154
( $impossible, undef, undef, undef ) = C4::Circulation::CanBookBeIssued( $patron, $yet_another_item->{barcode} );
164
( $impossible, undef, undef, undef ) = C4::Circulation::CanBookBeIssued( $patron, $yet_another_item->{barcode} );
155
is( $impossible->{TOO_MANY}, 'TOO_MANY_CHECKOUTS', 'Not a specific case, $delta should not be incremented' );
165
is( $impossible->{TOO_MANY}, 'TOO_MANY_CHECKOUTS', 'Not a specific case, $delta should not be incremented' );
156
166
157
$dbh->do(q|DELETE FROM issuingrules|);
167
Koha::CirculationRules->search()->delete();
158
my $borrower_circ_rule = $builder->build({
168
Koha::CirculationRules->set_rules(
159
    source => 'DefaultCircRule',
169
    {
160
    value => {
170
        branchcode   => $branch->{branchcode},
161
        branchcode         => $branch->{branchcode},
171
        categorycode => '*',
162
        categorycode       => '*',
172
        itemtype     => '*',
163
        maxissueqty        => 2,
173
        rules        => {
164
        maxonsiteissueqty  => 1,
174
            maxissueqty       => 2,
165
    },
175
            maxonsiteissueqty => 1,
166
});
176
        }
177
    }
178
);
167
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} );
179
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} );
168
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 2 - Switch is allowed' );
180
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 2 - Switch is allowed' );
169
is( exists $impossible->{TOO_MANY}, '', 'Specific case 2 - Switch is allowed' );
181
is( exists $impossible->{TOO_MANY}, '', 'Specific case 2 - Switch is allowed' );
(-)a/t/db_dependent/Circulation/TooMany.t (-49 / +56 lines)
Lines 26-31 use C4::Context; Link Here
26
26
27
use Koha::DateUtils qw( dt_from_string );
27
use Koha::DateUtils qw( dt_from_string );
28
use Koha::Database;
28
use Koha::Database;
29
use Koha::CirculationRules;
29
30
30
use t::lib::TestBuilder;
31
use t::lib::TestBuilder;
31
use t::lib::Mocks;
32
use t::lib::Mocks;
Lines 43-53 $dbh->do(q|DELETE FROM categories|); Link Here
43
$dbh->do(q|DELETE FROM accountlines|);
44
$dbh->do(q|DELETE FROM accountlines|);
44
$dbh->do(q|DELETE FROM itemtypes|);
45
$dbh->do(q|DELETE FROM itemtypes|);
45
$dbh->do(q|DELETE FROM branch_item_rules|);
46
$dbh->do(q|DELETE FROM branch_item_rules|);
46
$dbh->do(q|DELETE FROM branch_borrower_circ_rules|);
47
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
47
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
48
$dbh->do(q|DELETE FROM default_circ_rules|);
48
$dbh->do(q|DELETE FROM default_circ_rules|);
49
$dbh->do(q|DELETE FROM default_branch_item_rules|);
49
$dbh->do(q|DELETE FROM default_branch_item_rules|);
50
$dbh->do(q|DELETE FROM issuingrules|);
50
$dbh->do(q|DELETE FROM issuingrules|);
51
Koha::CirculationRules->search()->delete();
51
52
52
my $builder = t::lib::TestBuilder->new();
53
my $builder = t::lib::TestBuilder->new();
53
t::lib::Mocks::mock_preference('item-level_itypes', 1); # Assuming the item type is defined at item level
54
t::lib::Mocks::mock_preference('item-level_itypes', 1); # Assuming the item type is defined at item level
Lines 106-121 subtest 'no rules exist' => sub { Link Here
106
107
107
subtest '1 Issuingrule exist 0 0: no issue allowed' => sub {
108
subtest '1 Issuingrule exist 0 0: no issue allowed' => sub {
108
    plan tests => 4;
109
    plan tests => 4;
109
    my $issuingrule = $builder->build({
110
    Koha::CirculationRules->set_rules(
110
        source => 'Issuingrule',
111
        {
111
        value => {
112
            branchcode   => $branch->{branchcode},
112
            branchcode         => $branch->{branchcode},
113
            categorycode => $category->{categorycode},
113
            categorycode       => $category->{categorycode},
114
            itemtype     => '*',
114
            itemtype           => '*',
115
            rules        => {
115
            maxissueqty        => 0,
116
                maxissueqty       => 0,
116
            maxonsiteissueqty  => 0,
117
                maxonsiteissueqty => 0,
118
            }
117
        },
119
        },
118
    });
120
    );
119
    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
121
    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
120
    is_deeply(
122
    is_deeply(
121
        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
123
        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
Lines 214-229 subtest '1 Issuingrule exist with onsiteissueqty=unlimited' => sub { Link Here
214
216
215
subtest '1 Issuingrule exist 1 1: issue is allowed' => sub {
217
subtest '1 Issuingrule exist 1 1: issue is allowed' => sub {
216
    plan tests => 4;
218
    plan tests => 4;
217
    my $issuingrule = $builder->build({
219
    Koha::CirculationRules->set_rules(
218
        source => 'Issuingrule',
220
        {
219
        value => {
221
            branchcode   => $branch->{branchcode},
220
            branchcode         => $branch->{branchcode},
222
            categorycode => $category->{categorycode},
221
            categorycode       => $category->{categorycode},
223
            itemtype     => '*',
222
            itemtype           => '*',
224
            rules        => {
223
            maxissueqty        => 1,
225
                maxissueqty       => 1,
224
            maxonsiteissueqty  => 1,
226
                maxonsiteissueqty => 1,
225
        },
227
            }
226
    });
228
        }
229
    );
227
    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
230
    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
228
    is(
231
    is(
229
        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
232
        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
Lines 253-268 subtest '1 Issuingrule exist 1 1: issue is allowed' => sub { Link Here
253
256
254
subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub {
257
subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub {
255
    plan tests => 5;
258
    plan tests => 5;
256
    my $issuingrule = $builder->build({
259
    Koha::CirculationRules->set_rules(
257
        source => 'Issuingrule',
260
        {
258
        value => {
261
            branchcode   => $branch->{branchcode},
259
            branchcode         => $branch->{branchcode},
262
            categorycode => $category->{categorycode},
260
            categorycode       => $category->{categorycode},
263
            itemtype     => '*',
261
            itemtype           => '*',
264
            rules        => {
262
            maxissueqty        => 1,
265
                maxissueqty       => 1,
263
            maxonsiteissueqty  => 1,
266
                maxonsiteissueqty => 1,
264
        },
267
            }
265
    });
268
        }
269
    );
266
270
267
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string() );
271
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string() );
268
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
272
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
Lines 308-323 subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { Link Here
308
312
309
subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub {
313
subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub {
310
    plan tests => 5;
314
    plan tests => 5;
311
    my $issuingrule = $builder->build({
315
    Koha::CirculationRules->set_rules(
312
        source => 'Issuingrule',
316
        {
313
        value => {
317
            branchcode   => $branch->{branchcode},
314
            branchcode         => $branch->{branchcode},
318
            categorycode => $category->{categorycode},
315
            categorycode       => $category->{categorycode},
319
            itemtype     => '*',
316
            itemtype           => '*',
320
            rules        => {
317
            maxissueqty        => 1,
321
                maxissueqty       => 1,
318
            maxonsiteissueqty  => 1,
322
                maxonsiteissueqty => 1,
319
        },
323
            }
320
    });
324
        }
325
    );
321
326
322
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef, { onsite_checkout => 1 } );
327
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef, { onsite_checkout => 1 } );
323
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
328
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
Lines 366-380 subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { Link Here
366
    # DefaultBorrowerCircRule, DefaultBranchCircRule, DefaultBranchItemRule ans DefaultCircRule.pm
371
    # DefaultBorrowerCircRule, DefaultBranchCircRule, DefaultBranchItemRule ans DefaultCircRule.pm
367
372
368
    plan tests => 10;
373
    plan tests => 10;
369
    my $issuingrule = $builder->build({
374
    Koha::CirculationRules->set_rules(
370
        source => 'BranchBorrowerCircRule',
375
        {
371
        value => {
376
            branchcode   => $branch->{branchcode},
372
            branchcode         => $branch->{branchcode},
377
            categorycode => $category->{categorycode},
373
            categorycode       => $category->{categorycode},
378
            itemtype     => undef,
374
            maxissueqty        => 1,
379
            rules        => {
375
            maxonsiteissueqty  => 1,
380
                maxissueqty       => 1,
376
        },
381
                maxonsiteissueqty => 1,
377
    });
382
            }
383
        }
384
    );
378
385
379
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef );
386
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef );
380
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
387
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
(-)a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t (-1 lines)
Lines 98-104 my $rule = Koha::IssuingRule->new( Link Here
98
        categorycode => '*',
98
        categorycode => '*',
99
        itemtype     => '*',
99
        itemtype     => '*',
100
        branchcode   => '*',
100
        branchcode   => '*',
101
        maxissueqty  => 99,
102
        issuelength  => 7,
101
        issuelength  => 7,
103
        lengthunit   => 8,
102
        lengthunit   => 8,
104
        reservesallowed => 99,
103
        reservesallowed => 99,
(-)a/t/db_dependent/Reserves.t (-9 / +6 lines)
Lines 201-208 $requesters{$branch_3} = Koha::Patron->new({ Link Here
201
201
202
$dbh->do('DELETE FROM issuingrules');
202
$dbh->do('DELETE FROM issuingrules');
203
$dbh->do('DELETE FROM branch_item_rules');
203
$dbh->do('DELETE FROM branch_item_rules');
204
$dbh->do('DELETE FROM branch_borrower_circ_rules');
205
$dbh->do('DELETE FROM default_borrower_circ_rules');
206
$dbh->do('DELETE FROM default_branch_item_rules');
204
$dbh->do('DELETE FROM default_branch_item_rules');
207
$dbh->do('DELETE FROM default_branch_circ_rules');
205
$dbh->do('DELETE FROM default_branch_circ_rules');
208
$dbh->do('DELETE FROM default_circ_rules');
206
$dbh->do('DELETE FROM default_circ_rules');
Lines 215-232 $dbh->do( Link Here
215
213
216
# CPL allows only its own patrons to request its items
214
# CPL allows only its own patrons to request its items
217
$dbh->do(
215
$dbh->do(
218
    q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
216
    q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch)
219
      VALUES (?, ?, ?, ?)},
217
      VALUES (?, ?, ?)},
220
    {},
218
    {},
221
    $branch_1, 10, 1, 'homebranch',
219
    $branch_1, 1, 'homebranch',
222
);
220
);
223
221
224
# ... while FPL allows anybody to request its items
222
# ... while FPL allows anybody to request its items
225
$dbh->do(
223
$dbh->do(
226
    q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
224
    q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch)
227
      VALUES (?, ?, ?, ?)},
225
      VALUES (?, ?, ?)},
228
    {},
226
    {},
229
    $branch_2, 10, 2, 'homebranch',
227
    $branch_2, 2, 'homebranch',
230
);
228
);
231
229
232
# helper biblio for the bug 10272 regression test
230
# helper biblio for the bug 10272 regression test
233
- 

Return to bug 18925