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 399-424 sub CanItemBeReserved { Link Here
399
    }
400
    }
400
401
401
    # Now we need to check hold limits by patron category
402
    # Now we need to check hold limits by patron category
402
    my $schema = Koha::Database->new()->schema();
403
    my $rule = Koha::CirculationRules->find(
403
    my $rule = $schema->resultset('BranchBorrowerCircRule')->find(
404
        {
404
        {
405
            branchcode   => $borrower->{branchcode},
406
            categorycode => $borrower->{categorycode},
405
            categorycode => $borrower->{categorycode},
406
            branchcode   => $borrower->{branchcode},
407
            itemtype     => undef,
408
            rule_name    => 'max_holds',
407
        }
409
        }
408
    );
410
    );
409
    $rule ||= $schema->resultset('DefaultBorrowerCircRule')->find(
411
    $rule ||= Koha::CirculationRules->find(
410
        {
412
        {
411
            categorycode => $borrower->{categorycode}
413
            categorycode => $borrower->{categorycode},
414
            branchcode   => undef,,
415
            itemtype     => undef,
416
            rule_name    => 'max_holds',
412
        }
417
        }
413
    );
418
    );
414
    if ( $rule && defined $rule->max_holds ) {
419
    if ( $rule ) {
415
        my $total_holds_count = Koha::Holds->search(
420
        my $total_holds_count = Koha::Holds->search(
416
            {
421
            {
417
                borrowernumber => $borrower->{borrowernumber}
422
                borrowernumber => $borrower->{borrowernumber}
418
            }
423
            }
419
        )->count();
424
        )->count();
420
425
421
        return 'tooManyReserves' if $total_holds_count >= $rule->max_holds;
426
        return 'tooManyReserves' if $total_holds_count >= $rule->rule_value;
422
    }
427
    }
423
428
424
    my $circ_control_branch =
429
    my $circ_control_branch =
(-)a/admin/smart-rules.pl (-17 / +53 lines)
Lines 33-38 use Koha::Logger; Link Here
33
use Koha::RefundLostItemFeeRule;
33
use Koha::RefundLostItemFeeRule;
34
use Koha::RefundLostItemFeeRules;
34
use Koha::RefundLostItemFeeRules;
35
use Koha::Libraries;
35
use Koha::Libraries;
36
use Koha::CirculationRules;
36
use Koha::Patron::Categories;
37
use Koha::Patron::Categories;
37
use Koha::Patrons;
38
use Koha::Patrons;
38
39
Lines 101-106 elsif ($op eq 'delete-branch-cat') { Link Here
101
                                        AND categorycode = ?");
102
                                        AND categorycode = ?");
102
        $sth_delete->execute($branch, $categorycode);
103
        $sth_delete->execute($branch, $categorycode);
103
    }
104
    }
105
    Koha::CirculationRules->set_rule(
106
        {
107
            branchcode   => $branch,
108
            categorycode => $categorycode,
109
            itemtype     => undef,
110
            rule_name    => 'max_holds',
111
            rule_value   => undef,
112
        }
113
    );
104
}
114
}
105
elsif ($op eq 'delete-branch-item') {
115
elsif ($op eq 'delete-branch-item') {
106
    my $itemtype  = $input->param('itemtype');
116
    my $itemtype  = $input->param('itemtype');
Lines 276-321 elsif ($op eq "add-branch-cat") { Link Here
276
                                            FROM default_circ_rules");
286
                                            FROM default_circ_rules");
277
            my $sth_insert = $dbh->prepare(q|
287
            my $sth_insert = $dbh->prepare(q|
278
                INSERT INTO default_circ_rules
288
                INSERT INTO default_circ_rules
279
                    (maxissueqty, maxonsiteissueqty, max_holds)
289
                    (maxissueqty, maxonsiteissueqty)
280
                    VALUES (?, ?, ?)
290
                    VALUES (?, ?, )
281
            |);
291
            |);
282
            my $sth_update = $dbh->prepare(q|
292
            my $sth_update = $dbh->prepare(q|
283
                UPDATE default_circ_rules
293
                UPDATE default_circ_rules
284
                SET maxissueqty = ?,
294
                SET maxissueqty = ?,
285
                    maxonsiteissueqty = ?,
295
                    maxonsiteissueqty = ?
286
                    max_holds = ?
287
            |);
296
            |);
288
297
289
            $sth_search->execute();
298
            $sth_search->execute();
290
            my $res = $sth_search->fetchrow_hashref();
299
            my $res = $sth_search->fetchrow_hashref();
291
            if ($res->{total}) {
300
            if ($res->{total}) {
292
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $max_holds );
301
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty );
293
            } else {
302
            } else {
294
                $sth_insert->execute( $maxissueqty, $maxonsiteissueqty, $max_holds );
303
                $sth_insert->execute( $maxissueqty, $maxonsiteissueqty );
295
            }
304
            }
305
306
            Koha::CirculationRules->set_rule(
307
                {
308
                    branchcode   => undef,
309
                    categorycode => undef,
310
                    itemtype     => undef,
311
                    rule_name    => 'max_holds',
312
                    rule_value   => $max_holds,
313
                }
314
            );
296
        } else {
315
        } else {
297
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
316
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
298
                                            FROM default_borrower_circ_rules
317
                                            FROM default_borrower_circ_rules
299
                                            WHERE categorycode = ?");
318
                                            WHERE categorycode = ?");
300
            my $sth_insert = $dbh->prepare(q|
319
            my $sth_insert = $dbh->prepare(q|
301
                INSERT INTO default_borrower_circ_rules
320
                INSERT INTO default_borrower_circ_rules
302
                    (categorycode, maxissueqty, maxonsiteissueqty, max_holds)
321
                    (categorycode, maxissueqty, maxonsiteissueqty)
303
                    VALUES (?, ?, ?, ?)
322
                    VALUES (?, ?, ?, ?)
304
            |);
323
            |);
305
            my $sth_update = $dbh->prepare(q|
324
            my $sth_update = $dbh->prepare(q|
306
                UPDATE default_borrower_circ_rules
325
                UPDATE default_borrower_circ_rules
307
                SET maxissueqty = ?,
326
                SET maxissueqty = ?,
308
                    maxonsiteissueqty = ?,
327
                    maxonsiteissueqty = ?
309
                    max_holds = ?
310
                WHERE categorycode = ?
328
                WHERE categorycode = ?
311
            |);
329
            |);
312
            $sth_search->execute($branch);
330
            $sth_search->execute($branch);
313
            my $res = $sth_search->fetchrow_hashref();
331
            my $res = $sth_search->fetchrow_hashref();
314
            if ($res->{total}) {
332
            if ($res->{total}) {
315
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode, $max_holds );
333
                $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode );
316
            } else {
334
            } else {
317
                $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty, $max_holds );
335
                $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty );
318
            }
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
            );
319
        }
347
        }
320
    } elsif ($categorycode eq "*") {
348
    } elsif ($categorycode eq "*") {
321
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
349
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
Lines 346-359 elsif ($op eq "add-branch-cat") { Link Here
346
                                        AND   categorycode = ?");
374
                                        AND   categorycode = ?");
347
        my $sth_insert = $dbh->prepare(q|
375
        my $sth_insert = $dbh->prepare(q|
348
            INSERT INTO branch_borrower_circ_rules
376
            INSERT INTO branch_borrower_circ_rules
349
            (branchcode, categorycode, maxissueqty, maxonsiteissueqty, max_holds)
377
            (branchcode, categorycode, maxissueqty, maxonsiteissueqty)
350
            VALUES (?, ?, ?, ?, ?)
378
            VALUES (?, ?, ?, ?)
351
        |);
379
        |);
352
        my $sth_update = $dbh->prepare(q|
380
        my $sth_update = $dbh->prepare(q|
353
            UPDATE branch_borrower_circ_rules
381
            UPDATE branch_borrower_circ_rules
354
            SET maxissueqty = ?,
382
            SET maxissueqty = ?,
355
                maxonsiteissueqty = ?
383
                maxonsiteissueqty = ?
356
                max_holds = ?
357
            WHERE branchcode = ?
384
            WHERE branchcode = ?
358
            AND categorycode = ?
385
            AND categorycode = ?
359
        |);
386
        |);
Lines 361-370 elsif ($op eq "add-branch-cat") { Link Here
361
        $sth_search->execute($branch, $categorycode);
388
        $sth_search->execute($branch, $categorycode);
362
        my $res = $sth_search->fetchrow_hashref();
389
        my $res = $sth_search->fetchrow_hashref();
363
        if ($res->{total}) {
390
        if ($res->{total}) {
364
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $max_holds, $branch, $categorycode);
391
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch, $categorycode);
365
        } else {
392
        } else {
366
            $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty, $max_holds);
393
            $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty);
367
        }
394
        }
395
396
        Koha::CirculationRules->set_rule(
397
            {
398
                branchcode   => $branch,
399
                categorycode => $categorycode,
400
                itemtype     => undef,
401
                rule_name    => 'max_holds',
402
                rule_value   => $max_holds,
403
            }
404
        );
368
    }
405
    }
369
}
406
}
370
elsif ($op eq "add-branch-item") {
407
elsif ($op eq "add-branch-item") {
Lines 559-565 my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humanca Link Here
559
foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) {
596
foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) {
560
    $entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty});
597
    $entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty});
561
    $entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty});
598
    $entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty});
562
    $entry->{unlimited_max_holds} = 1 unless defined($entry->{max_holds});
563
}
599
}
564
600
565
@sorted_row_loop = sort by_category_and_itemtype @row_loop;
601
@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
[% SET footerjs = 1 %]
3
[% SET footerjs = 1 %]
3
[% INCLUDE 'doc-head-open.inc' %]
4
[% INCLUDE 'doc-head-open.inc' %]
4
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
5
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
Lines 493-502 Link Here
493
                                [% branch_cat_rule_loo.maxonsiteissueqty %]
494
                                [% branch_cat_rule_loo.maxonsiteissueqty %]
494
                            [% END %]
495
                            [% END %]
495
                        </td>
496
                        </td>
496
                        <td>[% IF ( branch_cat_rule_loo.unlimited_max_holds ) %]
497
                        <td>
497
                                Unlimited
498
                            [% SET rule_value = CirculationRules.Get( branch_cat_rule_loo.branchcode, branch_cat_rule_loo.categorycode, branch_cat_rule_loo.itemtype, 'max_holds' ) %]
499
                            [% IF rule_value  %]
500
                                [% rule_value %]
498
                            [% ELSE %]
501
                            [% ELSE %]
499
                                [% branch_cat_rule_loo.max_holds %]
502
                                Unlimited
500
                            [% END %]
503
                            [% END %]
501
                        </td>
504
                        </td>
502
505
(-)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 416-421 subtest 'Test max_holds per library/patron category' => sub { Link Here
416
417
417
    $dbh->do('DELETE FROM reserves');
418
    $dbh->do('DELETE FROM reserves');
418
    $dbh->do('DELETE FROM issuingrules');
419
    $dbh->do('DELETE FROM issuingrules');
420
    $dbh->do('DELETE FROM circulation_rules');
419
421
420
    ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST');
422
    ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST');
421
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
423
    ( $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 );
442
    my $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
441
    is( $ret, 'OK', 'Patron can place hold with no borrower circ rules' );
443
    is( $ret, 'OK', 'Patron can place hold with no borrower circ rules' );
442
444
443
    my $rule_all = $schema->resultset('DefaultBorrowerCircRule')->new(
445
    my $rule_all = Koha::CirculationRules->set_rule(
444
        {
446
        {
445
            categorycode => $category->{categorycode},
447
            categorycode => $category->{categorycode},
446
            max_holds    => 3,
448
            branchcode   => undef,
449
            itemtype     => undef,
450
            rule_name    => 'max_holds',
451
            rule_value   => 3,
447
        }
452
        }
448
    )->insert();
453
    );
449
454
450
    my $rule_branch = $schema->resultset('BranchBorrowerCircRule')->new(
455
    my $rule_branch = Koha::CirculationRules->set_rule(
451
        {
456
        {
452
            branchcode   => $branch_1,
457
            branchcode   => $branch_1,
453
            categorycode => $category->{categorycode},
458
            categorycode => $category->{categorycode},
454
            max_holds    => 5,
459
            itemtype     => undef,
460
            rule_name    => 'max_holds',
461
            rule_value   => 5,
455
        }
462
        }
456
    )->insert();
463
    );
457
464
458
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
465
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
459
    is( $ret, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 3' );
466
    is( $ret, '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, 'tooManyReserves', 'Patron cannot place hold with only a category rule of 3' );
471
    is( $ret, 'tooManyReserves', 'Patron cannot place hold with only a category rule of 3' );
465
472
466
    $rule_all->delete();
473
    $rule_all->delete();
467
    $rule_branch->max_holds(3);
474
    $rule_branch->rule_value(3);
468
    $rule_branch->insert();
475
    $rule_branch->store();
469
476
470
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
477
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
471
    is( $ret, 'tooManyReserves', 'Patron cannot place hold with only a branch/category rule of 3' );
478
    is( $ret, 'tooManyReserves', 'Patron cannot place hold with only a branch/category rule of 3' );
472
479
473
    $rule_branch->max_holds(5);
480
    $rule_branch->rule_value(5);
474
    $rule_branch->update();
481
    $rule_branch->update();
475
    $rule_branch->max_holds(5);
482
    $rule_branch->rule_value(5);
476
    $rule_branch->insert();
483
    $rule_branch->store();
477
484
478
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
485
    $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
479
    is( $ret, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 5' );
486
    is( $ret, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 5' );
480
- 

Return to bug 18887