2009-01-08 16:33:27 +01:00
|
|
|
class DeliveriesController < ApplicationController
|
2019-10-28 21:11:35 +01:00
|
|
|
before_action :find_supplier, :exclude => :fill_new_stock_article_form
|
|
|
|
|
2009-01-08 16:33:27 +01:00
|
|
|
def index
|
2020-08-01 18:39:34 +02:00
|
|
|
@deliveries = @supplier.deliveries.order('date DESC')
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@delivery = Delivery.find(params[:id])
|
2020-08-01 20:11:25 +02:00
|
|
|
@stock_changes = @delivery.stock_changes.includes(:stock_article).order('articles.name ASC')
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@delivery = @supplier.deliveries.build
|
2021-03-01 15:27:26 +01:00
|
|
|
@delivery.date = Date.today # TODO: move to model/database
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@delivery = Delivery.new(params[:delivery])
|
2020-08-01 18:39:34 +02:00
|
|
|
|
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
|
2020-08-01 18:39:34 +02:00
|
|
|
|
2009-01-08 16:33:27 +01:00
|
|
|
def update
|
|
|
|
@delivery = Delivery.find(params[:id])
|
|
|
|
|
2022-10-13 18:25:52 +02:00
|
|
|
if @delivery.update(params[:delivery])
|
2013-06-13 23:33:24 +02:00
|
|
|
flash[:notice] = I18n.t('deliveries.update.notice')
|
2021-03-01 15:27:26 +01:00
|
|
|
redirect_to [@supplier, @delivery]
|
2013-06-13 23:33:24 +02:00
|
|
|
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
|
2020-08-01 18:39:34 +02:00
|
|
|
|
2013-12-07 16:42:25 +01:00
|
|
|
def add_stock_change
|
|
|
|
@stock_change = StockChange.new
|
|
|
|
@stock_change.stock_article = StockArticle.find(params[:stock_article_id])
|
2013-07-07 14:14:32 +02:00
|
|
|
render :layout => false
|
|
|
|
end
|
2020-08-01 18:39:34 +02:00
|
|
|
|
2013-12-07 16:42:25 +01:00
|
|
|
def form_on_stock_article_create # See publish/subscribe design pattern in /doc.
|
|
|
|
@stock_article = StockArticle.find(params[:id])
|
2020-08-01 18:39:34 +02:00
|
|
|
|
2013-06-11 13:10:18 +02:00
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
|
2013-12-07 16:42:25 +01:00
|
|
|
def form_on_stock_article_update # See publish/subscribe design pattern in /doc.
|
|
|
|
@stock_article = StockArticle.find(params[:id])
|
2020-08-01 18:39:34 +02:00
|
|
|
|
2013-06-13 23:33:24 +02:00
|
|
|
render :layout => false
|
2009-02-10 20:06:08 +01:00
|
|
|
end
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|