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 410-435 sub CanItemBeReserved { Link Here
410
    }
411
    }
411
412
412
    # Now we need to check hold limits by patron category
413
    # Now we need to check hold limits by patron category
413
    my $schema = Koha::Database->new()->schema();
414
    my $rule = Koha::CirculationRules->find(
414
    my $rule = $schema->resultset('BranchBorrowerCircRule')->find(
415
        {
415
        {
416
            branchcode   => $borrower->{branchcode},
417
            categorycode => $borrower->{categorycode},
416
            categorycode => $borrower->{categorycode},
417
            branchcode   => $borrower->{branchcode},
418
            itemtype     => undef,
419
            rule_name    => 'max_holds',
418
        }
420
        }
419
    );
421
    );
420
    $rule ||= $schema->resultset('DefaultBorrowerCircRule')->find(
422
    $rule ||= Koha::CirculationRules->find(
421
        {
423
        {
422
            categorycode => $borrower->{categorycode}
424
            categorycode => $borrower->{categorycode},
425
            branchcode   => undef,,
426
            itemtype     => undef,
427
            rule_name    => 'max_holds',
423
        }
428
        }
424
    );
429
    );
425
    if ( $rule && defined $rule->max_holds ) {
430
    if ( $rule ) {
426
        my $total_holds_count = Koha::Holds->search(
431
        my $total_holds_count = Koha::Holds->search(
427
            {
432
            {
428
                borrowernumber => $borrower->{borrowernumber}
433
                borrowernumber => $borrower->{borrowernumber}
429
            }
434
            }
430
        )->count();
435
        )->count();
431
436
432
        return 'tooManyReserves' if $total_holds_count >= $rule->max_holds;
437
        return 'tooManyReserves' if $total_holds_count >= $rule->rule_value;
433
    }
438
    }
434
439
435
    my $circ_control_branch =
440
    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
37
37
my $input = CGI->new;
38
my $input = CGI->new;
Lines 93-98 elsif ($op eq 'delete-branch-cat') { Link Here
93
                                        AND categorycode = ?");
94
                                        AND categorycode = ?");
94
        $sth_delete->execute($branch, $categorycode);
95
        $sth_delete->execute($branch, $categorycode);
95
    }
96
    }
97
    Koha::CirculationRules->set_rule(
98
        {
99
            branchcode   => $branch,
100
            categorycode => $categorycode,
101
            itemtype     => undef,
102
            rule_name    => 'max_holds',
103
            rule_value   => undef,
104
        }
105
    );
96
}
106
}
97
elsif ($op eq 'delete-branch-item') {
107
elsif ($op eq 'delete-branch-item') {
98
    my $itemtype  = $input->param('itemtype');
108
    my $itemtype  = $input->param('itemtype');
Lines 283-292 elsif ($op eq "add-branch-cat") { Link Here
283
            $sth_search->execute();
293
            $sth_search->execute();
284
            my $res = $sth_search->fetchrow_hashref();
294
            my $res = $sth_search->fetchrow_hashref();
285
            if ($res->{total}) {
295
            if ($res->{total}) {
286
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $max_holds );
296
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty );
287
            } else {
297
            } else {
288
                $sth_insert->execute( $maxissueqty, $maxonsiteissueqty, $max_holds );
298
                $sth_insert->execute( $maxissueqty, $maxonsiteissueqty );
289
            }
299
            }
300
301
            Koha::CirculationRules->set_rule(
302
                {
303
                    branchcode   => undef,
304
                    categorycode => undef,
305
                    itemtype     => undef,
306
                    rule_name    => 'max_holds',
307
                    rule_value   => $max_holds,
308
                }
309
            );
290
        } else {
310
        } else {
291
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
311
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
292
                                            FROM default_borrower_circ_rules
312
                                            FROM default_borrower_circ_rules
Lines 306-315 elsif ($op eq "add-branch-cat") { Link Here
306
            $sth_search->execute($categorycode);
326
            $sth_search->execute($categorycode);
307
            my $res = $sth_search->fetchrow_hashref();
327
            my $res = $sth_search->fetchrow_hashref();
308
            if ($res->{total}) {
328
            if ($res->{total}) {
309
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $max_holds, $categorycode );
329
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode );
310
            } else {
330
            } else {
311
                $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty, $max_holds );
331
                $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty );
312
            }
332
            }
333
334
            Koha::CirculationRules->set_rule(
335
                {
336
                    branchcode   => undef,
337
                    categorycode => $categorycode,
338
                    itemtype     => undef,
339
                    rule_name    => 'max_holds',
340
                    rule_value   => $max_holds,
341
                }
342
            );
313
        }
343
        }
314
    } elsif ($categorycode eq "*") {
344
    } elsif ($categorycode eq "*") {
315
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
345
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
Lines 359-364 elsif ($op eq "add-branch-cat") { Link Here
359
        } else {
389
        } else {
360
            $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty, $max_holds);
390
            $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty, $max_holds);
361
        }
391
        }
392
393
        Koha::CirculationRules->set_rule(
394
            {
395
                branchcode   => $branch,
396
                categorycode => $categorycode,
397
                itemtype     => undef,
398
                rule_name    => 'max_holds',
399
                rule_value   => $max_holds,
400
            }
401
        );
362
    }
402
    }
363
}
403
}
364
elsif ($op eq "add-branch-item") {
404
elsif ($op eq "add-branch-item") {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-3 / +6 lines)
Lines 1-5 Link Here
1
[% USE Asset %]
1
[% USE Asset %]
2
[% USE Branches %]
2
[% USE Branches %]
3
[% USE CirculationRules %]
3
[% SET footerjs = 1 %]
4
[% SET footerjs = 1 %]
4
[% INCLUDE 'doc-head-open.inc' %]
5
[% INCLUDE 'doc-head-open.inc' %]
5
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
6
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
Lines 511-520 Link Here
511
                                [% branch_cat_rule_loo.maxonsiteissueqty %]
512
                                [% branch_cat_rule_loo.maxonsiteissueqty %]
512
                            [% END %]
513
                            [% END %]
513
                        </td>
514
                        </td>
514
                        <td>[% IF ( branch_cat_rule_loo.unlimited_max_holds ) %]
515
                        <td>
515
                                Unlimited
516
                            [% SET rule_value = CirculationRules.Get( branch_cat_rule_loo.branchcode, branch_cat_rule_loo.categorycode, branch_cat_rule_loo.itemtype, 'max_holds' ) %]
517
                            [% IF rule_value  %]
518
                                [% rule_value %]
516
                            [% ELSE %]
519
                            [% ELSE %]
517
                                [% branch_cat_rule_loo.max_holds %]
520
                                Unlimited
518
                            [% END %]
521
                            [% END %]
519
                        </td>
522
                        </td>
520
523
(-)a/t/db_dependent/Holds.t (-12 / +18 lines)
Lines 17-22 use Koha::DateUtils qw( dt_from_string output_pref ); Link Here
17
use Koha::Biblios;
17
use Koha::Biblios;
18
use Koha::Holds;
18
use Koha::Holds;
19
use Koha::Patrons;
19
use Koha::Patrons;
20
use Koha::CirculationRules;
20
21
21
BEGIN {
22
BEGIN {
22
    use FindBin;
23
    use FindBin;
Lines 415-420 subtest 'Test max_holds per library/patron category' => sub { Link Here
415
416
416
    $dbh->do('DELETE FROM reserves');
417
    $dbh->do('DELETE FROM reserves');
417
    $dbh->do('DELETE FROM issuingrules');
418
    $dbh->do('DELETE FROM issuingrules');
419
    $dbh->do('DELETE FROM circulation_rules');
418
420
419
    ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST');
421
    ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST');
420
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
422
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
Lines 439-458 subtest 'Test max_holds per library/patron category' => sub { Link Here
439
    my $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
441
    my $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
440
    is( $ret, 'OK', 'Patron can place hold with no borrower circ rules' );
442
    is( $ret, 'OK', 'Patron can place hold with no borrower circ rules' );
441
443
442
    my $rule_all = $schema->resultset('DefaultBorrowerCircRule')->new(
444
    my $rule_all = Koha::CirculationRules->set_rule(
443
        {
445
        {
444
            categorycode => $category->{categorycode},
446
            categorycode => $category->{categorycode},
445
            max_holds    => 3,
447
            branchcode   => undef,
448
            itemtype     => undef,
449
            rule_name    => 'max_holds',
450
            rule_value   => 3,
446
        }
451
        }
447
    )->insert();
452
    );
448
453
449
    my $rule_branch = $schema->resultset('BranchBorrowerCircRule')->new(
454
    my $rule_branch = Koha::CirculationRules->set_rule(
450
        {
455
        {
451
            branchcode   => $branch_1,
456
            branchcode   => $branch_1,
452
            categorycode => $category->{categorycode},
457
            categorycode => $category->{categorycode},
453
            max_holds    => 5,
458
            itemtype     => undef,
459
            rule_name    => 'max_holds',
460
            rule_value   => 5,
454
        }
461
        }
455
    )->insert();
462
    );
456
463
457
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
464
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
458
    is( $ret, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 3' );
465
    is( $ret, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 3' );
Lines 463-478 subtest 'Test max_holds per library/patron category' => sub { Link Here
463
    is( $ret, 'tooManyReserves', 'Patron cannot place hold with only a category rule of 3' );
470
    is( $ret, 'tooManyReserves', 'Patron cannot place hold with only a category rule of 3' );
464
471
465
    $rule_all->delete();
472
    $rule_all->delete();
466
    $rule_branch->max_holds(3);
473
    $rule_branch->rule_value(3);
467
    $rule_branch->insert();
474
    $rule_branch->store();
468
475
469
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
476
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
470
    is( $ret, 'tooManyReserves', 'Patron cannot place hold with only a branch/category rule of 3' );
477
    is( $ret, 'tooManyReserves', 'Patron cannot place hold with only a branch/category rule of 3' );
471
478
472
    $rule_branch->max_holds(5);
479
    $rule_branch->rule_value(5);
473
    $rule_branch->update();
480
    $rule_branch->update();
474
    $rule_all->max_holds(5);
481
    $rule_branch->rule_value(5);
475
    $rule_all->insert();
482
    $rule_branch->store();
476
483
477
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
484
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
478
    is( $ret, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 5' );
485
    is( $ret, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 5' );
479
- 

Return to bug 18887