lib/economic/debtor.rb in rconomic-0.1.0 vs lib/economic/debtor.rb in rconomic-0.2.0
- old
+ new
@@ -1,23 +1,53 @@
require 'economic/entity'
module Economic
+ # Represents a debtor in E-conomic.
+ #
+ # API documentation: http://www.e-conomic.com/apidocs/Documentation/T_Economic_Api_IDebtor.html
+ #
+ # Examples
+ #
+ # # Find a debtor:
+ # debtor = economic.debtors.find(558)
+ #
+ # # Creating a debtor:
+ # debtor = economic.debtors.build
+ # debtor.number = economic.debtors.next_available_number
+ # debtor.debtor_group_handle = { :number => 1 }
+ # debtor.name = 'Apple Inc'
+ # debtor.vat_zone = 'HomeCountry' # HomeCountry, EU, Abroad
+ # debtor.currency_handle = { :code => 'DKK' }
+ # debtor.price_group_handle = { :number => 1 }
+ # debtor.is_accessible = true
+ # debtor.ci_number = '12345678'
+ # debtor.term_of_payment_handle = { :id => 1 }
+ # debtor.layout_handle = { :id => 16 }
+ # debtor.save
class Debtor < Entity
has_properties :handle, :number, :debtor_group_handle, :name, :vat_zone, :currency_handle, :price_group_handle, :is_accessible, :ean, :public_entry_number, :email, :telephone_and_fax_number, :website, :address, :postal_code, :city, :country, :credit_maximum, :vat_number, :county, :ci_number, :term_of_payment_handle, :layout_handle, :attention_handle, :your_reference_handle, :our_reference_handle, :balance
+ def handle
+ Handle.new({:number => @number})
+ end
+
+ def contacts
+ @contacts ||= DebtorContactProxy.new(self)
+ end
+
# Provides access to the current invoices - ie invoices that haven't yet been booked
def current_invoices
@current_invoices ||= CurrentInvoiceProxy.new(self)
end
protected
def build_soap_data
data = ActiveSupport::OrderedHash.new
- data['Handle'] = { 'Number' => number }
- data['Number'] = number
+ data['Handle'] = handle.to_hash
+ data['Number'] = handle.number
data['DebtorGroupHandle'] = { 'Number' => debtor_group_handle[:number] } unless debtor_group_handle.blank?
data['Name'] = name
data['VatZone'] = vat_zone
data['CurrencyHandle'] = { 'Code' => currency_handle[:code] } unless currency_handle.blank?
data['PriceGroupHandle'] = { 'Number' => price_group_handle[:number] } unless price_group_handle.blank?
\ No newline at end of file