Sha256: 89b4de657e8e21185bd7e5d085bb05b3185a5fc6f3e08fef6225077d1a26c101

Contents?: true

Size: 1.77 KB

Versions: 48

Compression:

Stored size: 1.77 KB

Contents

module PaisLegacy
  class Error < StandardError; end

  class TrialBalance

    @report = nil

    def initialize(report)
      @report = report
    end

    def display
      puts @report
    end

    def save_sample
      File.open("tmp/trial_balance_screen.sample","w") do |f|
        @report.each do |line|
          f.write "#{line}\n"
        end
      end
    end

    def accounts_from_trial_balance
      read = false
      accounts = []
      @report.each do |row|
        next if row.strip.length == 0

        read = false if end_reading(row)
        if read && (row[0..9].to_i>0)
          accounts << code_from_row(row)
        end
        read = true if start_reading(row)
      end

      accounts
    end

    def main_account(row)
      @main_code = row[0..7].strip
      @main_name = account_name(row)
      {
        code: "#{@main_code}",
        name: "#{"#{@main_code}-#{@main_name}".strip}",
        dr: dr(row),
        cr: cr(row)
      }
    end

    def sub_account(row)
      code = "#{@main_code}/#{row[0..9].strip}"
      name = "#{code}-#{@main_name} #{account_name(row)}"
      {
        code: "#{code}",
        name: "#{name.strip}",
        dr: dr(row),
        cr: cr(row)
      }
    end

    private
    def dr(row)
      row[47..59].strip.gsub(",",'')
    end

    def cr(row)
      row[60..74].strip.gsub(",",'')
    end

    def start_reading(row)
      row.include?("Acc Gst")
    end

    def end_reading(row)
      row.include?("Not Audited.")
    end

    def code_from_row(row)
      if is_sub_account(row)
        sub_account(row)
      else
        main_account(row)
      end
    end

    def account_name(row)
      row[14..46].strip
    end

    def is_sub_account(row)
      sub = row[0..9].strip
      sub.to_i > 0 && !sub.include?("/")
    end

  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
pais_legacy-2.6.11 lib/pais_legacy/trial_balance.rb
pais_legacy-2.6.10 lib/pais_legacy/trial_balance.rb
pais_legacy-2.6.9 lib/pais_legacy/trial_balance.rb
pais_legacy-2.6.8 lib/pais_legacy/trial_balance.rb
pais_legacy-2.6.7 lib/pais_legacy/trial_balance.rb
pais_legacy-2.6.6 lib/pais_legacy/trial_balance.rb
pais_legacy-2.6.5 lib/pais_legacy/trial_balance.rb
pais_legacy-2.6.4 lib/pais_legacy/trial_balance.rb
pais_legacy-2.6.3 lib/pais_legacy/trial_balance.rb
pais_legacy-2.6.2 lib/pais_legacy/trial_balance.rb
pais_legacy-2.6.1 lib/pais_legacy/trial_balance.rb
pais_legacy-2.6.0 lib/pais_legacy/trial_balance.rb
pais_legacy-2.5.1 lib/pais_legacy/trial_balance.rb
pais_legacy-2.5.0 lib/pais_legacy/trial_balance.rb
pais_legacy-2.4.2 lib/pais_legacy/trial_balance.rb
pais_legacy-2.4.1 lib/pais_legacy/trial_balance.rb
pais_legacy-2.4.0 lib/pais_legacy/trial_balance.rb
pais_legacy-2.3.7 lib/pais_legacy/trial_balance.rb
pais_legacy-2.3.6 lib/pais_legacy/trial_balance.rb
pais_legacy-2.3.5 lib/pais_legacy/trial_balance.rb