rconomic 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +6 -14
  2. data/.travis.yml +0 -1
  3. data/Gemfile +0 -1
  4. data/lib/economic/account.rb +3 -5
  5. data/lib/economic/cash_book.rb +1 -1
  6. data/lib/economic/cash_book_entry.rb +92 -94
  7. data/lib/economic/creditor.rb +1 -1
  8. data/lib/economic/creditor_contact.rb +15 -17
  9. data/lib/economic/creditor_entry.rb +0 -1
  10. data/lib/economic/current_invoice.rb +32 -35
  11. data/lib/economic/current_invoice_line.rb +14 -2
  12. data/lib/economic/debtor.rb +60 -37
  13. data/lib/economic/debtor_contact.rb +26 -20
  14. data/lib/economic/endpoint.rb +72 -0
  15. data/lib/economic/entity/handle.rb +35 -21
  16. data/lib/economic/entity/mapper.rb +41 -0
  17. data/lib/economic/entity.rb +58 -34
  18. data/lib/economic/invoice.rb +15 -2
  19. data/lib/economic/proxies/account_proxy.rb +2 -3
  20. data/lib/economic/proxies/actions/find_by_ci_number.rb +4 -2
  21. data/lib/economic/proxies/actions/find_by_date_interval.rb +0 -1
  22. data/lib/economic/proxies/actions/find_by_name.rb +5 -1
  23. data/lib/economic/proxies/cash_book_entry_proxy.rb +1 -1
  24. data/lib/economic/proxies/entity_proxy.rb +15 -8
  25. data/lib/economic/session.rb +27 -31
  26. data/lib/rconomic/version.rb +1 -1
  27. data/rconomic.gemspec +1 -5
  28. data/spec/economic/cash_book_entry_spec.rb +27 -5
  29. data/spec/economic/cash_book_spec.rb +6 -6
  30. data/spec/economic/creditor_contact_spec.rb +24 -15
  31. data/spec/economic/creditor_spec.rb +9 -9
  32. data/spec/economic/current_invoice_line_spec.rb +7 -7
  33. data/spec/economic/current_invoice_spec.rb +82 -33
  34. data/spec/economic/debtor_contact_spec.rb +25 -15
  35. data/spec/economic/debtor_entry_spec.rb +3 -3
  36. data/spec/economic/debtor_spec.rb +49 -15
  37. data/spec/economic/endpoint_spec.rb +71 -0
  38. data/spec/economic/entity/handle_spec.rb +42 -49
  39. data/spec/economic/entity/mapper_spec.rb +54 -0
  40. data/spec/economic/entity_spec.rb +78 -72
  41. data/spec/economic/entry_spec.rb +3 -3
  42. data/spec/economic/invoice_spec.rb +37 -18
  43. data/spec/economic/proxies/actions/find_by_name_spec.rb +15 -12
  44. data/spec/economic/proxies/cash_book_entry_proxy_spec.rb +26 -24
  45. data/spec/economic/proxies/cash_book_proxy_spec.rb +23 -21
  46. data/spec/economic/proxies/creditor_contact_proxy_spec.rb +12 -16
  47. data/spec/economic/proxies/creditor_entry_proxy_spec.rb +18 -14
  48. data/spec/economic/proxies/creditor_proxy_spec.rb +23 -26
  49. data/spec/economic/proxies/current_invoice_line_proxy_spec.rb +17 -20
  50. data/spec/economic/proxies/current_invoice_proxy_spec.rb +38 -41
  51. data/spec/economic/proxies/debtor_contact_proxy_spec.rb +12 -15
  52. data/spec/economic/proxies/debtor_entry_proxy_spec.rb +18 -14
  53. data/spec/economic/proxies/debtor_proxy_spec.rb +31 -34
  54. data/spec/economic/proxies/entry_proxy_spec.rb +26 -22
  55. data/spec/economic/proxies/invoice_proxy_spec.rb +18 -21
  56. data/spec/economic/session_spec.rb +57 -44
  57. data/spec/fixtures/{spec_entity_create_from_data → account_create_from_data}/success.xml +5 -5
  58. data/spec/fixtures/{spec_entity_delete → account_delete}/success.xml +1 -1
  59. data/spec/fixtures/{spec_entity_get_data → account_get_data}/success.xml +5 -5
  60. data/spec/fixtures/{spec_entity_update_from_data → account_update_from_data}/success.xml +5 -5
  61. data/spec/fixtures/cash_book_entry_create_creditor_invoice/success.xml +2 -2
  62. data/spec/fixtures/cash_book_entry_create_creditor_payment/success.xml +2 -2
  63. data/spec/fixtures/creditor_contact_create_from_data/success.xml +10 -0
  64. data/spec/fixtures/debtor_contact_create_from_data/success.xml +10 -0
  65. data/spec/fixtures/debtor_create_from_data/success.xml +57 -0
  66. data/spec/spec_helper.rb +10 -104
  67. data/spec/support/api_requests.rb +20 -0
  68. data/spec/support/factories.rb +65 -0
  69. data/spec/support/fixtures.rb +9 -0
  70. metadata +27 -31
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZGU5ZmVjMDNkNDJlMzI0ODc3OWQ5NmVmNjhiM2UzNjY2NDQ1MjMzOQ==
5
- data.tar.gz: !binary |-
6
- ZWFjN2EyNGExYTNiZTNhNWM3Mzk0YTNhOTg2ODgxNWJhOGMxODY2Zg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NDMzYWQwOWMzYTE4NzUwNjA2YTBlMzJhZTA2ZjdjOTZhYmUzOTE2NmU5YzAx
10
- NWU5OWYyYmI0YzA2MWFmMTliZGFjNzY0MDc4YjgxYThjMTIzMTQyOTE5Yjg5
11
- YzU1ZTE4ZmM4OWM0ODcyNmNmM2JjZmMxMDdlZmU1MzdkMzgxYTQ=
12
- data.tar.gz: !binary |-
13
- N2Q2MzYxYTIxZmVmZWRlNDhiMDg3ZjE5N2U2MWI0NzJiM2RlODdmNjBlNGVk
14
- NTgwZGRmMDI2YzczZGI5OGM2NmUzNjRhOTFjZjkwY2ZhYjBlOWU0MGE2YmM5
15
- Y2NkYTQ5N2RlOGE5Zjg0NjliZDEyNzE5MzQwN2RmZTllODc4NWM=
2
+ SHA1:
3
+ metadata.gz: 14a1723793e7bc6dbb57eefc74016d232bef34f5
4
+ data.tar.gz: 36cec979913999f6ab22056e2b73893d06895444
5
+ SHA512:
6
+ metadata.gz: f99ac8b85d8783ae420c2258e827e1319031eb180d0464af38281f71bae8b8e10bc966950e10f15d96f57e81fa98aa28150dc9ba988459b7e714fe29d77b513b
7
+ data.tar.gz: 8ae97965563faa5fa04746ad62262848f954ff3a7494561d8fcf9aca709e972a076dd6dd6b7010590a80cd9f5fcc2a25cc7748e20d8bd1436417726235632293
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  # Specify which ruby versions you wish to run your tests on, each version will be used
2
2
  rvm:
3
- - 1.9.2
4
3
  - 1.9.3
5
4
  - 2.0.0
6
5
 
data/Gemfile CHANGED
@@ -5,7 +5,6 @@ gemspec
5
5
  group :test do
6
6
  gem 'coveralls', :require => false
7
7
  gem 'rake'
8
- gem 'savon_spec', '0.1.6'
9
8
  end
10
9
 
11
10
  # Not required to develop rconomic, but useful. See file
@@ -3,15 +3,13 @@ require 'economic/entity'
3
3
  module Economic
4
4
  class Account < Entity
5
5
  has_properties :name, :number, :balance, :block_direct_entries, :contra_account, :debit_credit, :department, :distribution_key, :is_accessible, :opening_account, :total_from, :type, :vat_account
6
-
7
-
6
+
8
7
  def handle
9
8
  Handle.build({:name => @name})
10
9
  end
11
-
12
-
10
+
13
11
  protected
14
-
12
+
15
13
  def build_soap_data
16
14
  {
17
15
  'Handle' => handle.to_hash,
@@ -9,7 +9,7 @@ module Economic
9
9
  has_properties :name, :number
10
10
 
11
11
  def handle
12
- @handle ||= Handle.new({:number => @number})
12
+ @handle || Handle.new({:number => @number})
13
13
  end
14
14
 
15
15
  def entries
@@ -6,109 +6,107 @@ module Economic
6
6
  # API documentation: http://www.e-conomic.com/apidocs/Documentation/T_Economic_Api_ICashBook.html
7
7
  class CashBookEntry < Entity
8
8
  has_properties :id1,
9
- :id2,
10
- :account_handle,
11
- :amount,
12
- :amount_default_currency,
13
- :bank_payment_creditor_id,
14
- :bank_payment_creditor_invoice_id,
15
- :bank_payment_type_handle,
16
- :capitalise_handle,
17
- :cash_book_handle,
18
- :contra_account_handle,
19
- :contra_vat_account_handle,
20
- :cost_type_handle,
21
- :creditor_handle,
22
- :creditor_invoice_number,
23
- :currency_handle,
24
- :date,
25
- :debtor_handle,
26
- :debtor_invoice_number,
27
- :department_handle,
28
- :distribution_key_handle,
29
- :due_date,
30
- :employee_handle,
31
- :end_date,
32
- :project_handle,
33
- :start_date,
34
- :text,
35
- :type,
36
- :vat_account_handle,
37
- :voucher_number
9
+ :id2,
10
+ :account_handle,
11
+ :amount,
12
+ :amount_default_currency,
13
+ :bank_payment_creditor_id,
14
+ :bank_payment_creditor_invoice_id,
15
+ :bank_payment_type_handle,
16
+ :capitalise_handle,
17
+ :cash_book_handle,
18
+ :contra_account_handle,
19
+ :contra_vat_account_handle,
20
+ :cost_type_handle,
21
+ :creditor_handle,
22
+ :creditor_invoice_number,
23
+ :currency_handle,
24
+ :date,
25
+ :debtor_handle,
26
+ :debtor_invoice_number,
27
+ :department_handle,
28
+ :distribution_key_handle,
29
+ :due_date,
30
+ :employee_handle,
31
+ :end_date,
32
+ :project_handle,
33
+ :start_date,
34
+ :text,
35
+ :type,
36
+ :vat_account_handle,
37
+ :voucher_number
38
38
 
39
39
  defaults(
40
- :account_handle => nil,
41
- :amount => 0,
42
- :amount_default_currency => 0,
43
- :bank_payment_creditor_id => nil,
44
- :bank_payment_creditor_invoice_id => nil,
45
- :bank_payment_type_handle => nil,
46
- :capitalise_handle => nil,
47
- :cash_book_handle => nil,
48
- :contra_account_handle => nil,
49
- :contra_vat_account_handle => nil,
50
- :cost_type_handle => nil,
51
- :creditor_handle => nil,
52
- :creditor_invoice_number => nil,
53
- :currency_handle => nil,
54
- :date => Time.now,
55
- :debtor_handle => nil,
56
- :debtor_invoice_number => nil,
57
- :department_handle => nil,
58
- :distribution_key_handle => nil,
59
- :due_date => nil,
60
- :employee_handle => nil,
61
- :end_date => nil,
62
- :project_handle => nil,
63
- :start_date => Time.now,
64
- :text => "",
65
- :type => "",
66
- :vat_account_handle => nil,
67
- :voucher_number => 0
40
+ :account_handle => nil,
41
+ :amount => 0,
42
+ :amount_default_currency => 0,
43
+ :bank_payment_creditor_id => nil,
44
+ :bank_payment_creditor_invoice_id => nil,
45
+ :bank_payment_type_handle => nil,
46
+ :capitalise_handle => nil,
47
+ :cash_book_handle => nil,
48
+ :contra_account_handle => nil,
49
+ :contra_vat_account_handle => nil,
50
+ :cost_type_handle => nil,
51
+ :creditor_handle => nil,
52
+ :creditor_invoice_number => nil,
53
+ :currency_handle => nil,
54
+ :date => Time.now,
55
+ :debtor_handle => nil,
56
+ :debtor_invoice_number => nil,
57
+ :department_handle => nil,
58
+ :distribution_key_handle => nil,
59
+ :due_date => nil,
60
+ :employee_handle => nil,
61
+ :end_date => nil,
62
+ :project_handle => nil,
63
+ :start_date => Time.now,
64
+ :text => "",
65
+ :type => "",
66
+ :vat_account_handle => nil,
67
+ :voucher_number => 0
68
68
  )
69
69
 
70
70
  def handle
71
- @handle ||= Handle.new(:id1 => @id1, :id2 => @id2)
71
+ @handle || Handle.new(:id1 => @id1, :id2 => @id2)
72
72
  end
73
73
 
74
74
  protected
75
75
 
76
- def build_soap_data
77
- data = {}
78
-
79
- data['Handle'] = handle.to_hash unless handle.empty?
80
- data['Id1'] = id1 unless id1.blank?
81
- data['Id2'] = id2 unless id2.blank?
82
- data['Type'] = type unless type.blank?
83
- data['CashBookHandle'] = { 'Number' => cash_book_handle[:number] } unless cash_book_handle.blank?
84
- data['DebtorHandle'] = { 'Number' => debtor_handle[:number] } unless debtor_handle.blank?
85
- data['CreditorHandle'] = { 'Number' => creditor_handle[:number] } unless creditor_handle.blank?
86
- data['AccountHandle'] = { 'Number' => account_handle[:number] } unless account_handle.blank?
87
- data['ContraAccountHandle'] = { 'Number' => contra_account_handle[:number] } unless contra_account_handle.blank?
88
- data['Date'] = date
89
- data['VoucherNumber'] = voucher_number
90
- data['Text'] = text
91
- data['AmountDefaultCurrency'] = amount_default_currency
92
- data['CurrencyHandle'] = { 'Code' => currency_handle[:code] } unless currency_handle.blank?
93
- data['Amount'] = amount
94
- data['VatAccountHandle'] = { 'Number' => vat_account_handle[:number] } unless vat_account_handle.blank?
95
- data['ContraVatAccountHandle'] = { 'Number' => contra_vat_account_handle[:number] } unless contra_vat_account_handle.blank?
96
- data['DebtorInvoiceNumber'] = debtor_invoice_number unless debtor_invoice_number.blank?
97
- data['CreditorInvoiceNumber'] = creditor_invoice_number unless creditor_invoice_number.blank?
98
- data['DueDate'] = due_date
99
- data['DepartmentHandle'] = { 'Number' => department_handle[:number] } unless department_handle.blank?
100
- data['DistributionKeyHandle'] = { 'Number' => distribution_key_handle[:number] } unless distribution_key_handle.blank?
101
- data['ProjectHandle'] = { 'Number' => project_handle[:number] } unless project_handle.blank?
102
- data['CostTypeHandle'] = { 'Number' => cost_type_handle[:number] } unless cost_type_handle.blank?
103
- data['BankPaymentTypeHandle'] = { 'Number' => bank_payment_type_handle[:number] } unless bank_payment_type_handle.blank?
104
- data['BankPaymentCreditorId'] = bank_payment_creditor_id unless bank_payment_creditor_id.blank?
105
- data['BankPaymentCreditorInvoiceId'] = bank_payment_creditor_invoice_id unless bank_payment_creditor_invoice_id.blank?
106
- data['CapitaliseHandle'] = { 'Number' => capitalise_handle[:number] } unless capitalise_handle.blank?
107
- data['StartDate'] = start_date
108
- data['EndDate'] = end_date
109
- data['EmployeeHandle'] = { 'Number' => employee_handle[:number] } unless employee_handle.blank?
110
-
111
- return data
76
+ def fields
77
+ to_hash = Proc.new { |handle| handle.to_hash }
78
+ [
79
+ ["Handle", :handle, Proc.new { |v| v.to_hash }],
80
+ ["Id1", :id1],
81
+ ["Id2", :id2],
82
+ ["Type", :type],
83
+ ["CashBookHandle", :cash_book_handle, to_hash],
84
+ ["DebtorHandle", :debtor_handle, to_hash],
85
+ ["AccountHandle", :account_handle, to_hash],
86
+ ["ContraAccountHandle", :contra_account_handle, to_hash],
87
+ ["Date", :date, nil, :required],
88
+ ["VoucherNumber", :voucher_number, nil, :required],
89
+ ["Text", :text, nil, :required],
90
+ ["AmountDefaultCurrency", :amount_default_currency, nil, :required],
91
+ ["CurrencyHandle", :currency_handle, to_hash],
92
+ ["Amount", :amount, nil, :required],
93
+ ["VatAccountHandle", :vat_account_handle, to_hash],
94
+ ["ContraVatAccountHandle", :contra_vat_account_handle, to_hash],
95
+ ["DebtorInvoiceNumber", :debtor_invoice_number],
96
+ ["CreditorInvoiceNumber", :creditor_invoice_number],
97
+ ["DueDate", :due_date, nil, :required],
98
+ ["DepartmentHandle", :department_handle, to_hash],
99
+ ["DistributionKeyHandle", :distribution_key_handle, to_hash],
100
+ ["ProjectHandle", :project_handle, to_hash],
101
+ ["CostTypeHandle", :cost_type_handle, to_hash],
102
+ ["BankPaymentTypeHandle", :bank_payment_type_handle, to_hash],
103
+ ["BankPaymentCreditorId", :bank_payment_creditor_id],
104
+ ["BankPaymentCreditorInvoiceId", :bank_payment_creditor_invoice_id],
105
+ ["CapitaliseHandle", :capitalise_handle, to_hash],
106
+ ["StartDate", :start_date, nil, :required],
107
+ ["EndDate", :end_date, nil, :required],
108
+ ["EmployeeHandle", :employee_handle, to_hash]
109
+ ]
112
110
  end
113
111
  end
114
112
  end
@@ -25,7 +25,7 @@ module Economic
25
25
  has_properties :number, :creditor_group_handle, :name, :vat_zone, :currency_handle, :term_of_payment_handle, :is_accessible, :ci_number, :email, :address, :postal_code, :city, :country, :bank_account, :attention_handle, :your_reference_handle, :our_reference_handle, :default_payment_type_handle, :default_payment_creditor_id, :county, :auto_contra_account_handle
26
26
 
27
27
  def handle
28
- @handle ||= Handle.build({:number => @number})
28
+ @handle || Handle.build({:number => @number})
29
29
  end
30
30
 
31
31
  # Returns the Creditors contacts
@@ -36,27 +36,25 @@ module Economic
36
36
  end
37
37
 
38
38
  def handle
39
- @handle ||= Handle.build({:id => @id})
39
+ @handle || Handle.build({:id => @id})
40
40
  end
41
41
 
42
42
  protected
43
43
 
44
- def build_soap_data
45
- data = {}
46
-
47
- data['Handle'] = handle.to_hash
48
- data['Id'] = id unless id.blank?
49
- data['CreditorHandle'] = { 'Number' => creditor_handle[:number] } unless creditor_handle.blank?
50
- data['Name'] = name unless name.blank?
51
- data['Number'] = handle.number
52
- data['TelephoneNumber'] = telephone_number unless telephone_number.blank?
53
- data['Email'] = email unless email.blank?
54
- data['Comments'] = comments unless comments.blank?
55
- data['ExternalId'] = external_id unless external_id.blank?
56
-
57
- return data
44
+ def fields
45
+ to_hash = Proc.new { |handle| handle.to_hash }
46
+ # SOAP field, entity method, formatter proc, required?
47
+ [
48
+ ["Handle", :handle, Proc.new { |v| v.to_hash }, :required],
49
+ ["Id", :id, nil],
50
+ ["CreditorHandle", :creditor_handle, to_hash],
51
+ ["Name", :name],
52
+ ["Number", :handle, Proc.new { |v| v.number }, :required],
53
+ ["TelephoneNumber", :telephone_number],
54
+ ["Email", :email],
55
+ ["Comments", :comments],
56
+ ["ExternalId", :external_id]
57
+ ]
58
58
  end
59
-
60
59
  end
61
-
62
60
  end
@@ -5,7 +5,6 @@ module Economic
5
5
  # Represents a creditor entry in E-conomic.
6
6
  #
7
7
  # API documentation: http://www.e-conomic.com/apidocs/Documentation/T_Economic_Api_ICreditorEntry.html
8
-
9
8
  class CreditorEntry < Entity
10
9
  has_properties :account,
11
10
  :amount,
@@ -2,7 +2,8 @@ require 'economic/entity'
2
2
 
3
3
  module Economic
4
4
 
5
- # CurrentInvoices are invoices that are not yet booked. They are therefore not read-only.
5
+ # CurrentInvoices are invoices that are not yet booked. They are therefore not
6
+ # read-only.
6
7
  #
7
8
  # API documentation: http://www.e-conomic.com/apidocs/Documentation/T_Economic_Api_ICurrentInvoice.html
8
9
  #
@@ -65,8 +66,8 @@ module Economic
65
66
  @attention_handle = handle
66
67
  end
67
68
 
68
- # Books a current invoice. An invoice number greater than all other invoice numbers will be
69
- # assigned to the resulting Economic::Invoice.
69
+ # Books a current invoice. An invoice number greater than all other invoice
70
+ # numbers will be assigned to the resulting Economic::Invoice.
70
71
  #
71
72
  # Returns the resulting Economic::Invoice object
72
73
  def book
@@ -108,7 +109,7 @@ module Economic
108
109
  end
109
110
 
110
111
  def handle
111
- @handle ||= Handle.new(:id => @id)
112
+ @handle || Handle.new(:id => @id)
112
113
  end
113
114
 
114
115
  def lines
@@ -120,7 +121,6 @@ module Economic
120
121
 
121
122
  result = super
122
123
  self.id = result[:id].to_i
123
- @handle = nil # Reset a memoized handle, leaving it up to #handle to recreate it with correct id
124
124
 
125
125
  lines.each do |invoice_line|
126
126
  invoice_line.session = session
@@ -131,36 +131,33 @@ module Economic
131
131
 
132
132
  protected
133
133
 
134
- # Returns Hash with the properties of CurrentInvoice in the correct order,
135
- # camelcased and ready to be sent via SOAP
136
- def build_soap_data
137
- data = {}
138
-
139
- data['Id'] = id
140
- data['DebtorHandle'] = debtor.handle.to_hash unless debtor.blank?
141
- data['DebtorName'] = debtor_name
142
- data['DebtorAddress'] = debtor_address unless debtor_address.blank?
143
- data['DebtorPostalCode'] = debtor_postal_code unless debtor_postal_code.blank?
144
- data['DebtorCity'] = debtor_city unless debtor_city.blank?
145
- data['DebtorCountry'] = debtor_country unless debtor_country.blank?
146
- data['AttentionHandle'] = { 'Id' => attention_handle[:id] } unless attention_handle.blank?
147
- data['Date'] = date.iso8601 unless date.blank?
148
- data['TermOfPaymentHandle'] = { 'Id' => term_of_payment_handle[:id] } unless term_of_payment_handle.blank?
149
- data['DueDate'] = (due_date.blank? ? nil : due_date.iso8601)
150
- data['CurrencyHandle'] = { 'Code' => currency_handle[:code] } unless currency_handle.blank?
151
- data['ExchangeRate'] = exchange_rate
152
- data['IsVatIncluded'] = is_vat_included
153
- data['LayoutHandle'] = { 'Id' => layout_handle[:id] } unless layout_handle.blank?
154
- data['DeliveryDate'] = delivery_date ? delivery_date.iso8601 : nil
155
- data['Heading'] = heading unless heading.blank?
156
- data['NetAmount'] = net_amount
157
- data['VatAmount'] = vat_amount
158
- data['GrossAmount'] = gross_amount
159
- data['Margin'] = margin
160
- data['MarginAsPercent'] = margin_as_percent
161
-
162
- return data
134
+ def fields
135
+ date_formatter = Proc.new { |date| date.respond_to?(:iso8601) ? date.iso8601 : nil }
136
+ to_hash = Proc.new { |handle| handle.to_hash }
137
+ [
138
+ ["Id", :id, nil, :required],
139
+ ["DebtorHandle", :debtor, Proc.new { |d| d.handle.to_hash }],
140
+ ["DebtorName", :debtor_name, nil, :required],
141
+ ["DebtorAddress", :debtor_address],
142
+ ["DebtorPostalCode", :debtor_postal_code],
143
+ ["DebtorCity", :debtor_city],
144
+ ["DebtorCountry", :debtor_country],
145
+ ["AttentionHandle", :attention_handle, to_hash],
146
+ ["Date", :date, date_formatter],
147
+ ["TermOfPaymentHandle", :term_of_payment_handle, to_hash],
148
+ ["DueDate", :due_date, date_formatter, :required],
149
+ ["CurrencyHandle", :currency_handle, to_hash],
150
+ ["ExchangeRate", :exchange_rate],
151
+ ["IsVatIncluded", :is_vat_included, nil, :required],
152
+ ["LayoutHandle", :layout_handle, to_hash],
153
+ ["DeliveryDate", :delivery_date, date_formatter, :required],
154
+ ["Heading", :heading],
155
+ ["NetAmount", :net_amount, nil, :required],
156
+ ["VatAmount", :vat_amount, nil, :required],
157
+ ["GrossAmount", :gross_amount, nil, :required],
158
+ ["Margin", :margin, nil, :required],
159
+ ["MarginAsPercent", :margin_as_percent, nil, :required]
160
+ ]
163
161
  end
164
162
  end
165
-
166
163
  end
@@ -9,7 +9,19 @@ module Economic
9
9
  #
10
10
  # See Economic::CurrentInvoice for usage example
11
11
  class CurrentInvoiceLine < Entity
12
- has_properties :number, :invoice_handle, :description, :delivery_date, :unit_handle, :product_handle, :quantity, :unit_net_price, :discount_as_percent, :unit_cost_price, :total_net_amount, :total_margin, :margin_as_percent
12
+ has_properties :number,
13
+ :invoice_handle,
14
+ :description,
15
+ :delivery_date,
16
+ :unit_handle,
17
+ :product_handle,
18
+ :quantity,
19
+ :unit_net_price,
20
+ :discount_as_percent,
21
+ :unit_cost_price,
22
+ :total_net_amount,
23
+ :total_margin,
24
+ :margin_as_percent
13
25
 
14
26
  defaults(
15
27
  :invoice_handle => nil,
@@ -27,7 +39,7 @@ module Economic
27
39
  )
28
40
 
29
41
  def handle
30
- @handle ||= Handle.build(:number => number)
42
+ @handle || Handle.build(:number => number)
31
43
  end
32
44
 
33
45
  def invoice
@@ -25,10 +25,35 @@ module Economic
25
25
  # debtor.layout_handle = { :id => 16 }
26
26
  # debtor.save
27
27
  class Debtor < Entity
28
- has_properties :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
28
+ has_properties :number,
29
+ :debtor_group_handle,
30
+ :name,
31
+ :vat_zone,
32
+ :currency_handle,
33
+ :price_group_handle,
34
+ :is_accessible,
35
+ :ean,
36
+ :public_entry_number,
37
+ :email,
38
+ :telephone_and_fax_number,
39
+ :website,
40
+ :address,
41
+ :postal_code,
42
+ :city,
43
+ :country,
44
+ :credit_maximum,
45
+ :vat_number,
46
+ :county,
47
+ :ci_number,
48
+ :term_of_payment_handle,
49
+ :layout_handle,
50
+ :attention_handle,
51
+ :your_reference_handle,
52
+ :our_reference_handle,
53
+ :balance
29
54
 
30
55
  def handle
31
- @handle ||= Handle.new({:number => @number})
56
+ @handle || Handle.new({:number => @number})
32
57
  end
33
58
 
34
59
  # Returns the Debtors contacts
@@ -36,47 +61,45 @@ module Economic
36
61
  @contacts ||= DebtorContactProxy.new(self)
37
62
  end
38
63
 
39
- # Provides access to the current invoices for Debtor - ie invoices that haven't yet been booked
64
+ # Provides access to the current invoices for Debtor - ie invoices that
65
+ # haven't yet been booked
40
66
  def current_invoices
41
67
  @current_invoices ||= CurrentInvoiceProxy.new(self)
42
68
  end
43
69
 
44
70
  protected
45
71
 
46
- def build_soap_data
47
- data = {}
48
-
49
- data['Handle'] = handle.to_hash
50
- data['Number'] = handle.number
51
- data['DebtorGroupHandle'] = { 'Number' => debtor_group_handle[:number] } unless debtor_group_handle.blank?
52
- data['Name'] = name
53
- data['VatZone'] = vat_zone
54
- data['CurrencyHandle'] = { 'Code' => currency_handle[:code] } unless currency_handle.blank?
55
- data['PriceGroupHandle'] = { 'Number' => price_group_handle[:number] } unless price_group_handle.blank?
56
- data['IsAccessible'] = is_accessible
57
- data['Ean'] = ean unless ean.blank?
58
- data['PublicEntryNumber'] = public_entry_number unless public_entry_number.blank?
59
- data['Email'] = email unless email.blank?
60
- data['TelephoneAndFaxNumber'] = telephone_and_fax_number unless telephone_and_fax_number.blank?
61
- data['Website'] = website unless website.blank?
62
- data['Address'] = address unless address.blank?
63
- data['PostalCode'] = postal_code unless postal_code.blank?
64
- data['City'] = city unless city.blank?
65
- data['Country'] = country unless country.blank?
66
- data['CreditMaximum'] = credit_maximum unless credit_maximum.blank?
67
- data['VatNumber'] = vat_number unless vat_number.blank?
68
- data['County'] = county unless county.blank?
69
- data['CINumber'] = ci_number unless ci_number.blank?
70
- data['TermOfPaymentHandle'] = { 'Id' => term_of_payment_handle[:id] } unless term_of_payment_handle.blank?
71
- data['LayoutHandle'] = { 'Id' => layout_handle[:id] } unless layout_handle.blank?
72
- data['AttentionHandle'] = attention_handle unless attention_handle.blank?
73
- data['YourReferenceHandle'] = your_reference_handle unless your_reference_handle.blank?
74
- data['OurReferenceHandle'] = our_reference_handle unless our_reference_handle.blank?
75
- data['Balance'] = balance unless balance.blank?
76
-
77
- return data
72
+ def fields
73
+ to_hash = Proc.new { |handle| handle.to_hash }
74
+ [
75
+ ["Handle", :handle, to_hash, :required],
76
+ ["Number", :handle, Proc.new { |h| h.number }, :required],
77
+ ["DebtorGroupHandle", :debtor_group_handle, to_hash],
78
+ ["Name", :name, nil, :required],
79
+ ["VatZone", :vat_zone, nil, :required],
80
+ ["CurrencyHandle", :currency_handle, to_hash],
81
+ ["PriceGroupHandle", :price_group_handle, to_hash],
82
+ ["IsAccessible", :is_accessible, nil, :required],
83
+ ["Ean", :ean],
84
+ ["PublicEntryNumber", :public_entry_number],
85
+ ["Email", :email],
86
+ ["TelephoneAndFaxNumber", :telephone_and_fax_number],
87
+ ["Website", :website],
88
+ ["Address", :address],
89
+ ["PostalCode", :postal_code],
90
+ ["City", :city],
91
+ ["Country", :country],
92
+ ["CreditMaximum", :credit_maximum],
93
+ ["VatNumber", :vat_number],
94
+ ["County", :county],
95
+ ["CINumber", :ci_number],
96
+ ["TermOfPaymentHandle", :term_of_payment_handle, to_hash],
97
+ ["LayoutHandle", :layout_handle, to_hash],
98
+ ["AttentionHandle", :attention_handle],
99
+ ["YourReferenceHandle", :your_reference_handle],
100
+ ["OurReferenceHandle", :our_reference_handle],
101
+ ["Balance", :balance]
102
+ ]
78
103
  end
79
-
80
104
  end
81
-
82
105
  end