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-02-25 10:13:44 +01:00
|
|
|
@stock_articles = StockArticle.includes(:supplier, :article_category).
|
|
|
|
order('suppliers.name, article_categories.name, articles.name')
|
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
|
2013-02-25 11:12:28 +01:00
|
|
|
@article = StockArticle.find(params[:id])
|
|
|
|
@article.destroy
|
|
|
|
render :layout => false
|
2009-02-11 18:09:04 +01:00
|
|
|
rescue => error
|
2013-02-25 10:02:21 +01:00
|
|
|
render :partial => "destroy_fail", :layout => false,
|
|
|
|
:locals => { :fail_msg => "Ein Fehler ist aufgetreten: " + error.message }
|
2009-02-11 18:09:04 +01:00
|
|
|
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
|