@@ -, +, @@ on). Date manipulation is tested so time is kept and resulting dates - We really need tests for this and doing it with selenium is no-end - I see a use for this new method for encapsulating behaviours, for example we might want to add Calendar support for the 'days' use case, and having the method here assures we will have tests, etc. $ kshell k$ prove t/db_dependent/Koha/Checkout.t --- Koha/Checkout.pm | 48 +++++++++++- .../en/modules/tools/batch_extend_due_dates.tt | 18 ++--- t/db_dependent/Koha/Checkout.t | 88 ++++++++++++++++++++++ tools/batch_extend_due_dates.pl | 75 +++++++----------- 4 files changed, 170 insertions(+), 59 deletions(-) create mode 100644 t/db_dependent/Koha/Checkout.t --- a/Koha/Checkout.pm +++ a/Koha/Checkout.pm @@ -22,11 +22,13 @@ use Modern::Perl; use Carp; use DateTime; +use Scalar::Util qw( looks_like_number ); use Try::Tiny; use Koha::Checkouts::ReturnClaims; use Koha::Database; -use Koha::DateUtils; +use Koha::DateUtils qw(dt_from_string); +use Koha::Exceptions; use Koha::Items; use base qw(Koha::Object); @@ -162,6 +164,50 @@ sub claim_returned { }; } +=head3 shift_due_date + + $checkout->shift_due_date({ hard_due_date => $dt }); + $checkout->shift_due_date({ days => $days_count }); + +=cut + +sub shift_due_date { + my ($self, $params) = @_; + + my $hard_due_date = $params->{hard_due_date}; + my $days = $params->{days}; + + if ( $hard_due_date and $days ) { + Koha::Exceptions::BadParameter->throw( "Called with both 'days' and 'hard_due_date'. Only one can be used." ); + } + + if ( !( $days or $hard_due_date ) ) { + Koha::Exceptions::BadParameter->throw( "At least one parameter needs to be passed" ); + } + + my $due_date = dt_from_string($self->date_due); + if ( $hard_due_date ) { + # We require a DateTime + Koha::Exceptions::WrongParameter->throw( + "'hard_due_date' must be a DateTime object" + ) unless $hard_due_date->isa('DateTime'); + + $due_date = $hard_due_date->clone->set( + hour => $due_date->hour, + minute => $due_date->minute, + second => $due_date->second + ); + } + else { + Koha::Exceptions::WrongParameter->throw( + "'days' must be an integer" + ) unless looks_like_number($days); + $due_date->add( days => $days ); + } + + return $self->date_due( $due_date ); +} + =head2 Internal methods =head3 _type --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_extend_due_dates.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_extend_due_dates.tt @@ -114,7 +114,7 @@ [% ELSIF view == 'list' %] - [% IF checkouts.count %] + [% IF checkouts.size > 0 %]