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

(-)a/C4/Circulation.pm (-3 / +3 lines)
Lines 418-424 sub TooMany { Link Here
418
    # if a rule is found and has a loan limit set, count
418
    # if a rule is found and has a loan limit set, count
419
    # how many loans the patron already has that meet that
419
    # how many loans the patron already has that meet that
420
    # rule
420
    # rule
421
    if (defined($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) {
421
    if (defined($maxissueqty_rule) and $maxissueqty_rule->rule_value ne '') {
422
        my @bind_params;
422
        my @bind_params;
423
        my $count_query = q|
423
        my $count_query = q|
424
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
424
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
Lines 484-490 sub TooMany { Link Here
484
        my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : 0;
484
        my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : 0;
485
        my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : 0;
485
        my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : 0;
486
486
487
        if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
487
        if ( $onsite_checkout and $max_onsite_checkouts_allowed ne '' ) {
488
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
488
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
489
                return {
489
                return {
490
                    reason => 'TOO_MANY_ONSITE_CHECKOUTS',
490
                    reason => 'TOO_MANY_ONSITE_CHECKOUTS',
Lines 2314-2320 sub _debar_user_on_return { Link Here
2314
            # If the max suspension days is < than the suspension days
2314
            # If the max suspension days is < than the suspension days
2315
            # the suspension days is limited to this maximum period.
2315
            # the suspension days is limited to this maximum period.
2316
            my $max_sd = $issuing_rule->{maxsuspensiondays};
2316
            my $max_sd = $issuing_rule->{maxsuspensiondays};
2317
            if ( defined $max_sd ) {
2317
            if ( defined $max_sd && $max_sd ne '' ) {
2318
                $max_sd = DateTime::Duration->new( days => $max_sd );
2318
                $max_sd = DateTime::Duration->new( days => $max_sd );
2319
                $suspension_days = $max_sd
2319
                $suspension_days = $max_sd
2320
                  if DateTime::Duration->compare( $max_sd, $suspension_days ) < 0;
2320
                  if DateTime::Duration->compare( $max_sd, $suspension_days ) < 0;
(-)a/admin/smart-rules.pl (-9 / +9 lines)
Lines 246-252 elsif ($op eq 'add') { Link Here
246
    my $fine = $input->param('fine');
246
    my $fine = $input->param('fine');
247
    my $finedays     = $input->param('finedays');
247
    my $finedays     = $input->param('finedays');
248
    my $maxsuspensiondays = $input->param('maxsuspensiondays');
248
    my $maxsuspensiondays = $input->param('maxsuspensiondays');
249
    $maxsuspensiondays = undef if $maxsuspensiondays eq q||;
249
    $maxsuspensiondays = '' if $maxsuspensiondays eq q||;
250
    my $firstremind  = $input->param('firstremind');
250
    my $firstremind  = $input->param('firstremind');
251
    my $chargeperiod = $input->param('chargeperiod');
251
    my $chargeperiod = $input->param('chargeperiod');
252
    my $chargeperiod_charge_at = $input->param('chargeperiod_charge_at');
252
    my $chargeperiod_charge_at = $input->param('chargeperiod_charge_at');
Lines 255-274 elsif ($op eq 'add') { Link Here
255
    my $renewalsallowed  = $input->param('renewalsallowed');
255
    my $renewalsallowed  = $input->param('renewalsallowed');
256
    my $renewalperiod    = $input->param('renewalperiod');
256
    my $renewalperiod    = $input->param('renewalperiod');
257
    my $norenewalbefore  = $input->param('norenewalbefore');
257
    my $norenewalbefore  = $input->param('norenewalbefore');
258
    $norenewalbefore = undef if $norenewalbefore =~ /^\s*$/;
258
    $norenewalbefore = '' if $norenewalbefore =~ /^\s*$/;
259
    my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0;
259
    my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0;
260
    my $no_auto_renewal_after = $input->param('no_auto_renewal_after');
260
    my $no_auto_renewal_after = $input->param('no_auto_renewal_after');
261
    $no_auto_renewal_after = undef if $no_auto_renewal_after =~ /^\s*$/;
261
    $no_auto_renewal_after = '' if $no_auto_renewal_after =~ /^\s*$/;
262
    my $no_auto_renewal_after_hard_limit = $input->param('no_auto_renewal_after_hard_limit') || undef;
262
    my $no_auto_renewal_after_hard_limit = $input->param('no_auto_renewal_after_hard_limit') || '';
263
    $no_auto_renewal_after_hard_limit = eval { dt_from_string( $input->param('no_auto_renewal_after_hard_limit') ) } if ( $no_auto_renewal_after_hard_limit );
263
    $no_auto_renewal_after_hard_limit = eval { dt_from_string( $input->param('no_auto_renewal_after_hard_limit') ) } if ( $no_auto_renewal_after_hard_limit );
264
    $no_auto_renewal_after_hard_limit = output_pref( { dt => $no_auto_renewal_after_hard_limit, dateonly => 1, dateformat => 'iso' } ) if ( $no_auto_renewal_after_hard_limit );
264
    $no_auto_renewal_after_hard_limit = output_pref( { dt => $no_auto_renewal_after_hard_limit, dateonly => 1, dateformat => 'iso' } ) if ( $no_auto_renewal_after_hard_limit );
265
    my $reservesallowed  = $input->param('reservesallowed');
265
    my $reservesallowed  = $input->param('reservesallowed');
266
    my $holds_per_record  = $input->param('holds_per_record');
266
    my $holds_per_record  = $input->param('holds_per_record');
267
    my $onshelfholds     = $input->param('onshelfholds') || 0;
267
    my $onshelfholds     = $input->param('onshelfholds') || 0;
268
    $maxissueqty =~ s/\s//g;
268
    $maxissueqty =~ s/\s//g;
269
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
269
    $maxissueqty = '' if $maxissueqty !~ /^\d+/;
270
    $maxonsiteissueqty =~ s/\s//g;
270
    $maxonsiteissueqty =~ s/\s//g;
271
    $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
271
    $maxonsiteissueqty = '' if $maxonsiteissueqty !~ /^\d+/;
272
    my $issuelength  = $input->param('issuelength');
272
    my $issuelength  = $input->param('issuelength');
273
    $issuelength = $issuelength eq q{} ? undef : $issuelength;
273
    $issuelength = $issuelength eq q{} ? undef : $issuelength;
274
    my $lengthunit  = $input->param('lengthunit');
274
    my $lengthunit  = $input->param('lengthunit');
Lines 279-285 elsif ($op eq 'add') { Link Here
279
    my $rentaldiscount = $input->param('rentaldiscount');
279
    my $rentaldiscount = $input->param('rentaldiscount');
280
    my $opacitemholds = $input->param('opacitemholds') || 0;
280
    my $opacitemholds = $input->param('opacitemholds') || 0;
281
    my $article_requests = $input->param('article_requests') || 'no';
281
    my $article_requests = $input->param('article_requests') || 'no';
282
    my $overduefinescap = $input->param('overduefinescap') || undef;
282
    my $overduefinescap = $input->param('overduefinescap') || '';
283
    my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on';
283
    my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on';
284
    warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
284
    warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
285
285
Lines 308-313 elsif ($op eq 'add') { Link Here
308
        overduefinescap               => $overduefinescap,
308
        overduefinescap               => $overduefinescap,
309
        cap_fine_to_replacement_price => $cap_fine_to_replacement_price,
309
        cap_fine_to_replacement_price => $cap_fine_to_replacement_price,
310
        article_requests              => $article_requests,
310
        article_requests              => $article_requests,
311
        maxissueqty                   => $maxissueqty,
312
        maxonsiteissueqty             => $maxonsiteissueqty,
311
    };
313
    };
312
314
313
    Koha::CirculationRules->set_rules(
315
    Koha::CirculationRules->set_rules(
Lines 316-323 elsif ($op eq 'add') { Link Here
316
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
318
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
317
            branchcode   => $br eq '*' ? undef : $br,
319
            branchcode   => $br eq '*' ? undef : $br,
318
            rules        => {
320
            rules        => {
319
                maxissueqty       => $maxissueqty,
320
                maxonsiteissueqty => $maxonsiteissueqty,
321
                %$params,
321
                %$params,
322
            }
322
            }
323
        }
323
        }
(-)a/installer/data/mysql/atomicupdate/bug_18936.perl (-1 / +3 lines)
Lines 27-39 if( CheckVersion( $DBversion ) ) { Link Here
27
        onshelfholds
27
        onshelfholds
28
        opacitemholds
28
        opacitemholds
29
        article_requests
29
        article_requests
30
        maxissueqty
31
        maxonsiteissueqty
30
    );
32
    );
31
33
32
    if ( column_exists( 'issuingrules', 'categorycode' ) ) {
34
    if ( column_exists( 'issuingrules', 'categorycode' ) ) {
33
        foreach my $column ( @columns ) {
35
        foreach my $column ( @columns ) {
34
            $dbh->do("
36
            $dbh->do("
35
                INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
37
                INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
36
                SELECT categorycode, branchcode, itemtype, \'$column\', $column
38
                SELECT categorycode, branchcode, itemtype, \'$column\', COALESCE( $column, '' )
37
                FROM issuingrules
39
                FROM issuingrules
38
            ");
40
            ");
39
        }
41
        }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-2 / +2 lines)
Lines 171-184 Link Here
171
                                      <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype || '*' %]&amp;categorycode=[% rule.categorycode || '*' %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
171
                                      <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype || '*' %]&amp;categorycode=[% rule.categorycode || '*' %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
172
                                    </td>
172
                                    </td>
173
                                    <td>
173
                                    <td>
174
                                        [% IF maxissueqty  %]
174
                                        [% IF maxissueqty.defined && maxissueqty != '' %]
175
                                            [% maxissueqty %]
175
                                            [% maxissueqty %]
176
                                        [% ELSE %]
176
                                        [% ELSE %]
177
                                            Unlimited
177
                                            Unlimited
178
                                        [% END %]
178
                                        [% END %]
179
                                    </td>
179
                                    </td>
180
                                    <td>
180
                                    <td>
181
                                        [% IF maxonsiteissueqty  %]
181
                                        [% IF maxonsiteissueqty.defined && maxonsiteissueqty != ''  %]
182
                                            [% maxonsiteissueqty %]
182
                                            [% maxonsiteissueqty %]
183
                                        [% ELSE %]
183
                                        [% ELSE %]
184
                                            Unlimited
184
                                            Unlimited
(-)a/t/db_dependent/Circulation.t (-21 / +29 lines)
Lines 817-823 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
817
            }
817
            }
818
        });
818
        });
819
819
820
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 11');
820
        Koha::CirculationRules->set_rules(
821
            {
822
                categorycode => undef,
823
                branchcode   => undef,
824
                itemtype     => undef,
825
                rules        => {
826
                    norenewalbefore       => 10,
827
                    no_auto_renewal_after => 11,
828
                }
829
            }
830
        );
821
831
822
        my $ten_days_before = dt_from_string->add( days => -10 );
832
        my $ten_days_before = dt_from_string->add( days => -10 );
823
        my $ten_days_ahead = dt_from_string->add( days => 10 );
833
        my $ten_days_ahead = dt_from_string->add( days => 10 );
Lines 2221-2246 subtest 'CanBookBeIssued | is_overdue' => sub { Link Here
2221
    plan tests => 3;
2231
    plan tests => 3;
2222
2232
2223
    # Set a simple circ policy
2233
    # Set a simple circ policy
2224
    $dbh->do('DELETE FROM issuingrules');
2234
    Koha::CirculationRules->set_rules(
2225
    $dbh->do(
2235
        {
2226
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed,
2236
            categorycode => undef,
2227
                                    maxissueqty, issuelength, lengthunit,
2237
            branchcode   => undef,
2228
                                    renewalsallowed, renewalperiod,
2238
            itemtype     => undef,
2229
                                    norenewalbefore, auto_renew,
2239
            rules        => {
2230
                                    fine, chargeperiod)
2240
                reservesallowed => 25,
2231
          VALUES (?, ?, ?, ?,
2241
                maxissueqty     => 1,
2232
                  ?, ?, ?,
2242
                issuelength     => 14,
2233
                  ?, ?,
2243
                lengthunit      => 'days',
2234
                  ?, ?,
2244
                renewalsallowed => 1,
2235
                  ?, ?
2245
                renewalperiod   => 7,
2236
                 )
2246
                norenewalbefore => undef,
2237
        },
2247
                auto_renew      => 0,
2238
        {},
2248
                fine            => .10,
2239
        '*',   '*', '*', 25,
2249
                chargeperiod    => 1,
2240
        1,     14,  'days',
2250
            }
2241
        1,     7,
2251
        }
2242
        undef, 0,
2243
        .10,   1
2244
    );
2252
    );
2245
2253
2246
    my $five_days_go = output_pref({ dt => dt_from_string->add( days => 5 ), dateonly => 1});
2254
    my $five_days_go = output_pref({ dt => dt_from_string->add( days => 5 ), dateonly => 1});
(-)a/t/db_dependent/Circulation/TooMany.t (-10 / +11 lines)
Lines 158-173 subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { Link Here
158
158
159
subtest '1 Issuingrule exist with onsiteissueqty=unlimited' => sub {
159
subtest '1 Issuingrule exist with onsiteissueqty=unlimited' => sub {
160
    plan tests => 4;
160
    plan tests => 4;
161
    my $issuingrule = $builder->build({
161
    Koha::CirculationRules->set_rules(
162
        source => 'Issuingrule',
162
        {
163
        value => {
163
            branchcode   => $branch->{branchcode},
164
            branchcode         => $branch->{branchcode},
164
            categorycode => $category->{categorycode},
165
            categorycode       => $category->{categorycode},
165
            itemtype     => undef,
166
            itemtype           => '*',
166
            rules        => {
167
            maxissueqty        => 1,
167
                maxissueqty        => 1,
168
            maxonsiteissueqty  => undef,
168
                maxonsiteissueqty  => '',
169
        },
169
            }
170
    });
170
        }
171
    );
171
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string() );
172
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string() );
172
    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
173
    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
173
    is_deeply(
174
    is_deeply(
(-)a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t (-11 / +43 lines)
Lines 7-13 use C4::Items; Link Here
7
use C4::Circulation;
7
use C4::Circulation;
8
use Koha::CirculationRules;
8
use Koha::CirculationRules;
9
9
10
use Test::More tests => 4;
10
use Test::More tests => 5;
11
11
12
use t::lib::TestBuilder;
12
use t::lib::TestBuilder;
13
use t::lib::Mocks;
13
use t::lib::Mocks;
Lines 128-135 AddReturn( $item1->{barcode} ); Link Here
128
128
129
        my $hold_allowed_from_home_library = 1;
129
        my $hold_allowed_from_home_library = 1;
130
        my $hold_allowed_from_any_libraries = 2;
130
        my $hold_allowed_from_any_libraries = 2;
131
        my $sth_delete_rules = $dbh->prepare(q|DELETE FROM default_circ_rules|);
131
        Koha::CirculationRules->set_rules(
132
        my $sth_insert_rule = $dbh->prepare(q|INSERT INTO default_circ_rules(singleton, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch) VALUES ('singleton', NULL, NULL, ?, 'any', 'homebranch');|);
132
            {
133
                branchcode   => undef,
134
                itemtype     => undef,
135
                rules        => {
136
                    hold_fulfillment_policy => 'any',
137
                    returnbranch            => 'homebranch',
138
                }
139
            }
140
        );
133
141
134
        subtest 'Item is available at a different library' => sub {
142
        subtest 'Item is available at a different library' => sub {
135
            plan tests => 4;
143
            plan tests => 4;
Lines 145-152 AddReturn( $item1->{barcode} ); Link Here
145
            #FIXME: ReservesControlBranch is not checked in these subs we are testing
153
            #FIXME: ReservesControlBranch is not checked in these subs we are testing
146
154
147
            {
155
            {
148
                $sth_delete_rules->execute;
156
                Koha::CirculationRules->set_rule(
149
                $sth_insert_rule->execute( $hold_allowed_from_home_library );
157
                    {
158
                        branchcode   => undef,
159
                        itemtype     => undef,
160
                        rule_name    => 'holdallowed',
161
                        rule_value   => $hold_allowed_from_home_library,
162
                    }
163
                );
150
164
151
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
165
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
152
                $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
166
                $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
Lines 158-165 AddReturn( $item1->{barcode} ); Link Here
158
            }
172
            }
159
173
160
            {
174
            {
161
                $sth_delete_rules->execute;
175
                Koha::CirculationRules->set_rule(
162
                $sth_insert_rule->execute( $hold_allowed_from_any_libraries );
176
                    {
177
                        branchcode   => undef,
178
                        itemtype     => undef,
179
                        rule_name    => 'holdallowed',
180
                        rule_value   => $hold_allowed_from_any_libraries,
181
                    }
182
                );
163
183
164
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
184
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
165
                $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
185
                $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
Lines 185-192 AddReturn( $item1->{barcode} ); Link Here
185
            #ReservesControlBranch is not checked in these subs we are testing?
205
            #ReservesControlBranch is not checked in these subs we are testing?
186
206
187
            {
207
            {
188
                $sth_delete_rules->execute;
208
                Koha::CirculationRules->set_rule(
189
                $sth_insert_rule->execute( $hold_allowed_from_home_library );
209
                    {
210
                        branchcode   => undef,
211
                        itemtype     => undef,
212
                        rule_name    => 'holdallowed',
213
                        rule_value   => $hold_allowed_from_home_library,
214
                    }
215
                );
190
216
191
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
217
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
192
                $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
218
                $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
Lines 198-205 AddReturn( $item1->{barcode} ); Link Here
198
            }
224
            }
199
225
200
            {
226
            {
201
                $sth_delete_rules->execute;
227
                Koha::CirculationRules->set_rule(
202
                $sth_insert_rule->execute( $hold_allowed_from_any_libraries );
228
                    {
229
                        branchcode   => undef,
230
                        itemtype     => undef,
231
                        rule_name    => 'holdallowed',
232
                        rule_value   => $hold_allowed_from_any_libraries,
233
                    }
234
                );
203
235
204
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
236
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
205
                $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
237
                $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
(-)a/t/db_dependent/TestBuilder.t (-3 lines)
Lines 34-41 our $schema = Koha::Database->new->schema; Link Here
34
$schema->storage->txn_begin;
34
$schema->storage->txn_begin;
35
our $builder;
35
our $builder;
36
36
37
$schema->resultset('DefaultCircRule')->delete; # Is a singleton table
38
39
subtest 'Start with some trivial tests' => sub {
37
subtest 'Start with some trivial tests' => sub {
40
    plan tests => 7;
38
    plan tests => 7;
41
39
42
- 

Return to bug 18936