query = "SELECT CASE WHEN(origem_destino = '$number') THEN 'CLIENT' ELSE 'AGENT' END AS phone, * " . "FROM " . self::SUPERVISOR_AGENTE . " WHERE (origem_destino = :number OR ramal = :number)"; return $this->read($this->query, ['number' => $number])->fetch(); } public function findAllAgentes($media = ['TELEGRAM', 'whatsapp'], $queue = null) { $data = []; $this->query = "SELECT * FROM " . self::SUPERVISOR_AGENTE . " WHERE 1=1 "; $this->query .= sprintf(" AND sala_1 in(%s) ", whereIn($media)); if ($queue) { $this->query .= " AND dac = :queue "; $data['queue'] = $queue; } $ret = $this->read($this->query, $data); if ($ret) { return $ret->fetchAll(); } else { return []; } } public function findByAgent($user) { $this->query = "SELECT * FROM " . self::USUARIOS . " WHERE apelido = :apelido;"; return $this->read($this->query, ['apelido' => $user])->fetch(); } public function findAgentByRamal($ramal) { $this->query = "SELECT * FROM " . self::SUPERVISOR_AGENTE . " WHERE ramal = :ramal;"; return $this->read($this->query, ['ramal' => $ramal])->fetch(); } public function findAgentByMatricula($matricula) { $this->query = "SELECT * FROM " . self::SUPERVISOR_AGENTE . " WHERE matricula = :matricula;"; return $this->read($this->query, ['matricula' => $matricula])->fetch(); } public function findAgentByQueue($queue, $status = 'LIVRE', $orderBy = null, $orderByType = 'ASC') { $data = []; $this->query = "SELECT ramal, b.matricula, b.nome, b.apelido, penalidade, (logado - duracao) as tempo_livre, (SELECT count(*) AS atendimentos FROM " . self::BILHETE . " ab INNER JOIN " . self::EVENTOS_DACS . " bc ON ab.uniqueid = bc.uid2 WHERE bc.fila = a.dac AND bc.agente = a.matricula AND bc.evento IN(:evento) AND ab.data_bilhete = 'now') FROM " . self::SUPERVISOR_AGENTE . " a INNER JOIN " . self::USUARIOS . " b ON a.matricula = b.matricula WHERE upper(a.dac) = upper(:queue) AND a.status = upper(:status) "; $data['queue'] = $queue; $data['status'] = $status; $data['evento'] = implode(',', [ CONF_EVENT_TIMERMINO_CLIENTE, CONF_EVENT_TIMERMINO_AGENTE ]); if ($orderBy && $orderByType) { $this->query .= " ORDER BY $orderBy $orderByType;"; } return $this->read($this->query, $data)->fetchAll(); } ######################################## ### SUPERVISOR AGENTE ### ######################################## public function addAgent($matricula, $ramal, $login, $queue, $media, $chamada_classificado = 1) { $this->query = "INSERT INTO " . self::SUPERVISOR_AGENTE . " (ramal, matricula, nome, tempo_login, modo_atendimento, dac, status, duracao, logado, status_time, disponivel_atendimento, sala_1, chamada_classificado) VALUES(:ramal, :matricula, :login, :tempo_login, :modo_atendimento, :queue, :status, :duracao, :logado, :status_time, :disponivel_atendimento, :media, :chamada_classificado);"; return $this->create($this->query, [ 'matricula' => $matricula, 'ramal' => $ramal, 'login' => $login, 'tempo_login' => 'now()', 'modo_atendimento' => 'Manual', 'queue' => $queue, 'status' => 'LIVRE', 'duracao' => 'now()', 'logado' => 'now()', 'status_time' => 'now()', 'disponivel_atendimento' => 1, 'media' => $media, 'chamada_classificado' => $chamada_classificado ]); } public function updateAgent($matricula, $ramal, $status = 'LIVRE', $origemDestino = null, $motivoPausa = null, $duracao = null, $uniqueid = null, $chamada_classificado = 1) { $data = []; $this->query = "UPDATE " . self::SUPERVISOR_AGENTE . " SET logado = :logado, origem_destino = :origem_destino, status = :status, motivo_pausa = :motivo_pausa, uniqueid = :uniqueid, chamada_classificado = :chamada_classificado"; if ($duracao) { $this->query .= ", duracao = :duracao "; } $this->query .= " WHERE matricula = :matricula AND ramal = :ramal;"; $data['matricula'] = $matricula; $data['ramal'] = $ramal; $data['logado'] = 'now()'; $data['duracao'] = 'now()'; $data['origem_destino'] = $origemDestino; $data['status'] = $status; $data['motivo_pausa'] = $motivoPausa; $data['uniqueid'] = $uniqueid; $data['chamada_classificado'] = ($chamada_classificado ? '1' : '0'); return $this->update($this->query, $data); } public function updateRefreshAgent($matricula, $ramal, $duracao = false) { $data = []; $this->query = "UPDATE " . self::SUPERVISOR_AGENTE . " SET logado = :logado "; if ($duracao) { $this->query .= ", duracao = :duracao "; $data['duracao'] = 'now()'; } $this->query .= " WHERE matricula = :matricula AND ramal = :ramal;"; $data['logado'] = 'now()'; $data['matricula'] = $matricula; $data['ramal'] = $ramal; return $this->update($this->query, $data); } public function updateSala2Agent($matricula, $ramal, $sala2 = null) { $data = []; $this->query = "UPDATE " . self::SUPERVISOR_AGENTE . " SET sala_2 = :sala_2 WHERE matricula = :matricula AND ramal = :ramal;"; $data['sala_2'] = $sala2; $data['matricula'] = $matricula; $data['ramal'] = $ramal; return $this->update($this->query, $data); } public function deleteAgent($matricula, $ramal) { $data = []; $this->query = "DELETE FROM " . self::SUPERVISOR_AGENTE . " WHERE matricula = :matricula AND ramal = :ramal;"; $data['matricula'] = $matricula; $data['ramal'] = $ramal; return $this->delete($this->query, $data); } public function updateLogadoAll($media = null) { $data = []; $this->query = "UPDATE " . self::SUPERVISOR_AGENTE . " SET logado = :logado "; if ($media) { $this->query .= " WHERE sala_1 = :sala_1; "; } $data['logado'] = 'now()'; $data['sala_1'] = $media; return $this->update($this->query, $data); } ######################################## ### EVENTOS ### ######################################## public function addEventoLoginAgent($matricula, $ramal, $idDac, $flag = 1) { $data = []; $this->query = "INSERT INTO " . self::EVENTO_AGENTE . "(matricula, ramal, login, logoff, id_dac, flag) VALUES(:matricula, :ramal, :login, :logoff, :id_dac, :flag) "; $data['matricula'] = $matricula; $data['ramal'] = $ramal; $data['login'] = 'now()'; $data['logoff'] = 'now()'; $data['id_dac'] = $idDac; $data['flag'] = $flag; return $this->create($this->query, $data); } public function updateEventoLogoffAgent($matricula, $ramal, $dac, $flag = 2) { $data = []; $this->query = "UPDATE " . self::EVENTO_AGENTE . " SET logoff = :logoff, flag = :flag " . "WHERE matricula = :matricula AND id_dac = :id_dac AND ramal = :ramal " . "AND login = (SELECT MAX(login) FROM pbx_eventos_agentes WHERE matricula = :matricula AND id_dac = :id_dac AND ramal= :ramal);"; $data['logoff'] = 'now()'; $data['flag'] = $flag; $data['matricula'] = $matricula; $data['id_dac'] = $dac; $data['ramal'] = $ramal; return $this->update($this->query, $data); } }