2009-01-18 17:42:51 +01:00
|
|
|
class StockitController < ApplicationController
|
2009-02-11 18:09:04 +01:00
|
|
|
|
2009-01-18 17:42:51 +01:00
|
|
|
def index
|
2013-01-28 20:46:35 +01:00
|
|
|
@stock_articles = StockArticle.elements_for_index
|
2013-01-12 16:14:06 +01:00
|
|
|
@stock_article_selection = StockArticleSelection.new
|
2009-02-11 18:09:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2009-02-12 18:32:20 +01:00
|
|
|
@stock_article = StockArticle.new
|
2009-02-11 18:09:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@stock_article = StockArticle.new(params[:stock_article])
|
|
|
|
if @stock_article.save
|
2011-05-27 14:09:01 +02:00
|
|
|
redirect_to stock_articles_path, :notice => "Lagerartikel wurde gespeichert."
|
2009-02-11 18:09:04 +01:00
|
|
|
else
|
|
|
|
render :action => 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@stock_article = StockArticle.find(params[:id])
|
2009-01-18 17:42:51 +01:00
|
|
|
end
|
|
|
|
|
2009-02-11 18:09:04 +01:00
|
|
|
def update
|
|
|
|
@stock_article = StockArticle.find(params[:id])
|
|
|
|
if @stock_article.update_attributes(params[:stock_article])
|
2011-05-27 14:09:01 +02:00
|
|
|
redirect_to stock_articles_path, :notice => "Lagerartikel wurde gespeichert."
|
2009-02-11 18:09:04 +01:00
|
|
|
else
|
|
|
|
render :action => 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
StockArticle.find(params[:id]).destroy
|
|
|
|
redirect_to stock_articles_path
|
|
|
|
rescue => error
|
|
|
|
flash[:error] = "Ein Fehler ist aufgetreten: " + error.message
|
|
|
|
redirect_to stock_articles_path
|
|
|
|
end
|
|
|
|
|
2011-05-27 14:09:01 +02:00
|
|
|
#TODO: Fix this!!
|
|
|
|
def articles_search
|
2012-09-30 21:15:55 +02:00
|
|
|
@articles = Article.not_in_stock.limit(8).where('name LIKE ?', "%#{params[:term]}%")
|
2011-05-27 14:09:01 +02:00
|
|
|
render :json => @articles.map(&:name)
|
2009-02-11 18:09:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def fill_new_stock_article_form
|
|
|
|
article = Article.find(params[:article_id])
|
|
|
|
@supplier = article.supplier
|
|
|
|
stock_article = @supplier.stock_articles.build(
|
|
|
|
article.attributes.reject { |attr| attr == ('id' || 'type')}
|
|
|
|
)
|
|
|
|
|
|
|
|
render :partial => 'form', :locals => {:stock_article => stock_article}
|
|
|
|
end
|
2009-01-18 17:42:51 +01:00
|
|
|
end
|