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

(-)a/C4/Circulation.pm (-3 / +19 lines)
Lines 1307-1321 sub checkHighHolds { Link Here
1307
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1307
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1308
1308
1309
        my $decreaseLoanHighHoldsDuration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1309
        my $decreaseLoanHighHoldsDuration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1310
1310
        my $rule = Koha::CirculationRules->get_effective_rule(
1311
        my $reduced_datedue = $calendar->addDate( $issuedate, $decreaseLoanHighHoldsDuration );
1311
            {
1312
                categorycode => $borrower->{categorycode},
1313
                itemtype     => $item_object->effective_itemtype,
1314
                branchcode   => $branchcode,
1315
                rule_name    => 'decreaseloanholds',
1316
            }
1317
        );
1318
        my $reduced_datedue;
1319
        my $duration;
1320
        if ( defined($rule) && $rule->rule_value ne '' ){
1321
            # overrides decreaseLoanHighHoldsDuration syspref
1322
            $duration = $rule->rule_value;
1323
            $reduced_datedue = $calendar->addDate( $issuedate, $rule->rule_value );
1324
        } else {
1325
            $duration = $decreaseLoanHighHoldsDuration;
1326
            $reduced_datedue = $calendar->addDate( $issuedate, $decreaseLoanHighHoldsDuration );
1327
        }
1312
        $reduced_datedue->set_hour($orig_due->hour);
1328
        $reduced_datedue->set_hour($orig_due->hour);
1313
        $reduced_datedue->set_minute($orig_due->minute);
1329
        $reduced_datedue->set_minute($orig_due->minute);
1314
        $reduced_datedue->truncate( to => 'minute' );
1330
        $reduced_datedue->truncate( to => 'minute' );
1315
1331
1316
        if ( DateTime->compare( $reduced_datedue, $orig_due ) == -1 ) {
1332
        if ( DateTime->compare( $reduced_datedue, $orig_due ) == -1 ) {
1317
            $return_data->{exceeded} = 1;
1333
            $return_data->{exceeded} = 1;
1318
            $return_data->{duration} = $decreaseLoanHighHoldsDuration;
1334
            $return_data->{duration} = $duration;
1319
            $return_data->{due_date} = $reduced_datedue;
1335
            $return_data->{due_date} = $reduced_datedue;
1320
        }
1336
        }
1321
    }
1337
    }
(-)a/Koha/CirculationRules.pm (+3 lines)
Lines 160-165 our $RULE_KINDS = { Link Here
160
    note => { # This is not really a rule. Maybe we will want to separate this later.
160
    note => { # This is not really a rule. Maybe we will want to separate this later.
161
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
161
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
162
    },
162
    },
163
    decreaseloanholds => {
164
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
165
    },
163
    # Not included (deprecated?):
166
    # Not included (deprecated?):
164
    #   * accountsent
167
    #   * accountsent
165
    #   * reservecharge
168
    #   * reservecharge
(-)a/admin/smart-rules.pl (+2 lines)
Lines 287-292 elsif ($op eq 'add') { Link Here
287
    my $overduefinescap = $input->param('overduefinescap') || '';
287
    my $overduefinescap = $input->param('overduefinescap') || '';
288
    my $cap_fine_to_replacement_price = ($input->param('cap_fine_to_replacement_price') || '') eq 'on';
288
    my $cap_fine_to_replacement_price = ($input->param('cap_fine_to_replacement_price') || '') eq 'on';
289
    my $note = $input->param('note');
289
    my $note = $input->param('note');
290
    my $decreaseloanholds = $input->param('decreaseloanholds') || undef;
290
    $debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
291
    $debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
291
292
292
    my $rules = {
293
    my $rules = {
Lines 320-325 elsif ($op eq 'add') { Link Here
320
        cap_fine_to_replacement_price => $cap_fine_to_replacement_price,
321
        cap_fine_to_replacement_price => $cap_fine_to_replacement_price,
321
        article_requests              => $article_requests,
322
        article_requests              => $article_requests,
322
        note                          => $note,
323
        note                          => $note,
324
        decreaseloanholds             => $decreaseloanholds,
323
    };
325
    };
324
326
325
    Koha::CirculationRules->set_rules(
327
    Koha::CirculationRules->set_rules(
(-)a/installer/data/mysql/atomicupdate/bug_14866-add_decreaseloanholds_circrule.perl (+6 lines)
Line 0 Link Here
1
$DBversion = 'XXX';
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do(q{INSERT IGNORE INTO circulation_rules (branchcode, categorycode, itemtype, rule_name, rule_value) VALUES (NULL, NULL, NULL, 'decreaseloanholds', NULL) });
4
5
    NewVersion( $DBversion, 14866, "Add decreaseloanholds circulation rule" );
6
}
(-)a/installer/onboarding.pl (+1 lines)
Lines 287-292 if ( $step == 5 ) { Link Here
287
                rentaldiscount                   => 0,
287
                rentaldiscount                   => 0,
288
                reservesallowed                  => $reservesallowed,
288
                reservesallowed                  => $reservesallowed,
289
                suspension_chargeperiod          => undef,
289
                suspension_chargeperiod          => undef,
290
                decreaseloanholds                => undef,
290
              }
291
              }
291
        };
292
        };
292
293
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-1 / +6 lines)
Lines 102-107 Link Here
102
                <th>Days mode</th>
102
                <th>Days mode</th>
103
                <th>Unit</th>
103
                <th>Unit</th>
104
                <th>Hard due date</th>
104
                <th>Hard due date</th>
105
                <th>Decreased loan period for high holds (day)</th>
105
                <th>Fine amount</th>
106
                <th>Fine amount</th>
106
                <th>Fine charging interval</th>
107
                <th>Fine charging interval</th>
107
                <th>When to charge</th>
108
                <th>When to charge</th>
Lines 163-170 Link Here
163
                        [% SET opacitemholds = all_rules.$c.$i.opacitemholds %]
164
                        [% SET opacitemholds = all_rules.$c.$i.opacitemholds %]
164
                        [% SET article_requests = all_rules.$c.$i.article_requests %]
165
                        [% SET article_requests = all_rules.$c.$i.article_requests %]
165
                        [% SET rentaldiscount = all_rules.$c.$i.rentaldiscount %]
166
                        [% SET rentaldiscount = all_rules.$c.$i.rentaldiscount %]
167
                        [% SET decreaseloanholds = all_rules.$c.$i.decreaseloanholds %]
166
168
167
                        [% SET show_rule = note || maxissueqty || maxonsiteissueqty || issuelength || daysmode || lengthunit || hardduedate || hardduedatecompare || fine || chargeperiod || chargeperiod_charge_at || firstremind || overduefinescap || cap_fine_to_replacement_price || finedays || maxsuspensiondays || suspension_chargeperiod || renewalsallowed || renewalperiod || norenewalbefore || auto_renew || no_auto_renewal_after || no_auto_renewal_after_hard_limit || reservesallowed || holds_per_day || holds_per_record || onshelfholds || opacitemholds || article_requests || rentaldiscount %]
169
                        [% SET show_rule = note || maxissueqty || maxonsiteissueqty || issuelength || daysmode || lengthunit || hardduedate || hardduedatecompare || fine || chargeperiod || chargeperiod_charge_at || firstremind || overduefinescap || cap_fine_to_replacement_price || finedays || maxsuspensiondays || suspension_chargeperiod || renewalsallowed || renewalperiod || norenewalbefore || auto_renew || no_auto_renewal_after || no_auto_renewal_after_hard_limit || reservesallowed || holds_per_day || holds_per_record || onshelfholds || opacitemholds || article_requests || rentaldiscount || decreaseloanholds %]
168
                        [% IF show_rule %]
170
                        [% IF show_rule %]
169
                            [% SET row_count = row_count + 1 %]
171
                            [% SET row_count = row_count + 1 %]
170
                            <tr row_countd="row_[% row_count | html %]">
172
                            <tr row_countd="row_[% row_count | html %]">
Lines 242-247 Link Here
242
                                        <span>None defined</span>
244
                                        <span>None defined</span>
243
                                      [% END %]
245
                                      [% END %]
244
                                    </td>
246
                                    </td>
247
                                    <td>[% decreaseloanholds | html %]</td>
245
                                    <td>[% fine | html %]</td>
248
                                    <td>[% fine | html %]</td>
246
                                    <td>[% chargeperiod | html %]</td>
249
                                    <td>[% chargeperiod | html %]</td>
247
                                    <td>[% IF chargeperiod_charge_at %]Start of interval[% ELSE %]End of interval[% END %]</td>
250
                                    <td>[% IF chargeperiod_charge_at %]Start of interval[% ELSE %]End of interval[% END %]</td>
Lines 391-396 Link Here
391
                        <input type="text" size="10" id="hardduedate" name="hardduedate" value="[% hardduedate | html %]" class="datepicker" />
394
                        <input type="text" size="10" id="hardduedate" name="hardduedate" value="[% hardduedate | html %]" class="datepicker" />
392
                        <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
395
                        <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
393
                    </td>
396
                    </td>
397
                    <td><input type="text" name="decreaseloanholds" id="decreaseloanholds" size="2" /></td>
394
                    <td><input type="text" name="fine" id="fine" size="4" /></td>
398
                    <td><input type="text" name="fine" id="fine" size="4" /></td>
395
                    <td><input type="text" name="chargeperiod" id="chargeperiod" size="2" /></td>
399
                    <td><input type="text" name="chargeperiod" id="chargeperiod" size="2" /></td>
396
                    <td>
400
                    <td>
Lines 465-470 Link Here
465
                      <th>Days mode</th>
469
                      <th>Days mode</th>
466
                      <th>Unit</th>
470
                      <th>Unit</th>
467
                      <th>Hard due date</th>
471
                      <th>Hard due date</th>
472
                      <th>Decreased loan period for high holds (day)</th>
468
                      <th>Fine amount</th>
473
                      <th>Fine amount</th>
469
                      <th>Fine charging interval</th>
474
                      <th>Fine charging interval</th>
470
                      <th>Charge when?</th>
475
                      <th>Charge when?</th>
(-)a/t/db_dependent/DecreaseLoanHighHolds.t (-4 / +34 lines)
Lines 30-36 use Koha::CirculationRules; Link Here
30
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
31
use t::lib::Mocks;
31
use t::lib::Mocks;
32
32
33
use Test::More tests => 19;
33
use Test::More tests => 21;
34
34
35
my $dbh    = C4::Context->dbh;
35
my $dbh    = C4::Context->dbh;
36
my $schema = Koha::Database->new()->schema();
36
my $schema = Koha::Database->new()->schema();
Lines 109-119 Koha::CirculationRules->set_rules( Link Here
109
            lengthunit      => 'days',
109
            lengthunit      => 'days',
110
            reservesallowed => '99',
110
            reservesallowed => '99',
111
            holds_per_record => '99',
111
            holds_per_record => '99',
112
            decreaseloanholds => 0,
112
        }
113
        }
113
    }
114
    }
114
);
115
);
115
116
116
117
my $orig_due = C4::Circulation::CalcDateDue(
117
my $orig_due = C4::Circulation::CalcDateDue(
118
    dt_from_string(),
118
    dt_from_string(),
119
    $item->effective_itemtype,
119
    $item->effective_itemtype,
Lines 133-141 my $patron_hr = { borrowernumber => $patron->id, branchcode => $library->{branch Link Here
133
my $data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
133
my $data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
134
is( $data->{exceeded},        1,          "Static mode should exceed threshold" );
134
is( $data->{exceeded},        1,          "Static mode should exceed threshold" );
135
is( $data->{outstanding},     6,          "Should have 6 outstanding holds" );
135
is( $data->{outstanding},     6,          "Should have 6 outstanding holds" );
136
is( $data->{duration},        1,          "Should have duration of 1" );
136
is( $data->{duration},        0,          "Should have duration of 0 because of specific circulation rules" );
137
is( ref( $data->{due_date} ), 'DateTime', "due_date should be a DateTime object" );
137
is( ref( $data->{due_date} ), 'DateTime', "due_date should be a DateTime object" );
138
138
139
Koha::CirculationRules->set_rules(
140
    {
141
        branchcode   => undef,
142
        categorycode => undef,
143
        itemtype     => $item->itype,
144
        rules        => {
145
            issuelength     => '14',
146
            lengthunit      => 'days',
147
            reservesallowed => '99',
148
            holds_per_record => '99',
149
            decreaseloanholds => undef,
150
        }
151
    }
152
);
153
154
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
155
is( $data->{duration}, 1, "Should have a duration of 1 because no specific circulation rules so defaults to system preference" );
156
139
my $duedate = $data->{due_date};
157
my $duedate = $data->{due_date};
140
is($duedate->hour, $orig_due->hour, 'New due hour is equal to original due hour.');
158
is($duedate->hour, $orig_due->hour, 'New due hour is equal to original due hour.');
141
is($duedate->min, $orig_due->min, 'New due minute is equal to original due minute.');
159
is($duedate->min, $orig_due->min, 'New due minute is equal to original due minute.');
Lines 215-218 ok( $needsconfirmation->{HIGHHOLDS}, "High holds checkout needs confirmation" ); Link Here
215
( undef, $needsconfirmation ) = CanBookBeIssued( $patron_object, $item->barcode, undef, undef, undef, { override_high_holds => 1 } );
233
( undef, $needsconfirmation ) = CanBookBeIssued( $patron_object, $item->barcode, undef, undef, undef, { override_high_holds => 1 } );
216
ok( !$needsconfirmation->{HIGHHOLDS}, "High holds checkout does not need confirmation" );
234
ok( !$needsconfirmation->{HIGHHOLDS}, "High holds checkout does not need confirmation" );
217
235
236
Koha::CirculationRules->set_rule(
237
    {
238
        branchcode   => undef,
239
        categorycode => undef,
240
        itemtype     => $item->itype,
241
        rule_name    => 'decreaseloanholds',
242
        rule_value   => 2,
243
    }
244
);
245
246
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
247
is( $data->{duration}, 2, "Circulation rules override system preferences" );
248
218
$schema->storage->txn_rollback();
249
$schema->storage->txn_rollback();
219
- 

Return to bug 14866