Class: IntacctRB::JournalEntry
- Inherits:
-
Base
show all
- Defined in:
- lib/intacctrb/journal_entry.rb
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
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/intacctrb/journal_entry.rb', line 4
def create
if object.intacct_id.present?
return_error('You tried to create an object that already had an intacct_id')
else
send_xml('create') do |xml|
xml.function(controlid: "f1") {
xml.send("create") {
xml.glbatch {
je_xml xml
}
}
}
end
return_result(response)
end
end
|
#date_string(date) ⇒ Object
193
194
195
196
197
198
199
|
# File 'lib/intacctrb/journal_entry.rb', line 193
def date_string(date)
if date.is_a?(Date) || date.is_a?(DateTime)
date.strftime('%Y-%m-%d')
elsif date.is_a? String
date
end
end
|
#get(options = {}) ⇒ Object
86
87
88
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
|
# File 'lib/intacctrb/journal_entry.rb', line 86
def get(options = {})
send_xml('read') do |xml|
xml.function(controlid: "f4") {
xml.read {
xml.object "glbatch"
xml.keys object.try(:intacct_id) || options[:intacct_id]
if options[:fields]
xml.fields {
options[:fields].each do |field|
xml.field field.to_s
end
}
end
}
}
end
if successful?
@data = []
@response.xpath('//glbatch').each do |je|
@data << OpenStruct.new({
id: je.at("RECORDNO").content,
batch_number: je.at("BATCHNO").content,
journal_id: je.at("JOURNAL").content,
date: Date.strptime(je.at("BATCH_DATE").content,'%Y-%m-%d'),
modified_at: DateTime.strptime(je.at("WHENMODIFIED").content, '%Y-%m-%dT%H:%M:%S'),
description: je.at("BATCH_TITLE").content,
state: je.at("STATE").content,
rows: get_rows(je)
})
end
if @data.empty?
false
else
@data
end
else
false
end
end
|
#get_date_at(xpath, object) ⇒ Object
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/intacctrb/journal_entry.rb', line 146
def get_date_at(xpath, object)
year = object.at("#{xpath}/year").content
month = object.at("#{xpath}/month").content
day = object.at("#{xpath}/day").content
if [year,month,day].any?(&:empty?)
nil
else
Date.new(year.to_i,month.to_i,day.to_i)
end
end
|
#get_list(options = {}) ⇒ Object
def delete
send_xml('delete') do |xml|
xml.function(controlid: "1") {
xml.delete_bill(externalkey: "false", key: object.intacct_key)
}
end
successful?
end
49
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
84
|
# File 'lib/intacctrb/journal_entry.rb', line 49
def get_list(options = {})
send_xml('readByQuery') do |xml|
xml.function(controlid: "f4") {
xml.readByQuery {
xml.object "glbatch"
xml.pagesize (options[:max_items] || 0)
xml.query options[:filter]
if options[:fields]
xml.fields {
options[:fields].each do |field|
xml.field field.to_s
end
}
end
}
}
end
if successful?
@data = []
@response.xpath('//glbatch').each do |invoice|
@data << OpenStruct.new({
id: invoice.at("RECORDNO").content,
batch_number: invoice.at("BATCHNO").content,
journal_id: invoice.at("JOURNAL").content,
date: Date.strptime(invoice.at("BATCH_DATE").content,'%m/%d/%Y'),
modified_at: DateTime.strptime(invoice.at("MODIFIED").content, '%m/%d/%Y %H:%H:%S'),
description: invoice.at("description").content,
state: invoice.at("STATE").content
})
end
@data
else
false
end
end
|
#get_rows(je) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/intacctrb/journal_entry.rb', line 127
def get_rows(je)
rows = []
je.xpath('//glentry').each do |row|
rows << {
type: row.at('TR_TYPE').content,
amount: row.at('AMOUNT').content,
account_number: (row.at('ACCOUNTNO') ? row.at('ACCOUNTNO').content : nil),
memo: (row.at('DESCRIPTION') ? row.at('DESCRIPTION').content : nil),
location_id: (row.at('LOCATION') ? row.at('LOCATION').content : nil),
department_id: (row.at('DEPARTMENT') ? row.at('DEPARTMENT').content : nil),
customer_id: (row.at('CUSTOMER') ? row.at('CUSTOMER').content : nil),
employee_id: (row.at('EMPLOYEE') ? row.at('EMPLOYEE').content : nil),
project_id: (row.at('PROJECT') ? row.at('PROJECT').content : nil),
item_id: (row.at('ITEM') ? row.at('ITEM').content : nil)
}
end
rows
end
|
#intacct_object_id ⇒ Object
157
158
159
|
# File 'lib/intacctrb/journal_entry.rb', line 157
def intacct_object_id
object.intacct_key
end
|
#je_item_fields(xml) ⇒ Object
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/intacctrb/journal_entry.rb', line 172
def je_item_fields xml
xml.entries {
object.rows.each do |row|
xml.glentry {
xml.tr_type row[:type]
xml.amount row[:amount]
xml.accountno row[:account_number]
xml.description row[:memo]
xml.location row[:location_id] if row[:location_id]
xml.department row[:department_id] if row[:department_id]
xml.customerid row[:customer_id] if row[:customer_id]
xml.employeeid row[:employee_id] if row[:employee_id]
xml.projectid row[:project_id] if row[:project_id]
xml.itemid row[:item_id] if row[:itemid]
xml.classid row[:class_id] if row[:class_id]
custom_fields_xml(xml, object)
}
end
}
end
|
#je_xml(xml) ⇒ Object
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/intacctrb/journal_entry.rb', line 161
def je_xml xml
xml.recordno object.intacct_id if object.intacct_id
xml.journal object.journal_id
xml.batch_date date_string(object.date) if object.date
xml.reverse_date date_string(object.reverse_date) if object.reverse_date
xml.batch_title object.description
xml.referenceno object.reference_number
custom_fields_xml(xml, object)
je_item_fields(xml)
end
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/intacctrb/journal_entry.rb', line 21
def update
unless object.intacct_id.present?
return_error('You tried to update an object without an intacct_id')
else
send_xml('update') do |xml|
xml.function(controlid: "f1") {
xml.send("update") {
xml.glbatch {
je_xml xml
}
}
}
end
return_result(response)
end
end
|