Class: KashflowApi::Invoice

Inherits:
SoapObject show all
Defined in:
lib/kashflow_api/models/invoice.rb

Direct Known Subclasses

Quote

Instance Attribute Summary

Attributes inherited from SoapObject

#hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SoapObject

build_from_soap, #initialize, #method_missing

Constructor Details

This class inherits a constructor from KashflowApi::SoapObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class KashflowApi::SoapObject

Class Method Details

.find(search) ⇒ Object



3
4
5
6
# File 'lib/kashflow_api/models/invoice.rb', line 3

def self.find(search)
    result = KashflowApi.api.get_invoice(search)
    self.build_from_soap(result.basic_hash["soap:Envelope"]["soap:Body"]["GetInvoiceResponse"]["GetInvoiceResult"])
end

Instance Method Details

#customerObject



8
9
10
# File 'lib/kashflow_api/models/invoice.rb', line 8

def customer
    KashflowApi::Customer.find_by_customer_id(self.customerid)
end

#saveObject



12
13
14
15
16
17
18
# File 'lib/kashflow_api/models/invoice.rb', line 12

def save
    if @hash["InvoiceDBID"] == "0"
        insert_invoice
    else
        update_invoice
    end
end

#to_xmlObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/kashflow_api/models/invoice.rb', line 20

def to_xml
    xml = []
    id_line = ""
    @hash.keys.each do |key|
        if key == "InvoiceDBID"
            id_line = "<#{key}>#{@hash[key]}</#{key}>" unless @hash[key] == "0"
        else
            xml.push("<#{key}>#{@hash[key]}</#{key}>")
        end
    end
    [id_line, xml.join].join
end