Class: IntacctRB::Vendor
Instance Attribute Summary
Attributes inherited from Base
#current_user, #data, #intacct_action, #object, #response, #sent_xml
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #intacct_id
Instance Method Details
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/intacctrb/vendor.rb', line 3
def create
send_xml('create') do |xml|
xml.function(controlid: "f1") {
xml.create {
xml.vendor {
vendor_xml xml
}
}
}
end
if !successful?
raise IntacctRB::Exceptions::Vendor.new(response.at('//error//description2'))
end
new_vendor = response.xpath('//result//data//vendor').first
new_vendor.at('VENDORID').content
end
|
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/intacctrb/vendor.rb', line 38
def delete
return false if object.intacct_system_id.nil?
@response = send_xml('delete') do |xml|
xml.function(controlid: "1") {
xml.delete_vendor(vendorid: intacct_system_id)
}
end
successful?
end
|
#get_list(options = {}) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/intacctrb/vendor.rb', line 50
def get_list(options = {})
send_xml('get_list') do |xml|
xml.function(controlid: "f4") {
xml.get_list(object: "vendor", maxitems: (options[:max_items] || 0),
start: (options[:start] || 0), showprivate:"true") {
filter_xml(xml, options)
if options[:fields]
xml.fields {
fields.each do |field|
xml.field field.to_s
end
}
end
}
}
end
if successful?
@data = []
@response.xpath('//vendor').each do |vendor|
@data << OpenStruct.new({
id: vendor.at("vendorid").content,
name: vendor.at("name").content,
tax_id: vendor.at("taxid").content,
total_due: vendor.at("totaldue").content,
billing_type: vendor.at("billingtype").content,
vendor_account_number: vendor.at("vendoraccountno").content
})
end
@data
else
false
end
end
|
#intacct_object_id ⇒ Object
85
86
87
|
# File 'lib/intacctrb/vendor.rb', line 85
def intacct_object_id
"#{intacct_vendor_prefix}#{object.id}"
end
|
#update(updated_vendor = false) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/intacctrb/vendor.rb', line 22
def update updated_vendor = false
@object = updated_vendor if updated_vendor
return false if object.intacct_system_id.nil?
send_xml('update') do |xml|
xml.function(controlid: "1") {
xml.update_vendor(vendorid: intacct_system_id) {
vendor_xml xml
}
}
end
successful?
end
|
#vendor_xml(xml) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/intacctrb/vendor.rb', line 89
def vendor_xml xml
xml.name "#{object.company_name.present? ? object.company_name : object.full_name}"
xml.vendtype object.vendor_type if object.vendor_type.present?
xml.taxid object.tax_id
xml.billingtype "balanceforward"
xml.status "active"
xml.vendoraccountno object.vendor_account_number
xml.paymethod object.payment_method
xml.onetime object.one_time || false
xml.primary {
xml.contact {
xml.contactname object.company_name
xml.printas object.print_as
xml.companyname object.company_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.mailing_address.present?
xml.mailaddress {
xml.address1 object.mailing_address.address_1
xml.address2 object.mailing_address.address_2
xml.city object.mailing_address.city
xml.state object.mailing_address.state
xml.zip object.mailing_address.zip
}
end
}
}
if object.ach_routing_number.present?
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")}"
end
end
|