clearbooks 0.16.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/AUTHORS.md +31 -0
  3. data/CHANGELOG.md +0 -0
  4. data/COPYING.md +12 -0
  5. data/FAQ.md +8 -0
  6. data/Gemfile +105 -0
  7. data/LICENSE.md +14 -0
  8. data/MAINTAINERS.md +40 -0
  9. data/README.md +549 -0
  10. data/Rakefile +94 -0
  11. data/Thorfile +80 -0
  12. data/bin/clearbooks +28 -0
  13. data/clearbooks.gemspec +119 -0
  14. data/examples/demo.rb +8 -0
  15. data/lib/clearbooks.rb +92 -0
  16. data/lib/clearbooks/core_ext.rb +8 -0
  17. data/lib/clearbooks/core_ext/array.rb +51 -0
  18. data/lib/clearbooks/core_ext/hash.rb +47 -0
  19. data/lib/clearbooks/core_ext/io_binary_read.rb +20 -0
  20. data/lib/clearbooks/core_ext/string.rb +21 -0
  21. data/lib/clearbooks/error.rb +8 -0
  22. data/lib/clearbooks/error/errors.rb +228 -0
  23. data/lib/clearbooks/interface/rake/cucumber.rb +36 -0
  24. data/lib/clearbooks/interface/rake/default.rb +28 -0
  25. data/lib/clearbooks/interface/rake/documentation.rb +45 -0
  26. data/lib/clearbooks/interface/rake/guard.rb +13 -0
  27. data/lib/clearbooks/interface/rake/helpers.rb +27 -0
  28. data/lib/clearbooks/interface/rake/library.rb +126 -0
  29. data/lib/clearbooks/interface/rake/metric.rb +15 -0
  30. data/lib/clearbooks/interface/rake/rspec.rb +31 -0
  31. data/lib/clearbooks/interface/thor/info.thor +292 -0
  32. data/lib/clearbooks/interface/thor/mixin/config_choice.rb +27 -0
  33. data/lib/clearbooks/interface/thor/mixin/configuration.rb +28 -0
  34. data/lib/clearbooks/interface/thor/mixin/default.rb +30 -0
  35. data/lib/clearbooks/interface/thor/mixin/default_config.rb +31 -0
  36. data/lib/clearbooks/interface/thor/mixin/guess.rb +57 -0
  37. data/lib/clearbooks/interface/thor/mixin/shell.rb +225 -0
  38. data/lib/clearbooks/interface/thor/version.thor +34 -0
  39. data/lib/clearbooks/library/client.rb +257 -0
  40. data/lib/clearbooks/library/configuration.rb +34 -0
  41. data/lib/clearbooks/model/account_code.rb +65 -0
  42. data/lib/clearbooks/model/base.rb +67 -0
  43. data/lib/clearbooks/model/entity.rb +225 -0
  44. data/lib/clearbooks/model/invoice.rb +163 -0
  45. data/lib/clearbooks/model/item.rb +78 -0
  46. data/lib/clearbooks/model/journal.rb +74 -0
  47. data/lib/clearbooks/model/ledger.rb +52 -0
  48. data/lib/clearbooks/model/payment.rb +113 -0
  49. data/lib/clearbooks/model/project.rb +58 -0
  50. data/lib/clearbooks/version.rb +12 -0
  51. data/spec/clearbooks/clearbooks_spec.rb +27 -0
  52. data/spec/clearbooks/model/account_code_spec.rb +52 -0
  53. data/spec/clearbooks/model/entity_spec.rb +107 -0
  54. data/spec/clearbooks/model/invoice_spec.rb +109 -0
  55. data/spec/clearbooks/model/journal_spec.rb +77 -0
  56. data/spec/clearbooks/model/payment_spec.rb +103 -0
  57. data/spec/clearbooks/model/project_spec.rb +72 -0
  58. data/spec/fixtures/response/allocate_payment.xml +12 -0
  59. data/spec/fixtures/response/create_entity.xml +12 -0
  60. data/spec/fixtures/response/create_invoice.xml +11 -0
  61. data/spec/fixtures/response/create_journal.xml +12 -0
  62. data/spec/fixtures/response/create_payment.xml +12 -0
  63. data/spec/fixtures/response/create_project.xml +12 -0
  64. data/spec/fixtures/response/delete_entity.xml +12 -0
  65. data/spec/fixtures/response/delete_journal.xml +12 -0
  66. data/spec/fixtures/response/list_account_codes.xml +168 -0
  67. data/spec/fixtures/response/list_entities.xml +45 -0
  68. data/spec/fixtures/response/list_invoices.xml +56 -0
  69. data/spec/fixtures/response/list_projects.xml +16 -0
  70. data/spec/fixtures/response/no_api_key_fault.xml +8 -0
  71. data/spec/fixtures/response/well_formed_request.xml +10 -0
  72. data/spec/fixtures/response/wrong_api_key_fault.xml +8 -0
  73. data/spec/spec_helper.rb +26 -0
  74. metadata +212 -0
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # System include
4
+ require 'yaml'
5
+
6
+
7
+ # @module Clearbooks
8
+ # @brief Handles Ruby idomatic expression of Clear Books SOAP API
9
+ module Clearbooks
10
+
11
+ # @class Configuration
12
+ # @brief Handles configurations of clearbooks gem such as api keys
13
+ class Configuration
14
+
15
+ attr_accessor :api_key, :wsdl, :log, :logger
16
+
17
+ # @fn def initialize
18
+ # @brief Constructor for Clearbooks::Configuration class objects
19
+ def initialize
20
+ defaults = YAML.load_file(DEFAULT_CONFIG) rescue nil
21
+ defaults ||= YAML.load_file(File.expand_path("~/#{DEFAULT_CONFIG}")) rescue Hash.new
22
+
23
+ @api_key = ENV['CLEARBOOKS_API_KEY'] || defaults['api_key']
24
+ @wsdl = defaults['wsdl'] || 'https://secure.clearbooks.co.uk/api/wsdl/'
25
+ @logger = Logger.new(STDOUT) if @log = defaults['log']
26
+
27
+ self
28
+ end # }}}
29
+
30
+ end # of module Configuration
31
+
32
+ end # of module Clearbooks
33
+
34
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # @module Clearbooks
5
+ # @brief Handles Ruby idomatic expression of Clear Books SOAP API
6
+ module Clearbooks
7
+
8
+ # @class Clearbooks AccountCode model
9
+ # @brief Used to get list of available account codes.
10
+ #
11
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/listaccountcodes/
12
+ class AccountCode < Base
13
+
14
+ attr_reader :id, :account_name, :group_name, :default_vat_rate, :show_sales, :show_purchases
15
+
16
+ # @!attribute [r] id
17
+ # Optional. The internal id of the account code.
18
+ # @return [Fixnum]
19
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/listaccountcodes/
20
+
21
+ # @!attribute [r] account_name
22
+ # Optional.
23
+ # @return [String]
24
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/listaccountcodes/
25
+
26
+ # @!attribute [r] group_name
27
+ # Optional. The name of the group the account code is assigned to.
28
+ # @return [String]
29
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/listaccountcodes/
30
+
31
+ # @!attribute [r] default_vat_rate
32
+ # Optional.
33
+ # @return [String]
34
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/listaccountcodes/
35
+
36
+ # @!attribute [r] show_sales
37
+ # Optional. Boolean value of whether the account code shows in the sales invoice form.
38
+ # @return [Boolean]
39
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/listaccountcodes/
40
+
41
+ # @!attribute [r] show_purchases
42
+ # Optional. Boolean value of whether the account code shows in the purchase invoice form.
43
+ # @return [Boolean]
44
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/listaccountcodes/
45
+
46
+ # @fn def initialize data {{{
47
+ # @brief Constructor for AccountCode model
48
+ #
49
+ # @param [Hash] data Account code attributes. See https://www.clearbooks.co.uk/support/api/docs/soap/listaccountcodes/
50
+ def initialize data
51
+ @id = data.savon(:id).to_i
52
+ @account_name = data.savon :account_name
53
+ @group_name = data.savon :group_name
54
+
55
+ @default_vat_rate = data.savon :default_vat_rate
56
+
57
+ @show_sales = data.savon(:show_sales).to_b
58
+ @show_purchases = data.savon(:show_purchases).to_b
59
+ end # }}}
60
+
61
+ end # of class AccountCode
62
+
63
+ end # of module Clearbooks
64
+
65
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # @module Clearbooks
5
+ # @brief Handles Ruby idomatic expression of Clear Books SOAP API
6
+ module Clearbooks
7
+
8
+ # @class Base class for Clearbooks API models
9
+ # @brief Implements common operations related to Savon and SOAP
10
+ class Base
11
+
12
+ class << self
13
+
14
+ # @fn def build {{{
15
+ # @brief Builds an array of items from a hash returned by Savon
16
+ #
17
+ # @param [Array] data An array of hashes representing collection or a hash representing a single item
18
+ #
19
+ # @return [Array] List of items that represent collection from hash returned by Savon
20
+ #
21
+ # @note Still returns an array when called with a hash representing a single item.
22
+ def build data
23
+ unless data.is_a? Array
24
+ [ create(data) ]
25
+ else
26
+ return data.map { |d| create(d) }
27
+ end
28
+ end # }}}
29
+
30
+ # @fn def create {{{
31
+ # @brief Creates an item from a hash returned by Savon
32
+ #
33
+ # @param [Hash] data Hash representing a single object returned by Savon
34
+ #
35
+ # @return [Object] An item instantiated from a hash returned by Savon
36
+ def create data
37
+ if data.is_a? Hash
38
+ new data
39
+ else
40
+ data
41
+ end
42
+ end # }}}
43
+
44
+ end # of class << self
45
+
46
+
47
+ protected
48
+
49
+ # @fn def parse_date date {{{
50
+ # @brief Parses a given date in expected form from upstream API
51
+ #
52
+ # @param [String] date Date string to parse
53
+ #
54
+ # @return [Date] Returns Date or DateTime from string parsing result
55
+ def parse_date date
56
+ if date.nil? || date.is_a?(Date)
57
+ date
58
+ else
59
+ DateTime.strptime date, '%Y-%m-%d %H:%M:%S'
60
+ end
61
+ end # }}}
62
+
63
+ end # of class Base
64
+
65
+ end # of module Clearbooks
66
+
67
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,225 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # @module Clearbooks
4
+ # @brief Handles Ruby idomatic expression of Clear Books SOAP API
5
+ module Clearbooks
6
+
7
+ # @class Clearbooks Entity model
8
+ # @brief Used to list existing entities or create new.
9
+ #
10
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
11
+ class Entity < Base
12
+
13
+ attr_reader :id,
14
+ :company_name, # string required
15
+ :contact_name, # string optional
16
+ :building, # string optional
17
+ :address1, # string optional
18
+ :address2, # string optional
19
+ :town, # string optional
20
+ :county, # string optional
21
+ :country, # string optional
22
+ # country codes http://www.iso.org/iso/support/country_codes/iso_3166_code_lists/iso-3166-1_decoding_table.htm
23
+ :postcode, # string optional
24
+ :email, # string optional
25
+ :phone1, # string optional
26
+ :phone2, # string optional
27
+ :fax, # string optional
28
+ :website, # string optional
29
+ :external_id, # integer optional
30
+ :statement_url,
31
+ :supplier,
32
+ # default_account_code string optional
33
+ # default_vat_rate string optional
34
+ # default_credit_terms integer optional
35
+ :customer
36
+ # default_account_code string optional
37
+ # default_vat_rate string optional
38
+ # default_credit_terms integer optional
39
+
40
+ # @!attribute [r] id
41
+ # @return [Fixnum] Entity Id.
42
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
43
+
44
+ # @!attribute [r] statement_url
45
+ # @return [String] The URL the customer/supplier can access to view statements.
46
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
47
+
48
+ # @!attribute [r] company_name
49
+ # Optional.
50
+ # @return [String]
51
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
52
+
53
+ # @!attribute [r] contact_name
54
+ # Optional.
55
+ # @return [String]
56
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
57
+
58
+ # @!attribute [r] building
59
+ # Optional.
60
+ # @return [String]
61
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
62
+
63
+ # @!attribute [r] address1
64
+ # Optional.
65
+ # @return [String]
66
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
67
+
68
+ # @!attribute [r] address2
69
+ # Optional.
70
+ # @return [String]
71
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
72
+
73
+ # @!attribute [r] town
74
+ # Optional.
75
+ # @return [String]
76
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
77
+
78
+ # @!attribute [r] county
79
+ # Optional.
80
+ # @return [String]
81
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
82
+
83
+ # @!attribute [r] country
84
+ # Optional. Country code.
85
+ # @return [String]
86
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
87
+
88
+ # @!attribute [r] postcode
89
+ # Optional.
90
+ # @return [String]
91
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
92
+
93
+ # @!attribute [r] email
94
+ # Optional.
95
+ # @return [String]
96
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
97
+
98
+ # @!attribute [r] phone1
99
+ # Optional.
100
+ # @return [String]
101
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
102
+
103
+ # @!attribute [r] phone2
104
+ # Optional.
105
+ # @return [String]
106
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
107
+
108
+ # @!attribute [r] fax
109
+ # Optional.
110
+ # @return [String]
111
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
112
+
113
+ # @!attribute [r] website
114
+ # Optional.
115
+ # @return [String]
116
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
117
+
118
+ # @!attribute [r] external_id
119
+ # Optional.
120
+ # @return [Fixnum]
121
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
122
+
123
+ # @!attribute [r] supplier
124
+ # Optional. [:default_account_code, :default_vat_rate, :default_credit_terms]
125
+ # @return [Hash]
126
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
127
+
128
+ # @!attribute [r] customer
129
+ # Optional. [:default_account_code, :default_vat_rate, :default_credit_terms]
130
+ # @return [Hash]
131
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
132
+
133
+
134
+ # @fn def initialize data {{{
135
+ # @brief Constructor of Entity class handling entity ie. personal data
136
+ #
137
+ # @param [Hash] data Entity attributes. For the list of available options see https://www.clearbooks.co.uk/support/api/docs/soap/createentity/
138
+ #
139
+ def initialize data
140
+ @id = data.savon(:id).to_i
141
+ @company_name = data.savon :company_name
142
+ @contact_name = data.savon :contact_name
143
+
144
+ @building = data.savon :building
145
+ @address1 = data.savon :address1
146
+ @address2 = data.savon :address2
147
+ @town = data.savon :town
148
+ @county = data.savon :county
149
+ @country = data.savon :country
150
+ @postcode = data.savon :postcode
151
+
152
+ @email = data.savon :email
153
+ @phone1 = data.savon :phone1
154
+ @phone2 = data.savon :phone2
155
+ @fax = data.savon :fax
156
+ @website = data.savon :website
157
+
158
+ @statement_url = data.savon :statement_url
159
+ @external_id = data.savon(:external_id).to_i
160
+
161
+ @supplier = entity_extra data.savon :supplier
162
+ @supplier = @supplier.from_savon if @supplier
163
+
164
+ @customer = entity_extra data.savon :customer
165
+ @customer = @customer.from_savon if @customer
166
+
167
+ end # }}}
168
+
169
+ # @fn def to_savon {{{
170
+ # @brief Converts given Entity (self) to savon readable format
171
+ #
172
+ # @return [Hash] Returns self as Savon readable Hash
173
+ def to_savon
174
+ {
175
+ entity: {
176
+ :@company_name => @company_name,
177
+ :@contact_name => @contact_name,
178
+
179
+ :@building => @building,
180
+ :@address1 => @address1,
181
+ :@address2 => @address2,
182
+ :@town => @town,
183
+ :@county => @county,
184
+ :@country => @country,
185
+ :@postcode => @postcode,
186
+
187
+ :@email => @email,
188
+ :@phone1 => @phone1,
189
+ :@phone2 => @phone2,
190
+ :@fax => @fax,
191
+ :@website => @website,
192
+
193
+ :@external_id => @external_id,
194
+ :supplier => entity_extra(@supplier),
195
+ :customer => entity_extra(@customer)
196
+ }.compact
197
+ }
198
+ end # }}}
199
+
200
+
201
+ private
202
+
203
+ # @fn def entity_extra extra {{{
204
+ # @brief Convert supplier/customer attributes to Savon readable format.
205
+ #
206
+ # @param [Hash] extra Supplier or customer attributes.
207
+ #
208
+ # @return [Hash] Supplier/customer attributes in Savon readable format
209
+ def entity_extra extra
210
+ if extra
211
+ {
212
+ :@default_account_code => extra[:default_account_code],
213
+ :@default_vat_rate => extra[:default_vat_rate],
214
+ :@default_credit_terms => extra[:default_credit_terms].to_i,
215
+ }.compact
216
+ end
217
+ end # }}}
218
+
219
+
220
+ end # of class Entity
221
+
222
+ end # of module Clearbooks
223
+
224
+
225
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # @module Clearbooks
5
+ # @brief Handles Ruby idomatic expression of Clear Books SOAP API
6
+ module Clearbooks
7
+
8
+ # @class Clearbooks Invoice model
9
+ # @brief Used to list existing invoices or create new.
10
+ #
11
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
12
+ class Invoice < Base
13
+
14
+ attr_reader :invoice_id, :date_created, :date_due, :date_accrual, :credit_terms, :description,
15
+ :entity_id, :reference, :project, :status, :invoice_prefix,
16
+ :invoice_number, :external_id, :statement_page, :date_modified, :items, :type, :bank_payment_id
17
+
18
+ # @!attribute [r] invoice_id
19
+ # @return [Fixnum] Invoice Id.
20
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
21
+
22
+ # @!attribute [r] date_created
23
+ # Required. The tax point of the invoice.
24
+ # @return [DateTime]
25
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
26
+
27
+ # @!attribute [r] date_due
28
+ # Required. The date the invoice is due.
29
+ # Use either this field or creditTerms.
30
+ # @return [DateTime]
31
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
32
+
33
+ # @!attribute [r] date_accrual
34
+ # Optional. The invoice accrual date.
35
+ # @return [DateTime]
36
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
37
+
38
+ # @!attribute [r] credit_terms
39
+ # Required. The number of days after the tax point that the invoice is due.
40
+ # @return [Fixnum]
41
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
42
+
43
+ # @!attribute [r] description
44
+ # Optional.
45
+ # @return [String]
46
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
47
+
48
+ # @!attribute [r] entity_id
49
+ # Required. The customer or supplier id.
50
+ # @return [Fixnum]
51
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
52
+
53
+ # @!attribute [r] reference
54
+ # Optional. A reference string for the invoice.
55
+ # @return [String]
56
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
57
+
58
+ # @!attribute [r] project
59
+ # Optional. The id of the project to assign the invoice to.
60
+ # @return [Fixnum]
61
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
62
+
63
+ # @!attribute [r] type
64
+ # Optional. A string identifying the type of the invoice.
65
+ # Value one of: purchases, sales, cn-sales, cn-purchases.
66
+ # @return [String]
67
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
68
+
69
+ # @!attribute [r] bank_payment_id
70
+ # Optional. The bank account code.
71
+ # @return [Fixnum]
72
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
73
+
74
+ # @!attribute [r] date_modified
75
+ # @return [DateTime] Date this invoice was last modified.
76
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
77
+
78
+ # @!attribute [r] external_id
79
+ # @return [Fixnum] Id used to link imported invoices.
80
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
81
+
82
+ # @!attribute [r] invoice_number
83
+ # @return [String] Invoice number.
84
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
85
+
86
+ # @!attribute [r] items
87
+ # Required.
88
+ # @return [Item] A list of item elements identifying the line items.
89
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
90
+
91
+ # @!attribute [r] statement_page
92
+ # @return [String] A link to a printable invoice page with a link to download as a PDF (top right corner).
93
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
94
+
95
+ # @!attribute [r] status
96
+ # @return [String] Invoice status: paid, unpaid.
97
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
98
+
99
+ # @!attribute [r] invoice_prefix
100
+ # @return [String] Invoice prefix.
101
+ # @see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
102
+
103
+
104
+ # @fn def initialize data {{{
105
+ # @brief Constructor for Invoice model
106
+ #
107
+ # @param [Hash] data Invoice attributes. For the list of available options see https://www.clearbooks.co.uk/support/api/docs/soap/createinvoice/
108
+ def initialize data
109
+ @invoice_id = data.savon(:invoice_id).to_i
110
+
111
+ @date_created = parse_date data.savon(:date_created)
112
+ @date_due = parse_date data.savon(:date_due)
113
+
114
+ @credit_terms = data.savon(:credit_terms).to_i
115
+ @description = data.savon :description
116
+
117
+ @entity_id = data.savon(:entity_id).to_i
118
+ @reference = data.savon :reference
119
+ @project = data.savon(:project).to_i
120
+ @status = data.savon :status
121
+
122
+ @invoice_prefix = data.savon :invoice_prefix
123
+ @invoice_number = data.savon :invoice_number
124
+ @external_id = data.savon(:external_id).to_i
125
+ @statement_page = data.savon :statement_page
126
+
127
+ @date_modified = parse_date data.savon(:date_modified)
128
+ @date_accrual = parse_date data.savon(:date_accrual)
129
+
130
+ @type = data.savon(:type)
131
+ @bank_payment_id = data.savon(:bank_payment_id).to_i
132
+
133
+ @items = Item.build( data[:items].is_a?(Array) ? data[:items] : data[:items][:item] )
134
+ end # }}}
135
+
136
+ # @fn def to_savon {{{
137
+ # @brief Converts given Invoice (self) to savon readable format
138
+ #
139
+ # @return [Hash] Returns self as Savon readable Hash
140
+ def to_savon
141
+ {
142
+ invoice: {
143
+ :@dateCreated => @date_created,
144
+ :@entityId => @entity_id,
145
+ :@type => @type,
146
+ :@dateDue => @date_due,
147
+ :@dateAccural => @date_accural,
148
+ :@creditTerms => @credit_terms,
149
+ :@reference => @reference,
150
+ :@project => @project,
151
+
152
+ description: @description,
153
+ items: { item: items.map(&:to_savon) }
154
+ }
155
+ }
156
+ end # }}}
157
+
158
+
159
+ end # of class Invoice
160
+
161
+ end # of module Clearbooks
162
+
163
+ # vim:ts=2:tw=100:wm=100:syntax=ruby