2009-01-08 16:33:27 +01:00
|
|
|
class DeliveriesController < ApplicationController
|
|
|
|
|
|
|
|
before_filter :find_supplier
|
|
|
|
|
|
|
|
def index
|
|
|
|
@deliveries = @supplier.deliveries.find(:all)
|
|
|
|
|
|
|
|
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-02-06 16:26:35 +01:00
|
|
|
@supplier.stock_articles.each { |article| @delivery.stock_changes.build(:stock_article => article) }
|
|
|
|
|
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}"
|
|
|
|
page.insert_html :top, 'stock_changes', :partial => 'stock_change',
|
|
|
|
:locals => {:stock_change => article.stock_changes.build}
|
|
|
|
|
|
|
|
page.replace_html 'new_stock_article', :partial => 'new_stock_article',
|
|
|
|
:locals => {:stock_article => @supplier.stock_articles.build}
|
|
|
|
else
|
|
|
|
page.replace_html 'new_stock_article', :partial => 'new_stock_article',
|
|
|
|
:locals => {:stock_article => article}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-16 02:17:49 +01:00
|
|
|
def drop_stock_change
|
|
|
|
stock_change = StockChange.find(params[:stock_change_id])
|
|
|
|
stock_change.destroy
|
|
|
|
|
|
|
|
render :update do |page|
|
2009-02-06 16:26:35 +01:00
|
|
|
page.visual_effect :DropOut, "stock_change_#{stock_change.id}"
|
2009-01-16 02:17:49 +01:00
|
|
|
end
|
|
|
|
end
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|