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

(-)a/admin/float_limits.pl (+83 lines)
Line 0 Link Here
1
## Please see file perltidy.ERR
2
## Please see file perltidy.ERR
3
## Please see file perltidy.ERR
4
## Please see file perltidy.ERR
5
#!/usr/bin/perl
6
# Copyright 2023 ByWater Solutions
7
#
8
# This file is part of Koha.
9
#
10
# Koha is free software; you can redistribute it and/or modify it
11
# under the terms of the GNU General Public License as published by
12
# the Free Software Foundation; either version 3 of the License, or
13
# (at your option) any later version.
14
#
15
# Koha is distributed in the hope that it will be useful, but
16
# WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU General Public License for more details.
19
#
20
# You should have received a copy of the GNU General Public License
21
# along with Koha; if not, see <http://www.gnu.org/licenses>.
22
23
use Modern::Perl;
24
use CGI qw ( -utf8 );
25
26
use C4::Context;
27
use C4::Output qw( output_html_with_http_headers );
28
use C4::Auth qw( get_template_and_user );
29
30
use Koha::ItemTypes;
31
use Koha::Libraries;
32
use Koha::Library::FloatLimits;
33
34
my $input = CGI->new;
35
36
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
37
    {
38
        template_name => "admin/float_limits.tt",
39
        query         => $input,
40
        type          => "intranet",
41
        flagsrequired => { parameters => 'manage_transfers' },
42
    }
43
);
44
45
my $op = $input->param('op');
46
47
if ( $op eq 'set_float_limits' ) {
48
    my $schema    = Koha::Database->new()->schema();
49
    my @branches  = Koha::Libraries->search()->as_list;
50
    my @itemtypes = Koha::ItemTypes->search()->as_list;
51
52
    $schema->txn_do(
53
        sub {
54
            $schema->storage->dbh->do("DELETE FROM library_float_limits");
55
            foreach my $branch (@branches) {
56
                foreach my $itemtype (@itemtypes) {
57
                    my $branchcode = $branch->id;
58
                    my $itype      = $itemtype->id;
59
60
                    my $limit = $input->param( "limit_" . $branchcode . "_" . $itype );
61
                    Koha::Library::FloatLimit->new(
62
                        {
63
                            branchcode => $branchcode,
64
                            itemtype   => $itype,
65
                            limit      => $limit
66
                        }
67
                    )->store()
68
                        if $limit;    # update or insert
69
                }
70
            }
71
            $template->param( float_limits_updated => 1 );
72
        }
73
    );
74
}
75
76
my $limits_hash = {};
77
my $limits      = Koha::Library::FloatLimits->search();
78
while ( my $l = $limits->next ) {
79
    $limits_hash->{ $l->branchcode }->{ $l->itemtype } = $l->limit;
80
}
81
$template->param( limits => $limits_hash );
82
83
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/float_limits.tt (-1 / +132 lines)
Line 0 Link Here
0
- 
1
[% USE raw %]
2
[% USE Asset %]
3
[% USE Branches %]
4
[% USE ItemTypes %]
5
[% USE Koha %]
6
[% SET footerjs = 1 %]
7
[% PROCESS 'i18n.inc' %]
8
[% INCLUDE 'doc-head-open.inc' %]
9
<title>[% FILTER collapse %]
10
    [% t("Library float limits") | html %] &rsaquo;
11
    [% t("Administration") | html %] &rsaquo;
12
    [% t("Koha") | html %]
13
[% END %]</title>
14
[% INCLUDE 'doc-head-close.inc' %]
15
<style>
16
.disabled-transfer {
17
    background-color: #FF8888;
18
}
19
</style>
20
</head>
21
22
<body id="admin_library_float_limits" class="admin">
23
[% WRAPPER 'header.inc' %]
24
    [% INCLUDE 'prefs-admin-search.inc' %]
25
[% END %]
26
27
[% WRAPPER 'sub-header.inc' %]
28
    [% WRAPPER breadcrumbs %]
29
        [% WRAPPER breadcrumb_item %]
30
            <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
31
        [% END %]
32
        [% WRAPPER breadcrumb_item bc_active= 1 %]
33
            <span>Library float limits</span>
34
        [% END %]
35
    [% END #/ WRAPPER breadcrumbs %]
36
[% END #/ WRAPPER sub-header.inc %]
37
38
<div class="main container-fluid">
39
    <div class="row">
40
        <div class="col-sm-10 col-sm-push-2">
41
            <main>
42
43
                <h1 class="parameters">
44
                    Library float limits
45
                </h1>
46
47
                [% UNLESS Koha.Preference('UseLibraryFloatLimits') %]
48
                    <div class="dialog message">
49
                        <p>Because the "UseLibraryFloatLimits" system preference is currently not enabled, float limits will not be enforced.</p>
50
                        <p>
51
                        Go to the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&amp;searchfield=UseLibraryFloatLimits">UseLibraryFloatLimits</a>
52
                        system preference if you wish to enable this feature.
53
                        </p>
54
                    </div>
55
                [% END %]
56
57
                <form method="post" action="/cgi-bin/koha/admin/float_limits.pl" id="float_limit_form">
58
                    <input type="hidden" name="op" value="set_float_limits" />
59
                    <fieldset id="float_limits">
60
                        <div class="help">
61
                            <p>Specify the total number of items per itemtype that are allowed to float at each library.</p>
62
                            <p>
63
                                When an item is checked in, the librarian will get a request to transfer the item to the library
64
                                with the lowest ratio of items held versus items allowed for that item type if the checkin library
65
                                has reached its' limit for that type of item.
66
                            </p>
67
                            <p>
68
                                If a library and item type combination is left empty, that library will be ignored when finding the
69
                                best library to transfer the item to.
70
                            </p>
71
                        </div>
72
73
                        <div class="form_validation_errors"><span></span></div>
74
75
                        <table>
76
                            <tr>
77
                                <th>Item type \ Library</th>
78
                                [% FOR b IN Branches.all(unfiltered => 1) %]
79
                                    <th>[% b.branchname | html %]</th>
80
                                [% END %]
81
                            </tr>
82
83
                            [% FOR i IN ItemTypes.Get() %]
84
                                <tr>
85
                                    <th>[% i.description | html %]</th>
86
87
                                    [% FOR b IN Branches.all(unfiltered => 1) %]
88
                                        <td>
89
                                            [% SET bc = b.branchcode %]
90
                                            [% SET it = i.itemtype %]
91
                                            <input name="limit_[% bc | html %]_[% it | html %]" size="4" class="float_limit" value="[% limits.$bc.$it | html %]" />
92
                                        </td>
93
                                    [% END %]
94
                                </tr>
95
                            [% END %]
96
                        </table>
97
                    </fieldset>
98
99
                        <div class="form_validation_errors"><span></span></div>
100
101
                    <fieldset class="action">
102
                        <input type="submit" class="btn btn-primary" value="Save" /> <a href="/cgi-bin/koha/admin/float_limits.pl" class="cancel">Cancel</a>
103
                    </fieldset>
104
                </form>
105
106
            </main>
107
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
108
109
        <div class="col-sm-2 col-sm-pull-10">
110
            <aside>
111
                [% INCLUDE 'admin-menu.inc' %]
112
            </aside>
113
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
114
    </div> <!-- /.row -->
115
116
[% MACRO jsinclude BLOCK %]
117
    [% Asset.js("js/admin-menu.js") | $raw %]
118
    <script>
119
        $(document).ready(function(){
120
            jQuery.validator.addClassRules("float_limit", {
121
                digits: true
122
            });
123
124
            $("#float_limit_form").validate({
125
                errorContainer: ".form_validation_errors",
126
                errorLabelContainer: ".form_validation_errors span",
127
            });
128
        });
129
    </script>
130
[% END %]
131
132
[% INCLUDE 'intranet-bottom.inc' %]

Return to bug 28530