br_invoices_pdf 0.2.6.alpha.19 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +0 -1
  3. data/CHANGELOG.md +0 -1
  4. data/Gemfile +0 -2
  5. data/Rakefile +0 -2
  6. data/bin/console +0 -1
  7. data/br_invoices_pdf.gemspec +0 -1
  8. data/lib/br_invoices_pdf.rb +0 -12
  9. data/lib/br_invoices_pdf/cfe.rb +1 -2
  10. data/lib/br_invoices_pdf/cfe/parser.rb +3 -5
  11. data/lib/br_invoices_pdf/cfe/parser/access_key.rb +1 -3
  12. data/lib/br_invoices_pdf/cfe/parser/base_parser.rb +19 -0
  13. data/lib/br_invoices_pdf/cfe/parser/cnpj.rb +1 -3
  14. data/lib/br_invoices_pdf/cfe/parser/company_attributes.rb +1 -3
  15. data/lib/br_invoices_pdf/cfe/parser/cpf.rb +1 -3
  16. data/lib/br_invoices_pdf/cfe/parser/document_number.rb +1 -3
  17. data/lib/br_invoices_pdf/cfe/parser/fisco_obs.rb +1 -3
  18. data/lib/br_invoices_pdf/cfe/parser/payment.rb +1 -3
  19. data/lib/br_invoices_pdf/cfe/parser/payments.rb +16 -6
  20. data/lib/br_invoices_pdf/cfe/parser/products_data.rb +2 -4
  21. data/lib/br_invoices_pdf/cfe/parser/sat.rb +1 -3
  22. data/lib/br_invoices_pdf/cfe/renderer.rb +18 -4
  23. data/lib/br_invoices_pdf/cfe/renderer/base_renderer.rb +62 -5
  24. data/lib/br_invoices_pdf/cfe/renderer/company_identification.rb +0 -3
  25. data/lib/br_invoices_pdf/cfe/renderer/fisco_info.rb +0 -3
  26. data/lib/br_invoices_pdf/cfe/renderer/header.rb +0 -3
  27. data/lib/br_invoices_pdf/cfe/renderer/payment_forms.rb +12 -6
  28. data/lib/br_invoices_pdf/cfe/renderer/product_table.rb +48 -4
  29. data/lib/br_invoices_pdf/cfe/renderer/qr_code.rb +9 -5
  30. data/lib/br_invoices_pdf/cfe/renderer/taxes_info.rb +2 -5
  31. data/lib/br_invoices_pdf/cfe/renderer/totals.rb +24 -3
  32. data/lib/br_invoices_pdf/errors/invalid_document_type.rb +0 -2
  33. data/lib/br_invoices_pdf/generator.rb +0 -2
  34. data/lib/br_invoices_pdf/version.rb +1 -3
  35. metadata +6 -34
  36. data/.codeclimate.yml +0 -17
  37. data/lib/br_invoices_pdf/nfce.rb +0 -11
  38. data/lib/br_invoices_pdf/nfce/parser.rb +0 -33
  39. data/lib/br_invoices_pdf/nfce/parser/additional_info.rb +0 -17
  40. data/lib/br_invoices_pdf/nfce/parser/company.rb +0 -25
  41. data/lib/br_invoices_pdf/nfce/parser/customer.rb +0 -32
  42. data/lib/br_invoices_pdf/nfce/parser/emission_details.rb +0 -51
  43. data/lib/br_invoices_pdf/nfce/parser/payments.rb +0 -30
  44. data/lib/br_invoices_pdf/nfce/parser/products.rb +0 -39
  45. data/lib/br_invoices_pdf/nfce/parser/totals.rb +0 -25
  46. data/lib/br_invoices_pdf/nfce/renderer.rb +0 -37
  47. data/lib/br_invoices_pdf/nfce/renderer/base_renderer.rb +0 -22
  48. data/lib/br_invoices_pdf/nfce/renderer/company_identification.rb +0 -37
  49. data/lib/br_invoices_pdf/nfce/renderer/customer_identification.rb +0 -47
  50. data/lib/br_invoices_pdf/nfce/renderer/fiscal_message.rb +0 -46
  51. data/lib/br_invoices_pdf/nfce/renderer/header.rb +0 -32
  52. data/lib/br_invoices_pdf/nfce/renderer/payment_forms.rb +0 -73
  53. data/lib/br_invoices_pdf/nfce/renderer/product_table.rb +0 -23
  54. data/lib/br_invoices_pdf/nfce/renderer/qr_code.rb +0 -56
  55. data/lib/br_invoices_pdf/nfce/renderer/taxes_info.rb +0 -28
  56. data/lib/br_invoices_pdf/nfce/renderer/totals.rb +0 -30
  57. data/lib/br_invoices_pdf/util/base_renderer.rb +0 -121
  58. data/lib/br_invoices_pdf/util/enum.rb +0 -20
  59. data/lib/br_invoices_pdf/util/mount_params.rb +0 -26
  60. data/lib/br_invoices_pdf/util/nfce_check_urls.rb +0 -102
  61. data/lib/br_invoices_pdf/util/pdf_renderer.rb +0 -33
  62. data/lib/br_invoices_pdf/util/product_table.rb +0 -57
  63. data/lib/br_invoices_pdf/util/xml_locate.rb +0 -21
  64. data/nfce.xml +0 -160
@@ -1,10 +1,7 @@
1
- # frozen_string_literal: true
2
-
3
1
  module BrInvoicesPdf
4
2
  module Cfe
5
3
  module Renderer
6
4
  module Header
7
- extend Util::BaseRenderer
8
5
  extend BaseRenderer
9
6
 
10
7
  module_function
@@ -1,16 +1,19 @@
1
- # frozen_string_literal: true
2
-
3
1
  module BrInvoicesPdf
4
2
  module Cfe
5
3
  module Renderer
6
4
  module PaymentForms
7
- extend Util::BaseRenderer
8
5
  extend BaseRenderer
9
6
 
10
7
  module_function
11
8
 
12
9
  def execute(pdf, data)
13
- execute_payment_form(pdf, payments_table_data(data))
10
+ pdf.font_size(6) do
11
+ width = page_content_width(pdf)
12
+ table_data = payments_table_data(data)
13
+ render_table(pdf, table_data, width)
14
+ end
15
+
16
+ pdf.move_down(5)
14
17
  end
15
18
 
16
19
  def render_table(pdf, table_data, width)
@@ -30,10 +33,13 @@ module BrInvoicesPdf
30
33
  end
31
34
  private_class_method :format_table
32
35
 
36
+ PAYMENTS_TABLE_BASE_DATA = [['FORMA DE PAGAMENTO', 'VALOR']].freeze
33
37
  def payments_table_data(data)
34
- payments_data = mount_payment_data(data)
38
+ payments_data = data[:payments].reduce(PAYMENTS_TABLE_BASE_DATA) do |result, cur|
39
+ result + [[cur[:type], format_currency(cur[:amount])]]
40
+ end
35
41
 
36
- add_default_values(payments_data, data[:totals])
42
+ add_default_values(payments_data, data[:payment])
37
43
  end
38
44
  private_class_method :payments_table_data
39
45
 
@@ -1,11 +1,7 @@
1
- # frozen_string_literal: true
2
-
3
1
  module BrInvoicesPdf
4
2
  module Cfe
5
3
  module Renderer
6
4
  module ProductTable
7
- extend Util::BaseRenderer
8
- extend Util::ProductTable
9
5
  extend BaseRenderer
10
6
 
11
7
  module_function
@@ -19,6 +15,54 @@ module BrInvoicesPdf
19
15
 
20
16
  pdf.move_down(5)
21
17
  end
18
+
19
+ def format_table(pdf, table_data)
20
+ width = page_content_width(pdf)
21
+ pdf.table(table_data, width: width) do |table|
22
+ format_row(table.row(0))
23
+ format_columns(table)
24
+ end
25
+ end
26
+ private_class_method :format_table
27
+
28
+ def format_row(row)
29
+ row.font_style = :bold
30
+ row.align = :center
31
+ end
32
+ private_class_method :format_row
33
+
34
+ # :reek:FeatureEnvy
35
+ def format_columns(table)
36
+ table.columns(0..5).valign = :center
37
+ table.columns([2, 4, 5]).align = :right
38
+ table.column(3).align = :center
39
+ table_widths(table, table.width)
40
+ end
41
+ private_class_method :format_columns
42
+
43
+ # :reek:FeatureEnvy
44
+ def table_widths(table, width)
45
+ table.column(0).width = width * 0.16
46
+ table.columns([2, 3]).width = width * 0.155
47
+ table.column([4, 5]).width = width * 0.135
48
+ end
49
+ private_class_method :table_widths
50
+
51
+ PRODUCT_TABLE_BASE_DATA = [['CÓD.', 'DESCRIÇÃO', 'QTD.', 'UND.', 'V.UNIT', 'V.TOT']].freeze
52
+ # :reek:FeatureEnvy
53
+ def product_table_data(data)
54
+ data[:products].reduce(PRODUCT_TABLE_BASE_DATA) do |result, cur|
55
+ result + [[
56
+ cur[:code],
57
+ cur[:description],
58
+ format_number(cur[:quantity]),
59
+ cur[:unit_label],
60
+ format_currency(cur[:unit_value]),
61
+ format_currency(cur[:total_value])
62
+ ]]
63
+ end
64
+ end
65
+ private_class_method :product_table_data
22
66
  end
23
67
  end
24
68
  end
@@ -1,15 +1,12 @@
1
- # frozen_string_literal: true
2
-
3
1
  module BrInvoicesPdf
4
2
  module Cfe
5
3
  module Renderer
6
4
  module QrCode
7
- extend Util::BaseRenderer
8
5
  extend BaseRenderer
9
6
 
10
7
  module_function
11
8
 
12
- SAT_QRCODE_SEPARATOR = '|'
9
+ SAT_QRCODE_SEPARATOR = '|'.freeze
13
10
  BARCODE_HEIGHT = 50
14
11
 
15
12
  def execute(pdf, data)
@@ -53,12 +50,19 @@ module BrInvoicesPdf
53
50
  end
54
51
  private_class_method :generate_qr_code
55
52
 
53
+ def generate_qr_code_data(qr_code_string, qrcode_size)
54
+ qrcode = RQRCode::QRCode.new(qr_code_string)
55
+ blob = qrcode.as_png(size: qrcode_size.to_i, border_modules: 0).to_blob
56
+ StringIO.new(blob)
57
+ end
58
+ private_class_method :generate_qr_code_data
59
+
56
60
  # rubocop:disable Metrics/AbcSize
57
61
  def generate_qr_code_string(access_key, data)
58
62
  sat_params = data[:sat_params]
59
63
  access_key + SAT_QRCODE_SEPARATOR + sat_params[:emission_date] +
60
64
  SAT_QRCODE_SEPARATOR + sat_params[:emission_hour] +
61
- SAT_QRCODE_SEPARATOR + data[:totals][:total].delete('.') + SAT_QRCODE_SEPARATOR +
65
+ SAT_QRCODE_SEPARATOR + data[:payment][:total].delete('.') + SAT_QRCODE_SEPARATOR +
62
66
  data[:company_attributes][:cnpj] + SAT_QRCODE_SEPARATOR +
63
67
  sat_params[:document_qr_code_signature]
64
68
  end
@@ -1,17 +1,14 @@
1
- # frozen_string_literal: true
2
-
3
1
  module BrInvoicesPdf
4
2
  module Cfe
5
3
  module Renderer
6
4
  module TaxesInfo
7
- extend Util::BaseRenderer
8
5
  extend BaseRenderer
9
6
 
10
7
  module_function
11
8
 
12
9
  def execute(pdf, data)
13
10
  box(pdf, [0, pdf.cursor], page_content_width(pdf)) do
14
- tribute_values(pdf, data[:totals])
11
+ tribute_values(pdf, data[:payment])
15
12
  sat_params = data[:sat_params]
16
13
  sat_number(pdf, sat_params[:sat_number])
17
14
  date_values(pdf, sat_params)
@@ -20,7 +17,7 @@ module BrInvoicesPdf
20
17
 
21
18
  def date_values(pdf, data)
22
19
  time = data[:emission_date] + data[:emission_hour]
23
- pdf.text(Date.parse(time).strftime('%d/%m/%Y %H:%M:%S'), align: :center)
20
+ pdf.text(DateTime.parse(time).strftime('%d/%m/%Y %H:%M:%S'), align: :center)
24
21
  end
25
22
  private_class_method :date_values
26
23
 
@@ -1,10 +1,7 @@
1
- # frozen_string_literal: true
2
-
3
1
  module BrInvoicesPdf
4
2
  module Cfe
5
3
  module Renderer
6
4
  module Totals
7
- extend Util::BaseRenderer
8
5
  extend BaseRenderer
9
6
 
10
7
  module_function
@@ -15,6 +12,30 @@ module BrInvoicesPdf
15
12
  pdf.move_down(5)
16
13
  end
17
14
 
15
+ def insert_box_info(pdf, data, xpos = 0)
16
+ third_width = page_content_width(pdf) * 0.333333333
17
+ ypos = pdf.cursor
18
+ box_info(data[:payment]).each do |(title, value)|
19
+ insert_box(pdf, title: title, value: value, xpos: xpos, ypos: ypos, third_width: third_width)
20
+ xpos += third_width
21
+ end
22
+ end
23
+ private_class_method :insert_box_info
24
+
25
+ # :reek:FeatureEnvy
26
+ def insert_box(pdf, params)
27
+ box(pdf, [params[:xpos], params[:ypos]], params[:third_width]) do
28
+ insert_texts(pdf, params[:title], params[:value])
29
+ end
30
+ end
31
+ private_class_method :insert_box
32
+
33
+ def insert_texts(pdf, title, value)
34
+ pdf.text(title, style: :italic)
35
+ pdf.text(value, align: :right)
36
+ end
37
+ private_class_method :insert_texts
38
+
18
39
  def box_info(data_payment)
19
40
  [
20
41
  ['Total bruto dos itens', format_currency(data_payment[:total_price])],
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module BrInvoicesPdf
4
2
  module Errors
5
3
  class InvalidDocumentType < StandardError
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module BrInvoicesPdf
4
2
  class Generator
5
3
  PDF_OPTIONS = { page_size: 'A4', margin: [40, 75] }.freeze
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module BrInvoicesPdf
4
- VERSION = '0.2.6'
2
+ VERSION = '0.2.6'.freeze
5
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: br_invoices_pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6.alpha.19
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thiago Ribeiro
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-10-26 00:00:00.000000000 Z
12
+ date: 2017-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: prawn
@@ -215,7 +215,6 @@ executables: []
215
215
  extensions: []
216
216
  extra_rdoc_files: []
217
217
  files:
218
- - ".codeclimate.yml"
219
218
  - ".coveralls.yml"
220
219
  - ".gitignore"
221
220
  - ".reek"
@@ -235,6 +234,7 @@ files:
235
234
  - lib/br_invoices_pdf/cfe.rb
236
235
  - lib/br_invoices_pdf/cfe/parser.rb
237
236
  - lib/br_invoices_pdf/cfe/parser/access_key.rb
237
+ - lib/br_invoices_pdf/cfe/parser/base_parser.rb
238
238
  - lib/br_invoices_pdf/cfe/parser/cnpj.rb
239
239
  - lib/br_invoices_pdf/cfe/parser/company_attributes.rb
240
240
  - lib/br_invoices_pdf/cfe/parser/cpf.rb
@@ -256,35 +256,7 @@ files:
256
256
  - lib/br_invoices_pdf/cfe/renderer/totals.rb
257
257
  - lib/br_invoices_pdf/errors/invalid_document_type.rb
258
258
  - lib/br_invoices_pdf/generator.rb
259
- - lib/br_invoices_pdf/nfce.rb
260
- - lib/br_invoices_pdf/nfce/parser.rb
261
- - lib/br_invoices_pdf/nfce/parser/additional_info.rb
262
- - lib/br_invoices_pdf/nfce/parser/company.rb
263
- - lib/br_invoices_pdf/nfce/parser/customer.rb
264
- - lib/br_invoices_pdf/nfce/parser/emission_details.rb
265
- - lib/br_invoices_pdf/nfce/parser/payments.rb
266
- - lib/br_invoices_pdf/nfce/parser/products.rb
267
- - lib/br_invoices_pdf/nfce/parser/totals.rb
268
- - lib/br_invoices_pdf/nfce/renderer.rb
269
- - lib/br_invoices_pdf/nfce/renderer/base_renderer.rb
270
- - lib/br_invoices_pdf/nfce/renderer/company_identification.rb
271
- - lib/br_invoices_pdf/nfce/renderer/customer_identification.rb
272
- - lib/br_invoices_pdf/nfce/renderer/fiscal_message.rb
273
- - lib/br_invoices_pdf/nfce/renderer/header.rb
274
- - lib/br_invoices_pdf/nfce/renderer/payment_forms.rb
275
- - lib/br_invoices_pdf/nfce/renderer/product_table.rb
276
- - lib/br_invoices_pdf/nfce/renderer/qr_code.rb
277
- - lib/br_invoices_pdf/nfce/renderer/taxes_info.rb
278
- - lib/br_invoices_pdf/nfce/renderer/totals.rb
279
- - lib/br_invoices_pdf/util/base_renderer.rb
280
- - lib/br_invoices_pdf/util/enum.rb
281
- - lib/br_invoices_pdf/util/mount_params.rb
282
- - lib/br_invoices_pdf/util/nfce_check_urls.rb
283
- - lib/br_invoices_pdf/util/pdf_renderer.rb
284
- - lib/br_invoices_pdf/util/product_table.rb
285
- - lib/br_invoices_pdf/util/xml_locate.rb
286
259
  - lib/br_invoices_pdf/version.rb
287
- - nfce.xml
288
260
  homepage: https://github.com/pdvend/br_invoices_pdf
289
261
  licenses:
290
262
  - MIT
@@ -300,12 +272,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
300
272
  version: '0'
301
273
  required_rubygems_version: !ruby/object:Gem::Requirement
302
274
  requirements:
303
- - - ">"
275
+ - - ">="
304
276
  - !ruby/object:Gem::Version
305
- version: 1.3.1
277
+ version: '0'
306
278
  requirements: []
307
279
  rubyforge_project:
308
- rubygems_version: 2.6.14
280
+ rubygems_version: 2.6.13
309
281
  signing_key:
310
282
  specification_version: 4
311
283
  summary: Brazilian Fiscal Documents PDF generator
data/.codeclimate.yml DELETED
@@ -1,17 +0,0 @@
1
- engines:
2
- rubocop:
3
- enabled: false
4
- #checks:
5
- # Rubocop/Metrics/ClassLength:
6
- # enabled: false
7
- duplication:
8
- enabled: true
9
- config:
10
- languages:
11
- - ruby:
12
- ratings:
13
- paths:
14
- - lib/**/*
15
- exclude_paths:
16
- - spec/**/*
17
- - lib/br_invoices_pdf/nfce/parser/emission_details.rb
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'br_invoices_pdf/nfce/parser'
4
- require 'br_invoices_pdf/nfce/renderer/base_renderer'
5
- require 'br_invoices_pdf/nfce/renderer'
6
-
7
- module BrInvoicesPdf
8
- module Cfe
9
- BrInvoicesPdf.register(:nfce, Nfce::Renderer, Nfce::Parser)
10
- end
11
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'br_invoices_pdf/nfce/parser/company'
4
- require 'br_invoices_pdf/nfce/parser/products'
5
- require 'br_invoices_pdf/nfce/parser/payments'
6
- require 'br_invoices_pdf/nfce/parser/customer'
7
- require 'br_invoices_pdf/nfce/parser/totals'
8
- require 'br_invoices_pdf/nfce/parser/additional_info'
9
- require 'br_invoices_pdf/nfce/parser/emission_details'
10
-
11
- module BrInvoicesPdf
12
- module Nfce
13
- module Parser
14
- module_function
15
-
16
- PARSERS = {
17
- company: Company,
18
- products: Products,
19
- payments: Payments,
20
- customer: Customer,
21
- totals: Totals,
22
- additional_info: AdditionalInfo,
23
- emission_details: EmissionDetails
24
- }.freeze
25
-
26
- def parse(xml)
27
- PARSERS.reduce({}) do |response, (param, parser)|
28
- { **response, param => parser.execute(xml) }
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BrInvoicesPdf
4
- module Nfce
5
- module Parser
6
- module AdditionalInfo
7
- extend Util::XmlLocate
8
-
9
- module_function
10
-
11
- def execute(xml)
12
- locate_element(xml, 'NFe/infAdic/infCpl')
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BrInvoicesPdf
4
- module Nfce
5
- module Parser
6
- module Company
7
- extend Util::XmlLocate
8
- extend Util::MountParams
9
-
10
- module_function
11
-
12
- EMIT_ROOT_PATH = "#{Util::XmlLocate::ROOT_PATH}/emit"
13
-
14
- def execute(xml)
15
- {
16
- name: locate_element(xml, "#{EMIT_ROOT_PATH}/xNome"),
17
- cnpj: locate_element(xml, "#{EMIT_ROOT_PATH}/CNPJ"),
18
- state_number: locate_element(xml, "#{EMIT_ROOT_PATH}/IE"),
19
- address: mount(xml, address_params(EMIT_ROOT_PATH, 'Emit'))
20
- }
21
- end
22
- end
23
- end
24
- end
25
- end