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 83-110 elsif ($op eq 'delete-branch-cat') { Link Here
83
        if ($categorycode eq "*") {
83
        if ($categorycode eq "*") {
84
            my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
84
            my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
85
            $sth_delete->execute();
85
            $sth_delete->execute();
86
        } else {
87
            my $sth_delete = $dbh->prepare("DELETE FROM default_borrower_circ_rules
88
                                            WHERE categorycode = ?");
89
            $sth_delete->execute($categorycode);
90
        }
86
        }
91
    } elsif ($categorycode eq "*") {
87
    } elsif ($categorycode eq "*") {
92
        my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
88
        my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
93
                                        WHERE branchcode = ?");
89
                                        WHERE branchcode = ?");
94
        $sth_delete->execute($branch);
90
        $sth_delete->execute($branch);
95
    } else {
96
        my $sth_delete = $dbh->prepare("DELETE FROM branch_borrower_circ_rules
97
                                        WHERE branchcode = ?
98
                                        AND categorycode = ?");
99
        $sth_delete->execute($branch, $categorycode);
100
    }
91
    }
101
    Koha::CirculationRules->set_rule(
92
    Koha::CirculationRules->set_rules(
102
        {
93
        {
103
            branchcode   => $branch,
94
            categorycode => $categorycode eq '*' ? undef : $categorycode,
104
            categorycode => $categorycode,
95
            branchcode   => $branch eq '*'       ? undef : $branch,
105
            itemtype     => undef,
96
            itemtype     => undef,
106
            rule_name    => 'max_holds',
97
            rules        => {
107
            rule_value   => undef,
98
                max_holds         => undef,
99
                maxissueqty       => undef,
100
                maxonsiteissueqty => undef,
101
            }
108
        }
102
        }
109
    );
103
    );
110
}
104
}
Lines 187-194 elsif ($op eq 'add') { Link Here
187
        firstremind                   => $firstremind,
181
        firstremind                   => $firstremind,
188
        chargeperiod                  => $chargeperiod,
182
        chargeperiod                  => $chargeperiod,
189
        chargeperiod_charge_at        => $chargeperiod_charge_at,
183
        chargeperiod_charge_at        => $chargeperiod_charge_at,
190
        maxissueqty                   => $maxissueqty,
191
        maxonsiteissueqty             => $maxonsiteissueqty,
192
        renewalsallowed               => $renewalsallowed,
184
        renewalsallowed               => $renewalsallowed,
193
        renewalperiod                 => $renewalperiod,
185
        renewalperiod                 => $renewalperiod,
194
        norenewalbefore               => $norenewalbefore,
186
        norenewalbefore               => $norenewalbefore,
Lines 216-221 elsif ($op eq 'add') { Link Here
216
        Koha::IssuingRule->new()->set($params)->store();
208
        Koha::IssuingRule->new()->set($params)->store();
217
    }
209
    }
218
210
211
    Koha::CirculationRules->set_rules(
212
        {
213
            categorycode => $bor,
214
            itemtype     => $itemtype,
215
            branchcode   => $br,
216
            rules        => {
217
                maxissueqty       => $maxissueqty,
218
                maxonsiteissueqty => $maxonsiteissueqty,
219
            }
220
        }
221
    );
222
219
}
223
}
220
elsif ($op eq "set-branch-defaults") {
224
elsif ($op eq "set-branch-defaults") {
221
    my $categorycode  = $input->param('categorycode');
225
    my $categorycode  = $input->param('categorycode');
Lines 238-272 elsif ($op eq "set-branch-defaults") { Link Here
238
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
242
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
239
                                        FROM default_circ_rules");
243
                                        FROM default_circ_rules");
240
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
244
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
241
                                        (maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
245
                                        (holdallowed, hold_fulfillment_policy, returnbranch)
242
                                        VALUES (?, ?, ?, ?, ?)");
246
                                        VALUES (?, ?, ?)");
243
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
247
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
244
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
248
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
245
249
246
        $sth_search->execute();
250
        $sth_search->execute();
247
        my $res = $sth_search->fetchrow_hashref();
251
        my $res = $sth_search->fetchrow_hashref();
248
        if ($res->{total}) {
252
        if ($res->{total}) {
249
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
253
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
250
        } else {
254
        } else {
251
            $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
255
            $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
252
        }
256
        }
257
258
        Koha::CirculationRules->set_rules(
259
            {
260
                categorycode => undef,
261
                itemtype     => undef,
262
                branchcode   => undef,
263
                rules        => {
264
                    maxissueqty       => $maxissueqty,
265
                    maxonsiteissueqty => $maxonsiteissueqty,
266
                }
267
            }
268
        );
253
    } else {
269
    } else {
254
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
270
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
255
                                        FROM default_branch_circ_rules
271
                                        FROM default_branch_circ_rules
256
                                        WHERE branchcode = ?");
272
                                        WHERE branchcode = ?");
257
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
273
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
258
                                        (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
274
                                        (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
259
                                        VALUES (?, ?, ?, ?, ?, ?)");
275
                                        VALUES (?, ?, ?, ?)");
260
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
276
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
261
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
277
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
262
                                        WHERE branchcode = ?");
278
                                        WHERE branchcode = ?");
263
        $sth_search->execute($branch);
279
        $sth_search->execute($branch);
264
        my $res = $sth_search->fetchrow_hashref();
280
        my $res = $sth_search->fetchrow_hashref();
265
        if ($res->{total}) {
281
        if ($res->{total}) {
266
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
282
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
267
        } else {
283
        } else {
268
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
284
            $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch);
269
        }
285
        }
286
287
        Koha::CirculationRules->set_rules(
288
            {
289
                categorycode => undef,
290
                itemtype     => undef,
291
                branchcode   => $branch,
292
                rules        => {
293
                    maxissueqty       => $maxissueqty,
294
                    maxonsiteissueqty => $maxonsiteissueqty,
295
                }
296
            }
297
        );
270
    }
298
    }
271
    Koha::CirculationRules->set_rule(
299
    Koha::CirculationRules->set_rule(
272
        {
300
        {
Lines 292-417 elsif ($op eq "add-branch-cat") { Link Here
292
320
293
    if ($branch eq "*") {
321
    if ($branch eq "*") {
294
        if ($categorycode eq "*") {
322
        if ($categorycode eq "*") {
295
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
323
            Koha::CirculationRules->set_rules(
296
                                            FROM default_circ_rules");
297
            my $sth_insert = $dbh->prepare(q|
298
                INSERT INTO default_circ_rules
299
                    (maxissueqty, maxonsiteissueqty, max_holds)
300
                    VALUES (?, ?, ?)
301
            |);
302
            my $sth_update = $dbh->prepare(q|
303
                UPDATE default_circ_rules
304
                SET maxissueqty = ?,
305
                    maxonsiteissueqty = ?,
306
                    max_holds = ?
307
            |);
308
309
            $sth_search->execute();
310
            my $res = $sth_search->fetchrow_hashref();
311
            if ($res->{total}) {
312
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty );
313
            } else {
314
                $sth_insert->execute( $maxissueqty, $maxonsiteissueqty );
315
            }
316
317
            Koha::CirculationRules->set_rule(
318
                {
324
                {
319
                    branchcode   => undef,
320
                    categorycode => undef,
325
                    categorycode => undef,
321
                    itemtype     => undef,
326
                    itemtype     => undef,
322
                    rule_name    => 'max_holds',
327
                    branchcode   => undef,
323
                    rule_value   => $max_holds,
328
                    rules        => {
329
                        max_holds         => $max_holds,
330
                        maxissueqty       => $maxissueqty,
331
                        maxonsiteissueqty => $maxonsiteissueqty,
332
                    }
324
                }
333
                }
325
            );
334
            );
326
        } else {
335
        } else {
327
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
336
            Koha::CirculationRules->set_rules(
328
                                            FROM default_borrower_circ_rules
329
                                            WHERE categorycode = ?");
330
            my $sth_insert = $dbh->prepare(q|
331
                INSERT INTO default_borrower_circ_rules
332
                    (categorycode, maxissueqty, maxonsiteissueqty)
333
                    VALUES ( ?, ?, ?)
334
            |);
335
            my $sth_update = $dbh->prepare(q|
336
                UPDATE default_borrower_circ_rules
337
                SET maxissueqty = ?,
338
                    maxonsiteissueqty = ?,
339
                WHERE categorycode = ?
340
            |);
341
            $sth_search->execute($categorycode);
342
            my $res = $sth_search->fetchrow_hashref();
343
            if ($res->{total}) {
344
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode );
345
            } else {
346
                $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty );
347
            }
348
349
            Koha::CirculationRules->set_rule(
350
                {
337
                {
351
                    branchcode   => undef,
338
                    branchcode   => undef,
352
                    categorycode => $categorycode,
339
                    categorycode => $categorycode,
353
                    itemtype     => undef,
340
                    itemtype     => undef,
354
                    rule_name    => 'max_holds',
341
                    rules        => {
355
                    rule_value   => $max_holds,
342
                        max_holds         => $max_holds,
343
                        maxissueqty       => $maxissueqty,
344
                        maxonsiteissueqty => $maxonsiteissueqty,
345
                    }
356
                }
346
                }
357
            );
347
            );
358
        }
348
        }
359
    } elsif ($categorycode eq "*") {
349
    } elsif ($categorycode eq "*") {
360
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
350
        Koha::CirculationRules->set_rules(
361
                                        FROM default_branch_circ_rules
362
                                        WHERE branchcode = ?");
363
        my $sth_insert = $dbh->prepare(q|
364
            INSERT INTO default_branch_circ_rules
365
            (branchcode, maxissueqty, maxonsiteissueqty)
366
            VALUES (?, ?, ?)
367
        |);
368
        my $sth_update = $dbh->prepare(q|
369
            UPDATE default_branch_circ_rules
370
            SET maxissueqty = ?,
371
                maxonsiteissueqty = ?
372
            WHERE branchcode = ?
373
        |);
374
        $sth_search->execute($branch);
375
        my $res = $sth_search->fetchrow_hashref();
376
        if ($res->{total}) {
377
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch);
378
        } else {
379
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty);
380
        }
381
    } else {
382
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
383
                                        FROM branch_borrower_circ_rules
384
                                        WHERE branchcode = ?
385
                                        AND   categorycode = ?");
386
        my $sth_insert = $dbh->prepare(q|
387
            INSERT INTO branch_borrower_circ_rules
388
            (branchcode, categorycode, maxissueqty, maxonsiteissueqty, max_holds)
389
            VALUES (?, ?, ?, ?, ?)
390
        |);
391
        my $sth_update = $dbh->prepare(q|
392
            UPDATE branch_borrower_circ_rules
393
            SET maxissueqty = ?,
394
                maxonsiteissueqty = ?
395
                max_holds = ?
396
            WHERE branchcode = ?
397
            AND categorycode = ?
398
        |);
399
400
        $sth_search->execute($branch, $categorycode);
401
        my $res = $sth_search->fetchrow_hashref();
402
        if ($res->{total}) {
403
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $max_holds, $branch, $categorycode);
404
        } else {
405
            $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty, $max_holds);
406
        }
407
408
        Koha::CirculationRules->set_rule(
409
            {
351
            {
352
                categorycode => undef,
353
                itemtype     => undef,
410
                branchcode   => $branch,
354
                branchcode   => $branch,
355
                rules        => {
356
                    max_holds         => $max_holds,
357
                    maxissueqty       => $maxissueqty,
358
                    maxonsiteissueqty => $maxonsiteissueqty,
359
                }
360
            }
361
        );
362
    } else {
363
        Koha::CirculationRules->set_rules(
364
            {
411
                categorycode => $categorycode,
365
                categorycode => $categorycode,
412
                itemtype     => undef,
366
                itemtype     => undef,
413
                rule_name    => 'max_holds',
367
                branchcode   => $branch,
414
                rule_value   => $max_holds,
368
                rules        => {
369
                    max_holds         => $max_holds,
370
                    maxissueqty       => $maxissueqty,
371
                    maxonsiteissueqty => $maxonsiteissueqty,
372
                }
415
            }
373
            }
416
        );
374
        );
417
    }
375
    }
Lines 579-618 while (my $row = $sth2->fetchrow_hashref) { Link Here
579
537
580
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
538
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
581
539
582
my $sth_branch_cat;
583
if ($branch eq "*") {
584
    $sth_branch_cat = $dbh->prepare("
585
        SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode
586
        FROM default_borrower_circ_rules
587
        JOIN categories USING (categorycode)
588
589
    ");
590
    $sth_branch_cat->execute();
591
} else {
592
    $sth_branch_cat = $dbh->prepare("
593
        SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode
594
        FROM branch_borrower_circ_rules
595
        JOIN categories USING (categorycode)
596
        WHERE branch_borrower_circ_rules.branchcode = ?
597
    ");
598
    $sth_branch_cat->execute($branch);
599
}
600
601
my @branch_cat_rules = ();
602
while (my $row = $sth_branch_cat->fetchrow_hashref) {
603
    push @branch_cat_rules, $row;
604
}
605
my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humancategorycode'} } @branch_cat_rules;
606
607
# note undef maxissueqty so that template can deal with them
608
foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) {
609
    $entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty});
610
    $entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty});
611
    $entry->{unlimited_max_holds} = 1 unless defined($entry->{max_holds});
612
}
613
614
@sorted_row_loop = sort by_category_and_itemtype @row_loop;
615
616
my $sth_branch_item;
540
my $sth_branch_item;
617
if ($branch eq "*") {
541
if ($branch eq "*") {
618
    $sth_branch_item = $dbh->prepare("
542
    $sth_branch_item = $dbh->prepare("
Lines 653-659 foreach my $entry (@sorted_branch_item_rules) { Link Here
653
577
654
$template->param(show_branch_cat_rule_form => 1);
578
$template->param(show_branch_cat_rule_form => 1);
655
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules);
579
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules);
656
$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules);
657
580
658
my $sth_defaults;
581
my $sth_defaults;
659
if ($branch eq "*") {
582
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 341-385 CREATE TABLE collections_tracking ( Link Here
341
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
341
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
342
342
343
--
343
--
344
-- Table structure for table `branch_borrower_circ_rules`
345
--
346
347
DROP TABLE IF EXISTS `branch_borrower_circ_rules`;
348
CREATE TABLE `branch_borrower_circ_rules` ( -- includes default circulation rules for patron categories found under "Checkout limit by patron category"
349
  `branchcode` VARCHAR(10) NOT NULL, -- the branch this rule applies to (branches.branchcode)
350
  `categorycode` VARCHAR(10) NOT NULL, -- the patron category this rule applies to (categories.categorycode)
351
  `maxissueqty` int(4) default NULL, -- the maximum number of checkouts this patron category can have at this branch
352
  `maxonsiteissueqty` int(4) default NULL, -- the maximum number of on-site checkouts this patron category can have at this branch
353
  PRIMARY KEY (`categorycode`, `branchcode`),
354
  CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
355
    ON DELETE CASCADE ON UPDATE CASCADE,
356
  CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
357
    ON DELETE CASCADE ON UPDATE CASCADE
358
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
359
360
--
361
-- Table structure for table `default_borrower_circ_rules`
362
--
363
364
DROP TABLE IF EXISTS `default_borrower_circ_rules`;
365
CREATE TABLE `default_borrower_circ_rules` ( -- default checkout rules found under "Default checkout, hold and return policy"
366
  `categorycode` VARCHAR(10) NOT NULL, -- patron category this rul
367
  `maxissueqty` int(4) default NULL,
368
  `maxonsiteissueqty` int(4) default NULL,
369
  PRIMARY KEY (`categorycode`),
370
  CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
371
    ON DELETE CASCADE ON UPDATE CASCADE
372
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
373
374
--
375
-- Table structure for table `default_branch_circ_rules`
344
-- Table structure for table `default_branch_circ_rules`
376
--
345
--
377
346
378
DROP TABLE IF EXISTS `default_branch_circ_rules`;
347
DROP TABLE IF EXISTS `default_branch_circ_rules`;
379
CREATE TABLE `default_branch_circ_rules` (
348
CREATE TABLE `default_branch_circ_rules` (
380
  `branchcode` VARCHAR(10) NOT NULL,
349
  `branchcode` VARCHAR(10) NOT NULL,
381
  `maxissueqty` int(4) default NULL,
382
  `maxonsiteissueqty` int(4) default NULL,
383
  `holdallowed` tinyint(1) default NULL,
350
  `holdallowed` tinyint(1) default NULL,
384
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
351
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
385
  `returnbranch` varchar(15) default NULL,
352
  `returnbranch` varchar(15) default NULL,
Lines 395-402 CREATE TABLE `default_branch_circ_rules` ( Link Here
395
DROP TABLE IF EXISTS `default_circ_rules`;
362
DROP TABLE IF EXISTS `default_circ_rules`;
396
CREATE TABLE `default_circ_rules` (
363
CREATE TABLE `default_circ_rules` (
397
    `singleton` enum('singleton') NOT NULL default 'singleton',
364
    `singleton` enum('singleton') NOT NULL default 'singleton',
398
    `maxissueqty` int(4) default NULL,
399
    `maxonsiteissueqty` int(4) default NULL,
400
    `holdallowed` int(1) default NULL,
365
    `holdallowed` int(1) default NULL,
401
    hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
366
    hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
402
    `returnbranch` varchar(15) default NULL,
367
    `returnbranch` varchar(15) default NULL,
Lines 844-851 CREATE TABLE `issuingrules` ( -- circulation and fine rules Link Here
844
  `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period
809
  `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period
845
  `accountsent` int(11) default NULL, -- not used? always NULL
810
  `accountsent` int(11) default NULL, -- not used? always NULL
846
  `chargename` varchar(100) default NULL, -- not used? always NULL
811
  `chargename` varchar(100) default NULL, -- not used? always NULL
847
  `maxissueqty` int(4) default NULL, -- total number of checkouts allowed
848
  `maxonsiteissueqty` int(4) default NULL, -- total number of on-site checkouts allowed
849
  `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit
812
  `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit
850
  `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours)
813
  `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours)
851
  `hardduedate` date default NULL, -- hard due date
814
  `hardduedate` date default NULL, -- hard due date
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-26 / +50 lines)
Lines 1-8 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Asset %]
2
[% USE Asset %]
3
[% USE Branches %]
3
[% USE Branches %]
4
[% USE Categories %]
4
[% USE CirculationRules %]
5
[% USE CirculationRules %]
5
[% SET footerjs = 1 %]
6
[% SET footerjs = 1 %]
7
8
[% SET branchcode = humanbranch %]
9
10
[% SET categorycodes = ['*'] %]
11
[% FOREACH pc IN patron_categories %]
12
    [% categorycodes.push( pc.id ) %]
13
[% END %]
14
6
[% INCLUDE 'doc-head-open.inc' %]
15
[% INCLUDE 'doc-head-open.inc' %]
7
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
16
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
8
[% INCLUDE 'doc-head-close.inc' %]
17
[% INCLUDE 'doc-head-close.inc' %]
Lines 117-134 Link Here
117
                                                          <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype | html %]&amp;categorycode=[% rule.categorycode | html %]&amp;branch=[% rule.current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
126
                                                          <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype | html %]&amp;categorycode=[% rule.categorycode | html %]&amp;branch=[% rule.current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
118
                                                        </td>
127
                                                        </td>
119
128
120
							<td>[% IF ( rule.unlimited_maxissueqty ) %]
129
							<td>
121
									<span>Unlimited</span>
130
                                [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxissueqty' ) %]
122
								[% ELSE %]
131
                                [% IF rule_value  %]
123
									[% rule.maxissueqty | html %]
132
                                    [% rule_value | html %]
124
								[% END %]
133
                                [% ELSE %]
125
							</td>
126
                            <td>[% IF rule.unlimited_maxonsiteissueqty %]
127
                                    <span>Unlimited</span>
134
                                    <span>Unlimited</span>
135
                                [% END %]
136
							</td>
137
							<td>
138
                                [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxonsiteissueqty' ) %]
139
                                [% IF rule_value  %]
140
                                    [% rule_value | html %]
128
                                [% ELSE %]
141
                                [% ELSE %]
129
                                    [% rule.maxonsiteissueqty | html %]
142
                                    <span>Unlimited</span>
130
                                [% END %]
143
                                [% END %]
131
                            </td>
144
							</td>
132
							<td>[% rule.issuelength | html %]</td>
145
							<td>[% rule.issuelength | html %]</td>
133
							<td>
146
							<td>
134
							    [% rule.lengthunit | html %]
147
							    [% rule.lengthunit | html %]
Lines 377-384 Link Here
377
                </tr>
390
                </tr>
378
                <tr>
391
                <tr>
379
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
392
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
380
                    <td><input type="text" name="maxissueqty" size="3" value="[% default_maxissueqty | html %]"/></td>
393
                    <td>
381
                    <td><input type="text" name="maxonsiteissueqty" size="3" value="[% default_maxonsiteissueqty | html %]"/></td>
394
                        [% SET maxissueqty  = CirculationRules.Get( branchcode, undef, undef, 'maxissueqty' ) %]
395
                        <input type="text" name="maxissueqty" size="3" value="[% maxissueqty | html %]"/>
396
                    </td>
397
                    <td>
398
                        [% SET maxonsiteissueqty  = CirculationRules.Get( branchcode, undef, undef, 'maxonsiteissueqty' ) %]
399
                        <input type="text" name="maxonsiteissueqty" size="3" value="[% maxonsiteissueqty | html %]"/>
400
                    </td>
382
                    <td>
401
                    <td>
383
                        [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %]
402
                        [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %]
384
                        <input name="max_holds" size="3" value="[% rule_value | html %]" />
403
                        <input name="max_holds" size="3" value="[% rule_value | html %]" />
Lines 494-521 Link Here
494
                    <th>Total holds allowed</th>
513
                    <th>Total holds allowed</th>
495
                    <th>&nbsp;</th>
514
                    <th>&nbsp;</th>
496
                </tr>
515
                </tr>
497
                [% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %]
516
                [% FOREACH c IN categorycodes %]
498
                    [% UNLESS ( loop.odd ) %]
517
                    [% SET maxissueqty = CirculationRules.Get( branchcode, c, undef, 'maxissueqty' ) %]
499
                    <tr class="highlight">
518
                    [% SET maxonsiteissueqty = CirculationRules.Get( branchcode, c, undef, 'maxonsiteissueqty' ) %]
500
                    [% ELSE %]
519
                    [% SET max_holds = CirculationRules.Get( branchcode, c, undef, 'max_holds' ) %]
520
521
                    [% IF maxissueqty || maxissueqty || max_holds %]
501
                    <tr>
522
                    <tr>
502
                    [% END %]
523
                        <td>
503
                        <td>[% IF ( branch_cat_rule_loo.default_humancategorycode ) %]
524
                            [% IF c == '*'%]
504
                                <em>Default</em>
525
                                <em>Default</em>
505
                            [% ELSE %]
526
                            [% ELSE %]
506
                                [% branch_cat_rule_loo.humancategorycode | html %]
527
                                [% Categories.GetName(c) | html %]
507
                            [% END %]
528
                            [% END %]
508
                        </td>
529
                        </td>
509
                        <td>[% IF ( branch_cat_rule_loo.unlimited_maxissueqty ) %]
530
                        <td>
510
                                <span>Unlimited</span>
531
                            [% IF maxissueqty  %]
532
                                [% maxissueqty | html %]
511
                            [% ELSE %]
533
                            [% ELSE %]
512
                                [% branch_cat_rule_loo.maxissueqty | html %]
534
                                <span>Unlimited</span>
513
                            [% END %]
535
                            [% END %]
514
                        </td>
536
                        </td>
515
                        <td>[% IF ( branch_cat_rule_loo.unlimited_maxonsiteissueqty ) %]
537
                        <td>
516
                                <span>Unlimited</span>
538
                            [% IF maxonsiteissueqty  %]
539
                                [% maxonsiteissueqty | html %]
517
                            [% ELSE %]
540
                            [% ELSE %]
518
                                [% branch_cat_rule_loo.maxonsiteissueqty | html %]
541
                                <span>Unlimited</span>
519
                            [% END %]
542
                            [% END %]
520
                        </td>
543
                        </td>
521
                        <td>
544
                        <td>
Lines 523-536 Link Here
523
                            [% IF rule_value.defined && rule_value != '' %]
546
                            [% IF rule_value.defined && rule_value != '' %]
524
                                [% rule_value | html %]
547
                                [% rule_value | html %]
525
                            [% ELSE %]
548
                            [% ELSE %]
526
                                Unlimited
549
                                <span>Unlimited</span>
527
                            [% END %]
550
                            [% END %]
528
                        </td>
551
                        </td>
529
552
530
                        <td class="actions">
553
                        <td class="actions">
531
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% branch_cat_rule_loo.categorycode | html %]&amp;branch=[% current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
554
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% c | html %]&amp;branch=[% current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
532
                        </td>
555
                        </td>
533
                    </tr>
556
                    </tr>
557
                    [% END %]
534
                [% END %]
558
                [% END %]
535
                <tr>
559
                <tr>
536
                    <td>
560
                    <td>
(-)a/t/db_dependent/Circulation.t (-7 / +19 lines)
Lines 37-42 use Koha::Database; Link Here
37
use Koha::IssuingRules;
37
use Koha::IssuingRules;
38
use Koha::Checkouts;
38
use Koha::Checkouts;
39
use Koha::Patrons;
39
use Koha::Patrons;
40
use Koha::CirculationRules;
40
use Koha::Subscriptions;
41
use Koha::Subscriptions;
41
use Koha::Account::Lines;
42
use Koha::Account::Lines;
42
use Koha::Account::Offsets;
43
use Koha::Account::Offsets;
Lines 186-199 is( Link Here
186
187
187
# Set a simple circ policy
188
# Set a simple circ policy
188
$dbh->do('DELETE FROM issuingrules');
189
$dbh->do('DELETE FROM issuingrules');
190
Koha::CirculationRules->search()->delete();
189
$dbh->do(
191
$dbh->do(
190
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed,
192
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed,
191
                                maxissueqty, issuelength, lengthunit,
193
                                issuelength, lengthunit,
192
                                renewalsallowed, renewalperiod,
194
                                renewalsallowed, renewalperiod,
193
                                norenewalbefore, auto_renew,
195
                                norenewalbefore, auto_renew,
194
                                fine, chargeperiod)
196
                                fine, chargeperiod)
195
      VALUES (?, ?, ?, ?,
197
      VALUES (?, ?, ?, ?,
196
              ?, ?, ?,
198
              ?, ?,
197
              ?, ?,
199
              ?, ?,
198
              ?, ?,
200
              ?, ?,
199
              ?, ?
201
              ?, ?
Lines 201-207 $dbh->do( Link Here
201
    },
203
    },
202
    {},
204
    {},
203
    '*', '*', '*', 25,
205
    '*', '*', '*', 25,
204
    20, 14, 'days',
206
    14, 'days',
205
    1, 7,
207
    1, 7,
206
    undef, 0,
208
    undef, 0,
207
    .10, 1
209
    .10, 1
Lines 1039-1056 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1039
    $dbh->do('DELETE FROM issues');
1041
    $dbh->do('DELETE FROM issues');
1040
    $dbh->do('DELETE FROM items');
1042
    $dbh->do('DELETE FROM items');
1041
    $dbh->do('DELETE FROM issuingrules');
1043
    $dbh->do('DELETE FROM issuingrules');
1044
    Koha::CirculationRules->search()->delete();
1042
    $dbh->do(
1045
    $dbh->do(
1043
        q{
1046
        q{
1044
        INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, maxissueqty, issuelength, lengthunit, renewalsallowed, renewalperiod,
1047
        INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, issuelength, lengthunit, renewalsallowed, renewalperiod,
1045
                    norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
1048
                    norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
1046
        },
1049
        },
1047
        {},
1050
        {},
1048
        '*', '*', '*', 25,
1051
        '*', '*', '*', 25,
1049
        20,  14,  'days',
1052
        14,  'days',
1050
        1,   7,
1053
        1,   7,
1051
        undef,  0,
1054
        undef,  0,
1052
        .10, 1
1055
        .10, 1
1053
    );
1056
    );
1057
    Koha::CirculationRules->set_rules(
1058
        {
1059
            categorycode => '*',
1060
            itemtype     => '*',
1061
            branchcode   => '*',
1062
            rules        => {
1063
                maxissueqty => 20
1064
            }
1065
        }
1066
    );
1054
    my ( $biblionumber, $biblioitemnumber ) = add_biblio();
1067
    my ( $biblionumber, $biblioitemnumber ) = add_biblio();
1055
1068
1056
    my $barcode1 = '1234';
1069
    my $barcode1 = '1234';
Lines 1657-1663 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1657
            categorycode => '*',
1670
            categorycode => '*',
1658
            itemtype     => '*',
1671
            itemtype     => '*',
1659
            branchcode   => '*',
1672
            branchcode   => '*',
1660
            maxissueqty  => 99,
1661
            issuelength  => 1,
1673
            issuelength  => 1,
1662
            firstremind  => 1,        # 1 day of grace
1674
            firstremind  => 1,        # 1 day of grace
1663
            finedays     => 2,        # 2 days of fine per day of overdue
1675
            finedays     => 2,        # 2 days of fine per day of overdue
(-)a/t/db_dependent/Circulation/Branch.t (-19 / +41 lines)
Lines 21-26 use C4::Circulation; Link Here
21
use C4::Items;
21
use C4::Items;
22
use C4::Biblio;
22
use C4::Biblio;
23
use C4::Context;
23
use C4::Context;
24
use Koha::CirculationRules;
24
25
25
use Koha::Patrons;
26
use Koha::Patrons;
26
27
Lines 53-59 $dbh->do(q|DELETE FROM categories|); Link Here
53
$dbh->do(q|DELETE FROM accountlines|);
54
$dbh->do(q|DELETE FROM accountlines|);
54
$dbh->do(q|DELETE FROM itemtypes|);
55
$dbh->do(q|DELETE FROM itemtypes|);
55
$dbh->do(q|DELETE FROM branch_item_rules|);
56
$dbh->do(q|DELETE FROM branch_item_rules|);
56
$dbh->do(q|DELETE FROM branch_borrower_circ_rules|);
57
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
57
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
58
$dbh->do(q|DELETE FROM default_circ_rules|);
58
$dbh->do(q|DELETE FROM default_circ_rules|);
59
$dbh->do(q|DELETE FROM default_branch_item_rules|);
59
$dbh->do(q|DELETE FROM default_branch_item_rules|);
Lines 152-182 is_deeply( Link Here
152
"Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined"
152
"Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined"
153
);
153
);
154
154
155
my $query = q|
155
Koha::CirculationRules->set_rules(
156
    INSERT INTO branch_borrower_circ_rules
156
    {
157
    (branchcode, categorycode, maxissueqty, maxonsiteissueqty)
157
        branchcode   => $samplebranch1->{branchcode},
158
    VALUES( ?, ?, ?, ? )
158
        categorycode => $samplecat->{categorycode},
159
|;
159
        itemtype     => undef,
160
160
        rules        => {
161
$dbh->do(
161
            maxissueqty       => 5,
162
    $query, {},
162
            maxonsiteissueqty => 6,
163
    $samplebranch1->{branchcode},
163
        }
164
    $samplecat->{categorycode}, 5, 6
164
    }
165
);
165
);
166
166
167
$query = q|
167
my $query = q|
168
    INSERT INTO default_branch_circ_rules
168
    INSERT INTO default_branch_circ_rules
169
    (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
169
    (branchcode, holdallowed, returnbranch)
170
    VALUES( ?, ?, ?, ?, ? )
170
    VALUES( ?, ?, ? )
171
|;
171
|;
172
$dbh->do( $query, {}, $samplebranch2->{branchcode},
172
$dbh->do( $query, {}, $samplebranch2->{branchcode}, 1, 'holdingbranch' );
173
    3, 2, 1, 'holdingbranch' );
173
Koha::CirculationRules->set_rules(
174
    {
175
        branchcode   => $samplebranch2->{branchcode},
176
        categorycode => undef,
177
        itemtype     => undef,
178
        rules        => {
179
            maxissueqty       => 3,
180
            maxonsiteissueqty => 2,
181
        }
182
    }
183
);
184
174
$query = q|
185
$query = q|
175
    INSERT INTO default_circ_rules
186
    INSERT INTO default_circ_rules
176
    (singleton, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
187
    (singleton, holdallowed, returnbranch)
177
    VALUES( ?, ?, ?, ?, ? )
188
    VALUES( ?, ?, ? )
178
|;
189
|;
179
$dbh->do( $query, {}, 'singleton', 4, 5, 3, 'homebranch' );
190
$dbh->do( $query, {}, 'singleton', 3, 'homebranch' );
191
Koha::CirculationRules->set_rules(
192
    {
193
        branchcode   => undef,
194
        categorycode => undef,
195
        itemtype     => undef,
196
        rules        => {
197
            maxissueqty       => 4,
198
            maxonsiteissueqty => 5,
199
        }
200
    }
201
);
180
202
181
$query =
203
$query =
182
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
204
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
(-)a/t/db_dependent/Circulation/GetHardDueDate.t (-17 / +3 lines)
Lines 117-124 my $sampleissuingrule1 = { Link Here
117
    chargename         => undef,
117
    chargename         => undef,
118
    restrictedtype     => 0,
118
    restrictedtype     => 0,
119
    accountsent        => 0,
119
    accountsent        => 0,
120
    maxissueqty        => 5,
121
    maxonsiteissueqty  => 4,
122
    finedays           => 0,
120
    finedays           => 0,
123
    lengthunit         => 'days',
121
    lengthunit         => 'days',
124
    renewalperiod      => 5,
122
    renewalperiod      => 5,
Lines 152-160 my $sampleissuingrule2 = { Link Here
152
    branchcode         => $samplebranch2->{branchcode},
150
    branchcode         => $samplebranch2->{branchcode},
153
    categorycode       => $samplecat->{categorycode},
151
    categorycode       => $samplecat->{categorycode},
154
    itemtype           => 'BOOK',
152
    itemtype           => 'BOOK',
155
    maxissueqty        => 2,
153
    renewalsallowed    => 'Null',
156
    maxonsiteissueqty  => 1,
157
    renewalsallowed    => 0,
158
    renewalperiod      => 2,
154
    renewalperiod      => 2,
159
    norenewalbefore    => 7,
155
    norenewalbefore    => 7,
160
    auto_renew         => 0,
156
    auto_renew         => 0,
Lines 185-193 my $sampleissuingrule3 = { Link Here
185
    branchcode         => $samplebranch1->{branchcode},
181
    branchcode         => $samplebranch1->{branchcode},
186
    categorycode       => $samplecat->{categorycode},
182
    categorycode       => $samplecat->{categorycode},
187
    itemtype           => 'DVD',
183
    itemtype           => 'DVD',
188
    maxissueqty        => 3,
184
    renewalsallowed    => 'Null',
189
    maxonsiteissueqty  => 2,
190
    renewalsallowed    => 0,
191
    renewalperiod      => 3,
185
    renewalperiod      => 3,
192
    norenewalbefore    => 8,
186
    norenewalbefore    => 8,
193
    auto_renew         => 0,
187
    auto_renew         => 0,
Lines 219-226 $query = 'INSERT INTO issuingrules ( Link Here
219
                branchcode,
213
                branchcode,
220
                categorycode,
214
                categorycode,
221
                itemtype,
215
                itemtype,
222
                maxissueqty,
223
                maxonsiteissueqty,
224
                renewalsallowed,
216
                renewalsallowed,
225
                renewalperiod,
217
                renewalperiod,
226
                norenewalbefore,
218
                norenewalbefore,
Lines 246-259 $query = 'INSERT INTO issuingrules ( Link Here
246
                opacitemholds,
238
                opacitemholds,
247
                cap_fine_to_replacement_price,
239
                cap_fine_to_replacement_price,
248
                article_requests
240
                article_requests
249
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
241
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
250
my $sth = $dbh->prepare($query);
242
my $sth = $dbh->prepare($query);
251
$sth->execute(
243
$sth->execute(
252
    $sampleissuingrule1->{branchcode},
244
    $sampleissuingrule1->{branchcode},
253
    $sampleissuingrule1->{categorycode},
245
    $sampleissuingrule1->{categorycode},
254
    $sampleissuingrule1->{itemtype},
246
    $sampleissuingrule1->{itemtype},
255
    $sampleissuingrule1->{maxissueqty},
256
    $sampleissuingrule1->{maxonsiteissueqty},
257
    $sampleissuingrule1->{renewalsallowed},
247
    $sampleissuingrule1->{renewalsallowed},
258
    $sampleissuingrule1->{renewalperiod},
248
    $sampleissuingrule1->{renewalperiod},
259
    $sampleissuingrule1->{norenewalbefore},
249
    $sampleissuingrule1->{norenewalbefore},
Lines 284-291 $sth->execute( Link Here
284
    $sampleissuingrule2->{branchcode},
274
    $sampleissuingrule2->{branchcode},
285
    $sampleissuingrule2->{categorycode},
275
    $sampleissuingrule2->{categorycode},
286
    $sampleissuingrule2->{itemtype},
276
    $sampleissuingrule2->{itemtype},
287
    $sampleissuingrule2->{maxissueqty},
288
    $sampleissuingrule2->{maxonsiteissueqty},
289
    $sampleissuingrule2->{renewalsallowed},
277
    $sampleissuingrule2->{renewalsallowed},
290
    $sampleissuingrule2->{renewalperiod},
278
    $sampleissuingrule2->{renewalperiod},
291
    $sampleissuingrule2->{norenewalbefore},
279
    $sampleissuingrule2->{norenewalbefore},
Lines 316-323 $sth->execute( Link Here
316
    $sampleissuingrule3->{branchcode},
304
    $sampleissuingrule3->{branchcode},
317
    $sampleissuingrule3->{categorycode},
305
    $sampleissuingrule3->{categorycode},
318
    $sampleissuingrule3->{itemtype},
306
    $sampleissuingrule3->{itemtype},
319
    $sampleissuingrule3->{maxissueqty},
320
    $sampleissuingrule3->{maxonsiteissueqty},
321
    $sampleissuingrule3->{renewalsallowed},
307
    $sampleissuingrule3->{renewalsallowed},
322
    $sampleissuingrule3->{renewalperiod},
308
    $sampleissuingrule3->{renewalperiod},
323
    $sampleissuingrule3->{norenewalbefore},
309
    $sampleissuingrule3->{norenewalbefore},
(-)a/t/db_dependent/Circulation/Returns.t (-1 lines)
Lines 54-60 my $rule = Koha::IssuingRule->new( Link Here
54
        categorycode => '*',
54
        categorycode => '*',
55
        itemtype     => '*',
55
        itemtype     => '*',
56
        branchcode   => '*',
56
        branchcode   => '*',
57
        maxissueqty  => 99,
58
        issuelength  => 1,
57
        issuelength  => 1,
59
    }
58
    }
60
);
59
);
(-)a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t (-13 / +25 lines)
Lines 27-32 use C4::Context; Link Here
27
use Koha::DateUtils qw( dt_from_string );
27
use Koha::DateUtils qw( dt_from_string );
28
use Koha::Database;
28
use Koha::Database;
29
use Koha::Checkouts;
29
use Koha::Checkouts;
30
use Koha::CirculationRules;
30
31
31
use t::lib::TestBuilder;
32
use t::lib::TestBuilder;
32
use t::lib::Mocks;
33
use t::lib::Mocks;
Lines 38-44 our $dbh = C4::Context->dbh; Link Here
38
39
39
$dbh->do(q|DELETE FROM branch_item_rules|);
40
$dbh->do(q|DELETE FROM branch_item_rules|);
40
$dbh->do(q|DELETE FROM issues|);
41
$dbh->do(q|DELETE FROM issues|);
41
$dbh->do(q|DELETE FROM branch_borrower_circ_rules|);
42
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
42
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
43
$dbh->do(q|DELETE FROM default_circ_rules|);
43
$dbh->do(q|DELETE FROM default_circ_rules|);
44
$dbh->do(q|DELETE FROM default_branch_item_rules|);
44
$dbh->do(q|DELETE FROM default_branch_item_rules|);
Lines 91-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