Module: SAFT::V2::Norway

Defined in:
lib/saft/v2/norway.rb

Defined Under Namespace

Modules: Types Classes: Account, VatTaxCode

Constant Summary collapse

PATH =
SAFT.gem_root + "vendor" + "norway"
VatTaxCodes =
Types::Array.of(VatTaxCode)
Accounts =
Types::Array.of(Account)

Class Method Summary collapse

Class Method Details

.general_ledger_accounts_2_digitsObject



104
105
106
107
108
109
110
# File 'lib/saft/v2/norway.rb', line 104

def self.general_ledger_accounts_2_digits
  return @general_ledger_accounts_2_digits if defined?(@general_ledger_accounts_2_digits)

  @general_ledger_accounts_2_digits = parse_general_ledger_accounts(
    SAFT::V2::Norway::PATH + "general_ledger_standard_accounts_2_character.csv",
  )
end

.general_ledger_accounts_4_digitsObject



112
113
114
115
116
117
118
# File 'lib/saft/v2/norway.rb', line 112

def self.general_ledger_accounts_4_digits
  return @general_ledger_accounts_4_digits if defined?(@general_ledger_accounts_4_digits)

  @general_ledger_accounts_4_digits = parse_general_ledger_accounts(
    SAFT::V2::Norway::PATH + "general_ledger_standard_accounts_4_character.csv",
  )
end

.parse_general_ledger_accounts(path) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/saft/v2/norway.rb', line 120

def self.parse_general_ledger_accounts(path)
  accounts = []

  CSV.foreach(path, headers: true, col_sep: ";") do |row|
    accounts.push({
      number: row["AccountID"],
      description_no: row["DescriptionNOB"],
      description_en: row["DescriptionENG"],
    })
  end

  Accounts[accounts].freeze
end

.std_account(number) ⇒ Object



80
81
82
# File 'lib/saft/v2/norway.rb', line 80

def self.(number)
  [number]
end

.std_account!(number) ⇒ Object



84
85
86
# File 'lib/saft/v2/norway.rb', line 84

def self.std_account!(number)
  .fetch(number)
end

.std_account_mapObject



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/saft/v2/norway.rb', line 68

def self.
  return @std_account_map if defined?(@std_account_map)

  @std_account_map = {}
  general_ledger_accounts_2_digits
    .each { @std_account_map[_1.number] = _1 }
  general_ledger_accounts_4_digits
    .each { @std_account_map[_1.number] = _1 }

  @std_account_map
end

.vat_code(code) ⇒ Object



96
97
98
# File 'lib/saft/v2/norway.rb', line 96

def self.vat_code(code)
  vat_code_map[code]
end

.vat_code!(code) ⇒ Object



100
101
102
# File 'lib/saft/v2/norway.rb', line 100

def self.vat_code!(code)
  vat_code_map.fetch(code)
end

.vat_code_mapObject



88
89
90
91
92
93
94
# File 'lib/saft/v2/norway.rb', line 88

def self.vat_code_map
  return @vat_code_map if defined?(@vat_code_map)

  @vat_code_map = vat_codes.each_with_object({}) do |vat_code, object|
    object[vat_code.code] = vat_code
  end
end

.vat_codesObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/saft/v2/norway.rb', line 47

def self.vat_codes
  return @vat_codes if defined?(@vat_codes)

  vat_codes = []
  CSV.foreach(
    SAFT::V2::Norway::PATH + "standard_tax_codes.csv",
    headers: true,
    col_sep: ";",
  ) do |row|
    vat_codes.push({
      code: row["Code"],
      description_no: row["DescriptionNOB"],
      description_en: row["DescriptionENG"],
      tax_rate: row["TaxRate"],
      compensation: row["Compensation"],
    })
  end

  @vat_codes = VatTaxCodes[vat_codes].freeze
end