Invoice forwarding in admin #2566

This commit is contained in:
Martin Lensment 2015-07-14 13:43:55 +03:00
parent bfd3e07981
commit 2e7f5a74c5
3 changed files with 32 additions and 1 deletions

View file

@ -41,6 +41,21 @@ class Admin::InvoicesController < AdminController
end
end
def forward
@invoice.billing_email = @invoice.buyer.billing_email
return unless request.post?
@invoice.billing_email = params[:invoice][:billing_email]
if @invoice.forward(render_to_string('registrar/invoices/pdf', layout: false))
flash[:notice] = t(:invoice_forwared)
redirect_to([:admin, @invoice])
else
flash.now[:alert] = t(:failed_to_forward_invoice)
end
end
def download_pdf
pdf = @invoice.pdf(render_to_string('registrar/invoices/pdf', layout: false))
send_data pdf, filename: @invoice.pdf_name

View file

@ -0,0 +1,15 @@
- content_for :actions do
= link_to(t(:back_to_invoice), admin_invoice_path(@invoice), class: 'btn btn-default')
= render 'shared/title', name: t(:forward_invoice)
= form_for([:admin, @invoice], url: { action: :forward }, method: :post) do |f|
.row
.col-md-4.col-md-offset-4
= render 'shared/full_errors', object: @invoice
.form-group
= f.label :billing_email
= f.text_field :billing_email, class: 'form-control', autocomplete: 'off'
.row
.col-md-12.text-right
= button_tag(t(:forward), class: 'btn btn-warning')

View file

@ -4,10 +4,11 @@
= @invoice
.col-sm-6
%h1.text-right.text-center-xs
= link_to(t(:download), admin_invoice_download_pdf_path(@invoice), class: 'btn btn-default')
= link_to(t(:forward), admin_invoice_forward_path(@invoice), class: 'btn btn-default')
- if !@invoice.cancelled? && !@invoice.binded?
= link_to(t(:cancel), cancel_admin_invoice_path(@invoice), method: :patch, class: 'btn btn-warning')
= link_to(t(:back), admin_invoices_path, class: 'btn btn-default')
= link_to(t(:download), admin_invoice_download_pdf_path(@invoice), class: 'btn btn-default')
%hr
= render 'shared/full_errors', object: @invoice