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

(-)a/Koha/Bookings.pm (+20 lines)
Lines 20-25 package Koha::Bookings; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::DateUtils qw( dt_from_string );
23
use Koha::Booking;
24
use Koha::Booking;
24
25
25
use base qw(Koha::Objects);
26
use base qw(Koha::Objects);
Lines 34-39 Koha::Bookings - Koha Booking object set class Link Here
34
35
35
=cut
36
=cut
36
37
38
=head3 filter_by_future
39
40
    $bookings->filter_by_future;
41
42
    Will return the bookings starting from now.
43
44
=cut
45
46
sub filter_by_future {
47
    my ($self) = @_;
48
    my $now    = dt_from_string;
49
    my $dtf    = Koha::Database->new->schema->storage->datetime_parser;
50
    return $self->search( { start_date => { '>' => $dtf->format_datetime($now) } } );
51
}
52
53
=head2 Internal Methods
54
55
=cut
56
37
=head3 type
57
=head3 type
38
58
39
=cut
59
=cut
(-)a/Koha/Template/Plugin/Biblio.pm (-12 lines)
Lines 29-36 use Koha::Patrons; Link Here
29
use Koha::ArticleRequests;
29
use Koha::ArticleRequests;
30
use Koha::Recalls;
30
use Koha::Recalls;
31
31
32
use Koha::DateUtils qw(dt_from_string);
33
34
# Do not use HoldsCount, it is deprecated and will be removed in a future release.
32
# Do not use HoldsCount, it is deprecated and will be removed in a future release.
35
sub HoldsCount {
33
sub HoldsCount {
36
    my ( $self, $biblionumber ) = @_;
34
    my ( $self, $biblionumber ) = @_;
Lines 72-85 sub RecallsCount { Link Here
72
    return $recalls->count;
70
    return $recalls->count;
73
}
71
}
74
72
75
sub BookingsCount {
76
    my ( $self, $biblionumber ) = @_;
77
78
    my $biblio = Koha::Biblios->find($biblionumber);
79
80
    my $now = dt_from_string;
81
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
82
    return $biblio->bookings->search( { start_date => { '>' => $dtf->format_datetime($now) } } )->count;
83
}
84
85
1;
73
1;
(-)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.BookingsCount( biblio_object_id ) | 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_future.count | html %]</span>)</a>
60
        </li>
60
        </li>
61
        [% END %]
61
        [% END %]
62
62
(-)a/t/db_dependent/Koha/Bookings.t (-1 / +79 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2024 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 1;
23
24
use Koha::Bookings;
25
use Koha::Database;
26
use Koha::DateUtils qw( dt_from_string );
27
28
use t::lib::TestBuilder;
29
30
my $schema = Koha::Database->new->schema;
31
32
my $builder = t::lib::TestBuilder->new;
33
34
subtest 'filter_by_future' => sub {
35
36
    plan tests => 1;
37
38
    $schema->storage->txn_begin;
39
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(
44
        {
45
            class => 'Koha::Bookings',
46
            value => {
47
                biblio_id  => $biblio->biblionumber,
48
                start_date => dt_from_string->subtract( days => 1 )->truncate( to => 'day' ),
49
                end_date   => undef
50
            }
51
        }
52
    );
53
54
    $builder->build_object(
55
        {
56
            class => 'Koha::Bookings',
57
            value => {
58
                biblio_id  => $biblio->biblionumber,
59
                start_date => dt_from_string->add( days => 1 )->truncate( to => 'day' ),
60
                end_date   => undef
61
            }
62
        }
63
    );
64
65
    $builder->build_object(
66
        {
67
            class => 'Koha::Bookings',
68
            value => {
69
                biblio_id  => $biblio->biblionumber,
70
                start_date => dt_from_string->add( days => 2 )->truncate( to => 'day' ),
71
                end_date   => undef
72
            }
73
        }
74
    );
75
76
    is( $biblio->bookings->filter_by_future->count, 2, 'There should have 2 bookings starting after now' );
77
78
    $schema->storage->txn_rollback;
79
};

Return to bug 35788