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
- #show ⇒ Object
- #update ⇒ Object
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
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/dorsale/billing_machine/invoices_controller.rb', line 35 def create # callback in BillingMachine::ApplicationController @invoice ||= scope.new(invoice_params_for_create) model, :create? if @invoice.save 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
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'app/controllers/dorsale/billing_machine/invoices_controller.rb', line 101 def email @invoice, :email? @subject = begin params[:email][:subject] rescue "#{model.t} #{@invoice.tracking_id} : #{@invoice.label}" end @body = begin params[:email][:body] rescue t("emails.invoices.send_invoice_to_customer", :from => current_user.to_s, :to => @invoice.customer.to_s, ) end if request.get? return end email = ::Dorsale::BillingMachine::InvoiceMailer .send_invoice_to_customer(@invoice, @subject, @body, current_user) if email.deliver_later 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 @filters ||= ::Dorsale::BillingMachine::SmallData::FilterForInvoices.new() @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 33 |
# 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.id_card = @id_cards.first if @id_cards.one? @invoice, :create? end |
#pay ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/controllers/dorsale/billing_machine/invoices_controller.rb', line 88 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 |
#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 |
# File 'app/controllers/dorsale/billing_machine/invoices_controller.rb', line 76 def update # callback in BillingMachine::ApplicationController @invoice, :update? if @invoice.update(invoice_params_for_update) flash[:notice] = t("messages.invoices.update_ok") redirect_to default_back_url else render :edit end end |