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



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/intacctrb/contact.rb', line 103

def contact_xml(xml, is_update = false)
  xml.contact {
    xml.recordno object.intacct_id if object.intacct_id
    xml.contactname object.name unless (is_update || object.intacct_id.nil?)
    xml.printas 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

#create ⇒ Object



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

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

  successful?
end

#delete ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/intacctrb/contact.rb', line 91

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

  successful?
end

#get(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(options = {})
  # return false unless object.intacct_id.present?

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

  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").content,
      name: response.at("//contact/PERSONALINFO/CONTACTNAME").content
    })
  end

  successful?
end

#get_list(*fields) ⇒ 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
70
71
72
73
74
# File 'lib/intacctrb/contact.rb', line 43

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

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

  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?
  puts response
end

#update(updated_contact = false) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/intacctrb/contact.rb', line 76

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

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

  successful?
end