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
|
2009-10-17 20:33:36 +02:00
|
|
|
@stock_articles = StockArticle.without_deleted.all(
|
2009-08-04 13:35:52 +02:00
|
|
|
:include => [: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
|
2009-02-12 18:32:20 +01:00
|
|
|
flash[:notice] = "Lagerartikel wurde gespeichert."
|
2009-02-11 18:09:04 +01:00
|
|
|
redirect_to stock_articles_path
|
|
|
|
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])
|
2009-02-12 18:32:20 +01:00
|
|
|
flash[:notice] = "Lagerartikel wurde gespeichert."
|
2009-02-11 18:09:04 +01:00
|
|
|
redirect_to stock_articles_path
|
|
|
|
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
|
|
|
|
|
|
|
|
def auto_complete_for_article_name
|
2009-02-12 18:32:20 +01:00
|
|
|
conditions = [ "LOWER(articles.name) LIKE ?", '%' + params[:article][:name].downcase + '%' ]
|
|
|
|
|
|
|
|
if params[:supplier_id]
|
|
|
|
@supplier = Supplier.find(params[:supplier_id])
|
|
|
|
@articles = @supplier.articles.without_deleted.all(:conditions => conditions, :limit => 8)
|
|
|
|
else
|
|
|
|
@articles = Article.without_deleted.not_in_stock.all(:conditions => conditions, :limit => 8)
|
|
|
|
end
|
2009-02-11 18:09:04 +01:00
|
|
|
render :partial => 'shared/auto_complete_articles'
|
|
|
|
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
|