Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class InvoicesController < ApplicationController
- before_action :set_invoice, only: [:show, :edit, :update, :destroy]
- before_action :authenticate_user!
- skip_before_action :verify_authenticity_token
- # GET /invoices
- # GET /invoices.json
- def index
- @invoices = Invoice.all
- @invoices = @invoices.client_id(params[:client_id]) if params[:client_id].present?
- @invoices = @invoices.created_at(params[:created_at]) if params[:created_at].present?
- end
- # GET /invoices/1
- # GET /invoices/1.json
- def show
- respond_to do |format|
- format.html
- format.pdf do
- render pdf: "file_name", :orientation => 'Landscape', :template => 'invoices/_withbackground.html.erb'
- end
- end
- end
- # GET /invoices/new
- def new
- @invoice = Invoice.new
- end
- def name
- @invoice = Invoice.client.name
- end
- # GET /invoices/1/edit
- def edit
- end
- # POST /invoices
- # POST /invoices.json
- def create
- @invoice = Invoice.new(invoice_params)
- respond_to do |format|
- if @invoice.save
- format.html { redirect_to @invoice, notice: 'Invoice was successfully created.' }
- format.json { render :show, status: :created, location: @invoice }
- else
- format.html { render :new }
- format.json { render json: @invoice.errors, status: :unprocessable_entity }
- end
- end
- end
- # PATCH/PUT /invoices/1
- # PATCH/PUT /invoices/1.json
- def update
- respond_to do |format|
- if @invoice.update(invoice_params)
- format.html { redirect_to @invoice, notice: 'Invoice was successfully updated.' }
- format.json { render :show, status: :ok, location: @invoice }
- else
- format.html { render :edit }
- format.json { render json: @invoice.errors, status: :unprocessable_entity }
- end
- end
- end
- # DELETE /invoices/1
- # DELETE /invoices/1.json
- def destroy
- @invoice.destroy
- respond_to do |format|
- format.html { redirect_to invoices_url, notice: 'Invoice was successfully destroyed.' }
- format.json { head :no_content }
- end
- end
- private
- # Use callbacks to share common setup or constraints between actions.
- def set_invoice
- @invoice = Invoice.find(params[:id])
- end
- # Never trust parameters from the scary internet, only allow the white list through.
- def invoice_params
- params.fetch(:invoice, {}).permit(:issue_time, :total, :vat, :item, :currency, :client_id, :invoice, :quarter, :pdf, :recurringmonthly, :recurringbiweekly)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment