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



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

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
  line_items.inject(BigDecimal.new('0')) { | sum, line_item | sum + BigDecimal.new(line_item.line_amount.to_s) }
end

#sub_total=(value) ⇒ Object

Deprecated (but API for setter remains).

As sub_total must equal SUM(line_item.line_amount) for the API call to pass, this is now automatically calculated in the sub_total method.



18
19
# File 'lib/xero_gateway/line_item_calculations.rb', line 18

def sub_total=(value)
end

#totalObject

Calculate the toal as sub_total + total_tax.



46
47
48
# File 'lib/xero_gateway/line_item_calculations.rb', line 46

def total
  sub_total + total_tax
end

#total=(value) ⇒ Object

Deprecated (but API for setter remains).

As total must equal sub_total + total_tax for the API call to pass, this is now automatically calculated in the total method.



42
43
# File 'lib/xero_gateway/line_item_calculations.rb', line 42

def total=(value)
end

#total_taxObject

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



34
35
36
# File 'lib/xero_gateway/line_item_calculations.rb', line 34

def total_tax
  line_items.inject(BigDecimal.new('0')) { | sum, line_item | sum + BigDecimal.new(line_item.tax_amount.to_s) }
end

#total_tax=(value) ⇒ Object

Deprecated (but API for setter remains).

As total_tax must equal SUM(line_item.tax_amount) for the API call to pass, this is now automatically calculated in the total_tax method.



30
31
# File 'lib/xero_gateway/line_item_calculations.rb', line 30

def total_tax=(value)
end