Class: Dorsale::BillingMachine::InvoicesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- ApplicationController
- Dorsale::BillingMachine::InvoicesController
- Defined in:
- app/controllers/dorsale/billing_machine/invoices_controller.rb
Instance Method Summary collapse
- #copy ⇒ Object
- #create ⇒ Object
- #edit ⇒ Object
- #email ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #pay ⇒ Object
- #preview ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#copy ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/dorsale/billing_machine/invoices_controller.rb', line 55 def copy # callback in BillingMachine::ApplicationController @invoice, :copy? @original = @invoice @invoice = Dorsale::BillingMachine::Invoice::Copy.(@original) render :new end |
#create ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/dorsale/billing_machine/invoices_controller.rb', line 34 def create # callback in BillingMachine::ApplicationController @invoice ||= scope.new(invoice_params_for_create) model, :create? if @invoice.save Dorsale::BillingMachine::PdfFileGenerator.(@invoice) flash[:notice] = t("messages.invoices.create_ok") redirect_to default_back_url else render :edit end end |
#edit ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/dorsale/billing_machine/invoices_controller.rb', line 65 def edit # callback in BillingMachine::ApplicationController @invoice, :update? if ::Dorsale::BillingMachine.vat_mode == :single @invoice.lines.build(vat_rate: @invoice.vat_rate) if @invoice.lines.empty? else @invoice.lines.build if @invoice.lines.empty? end end |
#email ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/dorsale/billing_machine/invoices_controller.rb', line 114 def email @invoice, :email? @email = Dorsale::BillingMachine::Email.new(@invoice, email_params) return if request.get? if @email.save flash[:notice] = t("messages.invoices.email_ok") redirect_to back_url else flash.now[:alert] = t("messages.invoices.email_error") render end end |
#index ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/dorsale/billing_machine/invoices_controller.rb', line 11 def index # callback in BillingMachine::ApplicationController model, :list? @invoices ||= scope.all.preload(:customer) @filters ||= ::Dorsale::BillingMachine::SmallData::FilterForInvoices.new(filters_jar) @invoices = @filters.apply(@invoices) @invoices_without_pagination = @invoices @invoices = @invoices.page(params[:page]).per(50) @statistics = ::Dorsale::BillingMachine::Invoice::Statistics.new(@invoices_without_pagination) end |
#new ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'app/controllers/dorsale/billing_machine/invoices_controller.rb', line 25 def new # callback in BillingMachine::ApplicationController @invoice ||= scope.new @invoice.lines.build if @invoice.lines.empty? @invoice, :create? end |
#pay ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/dorsale/billing_machine/invoices_controller.rb', line 101 def pay # callback in BillingMachine::ApplicationController @invoice, :update? if @invoice.update(paid: true) flash[:notice] = t("messages.invoices.pay_ok") else flash[:alert] = t("messages.invoices.pay_error") end redirect_to back_url end |
#preview ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'app/controllers/dorsale/billing_machine/invoices_controller.rb', line 91 def preview model, :preview? @invoice ||= scope.new(invoice_params_for_preview) @invoice.update_totals Dorsale::BillingMachine::PdfFileGenerator.(@invoice) render :show, formats: :pdf end |
#show ⇒ Object
49 50 51 52 53 |
# File 'app/controllers/dorsale/billing_machine/invoices_controller.rb', line 49 def show # callback in BillingMachine::ApplicationController @invoice, :read? @invoice, :download? if request.format.pdf? end |
#update ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/dorsale/billing_machine/invoices_controller.rb', line 76 def update # callback in BillingMachine::ApplicationController @invoice.attributes = invoice_params_for_update @invoice, :update? if @invoice.save Dorsale::BillingMachine::PdfFileGenerator.(@invoice) flash[:notice] = t("messages.invoices.update_ok") redirect_to default_back_url else render :edit end end |