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-03-16 17:53:24 +01:00
|
|
|
@stock_articles = StockArticle.undeleted.includes(:supplier, :article_category).
|
2011-05-27 14:09:01 +02:00
|
|
|
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
|
2013-02-11 11:19:26 +01:00
|
|
|
redirect_to stock_articles_path, :notice => I18n.t('stockit.stock_create.notice')
|
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])
|
2013-02-11 11:19:26 +01:00
|
|
|
redirect_to stock_articles_path, :notice => I18n.t('stockit.stock_update.notice')
|
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])
|
2013-03-16 17:53:24 +01:00
|
|
|
@article.mark_as_deleted
|
2013-02-25 11:12:28 +01:00
|
|
|
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,
|
2013-03-06 01:01:12 +01:00
|
|
|
:locals => { :fail_msg => I18n.t('errors.general_msg', :msg => 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
|
2013-07-13 09:32:27 +02:00
|
|
|
|
|
|
|
def history
|
|
|
|
@stock_article = StockArticle.undeleted.find(params[:stock_article_id])
|
|
|
|
@stock_changes = @stock_article.stock_changes.order('stock_changes.created_at DESC').each {|s| s.readonly!}
|
|
|
|
end
|
2009-01-18 17:42:51 +01:00
|
|
|
end
|