2012-04-16 08:48:01 +02:00
|
|
|
# encoding: utf-8
|
2009-01-08 16:33:27 +01:00
|
|
|
class DeliveriesController < ApplicationController
|
|
|
|
|
2009-02-10 20:06:08 +01:00
|
|
|
before_filter :find_supplier, :exclude => :fill_new_stock_article_form
|
|
|
|
|
2009-01-08 16:33:27 +01:00
|
|
|
def index
|
2009-05-15 17:58:02 +02:00
|
|
|
@deliveries = @supplier.deliveries.all :order => 'delivered_on DESC'
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@delivery = Delivery.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@delivery = @supplier.deliveries.build
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@delivery = Delivery.new(params[:delivery])
|
2013-06-13 23:33:24 +02:00
|
|
|
|
|
|
|
if @delivery.save
|
|
|
|
flash[:notice] = I18n.t('deliveries.create.notice')
|
|
|
|
redirect_to [@supplier, @delivery]
|
|
|
|
else
|
|
|
|
render :action => "new"
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-02-06 16:26:35 +01:00
|
|
|
def edit
|
|
|
|
@delivery = Delivery.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2009-01-08 16:33:27 +01:00
|
|
|
def update
|
|
|
|
@delivery = Delivery.find(params[:id])
|
|
|
|
|
2013-06-13 23:33:24 +02:00
|
|
|
if @delivery.update_attributes(params[:delivery])
|
|
|
|
flash[:notice] = I18n.t('deliveries.update.notice')
|
|
|
|
redirect_to [@supplier,@delivery]
|
|
|
|
else
|
|
|
|
render :action => "edit"
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@delivery = Delivery.find(params[:id])
|
|
|
|
@delivery.destroy
|
|
|
|
|
2013-04-10 17:02:16 +02:00
|
|
|
flash[:notice] = I18n.t('deliveries.destroy.notice')
|
2013-06-13 23:33:24 +02:00
|
|
|
redirect_to supplier_deliveries_url(@supplier)
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|
|
|
|
|
2013-06-11 13:10:18 +02:00
|
|
|
def new_stock_article
|
2013-06-18 10:48:19 +02:00
|
|
|
if params[:old_stock_article_id]
|
|
|
|
old_article = StockArticle.find_by_id(params[:old_stock_article_id])
|
|
|
|
elsif params[:old_article_id]
|
|
|
|
old_article = Article.find_by_id(params[:old_article_id])
|
|
|
|
old_article = old_article.becomes(StockArticle) unless old_article.nil?
|
|
|
|
end
|
2013-06-13 23:33:24 +02:00
|
|
|
|
2013-06-18 10:48:19 +02:00
|
|
|
unless old_article.nil?
|
|
|
|
@stock_article = old_article.dup
|
2013-06-13 23:33:24 +02:00
|
|
|
else
|
|
|
|
@stock_article = @supplier.stock_articles.build
|
|
|
|
end
|
2013-06-11 13:10:18 +02:00
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
|
2009-02-06 16:26:35 +01:00
|
|
|
def add_stock_article
|
2013-06-11 13:10:18 +02:00
|
|
|
@stock_article = StockArticle.new(params[:stock_article])
|
2013-06-13 23:33:24 +02:00
|
|
|
|
2013-06-11 13:10:18 +02:00
|
|
|
if @stock_article.valid? and @stock_article.save
|
|
|
|
render :layout => false
|
|
|
|
else
|
|
|
|
render :action => 'new_stock_article', :layout => false
|
2009-02-06 16:26:35 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-13 23:33:24 +02:00
|
|
|
def edit_stock_article
|
|
|
|
@stock_article = StockArticle.find(params[:stock_article_id])
|
2011-05-27 14:09:01 +02:00
|
|
|
render :layout => false
|
2009-01-16 02:17:49 +01:00
|
|
|
end
|
2009-02-10 20:06:08 +01:00
|
|
|
|
2013-06-13 23:33:24 +02:00
|
|
|
def update_stock_article
|
|
|
|
@stock_article = StockArticle.find(params[:stock_article][:id])
|
|
|
|
|
|
|
|
if @stock_article.update_attributes(params[:stock_article])
|
|
|
|
render :layout => false
|
|
|
|
else
|
|
|
|
render :action => 'edit_stock_article', :layout => false
|
|
|
|
end
|
|
|
|
end
|
2009-02-10 20:06:08 +01:00
|
|
|
|
2013-06-13 23:33:24 +02:00
|
|
|
def add_stock_change
|
|
|
|
@stock_change = StockChange.new
|
|
|
|
@stock_change.stock_article = StockArticle.find(params[:stock_article_id])
|
|
|
|
render :layout => false
|
2009-02-10 20:06:08 +01:00
|
|
|
end
|
2013-06-13 23:33:24 +02:00
|
|
|
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|