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
|
2013-06-26 15:16:52 +02:00
|
|
|
@delivery.delivered_on = Date.today #TODO: move to model/database
|
2009-01-08 16:33:27 +01:00
|
|
|
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-07-07 14:14:32 +02:00
|
|
|
|
|
|
|
# three possibilites to fill a new_stock_article form
|
|
|
|
# (1) start from blank or use params
|
2013-06-11 13:10:18 +02:00
|
|
|
def new_stock_article
|
2013-07-07 14:14:32 +02:00
|
|
|
@stock_article = @supplier.stock_articles.build(params[:stock_article])
|
|
|
|
|
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
|
|
|
|
# (2) StockArticle as template
|
|
|
|
def copy_stock_article
|
|
|
|
@stock_article = StockArticle.find(params[:old_stock_article_id]).dup
|
|
|
|
|
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
|
|
|
|
# (3) non-stock Article as template
|
|
|
|
def derive_stock_article
|
|
|
|
@stock_article = Article.find(params[:old_article_id]).becomes(StockArticle).dup
|
2013-06-13 23:33:24 +02:00
|
|
|
|
2013-06-11 13:10:18 +02:00
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
|
2013-06-26 15:16:52 +02:00
|
|
|
def create_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
|