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

(-)a/C4/Reserves.pm (-7 / +12 lines)
Lines 48-53 use Koha::IssuingRules; Link Here
48
use Koha::Items;
48
use Koha::Items;
49
use Koha::ItemTypes;
49
use Koha::ItemTypes;
50
use Koha::Patrons;
50
use Koha::Patrons;
51
use Koha::CirculationRules;
51
52
52
use List::MoreUtils qw( firstidx any );
53
use List::MoreUtils qw( firstidx any );
53
use Carp;
54
use Carp;
Lines 412-437 sub CanItemBeReserved { Link Here
412
    }
413
    }
413
414
414
    # Now we need to check hold limits by patron category
415
    # Now we need to check hold limits by patron category
415
    my $schema = Koha::Database->new()->schema();
416
    my $rule = Koha::CirculationRules->find(
416
    my $rule = $schema->resultset('BranchBorrowerCircRule')->find(
417
        {
417
        {
418
            branchcode   => $branchcode,
419
            categorycode => $borrower->{categorycode},
418
            categorycode => $borrower->{categorycode},
419
            branchcode   => $branchcode,
420
            itemtype     => undef,
421
            rule_name    => 'max_holds',
420
        }
422
        }
421
    );
423
    );
422
    $rule ||= $schema->resultset('DefaultBorrowerCircRule')->find(
424
    $rule ||= Koha::CirculationRules->find(
423
        {
425
        {
424
            categorycode => $borrower->{categorycode}
426
            categorycode => $borrower->{categorycode},
427
            branchcode   => undef,,
428
            itemtype     => undef,
429
            rule_name    => 'max_holds',
425
        }
430
        }
426
    );
431
    );
427
    if ( $rule && defined $rule->max_holds ) {
432
    if ( $rule ) {
428
        my $total_holds_count = Koha::Holds->search(
433
        my $total_holds_count = Koha::Holds->search(
429
            {
434
            {
430
                borrowernumber => $borrower->{borrowernumber}
435
                borrowernumber => $borrower->{borrowernumber}
431
            }
436
            }
432
        )->count();
437
        )->count();
433
438
434
        return { status => 'tooManyReserves', limit => $rule->max_holds } if $total_holds_count >= $rule->max_holds;
439
        return { status => 'tooManyReserves', limit => $rule->rule_value} if $total_holds_count >= $rule->rule_value;
435
    }
440
    }
436
441
437
    my $circ_control_branch =
442
    my $circ_control_branch =
(-)a/admin/smart-rules.pl (-4 / +44 lines)
Lines 32-37 use Koha::Logger; Link Here
32
use Koha::RefundLostItemFeeRule;
32
use Koha::RefundLostItemFeeRule;
33
use Koha::RefundLostItemFeeRules;
33
use Koha::RefundLostItemFeeRules;
34
use Koha::Libraries;
34
use Koha::Libraries;
35
use Koha::CirculationRules;
35
use Koha::Patron::Categories;
36
use Koha::Patron::Categories;
36
use Koha::Caches;
37
use Koha::Caches;
37
38
Lines 97-102 elsif ($op eq 'delete-branch-cat') { Link Here
97
                                        AND categorycode = ?");
98
                                        AND categorycode = ?");
98
        $sth_delete->execute($branch, $categorycode);
99
        $sth_delete->execute($branch, $categorycode);
99
    }
100
    }
101
    Koha::CirculationRules->set_rule(
102
        {
103
            branchcode   => $branch,
104
            categorycode => $categorycode,
105
            itemtype     => undef,
106
            rule_name    => 'max_holds',
107
            rule_value   => undef,
108
        }
109
    );
100
}
110
}
101
elsif ($op eq 'delete-branch-item') {
111
elsif ($op eq 'delete-branch-item') {
102
    my $itemtype  = $input->param('itemtype');
112
    my $itemtype  = $input->param('itemtype');
Lines 287-296 elsif ($op eq "add-branch-cat") { Link Here
287
            $sth_search->execute();
297
            $sth_search->execute();
288
            my $res = $sth_search->fetchrow_hashref();
298
            my $res = $sth_search->fetchrow_hashref();
289
            if ($res->{total}) {
299
            if ($res->{total}) {
290
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $max_holds );
300
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty );
291
            } else {
301
            } else {
292
                $sth_insert->execute( $maxissueqty, $maxonsiteissueqty, $max_holds );
302
                $sth_insert->execute( $maxissueqty, $maxonsiteissueqty );
293
            }
303
            }
304
305
            Koha::CirculationRules->set_rule(
306
                {
307
                    branchcode   => undef,
308
                    categorycode => undef,
309
                    itemtype     => undef,
310
                    rule_name    => 'max_holds',
311
                    rule_value   => $max_holds,
312
                }
313
            );
294
        } else {
314
        } else {
295
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
315
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
296
                                            FROM default_borrower_circ_rules
316
                                            FROM default_borrower_circ_rules
Lines 310-319 elsif ($op eq "add-branch-cat") { Link Here
310
            $sth_search->execute($categorycode);
330
            $sth_search->execute($categorycode);
311
            my $res = $sth_search->fetchrow_hashref();
331
            my $res = $sth_search->fetchrow_hashref();
312
            if ($res->{total}) {
332
            if ($res->{total}) {
313
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $max_holds, $categorycode );
333
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode );
314
            } else {
334
            } else {
315
                $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty, $max_holds );
335
                $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty );
316
            }
336
            }
337
338
            Koha::CirculationRules->set_rule(
339
                {
340
                    branchcode   => undef,
341
                    categorycode => $categorycode,
342
                    itemtype     => undef,
343
                    rule_name    => 'max_holds',
344
                    rule_value   => $max_holds,
345
                }
346
            );
317
        }
347
        }
318
    } elsif ($categorycode eq "*") {
348
    } elsif ($categorycode eq "*") {
319
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
349
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
Lines 363-368 elsif ($op eq "add-branch-cat") { Link Here
363
        } else {
393
        } else {
364
            $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty, $max_holds);
394
            $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty, $max_holds);
365
        }
395
        }
396
397
        Koha::CirculationRules->set_rule(
398
            {
399
                branchcode   => $branch,
400
                categorycode => $categorycode,
401
                itemtype     => undef,
402
                rule_name    => 'max_holds',
403
                rule_value   => $max_holds,
404
            }
405
        );
366
    }
406
    }
367
}
407
}
368
elsif ($op eq "add-branch-item") {
408
elsif ($op eq "add-branch-item") {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-3 / +6 lines)
Lines 1-6 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Asset %]
2
[% USE Asset %]
3
[% USE Branches %]
3
[% USE Branches %]
4
[% USE CirculationRules %]
4
[% SET footerjs = 1 %]
5
[% SET footerjs = 1 %]
5
[% INCLUDE 'doc-head-open.inc' %]
6
[% INCLUDE 'doc-head-open.inc' %]
6
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
7
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
Lines 512-521 Link Here
512
                                [% branch_cat_rule_loo.maxonsiteissueqty | html %]
513
                                [% branch_cat_rule_loo.maxonsiteissueqty | html %]
513
                            [% END %]
514
                            [% END %]
514
                        </td>
515
                        </td>
515
                        <td>[% IF ( branch_cat_rule_loo.unlimited_max_holds ) %]
516
                        <td>
516
                                Unlimited
517
                            [% SET rule_value = CirculationRules.Get( branch_cat_rule_loo.branchcode, branch_cat_rule_loo.categorycode, branch_cat_rule_loo.itemtype, 'max_holds' ) %]
518
                            [% IF rule_value  %]
519
                                [% rule_value %]
517
                            [% ELSE %]
520
                            [% ELSE %]
518
                                [% branch_cat_rule_loo.max_holds | html %]
521
                                Unlimited
519
                            [% END %]
522
                            [% END %]
520
                        </td>
523
                        </td>
521
524
(-)a/t/db_dependent/Holds.t (-12 / +19 lines)
Lines 21-26 use Koha::Biblios; Link Here
21
use Koha::Holds;
21
use Koha::Holds;
22
use Koha::Items;
22
use Koha::Items;
23
use Koha::Libraries;
23
use Koha::Libraries;
24
use Koha::Patrons;
25
use Koha::CirculationRules;
24
26
25
BEGIN {
27
BEGIN {
26
    use FindBin;
28
    use FindBin;
Lines 418-423 subtest 'Test max_holds per library/patron category' => sub { Link Here
418
420
419
    $dbh->do('DELETE FROM reserves');
421
    $dbh->do('DELETE FROM reserves');
420
    $dbh->do('DELETE FROM issuingrules');
422
    $dbh->do('DELETE FROM issuingrules');
423
    $dbh->do('DELETE FROM circulation_rules');
421
424
422
    ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST');
425
    ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST');
423
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
426
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
Lines 442-461 subtest 'Test max_holds per library/patron category' => sub { Link Here
442
    my $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
445
    my $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
443
    is( $ret->{status}, 'OK', 'Patron can place hold with no borrower circ rules' );
446
    is( $ret->{status}, 'OK', 'Patron can place hold with no borrower circ rules' );
444
447
445
    my $rule_all = $schema->resultset('DefaultBorrowerCircRule')->new(
448
    my $rule_all = Koha::CirculationRules->set_rule(
446
        {
449
        {
447
            categorycode => $category->{categorycode},
450
            categorycode => $category->{categorycode},
448
            max_holds    => 3,
451
            branchcode   => undef,
452
            itemtype     => undef,
453
            rule_name    => 'max_holds',
454
            rule_value   => 3,
449
        }
455
        }
450
    )->insert();
456
    );
451
457
452
    my $rule_branch = $schema->resultset('BranchBorrowerCircRule')->new(
458
    my $rule_branch = Koha::CirculationRules->set_rule(
453
        {
459
        {
454
            branchcode   => $branch_1,
460
            branchcode   => $branch_1,
455
            categorycode => $category->{categorycode},
461
            categorycode => $category->{categorycode},
456
            max_holds    => 5,
462
            itemtype     => undef,
463
            rule_name    => 'max_holds',
464
            rule_value   => 5,
457
        }
465
        }
458
    )->insert();
466
    );
459
467
460
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
468
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
461
    is( $ret->{status}, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 3' );
469
    is( $ret->{status}, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 3' );
Lines 466-481 subtest 'Test max_holds per library/patron category' => sub { Link Here
466
    is( $ret->{status}, 'tooManyReserves', 'Patron cannot place hold with only a category rule of 3' );
474
    is( $ret->{status}, 'tooManyReserves', 'Patron cannot place hold with only a category rule of 3' );
467
475
468
    $rule_all->delete();
476
    $rule_all->delete();
469
    $rule_branch->max_holds(3);
477
    $rule_branch->rule_value(3);
470
    $rule_branch->insert();
478
    $rule_branch->store();
471
479
472
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
480
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
473
    is( $ret->{status}, 'tooManyReserves', 'Patron cannot place hold with only a branch/category rule of 3' );
481
    is( $ret->{status}, 'tooManyReserves', 'Patron cannot place hold with only a branch/category rule of 3' );
474
482
475
    $rule_branch->max_holds(5);
483
    $rule_branch->rule_value(5);
476
    $rule_branch->update();
484
    $rule_branch->update();
477
    $rule_all->max_holds(5);
485
    $rule_branch->rule_value(5);
478
    $rule_all->insert();
486
    $rule_branch->store();
479
487
480
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
488
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
481
    is( $ret->{status}, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 5' );
489
    is( $ret->{status}, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 5' );
482
- 

Return to bug 18887