Module: SAFT::V2::Norway

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

Defined Under Namespace

Modules: Types Classes: GroupingCategory, VatTaxCode

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.general_ledger_grouping_categoriesObject



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

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

  @general_ledger_grouping_categories = parse_general_ledger_grouping_catergories(
    SAFT::V2::Norway::PATH + "general_ledger_account_grouping_category_codes_income_statement_naeringsspesifikasjon.csv",
  )
end

.grouping_categoriesObject



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

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

  @grouping_categories = {}
  general_ledger_grouping_categories
    .each { @grouping_categories[_1.grouping_code] = _1 }

  @grouping_categories
end

.grouping_category(grouping_code) ⇒ Object



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

def self.grouping_category(grouping_code)
  grouping_categories[grouping_code]
end

.grouping_category!(grouping_code) ⇒ Object



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

def self.grouping_category!(grouping_code)
  grouping_categories.fetch(grouping_code)
end

.parse_general_ledger_grouping_catergories(path) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/saft/v2/norway.rb', line 113

def self.parse_general_ledger_grouping_catergories(path)
  groupings = []
  CSV.foreach(path, headers: true, col_sep: ";") do |row|

    groupings.push({
      grouping_category: row["GroupingCategory"],
      category_description_no: row["CategoryDescriptionNOB"],
      category_description_en: row["CategoryDescriptionENG"],
      grouping_code: row["GroupingCode"],
      code_description_no: row["CodeDescriptionNOB"],
      code_description_en: row["CodeDescriptionENG"],
    })
  end

  GroupingCategories[groupings].freeze
end

.vat_code(code) ⇒ Object



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

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

.vat_code!(code) ⇒ Object



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

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

.vat_code_mapObject



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

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



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

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