Bug 14251: Allow use of CSS in discharge letter
[koha-ffzg.git] / tools / stockrotation.pl
index 8317617..ec60a17 100755 (executable)
 use Modern::Perl;
 use CGI;
 
-use C4::Auth;
+use C4::Auth qw( get_template_and_user );
 use C4::Context;
-use C4::Output;
+use C4::Output qw( output_html_with_http_headers );
 
 use Koha::Libraries;
 use Koha::StockRotationRotas;
 use Koha::StockRotationItems;
 use Koha::StockRotationStages;
 use Koha::Item;
-use Koha::Util::StockRotation qw(:ALL);
+use Koha::Util::StockRotation qw( get_branches get_stages move_to_next_stage toggle_indemand remove_from_stage add_items_to_rota get_barcodes_status );
 
-my $input = new CGI;
+my $input = CGI->new;
 
 unless (C4::Context->preference('StockRotation')) {
     # redirect to Intranet home if self-check is not enabled
@@ -193,6 +193,42 @@ if (!defined $op) {
         item_id  => $params{item_id}
     );
 
+} elsif ($op eq 'confirm_delete_rota') {
+
+    # Get the rota we're deleting
+    my $rota = Koha::StockRotationRotas->find($params{rota_id});
+
+    # Get all items on this rota, for each prefetch their
+    # stage and biblio objects
+    my $sritems = Koha::StockRotationItems->search(
+        { 'stage.rota_id' => $params{rota_id} },
+        {
+            prefetch => {
+                stage => {
+                    'stockrotationitems' => {
+                        'itemnumber' => 'biblionumber'
+                    }
+                }
+            }
+        }
+    );
+
+    $template->param(
+        rota_id  => $params{rota_id},
+        sritemstotal  => $sritems->count,
+        op       => $op
+    );
+
+} elsif ($op eq 'delete_rota') {
+
+    # Get the rota we're deleting
+    my $rota = Koha::StockRotationRotas->find($params{rota_id});
+
+    $rota->delete;
+
+    # Return to the rotas list
+    print $input->redirect("/cgi-bin/koha/tools/stockrotation.pl");
+
 } elsif ($op eq 'confirm_delete_stage') {
 
     # Get the stage we're deleting
@@ -252,7 +288,7 @@ if (!defined $op) {
 
     # Get all items on this rota, for each prefetch their
     # stage and biblio objects
-    my $items = Koha::StockRotationItems->search(
+    my $sritems = Koha::StockRotationItems->search(
         { 'stage.rota_id' => $params{rota_id} },
         {
             prefetch => {
@@ -268,7 +304,7 @@ if (!defined $op) {
     $template->param(
         rota_id  => $params{rota_id},
         error    => $params{error},
-        items    => $items,
+        sritems  => $sritems,
         branches => get_branches(),
         stages   => get_stages($rota),
         rota     => $rota,
@@ -376,7 +412,7 @@ if (!defined $op) {
 } elsif ($op eq 'move_items_to_rota') {
 
     # The barcodes of the items we're moving
-    my @move = $input->param('move_item');
+    my @move = $input->multi_param('move_item');
 
     foreach my $item(@move) {