Class: IntacctRB::Customer

Inherits:
Base show all
Defined in:
lib/intacctrb/customer.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

Constructor Details

This class inherits a constructor from IntacctRB::Base

Instance Method Details

#createObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/intacctrb/customer.rb', line 3

def create
  send_xml('create') do |xml|
    xml.function(controlid: "1") {
      xml.send("create_customer") {
        xml.customerid intacct_object_id
        xml.name object.name
        xml.comments
        xml.status "active"
      }
    }
  end

  successful?
end

#deleteObject



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/intacctrb/customer.rb', line 100

def delete
  return false unless object.intacct_system_id.present?

  @response = send_xml('delete') do |xml|
    xml.function(controlid: "1") {
      xml.delete_customer(customerid: intacct_system_id)
    }
  end

  successful?
end

#get(*fields) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/intacctrb/customer.rb', line 18

def get *fields
  #return false unless object.intacct_system_id.present?

  fields = [
    :customerid,
    :name,
    :termname
  ] if fields.empty?

  send_xml('get') do |xml|
    xml.function(controlid: "f4") {
      xml.get(object: "customer", key: "intacct_system_id") {
        xml.fields {
          fields.each do |field|
            xml.field field.to_s
          end
        }
      }
    }
  end

  if successful?
    @data = OpenStruct.new({
      id: response.at("//customer//customerid").content,
      name: response.at("//customer//name").content,
      termname: response.at("//customer//termname").content
    })
  end

  successful?
end

#get_list(*fields) ⇒ Object



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
# File 'lib/intacctrb/customer.rb', line 50

def get_list *fields
  #return false unless object.intacct_system_id.present?

  fields = [
    :customerid,
    :name,
    :termname
  ] if fields.empty?

  send_xml('get_list') do |xml|
    xml.function(controlid: "f4") {
      xml.get_list(object: "customer", maxitems: "10", showprivate:"false") {
        # xml.fields {
        #   fields.each do |field|
        #     xml.field field.to_s
        #   end
        # }
      }
    }
  end

  # if successful?
  #   @data = OpenStruct.new({
  #     id: response.at("//customer//customerid").content,
  #     name: response.at("//customer//name").content,
  #     termname: response.at("//customer//termname").content
  #   })
  # end
  #
  # successful?
  puts response
end

#intacct_object_idObject



112
113
114
# File 'lib/intacctrb/customer.rb', line 112

def intacct_object_id
  "#{intacct_customer_prefix}#{object.id}"
end

#update(updated_customer = false) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/intacctrb/customer.rb', line 83

def update updated_customer = false
  @object = updated_customer if updated_customer
  return false unless object.intacct_system_id.present?

  send_xml('update') do |xml|
    xml.function(controlid: "1") {
      xml.update_customer(customerid: intacct_system_id) {
        xml.name object.name
        xml.comments
        xml.status "active"
      }
    }
  end

  successful?
end