Class: IntacctRB::APPayment
- Defined in:
- lib/intacctrb/ap_payment.rb
Instance Attribute Summary collapse
-
#customer_data ⇒ Object
Returns the value of attribute customer_data.
Attributes inherited from Base
#current_user, #data, #intacct_action, #object, #response, #sent_xml
Instance Method Summary collapse
- #ap_payment_xml(xml) ⇒ Object
- #create ⇒ Object
- #delete_intacct_key ⇒ Object
- #delete_intacct_system_id ⇒ Object
- #get_date_at(xpath, object) ⇒ Object
- #get_list(options = {}) ⇒ Object
- #intacct_object_id ⇒ Object
- #reverse ⇒ Object
- #set_date_time(type) ⇒ Object
- #set_intacct_system_id ⇒ Object
- #update ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from IntacctRB::Base
Instance Attribute Details
#customer_data ⇒ Object
Returns the value of attribute customer_data.
3 4 5 |
# File 'lib/intacctrb/ap_payment.rb', line 3 def customer_data @customer_data end |
Instance Method Details
#ap_payment_xml(xml) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/intacctrb/ap_payment.rb', line 138 def ap_payment_xml xml xml.key object.intacct_id unless object.intacct_id.blank? xml.bankaccountid object.bank_account_id unless object.bank_account_id.blank? xml.chargecardid object.charge_card_id unless object.charge_card_id.blank? xml.vendorid object.vendor_id xml.memo object.memo xml.paymentmethod object.payment_method xml.checkdate { xml.year Date.parse(object.payment_date).year xml.month Date.parse(object.payment_date).month xml.day Date.parse(object.payment_date).day } xml.checkno object.check_number xml.billno object.bill_number xml.payitems { object.line_items.each do |line_item| xml.payitem { xml.glaccountno line_item.account_number xml.paymentamount line_item.amount xml.locationid line_item.location_id } end } end |
#create ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/intacctrb/ap_payment.rb', line 6 def create return false if object.intacct_system_id.present? send_xml('create') do |xml| xml.function(controlid: "f1") { xml.send("create_appayment") { ap_payment_xml xml } } end if !successful? raise IntacctRB::Exceptions::APPayment.new(response.at('//error//description2')) end return_result(response) end |
#delete_intacct_key ⇒ Object
171 172 173 |
# File 'lib/intacctrb/ap_payment.rb', line 171 def delete_intacct_key object.payment.intacct_key = nil end |
#delete_intacct_system_id ⇒ Object
167 168 169 |
# File 'lib/intacctrb/ap_payment.rb', line 167 def delete_intacct_system_id object.payment.intacct_system_id = nil end |
#get_date_at(xpath, object) ⇒ Object
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/intacctrb/ap_payment.rb', line 123 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
46 47 48 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 85 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 |
# File 'lib/intacctrb/ap_payment.rb', line 46 def get_list( = {}) send_xml('get_list') do |xml| xml.function(controlid: "f4") { xml.get_list(object: "appayment", maxitems: ([:max_items] || 0), start: ([:start] || 0), showprivate:"true") { if [:filters] xml.filter { xml.logical(logical_operator: "and") do [:filters][:and_filters].each do |filter| xml.expression do filter.each_pair do |k,v| xml.send(k,v) end end end if [:filters][:or_filters] xml.logical(logical_operator: "or") do [:filters][:or_filters].each do |filter| xml.expression do filter.each_pair do |k,v| xml.send(k,v) end end end end end end } end if [:fields] xml.fields { fields.each do |field| xml.field field.to_s end } end } } end puts response if successful? @data = [] @response.xpath('//appayment').each do |payment| item = OpenStruct.new({ id: payment.at("key").content, vendor_id: payment.at("vendorid").content, payment_amount: payment.at("paymentamount").content, payment_trx_amount: payment.at("paymenttrxamount").content, payment_method: payment.at("paymentmethod").content, payment_account_id: payment.at("financialentity").content, state: payment.at("transactionstate").content, date: get_date_at('paymentdate', payment), date_cleared: get_date_at('cleareddate', payment), cleared: payment.at("cleared").content, }) payment.xpath('.//appaymentitem').each do |payment_item| item[:payment_items] ||= [] item[:payment_items] << { bill_id: payment_item.at('billkey').content, line_item_id: payment_item.at('lineitemkey').content, gl_account_number: payment_item.at('glaccountno').content, amount: payment_item.at('amount').content, department_id: payment_item.at('departmentid').content, location_id: payment_item.at('locationid').content, trx_amount: payment_item.at('trx_amount').content, currency: payment_item.at('currency').content } end @data << item end @data else false end end |
#intacct_object_id ⇒ Object
134 135 136 |
# File 'lib/intacctrb/ap_payment.rb', line 134 def intacct_object_id "#{intacct_bill_prefix}#{object.payment.id}" end |
#reverse ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/intacctrb/ap_payment.rb', line 28 def reverse return false unless object.id.present? parsed_date = Date.parse(object.date) rescue Date.today send_xml('delete') do |xml| xml.function(controlid: "1") { xml.reverse_appayment(key: object.id) do |xml| xml.datereversed do |xml| xml.year parsed_date.year xml.month parsed_date.month xml.day parsed_date.day end end } end successful? end |
#set_date_time(type) ⇒ Object
175 176 177 178 179 180 181 |
# File 'lib/intacctrb/ap_payment.rb', line 175 def set_date_time type if %w(create update delete).include? type if object.payment.respond_to? :"intacct_#{type}d_at" object.payment.send("intacct_#{type}d_at=", DateTime.now) end end end |
#set_intacct_system_id ⇒ Object
163 164 165 |
# File 'lib/intacctrb/ap_payment.rb', line 163 def set_intacct_system_id object.payment.intacct_system_id = intacct_object_id end |
#update ⇒ Object
24 25 26 |
# File 'lib/intacctrb/ap_payment.rb', line 24 def update raise 'You intacct doesn\'t support #update on this object' end |