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
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # index.html.erb
|
|
|
|
format.xml { render :xml => @deliveries }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@delivery = Delivery.find(params[:id])
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # show.html.erb
|
|
|
|
format.xml { render :xml => @delivery }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@delivery = @supplier.deliveries.build
|
2009-05-17 16:11:39 +02:00
|
|
|
@delivery.stock_changes.build(:stock_article => @supplier.stock_articles.first)
|
2009-02-06 16:26:35 +01:00
|
|
|
|
2009-01-08 16:33:27 +01:00
|
|
|
respond_to do |format|
|
|
|
|
format.html # new.html.erb
|
|
|
|
format.xml { render :xml => @delivery }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@delivery = Delivery.new(params[:delivery])
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @delivery.save
|
|
|
|
flash[:notice] = 'Delivery was successfully created.'
|
|
|
|
format.html { redirect_to([@supplier,@delivery]) }
|
|
|
|
format.xml { render :xml => @delivery, :status => :created, :location => @delivery }
|
|
|
|
else
|
|
|
|
format.html { render :action => "new" }
|
|
|
|
format.xml { render :xml => @delivery.errors, :status => :unprocessable_entity }
|
|
|
|
end
|
|
|
|
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])
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @delivery.update_attributes(params[:delivery])
|
|
|
|
flash[:notice] = 'Delivery was successfully updated.'
|
|
|
|
format.html { redirect_to([@supplier,@delivery]) }
|
|
|
|
format.xml { head :ok }
|
|
|
|
else
|
|
|
|
format.html { render :action => "edit" }
|
|
|
|
format.xml { render :xml => @delivery.errors, :status => :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@delivery = Delivery.find(params[:id])
|
|
|
|
@delivery.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to(supplier_deliveries_url(@supplier)) }
|
|
|
|
format.xml { head :ok }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-02-06 16:26:35 +01:00
|
|
|
def add_stock_article
|
|
|
|
article = @supplier.stock_articles.build(params[:stock_article])
|
|
|
|
render :update do |page|
|
|
|
|
if article.save
|
|
|
|
logger.debug "new StockArticle: #{article.id}"
|
2009-05-17 16:11:39 +02:00
|
|
|
page.insert_html :bottom, 'stock_changes', :partial => 'stock_change',
|
|
|
|
:locals => {:stock_change => article.stock_changes.build, :supplier => @supplier}
|
2009-02-06 16:26:35 +01:00
|
|
|
|
2009-02-12 18:32:20 +01:00
|
|
|
page.replace_html 'new_stock_article', :partial => 'stock_article_form',
|
2009-02-06 16:26:35 +01:00
|
|
|
:locals => {:stock_article => @supplier.stock_articles.build}
|
|
|
|
else
|
2009-02-12 18:32:20 +01:00
|
|
|
page.replace_html 'new_stock_article', :partial => 'stock_article_form',
|
2009-02-06 16:26:35 +01:00
|
|
|
:locals => {:stock_article => article}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-05-17 16:11:39 +02:00
|
|
|
def add_stock_change
|
2009-01-16 02:17:49 +01:00
|
|
|
|
|
|
|
render :update do |page|
|
2009-05-17 16:11:39 +02:00
|
|
|
page.insert_html :bottom, 'stock_changes', :partial => 'stock_change',
|
|
|
|
:locals => {:stock_change => StockChange.new, :supplier => @supplier}
|
2009-01-16 02:17:49 +01:00
|
|
|
end
|
|
|
|
end
|
2009-02-10 20:06:08 +01:00
|
|
|
|
|
|
|
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')}
|
|
|
|
)
|
|
|
|
|
2009-02-12 18:32:20 +01:00
|
|
|
render :partial => 'stock_article_form', :locals => {:stock_article => stock_article}
|
2009-02-10 20:06:08 +01:00
|
|
|
end
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|