Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/intacct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'nokogiri'
require 'hooks'
require "intacct/base"
require "intacct/error"
require "intacct/customer"
require "intacct/vendor"
require "intacct/invoice"
Expand All @@ -24,7 +25,7 @@ module Intacct
attr_accessor :xml_sender_id , :xml_password ,
:app_user_id , :app_company_id , :app_password ,
:invoice_prefix , :bill_prefix ,
:vendor_prefix , :customer_prefix, :system_name
:vendor_prefix , :customer_prefix, :system_name, :service_url

def setup
yield self
Expand Down
4 changes: 2 additions & 2 deletions lib/intacct/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def send_xml action
xml = builder.doc.root.to_xml
@sent_xml = xml

url = "https://www.intacct.com/ia/xml/xmlgw.phtml"
url = Intacct.service_url
uri = URI(url)

res = Net::HTTP.post_form(uri, 'xmlrequest' => xml)
res = Net::HTTP.post_form(uri, 'xmlrequest' => xml, 'xml_document' => xml, 'name' => 'intacct')
@response = Nokogiri::XML(res.body)

if successful?
Expand Down
14 changes: 8 additions & 6 deletions lib/intacct/bill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def create
unless object.customer.intacct_system_id
intacct_customer = Intacct::Customer.new object.customer
unless intacct_customer.create
raise 'Could not grab Intacct customer data'
raise Intacct::Error.new message: 'Could not grab Intacct customer data',
sent_xml: intacct_customer.sent_xml, response: intacct_customer.response
end
end

Expand All @@ -20,7 +21,8 @@ def create
if intacct_vendor.create
object.vendor = intacct_vendor.object
else
raise 'Could not create vendor'
raise Intacct::Error.new message: 'Could not create vendor',
sent_xml: intacct_vendor.sent_xml, response: intacct_vendor.response
end
end

Expand Down Expand Up @@ -87,7 +89,7 @@ def get_list limit=1000
end

def intacct_object_id
"#{intacct_bill_prefix}#{object.payment.id}"
"#{intacct_bill_prefix}#{object.payment.legacy.legacy_id}"
end

def bill_xml xml
Expand All @@ -103,9 +105,9 @@ def bill_xml xml
xml.day object.payment.created_at.strftime("%d")
}
xml.datedue {
xml.year object.payment.paid_at.strftime("%Y")
xml.month object.payment.paid_at.strftime("%m")
xml.day object.payment.paid_at.strftime("%d")
xml.year object.payment.created_at.strftime("%Y")
xml.month object.payment.created_at.strftime("%m")
xml.day object.payment.created_at.strftime("%d")
}
run_hook :custom_bill_fields, xml
run_hook :bill_item_fields, xml
Expand Down
3 changes: 2 additions & 1 deletion lib/intacct/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def get *fields
#get fields
get_fields = {}
fields.each do |field|
puts field.inspect
get_fields[field.to_sym] = response.at("//customer//#{field.to_s}").content
end
@data = OpenStruct.new(get_fields)
Expand Down Expand Up @@ -90,7 +91,7 @@ def delete
end

def intacct_object_id
"#{intacct_customer_prefix}#{object.id}"
"#{intacct_customer_prefix}#{object.legacy.legacy_id}"
end
end
end
17 changes: 17 additions & 0 deletions lib/intacct/error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Intacct::Error < StandardError
attr_reader :sent_xml, :response

def initialize(message: 'Generic instant error', sent_xml: nil, response: nil)
error_description = nil
@sent_xml = Nokogiri::XML(sent_xml)
response.traverse do |n|
error_description = n.content if n.name == 'description'
end
@response = if error_description
error_description
else
response
end
super(message)
end
end
12 changes: 8 additions & 4 deletions lib/intacct/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ def create
intacct_customer = Intacct::Customer.new object.customer
unless object.customer.intacct_system_id.present?
unless intacct_customer.create
raise 'Could not create customer'
raise Intacct::Error.new message: 'Could not create customer',
sent_xml: intacct_customer.sent_xml, response: intacct_customer.response
#raise 'Could not create customer'
end
end

if intacct_customer.get
object.customer = intacct_customer.object
@customer_data = intacct_customer.data
else
raise 'Could not grab Intacct customer data'
raise Intacct::Error.new message: 'Could not grab Intacct customer data',
sent_xml: intacct_customer.sent_xml, response: intacct_customer.response
end

# Create vendor if we have one and not in Intacct
Expand All @@ -27,7 +30,8 @@ def create
if intacct_vendor.create
object.vendor = intacct_vendor.object
else
raise 'Could not create vendor'
raise Intacct::Error.new message: 'Could not create vendor',
sent_xml: intacct_vendor.sent_xml, response: intacct_vendor.response
end
end

Expand Down Expand Up @@ -111,7 +115,7 @@ def get_list limit=1000
end

def intacct_object_id
"#{intacct_invoice_prefix}#{object.invoice.id}"
"#{intacct_invoice_prefix}#{object.invoice.legacy.legacy_id}"
end

def invoice_xml xml
Expand Down
26 changes: 13 additions & 13 deletions lib/intacct/vendor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,45 +42,45 @@ def delete
end

def intacct_object_id
"#{intacct_vendor_prefix}#{object.id}"
"#{intacct_vendor_prefix}#{object.legacy.legacy_id}"
end

def vendor_xml xml
xml.name "#{object.company_name.present? ? object.company_name : object.full_name}"
xml.name object.carrier.name
#[todo] - Custom
xml.vendtype "Appraiser"
xml.taxid object.tax_number
xml.paymethod "ACH" if object.ach_routing_number.present?
xml.taxid object.tax
xml.paymethod "ACH" if object.routing_number.present?
xml.billingtype "balanceforward"
xml.status "active"
xml.contactinfo {
xml.contact {
xml.contactname "#{object.last_name}, #{object.first_name} (#{object.id})"
xml.printas object.full_name
xml.companyname object.company_name
xml.companyname object.carrier.name
xml.firstname object.first_name
xml.lastname object.last_name
xml.phone1 object.business_phone
xml.cellphone object.cell_phone
xml.email1 object.email
if object.billing_address.present?
xml.mailaddress {
xml.address1 object.billing_address.address1
xml.address2 object.billing_address.address2
xml.address1 object.billing_address.line_1
xml.address2 object.billing_address.line_2
xml.city object.billing_address.city
xml.state object.billing_address.state
xml.zip object.billing_address.zipcode
}
end
}
}
if object.ach_routing_number.present?
if object.routing_number.present?
xml.paymentnotify "true"
xml.achenabled "#{object.ach_routing_number.present? ? "true" : "false"}"
xml.achbankroutingnumber object.ach_routing_number
xml.achaccountnumber object.ach_account_number
xml.achaccounttype "#{object.ach_account_type.capitalize+" Account"}"
xml.achremittancetype "#{(object.ach_account_classification=="business" ? "CCD" : "PPD")}"
xml.achenabled "#{object.routing_number.present? ? "true" : "false"}"
xml.achbankroutingnumber object.routing_number
xml.achaccountnumber object.account_number
xml.achaccounttype "#{object.account_type.to_s.capitalize} Account"
xml.achremittancetype "#{(object.account_classification.to_s=="business" ? "CCD" : "PPD")}"
end
end
end
Expand Down