intacctrb 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45a40492167d51e7797d13f93b234a27664e2259
4
+ data.tar.gz: db414b02a91fcf344bbf9ba469523f47eb41b4e6
5
+ SHA512:
6
+ metadata.gz: f1d43f1bbf87b2a14a0156086b879ecd6b823a11f6e411434879ea784821122e3c925af4e79a216e60a09256aa849d4f1c5785e2700280ff2da8ade6e690daf9
7
+ data.tar.gz: c8333a7159f91daffa3af90f30a5e5040410a7a82b3e564edf1286741714034f5333a8d569ce62a6ea7fb02f32b1b6731de0f09d231c49bef0bae05e9f954937
Binary file
@@ -0,0 +1 @@
1
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ -r turnip
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in intacct.gemspec
4
+ gemspec
@@ -0,0 +1,113 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ intacctrb (0.1)
5
+ hooks
6
+ nokogiri
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionpack (5.0.0)
12
+ actionview (= 5.0.0)
13
+ activesupport (= 5.0.0)
14
+ rack (~> 2.0)
15
+ rack-test (~> 0.6.3)
16
+ rails-dom-testing (~> 2.0)
17
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
18
+ actionview (5.0.0)
19
+ activesupport (= 5.0.0)
20
+ builder (~> 3.1)
21
+ erubis (~> 2.7.0)
22
+ rails-dom-testing (~> 2.0)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
+ activesupport (5.0.0)
25
+ concurrent-ruby (~> 1.0, >= 1.0.2)
26
+ i18n (~> 0.7)
27
+ minitest (~> 5.1)
28
+ tzinfo (~> 1.1)
29
+ awesome_print (1.7.0)
30
+ builder (3.2.2)
31
+ coderay (1.1.1)
32
+ concurrent-ruby (1.0.2)
33
+ diff-lcs (1.2.5)
34
+ dotenv (2.1.1)
35
+ dotenv-rails (2.1.1)
36
+ dotenv (= 2.1.1)
37
+ railties (>= 4.0, < 5.1)
38
+ erubis (2.7.0)
39
+ faker (1.6.6)
40
+ i18n (~> 0.5)
41
+ gherkin (2.12.2)
42
+ multi_json (~> 1.3)
43
+ hooks (0.4.1)
44
+ uber (~> 0.0.14)
45
+ i18n (0.7.0)
46
+ loofah (2.0.3)
47
+ nokogiri (>= 1.5.9)
48
+ method_source (0.8.2)
49
+ mini_portile2 (2.1.0)
50
+ minitest (5.9.0)
51
+ multi_json (1.12.1)
52
+ nokogiri (1.6.8)
53
+ mini_portile2 (~> 2.1.0)
54
+ pkg-config (~> 1.1.7)
55
+ pkg-config (1.1.7)
56
+ pry (0.10.4)
57
+ coderay (~> 1.1.0)
58
+ method_source (~> 0.8.1)
59
+ slop (~> 3.4)
60
+ rack (2.0.1)
61
+ rack-test (0.6.3)
62
+ rack (>= 1.0)
63
+ rails-dom-testing (2.0.1)
64
+ activesupport (>= 4.2.0, < 6.0)
65
+ nokogiri (~> 1.6.0)
66
+ rails-html-sanitizer (1.0.3)
67
+ loofah (~> 2.0)
68
+ railties (5.0.0)
69
+ actionpack (= 5.0.0)
70
+ activesupport (= 5.0.0)
71
+ method_source
72
+ rake (>= 0.8.7)
73
+ thor (>= 0.18.1, < 2.0)
74
+ rake (11.2.2)
75
+ rspec (3.5.0)
76
+ rspec-core (~> 3.5.0)
77
+ rspec-expectations (~> 3.5.0)
78
+ rspec-mocks (~> 3.5.0)
79
+ rspec-core (3.5.2)
80
+ rspec-support (~> 3.5.0)
81
+ rspec-expectations (3.5.0)
82
+ diff-lcs (>= 1.2.0, < 2.0)
83
+ rspec-support (~> 3.5.0)
84
+ rspec-mocks (3.5.0)
85
+ diff-lcs (>= 1.2.0, < 2.0)
86
+ rspec-support (~> 3.5.0)
87
+ rspec-support (3.5.0)
88
+ slop (3.6.0)
89
+ thor (0.19.1)
90
+ thread_safe (0.3.5)
91
+ turnip (2.1.1)
92
+ gherkin (~> 2.5)
93
+ rspec (>= 3.0, < 4.0)
94
+ tzinfo (1.2.2)
95
+ thread_safe (~> 0.1)
96
+ uber (0.0.15)
97
+
98
+ PLATFORMS
99
+ ruby
100
+
101
+ DEPENDENCIES
102
+ awesome_print
103
+ bundler (~> 1.3)
104
+ dotenv-rails
105
+ faker (>= 1.2.0)
106
+ intacctrb!
107
+ pry
108
+ rake
109
+ rspec
110
+ turnip
111
+
112
+ BUNDLED WITH
113
+ 1.12.5
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2016 Apex Dental Partners
2
+ Derived from works (c) 2014 cj
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # IntacctRB
2
+
3
+ This is a WIP fork of the Intacct API client at https://github.com/cj/intacct.
4
+ Goal is to create a full-featured API wrapper for Intacct.
5
+
6
+ ## Status
7
+ Alpha; forked and added the features I needed *right now*. Plan to spend some time
8
+ refactoring and testing, but not sure when that will be.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'intacct'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install intacct
23
+
24
+ ## Usage
25
+
26
+ get_list
27
+ Example
28
+ to filter for vendorid = 'V100'
29
+ client.get_list(filters: [{field: 'vendorid', operator: '=', value: "V100"}])
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ task :default => :spec
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'intacctrb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "intacctrb"
8
+ spec.version = IntacctRB::VERSION
9
+ spec.authors = ["Matt Hale"]
10
+ spec.email = ["matt.hale.0@gmail.com"]
11
+ spec.description = %q{Ruby lib to communicate with the Intacct API system. Forked from https://github.com/cj/intacct.}
12
+ spec.summary = %q{Ruby Intacct API Client}
13
+ spec.homepage = "https://github.com/apexdp/intacctrb"
14
+ # spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "nokogiri"
22
+ spec.add_dependency "hooks"
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "turnip"
27
+ spec.add_development_dependency "awesome_print"
28
+ spec.add_development_dependency "pry"
29
+ spec.add_development_dependency "dotenv-rails"
30
+ spec.add_development_dependency "faker", ">=1.2.0"
31
+ end
Binary file
@@ -0,0 +1,35 @@
1
+ require "intacctrb/version"
2
+ require 'net/http'
3
+ require 'nokogiri'
4
+ require 'hooks'
5
+ require 'ostruct'
6
+ require "intacctrb/base"
7
+ require "intacctrb/customer"
8
+ require "intacctrb/journal_entry"
9
+ require "intacctrb/vendor"
10
+ require "intacctrb/invoice"
11
+ require "intacctrb/bill"
12
+ require "intacctrb/ap_payment"
13
+
14
+ class Object
15
+ def blank?
16
+ respond_to?(:empty?) ? empty? : !self
17
+ end
18
+
19
+ def present?
20
+ !blank?
21
+ end
22
+ end
23
+
24
+ module IntacctRB
25
+ extend self
26
+
27
+ attr_accessor :xml_sender_id , :xml_password ,
28
+ :app_user_id , :app_company_id , :app_password ,
29
+ :invoice_prefix , :bill_prefix ,
30
+ :vendor_prefix , :customer_prefix
31
+
32
+ def setup
33
+ yield self
34
+ end
35
+ end
@@ -0,0 +1,168 @@
1
+ module IntacctRB
2
+ class APPayment < IntacctRB::Base
3
+ attr_accessor :customer_data
4
+ define_hook :custom_bill_fields, :bill_item_fields
5
+
6
+ def create
7
+ return false if object.intacct_system_id.present?
8
+ send_xml('create') do |xml|
9
+ xml.function(controlid: "f1") {
10
+ xml.send("create_paymentrequest") {
11
+ ap_payment_xml xml
12
+ }
13
+ }
14
+ end
15
+ puts response
16
+ successful?
17
+ end
18
+
19
+ def reverse
20
+ return false unless object.id.present?
21
+
22
+ send_xml('delete') do |xml|
23
+ xml.function(controlid: "1") {
24
+ xml.reverse_appayment(key: object.id) do |xml|
25
+ xml.datereversed do |xml|
26
+ xml.year object.date.year
27
+ xml.month object.date.month
28
+ xml.day object.date.day
29
+ end
30
+ end
31
+ }
32
+ end
33
+
34
+ successful?
35
+ end
36
+
37
+ def get_list(options = {})
38
+ send_xml('get_list') do |xml|
39
+ xml.function(controlid: "f4") {
40
+ xml.get_list(object: "appayment", maxitems: (options[:max_items] || 0),
41
+ start: (options[:start] || 0), showprivate:"true") {
42
+ if options[:filters]
43
+ xml.filter {
44
+ xml.logical(logical_operator: "and") do
45
+ options[:filters][:and_filters].each do |filter|
46
+ xml.expression do
47
+ filter.each_pair do |k,v|
48
+ xml.send(k,v)
49
+ end
50
+ end
51
+ end
52
+ if options[:filters][:or_filters]
53
+ xml.logical(logical_operator: "or") do
54
+ options[:filters][:or_filters].each do |filter|
55
+ xml.expression do
56
+ filter.each_pair do |k,v|
57
+ xml.send(k,v)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ }
65
+ end
66
+ if options[:fields]
67
+ xml.fields {
68
+ fields.each do |field|
69
+ xml.field field.to_s
70
+ end
71
+ }
72
+ end
73
+ }
74
+ }
75
+ end
76
+
77
+ puts response
78
+ if successful?
79
+ @data = []
80
+ @response.xpath('//appayment').each do |payment|
81
+ item = OpenStruct.new({
82
+ id: payment.at("key").content,
83
+ vendor_id: payment.at("vendorid").content,
84
+ payment_amount: payment.at("paymentamount").content,
85
+ payment_trx_amount: payment.at("paymenttrxamount").content,
86
+ payment_method: payment.at("paymentmethod").content,
87
+ payment_account_id: payment.at("financialentity").content,
88
+ state: payment.at("transactionstate").content,
89
+ date: get_date_at('paymentdate', payment),
90
+ date_cleared: get_date_at('cleareddate', payment),
91
+ cleared: payment.at("cleared").content,
92
+ })
93
+ payment.xpath('.//appaymentitem').each do |payment_item|
94
+ item[:payment_items] ||= []
95
+ item[:payment_items] << {
96
+ bill_id: payment_item.at('billkey').content,
97
+ line_item_id: payment_item.at('lineitemkey').content,
98
+ gl_account_number: payment_item.at('glaccountno').content,
99
+ amount: payment_item.at('amount').content,
100
+ department_id: payment_item.at('departmentid').content,
101
+ location_id: payment_item.at('locationid').content,
102
+ trx_amount: payment_item.at('trx_amount').content,
103
+ currency: payment_item.at('currency').content
104
+ }
105
+ end
106
+ @data << item
107
+ end
108
+ @data
109
+ else
110
+ false
111
+ end
112
+ end
113
+
114
+ def get_date_at(xpath, object)
115
+ year = object.at("#{xpath}/year").content
116
+ month = object.at("#{xpath}/month").content
117
+ day = object.at("#{xpath}/day").content
118
+ if [year,month,day].any?(&:empty?)
119
+ nil
120
+ else
121
+ Date.new(year.to_i,month.to_i,day.to_i)
122
+ end
123
+ end
124
+
125
+ def intacct_object_id
126
+ "#{intacct_bill_prefix}#{object.payment.id}"
127
+ end
128
+
129
+ def ap_payment_xml xml
130
+ xml.bankaccountid object.bank_account_id if object.bank_account_id
131
+ xml.chargecardid object.charge_card_id if object.charge_card_id
132
+ xml.vendorid object.vendor_id
133
+ xml.paymentmethod object.payment_method
134
+ xml.paymentdate {
135
+ xml.year object.payment_date.strftime("%Y")
136
+ xml.month object.payment_date.strftime("%m")
137
+ xml.day object.payment_date.strftime("%d")
138
+ }
139
+ xml.paymentrequestitems {
140
+ xml.paymentrequestitem {
141
+ xml.key object.bill_key
142
+ xml.paymentamount object.amount
143
+ }
144
+ }
145
+ xml.documentnumber object.check_number
146
+ end
147
+
148
+ def set_intacct_system_id
149
+ object.payment.intacct_system_id = intacct_object_id
150
+ end
151
+
152
+ def delete_intacct_system_id
153
+ object.payment.intacct_system_id = nil
154
+ end
155
+
156
+ def delete_intacct_key
157
+ object.payment.intacct_key = nil
158
+ end
159
+
160
+ def set_date_time type
161
+ if %w(create update delete).include? type
162
+ if object.payment.respond_to? :"intacct_#{type}d_at"
163
+ object.payment.send("intacct_#{type}d_at=", DateTime.now)
164
+ end
165
+ end
166
+ end
167
+ end
168
+ end