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

(-)a/C4/Circulation.pm (-8 / +11 lines)
Lines 516-529 sub TooMany { Link Here
516
        |;
516
        |;
517
        push @bind_params, $borrower->{borrowernumber};
517
        push @bind_params, $borrower->{borrowernumber};
518
518
519
        if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
519
        # Only for specific or default branches.
520
            $branch_count_query .= " AND issues.branchcode = ? ";
520
        unless ($branch_borrower_circ_rule->{has_priority}) {
521
            push @bind_params, $branch;
521
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
522
        } elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') {
522
                $branch_count_query .= " AND issues.branchcode = ? ";
523
            ; # if branch is the patron's home branch, then count all loans by patron
523
                push @bind_params, $branch;
524
        } else {
524
            } elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') {
525
            $branch_count_query .= " AND items.homebranch = ? ";
525
                ; # if branch is the patron's home branch, then count all loans by patron
526
            push @bind_params, $branch;
526
            } else {
527
                $branch_count_query .= " AND items.homebranch = ? ";
528
                push @bind_params, $branch;
529
            }
527
        }
530
        }
528
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $branch_count_query, {}, @bind_params );
531
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $branch_count_query, {}, @bind_params );
529
        my $max_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxissueqty};
532
        my $max_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxissueqty};
(-)a/admin/smart-rules.pl (+6 lines)
Lines 408-413 elsif ($op eq "add-branch-cat") { Link Here
408
    my $max_holds = $input->param('max_holds');
408
    my $max_holds = $input->param('max_holds');
409
    $max_holds =~ s/\s//g;
409
    $max_holds =~ s/\s//g;
410
    $max_holds = undef if $max_holds !~ /^\d+/;
410
    $max_holds = undef if $max_holds !~ /^\d+/;
411
    my $has_priority = $input->param('has_priority');
412
    $has_priority = $has_priority ? 1 : 0;
411
413
412
    if ($branch eq "*") {
414
    if ($branch eq "*") {
413
        if ($categorycode eq "*") {
415
        if ($categorycode eq "*") {
Lines 423-428 elsif ($op eq "add-branch-cat") { Link Here
423
                }
425
                }
424
            );
426
            );
425
        } else {
427
        } else {
428
426
            Koha::CirculationRules->set_rules(
429
            Koha::CirculationRules->set_rules(
427
                {
430
                {
428
                    categorycode => $categorycode,
431
                    categorycode => $categorycode,
Lines 431-436 elsif ($op eq "add-branch-cat") { Link Here
431
                        max_holds         => $max_holds,
434
                        max_holds         => $max_holds,
432
                        patron_maxissueqty       => $patron_maxissueqty,
435
                        patron_maxissueqty       => $patron_maxissueqty,
433
                        patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
436
                        patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
437
                        has_priority      => $has_priority,
434
                    }
438
                    }
435
                }
439
                }
436
            );
440
            );
Lines 444-449 elsif ($op eq "add-branch-cat") { Link Here
444
                    max_holds         => $max_holds,
448
                    max_holds         => $max_holds,
445
                    patron_maxissueqty       => $patron_maxissueqty,
449
                    patron_maxissueqty       => $patron_maxissueqty,
446
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
450
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
451
                    has_priority      => $has_priority,
447
                }
452
                }
448
            }
453
            }
449
        );
454
        );
Lines 456-461 elsif ($op eq "add-branch-cat") { Link Here
456
                    max_holds         => $max_holds,
461
                    max_holds         => $max_holds,
457
                    patron_maxissueqty       => $patron_maxissueqty,
462
                    patron_maxissueqty       => $patron_maxissueqty,
458
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
463
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
464
                    has_priority      => $has_priority,
459
                }
465
                }
460
            }
466
            }
461
        );
467
        );
(-)a/installer/data/mysql/atomicupdate/Bug_8137-add-column-has_priority.sql (+5 lines)
Line 0 Link Here
1
ALTER TABLE default_borrower_circ_rules ADD has_priority INT(1) DEFAULT 0;
2
ALTER TABLE default_borrower_circ_rules DROP foreign key borrower_borrower_circ_rules_ibfk_1;
3
ALTER TABLE default_borrower_circ_rules DROP primary key;
4
ALTER TABLE default_borrower_circ_rules ADD primary key(categorycode, has_priority);
5
ALTER TABLE default_borrower_circ_rules ADD CONSTRAINT borrower_borrower_circ_rules_ibfk_1 FOREIGN KEY (categorycode) REFERENCES categories (categorycode) ON DELETE CASCADE ON UPDATE CASCADE;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (+15 lines)
Lines 648-653 Link Here
648
        <p>If the total amount loanable for a given patron category is left blank,
648
        <p>If the total amount loanable for a given patron category is left blank,
649
           no limit applies, except possibly for a limit you define for a specific item type.
649
           no limit applies, except possibly for a limit you define for a specific item type.
650
        </p>
650
        </p>
651
        <p>
652
            <b>Has priority: </b>If checked, the rule will override those for all branches. Else
653
            it behaves like a default one: used if no rule existe for the coresponding branch.
654
        </p>
651
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
655
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
652
            <input type="hidden" name="op" value="add-branch-cat" />
656
            <input type="hidden" name="op" value="add-branch-cat" />
653
            <input type="hidden" name="branch" value="[% current_branch | html %]"/>
657
            <input type="hidden" name="branch" value="[% current_branch | html %]"/>
Lines 657-662 Link Here
657
                    <th>Total current checkouts allowed</th>
661
                    <th>Total current checkouts allowed</th>
658
                    <th>Total current on-site checkouts allowed</th>
662
                    <th>Total current on-site checkouts allowed</th>
659
                    <th>Total holds allowed</th>
663
                    <th>Total holds allowed</th>
664
                    [% UNLESS humanbranch %]<th>Has priority</th>[% END %]
660
                    <th>&nbsp;</th>
665
                    <th>&nbsp;</th>
661
                </tr>
666
                </tr>
662
                [% FOREACH c IN categorycodes %]
667
                [% FOREACH c IN categorycodes %]
Lines 695-700 Link Here
695
                                <span>Unlimited</span>
700
                                <span>Unlimited</span>
696
                            [% END %]
701
                            [% END %]
697
                        </td>
702
                        </td>
703
                        [% UNLESS humanbranch %]
704
                            <td>
705
                                <input type="checkbox" [% IF branch_cat_rule_loo.has_priority %]checked[% END %] disabled/>
706
                            </td>
707
                        [% END %]
698
708
699
                        <td class="actions">
709
                        <td class="actions">
700
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% c | html %]&amp;branch=[% current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
710
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% c | html %]&amp;branch=[% current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
Lines 713-718 Link Here
713
                    <td><input name="patron_maxissueqty" size="3" type="text" /></td>
723
                    <td><input name="patron_maxissueqty" size="3" type="text" /></td>
714
                    <td><input name="patron_maxonsiteissueqty" size="3" type="text" /></td>
724
                    <td><input name="patron_maxonsiteissueqty" size="3" type="text" /></td>
715
                    <td><input name="max_holds" size="3" type="text" /></td>
725
                    <td><input name="max_holds" size="3" type="text" /></td>
726
                    [% UNLESS humanbranch %]
727
                        <td>
728
                            <input type="checkbox" name="has_priority"/>
729
                        </td>
730
                    [% END %]
716
                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td>
731
                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td>
717
                </tr>
732
                </tr>
718
            </table>
733
            </table>
(-)a/t/db_dependent/Circulation/Branch.t (-2 / +25 lines)
Lines 25-31 use Koha::CirculationRules; Link Here
25
25
26
use Koha::Patrons;
26
use Koha::Patrons;
27
27
28
use Test::More tests => 14;
28
use Test::More tests => 15;
29
use t::lib::Mocks;
29
use t::lib::Mocks;
30
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
31
31
Lines 232-238 Koha::CirculationRules->set_rules( Link Here
232
    }
232
    }
233
);
233
);
234
234
235
$query = q|
236
    INSERT INTO default_borrower_circ_rules
237
    (categorycode, maxissueqty, maxonsiteissueqty, has_priority)
238
    VALUES( ?, ?, ?, ? )
239
|;
240
$dbh->do($query, {}, $samplecat->{categorycode}, 3, 3, 0);
241
235
#Test GetBranchBorrowerCircRule
242
#Test GetBranchBorrowerCircRule
243
#
236
is_deeply(
244
is_deeply(
237
    GetBranchBorrowerCircRule(),
245
    GetBranchBorrowerCircRule(),
238
    { patron_maxissueqty => 4, patron_maxonsiteissueqty => 5 },
246
    { patron_maxissueqty => 4, patron_maxonsiteissueqty => 5 },
Lines 257-262 is_deeply( Link Here
257
"GetBranchBorrower with wrong parameters returns the patron_maxissueqty and patron_maxonsiteissueqty of default_circ_rules"
265
"GetBranchBorrower with wrong parameters returns the patron_maxissueqty and patron_maxonsiteissueqty of default_circ_rules"
258
);
266
);
259
267
268
$query = q|
269
    INSERT INTO default_borrower_circ_rules
270
    (categorycode, maxissueqty, maxonsiteissueqty, has_priority)
271
    VALUES( ?, ?, ?, ? )
272
|;
273
$dbh->do($query, {}, $samplecat->{categorycode}, 3, 3, 1);
274
275
is_deeply(
276
    GetBranchBorrowerCircRule(
277
        $samplebranch1->{branchcode},
278
        $samplecat->{categorycode}
279
    ),
280
    { maxissueqty => 3, maxonsiteissueqty => 3, has_priority => 1 },
281
    "GetBranchBorrower returns the rule having priority"
282
);
283
260
#Test GetBranchItemRule
284
#Test GetBranchItemRule
261
my @lazy_any = ( 'hold_fulfillment_policy' => 'any' );
285
my @lazy_any = ( 'hold_fulfillment_policy' => 'any' );
262
is_deeply(
286
is_deeply(
263
- 

Return to bug 8137