From 93018bb2aab88756ce21531827f616c5524641a9 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 18 Dec 2023 14:23:09 -0500 Subject: [PATCH] Bug 28530: Add float limits editor --- admin/float_limits.pl | 83 +++++++++++ .../prog/en/modules/admin/float_limits.tt | 132 ++++++++++++++++++ 2 files changed, 215 insertions(+) create mode 100755 admin/float_limits.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/float_limits.tt diff --git a/admin/float_limits.pl b/admin/float_limits.pl new file mode 100755 index 00000000000..c07b24227d6 --- /dev/null +++ b/admin/float_limits.pl @@ -0,0 +1,83 @@ +## Please see file perltidy.ERR +## Please see file perltidy.ERR +## Please see file perltidy.ERR +## Please see file perltidy.ERR +#!/usr/bin/perl +# Copyright 2023 ByWater Solutions +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use CGI qw ( -utf8 ); + +use C4::Context; +use C4::Output qw( output_html_with_http_headers ); +use C4::Auth qw( get_template_and_user ); + +use Koha::ItemTypes; +use Koha::Libraries; +use Koha::Library::FloatLimits; + +my $input = CGI->new; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "admin/float_limits.tt", + query => $input, + type => "intranet", + flagsrequired => { parameters => 'manage_transfers' }, + } +); + +my $op = $input->param('op'); + +if ( $op eq 'set_float_limits' ) { + my $schema = Koha::Database->new()->schema(); + my @branches = Koha::Libraries->search()->as_list; + my @itemtypes = Koha::ItemTypes->search()->as_list; + + $schema->txn_do( + sub { + $schema->storage->dbh->do("DELETE FROM library_float_limits"); + foreach my $branch (@branches) { + foreach my $itemtype (@itemtypes) { + my $branchcode = $branch->id; + my $itype = $itemtype->id; + + my $limit = $input->param( "limit_" . $branchcode . "_" . $itype ); + Koha::Library::FloatLimit->new( + { + branchcode => $branchcode, + itemtype => $itype, + limit => $limit + } + )->store() + if $limit; # update or insert + } + } + $template->param( float_limits_updated => 1 ); + } + ); +} + +my $limits_hash = {}; +my $limits = Koha::Library::FloatLimits->search(); +while ( my $l = $limits->next ) { + $limits_hash->{ $l->branchcode }->{ $l->itemtype } = $l->limit; +} +$template->param( limits => $limits_hash ); + +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/float_limits.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/float_limits.tt new file mode 100644 index 00000000000..454c022ee88 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/float_limits.tt @@ -0,0 +1,132 @@ +[% USE raw %] +[% USE Asset %] +[% USE Branches %] +[% USE ItemTypes %] +[% USE Koha %] +[% SET footerjs = 1 %] +[% PROCESS 'i18n.inc' %] +[% INCLUDE 'doc-head-open.inc' %] +[% FILTER collapse %] + [% t("Library float limits") | html %] › + [% t("Administration") | html %] › + [% t("Koha") | html %] +[% END %] +[% INCLUDE 'doc-head-close.inc' %] + + + + +[% WRAPPER 'header.inc' %] + [% INCLUDE 'prefs-admin-search.inc' %] +[% END %] + +[% WRAPPER 'sub-header.inc' %] + [% WRAPPER breadcrumbs %] + [% WRAPPER breadcrumb_item %] + Administration + [% END %] + [% WRAPPER breadcrumb_item bc_active= 1 %] + Library float limits + [% END %] + [% END #/ WRAPPER breadcrumbs %] +[% END #/ WRAPPER sub-header.inc %] + +
+
+
+
+ +

+ Library float limits +

+ + [% UNLESS Koha.Preference('UseLibraryFloatLimits') %] +
+

Because the "UseLibraryFloatLimits" system preference is currently not enabled, float limits will not be enforced.

+

+ Go to the UseLibraryFloatLimits + system preference if you wish to enable this feature. +

+
+ [% END %] + +
+ +
+
+

Specify the total number of items per itemtype that are allowed to float at each library.

+

+ When an item is checked in, the librarian will get a request to transfer the item to the library + with the lowest ratio of items held versus items allowed for that item type if the checkin library + has reached its' limit for that type of item. +

+

+ If a library and item type combination is left empty, that library will be ignored when finding the + best library to transfer the item to. +

+
+ +
+ + + + + [% FOR b IN Branches.all(unfiltered => 1) %] + + [% END %] + + + [% FOR i IN ItemTypes.Get() %] + + + + [% FOR b IN Branches.all(unfiltered => 1) %] + + [% END %] + + [% END %] +
Item type \ Library[% b.branchname | html %]
[% i.description | html %] + [% SET bc = b.branchcode %] + [% SET it = i.itemtype %] + +
+
+ +
+ +
+ Cancel +
+
+ +
+
+ +
+ +
+
+ +[% MACRO jsinclude BLOCK %] + [% Asset.js("js/admin-menu.js") | $raw %] + +[% END %] + +[% INCLUDE 'intranet-bottom.inc' %] -- 2.30.2