You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

112 lines
4.3 KiB

<?php
namespace app\Models;
use app\Core\Model;
/**
* Description of Pause
*
* @author Lucas Awade
*/
class Pause extends Model
{
const TABLE = "pbx_motivos_pausas";
const EVENTO_AGENTE = 'pbx_eventos_agentes';
public function findPauseByName($name)
{
$this->query = "SELECT * FROM " . self::TABLE . " WHERE upper(motivo) = :name ";
return $this->read($this->query, ['name' => strtoupper($name)])->fetch();
}
public function findPauseById($id)
{
$this->query = "SELECT * FROM " . self::TABLE . " WHERE id = :id";
return $this->read($this->query, ['id' => strtoupper($id)])->fetch();
}
public function addEventoPauseAgent($matricula, $ramal, $idMotivo, $idDac, $produtiva, $flag = 1)
{
$this->query = "INSERT INTO " . self::EVENTO_AGENTE . " (matricula, ramal, id_dac, id_motivo_pausa, flag, pausa_produtiva, entrada_pausa, saida_pausa)
VALUES(:matricula, :ramal, :id_dac, :id_motivo_pausa, :flag, :pausa_produtiva, :entrada_pausa, :saida_pausa);";
return $this->create(
$this->query,
[
'matricula' => $matricula,
'ramal' => $ramal,
'id_dac' => $idDac,
'id_motivo_pausa' => $idMotivo,
'flag' => $flag,
'pausa_produtiva' => $produtiva,
'entrada_pausa' => 'now()',
'saida_pausa' => 'now()'
]
);
}
public function addEventoIndisponivelAgent($matricula, $ramal, $idDac)
{
$this->query = "INSERT INTO " . self::EVENTO_AGENTE . " (matricula, ramal, id_dac, entrada_indisponivel, saida_indisponivel)
VALUES(:matricula, :ramal, :id_dac, :entrada_indisponivel, :saida_indisponivel);";
return $this->create(
$this->query,
[
'matricula' => $matricula,
'ramal' => $ramal,
'id_dac' => $idDac,
'entrada_indisponivel' => 'now()',
'saida_indisponivel' => 'now()'
]
);
}
public function updateEventoOutPause($matricula, $dac, $flag = 2)
{
$this->query = "UPDATE " . self::EVENTO_AGENTE . " SET saida_pausa = :saida_pausa, flag = :flag WHERE matricula = :matricula AND id_dac = :id_dac
AND entrada_pausa = (SELECT MAX(entrada_pausa) FROM " . self::EVENTO_AGENTE . " WHERE matricula = :matricula AND id_dac = :id_dac);";
return $this->update($this->query, ['saida_pausa' => 'now()', 'flag' => $flag, 'matricula' => $matricula, 'id_dac' => $dac]);
}
public function findGroupPause()
{
$this->query = "SELECT prm_pausa_grupo FROM pbx_parametros";
return $this->read($this->query)->fetchAll();
}
public function findPauseByGroupUser($matricula, $active = true)
{
$this->query = "SELECT DISTINCT d.id, d.motivo, d.produtiva, d.flag, d.tempo_alerta
FROM pbx_usuarios a
INNER JOIN pbx_grupo_usuario b ON a.id = b.user_id
INNER JOIN pbx_pausa_grupo_usuario c ON c.gp_id = b.gp_id
INNER JOIN pbx_motivos_pausas d ON d.id = c.id
WHERE matricula = :matricula
AND d.motivo NOT IN('login','ausente','RECUSADA') ";
if ($active) {
$this->query .= " AND d.flag = :flag";
$data['flag'] = 1;
}
$data['matricula'] = $matricula;
return $this->read($this->query, $data)->fetchAll();
}
public function findAllPause($active = true)
{
$this->query = "SELECT * FROM " . self::TABLE . " WHERE 1=1 ";
if ($active) {
$this->query .= " AND flag = :flag ";
$data['flag'] = 1;
}
$this->query .= " AND motivo NOT IN('login','ausente','RECUSADA') LIMIT 10 ";
return $this->read($this->query, $data)->fetchAll();
}
public function findAgentPause($matricula)
{
$this->query = "SELECT status, motivo_pausa FROM pbx_supervisor_agentes WHERE matricula = :matricula;";
return $this->read($this->query, ['matricula' => $matricula])->fetchAll();
}
}