mirror of
https://github.com/internetee/registry.git
synced 2025-07-19 17:25:57 +02:00
Basic pdf generating
This commit is contained in:
parent
e987e201ad
commit
727d1226ad
15 changed files with 298 additions and 3 deletions
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
|
||||
padding: 10px
|
||||
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
|
||||
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
|
||||
|
|
|
@ -7,6 +7,9 @@ class Invoice < ActiveRecord::Base
|
|||
|
||||
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,
|
||||
:seller_iban, :buyer_name, :invoice_items, :vat_prc, presence: true
|
||||
|
||||
|
@ -38,6 +41,14 @@ class Invoice < ActiveRecord::Base
|
|||
Country.new(buyer_country_code)
|
||||
end
|
||||
|
||||
def forward
|
||||
return false unless valid?
|
||||
return false unless billing_email
|
||||
|
||||
# TODO: forward invoice
|
||||
true
|
||||
end
|
||||
|
||||
def items
|
||||
invoice_items
|
||||
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
|
||||
= 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')
|
||||
= render 'shared/title', name: t(:invoice_no, no: @invoice.id)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue