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

(-)a/Koha/Library/FloatLimit.pm (+46 lines)
Line 0 Link Here
1
package Koha::Library::FloatLimit;
2
3
# Copyright ByWater Solutions 2023
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 base qw(Koha::Object);
23
24
=head1 NAME
25
26
Koha::Library::FloatLimit - Koha Library::FloatLimit object class
27
28
=head1 API
29
30
=head2 Internal methods
31
32
=head3 _type
33
34
=cut
35
36
sub _type {
37
    return 'LibraryFloatLimit';
38
}
39
40
=head1 AUTHOR
41
42
Kyle M Hall <kyle@bywatersolutions.com>
43
44
=cut
45
46
1;
(-)a/Koha/Library/FloatLimits.pm (-1 / +102 lines)
Line 0 Link Here
0
- 
1
package Koha::Library::FloatLimits;
2
3
# Copyright ByWater Solutions 2016
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 Koha::Database;
23
24
use Koha::Library::FloatLimit;
25
use C4::Circulation qw(IsBranchTransferAllowed);
26
27
use base qw(Koha::Objects);
28
29
=head1 NAME
30
31
Koha::Library::FloatLimits - Koha Library::FloatLimit object set class
32
33
=head1 API
34
35
=head2 Class Methods
36
37
=head3 lowest_ratio_library
38
39
=cut
40
41
sub lowest_ratio_library {
42
    my ( $self, $item, $branchcode ) = @_;
43
44
    my $field = C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype';
45
    my $query = qq{
46
        SELECT branchcode
47
        FROM library_float_limits
48
        LEFT JOIN items ON ( items.itype = library_float_limits.itemtype AND items.holdingbranch = library_float_limits.branchcode )
49
        LEFT JOIN biblioitems ON ( items.biblioitemnumber = biblioitems.biblioitemnumber )
50
        WHERE library_float_limits.itemtype = ?
51
              AND ( $field = ? OR $field IS NULL )
52
              AND library_float_limits.float_limit != 0
53
        GROUP BY branchcode
54
        ORDER BY COUNT(items.holdingbranch)/library_float_limits.float_limit ASC, library_float_limits.float_limit DESC;
55
    };
56
57
    my $results = C4::Context->dbh->selectall_arrayref(
58
        $query, { Slice => {} }, $item->effective_itemtype,
59
        $item->effective_itemtype
60
    );
61
62
    my $UseBranchTransferLimits = C4::Context->preference("UseBranchTransferLimits");
63
    my $BranchTransferLimitsType =
64
        C4::Context->preference("BranchTransferLimitsType") eq 'itemtype' ? 'effective_itemtype' : 'ccode';
65
66
    foreach my $r (@$results) {
67
        if ($UseBranchTransferLimits) {
68
            my $allowed = C4::Circulation::IsBranchTransferAllowed(
69
                $r->{branchcode},    # to
70
                $branchcode,         # from
71
                $item->$BranchTransferLimitsType
72
            );
73
            return $r->{branchcode} if $allowed;
74
        } else {
75
            return $r->{branchcode};
76
        }
77
    }
78
}
79
80
=head3 _type
81
82
=cut
83
84
sub _type {
85
    return 'LibraryFloatLimit';
86
}
87
88
=head3 object_class
89
90
=cut
91
92
sub object_class {
93
    return 'Koha::Library::FloatLimit';
94
}
95
96
=head1 AUTHOR
97
98
Kyle M Hall <kyle@bywatersolutions.com>
99
100
=cut
101
102
1;

Return to bug 28530