br_invoices_pdf 0.2.18 → 0.2.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 298be27e07b387193e6a49fbd0b1e69badf4bfc0
4
- data.tar.gz: db89d1cff2cf9d31bdf909a7e2587558f4169411
3
+ metadata.gz: 9789280a8f99b22f164b17335efc48fa5072a39b
4
+ data.tar.gz: 11546516680254d6b9502f55f7e813bd2a97077d
5
5
  SHA512:
6
- metadata.gz: 4dcd5f1177c71300991df3015951c148618fd650749002b2c766de21097a00e00616d03ec43dd145cfd6af3a446dcc8ae60c4a5f66b6043cf33170160ba1c41c
7
- data.tar.gz: 9b7d79d7cbb32652ba965a15149e7ead92b7cb9244005fcba150574050011bc9e53e26eab12310edb732f467f7afda8fef69fb51ac4c7768b7e437428caa2006
6
+ metadata.gz: bb34a40c5de90ac81f2fb6bb622832cee19f1c5a006e33f3e43af16d2f7e4bdce8c7835ed55d6439e826fb99fbbf7beec940e3d96351cceb1dd2af19e76b9a19
7
+ data.tar.gz: 0f6065d4951a1b3573cdc7ef9ba0062d743b542af4e153698115c817f01351de5fc33bafa236e02571bbb78fe5f28b72e184a034f7b367e8d44f88778e3057cb
@@ -26,11 +26,13 @@ module BrInvoicesPdf
26
26
  def generate(type, xml, options = {})
27
27
  generator = @generators[type]
28
28
  raise(Errors::InvalidDocumentType, type) unless generator
29
+
29
30
  generator.generate(xml, options)
30
31
  end
31
32
 
32
33
  def register(type, renderer, parser)
33
34
  raise(ArgumentError, "Expected Symbol or String to type. Received #{type.class}") unless valid_type?(type)
35
+
34
36
  @generators[type.to_sym] = Generator.new(renderer, parser)
35
37
  end
36
38
 
@@ -11,8 +11,10 @@ module BrInvoicesPdf
11
11
  def execute(xml)
12
12
  element = xml.locate('Signature/SignedInfo').first
13
13
  return unless element
14
+
14
15
  element = element.nodes.last
15
16
  return unless element
17
+
16
18
  element.attributes[:URI]
17
19
  end
18
20
  end
@@ -13,6 +13,7 @@ module BrInvoicesPdf
13
13
  node = element.nodes.first
14
14
  field = element.attributes[:xCampo]
15
15
  next unless node && field
16
+
16
17
  {
17
18
  text: node.text,
18
19
  field: field
@@ -12,6 +12,7 @@ module BrInvoicesPdf
12
12
  node_payments = xml.locate('infCFe/pgto')
13
13
 
14
14
  return unless node_payments
15
+
15
16
  payments_by_nodes(node_payments) if node_payments.any?
16
17
  end
17
18
 
@@ -9,16 +9,40 @@ module BrInvoicesPdf
9
9
  module_function
10
10
 
11
11
  def execute(xml)
12
- node_payments = xml.locate("#{root_path(xml)}/pag")
12
+ xml_version = xml.locate(root_path(xml).to_s)[0].attributes[:versao]
13
+
14
+ return payments_new_version(xml) if xml_version[0] == '4'
15
+
16
+ payments_old_version(xml)
17
+ end
13
18
 
19
+ def payments_old_version(xml)
20
+ node_payments = xml.locate("#{root_path(xml)}/pag")
14
21
  node_payments.map(&method(:payment_by))
15
22
  end
16
23
 
17
- def payment_by(element)
24
+ def payments_new_version(xml)
25
+ node_payments = xml.locate("#{root_path(xml)}/pag/detPag")
26
+ cashback = cashback_for(xml)
27
+
28
+ node_payments.map do |payment|
29
+ payment_by(payment, cashback: cashback)
30
+ end
31
+ end
32
+
33
+ def cashback_for(xml)
34
+ locate_element(xml.locate("#{root_path(xml)}/pag")[0], 'vTroco')
35
+ end
36
+
37
+ def payment_by(element, cashback: nil)
38
+ payment = locate_element(element, 'tPag')
39
+
40
+ cashback_amount = cashback if payment == '01'
41
+
18
42
  {
19
- type: Util::Enum::PAYMENT_TYPES[locate_element(element, 'tPag')],
43
+ type: Util::Enum::PAYMENT_TYPES[payment],
20
44
  amount: locate_element(element, 'vPag'),
21
- cashback: locate_element(element, 'vTroco')
45
+ cashback: cashback_amount || locate_element(element, 'vTroco')
22
46
  }
23
47
  end
24
48
  private_class_method :payment_by
@@ -13,6 +13,7 @@ module BrInvoicesPdf
13
13
  procon_message = data[:additional_variables][:procon_message]
14
14
 
15
15
  return if ['', nil].include? procon_message
16
+
16
17
  box(pdf, [0, pdf.cursor], page_content_width(pdf)) do
17
18
  procon_message(pdf, procon_message)
18
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BrInvoicesPdf
4
- VERSION = '0.2.18'
4
+ VERSION = '0.2.19'
5
5
  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.18
4
+ version: 0.2.19
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: 2018-08-30 00:00:00.000000000 Z
12
+ date: 2018-09-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: barby