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 124-129 Link Here
124
                <th>OPAC item level holds</th>
124
                <th>OPAC item level holds</th>
125
                <th>Article requests</th>
125
                <th>Article requests</th>
126
                <th>Rental discount (%)</th>
126
                <th>Rental discount (%)</th>
127
                <th>Decrease loan holds (day)</th>
127
                <th>Actions</th>
128
                <th>Actions</th>
128
            </tr>
129
            </tr>
129
            </thead>
130
            </thead>
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 320-325 Link Here
320
                                        [% END %]
322
                                        [% END %]
321
                                    </td>
323
                                    </td>
322
                                    <td>[% rentaldiscount | html %]</td>
324
                                    <td>[% rentaldiscount | html %]</td>
325
                                    <td>[% decreaseloanholds | html %]</td>
323
                                    <td class="actions">
326
                                    <td class="actions">
324
                                      <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
327
                                      <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
325
                                      <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% i || '*' | uri %]&amp;categorycode=[% c || '*' | uri %]&amp;branch=[% current_branch | uri %]"><i class="fa fa-trash"></i> Delete</a>
328
                                      <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% i || '*' | uri %]&amp;categorycode=[% c || '*' | uri %]&amp;branch=[% current_branch | uri %]"><i class="fa fa-trash"></i> Delete</a>
Lines 445-450 Link Here
445
                        </select>
448
                        </select>
446
                    </td>
449
                    </td>
447
                    <td><input type="text" name="rentaldiscount" id="rentaldiscount" size="2" /></td>
450
                    <td><input type="text" name="rentaldiscount" id="rentaldiscount" size="2" /></td>
451
                    <td><input type="text" name="decreaseloanholds" id="decreaseloanholds" size="2" /></td>
448
                    <td class="actions">
452
                    <td class="actions">
449
                        <input type="hidden" name="branch" value="[% current_branch | html %]"/>
453
                        <input type="hidden" name="branch" value="[% current_branch | html %]"/>
450
                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
454
                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
Lines 487-492 Link Here
487
                      <th>OPAC item level holds</th>
491
                      <th>OPAC item level holds</th>
488
                      <th>Article requests</th>
492
                      <th>Article requests</th>
489
                      <th>Rental discount (%)</th>
493
                      <th>Rental discount (%)</th>
494
                      <th>Decrease loan holds (day)</th>
490
                      <th>&nbsp;</th>
495
                      <th>&nbsp;</th>
491
                    </tr>
496
                    </tr>
492
                  </tfoot>
497
                  </tfoot>
(-)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