Sha256: 3b9d95460e7bcf6efae41ae43aa44482abe26a775c16e5c41c90333a89845056
Contents?: true
Size: 1.26 KB
Versions: 2
Compression:
Stored size: 1.26 KB
Contents
require 'bigdecimal' class ZbrojniNalogGenerator attr_accessor :datum, :nalozi attr_reader :rows, :iban_platitelj def initialize(iban_platitelj) @rows = [] @nalozi = [] @datum = DateTime.now @iban_platitelj = iban_platitelj end def rows @rows << row_300 @rows << row_301 @nalozi.each { |nalog| @rows << row_309(nalog) } @rows << row_399 end def row_300 datum.strftime('%Y%m%d') + "1701" + " "*985 + "300" end def row_301 "#{@iban_platitelj}HRK" + " "*24 + "%05d" % nalozi.count + zbroj_to_s + datum.strftime('%Y%m%d') + " "*916 + "301" end def row_309(nalog) nalog[2].ljust(34) + nalog[3].ljust(70) + " "*103 + nalog[1].ljust(140) +("%016.2f" % nalog[4]).gsub(".","") + nalog[0].gsub(" ","").ljust(26) + " "*159 + "0" + " "*449 + "309" end def zbroj_to_s raise 'nema naloga' if nalozi.count == 0 amount = nalozi.map do |nalog| BigDecimal.new(nalog[4].to_s).round(2) end.reduce(:+) ("%021.2f" % amount).gsub(".","") end def row_399 " "*997 + "399" end def export(file_name) File.open(File.expand_path(file_name), 'w:Windows-1250') do |file| rows.each do |row| encoded = (row + "\r\n").force_encoding("Windows-1250") file.write(encoded) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
fina_files-0.2.0 | lib/fina_files/zbrojni_nalog_generator.rb |
fina_files-0.1.9 | lib/fina_files/zbrojni_nalog_generator.rb |