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

(-)a/Koha/Checkout.pm (+26 lines)
Lines 1-6 Link Here
1
package Koha::Checkout;
1
package Koha::Checkout;
2
2
3
# Copyright ByWater Solutions 2015
3
# Copyright ByWater Solutions 2015
4
# Copyright 2016 Koha Development Team
4
#
5
#
5
# This file is part of Koha.
6
# This file is part of Koha.
6
#
7
#
Lines 22-27 use Modern::Perl; Link Here
22
use Carp;
23
use Carp;
23
24
24
use Koha::Database;
25
use Koha::Database;
26
use DateTime;
27
use Koha::DateUtils;
25
28
26
use base qw(Koha::Object);
29
use base qw(Koha::Object);
27
30
Lines 35-40 Koha::Checkout - Koha Checkout object class Link Here
35
38
36
=cut
39
=cut
37
40
41
=head3 is_overdue
42
43
my  $is_overdue = $checkout->is_overdue( [ $reference_dt ] );
44
45
Return 1 if the checkout is overdue.
46
47
A reference date can be passed, in this case it will be used, otherwise today
48
will be the reference date.
49
50
=cut
51
52
sub is_overdue {
53
    my ( $self, $dt ) = @_;
54
    $dt ||= DateTime->now( time_zone => C4::Context->tz );
55
    my $is_overdue =
56
      DateTime->compare( dt_from_string( $self->date_due, 'sql' ), $dt ) == -1
57
      ? 1
58
      : 0;
59
    return $is_overdue;
60
}
61
38
=head3 type
62
=head3 type
39
63
40
=cut
64
=cut
Lines 47-52 sub _type { Link Here
47
71
48
Kyle M Hall <kyle@bywatersolutions.com>
72
Kyle M Hall <kyle@bywatersolutions.com>
49
73
74
Jonathan Druart <jonathan.druart@bugs.koha-community.org>
75
50
=cut
76
=cut
51
77
52
1;
78
1;
(-)a/t/db_dependent/Koha/Checkouts.t (-3 / +33 lines)
Lines 19-29 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 5;
23
23
24
use Koha::Checkout;
25
use Koha::Checkouts;
24
use Koha::Checkouts;
26
use Koha::Database;
25
use Koha::Database;
26
use Koha::DateUtils qw( dt_from_string );
27
27
28
use t::lib::TestBuilder;
28
use t::lib::TestBuilder;
29
29
Lines 55-60 is( Koha::Checkouts->search->count, $nb_of_checkouts + 2, 'The 2 checkouts shoul Link Here
55
my $retrieved_checkout_1 = Koha::Checkouts->find( $new_checkout_1->issue_id );
55
my $retrieved_checkout_1 = Koha::Checkouts->find( $new_checkout_1->issue_id );
56
is( $retrieved_checkout_1->itemnumber, $new_checkout_1->itemnumber, 'Find a checkout by id should return the correct checkout' );
56
is( $retrieved_checkout_1->itemnumber, $new_checkout_1->itemnumber, 'Find a checkout by id should return the correct checkout' );
57
57
58
subtest 'is_overdue' => sub {
59
    plan tests => 6;
60
    my $ten_days_ago   = dt_from_string->add( days => -10 );
61
    my $ten_days_later = dt_from_string->add( days => 10 );
62
    my $yesterday      = dt_from_string->add( days => -1 );
63
    my $tomorrow       = dt_from_string->add( days => 1 );
64
65
    $retrieved_checkout_1->date_due($ten_days_ago)->store;
66
    is( $retrieved_checkout_1->is_overdue,
67
        1, 'The item should have been returned 10 days ago' );
68
69
    $retrieved_checkout_1->date_due($ten_days_later)->store;
70
    is( $retrieved_checkout_1->is_overdue, 0, 'The item is due in 10 days' );
71
72
    $retrieved_checkout_1->date_due($tomorrow)->store;
73
    is( $retrieved_checkout_1->is_overdue($ten_days_later),
74
        1, 'The item should have been returned yesterday' );
75
76
    $retrieved_checkout_1->date_due($yesterday)->store;
77
    is( $retrieved_checkout_1->is_overdue($ten_days_ago),
78
        0, 'Ten days ago the item due yesterday was not late' );
79
80
    $retrieved_checkout_1->date_due($tomorrow)->store;
81
    is( $retrieved_checkout_1->is_overdue($ten_days_later),
82
        1, 'In Ten days, the item due tomorrow will be late' );
83
84
    $retrieved_checkout_1->date_due($yesterday)->store;
85
    is( $retrieved_checkout_1->is_overdue($ten_days_ago),
86
        0, 'In Ten days, the item due yesterday will still be late' );
87
};
88
58
$retrieved_checkout_1->delete;
89
$retrieved_checkout_1->delete;
59
is( Koha::Checkouts->search->count, $nb_of_checkouts + 1, 'Delete should have deleted the checkout' );
90
is( Koha::Checkouts->search->count, $nb_of_checkouts + 1, 'Delete should have deleted the checkout' );
60
91
61
- 

Return to bug 17689