From 4bc074febd8e76dc4f8b1c07731f9e5ae99016cc Mon Sep 17 00:00:00 2001 From: Adrian Hinz Date: Thu, 6 Oct 2016 14:29:38 +0200 Subject: [PATCH] Signed-off-by: Adrian Hinz --- Gemfile | 3 ++- app/controllers/invoices_controller.rb | 8 ++++++++ app/views/invoices/_show.html.erb | 24 ++++++++++++++++++++++++ app/views/invoices/show.html.erb | 1 + app/views/invoices/show.pdf.erb | 1 + config/initializers/mime_types.rb | 1 + config/initializers/wicked_pdf.rb | 21 +++++++++++++++++++++ 7 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 app/views/invoices/show.pdf.erb create mode 100644 config/initializers/wicked_pdf.rb diff --git a/Gemfile b/Gemfile index 5e7fb07..39b8e6d 100644 --- a/Gemfile +++ b/Gemfile @@ -35,7 +35,8 @@ gem 'jbuilder', '~> 2.5' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development - +gem 'wicked_pdf' +gem 'wkhtmltopdf-binary' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri diff --git a/app/controllers/invoices_controller.rb b/app/controllers/invoices_controller.rb index 688327d..67e9b8c 100644 --- a/app/controllers/invoices_controller.rb +++ b/app/controllers/invoices_controller.rb @@ -5,6 +5,14 @@ class InvoicesController < ApplicationController def show @invoice = Invoice.find(params[:id]) + respond_to do |format| + format.html + format.pdf do + render pdf: "Faktura_VAT_#{@invoice.id}", # Excluding ".pdf" extension. + disposition: 'attachment', + exe_path: '' + end + end end def new diff --git a/app/views/invoices/_show.html.erb b/app/views/invoices/_show.html.erb index 2b705c1..13fbd89 100644 --- a/app/views/invoices/_show.html.erb +++ b/app/views/invoices/_show.html.erb @@ -180,6 +180,30 @@ +
+

 

+
+
+
+
+ + + + + +
Sprzedający:
Osoba upowazniona do wystawienia faktury VAT
+
+
+
+ + + + + +
Kupujący:
Osoba upowazniona do odbioru faktury VAT
+
+
+
diff --git a/app/views/invoices/show.html.erb b/app/views/invoices/show.html.erb index 941e44a..afd1c0a 100644 --- a/app/views/invoices/show.html.erb +++ b/app/views/invoices/show.html.erb @@ -3,6 +3,7 @@
Faktura: <%= @invoice.number %>
<%= link_to raw(" " + I18n.t('back')), invoices_path, title: I18n.t('back'), class: "text-primary" %> + <%= link_to 'PDF', invoice_path(@invoice, format: :pdf) %>
diff --git a/app/views/invoices/show.pdf.erb b/app/views/invoices/show.pdf.erb new file mode 100644 index 0000000..2f34b25 --- /dev/null +++ b/app/views/invoices/show.pdf.erb @@ -0,0 +1 @@ +<%= render file: '/invoices/_show.html.erb' %> diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index dc18996..00fa42e 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -2,3 +2,4 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf +Mime::Type.register "application/pdf", :pdf diff --git a/config/initializers/wicked_pdf.rb b/config/initializers/wicked_pdf.rb new file mode 100644 index 0000000..ad5cec2 --- /dev/null +++ b/config/initializers/wicked_pdf.rb @@ -0,0 +1,21 @@ +# WickedPDF Global Configuration +# +# Use this to set up shared configuration options for your entire application. +# Any of the configuration options shown here can also be applied to single +# models by passing arguments to the `render :pdf` call. +# +# To learn more, check out the README: +# +# https://github.com/mileszs/wicked_pdf/blob/master/README.md + +WickedPdf.config = { + # Path to the wkhtmltopdf executable: This usually isn't needed if using + # one of the wkhtmltopdf-binary family of gems. + # exe_path: 'c:/Program Files/wkhtmltopdf/bin/wkhtmltopdf', + # or + exe_path: Gem.bin_path('wkhtmltopdf-binary', 'wkhtmltopdf') + + # Layout file to be used for all PDFs + # (but can be overridden in `render :pdf` calls) + # layout: 'pdf.html', +}