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 |