Skip to content

Instantly share code, notes, and snippets.

@ndrluis
Last active December 23, 2015 19:59
Show Gist options
  • Save ndrluis/6686237 to your computer and use it in GitHub Desktop.
Save ndrluis/6686237 to your computer and use it in GitHub Desktop.
Gera Update com as informações que se encontram na Nota Fiscal Paulista.
tributos = '0700120018002500020000000000000000000000000000000000000000000000'
Dir.glob("#{Dir.pwd}/cat52/*").each do |file|
total_tributos = Array.new(16,'0' * 14)
File.open(file,'r').each do |line|
serie_ecf ||= line[3..22]
if line[0..2] == 'E13'
valor_tributo = line[59..71]
aliquota = line[52..58].strip
case aliquota
when 'F1'
@totalizador_subs_trib_icms = valor_tributo
when 'F2'
@totalizador_subs_trib_icms2 = valor_tributo
end
if aliquota.length == 7
pos = aliquota[1..1].to_i
total_tributos[pos] = '0' + valor_tributo
end
end
end
total_tributos = total_tributos.join
puts %{
update aqreducao set totalizador_subs_trib_icms = '#{@totalizador_subs_trib_icms}',
totalizador_subs_trib_icms2 = '#{@totalizador_subs_trib_icms2}',
tributos = '#{tributos}',
tot_parcial_tributados = '#{total_tributos}';
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment