2009-01-06 11:49:19 +01:00
|
|
|
class SuppliersController < ApplicationController
|
|
|
|
before_filter :authenticate_suppliers, :except => [:index, :list]
|
2009-01-18 17:42:51 +01:00
|
|
|
helper :deliveries
|
2009-01-06 11:49:19 +01:00
|
|
|
|
|
|
|
def index
|
2009-02-11 15:23:59 +01:00
|
|
|
@suppliers = Supplier.without_deleted :order => 'name'
|
2009-01-18 17:42:51 +01:00
|
|
|
@deliveries = Delivery.recent
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@supplier = Supplier.find(params[:id])
|
2009-01-18 17:42:51 +01:00
|
|
|
@deliveries = @supplier.deliveries.recent
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# new supplier
|
|
|
|
# if shared_supplier_id is given, the new supplier will filled whith its attributes
|
|
|
|
def new
|
|
|
|
if params[:shared_supplier_id]
|
|
|
|
shared_supplier = SharedSupplier.find(params[:shared_supplier_id])
|
|
|
|
@supplier = shared_supplier.build_supplier(shared_supplier.attributes)
|
|
|
|
else
|
|
|
|
@supplier = Supplier.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@supplier = Supplier.new(params[:supplier])
|
|
|
|
if @supplier.save
|
2009-01-18 17:42:51 +01:00
|
|
|
flash[:notice] = "Lieferant wurde erstellt"
|
2009-01-08 16:33:27 +01:00
|
|
|
redirect_to suppliers_path
|
2009-01-06 11:49:19 +01:00
|
|
|
else
|
|
|
|
render :action => 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@supplier = Supplier.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@supplier = Supplier.find(params[:id])
|
|
|
|
if @supplier.update_attributes(params[:supplier])
|
2009-01-18 17:42:51 +01:00
|
|
|
flash[:notice] = 'Lieferant wurde aktualisiert'
|
2009-01-08 16:33:27 +01:00
|
|
|
redirect_to @supplier
|
2009-01-06 11:49:19 +01:00
|
|
|
else
|
|
|
|
render :action => 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2009-01-08 16:33:27 +01:00
|
|
|
@supplier = Supplier.find(params[:id])
|
|
|
|
@supplier.destroy
|
2009-01-18 17:42:51 +01:00
|
|
|
flash[:notice] = "Lieferant wurde gelöscht"
|
2009-01-08 16:33:27 +01:00
|
|
|
redirect_to suppliers_path
|
2009-01-06 11:49:19 +01:00
|
|
|
rescue => e
|
2009-02-11 15:23:59 +01:00
|
|
|
flash[:error] = "Ein Fehler ist aufgetreten: " + e.message
|
2009-01-08 16:33:27 +01:00
|
|
|
redirect_to @supplier
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# gives a list with all available shared_suppliers
|
|
|
|
def shared_suppliers
|
|
|
|
@shared_suppliers = SharedSupplier.find(:all)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|