forked from SimplesIP/pabx-app
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.
118 lines
3.5 KiB
118 lines
3.5 KiB
<?php |
|
|
|
namespace app\Repositories; |
|
|
|
use app\core\Repository; |
|
|
|
class Bilhetes extends Repository |
|
{ |
|
//protected static string $table = 'pbx_bilhetes'; |
|
|
|
public static function getBilhetes(array $data): array |
|
{ |
|
$query = "SELECT |
|
a.id_bilhetes AS id, a.calldate AS data_hora, SPLIT_PART(a.clid, ' ', 1) AS entrada, |
|
a.src, a.dst, a.billsec AS tempo_conversacao, |
|
a.duration AS tempo_atendimento, a.accountcode AS id_transfer, a.uniqueid AS uniqueid, |
|
a.userfield AS nome_audio, a.fora_horario AS fora_horario, |
|
a.org_id |
|
FROM pbx_bilhetes a |
|
WHERE a.lastapp <> 'Transferred Call' "; |
|
|
|
|
|
// mountig the 'WHERE' statement |
|
foreach ($data as $k => $v) { |
|
|
|
if (!$v) { |
|
continue; |
|
} |
|
|
|
if (in_array($k, ['src', 'dst'])) { |
|
$query .= " AND $k LIKE :$k"; |
|
continue; |
|
} |
|
|
|
if ($k === 'entrada') { |
|
$query .= " AND a.clid LIKE :$k"; |
|
continue; |
|
} |
|
|
|
if ($k === 'data_i') { |
|
$query .= " AND calldate >= :$k"; |
|
continue; |
|
} |
|
|
|
if ($k === 'data_f') { |
|
$query .= " AND calldate <= :$k"; |
|
continue; |
|
} |
|
|
|
$query .= " AND $k = :$k"; |
|
} |
|
|
|
$query .= " ORDER BY calldate"; |
|
return self::query($query, $data, 'all'); |
|
} |
|
|
|
public static function getEventosBilhetes(array $data): array |
|
{ |
|
$query = "SELECT |
|
a.id_bilhetes AS id, |
|
a.src, |
|
a.dst, |
|
a.uniqueid, |
|
SPLIT_PART(a.clid, ' ', 1) AS entrada, |
|
c.id AS fila_id, |
|
b.fila, |
|
d.nome, |
|
d.apelido AS login, |
|
SUBSTRING(b.agente,7,4) AS matricula, |
|
b.evento AS evento, |
|
b.param1 AS param1, |
|
b.param2 AS param2, |
|
b.param3 AS param3, |
|
b.param4 AS param4 |
|
FROM pbx_bilhetes a |
|
INNER JOIN pbx_eventos_dacs b ON a.uniqueid = b.uid2 |
|
INNER JOIN pbx_dacs c ON c.nome = b.fila |
|
INNER JOIN pbx_usuarios d ON d.matricula = SUBSTRING(b.agente,7,4) |
|
WHERE evento IN ('ABANDON','COMPLETEAGENT','COMPLETECALLER','CONNECT','ENTERQUEUE', |
|
'EXITWITHTIMEOUT', 'TRANSBORDANDO', 'TRANSBORDADO','TRANSFER', 'TRANSFERORIG', |
|
'COMPLETACALLER', 'COMPLETAAGENT', 'ANSWERED', 'BUSYS', 'NOANSWERS') "; |
|
|
|
foreach ($data as $k => $v) { |
|
if (!$v) { |
|
continue; |
|
} |
|
|
|
if (in_array($k, ['src', 'dst', 'fila', 'evento'])) { |
|
$query .= " AND $k LIKE :$k"; |
|
continue; |
|
} |
|
|
|
if ($k === 'entrada') { |
|
$query .= " AND a.clid LIKE :$k"; |
|
continue; |
|
} |
|
|
|
if ($k === 'data_i') { |
|
$query .= " AND data_bilhete >= :$k"; |
|
continue; |
|
} |
|
|
|
if ($k === 'data_f') { |
|
$query .= " AND data_bilhete <= :$k"; |
|
continue; |
|
} |
|
|
|
if ($k === 'org_id') { |
|
$query .= " AND a.org_id = :$k"; |
|
continue; |
|
} |
|
|
|
$query .= " AND $k = :$k"; |
|
} |
|
|
|
return self::query($query, $data, 'all'); |
|
} |
|
}
|
|
|