From 28309bc61e0d2ba687f40dc8a59dc9f29044e681 Mon Sep 17 00:00:00 2001 From: Ian Walls Date: Wed, 21 Mar 2012 16:03:32 -0400 Subject: [PATCH] Bug 5549 Followup: fix suspension in days ISO dates were being compared with DateTime objects, and DateTime::Durations with integers. This patch reimplements the _FixFineDaysOnReturn subroutine to use the new hourly loans functionality. Also moves date formatting of patron debar date out of circ/returns.pl and into KohaDates on the template Signed-off-by: Chris Cormack --- C4/Circulation.pm | 38 ++++++++++------------ circ/returns.pl | 2 +- .../intranet-tmpl/prog/en/modules/circ/returns.tt | 3 +- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 0adc8dc971..70955ecb59 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1785,19 +1785,15 @@ Internal function, called only by AddReturn that calculate and update the user f sub _FixFineDaysOnReturn { my ( $borrower, $item, $datedue ) = @_; + return unless ($datedue); - my $dt_due = dt_from_string($datedue); + my $dt_due = dt_from_string( $datedue ); my $dt_today = DateTime->now( time_zone => C4::Context->tz() ); - if ($datedue) { - $datedue = C4::Dates->new( $datedue, "iso" ); - } else { - return; - } my $branchcode = _GetCircControlBranch( $item, $borrower ); my $calendar = Koha::Calendar->new( branchcode => $branchcode ); - my $today = C4::Dates->new(); + # $deltadays is a DateTime::Duration object my $deltadays = $calendar->days_between( $dt_due, $dt_today ); my $circcontrol = C4::Context::preference('CircControl'); @@ -1806,22 +1802,22 @@ sub _FixFineDaysOnReturn { # exit if no finedays defined return unless $finedays; - my $grace = $issuingrule->{firstremind}; - - if ( $deltadays - $grace > 0 ) { - my @newdate = Add_Delta_Days( Today(), $deltadays * $finedays ); - my $isonewdate = join( '-', @newdate ); - my ( $deby, $debm, $debd ) = split( /-/, $borrower->{debarred} ); - if ( check_date( $deby, $debm, $debd ) ) { - my @olddate = split( /-/, $borrower->{debarred} ); - - if ( Delta_Days( @olddate, @newdate ) > 0 ) { - C4::Members::DebarMember( $borrower->{borrowernumber}, $isonewdate ); - return $isonewdate; + my $grace = DateTime::Duration->new( days => $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(); } + # if the borrower's debar date is not set or valid, debar them } else { - C4::Members::DebarMember( $borrower->{borrowernumber}, $isonewdate ); - return $isonewdate; + C4::Members::DebarMember( $borrower->{borrowernumber}, $new_debar_dt->ymd() ); + return $new_debar_dt->ymd(); } } } diff --git a/circ/returns.pl b/circ/returns.pl index d1aaf0a10b..83817a8310 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -464,7 +464,7 @@ foreach my $code ( keys %$messages ) { elsif ( $code eq 'Wrongbranch' ) { } elsif ( $code eq 'Debarred' ) { - $err{debarred} = C4::Dates::format_date( $messages->{'Debarred'} ); + $err{debarred} = $messages->{'Debarred'}; $err{debarcardnumber} = $borrower->{cardnumber}; $err{debarborrowernumber} = $borrower->{borrowernumber}; $err{debarname} = "$borrower->{firstname} $borrower->{surname}"; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt index 004a44ef87..038a3c8069 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -1,3 +1,4 @@ +[% USE KohaDates %] [% INCLUDE 'doc-head-open.inc' %] Koha › Circulation › Check In [% title |html %] [% INCLUDE 'doc-head-close.inc' %] @@ -331,7 +332,7 @@ function Dopop(link) {

Item is withdrawn.

[% END %] [% IF ( errmsgloo.debarred ) %] -

[% errmsgloo.debarname %]([% errmsgloo.debarcardnumber %]) is now debarred until [% errmsgloo.debarred %]

+

[% errmsgloo.debarname %]([% errmsgloo.debarcardnumber %]) is now debarred until [% errmsgloo.debarred | $KohaDates %]

[% END %] [% END %] [% IF ( soundon ) %] -- 2.11.0