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

(-)a/Koha/Bookings.pm (+13 lines)
Lines 45-50 sub filter_by_future { Link Here
45
    return $self->search( { start_date => { '>' => \'NOW()' } } );
45
    return $self->search( { start_date => { '>' => \'NOW()' } } );
46
}
46
}
47
47
48
=head3 filter_by_active
49
50
    $bookings->filter_by_active;
51
52
Will return the bookings that have not ended.
53
54
=cut
55
56
sub filter_by_active {
57
    my ($self) = @_;
58
    return $self->search( { end_date => { '>=' => \'NOW()' } } );
59
}
60
48
=head2 Internal Methods
61
=head2 Internal Methods
49
62
50
=head3 _type
63
=head3 _type
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc (-1 / +1 lines)
Lines 56-62 Link Here
56
        [%- ELSE -%]
56
        [%- ELSE -%]
57
        <li>
57
        <li>
58
        [%- END -%]
58
        [%- END -%]
59
            <a href="/cgi-bin/koha/bookings/list.pl?biblionumber=[% biblio_object_id | url  %]">Bookings (<span class="bookings_count">[% biblio.bookings.filter_by_future.count | html %]</span>)</a>
59
            <a href="/cgi-bin/koha/bookings/list.pl?biblionumber=[% biblio_object_id | url  %]">Bookings (<span class="bookings_count">[% biblio.bookings.filter_by_active.count | html %]</span>)</a>
60
        </li>
60
        </li>
61
        [% END %]
61
        [% END %]
62
62
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc (-1 / +1 lines)
Lines 30-36 Link Here
30
                <span>Holds ([% holds_count || 0 | html %])</span>
30
                <span>Holds ([% holds_count || 0 | html %])</span>
31
            [% END %]
31
            [% END %]
32
            [% WRAPPER tab_item tabname="bookings" %]
32
            [% WRAPPER tab_item tabname="bookings" %]
33
                [% SET bookings_count = patron.bookings.filter_by_future.count %]
33
                [% SET bookings_count = patron.bookings.filter_by_active.count %]
34
                <span>Bookings ([% bookings_count || 0 | html %])</span>
34
                <span>Bookings ([% bookings_count || 0 | html %])</span>
35
            [% END %]
35
            [% END %]
36
        [% END %]
36
        [% END %]
(-)a/t/db_dependent/Koha/Bookings.t (-5 / +81 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 1;
22
use Test::More tests => 2;
23
23
24
use Koha::Bookings;
24
use Koha::Bookings;
25
use Koha::Database;
25
use Koha::Database;
Lines 37-45 subtest 'filter_by_future' => sub { Link Here
37
37
38
    $schema->storage->txn_begin;
38
    $schema->storage->txn_begin;
39
39
40
    my $biblio  = $builder->build_sample_biblio;
40
    my $biblio = $builder->build_sample_biblio;
41
    my $start_0 = dt_from_string->subtract( days => 2 )->truncate( to => 'day' );
42
    my $end_0   = dt_from_string->add( days => 4 )->truncate( to => 'day' );
43
    $builder->build_object(
41
    $builder->build_object(
44
        {
42
        {
45
            class => 'Koha::Bookings',
43
            class => 'Koha::Bookings',
Lines 90-92 subtest 'filter_by_future' => sub { Link Here
90
88
91
    $schema->storage->txn_rollback;
89
    $schema->storage->txn_rollback;
92
};
90
};
93
- 
91
92
subtest 'filter_by_active' => sub {
93
94
    plan tests => 5;
95
96
    $schema->storage->txn_begin;
97
98
    my $biblio     = $builder->build_sample_biblio;
99
    my $start_ago  = dt_from_string->subtract( hours => 1 );
100
    my $start_hour = dt_from_string->add( hours => 1 );
101
    my $start_day  = dt_from_string->add( days  => 1 );
102
    my $end_ago    = dt_from_string->subtract( minutes => 1 );
103
    my $end_hour   = dt_from_string->add( hours => 1 );
104
    my $end_day    = dt_from_string->add( days  => 1 );
105
    $builder->build_object(
106
        {
107
            class => 'Koha::Bookings',
108
            value => {
109
                biblio_id  => $biblio->biblionumber,
110
                start_date => $start_ago,
111
                end_date   => $end_hour
112
            }
113
        }
114
    );
115
    is( $biblio->bookings->filter_by_active->count, 1, 'Booking started in past, ending in future is counted' );
116
117
    $builder->build_object(
118
        {
119
            class => 'Koha::Bookings',
120
            value => {
121
                biblio_id  => $biblio->biblionumber,
122
                start_date => $start_ago,
123
                end_date   => $end_ago
124
            }
125
        }
126
    );
127
    is( $biblio->bookings->filter_by_active->count, 1, 'Booking started in past, ended now is not counted' );
128
129
    $builder->build_object(
130
        {
131
            class => 'Koha::Bookings',
132
            value => {
133
                biblio_id  => $biblio->biblionumber,
134
                start_date => $start_hour,
135
                end_date   => $end_hour
136
            }
137
        }
138
    );
139
    is( $biblio->bookings->filter_by_active->count, 2, 'Booking starting soon, ending soon is still counted' );
140
141
    $builder->build_object(
142
        {
143
            class => 'Koha::Bookings',
144
            value => {
145
                biblio_id  => $biblio->biblionumber,
146
                start_date => $start_day,
147
                end_date   => $end_day
148
            }
149
        }
150
    );
151
    is( $biblio->bookings->filter_by_active->count, 3, 'Booking starting tomorrow, ending tomorrow is counted' );
152
153
    $builder->build_object(
154
        {
155
            class => 'Koha::Bookings',
156
            value => {
157
                biblio_id  => $biblio->biblionumber,
158
                start_date => $start_day,
159
                end_date   => $end_ago
160
            }
161
        }
162
    );
163
    is(
164
        $biblio->bookings->filter_by_active->count, 3,
165
        'EDGE CASE: Booking starting in future, already ended is not counted - should be impossible, but good check'
166
    );
167
168
    $schema->storage->txn_rollback;
169
};

Return to bug 36428