Class: PaperlessToXero::InvoiceItem

Inherits:
Object
  • Object
show all
Includes:
DecimalHelpers
Defined in:
lib/paperless_to_xero/invoice_item.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DecimalHelpers

#amounts_when_vat_exclusive, #amounts_when_vat_inclusive, #formatted_decimal

Constructor Details

#initialize(description, amount, vat_amount, category, vat_note = 'VAT - 15%', vat_inclusive = true) ⇒ InvoiceItem

Returns a new instance of InvoiceItem.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/paperless_to_xero/invoice_item.rb', line 32

def initialize(description, amount, vat_amount, category, vat_note = 'VAT - 15%', vat_inclusive = true)
  @amount, @vat_amount, @description, @category, @vat_inclusive = amount, vat_amount, description, category, vat_inclusive
  @vat_type = extract_vat_type(vat_note)
  
  vat_rate = fetch_vat_rate(vat_type)
  case vat_rate
  when BigDecimal
    decimal_amount = BigDecimal.new(@amount)
    decimal_vat_amount = @vat_amount.nil? ? nil : BigDecimal.new(@vat_amount)
    amounts_method = vat_inclusive ? :amounts_when_vat_inclusive : :amounts_when_vat_exclusive
    @vat_exclusive_amount, @vat_amount, @vat_inclusive_amount = self.send(amounts_method, decimal_amount, decimal_vat_amount)
  else
    amounts_when_zero_rated_or_non_vat(vat_rate)
  end
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



30
31
32
# File 'lib/paperless_to_xero/invoice_item.rb', line 30

def amount
  @amount
end

#categoryObject (readonly)

Returns the value of attribute category.



30
31
32
# File 'lib/paperless_to_xero/invoice_item.rb', line 30

def category
  @category
end

#descriptionObject (readonly)

Returns the value of attribute description.



30
31
32
# File 'lib/paperless_to_xero/invoice_item.rb', line 30

def description
  @description
end

#vat_amountObject (readonly)

Returns the value of attribute vat_amount.



30
31
32
# File 'lib/paperless_to_xero/invoice_item.rb', line 30

def vat_amount
  @vat_amount
end

#vat_exclusive_amountObject (readonly)

Returns the value of attribute vat_exclusive_amount.



30
31
32
# File 'lib/paperless_to_xero/invoice_item.rb', line 30

def vat_exclusive_amount
  @vat_exclusive_amount
end

#vat_inclusiveObject (readonly)

Returns the value of attribute vat_inclusive.



30
31
32
# File 'lib/paperless_to_xero/invoice_item.rb', line 30

def vat_inclusive
  @vat_inclusive
end

#vat_inclusive_amountObject (readonly)

Returns the value of attribute vat_inclusive_amount.



30
31
32
# File 'lib/paperless_to_xero/invoice_item.rb', line 30

def vat_inclusive_amount
  @vat_inclusive_amount
end

#vat_typeObject (readonly)

Returns the value of attribute vat_type.



30
31
32
# File 'lib/paperless_to_xero/invoice_item.rb', line 30

def vat_type
  @vat_type
end

Class Method Details

.fetch_vat_rate(vat_type) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/paperless_to_xero/invoice_item.rb', line 10

def fetch_vat_rate(vat_type)
  @vat_rates ||= {
    '5.5% (France, VAT on expenses)' => 1.055.to_d,
    '19.6% (France, VAT on expenses)' => 1.196.to_d,
    '7% (Germany, VAT on expenses)' => 1.07.to_d,
    '19% (Germany, VAT on expenses)' => 1.19.to_d,
    '25% (Denmark, VAT on expenses)' => 1.25.to_d,
    '25% (Sweden, VAT on expenses)' => 1.25.to_d,
    '21.5% (Ireland, VAT on expenses)' => 1.215.to_d,
    '15% (EU VAT ID)' => 1.15.to_d,
    '15% (VAT on expenses)' => 1.15.to_d,
    '17.5% (VAT on expenses)' => 1.175.to_d,
    '20% (VAT on expenses)' => 1.2.to_d,
    'Zero Rated Expenses' => 0,
    '15% (Luxembourg, VAT on expenses)' => 1.15.to_d
  }
  @vat_rates[vat_type]
end