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

(-)a/C4/Circulation.pm (-54 / +71 lines)
Lines 388-397 sub TooMany { Link Here
388
 
388
 
389
    # given branch, patron category, and item type, determine
389
    # given branch, patron category, and item type, determine
390
    # applicable issuing rule
390
    # applicable issuing rule
391
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
391
    my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule(
392
        {   categorycode => $cat_borrower,
392
        {
393
            categorycode => $cat_borrower,
394
            itemtype     => $type,
395
            branchcode   => $branch,
396
            rule_name    => 'maxissueqty',
397
        }
398
    );
399
    my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule(
400
        {
401
            categorycode => $cat_borrower,
393
            itemtype     => $type,
402
            itemtype     => $type,
394
            branchcode   => $branch
403
            branchcode   => $branch,
404
            rule_name    => 'maxonsiteissueqty',
395
        }
405
        }
396
    );
406
    );
397
407
Lines 399-405 sub TooMany { Link Here
399
    # if a rule is found and has a loan limit set, count
409
    # if a rule is found and has a loan limit set, count
400
    # how many loans the patron already has that meet that
410
    # how many loans the patron already has that meet that
401
    # rule
411
    # rule
402
    if (defined($issuing_rule) and defined($issuing_rule->maxissueqty)) {
412
    if (defined($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) {
403
        my @bind_params;
413
        my @bind_params;
404
        my $count_query = q|
414
        my $count_query = q|
405
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
415
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
Lines 407-413 sub TooMany { Link Here
407
            JOIN items USING (itemnumber)
417
            JOIN items USING (itemnumber)
408
        |;
418
        |;
409
419
410
        my $rule_itemtype = $issuing_rule->itemtype;
420
        my $rule_itemtype = $maxissueqty_rule->itemtype;
411
        if ($rule_itemtype eq "*") {
421
        if ($rule_itemtype eq "*") {
412
            # matching rule has the default item type, so count only
422
            # matching rule has the default item type, so count only
413
            # those existing loans that don't fall under a more
423
            # those existing loans that don't fall under a more
Lines 428-435 sub TooMany { Link Here
428
                                    AND   itemtype <> '*'
438
                                    AND   itemtype <> '*'
429
                                  ) ";
439
                                  ) ";
430
            }
440
            }
431
            push @bind_params, $issuing_rule->branchcode;
441
            push @bind_params, $maxissueqty_rule->branchcode;
432
            push @bind_params, $issuing_rule->categorycode;
442
            push @bind_params, $maxissueqty_rule->categorycode;
433
            push @bind_params, $cat_borrower;
443
            push @bind_params, $cat_borrower;
434
        } else {
444
        } else {
435
            # rule has specific item type, so count loans of that
445
            # rule has specific item type, so count loans of that
Lines 445-451 sub TooMany { Link Here
445
455
446
        $count_query .= " AND borrowernumber = ? ";
456
        $count_query .= " AND borrowernumber = ? ";
447
        push @bind_params, $borrower->{'borrowernumber'};
457
        push @bind_params, $borrower->{'borrowernumber'};
448
        my $rule_branch = $issuing_rule->branchcode;
458
        my $rule_branch = $maxissueqty_rule->branchcode;
449
        if ($rule_branch ne "*") {
459
        if ($rule_branch ne "*") {
450
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
460
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
451
                $count_query .= " AND issues.branchcode = ? ";
461
                $count_query .= " AND issues.branchcode = ? ";
Lines 460-467 sub TooMany { Link Here
460
470
461
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
471
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
462
472
463
        my $max_checkouts_allowed = $issuing_rule->maxissueqty;
473
        my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : 0;
464
        my $max_onsite_checkouts_allowed = $issuing_rule->maxonsiteissueqty;
474
        my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : 0;
465
475
466
        if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
476
        if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
467
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
477
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
Lines 546-552 sub TooMany { Link Here
546
        }
556
        }
547
    }
557
    }
548
558
549
    if ( not defined( $issuing_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) {
559
    if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) {
550
        return { reason => 'NO_RULE_DEFINED', max_allowed => 0 };
560
        return { reason => 'NO_RULE_DEFINED', max_allowed => 0 };
551
    }
561
    }
552
562
Lines 1574-1587 maxonsiteissueqty - maximum of on-site checkouts that a Link Here
1574
patron of the given category can have at the given
1584
patron of the given category can have at the given
1575
branch.  If the value is undef, no limit.
1585
branch.  If the value is undef, no limit.
1576
1586
1577
This will first check for a specific branch and
1587
This will check for different branch/category combinations in the following order:
1578
category match from branch_borrower_circ_rules. 
1588
branch and category
1579
1589
branch only
1580
If no rule is found, it will then check default_branch_circ_rules
1590
category only
1581
(same branch, default category).  If no rule is found,
1591
default branch and category
1582
it will then check default_borrower_circ_rules (default 
1583
branch, same category), then failing that, default_circ_rules
1584
(default branch, default category).
1585
1592
1586
If no rule has been found in the database, it will default to
1593
If no rule has been found in the database, it will default to
1587
the buillt in rule:
1594
the buillt in rule:
Lines 1598-1641 wildcards. Link Here
1598
sub GetBranchBorrowerCircRule {
1605
sub GetBranchBorrowerCircRule {
1599
    my ( $branchcode, $categorycode ) = @_;
1606
    my ( $branchcode, $categorycode ) = @_;
1600
1607
1601
    my $rules;
1608
    # Set search prededences
1602
    my $dbh = C4::Context->dbh();
1609
    my @params = (
1603
    $rules = $dbh->selectrow_hashref( q|
1610
        {
1604
        SELECT maxissueqty, maxonsiteissueqty
1611
            branchcode   => $branchcode,
1605
        FROM branch_borrower_circ_rules
1612
            categorycode => $categorycode,
1606
        WHERE branchcode = ?
1613
            itemtype     => undef,
1607
        AND   categorycode = ?
1614
        },
1608
    |, {}, $branchcode, $categorycode ) ;
1615
        {
1609
    return $rules if $rules;
1616
            branchcode   => $branchcode,
1610
1617
            categorycode => undef,
1611
    # try same branch, default borrower category
1618
            itemtype     => undef,
1612
    $rules = $dbh->selectrow_hashref( q|
1619
        },
1613
        SELECT maxissueqty, maxonsiteissueqty
1620
        {
1614
        FROM default_branch_circ_rules
1621
            branchcode   => undef,
1615
        WHERE branchcode = ?
1622
            categorycode => $categorycode,
1616
    |, {}, $branchcode ) ;
1623
            itemtype     => undef,
1617
    return $rules if $rules;
1624
        },
1618
1625
        {
1619
    # try default branch, same borrower category
1626
            branchcode   => undef,
1620
    $rules = $dbh->selectrow_hashref( q|
1627
            categorycode => undef,
1621
        SELECT maxissueqty, maxonsiteissueqty
1628
            itemtype     => undef,
1622
        FROM default_borrower_circ_rules
1629
        },
1623
        WHERE categorycode = ?
1630
    );
1624
    |, {}, $categorycode ) ;
1625
    return $rules if $rules;
1626
1627
    # try default branch, default borrower category
1628
    $rules = $dbh->selectrow_hashref( q|
1629
        SELECT maxissueqty, maxonsiteissueqty
1630
        FROM default_circ_rules
1631
    |, {} );
1632
    return $rules if $rules;
1633
1631
1634
    # built-in default circulation rule
1632
    # Initialize default values
1635
    return {
1633
    my $rules = {
1636
        maxissueqty => undef,
1634
        maxissueqty       => undef,
1637
        maxonsiteissueqty => undef,
1635
        maxonsiteissueqty => undef,
1638
    };
1636
    };
1637
1638
    # Search for rules!
1639
    foreach my $rule_name (qw( maxissueqty maxonsiteissueqty )) {
1640
        foreach my $params (@params) {
1641
            my $rule = Koha::CirculationRules->search(
1642
                {
1643
                    rule_name => $rule_name,
1644
                    %$params,
1645
                }
1646
            )->next();
1647
1648
            if ( $rule ) {
1649
                $rules->{$rule_name} = $rule->rule_value;
1650
                last;
1651
            }
1652
        }
1653
    }
1654
1655
    return $rules;
1639
}
1656
}
1640
1657
1641
=head2 GetBranchItemRule
1658
=head2 GetBranchItemRule
(-)a/Koha/CirculationRules.pm (-4 / +8 lines)
Lines 145-161 sub set_rules { Link Here
145
    my $itemtype     = $params->{itemtype};
145
    my $itemtype     = $params->{itemtype};
146
    my $rules        = $params->{rules};
146
    my $rules        = $params->{rules};
147
147
148
    foreach my $rule (@$rules) {
148
    my $rule_objects = [];
149
        Koha::CirculationRules->set_rule(
149
    while ( my ( $rule_name, $rule_value ) = each %$rules ) {
150
        my $rule_object = Koha::CirculationRules->set_rule(
150
            {
151
            {
151
                branchcode   => $branchcode,
152
                branchcode   => $branchcode,
152
                categorycode => $categorycode,
153
                categorycode => $categorycode,
153
                itemtype     => $itemtype,
154
                itemtype     => $itemtype,
154
                rule_name    => $rule->{rule_name},
155
                rule_name    => $rule_name,
155
                rule_value   => $rule->{rule_value},
156
                rule_value   => $rule_value,
156
            }
157
            }
157
        );
158
        );
159
        push( @$rule_objects, $rule_object );
158
    }
160
    }
161
162
    return $rule_objects;
159
}
163
}
160
164
161
=head3 type
165
=head3 type
(-)a/admin/smart-rules.pl (-163 / +86 lines)
Lines 91-118 elsif ($op eq 'delete-branch-cat') { Link Here
91
        if ($categorycode eq "*") {
91
        if ($categorycode eq "*") {
92
            my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
92
            my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
93
            $sth_delete->execute();
93
            $sth_delete->execute();
94
        } else {
95
            my $sth_delete = $dbh->prepare("DELETE FROM default_borrower_circ_rules
96
                                            WHERE categorycode = ?");
97
            $sth_delete->execute($categorycode);
98
        }
94
        }
99
    } elsif ($categorycode eq "*") {
95
    } elsif ($categorycode eq "*") {
100
        my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
96
        my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
101
                                        WHERE branchcode = ?");
97
                                        WHERE branchcode = ?");
102
        $sth_delete->execute($branch);
98
        $sth_delete->execute($branch);
103
    } else {
104
        my $sth_delete = $dbh->prepare("DELETE FROM branch_borrower_circ_rules
105
                                        WHERE branchcode = ?
106
                                        AND categorycode = ?");
107
        $sth_delete->execute($branch, $categorycode);
108
    }
99
    }
109
    Koha::CirculationRules->set_rule(
100
    Koha::CirculationRules->set_rules(
110
        {
101
        {
111
            branchcode   => $branch,
102
            categorycode => $categorycode eq '*' ? undef : $categorycode,
112
            categorycode => $categorycode,
103
            branchcode   => $branch eq '*'       ? undef : $branch,
113
            itemtype     => undef,
104
            itemtype     => undef,
114
            rule_name    => 'max_holds',
105
            rules        => {
115
            rule_value   => undef,
106
                max_holds         => undef,
107
                maxissueqty       => undef,
108
                maxonsiteissueqty => undef,
109
            }
116
        }
110
        }
117
    );
111
    );
118
}
112
}
Lines 199-206 elsif ($op eq 'add') { Link Here
199
        firstremind                   => $firstremind,
193
        firstremind                   => $firstremind,
200
        chargeperiod                  => $chargeperiod,
194
        chargeperiod                  => $chargeperiod,
201
        chargeperiod_charge_at        => $chargeperiod_charge_at,
195
        chargeperiod_charge_at        => $chargeperiod_charge_at,
202
        maxissueqty                   => $maxissueqty,
203
        maxonsiteissueqty             => $maxonsiteissueqty,
204
        renewalsallowed               => $renewalsallowed,
196
        renewalsallowed               => $renewalsallowed,
205
        renewalperiod                 => $renewalperiod,
197
        renewalperiod                 => $renewalperiod,
206
        norenewalbefore               => $norenewalbefore,
198
        norenewalbefore               => $norenewalbefore,
Lines 230-235 elsif ($op eq 'add') { Link Here
230
        Koha::IssuingRule->new()->set($params)->store();
222
        Koha::IssuingRule->new()->set($params)->store();
231
    }
223
    }
232
224
225
    Koha::CirculationRules->set_rules(
226
        {
227
            categorycode => $bor,
228
            itemtype     => $itemtype,
229
            branchcode   => $br,
230
            rules        => {
231
                maxissueqty       => $maxissueqty,
232
                maxonsiteissueqty => $maxonsiteissueqty,
233
            }
234
        }
235
    );
236
233
}
237
}
234
elsif ($op eq "set-branch-defaults") {
238
elsif ($op eq "set-branch-defaults") {
235
    my $categorycode  = $input->param('categorycode');
239
    my $categorycode  = $input->param('categorycode');
Lines 252-286 elsif ($op eq "set-branch-defaults") { Link Here
252
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
256
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
253
                                        FROM default_circ_rules");
257
                                        FROM default_circ_rules");
254
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
258
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
255
                                        (maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
259
                                        (holdallowed, hold_fulfillment_policy, returnbranch)
256
                                        VALUES (?, ?, ?, ?, ?)");
260
                                        VALUES (?, ?, ?)");
257
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
261
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
258
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
262
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
259
263
260
        $sth_search->execute();
264
        $sth_search->execute();
261
        my $res = $sth_search->fetchrow_hashref();
265
        my $res = $sth_search->fetchrow_hashref();
262
        if ($res->{total}) {
266
        if ($res->{total}) {
263
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
267
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
264
        } else {
268
        } else {
265
            $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
269
            $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
266
        }
270
        }
271
272
        Koha::CirculationRules->set_rules(
273
            {
274
                categorycode => undef,
275
                itemtype     => undef,
276
                branchcode   => undef,
277
                rules        => {
278
                    maxissueqty       => $maxissueqty,
279
                    maxonsiteissueqty => $maxonsiteissueqty,
280
                }
281
            }
282
        );
267
    } else {
283
    } else {
268
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
284
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
269
                                        FROM default_branch_circ_rules
285
                                        FROM default_branch_circ_rules
270
                                        WHERE branchcode = ?");
286
                                        WHERE branchcode = ?");
271
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
287
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
272
                                        (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
288
                                        (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
273
                                        VALUES (?, ?, ?, ?, ?, ?)");
289
                                        VALUES (?, ?, ?, ?)");
274
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
290
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
275
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
291
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
276
                                        WHERE branchcode = ?");
292
                                        WHERE branchcode = ?");
277
        $sth_search->execute($branch);
293
        $sth_search->execute($branch);
278
        my $res = $sth_search->fetchrow_hashref();
294
        my $res = $sth_search->fetchrow_hashref();
279
        if ($res->{total}) {
295
        if ($res->{total}) {
280
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
296
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
281
        } else {
297
        } else {
282
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
298
            $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch);
283
        }
299
        }
300
301
        Koha::CirculationRules->set_rules(
302
            {
303
                categorycode => undef,
304
                itemtype     => undef,
305
                branchcode   => $branch,
306
                rules        => {
307
                    maxissueqty       => $maxissueqty,
308
                    maxonsiteissueqty => $maxonsiteissueqty,
309
                }
310
            }
311
        );
284
    }
312
    }
285
    Koha::CirculationRules->set_rule(
313
    Koha::CirculationRules->set_rule(
286
        {
314
        {
Lines 306-430 elsif ($op eq "add-branch-cat") { Link Here
306
334
307
    if ($branch eq "*") {
335
    if ($branch eq "*") {
308
        if ($categorycode eq "*") {
336
        if ($categorycode eq "*") {
309
            #FIXME This block is will probably be never used
337
            Koha::CirculationRules->set_rules(
310
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
311
                                            FROM default_circ_rules");
312
            my $sth_insert = $dbh->prepare(q|
313
                INSERT INTO default_circ_rules
314
                    (maxissueqty, maxonsiteissueqty)
315
                    VALUES (?, ?)
316
            |);
317
            my $sth_update = $dbh->prepare(q|
318
                UPDATE default_circ_rules
319
                SET maxissueqty = ?,
320
                    maxonsiteissueqty = ?,
321
            |);
322
323
            $sth_search->execute();
324
            my $res = $sth_search->fetchrow_hashref();
325
            if ($res->{total}) {
326
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty );
327
            } else {
328
                $sth_insert->execute( $maxissueqty, $maxonsiteissueqty );
329
            }
330
331
            Koha::CirculationRules->set_rule(
332
                {
338
                {
333
                    branchcode   => undef,
334
                    categorycode => undef,
339
                    categorycode => undef,
335
                    itemtype     => undef,
340
                    itemtype     => undef,
336
                    rule_name    => 'max_holds',
341
                    branchcode   => undef,
337
                    rule_value   => $max_holds,
342
                    rules        => {
343
                        max_holds         => $max_holds,
344
                        maxissueqty       => $maxissueqty,
345
                        maxonsiteissueqty => $maxonsiteissueqty,
346
                    }
338
                }
347
                }
339
            );
348
            );
340
        } else {
349
        } else {
341
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
350
            Koha::CirculationRules->set_rules(
342
                                            FROM default_borrower_circ_rules
343
                                            WHERE categorycode = ?");
344
            my $sth_insert = $dbh->prepare(q|
345
                INSERT INTO default_borrower_circ_rules
346
                    (categorycode, maxissueqty, maxonsiteissueqty)
347
                    VALUES ( ?, ?, ?)
348
            |);
349
            my $sth_update = $dbh->prepare(q|
350
                UPDATE default_borrower_circ_rules
351
                SET maxissueqty = ?,
352
                    maxonsiteissueqty = ?,
353
                WHERE categorycode = ?
354
            |);
355
            $sth_search->execute($categorycode);
356
            my $res = $sth_search->fetchrow_hashref();
357
            if ($res->{total}) {
358
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode );
359
            } else {
360
                $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty );
361
            }
362
363
            Koha::CirculationRules->set_rule(
364
                {
351
                {
365
                    branchcode   => undef,
352
                    branchcode   => undef,
366
                    categorycode => $categorycode,
353
                    categorycode => $categorycode,
367
                    itemtype     => undef,
354
                    itemtype     => undef,
368
                    rule_name    => 'max_holds',
355
                    rules        => {
369
                    rule_value   => $max_holds,
356
                        max_holds         => $max_holds,
357
                        maxissueqty       => $maxissueqty,
358
                        maxonsiteissueqty => $maxonsiteissueqty,
359
                    }
370
                }
360
                }
371
            );
361
            );
372
        }
362
        }
373
    } elsif ($categorycode eq "*") {
363
    } elsif ($categorycode eq "*") {
374
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
364
        Koha::CirculationRules->set_rules(
375
                                        FROM default_branch_circ_rules
376
                                        WHERE branchcode = ?");
377
        my $sth_insert = $dbh->prepare(q|
378
            INSERT INTO default_branch_circ_rules
379
            (branchcode, maxissueqty, maxonsiteissueqty)
380
            VALUES (?, ?, ?)
381
        |);
382
        my $sth_update = $dbh->prepare(q|
383
            UPDATE default_branch_circ_rules
384
            SET maxissueqty = ?,
385
                maxonsiteissueqty = ?
386
            WHERE branchcode = ?
387
        |);
388
        $sth_search->execute($branch);
389
        my $res = $sth_search->fetchrow_hashref();
390
        if ($res->{total}) {
391
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch);
392
        } else {
393
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty);
394
        }
395
    } else {
396
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
397
                                        FROM branch_borrower_circ_rules
398
                                        WHERE branchcode = ?
399
                                        AND   categorycode = ?");
400
        my $sth_insert = $dbh->prepare(q|
401
            INSERT INTO branch_borrower_circ_rules
402
            (branchcode, categorycode, maxissueqty, maxonsiteissueqty)
403
            VALUES (?, ?, ?, ?)
404
        |);
405
        my $sth_update = $dbh->prepare(q|
406
            UPDATE branch_borrower_circ_rules
407
            SET maxissueqty = ?,
408
                maxonsiteissueqty = ?
409
            WHERE branchcode = ?
410
            AND categorycode = ?
411
        |);
412
413
        $sth_search->execute($branch, $categorycode);
414
        my $res = $sth_search->fetchrow_hashref();
415
        if ($res->{total}) {
416
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch, $categorycode);
417
        } else {
418
            $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty);
419
        }
420
421
        Koha::CirculationRules->set_rule(
422
            {
365
            {
366
                categorycode => undef,
367
                itemtype     => undef,
423
                branchcode   => $branch,
368
                branchcode   => $branch,
369
                rules        => {
370
                    max_holds         => $max_holds,
371
                    maxissueqty       => $maxissueqty,
372
                    maxonsiteissueqty => $maxonsiteissueqty,
373
                }
374
            }
375
        );
376
    } else {
377
        Koha::CirculationRules->set_rules(
378
            {
424
                categorycode => $categorycode,
379
                categorycode => $categorycode,
425
                itemtype     => undef,
380
                itemtype     => undef,
426
                rule_name    => 'max_holds',
381
                branchcode   => $branch,
427
                rule_value   => $max_holds,
382
                rules        => {
383
                    max_holds         => $max_holds,
384
                    maxissueqty       => $maxissueqty,
385
                    maxonsiteissueqty => $maxonsiteissueqty,
386
                }
428
            }
387
            }
429
        );
388
        );
430
    }
389
    }
Lines 592-632 while (my $row = $sth2->fetchrow_hashref) { Link Here
592
551
593
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
552
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
594
553
595
my $sth_branch_cat;
596
if ($branch eq "*") {
597
    $sth_branch_cat = $dbh->prepare("
598
        SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode
599
        FROM default_borrower_circ_rules
600
        JOIN categories USING (categorycode)
601
602
    ");
603
    $sth_branch_cat->execute();
604
} else {
605
    $sth_branch_cat = $dbh->prepare("
606
        SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode
607
        FROM branch_borrower_circ_rules
608
        JOIN categories USING (categorycode)
609
        WHERE branch_borrower_circ_rules.branchcode = ?
610
    ");
611
    $sth_branch_cat->execute($branch);
612
}
613
614
my @branch_cat_rules = ();
615
while (my $row = $sth_branch_cat->fetchrow_hashref) {
616
    push @branch_cat_rules, $row;
617
}
618
my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humancategorycode'} } @branch_cat_rules;
619
620
# note undef maxissueqty so that template can deal with them
621
foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) {
622
    $entry->{unlimited_maxissueqty}       = 1 unless defined($entry->{maxissueqty});
623
    $entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty});
624
    $entry->{unlimited_max_holds}         = 1 unless defined($entry->{max_holds});
625
    $entry->{unlimited_holds_per_day}     = 1 unless defined($entry->{holds_per_day});
626
}
627
628
@sorted_row_loop = sort by_category_and_itemtype @row_loop;
629
630
my $sth_branch_item;
554
my $sth_branch_item;
631
if ($branch eq "*") {
555
if ($branch eq "*") {
632
    $sth_branch_item = $dbh->prepare("
556
    $sth_branch_item = $dbh->prepare("
Lines 667-673 foreach my $entry (@sorted_branch_item_rules) { Link Here
667
591
668
$template->param(show_branch_cat_rule_form => 1);
592
$template->param(show_branch_cat_rule_form => 1);
669
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules);
593
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules);
670
$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules);
671
594
672
my $sth_defaults;
595
my $sth_defaults;
673
if ($branch eq "*") {
596
if ($branch eq "*") {
(-)a/installer/data/mysql/atomicupdate/bug_18925.perl (+75 lines)
Line 0 Link Here
1
$DBversion = 'XXX';  # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    if ( column_exists( 'branch_borrower_circ_rules', 'maxissueqty' ) ) {
4
        $dbh->do("
5
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
6
            SELECT categorycode, branchcode, NULL, 'maxissueqty', maxissueqty
7
            FROM branch_borrower_circ_rules
8
        ");
9
        $dbh->do("
10
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
11
            SELECT categorycode, branchcode, NULL, 'maxonsiteissueqty', maxonsiteissueqty
12
            FROM branch_borrower_circ_rules
13
        ");
14
        $dbh->do("DROP TABLE branch_borrower_circ_rules");
15
    }
16
17
    if ( column_exists( 'default_borrower_circ_rules', 'maxissueqty' ) ) {
18
        $dbh->do("
19
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
20
            SELECT categorycode, NULL, NULL, 'maxissueqty', maxissueqty
21
            FROM default_borrower_circ_rules
22
        ");
23
        $dbh->do("
24
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
25
            SELECT categorycode, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty
26
            FROM default_borrower_circ_rules
27
        ");
28
        $dbh->do("DROP TABLE default_borrower_circ_rules");
29
    }
30
31
    if ( column_exists( 'default_circ_rules', 'maxissueqty' ) ) {
32
        $dbh->do("
33
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
34
            SELECT NULL, NULL, NULL, 'maxissueqty', maxissueqty
35
            FROM default_circ_rules
36
        ");
37
        $dbh->do("
38
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
39
            SELECT NULL, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty
40
            FROM default_circ_rules
41
        ");
42
        $dbh->do("ALTER TABLE default_circ_rules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty");
43
    }
44
45
    if ( column_exists( 'default_branch_circ_rules', 'maxissueqty' ) ) {
46
        $dbh->do("
47
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
48
            SELECT NULL, branchcode, NULL, 'maxissueqty', maxissueqty
49
            FROM default_branch_circ_rules
50
        ");
51
        $dbh->do("
52
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
53
            SELECT NULL, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty
54
            FROM default_branch_circ_rules
55
        ");
56
        $dbh->do("ALTER TABLE default_branch_circ_rules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty");
57
    }
58
59
    if ( column_exists( 'issuingrules', 'maxissueqty' ) ) {
60
        $dbh->do("
61
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
62
            SELECT categorycode, branchcode, itemtype, 'maxissueqty', maxissueqty
63
            FROM issuingrules
64
        ");
65
        $dbh->do("
66
            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
67
            SELECT categorycode, branchcode, itemtype, 'maxonsiteissueqty', maxonsiteissueqty
68
            FROM issuingrules
69
        ");
70
        $dbh->do("ALTER TABLE issuingrules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty");
71
    }
72
73
    SetVersion( $DBversion );
74
    print "Upgrade to $DBversion done (Bug 18925 - Move maxissueqty and maxonsiteissueqty to circulation_rules)\n";
75
}
(-)a/installer/data/mysql/kohastructure.sql (-37 lines)
Lines 353-397 CREATE TABLE collections_tracking ( Link Here
353
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
353
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
354
354
355
--
355
--
356
-- Table structure for table `branch_borrower_circ_rules`
357
--
358
359
DROP TABLE IF EXISTS `branch_borrower_circ_rules`;
360
CREATE TABLE `branch_borrower_circ_rules` ( -- includes default circulation rules for patron categories found under "Checkout limit by patron category"
361
  `branchcode` VARCHAR(10) NOT NULL, -- the branch this rule applies to (branches.branchcode)
362
  `categorycode` VARCHAR(10) NOT NULL, -- the patron category this rule applies to (categories.categorycode)
363
  `maxissueqty` int(4) default NULL, -- the maximum number of checkouts this patron category can have at this branch
364
  `maxonsiteissueqty` int(4) default NULL, -- the maximum number of on-site checkouts this patron category can have at this branch
365
  PRIMARY KEY (`categorycode`, `branchcode`),
366
  CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
367
    ON DELETE CASCADE ON UPDATE CASCADE,
368
  CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
369
    ON DELETE CASCADE ON UPDATE CASCADE
370
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
371
372
--
373
-- Table structure for table `default_borrower_circ_rules`
374
--
375
376
DROP TABLE IF EXISTS `default_borrower_circ_rules`;
377
CREATE TABLE `default_borrower_circ_rules` ( -- default checkout rules found under "Default checkout, hold and return policy"
378
  `categorycode` VARCHAR(10) NOT NULL, -- patron category this rul
379
  `maxissueqty` int(4) default NULL,
380
  `maxonsiteissueqty` int(4) default NULL,
381
  PRIMARY KEY (`categorycode`),
382
  CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
383
    ON DELETE CASCADE ON UPDATE CASCADE
384
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
385
386
--
387
-- Table structure for table `default_branch_circ_rules`
356
-- Table structure for table `default_branch_circ_rules`
388
--
357
--
389
358
390
DROP TABLE IF EXISTS `default_branch_circ_rules`;
359
DROP TABLE IF EXISTS `default_branch_circ_rules`;
391
CREATE TABLE `default_branch_circ_rules` (
360
CREATE TABLE `default_branch_circ_rules` (
392
  `branchcode` VARCHAR(10) NOT NULL,
361
  `branchcode` VARCHAR(10) NOT NULL,
393
  `maxissueqty` int(4) default NULL,
394
  `maxonsiteissueqty` int(4) default NULL,
395
  `holdallowed` tinyint(1) default NULL,
362
  `holdallowed` tinyint(1) default NULL,
396
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
363
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
397
  `returnbranch` varchar(15) default NULL,
364
  `returnbranch` varchar(15) default NULL,
Lines 407-414 CREATE TABLE `default_branch_circ_rules` ( Link Here
407
DROP TABLE IF EXISTS `default_circ_rules`;
374
DROP TABLE IF EXISTS `default_circ_rules`;
408
CREATE TABLE `default_circ_rules` (
375
CREATE TABLE `default_circ_rules` (
409
    `singleton` enum('singleton') NOT NULL default 'singleton',
376
    `singleton` enum('singleton') NOT NULL default 'singleton',
410
    `maxissueqty` int(4) default NULL,
411
    `maxonsiteissueqty` int(4) default NULL,
412
    `holdallowed` int(1) default NULL,
377
    `holdallowed` int(1) default NULL,
413
    hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
378
    hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
414
    `returnbranch` varchar(15) default NULL,
379
    `returnbranch` varchar(15) default NULL,
Lines 873-880 CREATE TABLE `issuingrules` ( -- circulation and fine rules Link Here
873
  `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period
838
  `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period
874
  `accountsent` int(11) default NULL, -- not used? always NULL
839
  `accountsent` int(11) default NULL, -- not used? always NULL
875
  `chargename` varchar(100) default NULL, -- not used? always NULL
840
  `chargename` varchar(100) default NULL, -- not used? always NULL
876
  `maxissueqty` int(4) default NULL, -- total number of checkouts allowed
877
  `maxonsiteissueqty` int(4) default NULL, -- total number of on-site checkouts allowed
878
  `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit
841
  `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit
879
  `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours)
842
  `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours)
880
  `hardduedate` date default NULL, -- hard due date
843
  `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 126-143 Link Here
126
                                                                <a name="viewnote" data-toggle="popover" title="Note" data-content="[% rule.note | html %]" data-placement="top" data-trigger="hover">View note</a>
135
                                                                <a name="viewnote" data-toggle="popover" title="Note" data-content="[% rule.note | html %]" data-placement="top" data-trigger="hover">View note</a>
127
                                                            [% ELSE %]&nbsp;[% END %]
136
                                                            [% ELSE %]&nbsp;[% END %]
128
                                                        </td>
137
                                                        </td>
129
							<td>[% IF ( rule.unlimited_maxissueqty ) %]
138
							<td>
130
									<span>Unlimited</span>
139
                                [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxissueqty' ) %]
131
								[% ELSE %]
140
                                [% IF rule_value  %]
132
									[% rule.maxissueqty | html %]
141
                                    [% rule_value | html %]
133
								[% END %]
142
                                [% ELSE %]
134
							</td>
135
                            <td>[% IF rule.unlimited_maxonsiteissueqty %]
136
                                    <span>Unlimited</span>
143
                                    <span>Unlimited</span>
144
                                [% END %]
145
							</td>
146
							<td>
147
                                [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxonsiteissueqty' ) %]
148
                                [% IF rule_value  %]
149
                                    [% rule_value | html %]
137
                                [% ELSE %]
150
                                [% ELSE %]
138
                                    [% rule.maxonsiteissueqty | html %]
151
                                    <span>Unlimited</span>
139
                                [% END %]
152
                                [% END %]
140
                            </td>
153
							</td>
141
							<td>[% rule.issuelength | html %]</td>
154
							<td>[% rule.issuelength | html %]</td>
142
							<td>
155
							<td>
143
							    [% rule.lengthunit | html %]
156
							    [% rule.lengthunit | html %]
Lines 396-403 Link Here
396
                </tr>
409
                </tr>
397
                <tr>
410
                <tr>
398
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
411
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
399
                    <td><input type="text" name="maxissueqty" size="3" value="[% default_maxissueqty | html %]"/></td>
412
                    <td>
400
                    <td><input type="text" name="maxonsiteissueqty" size="3" value="[% default_maxonsiteissueqty | html %]"/></td>
413
                        [% SET maxissueqty  = CirculationRules.Get( branchcode, undef, undef, 'maxissueqty' ) %]
414
                        <input type="text" name="maxissueqty" size="3" value="[% maxissueqty | html %]"/>
415
                    </td>
416
                    <td>
417
                        [% SET maxonsiteissueqty  = CirculationRules.Get( branchcode, undef, undef, 'maxonsiteissueqty' ) %]
418
                        <input type="text" name="maxonsiteissueqty" size="3" value="[% maxonsiteissueqty | html %]"/>
419
                    </td>
401
                    <td>
420
                    <td>
402
                        [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %]
421
                        [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %]
403
                        <input name="max_holds" size="3" value="[% rule_value | html %]" />
422
                        <input name="max_holds" size="3" value="[% rule_value | html %]" />
Lines 513-540 Link Here
513
                    <th>Total holds allowed</th>
532
                    <th>Total holds allowed</th>
514
                    <th>&nbsp;</th>
533
                    <th>&nbsp;</th>
515
                </tr>
534
                </tr>
516
                [% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %]
535
                [% FOREACH c IN categorycodes %]
517
                    [% UNLESS ( loop.odd ) %]
536
                    [% SET maxissueqty = CirculationRules.Get( branchcode, c, undef, 'maxissueqty' ) %]
518
                    <tr class="highlight">
537
                    [% SET maxonsiteissueqty = CirculationRules.Get( branchcode, c, undef, 'maxonsiteissueqty' ) %]
519
                    [% ELSE %]
538
                    [% SET max_holds = CirculationRules.Get( branchcode, c, undef, 'max_holds' ) %]
539
540
                    [% IF maxissueqty || maxissueqty || max_holds %]
520
                    <tr>
541
                    <tr>
521
                    [% END %]
542
                        <td>
522
                        <td>[% IF ( branch_cat_rule_loo.default_humancategorycode ) %]
543
                            [% IF c == '*'%]
523
                                <em>Default</em>
544
                                <em>Default</em>
524
                            [% ELSE %]
545
                            [% ELSE %]
525
                                [% branch_cat_rule_loo.humancategorycode | html %]
546
                                [% Categories.GetName(c) | html %]
526
                            [% END %]
547
                            [% END %]
527
                        </td>
548
                        </td>
528
                        <td>[% IF ( branch_cat_rule_loo.unlimited_maxissueqty ) %]
549
                        <td>
529
                                <span>Unlimited</span>
550
                            [% IF maxissueqty  %]
551
                                [% maxissueqty | html %]
530
                            [% ELSE %]
552
                            [% ELSE %]
531
                                [% branch_cat_rule_loo.maxissueqty | html %]
553
                                <span>Unlimited</span>
532
                            [% END %]
554
                            [% END %]
533
                        </td>
555
                        </td>
534
                        <td>[% IF ( branch_cat_rule_loo.unlimited_maxonsiteissueqty ) %]
556
                        <td>
535
                                <span>Unlimited</span>
557
                            [% IF maxonsiteissueqty  %]
558
                                [% maxonsiteissueqty | html %]
536
                            [% ELSE %]
559
                            [% ELSE %]
537
                                [% branch_cat_rule_loo.maxonsiteissueqty | html %]
560
                                <span>Unlimited</span>
538
                            [% END %]
561
                            [% END %]
539
                        </td>
562
                        </td>
540
                        <td>
563
                        <td>
Lines 542-555 Link Here
542
                            [% IF rule_value.defined && rule_value != '' %]
565
                            [% IF rule_value.defined && rule_value != '' %]
543
                                [% rule_value | html %]
566
                                [% rule_value | html %]
544
                            [% ELSE %]
567
                            [% ELSE %]
545
                                Unlimited
568
                                <span>Unlimited</span>
546
                            [% END %]
569
                            [% END %]
547
                        </td>
570
                        </td>
548
571
549
                        <td class="actions">
572
                        <td class="actions">
550
                            <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>
573
                            <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>
551
                        </td>
574
                        </td>
552
                    </tr>
575
                    </tr>
576
                    [% END %]
553
                [% END %]
577
                [% END %]
554
                <tr>
578
                <tr>
555
                    <td>
579
                    <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 1048-1065 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1048
    $dbh->do('DELETE FROM issues');
1050
    $dbh->do('DELETE FROM issues');
1049
    $dbh->do('DELETE FROM items');
1051
    $dbh->do('DELETE FROM items');
1050
    $dbh->do('DELETE FROM issuingrules');
1052
    $dbh->do('DELETE FROM issuingrules');
1053
    Koha::CirculationRules->search()->delete();
1051
    $dbh->do(
1054
    $dbh->do(
1052
        q{
1055
        q{
1053
        INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, maxissueqty, issuelength, lengthunit, renewalsallowed, renewalperiod,
1056
        INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, issuelength, lengthunit, renewalsallowed, renewalperiod,
1054
                    norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
1057
                    norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
1055
        },
1058
        },
1056
        {},
1059
        {},
1057
        '*', '*', '*', 25,
1060
        '*', '*', '*', 25,
1058
        20,  14,  'days',
1061
        14,  'days',
1059
        1,   7,
1062
        1,   7,
1060
        undef,  0,
1063
        undef,  0,
1061
        .10, 1
1064
        .10, 1
1062
    );
1065
    );
1066
    Koha::CirculationRules->set_rules(
1067
        {
1068
            categorycode => '*',
1069
            itemtype     => '*',
1070
            branchcode   => '*',
1071
            rules        => {
1072
                maxissueqty => 20
1073
            }
1074
        }
1075
    );
1063
    my ( $biblionumber, $biblioitemnumber ) = add_biblio();
1076
    my ( $biblionumber, $biblioitemnumber ) = add_biblio();
1064
1077
1065
    my $barcode1 = '1234';
1078
    my $barcode1 = '1234';
Lines 1666-1672 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1666
            categorycode => '*',
1679
            categorycode => '*',
1667
            itemtype     => '*',
1680
            itemtype     => '*',
1668
            branchcode   => '*',
1681
            branchcode   => '*',
1669
            maxissueqty  => 99,
1670
            issuelength  => 1,
1682
            issuelength  => 1,
1671
            firstremind  => 1,        # 1 day of grace
1683
            firstremind  => 1,        # 1 day of grace
1672
            finedays     => 2,        # 2 days of fine per day of overdue
1684
            finedays     => 2,        # 2 days of fine per day of overdue
(-)a/t/db_dependent/Circulation/Branch.t (-19 / +41 lines)
Lines 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 153-161 my $sampleissuingrule2 = { Link Here
153
    branchcode         => $samplebranch2->{branchcode},
151
    branchcode         => $samplebranch2->{branchcode},
154
    categorycode       => $samplecat->{categorycode},
152
    categorycode       => $samplecat->{categorycode},
155
    itemtype           => 'BOOK',
153
    itemtype           => 'BOOK',
156
    maxissueqty        => 2,
154
    renewalsallowed    => 'Null',
157
    maxonsiteissueqty  => 1,
158
    renewalsallowed    => 0,
159
    renewalperiod      => 2,
155
    renewalperiod      => 2,
160
    norenewalbefore    => 7,
156
    norenewalbefore    => 7,
161
    auto_renew         => 0,
157
    auto_renew         => 0,
Lines 186-194 my $sampleissuingrule3 = { Link Here
186
    branchcode         => $samplebranch1->{branchcode},
182
    branchcode         => $samplebranch1->{branchcode},
187
    categorycode       => $samplecat->{categorycode},
183
    categorycode       => $samplecat->{categorycode},
188
    itemtype           => 'DVD',
184
    itemtype           => 'DVD',
189
    maxissueqty        => 3,
185
    renewalsallowed    => 'Null',
190
    maxonsiteissueqty  => 2,
191
    renewalsallowed    => 0,
192
    renewalperiod      => 3,
186
    renewalperiod      => 3,
193
    norenewalbefore    => 8,
187
    norenewalbefore    => 8,
194
    auto_renew         => 0,
188
    auto_renew         => 0,
Lines 220-227 $query = 'INSERT INTO issuingrules ( Link Here
220
                branchcode,
214
                branchcode,
221
                categorycode,
215
                categorycode,
222
                itemtype,
216
                itemtype,
223
                maxissueqty,
224
                maxonsiteissueqty,
225
                renewalsallowed,
217
                renewalsallowed,
226
                renewalperiod,
218
                renewalperiod,
227
                norenewalbefore,
219
                norenewalbefore,
Lines 247-260 $query = 'INSERT INTO issuingrules ( Link Here
247
                opacitemholds,
239
                opacitemholds,
248
                cap_fine_to_replacement_price,
240
                cap_fine_to_replacement_price,
249
                article_requests
241
                article_requests
250
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
242
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
251
my $sth = $dbh->prepare($query);
243
my $sth = $dbh->prepare($query);
252
$sth->execute(
244
$sth->execute(
253
    $sampleissuingrule1->{branchcode},
245
    $sampleissuingrule1->{branchcode},
254
    $sampleissuingrule1->{categorycode},
246
    $sampleissuingrule1->{categorycode},
255
    $sampleissuingrule1->{itemtype},
247
    $sampleissuingrule1->{itemtype},
256
    $sampleissuingrule1->{maxissueqty},
257
    $sampleissuingrule1->{maxonsiteissueqty},
258
    $sampleissuingrule1->{renewalsallowed},
248
    $sampleissuingrule1->{renewalsallowed},
259
    $sampleissuingrule1->{renewalperiod},
249
    $sampleissuingrule1->{renewalperiod},
260
    $sampleissuingrule1->{norenewalbefore},
250
    $sampleissuingrule1->{norenewalbefore},
Lines 285-292 $sth->execute( Link Here
285
    $sampleissuingrule2->{branchcode},
275
    $sampleissuingrule2->{branchcode},
286
    $sampleissuingrule2->{categorycode},
276
    $sampleissuingrule2->{categorycode},
287
    $sampleissuingrule2->{itemtype},
277
    $sampleissuingrule2->{itemtype},
288
    $sampleissuingrule2->{maxissueqty},
289
    $sampleissuingrule2->{maxonsiteissueqty},
290
    $sampleissuingrule2->{renewalsallowed},
278
    $sampleissuingrule2->{renewalsallowed},
291
    $sampleissuingrule2->{renewalperiod},
279
    $sampleissuingrule2->{renewalperiod},
292
    $sampleissuingrule2->{norenewalbefore},
280
    $sampleissuingrule2->{norenewalbefore},
Lines 317-324 $sth->execute( Link Here
317
    $sampleissuingrule3->{branchcode},
305
    $sampleissuingrule3->{branchcode},
318
    $sampleissuingrule3->{categorycode},
306
    $sampleissuingrule3->{categorycode},
319
    $sampleissuingrule3->{itemtype},
307
    $sampleissuingrule3->{itemtype},
320
    $sampleissuingrule3->{maxissueqty},
321
    $sampleissuingrule3->{maxonsiteissueqty},
322
    $sampleissuingrule3->{renewalsallowed},
308
    $sampleissuingrule3->{renewalsallowed},
323
    $sampleissuingrule3->{renewalperiod},
309
    $sampleissuingrule3->{renewalperiod},
324
    $sampleissuingrule3->{norenewalbefore},
310
    $sampleissuingrule3->{norenewalbefore},
(-)a/t/db_dependent/Circulation/Returns.t (-1 lines)
Lines 54-60 my $rule = Koha::IssuingRule->new( Link Here
54
        categorycode => '*',
54
        categorycode => '*',
55
        itemtype     => '*',
55
        itemtype     => '*',
56
        branchcode   => '*',
56
        branchcode   => '*',
57
        maxissueqty  => 99,
58
        issuelength  => 1,
57
        issuelength  => 1,
59
    }
58
    }
60
);
59
);
(-)a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t (-13 / +25 lines)
Lines 27-32 use C4::Context; Link Here
27
use Koha::DateUtils qw( dt_from_string );
27
use Koha::DateUtils qw( dt_from_string );
28
use Koha::Database;
28
use Koha::Database;
29
use Koha::Checkouts;
29
use Koha::Checkouts;
30
use Koha::CirculationRules;
30
31
31
use t::lib::TestBuilder;
32
use t::lib::TestBuilder;
32
use t::lib::Mocks;
33
use t::lib::Mocks;
Lines 38-44 our $dbh = C4::Context->dbh; Link Here
38
39
39
$dbh->do(q|DELETE FROM branch_item_rules|);
40
$dbh->do(q|DELETE FROM branch_item_rules|);
40
$dbh->do(q|DELETE FROM issues|);
41
$dbh->do(q|DELETE FROM issues|);
41
$dbh->do(q|DELETE FROM branch_borrower_circ_rules|);
42
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
42
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
43
$dbh->do(q|DELETE FROM default_circ_rules|);
43
$dbh->do(q|DELETE FROM default_circ_rules|);
44
$dbh->do(q|DELETE FROM default_branch_item_rules|);
44
$dbh->do(q|DELETE FROM default_branch_item_rules|);
Lines 91-104 my $issuingrule = $builder->build({ Link Here
91
        branchcode         => $branch->{branchcode},
91
        branchcode         => $branch->{branchcode},
92
        categorycode       => '*',
92
        categorycode       => '*',
93
        itemtype           => '*',
93
        itemtype           => '*',
94
        maxissueqty        => 2,
95
        maxonsiteissueqty  => 1,
96
        lengthunit         => 'days',
94
        lengthunit         => 'days',
97
        issuelength        => 5,
95
        issuelength        => 5,
98
        hardduedate        => undef,
96
        hardduedate        => undef,
99
        hardduedatecompare => 0,
97
        hardduedatecompare => 0,
100
    },
98
    },
101
});
99
});
100
Koha::CirculationRules->search()->delete();
101
Koha::CirculationRules->set_rules(
102
    {
103
        branchcode   => $branch->{branchcode},
104
        categorycode => '*',
105
        itemtype     => '*',
106
        rules        => {
107
            maxissueqty       => 2,
108
            maxonsiteissueqty => 1,
109
        }
110
    }
111
);
102
112
103
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
113
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
104
C4::Context->set_userenv($patron->borrowernumber, $patron->userid, 'usercnum', 'First name', 'Surname', $branch->{branchcode}, 'My Library', 0);
114
C4::Context->set_userenv($patron->borrowernumber, $patron->userid, 'usercnum', 'First name', 'Surname', $branch->{branchcode}, 'My Library', 0);
Lines 156-171 my $yet_another_item = $builder->build({ Link Here
156
( $impossible, undef, undef, undef ) = C4::Circulation::CanBookBeIssued( $patron, $yet_another_item->{barcode} );
166
( $impossible, undef, undef, undef ) = C4::Circulation::CanBookBeIssued( $patron, $yet_another_item->{barcode} );
157
is( $impossible->{TOO_MANY}, 'TOO_MANY_CHECKOUTS', 'Not a specific case, $delta should not be incremented' );
167
is( $impossible->{TOO_MANY}, 'TOO_MANY_CHECKOUTS', 'Not a specific case, $delta should not be incremented' );
158
168
159
$dbh->do(q|DELETE FROM issuingrules|);
169
Koha::CirculationRules->search()->delete();
160
my $borrower_circ_rule = $builder->build({
170
Koha::CirculationRules->set_rules(
161
    source => 'DefaultCircRule',
171
    {
162
    value => {
172
        branchcode   => $branch->{branchcode},
163
        branchcode         => $branch->{branchcode},
173
        categorycode => '*',
164
        categorycode       => '*',
174
        itemtype     => '*',
165
        maxissueqty        => 2,
175
        rules        => {
166
        maxonsiteissueqty  => 1,
176
            maxissueqty       => 2,
167
    },
177
            maxonsiteissueqty => 1,
168
});
178
        }
179
    }
180
);
169
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} );
181
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} );
170
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 2 - Switch is allowed' );
182
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 2 - Switch is allowed' );
171
is( exists $impossible->{TOO_MANY}, '', 'Specific case 2 - Switch is allowed' );
183
is( exists $impossible->{TOO_MANY}, '', 'Specific case 2 - Switch is allowed' );
(-)a/t/db_dependent/Circulation/TooMany.t (-49 / +56 lines)
Lines 26-31 use C4::Context; Link Here
26
26
27
use Koha::DateUtils qw( dt_from_string );
27
use Koha::DateUtils qw( dt_from_string );
28
use Koha::Database;
28
use Koha::Database;
29
use Koha::CirculationRules;
29
30
30
use t::lib::TestBuilder;
31
use t::lib::TestBuilder;
31
use t::lib::Mocks;
32
use t::lib::Mocks;
Lines 43-53 $dbh->do(q|DELETE FROM categories|); Link Here
43
$dbh->do(q|DELETE FROM accountlines|);
44
$dbh->do(q|DELETE FROM accountlines|);
44
$dbh->do(q|DELETE FROM itemtypes|);
45
$dbh->do(q|DELETE FROM itemtypes|);
45
$dbh->do(q|DELETE FROM branch_item_rules|);
46
$dbh->do(q|DELETE FROM branch_item_rules|);
46
$dbh->do(q|DELETE FROM branch_borrower_circ_rules|);
47
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
47
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
48
$dbh->do(q|DELETE FROM default_circ_rules|);
48
$dbh->do(q|DELETE FROM default_circ_rules|);
49
$dbh->do(q|DELETE FROM default_branch_item_rules|);
49
$dbh->do(q|DELETE FROM default_branch_item_rules|);
50
$dbh->do(q|DELETE FROM issuingrules|);
50
$dbh->do(q|DELETE FROM issuingrules|);
51
Koha::CirculationRules->search()->delete();
51
52
52
my $builder = t::lib::TestBuilder->new();
53
my $builder = t::lib::TestBuilder->new();
53
t::lib::Mocks::mock_preference('item-level_itypes', 1); # Assuming the item type is defined at item level
54
t::lib::Mocks::mock_preference('item-level_itypes', 1); # Assuming the item type is defined at item level
Lines 106-121 subtest 'no rules exist' => sub { Link Here
106
107
107
subtest '1 Issuingrule exist 0 0: no issue allowed' => sub {
108
subtest '1 Issuingrule exist 0 0: no issue allowed' => sub {
108
    plan tests => 4;
109
    plan tests => 4;
109
    my $issuingrule = $builder->build({
110
    Koha::CirculationRules->set_rules(
110
        source => 'Issuingrule',
111
        {
111
        value => {
112
            branchcode   => $branch->{branchcode},
112
            branchcode         => $branch->{branchcode},
113
            categorycode => $category->{categorycode},
113
            categorycode       => $category->{categorycode},
114
            itemtype     => '*',
114
            itemtype           => '*',
115
            rules        => {
115
            maxissueqty        => 0,
116
                maxissueqty       => 0,
116
            maxonsiteissueqty  => 0,
117
                maxonsiteissueqty => 0,
118
            }
117
        },
119
        },
118
    });
120
    );
119
    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
121
    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
120
    is_deeply(
122
    is_deeply(
121
        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
123
        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
Lines 214-229 subtest '1 Issuingrule exist with onsiteissueqty=unlimited' => sub { Link Here
214
216
215
subtest '1 Issuingrule exist 1 1: issue is allowed' => sub {
217
subtest '1 Issuingrule exist 1 1: issue is allowed' => sub {
216
    plan tests => 4;
218
    plan tests => 4;
217
    my $issuingrule = $builder->build({
219
    Koha::CirculationRules->set_rules(
218
        source => 'Issuingrule',
220
        {
219
        value => {
221
            branchcode   => $branch->{branchcode},
220
            branchcode         => $branch->{branchcode},
222
            categorycode => $category->{categorycode},
221
            categorycode       => $category->{categorycode},
223
            itemtype     => '*',
222
            itemtype           => '*',
224
            rules        => {
223
            maxissueqty        => 1,
225
                maxissueqty       => 1,
224
            maxonsiteissueqty  => 1,
226
                maxonsiteissueqty => 1,
225
        },
227
            }
226
    });
228
        }
229
    );
227
    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
230
    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
228
    is(
231
    is(
229
        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
232
        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
Lines 253-268 subtest '1 Issuingrule exist 1 1: issue is allowed' => sub { Link Here
253
256
254
subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub {
257
subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub {
255
    plan tests => 5;
258
    plan tests => 5;
256
    my $issuingrule = $builder->build({
259
    Koha::CirculationRules->set_rules(
257
        source => 'Issuingrule',
260
        {
258
        value => {
261
            branchcode   => $branch->{branchcode},
259
            branchcode         => $branch->{branchcode},
262
            categorycode => $category->{categorycode},
260
            categorycode       => $category->{categorycode},
263
            itemtype     => '*',
261
            itemtype           => '*',
264
            rules        => {
262
            maxissueqty        => 1,
265
                maxissueqty       => 1,
263
            maxonsiteissueqty  => 1,
266
                maxonsiteissueqty => 1,
264
        },
267
            }
265
    });
268
        }
269
    );
266
270
267
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string() );
271
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string() );
268
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
272
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
Lines 308-323 subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { Link Here
308
312
309
subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub {
313
subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub {
310
    plan tests => 5;
314
    plan tests => 5;
311
    my $issuingrule = $builder->build({
315
    Koha::CirculationRules->set_rules(
312
        source => 'Issuingrule',
316
        {
313
        value => {
317
            branchcode   => $branch->{branchcode},
314
            branchcode         => $branch->{branchcode},
318
            categorycode => $category->{categorycode},
315
            categorycode       => $category->{categorycode},
319
            itemtype     => '*',
316
            itemtype           => '*',
320
            rules        => {
317
            maxissueqty        => 1,
321
                maxissueqty       => 1,
318
            maxonsiteissueqty  => 1,
322
                maxonsiteissueqty => 1,
319
        },
323
            }
320
    });
324
        }
325
    );
321
326
322
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef, { onsite_checkout => 1 } );
327
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef, { onsite_checkout => 1 } );
323
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
328
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
Lines 366-380 subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { Link Here
366
    # DefaultBorrowerCircRule, DefaultBranchCircRule, DefaultBranchItemRule ans DefaultCircRule.pm
371
    # DefaultBorrowerCircRule, DefaultBranchCircRule, DefaultBranchItemRule ans DefaultCircRule.pm
367
372
368
    plan tests => 10;
373
    plan tests => 10;
369
    my $issuingrule = $builder->build({
374
    Koha::CirculationRules->set_rules(
370
        source => 'BranchBorrowerCircRule',
375
        {
371
        value => {
376
            branchcode   => $branch->{branchcode},
372
            branchcode         => $branch->{branchcode},
377
            categorycode => $category->{categorycode},
373
            categorycode       => $category->{categorycode},
378
            itemtype     => undef,
374
            maxissueqty        => 1,
379
            rules        => {
375
            maxonsiteissueqty  => 1,
380
                maxissueqty       => 1,
376
        },
381
                maxonsiteissueqty => 1,
377
    });
382
            }
383
        }
384
    );
378
385
379
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef );
386
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef );
380
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
387
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
(-)a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t (-1 lines)
Lines 98-104 my $rule = Koha::IssuingRule->new( Link Here
98
        categorycode => '*',
98
        categorycode => '*',
99
        itemtype     => '*',
99
        itemtype     => '*',
100
        branchcode   => '*',
100
        branchcode   => '*',
101
        maxissueqty  => 99,
102
        issuelength  => 7,
101
        issuelength  => 7,
103
        lengthunit   => 8,
102
        lengthunit   => 8,
104
        reservesallowed => 99,
103
        reservesallowed => 99,
(-)a/t/db_dependent/Reserves.t (-9 / +6 lines)
Lines 201-208 $requesters{$branch_3} = Koha::Patron->new({ Link Here
201
201
202
$dbh->do('DELETE FROM issuingrules');
202
$dbh->do('DELETE FROM issuingrules');
203
$dbh->do('DELETE FROM branch_item_rules');
203
$dbh->do('DELETE FROM branch_item_rules');
204
$dbh->do('DELETE FROM branch_borrower_circ_rules');
205
$dbh->do('DELETE FROM default_borrower_circ_rules');
206
$dbh->do('DELETE FROM default_branch_item_rules');
204
$dbh->do('DELETE FROM default_branch_item_rules');
207
$dbh->do('DELETE FROM default_branch_circ_rules');
205
$dbh->do('DELETE FROM default_branch_circ_rules');
208
$dbh->do('DELETE FROM default_circ_rules');
206
$dbh->do('DELETE FROM default_circ_rules');
Lines 215-232 $dbh->do( Link Here
215
213
216
# CPL allows only its own patrons to request its items
214
# CPL allows only its own patrons to request its items
217
$dbh->do(
215
$dbh->do(
218
    q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
216
    q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch)
219
      VALUES (?, ?, ?, ?)},
217
      VALUES (?, ?, ?)},
220
    {},
218
    {},
221
    $branch_1, 10, 1, 'homebranch',
219
    $branch_1, 1, 'homebranch',
222
);
220
);
223
221
224
# ... while FPL allows anybody to request its items
222
# ... while FPL allows anybody to request its items
225
$dbh->do(
223
$dbh->do(
226
    q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
224
    q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch)
227
      VALUES (?, ?, ?, ?)},
225
      VALUES (?, ?, ?)},
228
    {},
226
    {},
229
    $branch_2, 10, 2, 'homebranch',
227
    $branch_2, 2, 'homebranch',
230
);
228
);
231
229
232
# helper biblio for the bug 10272 regression test
230
# helper biblio for the bug 10272 regression test
233
- 

Return to bug 18925