rconomic 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -1
- data/lib/economic/cash_book_entry.rb +42 -36
- data/lib/economic/creditor.rb +67 -0
- data/lib/economic/creditor_contact.rb +62 -0
- data/lib/economic/creditor_entry.rb +26 -0
- data/lib/economic/current_invoice.rb +30 -10
- data/lib/economic/current_invoice_line.rb +2 -0
- data/lib/economic/debtor_entry.rb +27 -0
- data/lib/economic/economic.wsdl +23134 -17255
- data/lib/economic/entity/handle.rb +1 -1
- data/lib/economic/entity.rb +8 -4
- data/lib/economic/entry.rb +26 -0
- data/lib/economic/proxies/cash_book_entry_proxy.rb +53 -15
- data/lib/economic/proxies/creditor_contact_proxy.rb +64 -0
- data/lib/economic/proxies/creditor_entry_proxy.rb +42 -0
- data/lib/economic/proxies/creditor_proxy.rb +73 -0
- data/lib/economic/proxies/current_invoice_proxy.rb +2 -1
- data/lib/economic/proxies/debtor_entry_proxy.rb +32 -0
- data/lib/economic/proxies/entity_proxy.rb +2 -2
- data/lib/economic/proxies/entry_proxy.rb +63 -0
- data/lib/economic/proxies/invoice_proxy.rb +2 -1
- data/lib/economic/session.rb +21 -4
- data/lib/economic/support/string.rb +5 -0
- data/lib/rconomic/version.rb +1 -1
- data/lib/rconomic.rb +10 -0
- data/rconomic.gemspec +6 -1
- data/spec/economic/creditor_contact_spec.rb +106 -0
- data/spec/economic/creditor_spec.rb +52 -0
- data/spec/economic/current_invoice_spec.rb +14 -0
- data/spec/economic/debtor_entry_spec.rb +20 -0
- data/spec/economic/debtor_spec.rb +12 -0
- data/spec/economic/entity/handle_spec.rb +21 -0
- data/spec/economic/entity_spec.rb +31 -0
- data/spec/economic/entry_spec.rb +20 -0
- data/spec/economic/proxies/cash_book_entry_proxy_spec.rb +35 -2
- data/spec/economic/proxies/creditor_contact_proxy_spec.rb +55 -0
- data/spec/economic/proxies/creditor_entry_proxy_spec.rb +49 -0
- data/spec/economic/proxies/creditor_proxy_spec.rb +81 -0
- data/spec/economic/proxies/current_invoice_line_proxy_spec.rb +1 -1
- data/spec/economic/proxies/current_invoice_proxy_spec.rb +3 -3
- data/spec/economic/proxies/debtor_entry_proxy_spec.rb +47 -0
- data/spec/economic/proxies/entry_proxy_spec.rb +73 -0
- data/spec/economic/proxies/invoice_proxy_spec.rb +3 -3
- data/spec/fixtures/cash_book_entry_create_creditor_invoice/success.xml +11 -0
- data/spec/fixtures/cash_book_entry_create_creditor_payment/success.xml +11 -0
- data/spec/fixtures/cash_book_entry_get_data/success.xml +4 -4
- data/spec/fixtures/cash_book_entry_set_due_date/success.xml +6 -0
- data/spec/fixtures/cash_book_get_all/multiple.xml +2 -2
- data/spec/fixtures/cash_book_get_entries/success.xml +4 -4
- data/spec/fixtures/creditor_contact_get_data/success.xml +22 -0
- data/spec/fixtures/creditor_entry_find_by_invoice_number/many.xml +15 -0
- data/spec/fixtures/creditor_entry_find_by_invoice_number/single.xml +12 -0
- data/spec/fixtures/creditor_entry_get_data/success.xml +32 -0
- data/spec/fixtures/creditor_entry_match_entries/success.xml +5 -0
- data/spec/fixtures/creditor_find_by_number/found.xml +10 -0
- data/spec/fixtures/creditor_find_by_number/not_found.xml +7 -0
- data/spec/fixtures/creditor_get_all/multiple.xml +15 -0
- data/spec/fixtures/creditor_get_all/single.xml +12 -0
- data/spec/fixtures/creditor_get_data/success.xml +49 -0
- data/spec/fixtures/creditor_get_data_array/multiple.xml +93 -0
- data/spec/fixtures/current_invoice_book_with_number/success.xml +10 -0
- data/spec/fixtures/current_invoice_get_data_array/multiple.xml +4 -4
- data/spec/fixtures/debtor_entry_find_by_invoice_number/many.xml +15 -0
- data/spec/fixtures/debtor_entry_find_by_invoice_number/single.xml +12 -0
- data/spec/fixtures/debtor_entry_match_entries/success.xml +6 -0
- data/spec/fixtures/debtor_get_data_array/multiple.xml +4 -4
- data/spec/fixtures/entry_find_by_date_interval/many.xml +15 -0
- data/spec/fixtures/entry_find_by_date_interval/none.xml +9 -0
- data/spec/fixtures/entry_find_by_date_interval/single.xml +12 -0
- data/spec/fixtures/entry_find_by_serial_number_interval/many.xml +15 -0
- data/spec/fixtures/entry_find_by_serial_number_interval/none.xml +9 -0
- data/spec/fixtures/entry_find_by_serial_number_interval/single.xml +12 -0
- data/spec/fixtures/entry_get_data/success.xml +40 -0
- data/spec/fixtures/entry_get_last_used_serial_number/success.xml +8 -0
- data/spec/spec_helper.rb +22 -2
- metadata +68 -11
- data/Gemfile.lock +0 -61
- data/spec/fixtures/wsdl.xml +0 -56596
data/README.md
CHANGED
@@ -5,6 +5,7 @@ Ruby wrapper for the [e-conomic](http://www.e-conomic.co.uk) SOAP API, that aims
|
|
5
5
|
|
6
6
|
E-conomic is a web-based accounting system. For their marketing speak, see [http://www.e-conomic.co.uk/about/](). More details about their API at [http://www.e-conomic.co.uk/integration/integration-partner/]().
|
7
7
|
|
8
|
+
[![Build Status](https://secure.travis-ci.org/lokalebasen/rconomic.png?branch=master)](http://travis-ci.org/lokalebasen/rconomic)
|
8
9
|
|
9
10
|
Usage example
|
10
11
|
-------------
|
@@ -60,7 +61,6 @@ Usage example
|
|
60
61
|
# without specifying the voucher number, the API will complain. This way, E-Conomics will assign a voucher number for us.
|
61
62
|
|
62
63
|
cash_book_entry = cash_book.entries.create_debtor_payment(:debtor_handle => debtor.handle, :contra_account_handle => { :number => '1920' })
|
63
|
-
cash_book_entry.cash_book_entry_type = "DebtorPayment" # For some reason, we need to specify this.
|
64
64
|
cash_book_entry.amount = -123.45
|
65
65
|
cash_book_entry.currency_handle = { "Code" => "DKK" }
|
66
66
|
cash_book_entry.debtor_invoice_number = invoice.number
|
@@ -91,6 +91,7 @@ Not even remotely... For now, limited to a small subset of all the [available op
|
|
91
91
|
CurrentInvoiceLine | X | X | X | X
|
92
92
|
Debtor | X | X | X | X
|
93
93
|
DebtorContact | X | X | X | X
|
94
|
+
Entry | X | X | X | X
|
94
95
|
Invoice | X | X | |
|
95
96
|
|
96
97
|
|
@@ -33,50 +33,23 @@ module Economic
|
|
33
33
|
:project_handle,
|
34
34
|
:start_date,
|
35
35
|
:text,
|
36
|
-
:
|
36
|
+
:type,
|
37
37
|
:vat_account_handle,
|
38
38
|
:voucher_number
|
39
39
|
|
40
|
-
def initialize_defaults
|
41
|
-
self.account_handle = nil
|
42
|
-
self.amount = 0
|
43
|
-
self.amount_default_currency = 0
|
44
|
-
self.bank_payment_creditor_id = 0
|
45
|
-
self.bank_payment_creditor_invoice_id = 0
|
46
|
-
self.bank_payment_type_handle = nil
|
47
|
-
self.capitalise_handle = nil
|
48
|
-
self.cash_book_handle = nil
|
49
|
-
self.contra_account_handle = nil
|
50
|
-
self.contra_vat_account_handle = nil
|
51
|
-
self.cost_type_handle = nil
|
52
|
-
self.creditor_handle = nil
|
53
|
-
self.creditor_invoice_number = nil
|
54
|
-
self.currency_handle = nil
|
55
|
-
self.date = Time.now
|
56
|
-
self.debtor_handle = nil
|
57
|
-
self.debtor_invoice_number = nil
|
58
|
-
self.department_handle = nil
|
59
|
-
self.distribution_key_handle = nil
|
60
|
-
self.due_date = nil
|
61
|
-
self.employee_handle = nil
|
62
|
-
self.end_date = nil
|
63
|
-
self.project_handle = nil
|
64
|
-
self.start_date = Time.now
|
65
|
-
self.text = ""
|
66
|
-
self.cash_book_entry_type = ""
|
67
|
-
self.vat_account_handle = nil
|
68
|
-
self.voucher_number = 0
|
69
|
-
end
|
70
|
-
|
71
40
|
def handle
|
72
41
|
Handle.new(:id1 => @id1, :id2 => @id2)
|
73
42
|
end
|
74
43
|
|
44
|
+
protected
|
45
|
+
|
75
46
|
def build_soap_data
|
76
47
|
data = ActiveSupport::OrderedHash.new
|
77
48
|
|
78
|
-
data['Handle'] = handle.to_hash
|
79
|
-
data['
|
49
|
+
data['Handle'] = handle.to_hash unless handle.to_hash.empty?
|
50
|
+
data['Id1'] = id1 unless id1.blank?
|
51
|
+
data['Id2'] = id2 unless id2.blank?
|
52
|
+
data['Type'] = type unless type.blank?
|
80
53
|
data['CashBookHandle'] = { 'Number' => cash_book_handle[:number] } unless cash_book_handle.blank?
|
81
54
|
data['DebtorHandle'] = { 'Number' => debtor_handle[:number] } unless debtor_handle.blank?
|
82
55
|
data['CreditorHandle'] = { 'Number' => creditor_handle[:number] } unless creditor_handle.blank?
|
@@ -98,8 +71,8 @@ module Economic
|
|
98
71
|
data['ProjectHandle'] = { 'Number' => project_handle[:number] } unless project_handle.blank?
|
99
72
|
data['CostTypeHandle'] = { 'Number' => cost_type_handle[:number] } unless cost_type_handle.blank?
|
100
73
|
data['BankPaymentTypeHandle'] = { 'Number' => bank_payment_type_handle[:number] } unless bank_payment_type_handle.blank?
|
101
|
-
data['BankPaymentCreditorId'] = bank_payment_creditor_id
|
102
|
-
data['BankPaymentCreditorInvoiceId'] = bank_payment_creditor_invoice_id
|
74
|
+
data['BankPaymentCreditorId'] = bank_payment_creditor_id unless bank_payment_creditor_id.blank?
|
75
|
+
data['BankPaymentCreditorInvoiceId'] = bank_payment_creditor_invoice_id unless bank_payment_creditor_invoice_id.blank?
|
103
76
|
data['CapitaliseHandle'] = { 'Number' => capitalise_handle[:number] } unless capitalise_handle.blank?
|
104
77
|
data['StartDate'] = start_date
|
105
78
|
data['EndDate'] = end_date
|
@@ -107,5 +80,38 @@ module Economic
|
|
107
80
|
|
108
81
|
return data
|
109
82
|
end
|
83
|
+
|
84
|
+
def initialize_defaults
|
85
|
+
self.account_handle = nil
|
86
|
+
self.amount = 0
|
87
|
+
self.amount_default_currency = 0
|
88
|
+
self.bank_payment_creditor_id = nil
|
89
|
+
self.bank_payment_creditor_invoice_id = nil
|
90
|
+
self.bank_payment_type_handle = nil
|
91
|
+
self.capitalise_handle = nil
|
92
|
+
self.cash_book_handle = nil
|
93
|
+
self.contra_account_handle = nil
|
94
|
+
self.contra_vat_account_handle = nil
|
95
|
+
self.cost_type_handle = nil
|
96
|
+
self.creditor_handle = nil
|
97
|
+
self.creditor_invoice_number = nil
|
98
|
+
self.currency_handle = nil
|
99
|
+
self.date = Time.now
|
100
|
+
self.debtor_handle = nil
|
101
|
+
self.debtor_invoice_number = nil
|
102
|
+
self.department_handle = nil
|
103
|
+
self.distribution_key_handle = nil
|
104
|
+
self.due_date = nil
|
105
|
+
self.employee_handle = nil
|
106
|
+
self.end_date = nil
|
107
|
+
self.project_handle = nil
|
108
|
+
self.start_date = Time.now
|
109
|
+
self.text = ""
|
110
|
+
self.type = ""
|
111
|
+
self.vat_account_handle = nil
|
112
|
+
self.voucher_number = 0
|
113
|
+
end
|
114
|
+
|
115
|
+
|
110
116
|
end
|
111
117
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'economic/entity'
|
2
|
+
|
3
|
+
module Economic
|
4
|
+
|
5
|
+
# Represents a creditor in E-conomic.
|
6
|
+
#
|
7
|
+
# API documentation: http://www.e-conomic.com/apidocs/Documentation/T_Economic_Api_ICreditor.html
|
8
|
+
#
|
9
|
+
# Examples
|
10
|
+
#
|
11
|
+
# # Find a creditor:
|
12
|
+
# creditor = economic.creditors.find(558)
|
13
|
+
#
|
14
|
+
# # Creating a creditor:
|
15
|
+
# creditor = economic.creditors.build
|
16
|
+
# creditor.number = economic.creditors.next_available_number
|
17
|
+
# creditor.creditor_group_handle = { :number => 1 }
|
18
|
+
# creditor.name = 'Apple Inc'
|
19
|
+
# creditor.vat_zone = 'HomeCountry' # HomeCountry, EU, Abroad
|
20
|
+
# creditor.is_accessible = true
|
21
|
+
# creditor.ci_number = '12345678'
|
22
|
+
# creditor.term_of_payment = 1
|
23
|
+
# creditor.save
|
24
|
+
class Creditor < Entity
|
25
|
+
has_properties :handle, :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
|
+
|
27
|
+
def handle
|
28
|
+
Handle.new({:number => @number})
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns the Creditors contacts
|
32
|
+
def contacts
|
33
|
+
@contacts ||= CreditorContactProxy.new(self)
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
def build_soap_data
|
39
|
+
data = ActiveSupport::OrderedHash.new
|
40
|
+
|
41
|
+
data['Handle'] = handle.to_hash
|
42
|
+
data['Number'] = handle.number
|
43
|
+
data['CreditorGroupHandle'] = { 'Number' => creditor_group_handle[:number] } unless creditor_group_handle.blank?
|
44
|
+
data['Name'] = name unless name.blank?
|
45
|
+
data['VatZone'] = vat_zone unless vat_zone.blank?
|
46
|
+
data['CurrencyHandle'] = { 'Code' => currency_handle[:code] } unless currency_handle.blank?
|
47
|
+
data['TermOfPaymentHandle'] = { 'Id' => term_of_payment_handle[:id] } unless term_of_payment_handle.blank?
|
48
|
+
data['IsAccessible'] = is_accessible unless is_accessible.blank?
|
49
|
+
data['CINumber'] = ci_number unless ci_number.blank?
|
50
|
+
data['Email'] = email unless email.blank?
|
51
|
+
data['Address'] = address unless address.blank?
|
52
|
+
data['PostalCode'] = postal_code unless postal_code.blank?
|
53
|
+
data['City'] = city unless city.blank?
|
54
|
+
data['Country'] = country unless country.blank?
|
55
|
+
data['BankAccount'] = bank_account unless bank_account.blank?
|
56
|
+
data['AttentionHandle'] = { 'Id' => attention_handle[:id] } unless attention_handle.blank?
|
57
|
+
data['YourReferenceHandle'] = { 'Id' => your_reference_handle[:id] } unless your_reference_handle.blank?
|
58
|
+
data['OurReferenceHandle'] = { 'Number' => our_reference_handle[:number] } unless our_reference_handle.blank?
|
59
|
+
data['DefaultPaymentTypeHandle'] = { 'Number' => default_payment_type_handle[:number] } unless default_payment_type_handle.blank?
|
60
|
+
data['DefaultPaymentCreditorId'] = default_payment_creditor_id unless default_payment_creditor_id.blank?
|
61
|
+
data['County'] = county unless county.blank?
|
62
|
+
data['AutoContraAccountHandle'] = { 'Number' => auto_contra_account_handle[:number] } unless auto_contra_account_handle.blank?
|
63
|
+
|
64
|
+
data
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'economic/entity'
|
2
|
+
|
3
|
+
module Economic
|
4
|
+
|
5
|
+
# Represents a creditor contact.
|
6
|
+
#
|
7
|
+
# API documentation: http://www.e-conomic.com/apidocs/Documentation/T_Economic_Api_ICreditorContact.html
|
8
|
+
#
|
9
|
+
# Examples
|
10
|
+
#
|
11
|
+
# # Find contact
|
12
|
+
# contact = economic.contacts.find(5)
|
13
|
+
#
|
14
|
+
# # Creating a contact
|
15
|
+
# contact = creditor.contacts.build
|
16
|
+
# contact.id = 0
|
17
|
+
# contact.number = 0
|
18
|
+
# contact.name = 'John Appleseed'
|
19
|
+
# contact.save
|
20
|
+
class CreditorContact < Entity
|
21
|
+
has_properties :handle, :id, :creditor_handle, :name, :number, :telephone_number, :email, :comments, :external_id
|
22
|
+
|
23
|
+
def creditor
|
24
|
+
return nil if creditor_handle.blank?
|
25
|
+
@creditor ||= session.creditors.find(creditor_handle[:number])
|
26
|
+
end
|
27
|
+
|
28
|
+
def creditor=(creditor)
|
29
|
+
self.creditor_handle = creditor.handle
|
30
|
+
@creditor = creditor
|
31
|
+
end
|
32
|
+
|
33
|
+
def creditor_handle=(handle)
|
34
|
+
@creditor = nil unless handle == @creditor_handle
|
35
|
+
@creditor_handle = handle
|
36
|
+
end
|
37
|
+
|
38
|
+
def handle
|
39
|
+
Handle.new({:id => @id})
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def build_soap_data
|
45
|
+
data = ActiveSupport::OrderedHash.new
|
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
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'economic/entity'
|
2
|
+
|
3
|
+
module Economic
|
4
|
+
|
5
|
+
# Represents a creditor entry in E-conomic.
|
6
|
+
#
|
7
|
+
# API documentation: http://www.e-conomic.com/apidocs/Documentation/T_Economic_Api_ICreditorEntry.html
|
8
|
+
|
9
|
+
class CreditorEntry < Entity
|
10
|
+
has_properties :account,
|
11
|
+
:amount,
|
12
|
+
:amount_default_currency,
|
13
|
+
:creditor,
|
14
|
+
:currency,
|
15
|
+
:date,
|
16
|
+
:due_date,
|
17
|
+
:invoice_number,
|
18
|
+
:remainder,
|
19
|
+
:remainder_default_currency,
|
20
|
+
:serial_number,
|
21
|
+
:text,
|
22
|
+
:type,
|
23
|
+
:voucher_number
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -60,6 +60,23 @@ module Economic
|
|
60
60
|
session.invoices.find(response[:number])
|
61
61
|
end
|
62
62
|
|
63
|
+
# Books a current invoice. The given number will be assigned to the
|
64
|
+
# resulting Economic::Invoice.
|
65
|
+
#
|
66
|
+
# Returns the resulting Economic::Invoice object
|
67
|
+
def book_with_number(number)
|
68
|
+
response = session.request soap_action(:book_with_number) do
|
69
|
+
soap.body = {
|
70
|
+
"currentInvoiceHandle" => handle.to_hash,
|
71
|
+
"number" => number,
|
72
|
+
:order! => ["currentInvoiceHandle", "number"]
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
# Find the created Invoice
|
77
|
+
session.invoices.find(response[:number])
|
78
|
+
end
|
79
|
+
|
63
80
|
def debtor
|
64
81
|
return nil if debtor_handle.blank?
|
65
82
|
@debtor ||= session.debtors.find(debtor_handle)
|
@@ -84,6 +101,19 @@ module Economic
|
|
84
101
|
@lines ||= CurrentInvoiceLineProxy.new(self)
|
85
102
|
end
|
86
103
|
|
104
|
+
def save
|
105
|
+
result = super
|
106
|
+
id = result[:id]
|
107
|
+
|
108
|
+
self.lines.each do |invoice_line|
|
109
|
+
invoice_line.session = session
|
110
|
+
invoice_line.invoice = self
|
111
|
+
invoice_line.save
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
protected
|
116
|
+
|
87
117
|
def initialize_defaults
|
88
118
|
self.id = 0
|
89
119
|
self.date = Time.now
|
@@ -133,16 +163,6 @@ module Economic
|
|
133
163
|
return data
|
134
164
|
end
|
135
165
|
|
136
|
-
def save
|
137
|
-
result = super
|
138
|
-
id = result[:id]
|
139
|
-
|
140
|
-
self.lines.each do |invoice_line|
|
141
|
-
invoice_line.session = session
|
142
|
-
invoice_line.invoice = self
|
143
|
-
invoice_line.save
|
144
|
-
end
|
145
|
-
end
|
146
166
|
end
|
147
167
|
|
148
168
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'economic/entity'
|
2
|
+
|
3
|
+
module Economic
|
4
|
+
|
5
|
+
# Represents a debtor entry in E-conomic.
|
6
|
+
#
|
7
|
+
# API documentation: http://www.e-conomic.com/apidocs/Documentation/T_Economic_Api_IDebtorEntry.html
|
8
|
+
|
9
|
+
class DebtorEntry < Entity
|
10
|
+
has_properties :handle,
|
11
|
+
:serial_number,
|
12
|
+
:type,
|
13
|
+
:date,
|
14
|
+
:debtor_handle,
|
15
|
+
:account_handle,
|
16
|
+
:voucher_number,
|
17
|
+
:text,
|
18
|
+
:amount_default_currency,
|
19
|
+
:currency_handle,
|
20
|
+
:amount,
|
21
|
+
:invoice_number,
|
22
|
+
:due_date,
|
23
|
+
:remainder,
|
24
|
+
:remainder_default_currency
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|