- my $issuingrule = GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
- my $finedays = $issuingrule->{finedays};
- my $unit = $issuingrule->{lengthunit};
-
- # exit if no finedays defined
- return unless $finedays;
- # finedays is in days, so hourly loans must multiply by 24
- # thus 1 hour late equals 1 day suspension * finedays rate
- $finedays = $finedays * 24 if ($unit eq 'hours');
-
- # grace period is measured in the same units as the loan
- my $grace = DateTime::Duration->new( $unit => $issuingrule->{firstremind} );
-
- if ( ( $deltadays - $grace )->is_positive ) { # you can't compare DateTime::Durations with logical operators
- my $new_debar_dt = $dt_today->clone()->add_duration( $deltadays * $finedays );
- my $borrower_debar_dt = dt_from_string( $borrower->{debarred} );
- # check to see if the current debar date is a valid date
- if ( $borrower->{debarred} && $borrower_debar_dt ) {
- # if so, is it before the new date? update only if true
- if ( DateTime->compare( $borrower_debar_dt, $new_debar_dt ) == -1 ) {
- C4::Members::DebarMember( $borrower->{borrowernumber}, $new_debar_dt->ymd() );
- return $new_debar_dt->ymd();
+ my $issuingrule =
+ GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
+ my $finedays = $issuingrule->{finedays};
+ my $unit = $issuingrule->{lengthunit};
+
+ if ($finedays) {
+
+ # finedays is in days, so hourly loans must multiply by 24
+ # thus 1 hour late equals 1 day suspension * finedays rate
+ $finedays = $finedays * 24 if ( $unit eq 'hours' );
+
+ # grace period is measured in the same units as the loan
+ my $grace =
+ DateTime::Duration->new( $unit => $issuingrule->{firstremind} );
+ if ( $deltadays->subtract($grace)->is_positive() ) {
+
+ my $new_debar_dt =
+ $dt_today->clone()->add_duration( $deltadays * $finedays );
+ if ( $borrower->{debarred} ) {
+ my $borrower_debar_dt = dt_from_string( $borrower->{debarred} );
+
+ # Update patron only if new date > old
+ if ( DateTime->compare( $borrower_debar_dt, $new_debar_dt ) !=
+ -1 )
+ {
+ return;
+ }
+