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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 =head1 stockrotation.pl
22 Script to manage item assignments to stock rotation rotas. Including their
37 use Koha
::StockRotationRotas
;
38 use Koha
::StockRotationStages
;
39 use Koha
::Util
::StockRotation
qw(:ALL);
43 unless (C4
::Context
->preference('StockRotation')) {
44 # redirect to Intranet home if self-check is not enabled
45 print $input->redirect("/cgi-bin/koha/mainpage.pl");
49 my %params = $input->Vars();
53 my $biblionumber = $input->param('biblionumber');
55 my ($template, $loggedinuser, $cookie) = get_template_and_user
(
57 template_name
=> 'catalogue/stockrotation.tt',
63 stockrotation
=> 'manage_rota_items',
70 # List all items along with their associated rotas
71 my $biblio = Koha
::Biblios
->find($biblionumber);
73 my $items = $biblio->items;
75 # Get only rotas with stages
76 my $rotas = Koha
::StockRotationRotas
->search(
78 'stockrotationstages.stage_id' => { '!=', undef }
81 join => 'stockrotationstages',
87 # Construct a model to pass to the view
90 while (my $item = $items->next) {
96 my $stockrotationitem = $item->stockrotationitem;
98 # If this item is on a rota
99 if ($stockrotationitem != 0) {
102 my $rota = $stockrotationitem->stage->rota;
105 my $stages = get_stages
($rota);
107 $item_hashref->{rota
} = $rota;
109 $item_hashref->{stockrotationitem
} = $stockrotationitem;
111 $item_hashref->{stages
} = $stages;
115 push @item_data, $item_hashref;
122 items
=> \
@item_data,
123 branches
=> get_branches
(),
125 biblionumber
=> $biblio->biblionumber,
126 stockrotationview
=> 1,
127 subscriptionsnumber
=> CountSubscriptionFromBiblionumber
($biblionumber),
128 C4
::Search
::enabled_staff_search_views
131 } elsif ($op eq "toggle_in_demand") {
134 toggle_indemand
($params{item_id
}, $params{stage_id
});
136 # Return to items list
137 print $input->redirect("?biblionumber=$biblionumber");
139 } elsif ($op eq "remove_item_from_stage") {
141 # Remove from the stage
142 remove_from_stage
($params{item_id
}, $params{stage_id
});
144 # Return to items list
145 print $input->redirect("?biblionumber=$biblionumber");
147 } elsif ($op eq "move_to_next_stage") {
149 move_to_next_stage
($params{item_id
}, $params{stage_id
});
151 # Return to items list
152 print $input->redirect("?biblionumber=" . $params{biblionumber
});
154 } elsif ($op eq "add_item_to_rota") {
156 my $item = Koha
::Items
->find($params{item_id
});
158 $item->add_to_rota($params{rota_id
});
160 print $input->redirect("?biblionumber=" . $params{biblionumber
});
162 } elsif ($op eq "confirm_remove_from_rota") {
166 stage_id
=> $params{stage_id
},
167 item_id
=> $params{item_id
},
168 biblionumber
=> $params{biblionumber
},
169 stockrotationview
=> 1,
170 subscriptionsnumber
=> CountSubscriptionFromBiblionumber
($biblionumber),
171 C4
::Search
::enabled_staff_search_views
176 output_html_with_http_headers
$input, $cookie, $template->output;
180 Andrew Isherwood <andrew.isherwood@ptfs-europe.com>