Class: SAFT::V2::HTML::TaxTable

Inherits:
Object
  • Object
show all
Defined in:
lib/saft/v2/html.rb

Instance Method Summary collapse

Constructor Details

#initialize(tax_table) ⇒ TaxTable

Returns a new instance of TaxTable.



296
297
298
# File 'lib/saft/v2/html.rb', line 296

def initialize(tax_table)
  @tax_table = tax_table
end

Instance Method Details

#to_tubbyObject



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/saft/v2/html.rb', line 300

def to_tubby
  Tubby.new { |t|
    t.table {
      t.thead {
        t.tr {
          t.th("Tax code")
          t.th("Description")
          t.th("Country")
          t.th("Std code")
          t.th("Tax %", class: "text-right")
          t.th("Base rate", class: "text-right")
          t.th("rest")
        }
      }
      t.tbody {
        @tax_table.each { |table|
          table.tax_code_details.each { |detail|
            vat_code = SAFT::V2::Norway.vat_code(detail.standard_tax_code)
            vat_code_title = "Not found"
            if vat_code
              vat_code_title = <<~TEXT
                Vat Code #{vat_code.code}
                #{vat_code.description_en}
                #{vat_code.description_no}
                #{vat_code.tax_rate}
                #{"Can be used for compensation" if vat_code.compensation}
              TEXT
            end

            t.tr {
              t.td(detail.tax_code)
              t.td(detail.description)
              t.td(detail.country)
              t.td(detail.standard_tax_code, title: vat_code_title)
              t.td(detail.tax_percentage, class: "text-right")
              t.td(class: "text-right") { detail.base_rates.each { t.div(_1) } }
              t.td(class: "pl-2") {
                t.div(class: "pl-2 border-l-2") {
                  t <<
                    RenderHash.new(
                      detail
                        .attributes
                        .except(
                          :tax_code,
                          :description,
                          :country,
                          :standard_tax_code,
                          :base_rate,
                          :tax_percentage,
                        ),
                    )
                }
              }
            }
          }
        }
      }
    }
  }
end