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 426-451 sub CanItemBeReserved { Link Here
426
    }
427
    }
427
428
428
    # Now we need to check hold limits by patron category
429
    # Now we need to check hold limits by patron category
429
    my $schema = Koha::Database->new()->schema();
430
    my $rule = Koha::CirculationRules->find(
430
    my $rule = $schema->resultset('BranchBorrowerCircRule')->find(
431
        {
431
        {
432
            branchcode   => $borrower->{branchcode},
433
            categorycode => $borrower->{categorycode},
432
            categorycode => $borrower->{categorycode},
433
            branchcode   => $borrower->{branchcode},
434
            itemtype     => undef,
435
            rule_name    => 'max_holds',
434
        }
436
        }
435
    );
437
    );
436
    $rule ||= $schema->resultset('DefaultBorrowerCircRule')->find(
438
    $rule ||= Koha::CirculationRules->find(
437
        {
439
        {
438
            categorycode => $borrower->{categorycode}
440
            categorycode => $borrower->{categorycode},
441
            branchcode   => undef,,
442
            itemtype     => undef,
443
            rule_name    => 'max_holds',
439
        }
444
        }
440
    );
445
    );
441
    if ( $rule && defined $rule->max_holds ) {
446
    if ( $rule ) {
442
        my $total_holds_count = Koha::Holds->search(
447
        my $total_holds_count = Koha::Holds->search(
443
            {
448
            {
444
                borrowernumber => $borrower->{borrowernumber}
449
                borrowernumber => $borrower->{borrowernumber}
445
            }
450
            }
446
        )->count();
451
        )->count();
447
452
448
        return 'tooManyReserves' if $total_holds_count >= $rule->max_holds;
453
        return 'tooManyReserves' if $total_holds_count >= $rule->rule_value;
449
    }
454
    }
450
455
451
    my $circ_control_branch =
456
    my $circ_control_branch =
(-)a/admin/smart-rules.pl (-17 / +53 lines)
Lines 34-39 use Koha::RefundLostItemFeeRule; Link Here
34
use Koha::RefundLostItemFeeRules;
34
use Koha::RefundLostItemFeeRules;
35
use Koha::Libraries;
35
use Koha::Libraries;
36
use Koha::Patron::Categories;
36
use Koha::Patron::Categories;
37
use Koha::CirculationRules;
37
38
38
my $input = CGI->new;
39
my $input = CGI->new;
39
my $dbh = C4::Context->dbh;
40
my $dbh = C4::Context->dbh;
Lines 94-99 elsif ($op eq 'delete-branch-cat') { Link Here
94
                                        AND categorycode = ?");
95
                                        AND categorycode = ?");
95
        $sth_delete->execute($branch, $categorycode);
96
        $sth_delete->execute($branch, $categorycode);
96
    }
97
    }
98
    Koha::CirculationRules->set_rule(
99
        {
100
            branchcode   => $branch,
101
            categorycode => $categorycode,
102
            itemtype     => undef,
103
            rule_name    => 'max_holds',
104
            rule_value   => undef,
105
        }
106
    );
97
}
107
}
98
elsif ($op eq 'delete-branch-item') {
108
elsif ($op eq 'delete-branch-item') {
99
    my $itemtype  = $input->param('itemtype');
109
    my $itemtype  = $input->param('itemtype');
Lines 269-314 elsif ($op eq "add-branch-cat") { Link Here
269
                                            FROM default_circ_rules");
279
                                            FROM default_circ_rules");
270
            my $sth_insert = $dbh->prepare(q|
280
            my $sth_insert = $dbh->prepare(q|
271
                INSERT INTO default_circ_rules
281
                INSERT INTO default_circ_rules
272
                    (maxissueqty, maxonsiteissueqty, max_holds)
282
                    (maxissueqty, maxonsiteissueqty)
273
                    VALUES (?, ?, ?)
283
                    VALUES (?, ?, )
274
            |);
284
            |);
275
            my $sth_update = $dbh->prepare(q|
285
            my $sth_update = $dbh->prepare(q|
276
                UPDATE default_circ_rules
286
                UPDATE default_circ_rules
277
                SET maxissueqty = ?,
287
                SET maxissueqty = ?,
278
                    maxonsiteissueqty = ?,
288
                    maxonsiteissueqty = ?
279
                    max_holds = ?
280
            |);
289
            |);
281
290
282
            $sth_search->execute();
291
            $sth_search->execute();
283
            my $res = $sth_search->fetchrow_hashref();
292
            my $res = $sth_search->fetchrow_hashref();
284
            if ($res->{total}) {
293
            if ($res->{total}) {
285
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $max_holds );
294
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty );
286
            } else {
295
            } else {
287
                $sth_insert->execute( $maxissueqty, $maxonsiteissueqty, $max_holds );
296
                $sth_insert->execute( $maxissueqty, $maxonsiteissueqty );
288
            }
297
            }
298
299
            Koha::CirculationRules->set_rule(
300
                {
301
                    branchcode   => undef,
302
                    categorycode => undef,
303
                    itemtype     => undef,
304
                    rule_name    => 'max_holds',
305
                    rule_value   => $max_holds,
306
                }
307
            );
289
        } else {
308
        } else {
290
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
309
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
291
                                            FROM default_borrower_circ_rules
310
                                            FROM default_borrower_circ_rules
292
                                            WHERE categorycode = ?");
311
                                            WHERE categorycode = ?");
293
            my $sth_insert = $dbh->prepare(q|
312
            my $sth_insert = $dbh->prepare(q|
294
                INSERT INTO default_borrower_circ_rules
313
                INSERT INTO default_borrower_circ_rules
295
                    (categorycode, maxissueqty, maxonsiteissueqty, max_holds)
314
                    (categorycode, maxissueqty, maxonsiteissueqty)
296
                    VALUES (?, ?, ?, ?)
315
                    VALUES (?, ?, ?, ?)
297
            |);
316
            |);
298
            my $sth_update = $dbh->prepare(q|
317
            my $sth_update = $dbh->prepare(q|
299
                UPDATE default_borrower_circ_rules
318
                UPDATE default_borrower_circ_rules
300
                SET maxissueqty = ?,
319
                SET maxissueqty = ?,
301
                    maxonsiteissueqty = ?,
320
                    maxonsiteissueqty = ?
302
                    max_holds = ?
303
                WHERE categorycode = ?
321
                WHERE categorycode = ?
304
            |);
322
            |);
305
            $sth_search->execute($branch);
323
            $sth_search->execute($branch);
306
            my $res = $sth_search->fetchrow_hashref();
324
            my $res = $sth_search->fetchrow_hashref();
307
            if ($res->{total}) {
325
            if ($res->{total}) {
308
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode, $max_holds );
326
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode );
309
            } else {
327
            } else {
310
                $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty, $max_holds );
328
                $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty );
311
            }
329
            }
330
331
            Koha::CirculationRules->set_rule(
332
                {
333
                    branchcode   => undef,
334
                    categorycode => $categorycode,
335
                    itemtype     => undef,
336
                    rule_name    => 'max_holds',
337
                    rule_value   => $max_holds,
338
                }
339
            );
312
        }
340
        }
313
    } elsif ($categorycode eq "*") {
341
    } elsif ($categorycode eq "*") {
314
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
342
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
Lines 339-352 elsif ($op eq "add-branch-cat") { Link Here
339
                                        AND   categorycode = ?");
367
                                        AND   categorycode = ?");
340
        my $sth_insert = $dbh->prepare(q|
368
        my $sth_insert = $dbh->prepare(q|
341
            INSERT INTO branch_borrower_circ_rules
369
            INSERT INTO branch_borrower_circ_rules
342
            (branchcode, categorycode, maxissueqty, maxonsiteissueqty, max_holds)
370
            (branchcode, categorycode, maxissueqty, maxonsiteissueqty)
343
            VALUES (?, ?, ?, ?, ?)
371
            VALUES (?, ?, ?, ?)
344
        |);
372
        |);
345
        my $sth_update = $dbh->prepare(q|
373
        my $sth_update = $dbh->prepare(q|
346
            UPDATE branch_borrower_circ_rules
374
            UPDATE branch_borrower_circ_rules
347
            SET maxissueqty = ?,
375
            SET maxissueqty = ?,
348
                maxonsiteissueqty = ?
376
                maxonsiteissueqty = ?
349
                max_holds = ?
350
            WHERE branchcode = ?
377
            WHERE branchcode = ?
351
            AND categorycode = ?
378
            AND categorycode = ?
352
        |);
379
        |);
Lines 354-363 elsif ($op eq "add-branch-cat") { Link Here
354
        $sth_search->execute($branch, $categorycode);
381
        $sth_search->execute($branch, $categorycode);
355
        my $res = $sth_search->fetchrow_hashref();
382
        my $res = $sth_search->fetchrow_hashref();
356
        if ($res->{total}) {
383
        if ($res->{total}) {
357
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $max_holds, $branch, $categorycode);
384
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch, $categorycode);
358
        } else {
385
        } else {
359
            $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty, $max_holds);
386
            $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty);
360
        }
387
        }
388
389
        Koha::CirculationRules->set_rule(
390
            {
391
                branchcode   => $branch,
392
                categorycode => $categorycode,
393
                itemtype     => undef,
394
                rule_name    => 'max_holds',
395
                rule_value   => $max_holds,
396
            }
397
        );
361
    }
398
    }
362
}
399
}
363
elsif ($op eq "add-branch-item") {
400
elsif ($op eq "add-branch-item") {
Lines 552-558 my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humanca Link Here
552
foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) {
589
foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) {
553
    $entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty});
590
    $entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty});
554
    $entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty});
591
    $entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty});
555
    $entry->{unlimited_max_holds} = 1 unless defined($entry->{max_holds});
556
}
592
}
557
593
558
@sorted_row_loop = sort by_category_and_itemtype @row_loop;
594
@sorted_row_loop = sort by_category_and_itemtype @row_loop;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-3 / +6 lines)
Lines 1-4 Link Here
1
[% USE Branches %]
1
[% USE Branches %]
2
[% USE CirculationRules %]
2
[% INCLUDE 'doc-head-open.inc' %]
3
[% INCLUDE 'doc-head-open.inc' %]
3
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
4
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
4
[% INCLUDE 'doc-head-close.inc' %]
5
[% INCLUDE 'doc-head-close.inc' %]
Lines 582-591 $(document).ready(function() { Link Here
582
                                [% branch_cat_rule_loo.maxonsiteissueqty %]
583
                                [% branch_cat_rule_loo.maxonsiteissueqty %]
583
                            [% END %]
584
                            [% END %]
584
                        </td>
585
                        </td>
585
                        <td>[% IF ( branch_cat_rule_loo.unlimited_max_holds ) %]
586
                        <td>
586
                                Unlimited
587
                            [% SET rule_value = CirculationRules.Get( branch_cat_rule_loo.branchcode, branch_cat_rule_loo.categorycode, branch_cat_rule_loo.itemtype, 'max_holds' ) %]
588
                            [% IF rule_value  %]
589
                                [% rule_value %]
587
                            [% ELSE %]
590
                            [% ELSE %]
588
                                [% branch_cat_rule_loo.max_holds %]
591
                                Unlimited
589
                            [% END %]
592
                            [% END %]
590
                        </td>
593
                        </td>
591
594
(-)a/t/db_dependent/Holds.t (-12 / +18 lines)
Lines 18-23 use Koha::DateUtils qw( dt_from_string output_pref ); Link Here
18
use Koha::Biblios;
18
use Koha::Biblios;
19
use Koha::Holds;
19
use Koha::Holds;
20
use Koha::Patrons;
20
use Koha::Patrons;
21
use Koha::CirculationRules;
21
22
22
BEGIN {
23
BEGIN {
23
    use FindBin;
24
    use FindBin;
Lines 467-472 subtest 'Test max_holds per library/patron category' => sub { Link Here
467
468
468
    $dbh->do('DELETE FROM reserves');
469
    $dbh->do('DELETE FROM reserves');
469
    $dbh->do('DELETE FROM issuingrules');
470
    $dbh->do('DELETE FROM issuingrules');
471
    $dbh->do('DELETE FROM circulation_rules');
470
472
471
    ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST');
473
    ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST');
472
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
474
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
Lines 491-510 subtest 'Test max_holds per library/patron category' => sub { Link Here
491
    my $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
493
    my $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
492
    is( $ret, 'OK', 'Patron can place hold with no borrower circ rules' );
494
    is( $ret, 'OK', 'Patron can place hold with no borrower circ rules' );
493
495
494
    my $rule_all = $schema->resultset('DefaultBorrowerCircRule')->new(
496
    my $rule_all = Koha::CirculationRules->set_rule(
495
        {
497
        {
496
            categorycode => $category->{categorycode},
498
            categorycode => $category->{categorycode},
497
            max_holds    => 3,
499
            branchcode   => undef,
500
            itemtype     => undef,
501
            rule_name    => 'max_holds',
502
            rule_value   => 3,
498
        }
503
        }
499
    )->insert();
504
    );
500
505
501
    my $rule_branch = $schema->resultset('BranchBorrowerCircRule')->new(
506
    my $rule_branch = Koha::CirculationRules->set_rule(
502
        {
507
        {
503
            branchcode   => $branch_1,
508
            branchcode   => $branch_1,
504
            categorycode => $category->{categorycode},
509
            categorycode => $category->{categorycode},
505
            max_holds    => 5,
510
            itemtype     => undef,
511
            rule_name    => 'max_holds',
512
            rule_value   => 5,
506
        }
513
        }
507
    )->insert();
514
    );
508
515
509
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
516
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
510
    is( $ret, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 3' );
517
    is( $ret, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 3' );
Lines 515-530 subtest 'Test max_holds per library/patron category' => sub { Link Here
515
    is( $ret, 'tooManyReserves', 'Patron cannot place hold with only a category rule of 3' );
522
    is( $ret, 'tooManyReserves', 'Patron cannot place hold with only a category rule of 3' );
516
523
517
    $rule_all->delete();
524
    $rule_all->delete();
518
    $rule_branch->max_holds(3);
525
    $rule_branch->rule_value(3);
519
    $rule_branch->insert();
526
    $rule_branch->store();
520
527
521
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
528
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
522
    is( $ret, 'tooManyReserves', 'Patron cannot place hold with only a branch/category rule of 3' );
529
    is( $ret, 'tooManyReserves', 'Patron cannot place hold with only a branch/category rule of 3' );
523
530
524
    $rule_branch->max_holds(5);
531
    $rule_branch->rule_value(5);
525
    $rule_branch->update();
532
    $rule_branch->update();
526
    $rule_branch->max_holds(5);
533
    $rule_branch->rule_value(5);
527
    $rule_branch->insert();
534
    $rule_branch->store();
528
535
529
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
536
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
530
    is( $ret, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 5' );
537
    is( $ret, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 5' );
531
- 

Return to bug 18887