Class: PaperlessToXero::Invoice

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DecimalHelpers

#amounts_when_vat_exclusive, #amounts_when_vat_inclusive, #formatted_decimal

Constructor Details

#initialize(date, merchant, reference_id, total, vat, vat_inclusive = true, currency = 'GBP') ⇒ Invoice

Returns a new instance of Invoice.



11
12
13
14
15
16
17
# File 'lib/paperless_to_xero/invoice.rb', line 11

def initialize(date, merchant, reference_id, total, vat, vat_inclusive = true, currency = 'GBP')
  @date, @merchant, @reference_id = date, merchant, reference_id
  @total, @vat_inclusive, @currency = total, vat_inclusive, currency
  decimal_total = BigDecimal.new(total)
  decimal_vat = BigDecimal.new(vat)
  @ex_vat_total, @vat_total, @inc_vat_total = amounts_when_vat_inclusive(decimal_total, decimal_vat)
end

Instance Attribute Details

#currencyObject (readonly)

Returns the value of attribute currency.



9
10
11
# File 'lib/paperless_to_xero/invoice.rb', line 9

def currency
  @currency
end

#dateObject (readonly)

Returns the value of attribute date.



9
10
11
# File 'lib/paperless_to_xero/invoice.rb', line 9

def date
  @date
end

#ex_vat_totalObject (readonly)

Returns the value of attribute ex_vat_total.



9
10
11
# File 'lib/paperless_to_xero/invoice.rb', line 9

def ex_vat_total
  @ex_vat_total
end

#inc_vat_totalObject (readonly)

Returns the value of attribute inc_vat_total.



9
10
11
# File 'lib/paperless_to_xero/invoice.rb', line 9

def inc_vat_total
  @inc_vat_total
end

#merchantObject (readonly)

Returns the value of attribute merchant.



9
10
11
# File 'lib/paperless_to_xero/invoice.rb', line 9

def merchant
  @merchant
end

#reference_idObject (readonly)

Returns the value of attribute reference_id.



9
10
11
# File 'lib/paperless_to_xero/invoice.rb', line 9

def reference_id
  @reference_id
end

#totalObject (readonly)

Returns the value of attribute total.



9
10
11
# File 'lib/paperless_to_xero/invoice.rb', line 9

def total
  @total
end

#vat_totalObject (readonly)

Returns the value of attribute vat_total.



9
10
11
# File 'lib/paperless_to_xero/invoice.rb', line 9

def vat_total
  @vat_total
end

Instance Method Details

#add_item(description, amount, vat_amount, category, vat_note) ⇒ Object



27
28
29
# File 'lib/paperless_to_xero/invoice.rb', line 27

def add_item(description, amount, vat_amount, category, vat_note)
  items << PaperlessToXero::InvoiceItem.new(description, amount, vat_amount, category, vat_note, @vat_inclusive)
end

#itemsObject



19
20
21
# File 'lib/paperless_to_xero/invoice.rb', line 19

def items
  @items ||= []
end

#serialise_to_csv(csv) ⇒ Object



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

def serialise_to_csv(csv)
  serialising_items = items.dup
  first_item = serialising_items.shift
  
  marked_merchant = currency != 'GBP' ? merchant + " (#{currency})" : merchant
  unless first_item.nil?
    csv << [marked_merchant, reference_id, date.strftime('%d/%m/%Y'), date.strftime('%d/%m/%Y'), 
            ex_vat_total, vat_total, inc_vat_total, first_item.description, '1', 
            first_item.vat_exclusive_amount, first_item.category, first_item.vat_type, first_item.vat_amount, 
            nil, nil, nil, nil]
  end
  serialising_items.each do |item|
    csv << [nil, reference_id, nil, nil, 
            nil, nil, nil, item.description, '1', 
            item.vat_exclusive_amount, item.category, item.vat_type, item.vat_amount, 
            nil, nil, nil, nil]
  end
end

#vat_inclusive?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/paperless_to_xero/invoice.rb', line 23

def vat_inclusive?
  @vat_inclusive
end