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

(-)a/C4/Circulation.pm (-9 / +19 lines)
Lines 417-423 sub TooMany { Link Here
417
                                    AND   (categorycode = ? OR categorycode = ?)
417
                                    AND   (categorycode = ? OR categorycode = ?)
418
                                    AND   itemtype <> '*'
418
                                    AND   itemtype <> '*'
419
                                  ) ";
419
                                  ) ";
420
            } else { 
420
            } else {
421
                $count_query .= " JOIN  biblioitems USING (biblionumber) 
421
                $count_query .= " JOIN  biblioitems USING (biblionumber) 
422
                                  WHERE biblioitems.itemtype NOT IN (
422
                                  WHERE biblioitems.itemtype NOT IN (
423
                                    SELECT itemtype FROM issuingrules
423
                                    SELECT itemtype FROM issuingrules
Lines 502-515 sub TooMany { Link Here
502
        |;
502
        |;
503
        push @bind_params, $borrower->{borrowernumber};
503
        push @bind_params, $borrower->{borrowernumber};
504
504
505
        if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
505
        # Only for specific or default branches.
506
            $branch_count_query .= " AND issues.branchcode = ? ";
506
        unless ($branch_borrower_circ_rule->{has_priority}) {
507
            push @bind_params, $branch;
507
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
508
        } elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') {
508
                $branch_count_query .= " AND issues.branchcode = ? ";
509
            ; # if branch is the patron's home branch, then count all loans by patron
509
                push @bind_params, $branch;
510
        } else {
510
            } elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') {
511
            $branch_count_query .= " AND items.homebranch = ? ";
511
                ; # if branch is the patron's home branch, then count all loans by patron
512
            push @bind_params, $branch;
512
            } else {
513
                $branch_count_query .= " AND items.homebranch = ? ";
514
                push @bind_params, $branch;
515
            }
513
        }
516
        }
514
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $branch_count_query, {}, @bind_params );
517
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $branch_count_query, {}, @bind_params );
515
        my $max_checkouts_allowed = $branch_borrower_circ_rule->{maxissueqty};
518
        my $max_checkouts_allowed = $branch_borrower_circ_rule->{maxissueqty};
Lines 1597-1602 sub GetBranchBorrowerCircRule { Link Here
1597
    my $rules;
1600
    my $rules;
1598
    my $dbh = C4::Context->dbh();
1601
    my $dbh = C4::Context->dbh();
1599
    $rules = $dbh->selectrow_hashref( q|
1602
    $rules = $dbh->selectrow_hashref( q|
1603
        SELECT maxissueqty, maxonsiteissueqty, has_priority
1604
        FROM default_borrower_circ_rules
1605
        WHERE categorycode = ? AND has_priority = 1
1606
    |, {}, $categorycode ) ;
1607
    return $rules if $rules;
1608
1609
    $rules = $dbh->selectrow_hashref( q|
1600
        SELECT maxissueqty, maxonsiteissueqty
1610
        SELECT maxissueqty, maxonsiteissueqty
1601
        FROM branch_borrower_circ_rules
1611
        FROM branch_borrower_circ_rules
1602
        WHERE branchcode = ?
1612
        WHERE branchcode = ?
(-)a/admin/smart-rules.pl (-6 / +10 lines)
Lines 254-263 elsif ($op eq "add-branch-cat") { Link Here
254
    my $categorycode  = $input->param('categorycode');
254
    my $categorycode  = $input->param('categorycode');
255
    my $maxissueqty   = $input->param('maxissueqty');
255
    my $maxissueqty   = $input->param('maxissueqty');
256
    my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
256
    my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
257
    my $has_priority = $input->param('has_priority');
257
    $maxissueqty =~ s/\s//g;
258
    $maxissueqty =~ s/\s//g;
258
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
259
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
259
    $maxonsiteissueqty =~ s/\s//g;
260
    $maxonsiteissueqty =~ s/\s//g;
260
    $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
261
    $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
262
    $has_priority = $has_priority ? 1 : 0;
261
263
262
    if ($branch eq "*") {
264
    if ($branch eq "*") {
263
        if ($categorycode eq "*") {
265
        if ($categorycode eq "*") {
Lines 284-307 elsif ($op eq "add-branch-cat") { Link Here
284
        } else {
286
        } else {
285
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
287
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
286
                                            FROM default_borrower_circ_rules
288
                                            FROM default_borrower_circ_rules
287
                                            WHERE categorycode = ?");
289
                                            WHERE categorycode = ?
290
                                            AND has_priority = ?");
288
            my $sth_insert = $dbh->prepare(q|
291
            my $sth_insert = $dbh->prepare(q|
289
                INSERT INTO default_borrower_circ_rules
292
                INSERT INTO default_borrower_circ_rules
290
                    (categorycode, maxissueqty, maxonsiteissueqty)
293
                    (categorycode, maxissueqty, maxonsiteissueqty, has_priority)
291
                    VALUES (?, ?, ?)
294
                    VALUES (?, ?, ?, ?)
292
            |);
295
            |);
293
            my $sth_update = $dbh->prepare(q|
296
            my $sth_update = $dbh->prepare(q|
294
                UPDATE default_borrower_circ_rules
297
                UPDATE default_borrower_circ_rules
295
                SET maxissueqty = ?,
298
                SET maxissueqty = ?,
296
                    maxonsiteissueqty = ?
299
                    maxonsiteissueqty = ?
297
                WHERE categorycode = ?
300
                WHERE categorycode = ?
301
                AND has_priority = ?
298
            |);
302
            |);
299
            $sth_search->execute($categorycode);
303
            $sth_search->execute($categorycode, $has_priority);
300
            my $res = $sth_search->fetchrow_hashref();
304
            my $res = $sth_search->fetchrow_hashref();
301
            if ($res->{total}) {
305
            if ($res->{total}) {
302
                $sth_update->execute($maxissueqty, $maxonsiteissueqty, $categorycode);
306
                $sth_update->execute($maxissueqty, $maxonsiteissueqty, $categorycode, $has_priority) or die $sth_update->errstr;;
303
            } else {
307
            } else {
304
                $sth_insert->execute($categorycode, $maxissueqty, $maxonsiteissueqty);
308
                $sth_insert->execute($categorycode, $maxissueqty, $maxonsiteissueqty, $has_priority);
305
            }
309
            }
306
        }
310
        }
307
    } elsif ($categorycode eq "*") {
311
    } 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 456-461 Link Here
456
        <p>If the total amount loanable for a given patron category is left blank,
456
        <p>If the total amount loanable for a given patron category is left blank,
457
           no limit applies, except possibly for a limit you define for a specific item type.
457
           no limit applies, except possibly for a limit you define for a specific item type.
458
        </p>
458
        </p>
459
        <p>
460
            <b>Has priority: </b>If checked, the rule will override those for all branches. Else
461
            it behaves like a default one: used if no rule existe for the coresponding branch.
462
        </p>
459
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
463
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
460
            <input type="hidden" name="op" value="add-branch-cat" />
464
            <input type="hidden" name="op" value="add-branch-cat" />
461
            <input type="hidden" name="branch" value="[% current_branch %]"/>
465
            <input type="hidden" name="branch" value="[% current_branch %]"/>
Lines 464-469 Link Here
464
                    <th>Patron category</th>
468
                    <th>Patron category</th>
465
                    <th>Total current checkouts allowed</th>
469
                    <th>Total current checkouts allowed</th>
466
                    <th>Total current on-site checkouts allowed</th>
470
                    <th>Total current on-site checkouts allowed</th>
471
                    [% UNLESS humanbranch %]<th>Has priority</th>[% END %]
467
                    <th>&nbsp;</th>
472
                    <th>&nbsp;</th>
468
                </tr>
473
                </tr>
469
                [% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %]
474
                [% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %]
Lines 490-495 Link Here
490
                                [% branch_cat_rule_loo.maxonsiteissueqty %]
495
                                [% branch_cat_rule_loo.maxonsiteissueqty %]
491
                            [% END %]
496
                            [% END %]
492
                        </td>
497
                        </td>
498
                        [% UNLESS humanbranch %]
499
                            <td>
500
                                <input type="checkbox" [% IF branch_cat_rule_loo.has_priority %]checked[% END %] disabled/>
501
                            </td>
502
                        [% END %]
493
503
494
                        <td class="actions">
504
                        <td class="actions">
495
                            <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>
505
                            <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 506-511 Link Here
506
                    </td>
516
                    </td>
507
                    <td><input name="maxissueqty" size="3" /></td>
517
                    <td><input name="maxissueqty" size="3" /></td>
508
                    <td><input name="maxonsiteissueqty" size="3" /></td>
518
                    <td><input name="maxonsiteissueqty" size="3" /></td>
519
                    [% UNLESS humanbranch %]
520
                        <td>
521
                            <input type="checkbox" name="has_priority"/>
522
                        </td>
523
                    [% END %]
509
                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td>
524
                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td>
510
                </tr>
525
                </tr>
511
            </table>
526
            </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