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

(-)a/Koha/Issue.pm (+33 lines)
Lines 18-26 package Koha::Issue; Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Koha::Database;
20
use Koha::Database;
21
use DateTime;
22
use Koha::DateUtils;
21
23
22
use base qw(Koha::Object);
24
use base qw(Koha::Object);
23
25
26
=head1 NAME
27
28
Koha::Issue - Koha Issue Object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 is_overdue
37
38
my  $is_overdue = $issue->is_overdue( [ $reference_dt ] );
39
40
Return 1 if the issue is overdue.
41
42
A reference date can be passed, in this case it will be used, otherwise today
43
will be the reference date.
44
45
=cut
46
47
sub is_overdue {
48
    my ( $self, $dt ) = @_;
49
    $dt ||= DateTime->now( time_zone => C4::Context->tz );
50
    my $is_overdue =
51
      DateTime->compare( dt_from_string( $self->date_due, 'sql' ), $dt ) == -1
52
      ? 1
53
      : 0;
54
    return $is_overdue;
55
}
56
24
sub _type {
57
sub _type {
25
    return 'Issue';
58
    return 'Issue';
26
}
59
}
(-)a/t/db_dependent/Koha/Issues.t (-2 / +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::Issue;
24
use Koha::Issue;
25
use Koha::Issues;
25
use Koha::Issues;
26
use Koha::Database;
26
use Koha::Database;
27
use Koha::DateUtils;
27
28
28
use t::lib::TestBuilder;
29
use t::lib::TestBuilder;
29
30
Lines 52-57 is( Koha::Issues->search->count, $nb_of_issues + 2, 'The 2 issues should have be Link Here
52
my $retrieved_issue_1 = Koha::Issues->find( $new_issue_1->issue_id );
53
my $retrieved_issue_1 = Koha::Issues->find( $new_issue_1->issue_id );
53
is( $retrieved_issue_1->itemnumber, $new_issue_1->itemnumber, 'Find a issue by id should return the correct issue' );
54
is( $retrieved_issue_1->itemnumber, $new_issue_1->itemnumber, 'Find a issue by id should return the correct issue' );
54
55
56
subtest 'is_overdue' => sub {
57
    plan tests => 6;
58
    my $ten_days_ago   = dt_from_string->add( days => -10 );
59
    my $ten_days_later = dt_from_string->add( days => 10 );
60
    my $yesterday      = dt_from_string->add( days => -1 );
61
    my $tomorrow       = dt_from_string->add( days => 1 );
62
63
    $retrieved_issue_1->date_due($ten_days_ago)->store;
64
    is( $retrieved_issue_1->is_overdue,
65
        1, 'The item should have been returned 10 days ago' );
66
67
    $retrieved_issue_1->date_due($ten_days_later)->store;
68
    is( $retrieved_issue_1->is_overdue, 0, 'The item is due in 10 days' );
69
70
    $retrieved_issue_1->date_due($tomorrow)->store;
71
    is( $retrieved_issue_1->is_overdue($ten_days_later),
72
        1, 'The item should have been returned yesterday' );
73
74
    $retrieved_issue_1->date_due($yesterday)->store;
75
    is( $retrieved_issue_1->is_overdue($ten_days_ago),
76
        0, 'Ten days ago the item due yesterday was not late' );
77
78
    $retrieved_issue_1->date_due($tomorrow)->store;
79
    is( $retrieved_issue_1->is_overdue($ten_days_later),
80
        1, 'In Ten days, the item due tomorrow will be late' );
81
82
    $retrieved_issue_1->date_due($yesterday)->store;
83
    is( $retrieved_issue_1->is_overdue($ten_days_ago),
84
        0, 'In Ten days, the item due yesterday will still be late' );
85
};
86
55
$retrieved_issue_1->delete;
87
$retrieved_issue_1->delete;
56
is( Koha::Issues->search->count, $nb_of_issues + 1, 'Delete should delete the issue' );
88
is( Koha::Issues->search->count, $nb_of_issues + 1, 'Delete should delete the issue' );
57
89
58
- 

Return to bug 17689