Module: XeroGateway::LineItemCalculations

Included in:
BankTransaction, CreditNote, Invoice
Defined in:
lib/xero_gateway/line_item_calculations.rb

Instance Method Summary collapse

Instance Method Details

#add_line_item(params = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/xero_gateway/line_item_calculations.rb', line 4

def add_line_item(params = {})
  line_item = nil
  case params
    when Hash then      line_item = LineItem.new(params)
    when LineItem then  line_item = params
    else                raise InvalidLineItemError
  end
  @line_items << line_item
  line_item
end

#sub_totalObject

Calculate the sub_total as the SUM(line_item.line_amount).



22
23
24
# File 'lib/xero_gateway/line_item_calculations.rb', line 22

def sub_total
  total_cache(:sub_total) || sum_line_items(line_items, :line_amount)
end

#totalObject

Calculate the toal as sub_total + total_tax.



32
33
34
# File 'lib/xero_gateway/line_item_calculations.rb', line 32

def total
  total_cache(:total) || (sub_total + total_tax)
end

#total_taxObject

Calculate the total_tax as the SUM(line_item.tax_amount).



27
28
29
# File 'lib/xero_gateway/line_item_calculations.rb', line 27

def total_tax
  total_cache(:total_tax) || sum_line_items(line_items, :tax_amount)
end