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

(-)a/catalogue/stockrotation.pl (+169 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2016 PTFS-Europe Ltd
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
=head1 stockrotation.pl
21
22
 Script to manage item assignments to stock rotation rotas. Including their
23
 assiciated stages
24
25
=cut
26
27
use Modern::Perl;
28
use CGI;
29
30
use C4::Auth;
31
use C4::Output;
32
use C4::Search;
33
34
use Koha::Biblio;
35
use Koha::Item;
36
use Koha::Stockrotationrotas;
37
use Koha::Stockrotationstages;
38
use Koha::Util::Stockrotation qw(:ALL);
39
40
my $input = new CGI;
41
42
my %params = $input->Vars();
43
44
my $op = $params{op};
45
46
my $biblionumber = $input->param('biblionumber');
47
48
my ($template, $loggedinuser, $cookie) = get_template_and_user(
49
    {
50
        template_name   => 'catalogue/stockrotation.tt',
51
        query           => $input,
52
        type            => 'intranet',
53
        authnotrequired => 0,
54
        flagsrequired   => { catalogue => 1 }
55
    }
56
);
57
58
if (!defined $op) {
59
60
    # List all items along with their associated rotas
61
    my $biblio = Koha::Biblios->find($biblionumber);
62
63
    my $items = $biblio->items;
64
65
    # Get only rotas with stages
66
    my $rotas = Koha::Stockrotationrotas->search(
67
        {
68
            'stockrotationstages.stage_id' => { '!=', undef }
69
        },
70
        {
71
            join     => 'stockrotationstages',
72
            collapse => 1
73
        }
74
    );
75
76
    # Construct a model to pass to the view
77
    my @item_data = ();
78
79
    while (my $item = $items->next) {
80
81
        my $item_hashref = {
82
            bib_item   => $item
83
        };
84
85
        my $stockrotationitem = $item->stockrotationitem;
86
87
        # If this item is on a rota
88
        if ($stockrotationitem != 0) {
89
90
            # This item's rota
91
            my $rota = $stockrotationitem->stage->rota;
92
93
            # This rota's stages
94
            my $stages = get_stages($rota);
95
96
            $item_hashref->{rota} = $rota;
97
98
            $item_hashref->{stockrotationitem} = $stockrotationitem;
99
100
            $item_hashref->{stages} = $stages;
101
102
        }
103
104
        push @item_data, $item_hashref;
105
106
    }
107
108
    $template->param(
109
        no_op_set         => 1,
110
        rotas             => $rotas,
111
        items             => \@item_data,
112
        branches          => get_branches(),
113
        biblio            => $biblio,
114
        biblionumber      => $biblio->biblionumber,
115
        stockrotationview => 1,
116
        C4::Search::enabled_staff_search_views
117
    );
118
119
} elsif ($op eq "toggle_in_demand") {
120
121
    # Toggle in demand
122
    toggle_indemand($params{item_id}, $params{stage_id});
123
124
    # Return to items list
125
    print $input->redirect("?biblionumber=$biblionumber");
126
127
} elsif ($op eq "remove_item_from_stage") {
128
129
    # Remove from the stage
130
    remove_from_stage($params{item_id}, $params{stage_id});
131
132
    # Return to items list
133
    print $input->redirect("?biblionumber=$biblionumber");
134
135
} elsif ($op eq "move_to_next_stage") {
136
137
    move_to_next_stage($params{item_id}, $params{stage_id});
138
139
    # Return to items list
140
    print $input->redirect("?biblionumber=" . $params{biblionumber});
141
142
} elsif ($op eq "add_item_to_rota") {
143
144
    my $item = Koha::Items->find($params{item_id});
145
146
    $item->add_to_rota($params{rota_id});
147
148
    print $input->redirect("?biblionumber=" . $params{biblionumber});
149
150
} elsif ($op eq "confirm_remove_from_rota") {
151
152
    $template->param(
153
        op                => $params{op},
154
        stage_id          => $params{stage_id},
155
        item_id           => $params{item_id},
156
        biblionumber      => $params{biblionumber},
157
        stockrotationview => 1,
158
        C4::Search::enabled_staff_search_views
159
    );
160
161
}
162
163
output_html_with_http_headers $input, $cookie, $template->output;
164
165
=head1 AUTHOR
166
167
Andrew Isherwood <andrew.isherwood@ptfs-europe.com>
168
169
=cut
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/stockrotation.tt (-1 / +157 lines)
Line 0 Link Here
0
- 
1
[% USE Koha %]
2
[% USE Branches %]
3
[% INCLUDE 'doc-head-open.inc' %]
4
<title>Koha &rsaquo; Catalog &rsaquo; Stock rotation details for [% biblio.title %]</title>
5
[% INCLUDE 'doc-head-close.inc' %]
6
[% INCLUDE 'browser-strings.inc' %]
7
<!--[if lt IE 9]>
8
<script type="text/javascript" src="[% interface %]/lib/shims/json2.min.js"></script>
9
<![endif]-->
10
<script type="text/javascript" src="[% interface %]/js/browser.js"></script>
11
<script type="text/javascript">
12
//<![CDATA[
13
    var browser = KOHA.browser('[% searchid %]', parseInt('[% biblionumber %]', 10));
14
    browser.show();
15
//]]>
16
</script>
17
</head>
18
<body id="catalog_stockrotation" class="catalog">
19
[% USE KohaDates %]
20
[% INCLUDE 'header.inc' %]
21
[% INCLUDE 'cat-search.inc' %]
22
23
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a>  &rsaquo; Stock rotation details for <i>[% biblio.title | html %][% FOREACH subtitle IN biblio.subtitles %][% subtitle.subfield %][% END %]</i></div>
24
25
<div id="doc3" class="yui-t2">
26
27
   <div id="bd">
28
    <div id="yui-main">
29
    <div class="yui-b">
30
31
<div id="catalogue_detail_biblio">
32
33
    [% IF no_op_set %]
34
        <h1 class="title">Stock rotation details for [% biblio.title | html %]</h1>
35
        [% IF rotas.count > 0 && items.size > 0 %]
36
37
            <table class="items_table dataTable no-footer" role="grid">
38
                <thead>
39
                    <tr>
40
                        <th>Barcode</th>
41
                        <th>Shelfmark</th>
42
                        <th>Rota</th>
43
                        <th>Rota status</th>
44
                        <th>In transit</th>
45
                        <th>Stages &amp; duration in days<br>(current stage highlighted)</th>
46
                        <th>&nbsp;</th>
47
                    </tr>
48
                </thead>
49
                <tbody>
50
                    [% FOREACH item IN items %]
51
                        <tr>
52
                            <td>[% item.bib_item.barcode %]</td>
53
                            <td>[% item.bib_item.itemcallnumber %]</td>
54
                            <td>
55
                                [% item.rota.title %]
56
                            </td>
57
                            <td>
58
                                [% IF item.rota %]
59
                                    [% IF !item.rota.active %]
60
                                        <span class="highlighted-row">
61
                                    [% END %]
62
                                        [% item.rota.active ? 'Active' : 'Inactive' %]
63
64
                                    [% IF !item.rota.active %]
65
                                        </span>
66
                                    [% END %]
67
                                [% END %]
68
                            </td>
69
                            <td>
70
                                [% item.bib_item.get_transfer ? 'Yes' : 'No' %]
71
                            </td>
72
                            <td>
73
                                [% FOREACH this_stage IN item.stages %]
74
                                    [% IF this_stage.stage_id == item.stockrotationitem.stage.stage_id %]
75
                                        <span class="stage highlight_stage">
76
                                    [% ELSE %]
77
                                        <span class="stage">
78
                                    [% END %]
79
                                    [% Branches.GetName(this_stage.branchcode_id) %] ([% this_stage.duration %])
80
                                    </span>
81
                                    &raquo;
82
                                [% END %]
83
                                [% IF item.stages.size > 0 %]
84
                                    <span class="stage">[% item.rota.cyclical ? 'START' : 'END' %]</span>
85
                                [% END %]
86
                            </td>
87
                            <td class="actions">
88
                                [% IF item.stockrotationitem %]
89
                                    [% in_transit = item.bib_item.get_transfer %]
90
                                    [% IF !in_transit && item.stages.size > 1 %]
91
                                        <a class="btn btn-mini" href="?op=move_to_next_stage&amp;stage_id=[% item.stockrotationitem.stage.stage_id %]&amp;item_id=[% item.bib_item.id %]&amp;biblionumber=[% biblionumber %]">
92
                                    [% ELSE %]
93
                                        <a class="btn btn-mini" disabled>
94
                                    [% END %]
95
                                        <i class="fa fa-arrow-right"></i>
96
                                        Move to next stage
97
                                    </a>
98
                                    [% IF !in_transit %]
99
                                        <a class="btn btn-mini" href="?op=toggle_in_demand&amp;stage_id=[% item.stockrotationitem.stage.stage_id %]&amp;item_id=[% item.bib_item.id %]&amp;biblionumber=[% biblionumber %]">
100
                                    [% ELSE %]
101
                                        <a class="btn btn-mini" disabled>
102
                                    [% END %]
103
                                        <i class="fa fa-fire"></i>
104
                                        [% item.stockrotationitem.indemand ? 'Remove &quot;In demand&quot;' : 'Add &quot;In demand&quot;' %]
105
                                    </a>
106
                                    [% IF !in_transit %]
107
                                        <a class="btn btn-mini" href="?op=confirm_remove_from_rota&amp;stage_id=[% item.stockrotationitem.stage.stage_id %]&amp;item_id=[% item.bib_item.id %]&amp;biblionumber=[% biblionumber %]">
108
                                    [% ELSE %]
109
                                        <a class="btn btn-mini" disabled>
110
                                    [% END %]
111
                                        <i class="fa fa-trash"></i>
112
                                        Remove from rota
113
                                    </a>
114
                                [% ELSE %]
115
                                    <form class="rota_select_form" method="post" enctype="multipart/form-data">
116
                                        <select class="item_select_rota" name="rota_id">
117
                                            [% FOREACH rota IN rotas %]
118
                                                <option value="[% rota.rota_id %]">[% rota.title %]</option>
119
                                            [% END %]
120
                                        </select>
121
                                        <button class="btn btn-mini" type="submit"><i class="fa fa-plus"></i> Add to rota</button>
122
                                        <input type="hidden" name="op" value="add_item_to_rota"></input>
123
                                        <input type="hidden" name="item_id" value="[% item.bib_item.id %]"></input>
124
                                        <input type="hidden" name="biblionumber" value="[% biblionumber %]"></input>
125
                                    </form>
126
                                [% END %]
127
                            </td>
128
                        </tr>
129
                    [% END %]
130
                </tbody>
131
            </table>
132
        [% END %]
133
        [% IF !items || items.size == 0 %]
134
            <h1>No physical items for this record</h1>
135
        [% END %]
136
        [% IF !rotas || rotas.count == 0 %]
137
            <h1>There are no rotas with stages assigned</h1>
138
        [% END %]
139
    [% ELSIF op == 'confirm_remove_from_rota' %]
140
        <div class="dialog alert">
141
            <h3>Are you sure you want to remove this item from it's rota?</h3>
142
            <p>
143
                <a class="btn approve" href="?op=remove_item_from_stage&amp;stage_id=[% stage_id %]&amp;item_id=[% item_id %]&amp;biblionumber=[% biblionumber %]"><i class="fa fa-fw fa-check"></i>Yes</a>
144
                <a class="btn deny" href="?biblionumber=[% biblionumber %]"><i class="fa fa-fw fa-remove"></i>No</a>
145
            </p>
146
        </div>
147
    [% END %]
148
149
</div>
150
151
</div>
152
</div>
153
<div class="yui-b">
154
[% INCLUDE 'biblio-view-menu.inc' %]
155
</div>
156
</div>
157
[% INCLUDE 'intranet-bottom.inc' %]

Return to bug 11897