Sha256: e8fdee876b6cff791595560c1cb9c99c2e23bfd56710c0333266cd1e46576ad6

Contents?: true

Size: 1.18 KB

Versions: 15

Compression:

Stored size: 1.18 KB

Contents

require 'bigdecimal'

class ZbrojniNalog
  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 { |row| file.write(row + "\r\n") }
   end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
fina_files-0.1.7 lib/fina_files/zbrojni_nalog.rb
fina_files-0.1.6 lib/fina_files/zbrojni_nalog.rb
fina_files-0.1.5 lib/fina_files/zbrojni_nalog.rb
fina_files-0.1.4 lib/fina_files/zbrojni_nalog.rb
fina_files-0.1.3 lib/fina_files/zbrojni_nalog.rb
fina_files-0.1.2 lib/fina_files/zbrojni_nalog.rb
fina_files-0.1.1 lib/fina_files/zbrojni_nalog.rb
fina_files-0.1.0 lib/fina_files/zbrojni_nalog.rb
fina_files-0.0.9 lib/fina_files/zbrojni_nalog.rb
fina_files-0.0.8 lib/fina_files/zbrojni_nalog.rb
fina_files-0.0.7 lib/fina_files/zbrojni_nalog.rb
fina_files-0.0.6 lib/fina_files/zbrojni_nalog.rb
fina_files-0.0.5 lib/fina_files/zbrojni_nalog.rb
fina_files-0.0.4 lib/fina_files/zbrojni_nalog.rb
fina_files-0.0.3 lib/fina_files/zbrojni_nalog.rb