2009-01-10 19:36:58 +01:00
|
|
|
class Finance::InvoicesController < ApplicationController
|
2009-01-08 16:33:27 +01:00
|
|
|
|
|
|
|
def index
|
2012-09-30 21:15:55 +02:00
|
|
|
@invoices = Invoice.includes(:supplier, :delivery, :order).order('date DESC').paginate(page: params[:page])
|
2009-01-08 16:33:27 +01:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # index.html.erb
|
|
|
|
format.xml { render :xml => @invoices }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@invoice = Invoice.find(params[:id])
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # show.html.erb
|
|
|
|
format.xml { render :xml => @invoice }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2009-01-29 21:28:22 +01:00
|
|
|
@invoice = Invoice.new :supplier_id => params[:supplier_id],
|
|
|
|
:delivery_id => params[:delivery_id], :order_id => params[:order_id]
|
2009-01-08 16:33:27 +01:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # new.html.erb
|
|
|
|
format.xml { render :xml => @invoice }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@invoice = Invoice.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
# POST /invoices
|
|
|
|
# POST /invoices.xml
|
|
|
|
def create
|
|
|
|
@invoice = Invoice.new(params[:invoice])
|
|
|
|
|
2009-01-29 21:28:22 +01:00
|
|
|
if @invoice.save
|
|
|
|
flash[:notice] = "Rechnung wurde erstellt."
|
|
|
|
if @invoice.order
|
|
|
|
# Redirect to balancing page
|
|
|
|
redirect_to :controller => 'balancing', :action => 'new', :id => @invoice.order
|
2009-01-08 16:33:27 +01:00
|
|
|
else
|
2009-01-29 21:28:22 +01:00
|
|
|
redirect_to [:finance, @invoice]
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|
2009-01-29 21:28:22 +01:00
|
|
|
else
|
|
|
|
render :action => "new"
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /invoices/1
|
|
|
|
# PUT /invoices/1.xml
|
|
|
|
def update
|
|
|
|
@invoice = Invoice.find(params[:id])
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @invoice.update_attributes(params[:invoice])
|
|
|
|
flash[:notice] = 'Invoice was successfully updated.'
|
2009-01-10 19:36:58 +01:00
|
|
|
format.html { redirect_to([:finance, @invoice]) }
|
2009-01-08 16:33:27 +01:00
|
|
|
format.xml { head :ok }
|
|
|
|
else
|
|
|
|
format.html { render :action => "edit" }
|
|
|
|
format.xml { render :xml => @invoice.errors, :status => :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /invoices/1
|
|
|
|
# DELETE /invoices/1.xml
|
|
|
|
def destroy
|
|
|
|
@invoice = Invoice.find(params[:id])
|
|
|
|
@invoice.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
2009-01-10 19:36:58 +01:00
|
|
|
format.html { redirect_to(finance_invoices_path) }
|
2009-01-08 16:33:27 +01:00
|
|
|
format.xml { head :ok }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|