intacctrb 0.2.1pre → 0.3pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90c68c290f0ec9f5a0834610d2a3bdff3d0066f3
4
- data.tar.gz: 3e2591b1362b4e0fdce8808b33a608cd900d9ffc
3
+ metadata.gz: b8ccb356ac2c6933b8dad65d7e8135345c321228
4
+ data.tar.gz: 75032daf9956d8a9b8f1aa12a87fd965e4904cb3
5
5
  SHA512:
6
- metadata.gz: 9968e5ef5547aeed64ad2df53760dcdb7c3b0ce502d4f4f91eec206353b7b0850be4b827e021eaaa6a6730c75d6f58228851ab7808278162e9624947366bbdb8
7
- data.tar.gz: 71db9b3295041a7e10db6a8372c1d22b519961d05426f7894575aa0e6c774768db269693fde7dd4f3adc8ed1f60b67742fecd1de1ac253baa76e462360b07e8a
6
+ metadata.gz: e6439c42ff5ba6be1732f5be37f9dabc40297feaa145b42d812f8f8e14f7d27c1b51f24628f32e889c70233ebb92305cd599c039e190d585dbdabfa67a288b9c
7
+ data.tar.gz: 9d58bca5fd26d4e1458ff0f139cb3a6cc11fdd53b644f76ebcf22681c8036c9f5079a35fb8fdd57bcbbb9d6db6a9456345a4d29a94dc3cd28fab5e43ddfad9d1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- intacctrb (0.2.1pre)
4
+ intacctrb (0.3pre)
5
5
  hooks
6
6
  nokogiri
7
7
 
@@ -10,6 +10,7 @@ require "intacctrb/vendor"
10
10
  require "intacctrb/invoice"
11
11
  require "intacctrb/bill"
12
12
  require "intacctrb/ap_payment"
13
+ require "intacctrb/account"
13
14
 
14
15
  class Object
15
16
  def blank?
@@ -0,0 +1,39 @@
1
+ module IntacctRB
2
+ class Account < IntacctRB::Base
3
+ def get_list(options = {})
4
+ send_xml('get_list') do |xml|
5
+ xml.function(controlid: "f4") {
6
+ xml.get_list(object: "glaccount", maxitems: (options[:max_items] || 0),
7
+ start: (options[:start] || 0), showprivate:"true") {
8
+ filter_xml(xml, options)
9
+ if options[:fields]
10
+ xml.fields {
11
+ fields.each do |field|
12
+ xml.field field.to_s
13
+ end
14
+ }
15
+ end
16
+ }
17
+ }
18
+ end
19
+
20
+ if successful?
21
+ @data = []
22
+ @response.xpath('//glaccount').each do |account|
23
+ @data << OpenStruct.new({
24
+ id: account.at("glaccountno").content,
25
+ name: account.at("title").content,
26
+ normal_balance: account.at("normalbalance").content,
27
+ account_type: account.at("accounttype").content,
28
+ closing_type: account.at("closingtype").content,
29
+ updated_at: account.at("whenmodified").content,
30
+ status: account.at("status").content
31
+ })
32
+ end
33
+ @data
34
+ else
35
+ false
36
+ end
37
+ end
38
+ end
39
+ end
@@ -14,7 +14,10 @@ module IntacctRB
14
14
  attr_accessor :response, :data, :sent_xml, :intacct_action
15
15
 
16
16
  def initialize *params
17
- params[0] = OpenStruct.new(params[0]) if params[0].is_a? Hash
17
+ if params[0].is_a? Hash
18
+ json_data = params[0].to_json
19
+ params[0] = JSON.parse(json_data, object_class: OpenStruct)
20
+ end
18
21
  params[0] ||= OpenStruct.new()
19
22
  super(*params)
20
23
  end
@@ -108,5 +111,25 @@ module IntacctRB
108
111
  end
109
112
  end
110
113
  end
114
+
115
+ def filter_xml(xml, options)
116
+ if options[:filters]
117
+ xml.filter {
118
+ options[:filters].each do |filter|
119
+ xml.expression do
120
+ xml.field(filter[:field])
121
+ xml.operator(filter[:operator] || '=')
122
+ xml.value(filter[:value])
123
+ end
124
+ end
125
+ }
126
+ end
127
+ end
128
+
129
+ def date_xml(xml, date)
130
+ xml.year date.to_date.strftime("%Y")
131
+ xml.month date.to_date.strftime("%m")
132
+ xml.day date.to_date.strftime("%d")
133
+ end
111
134
  end
112
135
  end
@@ -4,30 +4,30 @@ module IntacctRB
4
4
  define_hook :custom_bill_fields, :bill_item_fields
5
5
 
6
6
  def create
7
- return false if object.payment.intacct_system_id.present?
7
+ return false if object.intacct_system_id.present?
8
8
 
9
- # Need to create the customer if one doesn't exist
10
- unless object.customer.intacct_system_id
11
- intacct_customer = Intacct::Customer.new object.customer
12
- unless intacct_customer.create
13
- raise 'Could not grab Intacct customer data'
14
- end
9
+ send_xml('create') do |xml|
10
+ xml.function(controlid: "f1") {
11
+ xml.create {
12
+ xml.apbill {
13
+ bill_xml xml
14
+ }
15
+ }
16
+ }
15
17
  end
16
18
 
17
- # Create vendor if we have one and not in Intacct
18
- if object.vendor and object.vendor.intacct_system_id.blank?
19
- intacct_vendor = Intacct::Vendor.new object.vendor
20
- if intacct_vendor.create
21
- object.vendor = intacct_vendor.object
22
- else
23
- raise 'Could not create vendor'
24
- end
25
- end
19
+ successful?
20
+ end
26
21
 
27
- send_xml('create') do |xml|
22
+ def update
23
+ raise 'You must pass an id to update a bill' unless object.intacct_id.present?
24
+
25
+ send_xml('update') do |xml|
28
26
  xml.function(controlid: "f1") {
29
- xml.send("create_bill") {
30
- bill_xml xml
27
+ xml.update {
28
+ xml.apbill(key: object.intacct_id) {
29
+ bill_xml xml
30
+ }
31
31
  }
32
32
  }
33
33
  end
@@ -36,7 +36,7 @@ module IntacctRB
36
36
  end
37
37
 
38
38
  def delete
39
- # return false unless object.payment.intacct_system_id.present?
39
+ # return false unless object.intacct_system_id.present?
40
40
 
41
41
  send_xml('delete') do |xml|
42
42
  xml.function(controlid: "1") {
@@ -112,46 +112,50 @@ module IntacctRB
112
112
  end
113
113
 
114
114
  def intacct_object_id
115
- "#{intacct_bill_prefix}#{object.payment.id}"
115
+ "#{intacct_bill_prefix}#{object.id}"
116
116
  end
117
117
 
118
118
  def bill_xml xml
119
- xml.vendorid object.vendor.intacct_system_id
120
- xml.datecreated {
121
- xml.year object.payment.created_at.strftime("%Y")
122
- xml.month object.payment.created_at.strftime("%m")
123
- xml.day object.payment.created_at.strftime("%d")
124
- }
125
- xml.dateposted {
126
- xml.year object.payment.created_at.strftime("%Y")
127
- xml.month object.payment.created_at.strftime("%m")
128
- xml.day object.payment.created_at.strftime("%d")
129
- }
130
- xml.datedue {
131
- xml.year object.payment.paid_at.strftime("%Y")
132
- xml.month object.payment.paid_at.strftime("%m")
133
- xml.day object.payment.paid_at.strftime("%d")
119
+ xml.recordno object.intacct_id
120
+ xml.vendorid object.vendor_id
121
+ xml.whenposted object.posted_at
122
+ xml.whencreated object.invoice_date
123
+ xml.whendue object.due_date
124
+ xml.action object.action
125
+ xml.recordid object.record_id
126
+
127
+ xml.apbillitems {
128
+ object.line_items.each do |line_item|
129
+ xml.apbillitem {
130
+ xml.accountno line_item.account_number
131
+ xml.amount line_item.amount
132
+ xml.entrydescription line_item.memo
133
+ xml.locationid line_item.location_id
134
+ xml.projectid line_item.provider_id
135
+ }
136
+ end
134
137
  }
138
+
135
139
  run_hook :custom_bill_fields, xml
136
140
  run_hook :bill_item_fields, xml
137
141
  end
138
142
 
139
143
  def set_intacct_system_id
140
- object.payment.intacct_system_id = intacct_object_id
144
+ object.intacct_system_id = intacct_object_id
141
145
  end
142
146
 
143
147
  def delete_intacct_system_id
144
- object.payment.intacct_system_id = nil
148
+ object.intacct_system_id = nil
145
149
  end
146
150
 
147
151
  def delete_intacct_key
148
- object.payment.intacct_key = nil
152
+ object.intacct_key = nil
149
153
  end
150
154
 
151
155
  def set_date_time type
152
156
  if %w(create update delete).include? type
153
- if object.payment.respond_to? :"intacct_#{type}d_at"
154
- object.payment.send("intacct_#{type}d_at=", DateTime.now)
157
+ if object.respond_to? :"intacct_#{type}d_at"
158
+ object.send("intacct_#{type}d_at=", DateTime.now)
155
159
  end
156
160
  end
157
161
  end
@@ -10,7 +10,11 @@ module IntacctRB
10
10
  }
11
11
  end
12
12
 
13
- successful?
13
+ if !successful?
14
+ raise(response.at('//error//description2'));
15
+ end
16
+
17
+ true
14
18
  end
15
19
 
16
20
  def update updated_vendor = false
@@ -46,17 +50,7 @@ module IntacctRB
46
50
  xml.function(controlid: "f4") {
47
51
  xml.get_list(object: "vendor", maxitems: (options[:max_items] || 0),
48
52
  start: (options[:start] || 0), showprivate:"true") {
49
- if options[:filters]
50
- xml.filter {
51
- options[:filters].each do |filter|
52
- xml.expression do
53
- filter.each_pair do |k,v|
54
- xml.send(k,v)
55
- end
56
- end
57
- end
58
- }
59
- end
53
+ filter_xml(xml, options)
60
54
  if options[:fields]
61
55
  xml.fields {
62
56
  fields.each do |field|
@@ -70,14 +64,14 @@ module IntacctRB
70
64
 
71
65
  if successful?
72
66
  @data = []
73
- @response.xpath('//vendor').each do |invoice|
67
+ @response.xpath('//vendor').each do |vendor|
74
68
  @data << OpenStruct.new({
75
- id: invoice.at("vendorid").content,
76
- name: invoice.at("name").content,
77
- tax_id: invoice.at("taxid").content,
78
- total_due: invoice.at("totaldue").content,
79
- billing_type: invoice.at("billingtype").content,
80
- vendor_account_number: invoice.at("vendoraccountno").content
69
+ id: vendor.at("vendorid").content,
70
+ name: vendor.at("name").content,
71
+ tax_id: vendor.at("taxid").content,
72
+ total_due: vendor.at("totaldue").content,
73
+ billing_type: vendor.at("billingtype").content,
74
+ vendor_account_number: vendor.at("vendoraccountno").content
81
75
  })
82
76
  end
83
77
  @data
@@ -97,9 +91,11 @@ module IntacctRB
97
91
  xml.taxid object.tax_id
98
92
  xml.billingtype "balanceforward"
99
93
  xml.status "active"
94
+ xml.vendoraccountno object.vendor_account_number
95
+ xml.paymethod object.payment_method
100
96
  xml.contactinfo {
101
97
  xml.contact {
102
- xml.contactname "#{object.last_name}, #{object.first_name} (#{object.id})"
98
+ xml.contactname object.contact_name
103
99
  xml.printas object.full_name
104
100
  xml.companyname object.company_name
105
101
  xml.firstname object.first_name
@@ -1,3 +1,3 @@
1
1
  module IntacctRB
2
- VERSION = "0.2.1pre"
2
+ VERSION = "0.3pre"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intacctrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1pre
4
+ version: 0.3pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Hale
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-17 00:00:00.000000000 Z
11
+ date: 2017-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -168,6 +168,7 @@ files:
168
168
  - intacctrb.gemspec
169
169
  - lib/.DS_Store
170
170
  - lib/intacctrb.rb
171
+ - lib/intacctrb/account.rb
171
172
  - lib/intacctrb/ap_payment.rb
172
173
  - lib/intacctrb/base.rb
173
174
  - lib/intacctrb/bill.rb