Module: Orion6Rep::InstanceMethods

Defined in:
lib/orion6_rep.rb

Instance Method Summary collapse

Instance Method Details

#change_ip(new_ip, interface = nil, rep_data = nil) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/orion6_rep.rb', line 119

def change_ip(new_ip, interface = nil, rep_data = nil)
  if interface.nil? or rep_data.nil?
    data = get_data_from_detection(self.ip)
    interface = data.first if interface.nil?
    rep_data = data.last if rep_data.nil?
  end
  if interface.nil? || rep_data.nil?
    raise "The specified IP address is not an Orion6 REP"
  end
  command = Orion6Rep::ChangeIp.new(interface, new_ip, rep_data)
  response = command.execute
  if response
    on_communication_success(__method__.to_sym) if respond_to?(:on_communication_success)
    return new_ip
  end
end

#get_employees(quantity = nil) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/orion6_rep.rb', line 96

def get_employees(quantity = nil)
  employees_quantity = quantity.nil? ? get_employees_quantity : quantity
  employees = []
  call_id = 1
  while employees_quantity > 0
    # 11 is the max number of employees retrieved in one call
    call_quantity = employees_quantity > 11 ? 11 : employees_quantity
    command = Orion6Rep::EmployeeGet.new(call_id, call_quantity, self.number, self.ip, self.tcp_port)
    employees += command.execute
    employees_quantity -= call_quantity
    call_id += call_quantity
  end
  on_communication_success(__method__.to_sym) if respond_to?(:on_communication_success)
  return employees
end

#get_employees_quantityObject



89
90
91
92
93
94
# File 'lib/orion6_rep.rb', line 89

def get_employees_quantity
  command = Orion6Rep::EmployeeQuantityGet.new(self.number, self.ip, self.tcp_port)
  response = command.execute
  on_communication_success(__method__.to_sym) if respond_to?(:on_communication_success)
  return response
end

#get_employerObject



75
76
77
78
79
80
# File 'lib/orion6_rep.rb', line 75

def get_employer
  command = Orion6Rep::EmployerGet.new(self.number, self.ip, self.tcp_port)
  response = command.execute
  on_communication_success(__method__.to_sym) if respond_to?(:on_communication_success)
  return response
end

#get_record_id(datetime) ⇒ Object



143
144
145
146
147
148
# File 'lib/orion6_rep.rb', line 143

def get_record_id(datetime)
  command = Orion6Rep::RecordIdGet.new(datetime, self.number, self.ip, self.tcp_port)
  response = command.execute
  on_communication_success(__method__.to_sym) if respond_to?(:on_communication_success)
  return response
end

#get_records(first_id = nil) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/orion6_rep.rb', line 150

def get_records(first_id = nil)
  if first_id.nil?
    first_id = 1 # get all the records
  end

  id = first_id
  parser = AfdParser.new(false)
  records = []
  while !id.nil?
    command = Orion6Rep::RecordsGet.new(id, self.number, self.ip, self.tcp_port)
    data = command.execute
    record = nil
    while data.size > 0
      record = parser.parse_line(data, id)
      size = record.class.size
      data.slice!(0..(size-1))
      records << record
      id += 1
    end

    id = record.nil? ? nil : (record.line_id + 1)
  end

  afd_start_date = parser.first_creation_date
  afd_end_date = parser.last_creation_date
  employer = get_employer
  serial_number = get_serial_number
  parser.create_header(employer[:document_type], employer[:document_number],
                       employer[:cei_document], employer[:company_name],
                       serial_number, afd_start_date, afd_end_date, Time.now)
  parser.create_trailer
  return parser
end

#get_serial_numberObject



136
137
138
139
140
141
# File 'lib/orion6_rep.rb', line 136

def get_serial_number
  command = Orion6Rep::GetSerialNumber.new(self.number, self.ip, self.tcp_port)
  response = command.execute
  on_communication_success(__method__.to_sym) if respond_to?(:on_communication_success)
  return response
end

#get_timeObject



61
62
63
64
65
66
# File 'lib/orion6_rep.rb', line 61

def get_time
  command = Orion6Rep::ClockTime::Get.new(self.number, self.ip, self.tcp_port)
  response = command.execute
  on_communication_success(__method__.to_sym) if respond_to?(:on_communication_success)
  return response
end

#set_employee(operation_type, registration, pis_number, name) ⇒ Object



112
113
114
115
116
117
# File 'lib/orion6_rep.rb', line 112

def set_employee(operation_type, registration, pis_number, name)
  command = Orion6Rep::EmployeeSet.new(operation_type, registration, pis_number, name, self.number, self.ip, self.tcp_port)
  response = command.execute
  on_communication_success(__method__.to_sym) if respond_to?(:on_communication_success)
  return response
end

#set_employer(employer_name, employer_location, document_type, document_number, cei_number) ⇒ Object



82
83
84
85
86
87
# File 'lib/orion6_rep.rb', line 82

def set_employer(employer_name, employer_location, document_type, document_number, cei_number)
  command = Orion6Rep::EmployerSet.new(employer_name, employer_location, document_type, document_number, cei_number, self.number, self.ip, self.tcp_port)
  response = command.execute
  on_communication_success(__method__.to_sym) if respond_to?(:on_communication_success)
  return response
end

#set_time(time, start_dst = nil, end_dst = nil) ⇒ Object



68
69
70
71
72
73
# File 'lib/orion6_rep.rb', line 68

def set_time(time, start_dst = nil, end_dst = nil)
  command = Orion6Rep::ClockTime::Set.new(time, start_dst, end_dst, self.number, self.ip, self.tcp_port)
  response = command.execute
  on_communication_success(__method__.to_sym) if respond_to?(:on_communication_success)
  return response
end