Class: InvoiceItem

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/fastbill/invoice_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth = nil) ⇒ InvoiceItem

Returns a new instance of InvoiceItem.



7
8
9
# File 'lib/fastbill/invoice_item.rb', line 7

def initialize(auth = nil)
  @auth = auth
end

Instance Attribute Details

#complete_grossObject

Returns the value of attribute complete_gross.



5
6
7
# File 'lib/fastbill/invoice_item.rb', line 5

def complete_gross
  @complete_gross
end

#complete_netObject

Returns the value of attribute complete_net.



5
6
7
# File 'lib/fastbill/invoice_item.rb', line 5

def complete_net
  @complete_net
end

#currency_codeObject

Returns the value of attribute currency_code.



5
6
7
# File 'lib/fastbill/invoice_item.rb', line 5

def currency_code
  @currency_code
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/fastbill/invoice_item.rb', line 5

def description
  @description
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/fastbill/invoice_item.rb', line 5

def id
  @id
end

#quantityObject

Returns the value of attribute quantity.



5
6
7
# File 'lib/fastbill/invoice_item.rb', line 5

def quantity
  @quantity
end

#sort_orderObject

Returns the value of attribute sort_order.



5
6
7
# File 'lib/fastbill/invoice_item.rb', line 5

def sort_order
  @sort_order
end

#unit_priceObject

Returns the value of attribute unit_price.



5
6
7
# File 'lib/fastbill/invoice_item.rb', line 5

def unit_price
  @unit_price
end

#vat_percentObject

Returns the value of attribute vat_percent.



5
6
7
# File 'lib/fastbill/invoice_item.rb', line 5

def vat_percent
  @vat_percent
end

#vat_valueObject

Returns the value of attribute vat_value.



5
6
7
# File 'lib/fastbill/invoice_item.rb', line 5

def vat_value
  @vat_value
end

Instance Method Details

#delete!Object



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

def delete!
  options = {
    :basic_auth => @auth,
    :headers => {
      "Content-Type" => "application/xml"
    },
    :body => '<?xml version="1.0" encoding="utf-8"?><FBAPI><SERVICE>item.delete</SERVICE><DATA><INVOICE_ITEM_ID>' + @id + '</INVOICE_ITEM_ID></DATA></FBAPI>'
  }
  r = self.class.post('/api/0.1/api.php', options)
  body = Crack::XML.parse r.body
  if !body['FBAPI']["RESPONSE"]["STATUS"].nil? && body['FBAPI']["RESPONSE"]["STATUS"] == "success"
    true
  else
    false
  end    
end

#hydrate(body) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fastbill/invoice_item.rb', line 26

def hydrate(body)
  @id = body["INVOICE_ITEM_ID"]
  @article_number = body["ARTICLE_NUMBER"]
  @description = body["DESCRIPTION"]
  @quantity = body["QUANTITY"]
  @unit_price = body["UNIT_PRICE"]
  @vat_percent = body["VAT_PERCENT"]
  @vat_value = body["VAT_VALUE"]
  @complete_net = body["COMPLETE_NET"]
  @complete_gross = body["COMPLETE_GROSS"]
  @sort_order = body["SORT_ORDER"]
end

#to_xmlObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fastbill/invoice_item.rb', line 38

def to_xml
  xml = "<ITEM>"
  unless @id.nil?
    xml = xml + "<INVOICE_ITEM_ID>#{@id}</INVOICE_ITEM_ID>"
  end
  unless @article_number.nil?
    xml = xml + "<ARTICLE_NUMBER>#{@article_number}</ARTICLE_NUMBER>"
  end
  unless @description.nil?
    xml = xml + "<DESCRIPTION>#{@description}</DESCRIPTION>"
  end
  unless @quantity.nil?
    xml = xml + "<QUANTITY>#{@quantity}</QUANTITY>"
  end
  unless @unit_price.nil?
    xml = xml + "<UNIT_PRICE>#{@unit_price}</UNIT_PRICE>"
  end
  unless @vat_percent.nil?
    xml = xml + "<VAT_PERCENT>#{@vat_percent}</VAT_PERCENT>"
  end
  unless @vat_value.nil?
    xml = xml + "<VAT_VALUE>#{@vat_value}</VAT_VALUE>"
  end
  unless @complete_net.nil?
    xml = xml + "<COMPLETE_NET>#{@complete_net}</COMPLETE_NET>"
  end
  unless @complete_gross.nil?
    xml = xml + "<COMPLETE_GROSS>#{@complete_gross}</COMPLETE_GROSS>"
  end
  unless @sort_order.nil?
    xml = xml + "<SORT_ORDER>#{@sort_order}</SORT_ORDER>"
  end
  xml = xml + "</ITEM>"
end