2009-01-10 19:36:58 +01:00
|
|
|
class Finance::InvoicesController < ApplicationController
|
2009-01-08 16:33:27 +01:00
|
|
|
|
|
|
|
def index
|
2012-11-10 16:44:05 +01:00
|
|
|
@invoices = Invoice.includes(:supplier, :delivery, :order).order('date DESC').page(params[:page]).per(@per_page)
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@invoice = Invoice.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2009-01-29 21:28:22 +01:00
|
|
|
@invoice = Invoice.new :supplier_id => params[:supplier_id],
|
2012-11-10 16:44:05 +01:00
|
|
|
:delivery_id => params[:delivery_id],
|
|
|
|
:order_id => params[:order_id]
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@invoice = Invoice.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2012-11-10 16:44:05 +01:00
|
|
|
redirect_to new_finance_order_url(order_id: @invoice.order.id)
|
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
|
|
|
|
|
|
|
|
def update
|
|
|
|
@invoice = Invoice.find(params[:id])
|
|
|
|
|
2012-11-10 16:44:05 +01:00
|
|
|
if @invoice.update_attributes(params[:invoice])
|
|
|
|
redirect_to [:finance, @invoice], notice: "Rechnung wurde aktualisiert."
|
|
|
|
else
|
|
|
|
render :edit
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@invoice = Invoice.find(params[:id])
|
|
|
|
@invoice.destroy
|
|
|
|
|
2012-11-10 16:44:05 +01:00
|
|
|
redirect_to finance_invoices_url
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|
|
|
|
end
|