|
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 = ? OR $field IS NULL ) |
| 54 |
AND library_float_limits.float_limit != 0 |
| 55 |
GROUP BY branchcode |
| 56 |
ORDER BY COUNT(items.holdingbranch)/library_float_limits.float_limit ASC, library_float_limits.float_limit DESC; |
| 57 |
}; |
| 58 |
|
| 59 |
my $results = C4::Context->dbh->selectall_arrayref( |
| 60 |
$query, { Slice => {} }, $item->effective_itemtype, |
| 61 |
$item->effective_itemtype |
| 62 |
); |
| 63 |
|
| 64 |
my $UseBranchTransferLimits = C4::Context->preference("UseBranchTransferLimits"); |
| 65 |
my $BranchTransferLimitsType = |
| 66 |
C4::Context->preference("BranchTransferLimitsType") eq 'itemtype' ? 'effective_itemtype' : 'ccode'; |
| 67 |
|
| 68 |
foreach my $r (@$results) { |
| 69 |
if ($UseBranchTransferLimits) { |
| 70 |
my $allowed = C4::Circulation::IsBranchTransferAllowed( |
| 71 |
$r->{branchcode}, # to |
| 72 |
$branchcode, # from |
| 73 |
$item->$BranchTransferLimitsType |
| 74 |
); |
| 75 |
return $r->{branchcode} if $allowed; |
| 76 |
} else { |
| 77 |
return $r->{branchcode}; |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
=head3 _type |
| 83 |
|
| 84 |
=cut |
| 85 |
|
| 86 |
sub _type { |
| 87 |
return 'LibraryFloatLimit'; |
| 88 |
} |
| 89 |
|
| 90 |
=head3 object_class |
| 91 |
|
| 92 |
=cut |
| 93 |
|
| 94 |
sub object_class { |
| 95 |
return 'Koha::Library::FloatLimit'; |
| 96 |
} |
| 97 |
|
| 98 |
=head1 AUTHOR |
| 99 |
|
| 100 |
Kyle M Hall <kyle@bywatersolutions.com> |
| 101 |
|
| 102 |
=cut |
| 103 |
|
| 104 |
1; |