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   => $branchcode,
417
            categorycode => $borrower->{categorycode},
416
            categorycode => $borrower->{categorycode},
417
            branchcode   => $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 { status => 'tooManyReserves', limit => $rule->max_holds } if $total_holds_count >= $rule->max_holds;
437
        return { status => 'tooManyReserves', limit => $rule->rule_value} 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-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 19-24 use Koha::Database; Link Here
19
use Koha::DateUtils qw( dt_from_string output_pref );
19
use Koha::DateUtils qw( dt_from_string output_pref );
20
use Koha::Biblios;
20
use Koha::Biblios;
21
use Koha::Holds;
21
use Koha::Holds;
22
use Koha::Patrons;
23
use Koha::CirculationRules;
22
24
23
BEGIN {
25
BEGIN {
24
    use FindBin;
26
    use FindBin;
Lines 416-421 subtest 'Test max_holds per library/patron category' => sub { Link Here
416
418
417
    $dbh->do('DELETE FROM reserves');
419
    $dbh->do('DELETE FROM reserves');
418
    $dbh->do('DELETE FROM issuingrules');
420
    $dbh->do('DELETE FROM issuingrules');
421
    $dbh->do('DELETE FROM circulation_rules');
419
422
420
    ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST');
423
    ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST');
421
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
424
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
Lines 440-459 subtest 'Test max_holds per library/patron category' => sub { Link Here
440
    my $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
443
    my $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
441
    is( $ret->{status}, 'OK', 'Patron can place hold with no borrower circ rules' );
444
    is( $ret->{status}, 'OK', 'Patron can place hold with no borrower circ rules' );
442
445
443
    my $rule_all = $schema->resultset('DefaultBorrowerCircRule')->new(
446
    my $rule_all = Koha::CirculationRules->set_rule(
444
        {
447
        {
445
            categorycode => $category->{categorycode},
448
            categorycode => $category->{categorycode},
446
            max_holds    => 3,
449
            branchcode   => undef,
450
            itemtype     => undef,
451
            rule_name    => 'max_holds',
452
            rule_value   => 3,
447
        }
453
        }
448
    )->insert();
454
    );
449
455
450
    my $rule_branch = $schema->resultset('BranchBorrowerCircRule')->new(
456
    my $rule_branch = Koha::CirculationRules->set_rule(
451
        {
457
        {
452
            branchcode   => $branch_1,
458
            branchcode   => $branch_1,
453
            categorycode => $category->{categorycode},
459
            categorycode => $category->{categorycode},
454
            max_holds    => 5,
460
            itemtype     => undef,
461
            rule_name    => 'max_holds',
462
            rule_value   => 5,
455
        }
463
        }
456
    )->insert();
464
    );
457
465
458
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
466
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
459
    is( $ret->{status}, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 3' );
467
    is( $ret->{status}, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 3' );
Lines 464-479 subtest 'Test max_holds per library/patron category' => sub { Link Here
464
    is( $ret->{status}, 'tooManyReserves', 'Patron cannot place hold with only a category rule of 3' );
472
    is( $ret->{status}, 'tooManyReserves', 'Patron cannot place hold with only a category rule of 3' );
465
473
466
    $rule_all->delete();
474
    $rule_all->delete();
467
    $rule_branch->max_holds(3);
475
    $rule_branch->rule_value(3);
468
    $rule_branch->insert();
476
    $rule_branch->store();
469
477
470
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
478
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
471
    is( $ret->{status}, 'tooManyReserves', 'Patron cannot place hold with only a branch/category rule of 3' );
479
    is( $ret->{status}, 'tooManyReserves', 'Patron cannot place hold with only a branch/category rule of 3' );
472
480
473
    $rule_branch->max_holds(5);
481
    $rule_branch->rule_value(5);
474
    $rule_branch->update();
482
    $rule_branch->update();
475
    $rule_all->max_holds(5);
483
    $rule_branch->rule_value(5);
476
    $rule_all->insert();
484
    $rule_branch->store();
477
485
478
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
486
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
479
    is( $ret->{status}, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 5' );
487
    is( $ret->{status}, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 5' );
480
- 

Return to bug 18887