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

(-)a/C4/Circulation.pm (-7 / +8 lines)
Lines 2266-2274 sub _calculate_new_debar_dt { Link Here
2266
    my $deltadays = DateTime::Duration->new(
2266
    my $deltadays = DateTime::Duration->new(
2267
        days => $chargeable_units
2267
        days => $chargeable_units
2268
    );
2268
    );
2269
2269
    if ( $deltadays->subtract($grace)->is_positive() ) {
2270
    if ( $deltadays->subtract($grace)->is_positive() ) {
2270
        my $suspension_days = $deltadays * $finedays;
2271
        my $suspension_days = $deltadays * $finedays;
2271
2272
2273
        if ( $issuing_rule->suspension_chargeperiod > 1 ) {
2274
            # No need to / 1 and do not consider / 0
2275
            $suspension_days = DateTime::Duration->new(
2276
                days => floor( $suspension_days->in_units('days') / $issuing_rule->suspension_chargeperiod )
2277
            );
2278
        }
2279
2272
        # If the max suspension days is < than the suspension days
2280
        # If the max suspension days is < than the suspension days
2273
        # the suspension days is limited to this maximum period.
2281
        # the suspension days is limited to this maximum period.
2274
        my $max_sd = $issuing_rule->maxsuspensiondays;
2282
        my $max_sd = $issuing_rule->maxsuspensiondays;
Lines 2287-2299 sub _calculate_new_debar_dt { Link Here
2287
            }
2295
            }
2288
        }
2296
        }
2289
2297
2290
        if ( $issuing_rule->suspension_chargeperiod > 1 ) {
2291
            # No need to / 1 and do not consider / 0
2292
            $suspension_days = DateTime::Duration->new(
2293
                days => floor( $suspension_days->in_units('days') / $issuing_rule->suspension_chargeperiod )
2294
            );
2295
        }
2296
2297
        my $new_debar_dt;
2298
        my $new_debar_dt;
2298
        # Use the calendar or not to calculate the debarment date
2299
        # Use the calendar or not to calculate the debarment date
2299
        if ( C4::Context->preference('SuspensionsCalendar') eq 'noSuspensionsWhenClosed' ) {
2300
        if ( C4::Context->preference('SuspensionsCalendar') eq 'noSuspensionsWhenClosed' ) {
(-)a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t (-2 / +56 lines)
Lines 1-5 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
use Test::More tests => 2;
2
use Test::More tests => 4;
3
3
4
use MARC::Record;
4
use MARC::Record;
5
use MARC::Field;
5
use MARC::Field;
Lines 101-104 is( Link Here
101
);
101
);
102
DelDebarment( $debarments->[0]->{borrower_debarment_id} );
102
DelDebarment( $debarments->[0]->{borrower_debarment_id} );
103
103
104
subtest "suspension_chargeperiod" => sub {
105
    Koha::IssuingRules->search->delete;
106
    $builder->build(
107
        {
108
            source => 'Issuingrule',
109
            value  => {
110
                categorycode => '*',
111
                itemtype     => '*',
112
                branchcode   => '*',
113
                firstremind  => 0,
114
                finedays     => 7,
115
                lengthunit   => 'days',
116
                suspension_chargeperiod => 15,
117
                maxsuspensiondays => 333,
118
            }
119
        }
120
    );
121
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
122
    my $item = $builder->build_sample_item;
123
124
    my $last_year = dt_from_string->clone->subtract( years => 1 );
125
    my $today = dt_from_string;
126
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron->unblessed, $item->unblessed, $last_year, $today );
127
    is( $new_debar_dt->truncate( to => 'day' ),
128
        $today->clone->add( days => 365 / 15 * 7 )->truncate( to => 'day' ) );
129
130
};
131
132
subtest "maxsuspensiondays" => sub {
133
    Koha::IssuingRules->search->delete;
134
    $builder->build(
135
        {
136
            source => 'Issuingrule',
137
            value  => {
138
                categorycode => '*',
139
                itemtype     => '*',
140
                branchcode   => '*',
141
                firstremind  => 0,
142
                finedays     => 15,
143
                lengthunit   => 'days',
144
                suspension_chargeperiod => 7,
145
                maxsuspensiondays => 333,
146
            }
147
        }
148
    );
149
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
150
    my $item = $builder->build_sample_item;
151
152
    my $last_year = dt_from_string->clone->subtract( years => 1 );
153
    my $today = dt_from_string;
154
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron->unblessed, $item->unblessed, $last_year, $today );
155
    is( $new_debar_dt->truncate( to => 'day' ),
156
        $today->clone->add( days => 333 )->truncate( to => 'day' ) );
157
};
158
104
$schema->storage->txn_rollback;
159
$schema->storage->txn_rollback;
105
- 

Return to bug 24138