2009-01-08 16:33:27 +01:00
|
|
|
class DeliveriesController < ApplicationController
|
2023-05-12 13:01:12 +02:00
|
|
|
before_action :find_supplier, exclude: :fill_new_stock_article_form
|
2019-10-28 21:11:35 +01:00
|
|
|
|
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
|
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
def edit
|
|
|
|
@delivery = Delivery.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2009-01-08 16:33:27 +01:00
|
|
|
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
|
2023-05-12 13:01:12 +02:00
|
|
|
render action: 'new'
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2023-05-12 13:01:12 +02:00
|
|
|
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])
|
2023-05-12 13:01:12 +02:00
|
|
|
render layout: false
|
2013-07-07 14:14:32 +02:00
|
|
|
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
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
render layout: false
|
2013-06-11 13:10:18 +02:00
|
|
|
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
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
render layout: false
|
2009-02-10 20:06:08 +01:00
|
|
|
end
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|