56 lines
1.2 KiB
Ruby
56 lines
1.2 KiB
Ruby
class InvoicesController < ApplicationController
|
|
def index
|
|
@invoices = Invoice.where(user_id: current_user.id)
|
|
end
|
|
|
|
def show
|
|
@invoice = Invoice.find(params[:id])
|
|
end
|
|
|
|
def new
|
|
@invoice = Invoice.new(date: Date.today)
|
|
@user_firms = current_user.user_firms
|
|
@customers = current_user.customers
|
|
end
|
|
|
|
def create
|
|
@invoice = Invoice.new(invoice_params)
|
|
@invoice.user_id = current_user.id
|
|
if @invoice.save
|
|
redirect_to @invoice
|
|
else
|
|
@user_firms = current_user.user_firms
|
|
@customers = current_user.customers
|
|
render :new
|
|
end
|
|
end
|
|
|
|
def edit
|
|
@invoice = Invoice.find(params[:id])
|
|
@user_firms = current_user.user_firms
|
|
@customers = current_user.customers
|
|
end
|
|
|
|
def update
|
|
@invoice = Invoice.find(params[:id])
|
|
if @invoice.update_attributes(invoice_params)
|
|
redirect_to @invoice
|
|
else
|
|
@user_firms = current_user.user_firms
|
|
@customers = current_user.customers
|
|
render :edit
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@invoice = Invoice.find(params[:id])
|
|
@invoice.destroy unless @invoice.blank?
|
|
redirect_to invoices_path
|
|
end
|
|
|
|
private
|
|
def invoice_params
|
|
params.require(:invoice).permit(:number, :user_firm_id, :customer_id, :date, :date_of_payment)
|
|
end
|
|
end
|