Class: IntacctRB::APPaymentRequest

Inherits:
Base show all
Defined in:
lib/intacctrb/ap_payment_request.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#current_user, #data, #intacct_action, #object, #response, #sent_xml

Instance Method Summary collapse

Methods inherited from Base

#initialize, #intacct_id

Constructor Details

This class inherits a constructor from IntacctRB::Base

Instance Attribute Details

#customer_dataObject

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. if object.
  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

#createObject



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_keyObject



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_idObject



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(options = {})
  send_xml('get_list') do |xml|
    xml.function(controlid: "f4") {
      xml.get_list(object: "appayment", maxitems: (options[:max_items] || 0),
        start: (options[:start] || 0), showprivate:"true") {
        if options[:filters]
          xml.filter {
            xml.logical(logical_operator: "and") do
              options[:filters][:and_filters].each do |filter|
                xml.expression do
                  filter.each_pair do |k,v|
                    xml.send(k,v)
                  end
                end
              end
              if options[:filters][:or_filters]
                xml.logical(logical_operator: "or") do
                  options[: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 options[: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_idObject



125
126
127
# File 'lib/intacctrb/ap_payment_request.rb', line 125

def intacct_object_id
  "#{intacct_bill_prefix}#{object.payment.id}"
end

#reverseObject



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_idObject



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