Class: IntacctRB::APPaymentRequest
- Defined in:
- lib/intacctrb/ap_payment_request.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
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_request.rb', line 3 def customer_data @customer_data end |
Instance Method Details
#ap_payment_xml(xml) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/intacctrb/ap_payment_request.rb', line 129 def ap_payment_xml xml xml.bankaccountid object.bank_account_id if object.bank_account_id xml.chargecardid object.charge_card_id if object.charge_card_id xml.vendorid object.vendor_id xml.paymentmethod object.payment_method xml.paymentdate { xml.year object.payment_date.strftime("%Y") xml.month object.payment_date.strftime("%m") xml.day object.payment_date.strftime("%d") } xml.paymentrequestitems { xml.paymentrequestitem { xml.key object.bill_key xml.paymentamount object.amount } } xml.documentnumber object.check_number end |
#create ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/intacctrb/ap_payment_request.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_paymentrequest") { ap_payment_xml xml } } end puts response successful? end |
#delete_intacct_key ⇒ Object
156 157 158 |
# File 'lib/intacctrb/ap_payment_request.rb', line 156 def delete_intacct_key object.payment.intacct_key = nil end |
#delete_intacct_system_id ⇒ Object
152 153 154 |
# File 'lib/intacctrb/ap_payment_request.rb', line 152 def delete_intacct_system_id object.payment.intacct_system_id = nil end |
#get_date_at(xpath, object) ⇒ Object
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/intacctrb/ap_payment_request.rb', line 114 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
37 38 39 40 41 42 43 44 45 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 |
# File 'lib/intacctrb/ap_payment_request.rb', line 37 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
125 126 127 |
# File 'lib/intacctrb/ap_payment_request.rb', line 125 def intacct_object_id "#{intacct_bill_prefix}#{object.payment.id}" end |
#reverse ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/intacctrb/ap_payment_request.rb', line 19 def reverse return false unless object.id.present? send_xml('delete') do |xml| xml.function(controlid: "1") { xml.reverse_appayment(key: object.id) do |xml| xml.datereversed do |xml| xml.year object.date.year xml.month object.date.month xml.day object.date.day end end } end successful? end |
#set_date_time(type) ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/intacctrb/ap_payment_request.rb', line 160 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
148 149 150 |
# File 'lib/intacctrb/ap_payment_request.rb', line 148 def set_intacct_system_id object.payment.intacct_system_id = intacct_object_id end |