diff --git a/app/controllers/admin/invoices_controller.rb b/app/controllers/admin/invoices_controller.rb index be31e6ffe..39d4e805c 100644 --- a/app/controllers/admin/invoices_controller.rb +++ b/app/controllers/admin/invoices_controller.rb @@ -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 diff --git a/app/views/admin/invoices/forward.haml b/app/views/admin/invoices/forward.haml new file mode 100644 index 000000000..25f59d3ad --- /dev/null +++ b/app/views/admin/invoices/forward.haml @@ -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') diff --git a/app/views/admin/invoices/show.haml b/app/views/admin/invoices/show.haml index 7909688fb..1d8480da4 100644 --- a/app/views/admin/invoices/show.haml +++ b/app/views/admin/invoices/show.haml @@ -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