Guest User

Untitled

a guest
May 14th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. class InvoicesController < ApplicationController
  2. before_action :set_invoice, only: [:show, :edit, :update, :destroy]
  3. before_action :authenticate_user!
  4. skip_before_action :verify_authenticity_token
  5.  
  6. # GET /invoices
  7. # GET /invoices.json
  8. def index
  9. @invoices = Invoice.all
  10. @invoices = @invoices.client_id(params[:client_id]) if params[:client_id].present?
  11. @invoices = @invoices.created_at(params[:created_at]) if params[:created_at].present?
  12.  
  13. end
  14.  
  15. # GET /invoices/1
  16. # GET /invoices/1.json
  17. def show
  18. respond_to do |format|
  19. format.html
  20. format.pdf do
  21. render pdf: "file_name", :orientation => 'Landscape', :template => 'invoices/_withbackground.html.erb'
  22. end
  23. end
  24. end
  25.  
  26. # GET /invoices/new
  27. def new
  28. @invoice = Invoice.new
  29. end
  30.  
  31. def name
  32. @invoice = Invoice.client.name
  33. end
  34.  
  35. # GET /invoices/1/edit
  36. def edit
  37. end
  38.  
  39. # POST /invoices
  40. # POST /invoices.json
  41. def create
  42. @invoice = Invoice.new(invoice_params)
  43.  
  44. respond_to do |format|
  45. if @invoice.save
  46. format.html { redirect_to @invoice, notice: 'Invoice was successfully created.' }
  47. format.json { render :show, status: :created, location: @invoice }
  48. else
  49. format.html { render :new }
  50. format.json { render json: @invoice.errors, status: :unprocessable_entity }
  51. end
  52. end
  53. end
  54.  
  55. # PATCH/PUT /invoices/1
  56. # PATCH/PUT /invoices/1.json
  57. def update
  58. respond_to do |format|
  59. if @invoice.update(invoice_params)
  60. format.html { redirect_to @invoice, notice: 'Invoice was successfully updated.' }
  61. format.json { render :show, status: :ok, location: @invoice }
  62. else
  63. format.html { render :edit }
  64. format.json { render json: @invoice.errors, status: :unprocessable_entity }
  65. end
  66. end
  67. end
  68.  
  69. # DELETE /invoices/1
  70. # DELETE /invoices/1.json
  71. def destroy
  72. @invoice.destroy
  73. respond_to do |format|
  74. format.html { redirect_to invoices_url, notice: 'Invoice was successfully destroyed.' }
  75. format.json { head :no_content }
  76. end
  77. end
  78.  
  79. private
  80. # Use callbacks to share common setup or constraints between actions.
  81. def set_invoice
  82. @invoice = Invoice.find(params[:id])
  83. end
  84.  
  85. # Never trust parameters from the scary internet, only allow the white list through.
  86. def invoice_params
  87. params.fetch(:invoice, {}).permit(:issue_time, :total, :vat, :item, :currency, :client_id, :invoice, :quarter, :pdf, :recurringmonthly, :recurringbiweekly)
  88. end
  89. end
Advertisement
Add Comment
Please, Sign In to add comment