X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FCirculation.pm;h=6b700ec5b987f3013243365145b2f51cbf874b04;hb=5d6c092921919526ade501facb1220f8a108a08f;hp=91ed2dbecd76f4ba3e097bce8d9a78dac0633f28;hpb=0b2e9dbf620afeca2ec4a82b583c6787d8f1208b;p=koha_fer diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 91ed2dbecd..6b700ec5b9 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1756,6 +1756,26 @@ sub AddReturn { my $borrowernumber = $borrower->{'borrowernumber'} || undef; # we don't know if we had a borrower or not + my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckin'); + if ($yaml) { + $yaml = "$yaml\n\n"; # YAML is anal on ending \n. Surplus does not hurt + my $rules; + eval { $rules = YAML::Load($yaml); }; + if ($@) { + warn "Unable to parse UpdateNotForLoanStatusOnCheckin syspref : $@"; + } + else { + foreach my $key ( keys %$rules ) { + if ( $item->{notforloan} eq $key ) { + $messages->{'NotForLoanStatusUpdated'} = { from => $item->{notforloan}, to => $rules->{$key} }; + ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber ); + last; + } + } + } + } + + # check if the book is in a permanent collection.... # FIXME -- This 'PE' attribute is largely undocumented. afaict, there's no user interface that reflects this functionality. if ( $hbr ) { @@ -1781,6 +1801,7 @@ sub AddReturn { # case of a return of document (deal with issues and holdingbranch) my $today = DateTime->now( time_zone => C4::Context->tz() ); + if ($doreturn) { my $datedue = $issue->{date_due}; $borrower or warn "AddReturn without current borrower"; @@ -1888,10 +1909,21 @@ sub AddReturn { defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!"; # zero is OK, check defined if ( $issue->{overdue} && $issue->{date_due} ) { -# fix fine days - my $debardate = - _debar_user_on_return( $borrower, $item, $issue->{date_due}, $today ); - $messages->{Debarred} = $debardate if ($debardate); + # fix fine days + my ($debardate,$reminder) = _debar_user_on_return( $borrower, $item, $issue->{date_due}, $today ); + if ($reminder){ + $messages->{'PrevDebarred'} = $debardate; + } else { + $messages->{'Debarred'} = $debardate if $debardate; + } + # there's no overdue on the item but borrower had been previously debarred + } elsif ( $issue->{date_due} and $borrower->{'debarred'} ) { + my $borrower_debar_dt = dt_from_string( $borrower->{debarred} ); + $borrower_debar_dt->truncate(to => 'day'); + my $today_dt = $today->clone()->truncate(to => 'day'); + if ( DateTime->compare( $borrower_debar_dt, $today_dt ) != -1 ) { + $messages->{'PrevDebarred'} = $borrower->{'debarred'}; + } } } @@ -2073,17 +2105,31 @@ sub _debar_user_on_return { # 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 $suspension_days = $deltadays * $finedays; + + # If the max suspension days is < than the suspension days + # the suspension days is limited to this maximum period. + my $max_sd = $issuingrule->{maxsuspensiondays}; + if ( defined $max_sd ) { + $max_sd = DateTime::Duration->new( days => $max_sd ); + $suspension_days = $max_sd + if DateTime::Duration->compare( $max_sd, $suspension_days ) < 0; + } my $new_debar_dt = - $dt_today->clone()->add_duration( $deltadays * $finedays ); + $dt_today->clone()->add_duration( $suspension_days ); Koha::Borrower::Debarments::AddUniqueDebarment({ borrowernumber => $borrower->{borrowernumber}, expiration => $new_debar_dt->ymd(), type => 'SUSPENSION', }); - + # if borrower was already debarred but does not get an extra debarment + if ( $borrower->{debarred} eq Koha::Borrower::Debarments::IsDebarred($borrower->{borrowernumber}) ) { + return ($borrower->{debarred},1); + } return $new_debar_dt->ymd(); } }