Class: SEFAZ::Webservice::SAT::Dataset::Sale

Inherits:
Object
  • Object
show all
Defined in:
lib/sefaz/webservice/sat/dataset/sale.rb

Overview

Principal classe de elaboração do XML de Venda para o módulo CFe-SAT

Defined Under Namespace

Classes: COFINS, COFINSAliq, COFINSNT, COFINSOutr, COFINSQtde, COFINSSN, COFINSST, DEST, DET, DescAcrEntr, EMIT, ENTREGA, ICMS, ICMS00, ICMS40, ICMSSN102, ICMSSN900, IDE, IMPOSTO, INFADIC, ISSQN, MP, OBSFISCODET, PGTO, PIS, PISAliq, PISNT, PISOutr, PISQtde, PISSN, PISST, PROD, TOTAL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSale

Returns a new instance of Sale.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/sefaz/webservice/sat/dataset/sale.rb', line 46

def initialize
  @versaoDadosEnt = "0.08"
  
  @ide = IDE.new
  @emit = EMIT.new
  @dest = DEST.new
  @entrega = ENTREGA.new
  @total = TOTAL.new
  @total.DescAcrEntr = DescAcrEntr.new
  @pgto = PGTO.new
  @pgto.MP = []
  @infAdic = INFADIC.new
  
  @listas = {}
  @listas[:det] = []
end

Instance Attribute Details

#destObject

Returns the value of attribute dest.



10
11
12
# File 'lib/sefaz/webservice/sat/dataset/sale.rb', line 10

def dest
  @dest
end

#detObject

Returns the value of attribute det.



10
11
12
# File 'lib/sefaz/webservice/sat/dataset/sale.rb', line 10

def det
  @det
end

#emitObject

Returns the value of attribute emit.



10
11
12
# File 'lib/sefaz/webservice/sat/dataset/sale.rb', line 10

def emit
  @emit
end

#entregaObject

Returns the value of attribute entrega.



10
11
12
# File 'lib/sefaz/webservice/sat/dataset/sale.rb', line 10

def entrega
  @entrega
end

#ideObject

Returns the value of attribute ide.



10
11
12
# File 'lib/sefaz/webservice/sat/dataset/sale.rb', line 10

def ide
  @ide
end

#infAdicObject

Returns the value of attribute infAdic.



10
11
12
# File 'lib/sefaz/webservice/sat/dataset/sale.rb', line 10

def infAdic
  @infAdic
end

#mpObject

Returns the value of attribute mp.



10
11
12
# File 'lib/sefaz/webservice/sat/dataset/sale.rb', line 10

def mp
  @mp
end

#obsfiscodetObject

Returns the value of attribute obsfiscodet.



10
11
12
# File 'lib/sefaz/webservice/sat/dataset/sale.rb', line 10

def obsfiscodet
  @obsfiscodet
end

#pgtoObject

Returns the value of attribute pgto.



10
11
12
# File 'lib/sefaz/webservice/sat/dataset/sale.rb', line 10

def pgto
  @pgto
end

#totalObject

Returns the value of attribute total.



10
11
12
# File 'lib/sefaz/webservice/sat/dataset/sale.rb', line 10

def total
  @total
end

Instance Method Details

#add(part_name) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/sefaz/webservice/sat/dataset/sale.rb', line 85

def add(part_name)
  part_object = case part_name
  when "DET"
    @det = DET.new
    @det.prod = PROD.new
    @det.prod.obsFiscoDet = []
    @det.imposto = IMPOSTO.new
    @det.imposto.ICMS = ICMS.new
    @det.imposto.ICMS.ICMS00 = ICMS00.new
    @det.imposto.ICMS.ICMS40 = ICMS40.new
    @det.imposto.ICMS.ICMSSN102 = ICMSSN102.new
    @det.imposto.ICMS.ICMSSN900 = ICMSSN900.new
    @det.imposto.PIS = PIS.new
    @det.imposto.PIS.PISAliq = PISAliq.new
    @det.imposto.PIS.PISQtde = PISQtde.new
    @det.imposto.PIS.PISNT = PISNT.new
    @det.imposto.PIS.PISSN = PISSN.new
    @det.imposto.PIS.PISOutr = PISOutr.new
    @det.imposto.PISST = PISST.new
    @det.imposto.COFINS = COFINS.new
    @det.imposto.COFINS.COFINSAliq = COFINSAliq.new
    @det.imposto.COFINS.COFINSQtde = COFINSQtde.new
    @det.imposto.COFINS.COFINSNT = COFINSNT.new
    @det.imposto.COFINS.COFINSSN = COFINSSN.new
    @det.imposto.COFINS.COFINSOutr = COFINSOutr.new
    @det.imposto.COFINSST = COFINSST.new
    @det.imposto.ISSQN = ISSQN.new
    @det
  when "OBSFISCODET"
    @obsfiscodet = OBSFISCODET.new
    @obsfiscodet
  when "MP"
    @mp = MP.new
    @mp
  end
  
  if block_given?
    yield(part_object)
    save(part_name)
  end
  
  nil
end

#gerarCFObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/sefaz/webservice/sat/dataset/sale.rb', line 63

def gerarCF
  # Raiz = CFe
  # A01 = infCFe
  # H01 = det
  # I01 = prod
  # M01 = imposto
  # N01 = ICMS
  hash = { CFe: { infCFe: { :@versaoDadosEnt => @versaoDadosEnt } } }
  hash[:CFe][:infCFe][:ide] = @ide.to_h
  hash[:CFe][:infCFe][:emit] = @emit.to_h
  hash[:CFe][:infCFe][:dest] = @dest.to_h
  hash[:CFe][:infCFe][:entrega] = @entrega.to_h
  hash[:CFe][:infCFe][:det] = @listas[:det]
  hash[:CFe][:infCFe][:total] = @total.to_h
  hash[:CFe][:infCFe][:total][:DescAcrEntr] = @total.DescAcrEntr.to_h
  hash[:CFe][:infCFe][:pgto] = @pgto.to_h
  hash[:CFe][:infCFe][:infAdic] = @infAdic.to_h
  compressed = hash.compress!
  
  return [compressed.to_xml!, compressed]
end

#save(part_name) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/sefaz/webservice/sat/dataset/sale.rb', line 129

def save(part_name)
  case part_name
  when "DET"
    if @det.is_a?(Struct::DET)
      item = @det
      item.prod = item.prod.to_h
      item.imposto.ICMS.ICMS00 = item.imposto.ICMS.ICMS00.to_h
      item.imposto.ICMS.ICMS40 = item.imposto.ICMS.ICMS40.to_h
      item.imposto.ICMS.ICMSSN102 = item.imposto.ICMS.ICMSSN102.to_h
      item.imposto.ICMS.ICMSSN900 = item.imposto.ICMS.ICMSSN900.to_h
      item.imposto.ICMS = item.imposto.ICMS.to_h
      item.imposto.PIS.PISAliq = item.imposto.PIS.PISAliq.to_h
      item.imposto.PIS.PISQtde = item.imposto.PIS.PISQtde.to_h
      item.imposto.PIS.PISNT = item.imposto.PIS.PISNT.to_h
      item.imposto.PIS.PISSN = item.imposto.PIS.PISSN.to_h
      item.imposto.PIS.PISOutr = item.imposto.PIS.PISOutr.to_h
      item.imposto.PIS = item.imposto.PIS.to_h
      item.imposto.PISST = item.imposto.PISST.to_h
      item.imposto.COFINS.COFINSAliq = item.imposto.COFINS.COFINSAliq.to_h
      item.imposto.COFINS.COFINSQtde = item.imposto.COFINS.COFINSQtde.to_h
      item.imposto.COFINS.COFINSNT = item.imposto.COFINS.COFINSNT.to_h
      item.imposto.COFINS.COFINSSN = item.imposto.COFINS.COFINSSN.to_h
      item.imposto.COFINS.COFINSOutr = item.imposto.COFINS.COFINSOutr.to_h
      item.imposto.COFINS = item.imposto.COFINS.to_h
      item.imposto.COFINSST = item.imposto.COFINSST.to_h
      item.imposto.ISSQN = item.imposto.ISSQN.to_h
      item.imposto = item.imposto.to_h
      item[:@nItem] = (@listas[:det].length + 1)
      @listas[:det].push(item.to_h)
    end
  when "OBSFISCODET"
    if @det.is_a?(Struct::DET) && @obsfiscodet.is_a?(Struct::OBSFISCODET)
      @det.prod.obsFiscoDet.push(@obsfiscodet.to_h)
    end
  when "MP"
    if @pgto.is_a?(Struct::PGTO) && @mp.is_a?(Struct::MP)
      @pgto.MP.push(@mp.to_h)
    end
  end
  
  nil
end