Basic pdf generating

This commit is contained in:
Martin Lensment 2015-04-21 11:16:43 +03:00
parent e987e201ad
commit 727d1226ad
15 changed files with 298 additions and 3 deletions

View file

@ -1,7 +1,7 @@
class Registrar::InvoicesController < RegistrarController
load_and_authorize_resource
before_action :set_invoice, only: [:show]
before_action :set_invoice, only: [:show, :forward, :download_pdf]
def index
invoices = current_user.registrar.invoices.includes(:invoice_items, :account_activity)
@ -13,6 +13,30 @@ class Registrar::InvoicesController < RegistrarController
def show
end
def forward
@invoice.billing_email = @invoice.buyer.billing_email
return unless request.post?
@invoice.billing_email = params[:invoice][:billing_email]
if @invoice.forward
flash[:notice] = t('invoice_forwared')
redirect_to([:registrar, @invoice])
else
flash.now[:alert] = t('failed_to_forward_invoice')
end
end
def download_pdf
# render 'pdf', layout: false
kit = PDFKit.new(render_to_string('pdf', layout: false))
pdf = kit.to_pdf
send_data pdf, filename: "test.pdf"
end
private
def set_invoice