* Consulta as informacoes de uma lista de acordo com o clo_id
* @param int $clo_id
* @return type
* @throws Exception
*/
function getClienteOrigem($clo_id) {
$query = "SELECT clo_id,clo_titulo,clo_descricao,a.cfr_id,cfr_razao_social,nome,apelido, (SELECT count(clo_id) FROM pbx_cliente WHERE clo_id = a.clo_id) AS registros, a.data_reg
FROM pbx_cliente_origem a
INNER JOIN pbx_cliente_fornecedor b ON a.cfr_id = b.cfr_id
INNER JOIN pbx_usuarios c ON c.matricula = a.user_reg::VARCHAR
WHERE clo_id = {$clo_id}; ";
$result = pg_query($query);
if (!$result) {
throw new Exception("[Exception in " . __FUNCTION__ . "] - N<EFBFBD>o foi poss<EFBFBD>vel localizar a lista informada.");
}
$data = pg_fetch_all($result);
return $data;
}
/**
* Busca os agentes que tem permissao para operar na campanha
* @param int $cfr_id
* @return type
* @throws Exception
*/
function getClienteAgentes() {
$query = "SELECT DISTINCT id, nome, apelido, matricula FROM pbx_usuarios a
INNER JOIN pbx_grupo_usuario b ON a.id = b.user_id
INNER JOIN pbx_grupo_funcoes c ON c.gp_id = b.gp_id
WHERE b.gp_id IN(SELECT gp_id FROM (SELECT CASE WHEN(COUNT(gp_id) > 1) THEN gp_id END AS gp_id
FROM pbx_grupo_funcoes WHERE fun_id = 209 OR fun_id = 2
GROUP BY gp_id
ORDER BY 1) AS DATA)";
$result = pg_query($query);
if (!$result) {
throw new Exception("[Exception in " . __FUNCTION__ . "] - N<EFBFBD>o foi poss<EFBFBD>vel localizar os Agentes da lista informada.");
}
$data = pg_fetch_all($result);
return $data;
}
/**
* Busca a matricula pelo apelido do usuario
* @param string $apelido
* @return boolean
*/
function __getMatriculaAgente($apelido) {
$query = "SELECT matricula FROM pbx_usuarios WHERE apelido = '{$apelido}';";
$result = pg_query($query);
$data = pg_fetch_assoc($result);
if ($data) {
return $data['matricula'];
}
return false;
}
/**
* Retorna todos os cliente referentes a Cliente Origem.
* V<EFBFBD>riavel de parametro $apenasMatricula para buscar somente registros com o agente.
* @param type $cloid
* @param bool $apenasMatricula
* @return boolean
*/
function __getClientesPorCloid($cloid) {
$query = "SELECT * FROM pbx_cliente WHERE clo_id = '{$cloid}' AND client_user_contato <> '' AND list_id IS NULL AND cmp_id IS NULL and client_status <> '999'; ";
$result = pg_query($query);
if (!$result) {
throw new Exception("[Exception in " . __FUNCTION__ . "] - N<EFBFBD>o foi poss<EFBFBD>vel buscar os clientes por origem.");
}
$data = pg_fetch_all($result);
return $data;
}
/**
* Realiza um update nos registros buscados de acordo com a quantidade de limit
* @param string $matricula
* @param int $cloid
* @param int $reg
* @return boolean
*/
function setMatriculaCliente($matricula, $cloid, $reg) {
$query = "UPDATE pbx_cliente SET client_user_contato = '{$matricula}' WHERE client_id IN (SELECT client_id FROM pbx_cliente WHERE clo_id = $cloid AND list_id IS NULL AND cmp_id IS NULL AND client_user_contato IS NULL and client_status <> '999' LIMIT $reg);";
$result = pg_query($query);
if (!$result) {
throw new Exception("[Exception in " . __FUNCTION__ . "] - N<EFBFBD>o foi poss<EFBFBD>vel atribuir a matricula no registros de cliente.");
}
return true;
}
/**
* Realiza o resete das matriculas cadastradas
* @param int $cloid
* @return boolean
*/
function resetMatriculaCliente($cloid) {
$query = "UPDATE pbx_cliente SET client_user_contato = NULL WHERE client_id IN (SELECT client_id FROM pbx_cliente WHERE clo_id = {$cloid}) AND list_id IS NULL AND cmp_id IS NULL and client_status <> '999';";
$result = pg_query($query);
if (!$result) {
throw new Exception("[Exception in " . __FUNCTION__ . "] - N<EFBFBD>o foi poss<EFBFBD>vel resetar os dados referente a matricula referente aos registros de cliente.");
}
return true;
}
/**
* Verifica a se a campanha possui os registros de matriculas
* @param int $cloid
* @return boolean
*/
function getRegistrosMatricula($cloid) {
$query = "SELECT COUNT(client_id) AS registros, SUM(CASE WHEN(client_user_contato <> '')THEN 1 ELSE 0 END) AS registros_matricula FROM pbx_cliente WHERE clo_id = {$cloid} and client_status <> '999'";
$result = pg_query($query);
if (!$result) {
throw new Exception("[Exception in " . __FUNCTION__ . "] - N<EFBFBD>o foi poss<EFBFBD>vel localizar os dados referente a lista.");
}
$data = pg_fetch_assoc($result);
return $data;
}
/**
* Retorna a quantidade de registros para cada agente
*/
function getUsuariosRegistros($cloid) {
$query = "SELECT apelido, matricula, count(client_user_contato) AS registros
FROM pbx_cliente a
INNER JOIN pbx_usuarios b ON b.matricula = a.client_user_contato
WHERE clo_id = {$cloid}
AND list_id IS NULL AND cmp_id IS NULL
GROUP BY 1,2";
$result = pg_query($query);
if (!$result) {
throw new Exception("[Exception in " . __FUNCTION__ . "] - N<EFBFBD>o foi poss<EFBFBD>vel localizar os registros dos Agentes.");
}
$data = pg_fetch_all($result);
return $data;
}
function __getSelectCamp($id = null) {
$query = "SELECT cmp_id, cmp_descricao FROM pbx_campanha WHERE cmp_status IN (2,3) ";
$result = pg_query($query);
if (!$result) {
throw new Exception("[Exception in " . __FUNCTION__ . "] - N<EFBFBD>o foi poss<EFBFBD>vel localizar as campanhas.");
* VERIFICA SE A CAMPANHA SELECIONADA ESTA COM STATUS ATIVA OU EXCLUIDA
*/
$statusCamp = verificaStatusCampanha($cmp_id);
if ($statusCamp == 1 || $statusCamp == 0) {
__transaction('ROLLBACK;');
// logger(__FILE__)->debug('[ERROR LIST 001] - A campanha n<EFBFBD>o pode estar ativa!');
throw new Exception("[ERROR LIST 001] - A campanha n<EFBFBD>o pode estar ativa! ");
}
/**
* Table: pbx_campanha && pbx_campanha_lista
* VERIFICA SE EXISTE UMA LISTA NA CAMPANHA
*/
$query = "SELECT COUNT(cmp_id), (SELECT cmp_descricao FROM pbx_campanha WHERE cmp_id = {$cmp_id} ORDER BY 1 DESC LIMIT 1) AS list_name FROM pbx_campanha_lista WHERE cmp_id = {$cmp_id} GROUP BY 2;";
$result = pg_query($query);
if (!$result) {
__transaction('ROLLBACK;');
throw new Exception("[ERROR LIST 002] - N<EFBFBD>o foi poss<EFBFBD>vel buscar as informa<EFBFBD><EFBFBD>es da campanha!");
}
$data = pg_fetch_assoc($result);
/**
* SE N<EFBFBD>O HOUVER LISTA CRIADA, BUSCA OS DADOS DA CAMPANHA PARA COMPLEMENTAR
$query = "SELECT * FROM pbx_cliente WHERE client_id IN (SELECT client_id FROM pbx_cliente WHERE clo_id = {$id}) AND list_id IS NULL AND cmp_id IS NULL AND client_user_contato <> '';";