Class: IntacctRB::Employee

Inherits:
Base show all
Defined in:
lib/intacctrb/employee.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
17
18
19
20
21
22
# File 'lib/intacctrb/employee.rb', line 3

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

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

  return_result(response, data)
end

#deleteObject



121
122
123
124
125
126
127
128
129
130
131
# File 'lib/intacctrb/employee.rb', line 121

def delete
  return false unless object.intacct_id.present?

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

  return_result(response)
end

#employee_xml(xml) ⇒ Object



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

def employee_xml xml
  xml.employee {
    xml.recordno object.intacct_id if object.intacct_id
    xml.title object.title if object.title
    xml.personalinfo {
      xml.contactname object.name
    }
    xml.locationid object.location_id if object.location_id
    xml.departmentid object.departmentid if object.department_id
    xml.classid object.classid if object.department_id
    xml.supervisorid object.supervisorid if object.department_id
    xml.birthdate date_string(object.birthdate) if object.birthdate
    xml.startdate date_string(object.startdate) if object.startdate
    xml.enddate date_string(object.enddate) if object.enddate
    xml.terminationtype object.terminationtype if object.terminationtype
    xml.employeetype object.employeetype if object.employeetype
    xml.gender object.gender if object.gender
    xml.status object.status if object.status
    xml.currency object.currency if object.currency
  }
end

#get(options = {}) ⇒ Object



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
49
50
51
52
# File 'lib/intacctrb/employee.rb', line 24

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

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

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

  if successful?
    data = OpenStruct.new({
      id: response.at("//EMPLOYEE/RECORDNO").try(:content),
      name: response.at("//EMPLOYEE/PERSONALINFO/CONTACTNAME").try(:content),
      contact_id: response.at("//EMPLOYEE/CONTACTKEY").try(:content),
      employee_id: response.at("//EMPLOYEE/EMPLOYEEID").try(:content)
    })
  end

  return_result(response, data)
end

#get_by_employee_id(options = {}) ⇒ Object



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

def get_by_employee_id(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 'EMPLOYEE'
        xml.keys object.try(:employee_id) || options[:employee_id]
        xml.fields '*'
      }
    }
  end

  if successful?
    data = OpenStruct.new({
      id: response.at("//EMPLOYEE/RECORDNO").try(:content),
      name: response.at("//EMPLOYEE/PERSONALINFO/CONTACTNAME").try(:content),
      contact_id: response.at("//EMPLOYEE/CONTACTKEY").try(:content),
      employee_id: response.at("//EMPLOYEE/EMPLOYEEID").try(:content)
    })
  end

  return_result(response, data)
end

#get_list(*fields) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/intacctrb/employee.rb', line 84

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: "employee", maxitems: "10", showprivate:"false") {
        # xml.fields {
        #   fields.each do |field|
        #     xml.field field.to_s
        #   end
        # }
      }
    }
  end
  return_result(response)
end

#update(updated_employee = false) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/intacctrb/employee.rb', line 107

def update updated_employee = false
  @object = updated_employee if updated_employee
  return false unless object.intacct_id.present?
  response = send_xml('update') do |xml|
    xml.function(controlid: "1") {
      xml.update {
        employee_xml(xml)
      }
    }
  end

  return_result(response)
end