mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Basic pdf generating
This commit is contained in:
parent
e987e201ad
commit
727d1226ad
15 changed files with 298 additions and 3 deletions
3
Gemfile
3
Gemfile
|
@ -70,6 +70,9 @@ gem 'uuidtools', '~> 2.1.4' # For unique IDs (used by the epp gem)
|
||||||
# for importing legacy db
|
# for importing legacy db
|
||||||
gem 'activerecord-import', '~> 0.7.0' # for inserting dummy data
|
gem 'activerecord-import', '~> 0.7.0' # for inserting dummy data
|
||||||
|
|
||||||
|
# for generating pdf
|
||||||
|
gem 'pdfkit', '~> 0.6.2'
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
# dev tools
|
# dev tools
|
||||||
gem 'spring', '~> 1.3.3'
|
gem 'spring', '~> 1.3.3'
|
||||||
|
|
|
@ -272,6 +272,7 @@ GEM
|
||||||
orm_adapter (0.5.0)
|
orm_adapter (0.5.0)
|
||||||
parser (2.2.0.3)
|
parser (2.2.0.3)
|
||||||
ast (>= 1.1, < 3.0)
|
ast (>= 1.1, < 3.0)
|
||||||
|
pdfkit (0.6.2)
|
||||||
pg (0.18.1)
|
pg (0.18.1)
|
||||||
phantomjs (1.9.7.1)
|
phantomjs (1.9.7.1)
|
||||||
phantomjs-binaries (1.9.2.4)
|
phantomjs-binaries (1.9.2.4)
|
||||||
|
@ -521,6 +522,7 @@ DEPENDENCIES
|
||||||
nokogiri (>= 1.6.2.2)
|
nokogiri (>= 1.6.2.2)
|
||||||
nprogress-rails (~> 0.1.6.5)
|
nprogress-rails (~> 0.1.6.5)
|
||||||
paper_trail!
|
paper_trail!
|
||||||
|
pdfkit (~> 0.6.2)
|
||||||
pg (~> 0.18.0)
|
pg (~> 0.18.0)
|
||||||
phantomjs (~> 1.9.7.1)
|
phantomjs (~> 1.9.7.1)
|
||||||
phantomjs-binaries (~> 1.9.2.4)
|
phantomjs-binaries (~> 1.9.2.4)
|
||||||
|
|
BIN
app/assets/images/eis-logo-black-et.png
Normal file
BIN
app/assets/images/eis-logo-black-et.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
|
@ -36,3 +36,6 @@
|
||||||
box-sizing: border-box
|
box-sizing: border-box
|
||||||
padding: 10px
|
padding: 10px
|
||||||
font-size: 16px
|
font-size: 16px
|
||||||
|
|
||||||
|
.no-border
|
||||||
|
border: 0px !important
|
||||||
|
|
16
app/assets/stylesheets/shared/pdf.sass
Normal file
16
app/assets/stylesheets/shared/pdf.sass
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
@import "bootstrap-sprockets"
|
||||||
|
@import "bootstrap"
|
||||||
|
|
||||||
|
#logo
|
||||||
|
text-align: right
|
||||||
|
|
||||||
|
.no-border
|
||||||
|
border: 0px !important
|
||||||
|
|
||||||
|
body, html, .container
|
||||||
|
height: 100%
|
||||||
|
|
||||||
|
#footer
|
||||||
|
position: absolute
|
||||||
|
bottom: 0
|
||||||
|
width: 100%
|
|
@ -1,7 +1,7 @@
|
||||||
class Registrar::InvoicesController < RegistrarController
|
class Registrar::InvoicesController < RegistrarController
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|
||||||
before_action :set_invoice, only: [:show]
|
before_action :set_invoice, only: [:show, :forward, :download_pdf]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
invoices = current_user.registrar.invoices.includes(:invoice_items, :account_activity)
|
invoices = current_user.registrar.invoices.includes(:invoice_items, :account_activity)
|
||||||
|
@ -13,6 +13,30 @@ class Registrar::InvoicesController < RegistrarController
|
||||||
def show
|
def show
|
||||||
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
|
||||||
|
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
|
private
|
||||||
|
|
||||||
def set_invoice
|
def set_invoice
|
||||||
|
|
|
@ -7,6 +7,9 @@ class Invoice < ActiveRecord::Base
|
||||||
|
|
||||||
accepts_nested_attributes_for :invoice_items
|
accepts_nested_attributes_for :invoice_items
|
||||||
|
|
||||||
|
attr_accessor :billing_email
|
||||||
|
validates :billing_email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }
|
||||||
|
|
||||||
validates :invoice_type, :due_date, :currency, :seller_name,
|
validates :invoice_type, :due_date, :currency, :seller_name,
|
||||||
:seller_iban, :buyer_name, :invoice_items, :vat_prc, presence: true
|
:seller_iban, :buyer_name, :invoice_items, :vat_prc, presence: true
|
||||||
|
|
||||||
|
@ -38,6 +41,14 @@ class Invoice < ActiveRecord::Base
|
||||||
Country.new(buyer_country_code)
|
Country.new(buyer_country_code)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def forward
|
||||||
|
return false unless valid?
|
||||||
|
return false unless billing_email
|
||||||
|
|
||||||
|
# TODO: forward invoice
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def items
|
def items
|
||||||
invoice_items
|
invoice_items
|
||||||
end
|
end
|
||||||
|
|
15
app/views/registrar/invoices/forward.haml
Normal file
15
app/views/registrar/invoices/forward.haml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
- content_for :actions do
|
||||||
|
= link_to(t(:back_to_invoice), registrar_invoice_path(@invoice), class: 'btn btn-default')
|
||||||
|
= render 'shared/title', name: t(:forward_invoice)
|
||||||
|
|
||||||
|
= form_for([:registrar, @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-primary')
|
203
app/views/registrar/invoices/pdf.haml
Normal file
203
app/views/registrar/invoices/pdf.haml
Normal file
|
@ -0,0 +1,203 @@
|
||||||
|
%html{lang: I18n.locale.to_s}
|
||||||
|
%head
|
||||||
|
%meta{charset: "utf-8"}
|
||||||
|
:css
|
||||||
|
.container {
|
||||||
|
margin: auto;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
.col-md-12 {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.col-md-6 {
|
||||||
|
width: 49%;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.col-xs-4 {
|
||||||
|
width: 33%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.col-xs-2 {
|
||||||
|
width: 16%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.left {
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.left {
|
||||||
|
padding-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.right {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
dt {
|
||||||
|
float: left;
|
||||||
|
width: 100px;
|
||||||
|
clear: left;
|
||||||
|
text-align: right;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
font-weight: bold;
|
||||||
|
line-height: 1.42857;
|
||||||
|
}
|
||||||
|
|
||||||
|
dd {
|
||||||
|
margin-left: 120px;
|
||||||
|
line-height: 1.42857;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
text-align: left;
|
||||||
|
border: 0px;
|
||||||
|
border-top: 1px solid #DDD;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
thead th {
|
||||||
|
border-bottom: 2px solid #DDD;
|
||||||
|
border-top: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
border-top: 1px solid #DDD;
|
||||||
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-border {
|
||||||
|
border: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr {
|
||||||
|
height: 1px;
|
||||||
|
border: 0;
|
||||||
|
color: #333;
|
||||||
|
background-color: #C4C4C4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.clear {
|
||||||
|
clear: both;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pull-down {
|
||||||
|
margin-top: 50px;
|
||||||
|
}
|
||||||
|
/%style{type:"text/css"}
|
||||||
|
/ = Rails.application.assets.find_asset('shared/pdf').to_s
|
||||||
|
/ = stylesheet_link_tag 'shared/pdf', media: 'all'
|
||||||
|
/ = stylesheet_link_tag 'shared/pdf', media: 'all'
|
||||||
|
%body
|
||||||
|
.container
|
||||||
|
.row
|
||||||
|
.col-md-12.text-right
|
||||||
|
= image_tag('eis-logo-black-et.png')
|
||||||
|
.row
|
||||||
|
.col-md-12
|
||||||
|
= render 'shared/title', name: t(:invoice_no, no: @invoice.id)
|
||||||
|
.row
|
||||||
|
.col-md-6.left
|
||||||
|
%h4
|
||||||
|
Details
|
||||||
|
%hr
|
||||||
|
%dl.dl-horizontal
|
||||||
|
%dt= t('issue_date')
|
||||||
|
%dd= l(@invoice.created_at)
|
||||||
|
|
||||||
|
%dt= t('due_date')
|
||||||
|
%dd= l(@invoice.due_date)
|
||||||
|
|
||||||
|
%dt= t('receipt_date')
|
||||||
|
- if @invoice.binded?
|
||||||
|
%dd= l(@invoice.receipt_date)
|
||||||
|
- else
|
||||||
|
%dd{class: 'text-danger'}= t('unpaid')
|
||||||
|
|
||||||
|
%dt= t('payment_term')
|
||||||
|
%dd= t(@invoice.payment_term)
|
||||||
|
|
||||||
|
%dt= t('description')
|
||||||
|
- @invoice.description.prepend(' - ') if @invoice.description.present?
|
||||||
|
%dd= "#{t('invoice_no', no: @invoice.id)}#{@invoice.description}"
|
||||||
|
|
||||||
|
%dt= t('reference_no')
|
||||||
|
%dd= @invoice.reference_no
|
||||||
|
.col-md-6.right
|
||||||
|
%h4= t('buyer')
|
||||||
|
%hr
|
||||||
|
%dl.dl-horizontal
|
||||||
|
%dt= t('name')
|
||||||
|
%dd= @invoice.buyer_name
|
||||||
|
|
||||||
|
%dt= t('reg_no')
|
||||||
|
%dd= @invoice.buyer_reg_no
|
||||||
|
|
||||||
|
%dt= t('address')
|
||||||
|
%dd= @invoice.buyer_address
|
||||||
|
|
||||||
|
%dt= t('country')
|
||||||
|
%dd= @invoice.buyer_country
|
||||||
|
|
||||||
|
%dt= t('phone')
|
||||||
|
%dd= @invoice.buyer_phone
|
||||||
|
|
||||||
|
%dt= t('url')
|
||||||
|
%dd= @invoice.buyer_url
|
||||||
|
|
||||||
|
%dt= t('email')
|
||||||
|
%dd= @invoice.buyer_email
|
||||||
|
|
||||||
|
|
||||||
|
/ = render 'registrar/invoices/partials/details'
|
||||||
|
|
||||||
|
/ .col-md-6= render 'registrar/invoices/partials/buyer'
|
||||||
|
.clear
|
||||||
|
.row.pull-down
|
||||||
|
.col-md-12= render 'registrar/invoices/partials/items'
|
||||||
|
|
||||||
|
#footer
|
||||||
|
%hr
|
||||||
|
.row
|
||||||
|
.col-md-3
|
||||||
|
= @invoice.seller_name
|
||||||
|
%br
|
||||||
|
= @invoice.seller_address
|
||||||
|
%br
|
||||||
|
= @invoice.seller_country
|
||||||
|
%br
|
||||||
|
= "#{t('reg_no')} #{@invoice.seller_reg_no}"
|
||||||
|
%br
|
||||||
|
= "#{t('vat_no')} #{@invoice.seller_vat_no}"
|
||||||
|
|
||||||
|
.col-md-3
|
||||||
|
= @invoice.seller_phone
|
||||||
|
%br
|
||||||
|
= @invoice.seller_email
|
||||||
|
%br
|
||||||
|
= @invoice.seller_url
|
||||||
|
|
||||||
|
.col-md-3.text-right
|
||||||
|
= t('bank')
|
||||||
|
%br
|
||||||
|
= t('iban')
|
||||||
|
%br
|
||||||
|
= t('swift')
|
||||||
|
|
||||||
|
.col-md-3
|
||||||
|
= @invoice.seller_bank
|
||||||
|
%br
|
||||||
|
= @invoice.seller_iban
|
||||||
|
%br
|
||||||
|
= @invoice.seller_swift
|
|
@ -1,4 +1,6 @@
|
||||||
- content_for :actions do
|
- content_for :actions do
|
||||||
|
= link_to(t(:download), download_pdf_registrar_invoice_path(@invoice), class: 'btn btn-default')
|
||||||
|
= link_to(t(:forward_invoice), forward_registrar_invoice_path(@invoice), class: 'btn btn-default')
|
||||||
= link_to(t(:back), :back, class: 'btn btn-default')
|
= link_to(t(:back), :back, class: 'btn btn-default')
|
||||||
= render 'shared/title', name: t(:invoice_no, no: @invoice.id)
|
= render 'shared/title', name: t(:invoice_no, no: @invoice.id)
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Rails.application.config.assets.precompile += %w( login.css registrar-manifest.css )
|
Rails.application.config.assets.precompile += %w( login.css registrar-manifest.css shared/pdf.css )
|
||||||
|
|
7
config/initializers/pdfkit.rb
Normal file
7
config/initializers/pdfkit.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
PDFKit.configure do |config|
|
||||||
|
config.wkhtmltopdf = "#{Rails.root}/vendor/bin/wkhtmltopdf"
|
||||||
|
config.default_options = {
|
||||||
|
page_size: 'A4'
|
||||||
|
# :print_media_type => true
|
||||||
|
}
|
||||||
|
end
|
|
@ -723,3 +723,8 @@ en:
|
||||||
registrar_head_title: 'EIS Registrar'
|
registrar_head_title: 'EIS Registrar'
|
||||||
admin_head_title: 'Estonian Internet Foundation'
|
admin_head_title: 'Estonian Internet Foundation'
|
||||||
bind_manually: 'Bind manually'
|
bind_manually: 'Bind manually'
|
||||||
|
forward_invoice: 'Forward invoice'
|
||||||
|
forward: 'Forward'
|
||||||
|
back_to_invoice: 'Back to invoice'
|
||||||
|
invoice_forwared: 'Invoice forwarded'
|
||||||
|
failed_to_forward_invoice: 'Failed to forward invoice'
|
||||||
|
|
|
@ -20,7 +20,11 @@ Rails.application.routes.draw do
|
||||||
namespace :registrar do
|
namespace :registrar do
|
||||||
root 'polls#show'
|
root 'polls#show'
|
||||||
|
|
||||||
resources :invoices
|
resources :invoices do
|
||||||
|
get 'download_pdf', on: :member
|
||||||
|
match 'forward', on: :member, via: [:post, :get]
|
||||||
|
end
|
||||||
|
|
||||||
resources :deposits
|
resources :deposits
|
||||||
resources :account_activities
|
resources :account_activities
|
||||||
|
|
||||||
|
|
BIN
vendor/bin/wkhtmltopdf
vendored
Executable file
BIN
vendor/bin/wkhtmltopdf
vendored
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue