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 / +103 lines)
Line 0 Link Here
0
- 
1
## Please see file perltidy.ERR
2
## Please see file perltidy.ERR
3
package Koha::Library::FloatLimits;
4
5
# Copyright ByWater Solutions 2016
6
#
7
# This file is part of Koha.
8
#
9
# Koha is free software; you can redistribute it and/or modify it
10
# under the terms of the GNU General Public License as published by
11
# the Free Software Foundation; either version 3 of the License, or
12
# (at your option) any later version.
13
#
14
# Koha is distributed in the hope that it will be useful, but
15
# WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
18
#
19
# You should have received a copy of the GNU General Public License
20
# along with Koha; if not, see <http://www.gnu.org/licenses>.
21
22
use Modern::Perl;
23
24
use Koha::Database;
25
26
use Koha::Library::FloatLimit;
27
use C4::Circulation qw(IsBranchTransferAllowed);
28
29
use base qw(Koha::Objects);
30
31
=head1 NAME
32
33
Koha::Library::FloatLimits - Koha Library::FloatLimit object set class
34
35
=head1 API
36
37
=head2 Class Methods
38
39
=head3 lowest_ratio_library
40
41
=cut
42
43
sub lowest_ratio_library {
44
    my ( $self, $item, $branchcode ) = @_;
45
46
    my $field = C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype';
47
    my $query = qq{
48
        SELECT branchcode
49
        FROM library_float_limits
50
        LEFT JOIN items ON ( items.itype = library_float_limits.itemtype AND items.holdingbranch = library_float_limits.branchcode )
51
        LEFT JOIN biblioitems ON ( items.biblioitemnumber = biblioitems.biblioitemnumber )
52
        WHERE library_float_limits.itemtype = ?
53
              AND $field = ?
54
        GROUP BY branchcode
55
        ORDER BY COUNT(items.holdingbranch)/library_float_limits.limit
56
    };
57
58
    my $results = C4::Context->dbh->selectall_arrayref(
59
        $query, { Slice => {} }, $item->effective_itemtype,
60
        $item->effective_itemtype
61
    );
62
63
    my $UseBranchTransferLimits = C4::Context->preference("UseBranchTransferLimits");
64
    my $BranchTransferLimitsType =
65
        C4::Context->preference("BranchTransferLimitsType") eq 'itemtype' ? 'effective_itemtype' : 'ccode';
66
67
    foreach my $r (@$results) {
68
        if ($UseBranchTransferLimits) {
69
            my $allowed = C4::Circulation::IsBranchTransferAllowed(
70
                $r->{branchcode},    # to
71
                $branchcode,         # from
72
                $item->$BranchTransferLimitsType
73
            );
74
            return $r->{branchcode} if $allowed;
75
        } else {
76
            return $r->{branchcode};
77
        }
78
    }
79
}
80
81
=head3 _type
82
83
=cut
84
85
sub _type {
86
    return 'LibraryFloatLimit';
87
}
88
89
=head3 object_class
90
91
=cut
92
93
sub object_class {
94
    return 'Koha::Library::FloatLimit';
95
}
96
97
=head1 AUTHOR
98
99
Kyle M Hall <kyle@bywatersolutions.com>
100
101
=cut
102
103
1;

Return to bug 28530