Bug 20772: Display and edit of price_paid
[koha.git] / catalogue / stockrotation.pl
blob8b6a32451f0f26ae17662c4d923a49875b6352af
1 #!/usr/bin/perl
3 # Copyright 2016 PTFS-Europe Ltd
5 # This file is part of Koha.
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.
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.
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.
20 =head1 stockrotation.pl
22 Script to manage item assignments to stock rotation rotas. Including their
23 assiciated stages
25 =cut
27 use Modern::Perl;
28 use CGI;
30 use C4::Auth;
31 use C4::Output;
32 use C4::Search;
34 use Koha::Biblio;
35 use Koha::Item;
36 use Koha::StockRotationRotas;
37 use Koha::StockRotationStages;
38 use Koha::Util::StockRotation qw(:ALL);
40 my $input = new CGI;
42 unless (C4::Context->preference('StockRotation')) {
43 # redirect to Intranet home if self-check is not enabled
44 print $input->redirect("/cgi-bin/koha/mainpage.pl");
45 exit;
48 my %params = $input->Vars();
50 my $op = $params{op};
52 my $biblionumber = $input->param('biblionumber');
54 my ($template, $loggedinuser, $cookie) = get_template_and_user(
56 template_name => 'catalogue/stockrotation.tt',
57 query => $input,
58 type => 'intranet',
59 authnotrequired => 0,
60 flagsrequired => {
61 catalogue => 1,
62 stockrotation => 'manage_rota_items',
67 if (!defined $op) {
69 # List all items along with their associated rotas
70 my $biblio = Koha::Biblios->find($biblionumber);
72 my $items = $biblio->items;
74 # Get only rotas with stages
75 my $rotas = Koha::StockRotationRotas->search(
77 'stockrotationstages.stage_id' => { '!=', undef }
80 join => 'stockrotationstages',
81 collapse => 1,
82 order_by => 'title'
86 # Construct a model to pass to the view
87 my @item_data = ();
89 while (my $item = $items->next) {
91 my $item_hashref = {
92 bib_item => $item
95 my $stockrotationitem = $item->stockrotationitem;
97 # If this item is on a rota
98 if ($stockrotationitem != 0) {
100 # This item's rota
101 my $rota = $stockrotationitem->stage->rota;
103 # This rota's stages
104 my $stages = get_stages($rota);
106 $item_hashref->{rota} = $rota;
108 $item_hashref->{stockrotationitem} = $stockrotationitem;
110 $item_hashref->{stages} = $stages;
114 push @item_data, $item_hashref;
118 $template->param(
119 no_op_set => 1,
120 rotas => $rotas,
121 items => \@item_data,
122 branches => get_branches(),
123 biblio => $biblio,
124 biblionumber => $biblio->biblionumber,
125 stockrotationview => 1,
126 C4::Search::enabled_staff_search_views
129 } elsif ($op eq "toggle_in_demand") {
131 # Toggle in demand
132 toggle_indemand($params{item_id}, $params{stage_id});
134 # Return to items list
135 print $input->redirect("?biblionumber=$biblionumber");
137 } elsif ($op eq "remove_item_from_stage") {
139 # Remove from the stage
140 remove_from_stage($params{item_id}, $params{stage_id});
142 # Return to items list
143 print $input->redirect("?biblionumber=$biblionumber");
145 } elsif ($op eq "move_to_next_stage") {
147 move_to_next_stage($params{item_id}, $params{stage_id});
149 # Return to items list
150 print $input->redirect("?biblionumber=" . $params{biblionumber});
152 } elsif ($op eq "add_item_to_rota") {
154 my $item = Koha::Items->find($params{item_id});
156 $item->add_to_rota($params{rota_id});
158 print $input->redirect("?biblionumber=" . $params{biblionumber});
160 } elsif ($op eq "confirm_remove_from_rota") {
162 $template->param(
163 op => $params{op},
164 stage_id => $params{stage_id},
165 item_id => $params{item_id},
166 biblionumber => $params{biblionumber},
167 stockrotationview => 1,
168 C4::Search::enabled_staff_search_views
173 output_html_with_http_headers $input, $cookie, $template->output;
175 =head1 AUTHOR
177 Andrew Isherwood <andrew.isherwood@ptfs-europe.com>
179 =cut