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

(-)a/C4/Circulation.pm (-3 / +3 lines)
Lines 405-411 sub TooMany { Link Here
405
    # if a rule is found and has a loan limit set, count
405
    # if a rule is found and has a loan limit set, count
406
    # how many loans the patron already has that meet that
406
    # how many loans the patron already has that meet that
407
    # rule
407
    # rule
408
    if (defined($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) {
408
    if (defined($maxissueqty_rule) and $maxissueqty_rule->rule_value ne '') {
409
        my @bind_params;
409
        my @bind_params;
410
        my $count_query = q|
410
        my $count_query = q|
411
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
411
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
Lines 471-477 sub TooMany { Link Here
471
        my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : 0;
471
        my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : 0;
472
        my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : 0;
472
        my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : 0;
473
473
474
        if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
474
        if ( $onsite_checkout and $max_onsite_checkouts_allowed ne '' ) {
475
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
475
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
476
                return {
476
                return {
477
                    reason => 'TOO_MANY_ONSITE_CHECKOUTS',
477
                    reason => 'TOO_MANY_ONSITE_CHECKOUTS',
Lines 2279-2285 sub _debar_user_on_return { Link Here
2279
            # If the max suspension days is < than the suspension days
2279
            # If the max suspension days is < than the suspension days
2280
            # the suspension days is limited to this maximum period.
2280
            # the suspension days is limited to this maximum period.
2281
            my $max_sd = $issuing_rule->{maxsuspensiondays};
2281
            my $max_sd = $issuing_rule->{maxsuspensiondays};
2282
            if ( defined $max_sd ) {
2282
            if ( defined $max_sd && $max_sd ne '' ) {
2283
                $max_sd = DateTime::Duration->new( days => $max_sd );
2283
                $max_sd = DateTime::Duration->new( days => $max_sd );
2284
                $suspension_days = $max_sd
2284
                $suspension_days = $max_sd
2285
                  if DateTime::Duration->compare( $max_sd, $suspension_days ) < 0;
2285
                  if DateTime::Duration->compare( $max_sd, $suspension_days ) < 0;
(-)a/admin/smart-rules.pl (-9 / +9 lines)
Lines 238-244 elsif ($op eq 'add') { Link Here
238
    my $fine = $input->param('fine');
238
    my $fine = $input->param('fine');
239
    my $finedays     = $input->param('finedays');
239
    my $finedays     = $input->param('finedays');
240
    my $maxsuspensiondays = $input->param('maxsuspensiondays');
240
    my $maxsuspensiondays = $input->param('maxsuspensiondays');
241
    $maxsuspensiondays = undef if $maxsuspensiondays eq q||;
241
    $maxsuspensiondays = '' if $maxsuspensiondays eq q||;
242
    my $firstremind  = $input->param('firstremind');
242
    my $firstremind  = $input->param('firstremind');
243
    my $chargeperiod = $input->param('chargeperiod');
243
    my $chargeperiod = $input->param('chargeperiod');
244
    my $chargeperiod_charge_at = $input->param('chargeperiod_charge_at');
244
    my $chargeperiod_charge_at = $input->param('chargeperiod_charge_at');
Lines 247-266 elsif ($op eq 'add') { Link Here
247
    my $renewalsallowed  = $input->param('renewalsallowed');
247
    my $renewalsallowed  = $input->param('renewalsallowed');
248
    my $renewalperiod    = $input->param('renewalperiod');
248
    my $renewalperiod    = $input->param('renewalperiod');
249
    my $norenewalbefore  = $input->param('norenewalbefore');
249
    my $norenewalbefore  = $input->param('norenewalbefore');
250
    $norenewalbefore = undef if $norenewalbefore =~ /^\s*$/;
250
    $norenewalbefore = '' if $norenewalbefore =~ /^\s*$/;
251
    my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0;
251
    my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0;
252
    my $no_auto_renewal_after = $input->param('no_auto_renewal_after');
252
    my $no_auto_renewal_after = $input->param('no_auto_renewal_after');
253
    $no_auto_renewal_after = undef if $no_auto_renewal_after =~ /^\s*$/;
253
    $no_auto_renewal_after = '' if $no_auto_renewal_after =~ /^\s*$/;
254
    my $no_auto_renewal_after_hard_limit = $input->param('no_auto_renewal_after_hard_limit') || undef;
254
    my $no_auto_renewal_after_hard_limit = $input->param('no_auto_renewal_after_hard_limit') || '';
255
    $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 );
255
    $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 );
256
    $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 );
256
    $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 );
257
    my $reservesallowed  = $input->param('reservesallowed');
257
    my $reservesallowed  = $input->param('reservesallowed');
258
    my $holds_per_record  = $input->param('holds_per_record');
258
    my $holds_per_record  = $input->param('holds_per_record');
259
    my $onshelfholds     = $input->param('onshelfholds') || 0;
259
    my $onshelfholds     = $input->param('onshelfholds') || 0;
260
    $maxissueqty =~ s/\s//g;
260
    $maxissueqty =~ s/\s//g;
261
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
261
    $maxissueqty = '' if $maxissueqty !~ /^\d+/;
262
    $maxonsiteissueqty =~ s/\s//g;
262
    $maxonsiteissueqty =~ s/\s//g;
263
    $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
263
    $maxonsiteissueqty = '' if $maxonsiteissueqty !~ /^\d+/;
264
    my $issuelength  = $input->param('issuelength');
264
    my $issuelength  = $input->param('issuelength');
265
    $issuelength = $issuelength eq q{} ? undef : $issuelength;
265
    $issuelength = $issuelength eq q{} ? undef : $issuelength;
266
    my $lengthunit  = $input->param('lengthunit');
266
    my $lengthunit  = $input->param('lengthunit');
Lines 271-277 elsif ($op eq 'add') { Link Here
271
    my $rentaldiscount = $input->param('rentaldiscount');
271
    my $rentaldiscount = $input->param('rentaldiscount');
272
    my $opacitemholds = $input->param('opacitemholds') || 0;
272
    my $opacitemholds = $input->param('opacitemholds') || 0;
273
    my $article_requests = $input->param('article_requests') || 'no';
273
    my $article_requests = $input->param('article_requests') || 'no';
274
    my $overduefinescap = $input->param('overduefinescap') || undef;
274
    my $overduefinescap = $input->param('overduefinescap') || '';
275
    my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on';
275
    my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on';
276
    warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
276
    warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
277
277
Lines 300-305 elsif ($op eq 'add') { Link Here
300
        overduefinescap               => $overduefinescap,
300
        overduefinescap               => $overduefinescap,
301
        cap_fine_to_replacement_price => $cap_fine_to_replacement_price,
301
        cap_fine_to_replacement_price => $cap_fine_to_replacement_price,
302
        article_requests              => $article_requests,
302
        article_requests              => $article_requests,
303
        maxissueqty                   => $maxissueqty,
304
        maxonsiteissueqty             => $maxonsiteissueqty,
303
    };
305
    };
304
306
305
    Koha::CirculationRules->set_rules(
307
    Koha::CirculationRules->set_rules(
Lines 308-315 elsif ($op eq 'add') { Link Here
308
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
310
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
309
            branchcode   => $br eq '*' ? undef : $br,
311
            branchcode   => $br eq '*' ? undef : $br,
310
            rules        => {
312
            rules        => {
311
                maxissueqty       => $maxissueqty,
312
                maxonsiteissueqty => $maxonsiteissueqty,
313
                %$params,
313
                %$params,
314
            }
314
            }
315
        }
315
        }
(-)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 169-182 Link Here
169
                                      <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>
169
                                      <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>
170
                                    </td>
170
                                    </td>
171
                                    <td>
171
                                    <td>
172
                                        [% IF maxissueqty  %]
172
                                        [% IF maxissueqty.defined && maxissueqty != '' %]
173
                                            [% maxissueqty %]
173
                                            [% maxissueqty %]
174
                                        [% ELSE %]
174
                                        [% ELSE %]
175
                                            Unlimited
175
                                            Unlimited
176
                                        [% END %]
176
                                        [% END %]
177
                                    </td>
177
                                    </td>
178
                                    <td>
178
                                    <td>
179
                                        [% IF maxonsiteissueqty  %]
179
                                        [% IF maxonsiteissueqty.defined && maxonsiteissueqty != ''  %]
180
                                            [% maxonsiteissueqty %]
180
                                            [% maxonsiteissueqty %]
181
                                        [% ELSE %]
181
                                        [% ELSE %]
182
                                            Unlimited
182
                                            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 (-10 / +42 lines)
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