Class: Nfe::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/nfe_reader/product.rb

Overview

Detalhamento de Produtos e Serviços da NF-e

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Product

Fields Values

indTot: 0 - o valor do item (vProd) compõe o valor total da NF-e (vProd)

1 - o valor do item (vProd) não compõe o valor total da NF-e (vProd) (v2.0)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/nfe_reader/product.rb', line 17

def initialize(attrs = {})
  @number = attrs[:nItem]
  
  if attrs[:prod]
    @product_code = attrs[:prod][:cProd]
    @product = attrs[:prod][:xProd]
    @ean = attrs[:prod][:cEAN]
    @ncm = attrs[:prod][:NCM]
    
    # Sale
    @cfop = attrs[:prod][:CFOP]
    @unit_sale = attrs[:prod][:uCom]
    @amount_sale = attrs[:prod][:qCom]
    @value_sale = attrs[:prod][:vUnCom]
    @total = attrs[:prod][:vProd]

    # Numero do Pedido de Compra
    @demand_number = attrs[:prod][:xPed]
    # Item do Pedido de Compra
    @demand_item = attrs[:prod][:nItemPed]

    # GTIN (Global Trade ItemNumber)
    @gtin = attrs[:prod][:cEANTrib]
    
    @unit = attrs[:prod][:uTrib]
    @amount = attrs[:prod][:qTrib]
    @value = attrs[:prod][:vUnTrib]
    @kind = attrs[:prod][:indTot]
    @ipi_exception = attrs[:prod][:EXTIPI]
    @freight = attrs[:prod][:vFrete]
    @insurance = attrs[:prod][:vSeg]
    @discount = attrs[:prod][:vDesc]
    @other_value = attrs[:prod][:vOutro]
    
    @importation = create_resource(Nfe::Importation, attrs[:prod][:DI])
  end

  @armament = create_resources(Nfe::Armament, attrs[:arma])    if attrs[:arma]
  @medicament = create_resources(Nfe::Medicament, attrs[:med]) if attrs[:med]
  @fuel = Nfe::Fuel.new(attrs[:comb]) if attrs[:comb]
  @vehicle = Nfe::Vehicle.new(attrs[:veicProd]) if attrs[:veicProd]

  @exportation = create_resources(Nfe::Exportation, attrs[:detExport])

  if attrs[:imposto]
    @icms = create_resources(Nfe::Icms, attrs[:imposto][:ICMS])
    @cofins = create_resources(Nfe::Cofins, attrs[:imposto][:COFINS])
    @pis = create_resources(Nfe::Pis, attrs[:imposto][:PIS])
    @importation_tax = create_resource(Nfe::ImportationTax, attrs[:imposto][:II])
    @ipi = create_resource(Nfe::Ipi, attrs[:imposto][:IPI])
    @pis_st = create_resource(Nfe::PisSt, attrs[:imposto][:PISST])
    @cofins_st = create_resource(Nfe::CofinsSt, attrs[:imposto][:COFINSST])
    @issqn = create_resource(Nfe::Issqn, attrs[:imposto][:ISSQN])
  end
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def amount
  @amount
end

#amount_saleObject (readonly)

Returns the value of attribute amount_sale.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def amount_sale
  @amount_sale
end

#armamentObject (readonly)

Returns the value of attribute armament.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def armament
  @armament
end

#cfopObject (readonly)

Returns the value of attribute cfop.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def cfop
  @cfop
end

#demand_itemObject (readonly)

Returns the value of attribute demand_item.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def demand_item
  @demand_item
end

#demand_numberObject (readonly)

Returns the value of attribute demand_number.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def demand_number
  @demand_number
end

#discountObject (readonly)

Returns the value of attribute discount.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def discount
  @discount
end

#eanObject (readonly)

Returns the value of attribute ean.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def ean
  @ean
end

#exportationObject (readonly)

Returns the value of attribute exportation.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def exportation
  @exportation
end

#freightObject (readonly)

Returns the value of attribute freight.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def freight
  @freight
end

#fuelObject (readonly)

Returns the value of attribute fuel.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def fuel
  @fuel
end

#gtinObject (readonly)

Returns the value of attribute gtin.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def gtin
  @gtin
end

#icmsObject (readonly)

Returns the value of attribute icms.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def icms
  @icms
end

#importationObject (readonly)

Returns the value of attribute importation.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def importation
  @importation
end

#importation_taxObject (readonly)

Returns the value of attribute importation_tax.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def importation_tax
  @importation_tax
end

#insuranceObject (readonly)

Returns the value of attribute insurance.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def insurance
  @insurance
end

#ipiObject (readonly)

Returns the value of attribute ipi.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def ipi
  @ipi
end

#ipi_exceptionObject (readonly)

Returns the value of attribute ipi_exception.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def ipi_exception
  @ipi_exception
end

#kindObject (readonly)

Returns the value of attribute kind.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def kind
  @kind
end

#ncmObject (readonly)

Returns the value of attribute ncm.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def ncm
  @ncm
end

#numberObject (readonly)

Returns the value of attribute number.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def number
  @number
end

#other_valueObject (readonly)

Returns the value of attribute other_value.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def other_value
  @other_value
end

#pisObject (readonly)

Returns the value of attribute pis.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def pis
  @pis
end

#productObject (readonly)

Returns the value of attribute product.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def product
  @product
end

#product_codeObject (readonly)

Returns the value of attribute product_code.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def product_code
  @product_code
end

#totalObject (readonly)

Returns the value of attribute total.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def total
  @total
end

#unitObject (readonly)

Returns the value of attribute unit.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def unit
  @unit
end

#unit_saleObject (readonly)

Returns the value of attribute unit_sale.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def unit_sale
  @unit_sale
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def value
  @value
end

#value_saleObject (readonly)

Returns the value of attribute value_sale.



5
6
7
# File 'lib/nfe_reader/product.rb', line 5

def value_sale
  @value_sale
end

Instance Method Details

#create_resource(klass, attrs = {}) ⇒ Object



73
74
75
76
# File 'lib/nfe_reader/product.rb', line 73

def create_resource(klass, attrs = {})
  return unless attrs
  klass.new(attrs)
end

#create_resources(klass, attrs = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/nfe_reader/product.rb', line 78

def create_resources(klass, attrs = {})
  resources = []

  return resources unless attrs

  attrs.each do |a|
    resources << klass.new(a.last)
  end

  resources
end