From 9bee10f89a119524aadb1d03904edb2970bfbce2 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 Signed-off-by: Andrew Fuerste-Henry --- admin/float_limits.pl | 83 ++++++++++++ .../prog/en/includes/admin-menu.inc | 67 +++++----- .../prog/en/modules/admin/float_limits.tt | 125 ++++++++++++++++++ 3 files changed, 242 insertions(+), 33 deletions(-) create mode 100644 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 100644 index 00000000000..30d9f9bffdb --- /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, + float_limit => $limit, + } + )->store() + if $limit ne q{}; # 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->float_limit; +} +$template->param( limits => $limits_hash ); + +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc index 464dbf7a568..b6a4d1324b4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc @@ -24,39 +24,40 @@ [% END %] - [% IF ( CAN_user_parameters_manage_patron_categories || CAN_user_parameters_manage_circ_rules || CAN_user_parameters_manage_patron_attributes || CAN_user_parameters_manage_transfers || CAN_user_parameters_manage_item_circ_alerts || CAN_user_parameters_manage_cities || CAN_user_parameters_manage_curbside_pickups || CAN_user_parameters_manage_patron_restrictions ) %] -
Patrons and circulation
- - [% END %] + [% IF ( CAN_user_parameters_manage_patron_categories || CAN_user_parameters_manage_circ_rules || CAN_user_parameters_manage_patron_attributes || CAN_user_parameters_manage_transfers || CAN_user_parameters_manage_item_circ_alerts || CAN_user_parameters_manage_cities || CAN_user_parameters_manage_curbside_pickups || CAN_user_parameters_manage_patron_restrictions ) %] +
Patrons and circulation
+ + [% END %] [% IF ( CAN_user_parameters_manage_accounts || ( Koha.Preference('UseCashRegisters') && CAN_user_parameters_manage_cash_registers ) ) %]
Accounting
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..5b051e13a6b --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/float_limits.tt @@ -0,0 +1,125 @@ +[% 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.39.5