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

#create ⇒ Object



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

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

  successful?
end

#delete ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/intacctrb/employee.rb', line 93

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

  successful?
end

#employee_xml(xml) ⇒ Object



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

def employee_xml xml
  xml.employee {
    xml.recordno 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



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

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

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

  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").content,
      name: response.at("//EMPLOYEE/PERSONALINFO/CONTACTNAME").content,
      contact_id: response.at("//EMPLOYEE/CONTACTKEY").content,
      employee_id: response.at("//EMPLOYEE/EMPLOYEEID").content
    })
  end

  successful?
end

#get_list(*fields) ⇒ Object



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

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: "employee", 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_employee = false) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/intacctrb/employee.rb', line 78

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

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

  successful?
end