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

(-)a/C4/Circulation.pm (-9 / +19 lines)
Lines 427-433 sub TooMany { Link Here
427
                                    AND   (categorycode = ? OR categorycode = ?)
427
                                    AND   (categorycode = ? OR categorycode = ?)
428
                                    AND   itemtype <> '*'
428
                                    AND   itemtype <> '*'
429
                                  ) ";
429
                                  ) ";
430
            } else { 
430
            } else {
431
                $count_query .= " JOIN  biblioitems USING (biblionumber) 
431
                $count_query .= " JOIN  biblioitems USING (biblionumber) 
432
                                  WHERE biblioitems.itemtype NOT IN (
432
                                  WHERE biblioitems.itemtype NOT IN (
433
                                    SELECT itemtype FROM issuingrules
433
                                    SELECT itemtype FROM issuingrules
Lines 512-525 sub TooMany { Link Here
512
        |;
512
        |;
513
        push @bind_params, $borrower->{borrowernumber};
513
        push @bind_params, $borrower->{borrowernumber};
514
514
515
        if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
515
        # Only for specific or default branches.
516
            $branch_count_query .= " AND issues.branchcode = ? ";
516
        unless ($branch_borrower_circ_rule->{has_priority}) {
517
            push @bind_params, $branch;
517
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
518
        } elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') {
518
                $branch_count_query .= " AND issues.branchcode = ? ";
519
            ; # if branch is the patron's home branch, then count all loans by patron
519
                push @bind_params, $branch;
520
        } else {
520
            } elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') {
521
            $branch_count_query .= " AND items.homebranch = ? ";
521
                ; # if branch is the patron's home branch, then count all loans by patron
522
            push @bind_params, $branch;
522
            } else {
523
                $branch_count_query .= " AND items.homebranch = ? ";
524
                push @bind_params, $branch;
525
            }
523
        }
526
        }
524
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $branch_count_query, {}, @bind_params );
527
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $branch_count_query, {}, @bind_params );
525
        my $max_checkouts_allowed = $branch_borrower_circ_rule->{maxissueqty};
528
        my $max_checkouts_allowed = $branch_borrower_circ_rule->{maxissueqty};
Lines 1616-1621 sub GetBranchBorrowerCircRule { Link Here
1616
    my $rules;
1619
    my $rules;
1617
    my $dbh = C4::Context->dbh();
1620
    my $dbh = C4::Context->dbh();
1618
    $rules = $dbh->selectrow_hashref( q|
1621
    $rules = $dbh->selectrow_hashref( q|
1622
        SELECT maxissueqty, maxonsiteissueqty, has_priority
1623
        FROM default_borrower_circ_rules
1624
        WHERE categorycode = ? AND has_priority = 1
1625
    |, {}, $categorycode ) ;
1626
    return $rules if $rules;
1627
1628
    $rules = $dbh->selectrow_hashref( q|
1619
        SELECT maxissueqty, maxonsiteissueqty
1629
        SELECT maxissueqty, maxonsiteissueqty
1620
        FROM branch_borrower_circ_rules
1630
        FROM branch_borrower_circ_rules
1621
        WHERE branchcode = ?
1631
        WHERE branchcode = ?
(-)a/admin/smart-rules.pl (-6 / +10 lines)
Lines 255-264 elsif ($op eq "add-branch-cat") { Link Here
255
    my $categorycode  = $input->param('categorycode');
255
    my $categorycode  = $input->param('categorycode');
256
    my $maxissueqty   = $input->param('maxissueqty');
256
    my $maxissueqty   = $input->param('maxissueqty');
257
    my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
257
    my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
258
    my $has_priority = $input->param('has_priority');
258
    $maxissueqty =~ s/\s//g;
259
    $maxissueqty =~ s/\s//g;
259
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
260
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
260
    $maxonsiteissueqty =~ s/\s//g;
261
    $maxonsiteissueqty =~ s/\s//g;
261
    $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
262
    $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
263
    $has_priority = $has_priority ? 1 : 0;
262
264
263
    if ($branch eq "*") {
265
    if ($branch eq "*") {
264
        if ($categorycode eq "*") {
266
        if ($categorycode eq "*") {
Lines 285-308 elsif ($op eq "add-branch-cat") { Link Here
285
        } else {
287
        } else {
286
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
288
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
287
                                            FROM default_borrower_circ_rules
289
                                            FROM default_borrower_circ_rules
288
                                            WHERE categorycode = ?");
290
                                            WHERE categorycode = ?
291
                                            AND has_priority = ?");
289
            my $sth_insert = $dbh->prepare(q|
292
            my $sth_insert = $dbh->prepare(q|
290
                INSERT INTO default_borrower_circ_rules
293
                INSERT INTO default_borrower_circ_rules
291
                    (categorycode, maxissueqty, maxonsiteissueqty)
294
                    (categorycode, maxissueqty, maxonsiteissueqty, has_priority)
292
                    VALUES (?, ?, ?)
295
                    VALUES (?, ?, ?, ?)
293
            |);
296
            |);
294
            my $sth_update = $dbh->prepare(q|
297
            my $sth_update = $dbh->prepare(q|
295
                UPDATE default_borrower_circ_rules
298
                UPDATE default_borrower_circ_rules
296
                SET maxissueqty = ?,
299
                SET maxissueqty = ?,
297
                    maxonsiteissueqty = ?
300
                    maxonsiteissueqty = ?
298
                WHERE categorycode = ?
301
                WHERE categorycode = ?
302
                AND has_priority = ?
299
            |);
303
            |);
300
            $sth_search->execute($branch);
304
            $sth_search->execute($categorycode, $has_priority);
301
            my $res = $sth_search->fetchrow_hashref();
305
            my $res = $sth_search->fetchrow_hashref();
302
            if ($res->{total}) {
306
            if ($res->{total}) {
303
                $sth_update->execute($maxissueqty, $maxonsiteissueqty, $categorycode);
307
                $sth_update->execute($maxissueqty, $maxonsiteissueqty, $categorycode, $has_priority) or die $sth_update->errstr;;
304
            } else {
308
            } else {
305
                $sth_insert->execute($categorycode, $maxissueqty, $maxonsiteissueqty);
309
                $sth_insert->execute($categorycode, $maxissueqty, $maxonsiteissueqty, $has_priority);
306
            }
310
            }
307
        }
311
        }
308
    } elsif ($categorycode eq "*") {
312
    } elsif ($categorycode eq "*") {
(-)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 547-552 $(document).ready(function() { Link Here
547
        <p>If the total amount loanable for a given patron category is left blank,
547
        <p>If the total amount loanable for a given patron category is left blank,
548
           no limit applies, except possibly for a limit you define for a specific item type.
548
           no limit applies, except possibly for a limit you define for a specific item type.
549
        </p>
549
        </p>
550
        <p>
551
            <b>Has priority: </b>If checked, the rule will override those for all branches. Else
552
            it behaves like a default one: used if no rule existe for the coresponding branch.
553
        </p>
550
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
554
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
551
            <input type="hidden" name="op" value="add-branch-cat" />
555
            <input type="hidden" name="op" value="add-branch-cat" />
552
            <input type="hidden" name="branch" value="[% current_branch %]"/>
556
            <input type="hidden" name="branch" value="[% current_branch %]"/>
Lines 555-560 $(document).ready(function() { Link Here
555
                    <th>Patron category</th>
559
                    <th>Patron category</th>
556
                    <th>Total current checkouts allowed</th>
560
                    <th>Total current checkouts allowed</th>
557
                    <th>Total current on-site checkouts allowed</th>
561
                    <th>Total current on-site checkouts allowed</th>
562
                    [% UNLESS humanbranch %]<th>Has priority</th>[% END %]
558
                    <th>&nbsp;</th>
563
                    <th>&nbsp;</th>
559
                </tr>
564
                </tr>
560
                [% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %]
565
                [% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %]
Lines 581-586 $(document).ready(function() { Link Here
581
                                [% branch_cat_rule_loo.maxonsiteissueqty %]
586
                                [% branch_cat_rule_loo.maxonsiteissueqty %]
582
                            [% END %]
587
                            [% END %]
583
                        </td>
588
                        </td>
589
                        [% UNLESS humanbranch %]
590
                            <td>
591
                                <input type="checkbox" [% IF branch_cat_rule_loo.has_priority %]checked[% END %] disabled/>
592
                            </td>
593
                        [% END %]
584
594
585
                        <td class="actions">
595
                        <td class="actions">
586
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% branch_cat_rule_loo.categorycode %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
596
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% branch_cat_rule_loo.categorycode %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
Lines 597-602 $(document).ready(function() { Link Here
597
                    </td>
607
                    </td>
598
                    <td><input name="maxissueqty" size="3" /></td>
608
                    <td><input name="maxissueqty" size="3" /></td>
599
                    <td><input name="maxonsiteissueqty" size="3" /></td>
609
                    <td><input name="maxonsiteissueqty" size="3" /></td>
610
                    [% UNLESS humanbranch %]
611
                        <td>
612
                            <input type="checkbox" name="has_priority"/>
613
                        </td>
614
                    [% END %]
600
                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td>
615
                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td>
601
                </tr>
616
                </tr>
602
            </table>
617
            </table>
(-)a/t/db_dependent/Circulation/Branch.t (-2 / +25 lines)
Lines 23-29 use C4::Circulation; Link Here
23
use C4::Items;
23
use C4::Items;
24
use C4::Context;
24
use C4::Context;
25
25
26
use Test::More tests => 14;
26
use Test::More tests => 15;
27
use t::lib::Mocks;
27
use t::lib::Mocks;
28
use t::lib::TestBuilder;
28
use t::lib::TestBuilder;
29
29
Lines 196-202 $sth->execute( Link Here
196
    5, 'noreturn'
196
    5, 'noreturn'
197
);
197
);
198
198
199
$query = q|
200
    INSERT INTO default_borrower_circ_rules
201
    (categorycode, maxissueqty, maxonsiteissueqty, has_priority)
202
    VALUES( ?, ?, ?, ? )
203
|;
204
$dbh->do($query, {}, $samplecat->{categorycode}, 3, 3, 0);
205
199
#Test GetBranchBorrowerCircRule
206
#Test GetBranchBorrowerCircRule
207
#
200
is_deeply(
208
is_deeply(
201
    GetBranchBorrowerCircRule(),
209
    GetBranchBorrowerCircRule(),
202
    { maxissueqty => 4, maxonsiteissueqty => 5 },
210
    { maxissueqty => 4, maxonsiteissueqty => 5 },
Lines 221-226 is_deeply( Link Here
221
"GetBranchBorrower with wrong parameters returns the maxissueqty and maxonsiteissueqty of default_circ_rules"
229
"GetBranchBorrower with wrong parameters returns the maxissueqty and maxonsiteissueqty of default_circ_rules"
222
);
230
);
223
231
232
$query = q|
233
    INSERT INTO default_borrower_circ_rules
234
    (categorycode, maxissueqty, maxonsiteissueqty, has_priority)
235
    VALUES( ?, ?, ?, ? )
236
|;
237
$dbh->do($query, {}, $samplecat->{categorycode}, 3, 3, 1);
238
239
is_deeply(
240
    GetBranchBorrowerCircRule(
241
        $samplebranch1->{branchcode},
242
        $samplecat->{categorycode}
243
    ),
244
    { maxissueqty => 3, maxonsiteissueqty => 3, has_priority => 1 },
245
    "GetBranchBorrower returns the rule having priority"
246
);
247
224
#Test GetBranchItemRule
248
#Test GetBranchItemRule
225
my @lazy_any = ( 'hold_fulfillment_policy' => 'any' );
249
my @lazy_any = ( 'hold_fulfillment_policy' => 'any' );
226
is_deeply(
250
is_deeply(
227
- 

Return to bug 8137