diff --git a/app/controllers/admin/invoices_controller.rb b/app/controllers/admin/invoices_controller.rb index ce368742c..be31e6ffe 100644 --- a/app/controllers/admin/invoices_controller.rb +++ b/app/controllers/admin/invoices_controller.rb @@ -1,6 +1,8 @@ class Admin::InvoicesController < AdminController load_and_authorize_resource + before_action :set_invoice, only: [:forward, :download_pdf] + def new @deposit = Deposit.new end @@ -39,9 +41,18 @@ class Admin::InvoicesController < AdminController end end + def download_pdf + pdf = @invoice.pdf(render_to_string('registrar/invoices/pdf', layout: false)) + send_data pdf, filename: @invoice.pdf_name + end + private def deposit_params params.require(:deposit).permit(:amount, :description, :registrar_id) end + + def set_invoice + @invoice = Invoice.find(params[:invoice_id]) + end end diff --git a/app/views/admin/invoices/show.haml b/app/views/admin/invoices/show.haml index c96cbb583..7909688fb 100644 --- a/app/views/admin/invoices/show.haml +++ b/app/views/admin/invoices/show.haml @@ -7,6 +7,7 @@ - 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 diff --git a/config/routes.rb b/config/routes.rb index 96cddbdf2..bb1828c36 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -176,7 +176,9 @@ Rails.application.routes.draw do end resources :invoices do + get 'download_pdf' patch 'cancel', on: :member + match 'forward', via: [:post, :get] end resources :domains do