Class: IntacctRB::Contact

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

#contact_xml(xml, is_update = false) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/intacctrb/contact.rb', line 131

def contact_xml(xml, is_update = false)
  xml.contact {
    xml.recordno object.intacct_id if object.intacct_id
    xml.contactname object.name if object.name
    xml.printas object.name if object.name
    # COMPANYNAME	Optional	string	Company name
    # TAXABLE	Optional	boolean	Taxable. Use false for No, true for Yes. (Default: true)
    # TAXGROUP	Optional	string	Contact tax group name
    # PREFIX	Optional	string	Prefix
    # FIRSTNAME	Optional	string	First name
    # LASTNAME	Optional	string	Last name
    # INITIAL	Optional	string	Middle name
    # PHONE1	Optional	string	Primary phone number
    # PHONE2	Optional	string	Secondary phone number
    # CELLPHONE	Optional	string	Cellular phone number
    # PAGER	Optional	string	Pager number
    # FAX	Optional	string	Fax number
    # EMAIL1	Optional	string	Primary email address
    # EMAIL2	Optional	string	Secondary email address
    # URL1	Optional	string	Primary URL
    # URL2	Optional	string	Secondary URL
    # STATUS	Optional	string	Status. Use active for Active or inactive for Inactive (Default: active)
    # MAILADDRESS	Optional	object	Mail address
  }
end

#createObject



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

def create
  response = send_xml('create') do |xml|
    xml.function(controlid: "1") {
      xml.send("create") {
        contact_xml(xml)
      }
    }
  end

  return_result(response)
end

#deleteObject



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/intacctrb/contact.rb', line 119

def delete
  return false unless object.intacct_id.present?

  response = send_xml('delete') do |xml|
    xml.function(controlid: "1") {
      xml.delete_contact(contactid: intacct_id)
    }
  end

  return_result(response)
end

#get(options = {}) ⇒ Object



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

def get(options = {})
  # return false unless object.intacct_id.present?

  options[:fields] = [
    :contactid,
    :contactname
  ] if options[:fields].nil?

  response = send_xml('get') do |xml|
    xml.function(controlid: "f4") {
      xml.read {
        xml.object 'contact'
        xml.keys object.try(:intacct_id) || options[:intacct_id]
        xml.fields '*'
      }
    }
  end

  if successful?
    data = OpenStruct.new({
      id: response.at("//contact/RECORDNO").try(:content),
      name: response.at("//contact/CONTACTNAME").try(:content)
    })
  end

  return_result(response, data)
end

#get_by_name(options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/intacctrb/contact.rb', line 15

def get_by_name(options = {})
  # return false unless object.intacct_id.present?

  options[:fields] = [
    :contactid,
    :contactname
  ] if options[:fields].nil?

  response = send_xml('get') do |xml|
    xml.function(controlid: "f4") {
      xml.readByName {
        xml.object 'contact'
        xml.keys object.try(:name) || options[:name]
        xml.fields '*'
      }
    }
  end

  if successful?
    data = OpenStruct.new({
      id: response.at("//contact/RECORDNO").try(:content),
      name: response.at("//contact/CONTACTNAME").try(:content)
    })
  end

  return_result(response, data)
end

#get_list(*fields) ⇒ Object



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

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

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

  response = send_xml('get_list') do |xml|
    xml.function(controlid: "f4") {
      xml.get_list(object: "contact", 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?
  return_result(response)
end

#update(updated_contact = false) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/intacctrb/contact.rb', line 104

def update updated_contact = false
  @object = updated_contact if updated_contact
  return false unless object.intacct_id.present?

  response = send_xml('update') do |xml|
    xml.function(controlid: "1") {
      xml.update {
        contact_xml(xml, true)
      }
    }
  end

  return_result(response)
end