2013-01-12 16:14:06 +01:00
|
|
|
# encoding: utf-8
|
|
|
|
class StockitSelectionsController < ApplicationController
|
|
|
|
|
|
|
|
def index
|
2013-01-28 20:46:35 +01:00
|
|
|
@stock_article_selections = StockArticleSelection.find(:all, :order => 'created_at DESC')
|
2013-01-12 16:14:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@stock_article_selection = StockArticleSelection.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@stock_article_selection = StockArticleSelection.new(params[:stock_article_selection])
|
|
|
|
@stock_article_selection.created_by = current_user
|
|
|
|
|
|
|
|
if @stock_article_selection.save
|
2013-01-28 20:46:35 +01:00
|
|
|
redirect_to(@stock_article_selection, :notice => 'Löschvorschlag für gewählte Artikel erstellt.')
|
2013-01-12 16:14:06 +01:00
|
|
|
else
|
2013-01-28 20:46:35 +01:00
|
|
|
@stock_articles = StockArticle.elements_for_index
|
2013-01-12 16:14:06 +01:00
|
|
|
render 'stockit/index'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-28 20:46:35 +01:00
|
|
|
def destroy # destroy selection without deleting articles
|
2013-01-12 16:14:06 +01:00
|
|
|
stock_article_selection = StockArticleSelection.find(params[:id])
|
|
|
|
stock_article_selection.destroy
|
|
|
|
|
2013-01-28 20:46:35 +01:00
|
|
|
redirect_to stock_article_selections_path, :notice => 'Löschvorschlag verworfen.'
|
2013-01-12 16:14:06 +01:00
|
|
|
end
|
|
|
|
|
2013-01-28 20:46:35 +01:00
|
|
|
def articles # destroy articles
|
2013-01-12 16:14:06 +01:00
|
|
|
stock_article_selection = StockArticleSelection.find(params[:id])
|
|
|
|
|
|
|
|
destroyed_articles_count = 0
|
|
|
|
failed_articles_count = 0
|
|
|
|
stock_article_selection.stock_articles.each do |article|
|
|
|
|
begin
|
2013-01-28 20:46:35 +01:00
|
|
|
article.destroy
|
2013-01-12 16:14:06 +01:00
|
|
|
destroyed_articles_count += 1
|
|
|
|
rescue => error # recover if article.destroy fails and continue with next article
|
|
|
|
failed_articles_count += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-28 20:46:35 +01:00
|
|
|
if destroyed_articles_count > 0
|
|
|
|
flash[:notice] = "#{destroyed_articles_count} gewählte Artikel gelöscht."
|
2013-01-12 16:14:06 +01:00
|
|
|
flash[:error] = "#{failed_articles_count} Artikel konnten nicht gelöscht werden." unless 0==failed_articles_count
|
|
|
|
else
|
2013-01-28 20:46:35 +01:00
|
|
|
flash[:error] = 'Löschvorgang fehlgeschlagen. Keine Artikel gelöscht.'
|
2013-01-12 16:14:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to stock_articles_path
|
|
|
|
end
|
2013-01-28 20:46:35 +01:00
|
|
|
|
|
|
|
def finished # delete all finished selections
|
|
|
|
finished_selections = StockArticleSelection.all.select { |sel| sel.deletable_count + sel.nondeletable_count <= 0 }
|
|
|
|
finished_selections.each { |sel| sel.destroy }
|
|
|
|
|
|
|
|
redirect_to stock_article_selections_path, :notice => 'Alle erledigten Löschvorschläge entfernt.'
|
|
|
|
end
|
2013-01-12 16:14:06 +01:00
|
|
|
end
|