Class: IntacctRB::JournalEntry
- Defined in:
- lib/intacctrb/journal_entry.rb
Instance Method Summary collapse
- #create ⇒ Object
- #date_string(date) ⇒ Object
- #get(options = {}) ⇒ Object
- #get_date_at(xpath, object) ⇒ Object
-
#get_list(options = {}) ⇒ Object
def delete # return false unless object.payment.intacct_system_id.present? send_xml('delete') do |xml| xml.function(controlid: "1") { xml.delete_bill(externalkey: "false", key: object.intacct_key) } end.
- #get_rows(je) ⇒ Object
- #intacct_object_id ⇒ Object
- #je_item_fields(xml) ⇒ Object
- #je_xml(xml) ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
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
191 192 193 194 195 196 197 |
# File 'lib/intacctrb/journal_entry.rb', line 191 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( = {}) send_xml('read') do |xml| xml.function(controlid: "f4") { xml.read { xml.object "glbatch" xml.keys object.try(:intacct_id) || [:intacct_id] if [:fields] xml.fields { [: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
return false unless object.payment.intacct_system_id.present?
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( = {}) send_xml('readByQuery') do |xml| xml.function(controlid: "f4") { xml.readByQuery { xml.object "glbatch" xml.pagesize ([:max_items] || 0) xml.query [:filter] if [:fields] xml.fields { [: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
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/intacctrb/journal_entry.rb', line 171 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] } end } end |
#je_xml(xml) ⇒ Object
161 162 163 164 165 166 167 168 169 |
# 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 je_item_fields(xml) end |
#update ⇒ Object
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 |