Browse Source

Merge pull request 'inserido org_id junto a tabela do ast_eventos_dacs' (#306) from matheorb/developer:dev-1.9 into 1.9

Reviewed-on: SimplesIP/pabx-app#306
1.9
Matheo Bonucia 2 months ago
parent
commit
beb0745464
  1. 74
      agente/agenteHitorico.php
  2. 146
      include/util/util.php

74
agente/agenteHitorico.php

@ -65,26 +65,62 @@
function ___GetData($dbcon) {
$matricula = GetMatricula();
$dac = $_SESSION[AGT_DAC_CONECT_DESC];
$org_id = $_SESSION['SSEmpresaPadrao'];
$query = "SELECT
bil.calldate,
src AS clid,
dac.param2 AS duracao,
protocolo,
to_timestamp(uid1::float) AS data_atend,
'E' AS direcao
FROM
ast_eventos_dacs dac,
ast_bilhetes bil,
pbx_protocolo_reg reg
WHERE
bil.uniqueid = dac.uid2
AND dac.org_id = $org_id
AND bil.org_id = dac.org_id
AND reg.org_id = dac.org_id
AND reg.uniqueid = bil.uniqueid
AND bil.data_bilhete = CAST(now() AS date)
AND substring(dac.agente,
7,
4) = '$matricula'
AND dac.fila = '$dac'
AND dac.evento IN('COMPLETEAGENT', 'COMPLETECALLER', 'COMPLETECALLERRAMAL', 'TRANSFER', 'COMPLETECALLERRAMAL')
AND bil.lastapp <> 'Transferred Call'
UNION ALL
SELECT
bil.calldate,
dst AS clid,
dac.param2 AS duracao,
protocolo,
bil.calldate AS data_atend,
'S' AS direcao
FROM
ast_eventos_dacs dac,
ast_bilhetes bil,
pbx_protocolo_reg reg
WHERE
bil.uniqueid = dac.uid2
AND dac.org_id = $org_id
AND bil.org_id = dac.org_id
AND reg.org_id = dac.org_id
AND reg.uniqueid = bil.uniqueid
AND bil.data_bilhete = CAST(now() AS date)
AND substring(dac.agente,
7,
4) = '$matricula'
AND dac.fila = '$dac'
AND dac.evento IN('COMPLETAAGENT', 'COMPLETACALLER', 'TRANSFERORIG', 'BUSYS', 'NOANSWERS')
AND bil.lastapp <> 'Transferred Call'
ORDER BY
1,
4;"
;
$query = "Select bil.calldate, src as clid, dac.param2 as duracao, protocolo, to_timestamp(uid1::float) as data_atend, 'E' as direcao
from ast_eventos_dacs dac, ast_bilhetes bil, pbx_protocolo_reg reg
where bil.uniqueid = dac.uid2
and reg.uniqueid = bil.uniqueid
and bil.data_bilhete = cast(now() as date)
and substring(dac.agente, 7,4) = '$matricula'
and dac.fila = '$dac'
and dac.evento in('COMPLETEAGENT', 'COMPLETECALLER', 'COMPLETECALLERRAMAL', 'TRANSFER', 'COMPLETECALLERRAMAL')
and bil.lastapp <> 'Transferred Call'
union all
Select bil.calldate, dst as clid, dac.param2 as duracao, protocolo, bil.calldate as data_atend, 'S' as direcao
from ast_eventos_dacs dac, ast_bilhetes bil, pbx_protocolo_reg reg
where bil.uniqueid = dac.uid2
and reg.uniqueid = bil.uniqueid
and bil.data_bilhete = cast(now() as date)
and substring(dac.agente, 7,4) = '$matricula'
and dac.fila = '$dac'
and dac.evento in('COMPLETAAGENT','COMPLETACALLER','TRANSFERORIG','BUSYS','NOANSWERS')
and bil.lastapp <> 'Transferred Call' order by 1, 4";
//if(IsAdmin()) echo $query;
$result = pg_query($dbcon, $query);

146
include/util/util.php

@ -1434,76 +1434,82 @@ function CorrigeAbandonTransbordo($dbcon)
$path = '/var/log/asterisk/corrige_abandon_transbordo.log';
$query = "-- Procura todas os transbordos que foram gerados pelo asterisk. EXITWITHTIMEOUT
drop table if exists transbordo_saida;
create temporary table transbordo_saida as
select distinct a.fila, a.uniqueid, a.trbd_origem_destino as fila_destino
from pbx_eventos_transbordo a, ast_eventos_dacs b
where b.fila = a.trbd_origem_destino
and b.uid2 = a.uniqueid
and a.data_reg::date = now()::date
and a.trbd_aplicacao = 'EXITWITHTIMEOUT'
and a.trbd_origem_destino_tipo = 'filas'
and trbd_tipo = 'S';
-- Insere o evento TRANSBORDANDO na fila que a chamdada saiu.
insert into ast_eventos_dacs(uid1,uid2,fila,evento)
select trunc(uniqueid::numeric),uniqueid,fila, 'TRANSBORDANDO' as evento from transbordo_saida a where not exists(select '' from ast_eventos_dacs where fila = a.fila and uid2 = a.uniqueid and evento = 'TRANSBORDANDO');
-- Insere o evento TRANSBORDADO na fila que a chamdada entrou(Destino do Transbordo). EXITWITHTIMEOUT faz transbordo mas não insere o evento na fila de destino.
insert into ast_eventos_dacs(uid1,uid2,fila,evento)
select trunc(uniqueid::numeric),uniqueid,fila_destino, 'TRANSBORDADO' as evento from transbordo_saida a where not exists(select '' from ast_eventos_dacs where fila = a.fila_destino and uid2 = a.uniqueid and evento = 'TRANSBORDADO');
-- Procura todas os transbordos que foram gerados de forma assistida pela aplicacao.
drop table if exists transbordo_saida;
create temporary table transbordo_saida as
select distinct a.fila, a.uniqueid, a.trbd_origem_destino as fila_destino
from pbx_eventos_transbordo a, ast_eventos_dacs b
where b.fila = a.trbd_origem_destino
and b.uid2 = a.uniqueid
and a.data_reg::date = now()::date
and a.trbd_aplicacao <> 'EXITWITHTIMEOUT'
and a.trbd_origem_destino_tipo = 'filas'
and trbd_tipo = 'S';
-- Todas as chamadas transbordadas pelo transbordo assistido gera um evento abandon que precisa ser removido.
delete from ast_eventos_dacs a
where exists(select '' from transbordo_saida where uniqueid = a.uid2 and fila = a.fila)
and a.evento = 'ABANDON';
-- Insere o evento TRANSBORDANDO na fila que a chamdada saiu caso nao exista.
insert into ast_eventos_dacs(uid1,uid2,fila,evento)
select trunc(uniqueid::numeric),uniqueid,fila, 'TRANSBORDANDO' as evento from transbordo_saida a where not exists(select '' from ast_eventos_dacs where fila = a.fila and uid2 = a.uniqueid and evento = 'TRANSBORDANDO');
-- Insere o evento TRANSBORDADO na fila que a chamdada entrou(Destino do Transbordo) caso nao exista. EXITWITHTIMEOUT faz transbordo mas não insere o evento na fila de destino.
insert into ast_eventos_dacs(uid1,uid2,fila,evento)
select trunc(uniqueid::numeric),uniqueid,fila_destino, 'TRANSBORDADO' as evento from transbordo_saida a where not exists(select '' from ast_eventos_dacs where fila = a.fila_destino and uid2 = a.uniqueid and evento = 'TRANSBORDADO');
--Procura todos os transbordo que foram gerados para um dispositivo diferente de uma fila.
drop table if exists transbordo_saida;
create temporary table transbordo_saida as
select distinct a.fila, a.uniqueid
from pbx_eventos_transbordo a
where a.data_reg::date = now()::date
and a.trbd_origem_destino_tipo <> 'filas'
and trbd_tipo = 'S';
-- Todas as chamadas transbordadas pelo transbordo assistido gera um evento abandon que precisa ser removido.
delete from ast_eventos_dacs a
where exists(select '' from transbordo_saida where uniqueid = a.uid2 and fila = a.fila)
and a.evento = 'ABANDON';
-- Insere o evento transbordando caso o mesmo nao exista na fila de origem.
insert into ast_eventos_dacs(uid1,uid2,fila,evento)
select trunc(uniqueid::numeric),uniqueid,fila, 'TRANSBORDANDO' as evento from transbordo_saida a where not exists(select '' from ast_eventos_dacs where fila = a.fila and uid2 = a.uniqueid and evento = 'TRANSBORDANDO');
-- Apaga o evento \"EXITWITHTIMEOUT\" gerado pelo transbordo nativo.
delete from ast_eventos_dacs b using ast_bilhetes a where b.uid2 = a.uniqueid and a.calldate::date = now()::date and b.evento = 'EXITWITHTIMEOUT';";
drop table if exists transbordo_saida;
create temporary table transbordo_saida as
select distinct a.fila, a.uniqueid, a.trbd_origem_destino as fila_destino, a.org_id
from pbx_eventos_transbordo a, ast_eventos_dacs b
where b.fila = a.trbd_origem_destino
and b.uid2 = a.uniqueid
and a.data_reg::date = now()::date
and a.trbd_aplicacao = 'EXITWITHTIMEOUT'
and a.trbd_origem_destino_tipo = 'filas'
and trbd_tipo = 'S'
and a.org_id = b.org_id
;
-- Insere o evento TRANSBORDANDO na fila que a chamdada saiu.
insert into ast_eventos_dacs(uid1,uid2,fila,evento, org_id)
select trunc(uniqueid::numeric),uniqueid,fila, 'TRANSBORDANDO' as evento, org_id from transbordo_saida a where not exists(select '' from ast_eventos_dacs where fila = a.fila and uid2 = a.uniqueid and evento = 'TRANSBORDANDO');
-- Insere o evento TRANSBORDADO na fila que a chamdada entrou(Destino do Transbordo). EXITWITHTIMEOUT faz transbordo mas não insere o evento na fila de destino.
insert into ast_eventos_dacs(uid1,uid2,fila,evento, org_id)
select trunc(uniqueid::numeric),uniqueid,fila_destino, 'TRANSBORDADO' as evento, org_id from transbordo_saida a where not exists(select '' from ast_eventos_dacs where fila = a.fila_destino and uid2 = a.uniqueid and evento = 'TRANSBORDADO');
-- Procura todas os transbordos que foram gerados de forma assistida pela aplicacao.
drop table if exists transbordo_saida;
create temporary table transbordo_saida as
select distinct a.fila, a.uniqueid, a.trbd_origem_destino as fila_destino, a.org_id
from pbx_eventos_transbordo a, ast_eventos_dacs b
where b.fila = a.trbd_origem_destino
and b.uid2 = a.uniqueid
and a.data_reg::date = now()::date
and a.trbd_aplicacao <> 'EXITWITHTIMEOUT'
and a.trbd_origem_destino_tipo = 'filas'
and trbd_tipo = 'S'
and a.org_id = b.org_id
;
-- Todas as chamadas transbordadas pelo transbordo assistido gera um evento abandon que precisa ser removido.
delete from ast_eventos_dacs a
where exists(select '' from transbordo_saida where uniqueid = a.uid2 and fila = a.fila and org_id = a.org_id)
and a.evento = 'ABANDON'
;
-- Insere o evento TRANSBORDANDO na fila que a chamdada saiu caso nao exista.
insert into ast_eventos_dacs(uid1,uid2,fila,evento, org_id)
select trunc(uniqueid::numeric),uniqueid,fila, 'TRANSBORDANDO' as evento, org_id from transbordo_saida a where not exists(select '' from ast_eventos_dacs where fila = a.fila and uid2 = a.uniqueid and evento = 'TRANSBORDANDO' and org_id = a.org_id);
-- Insere o evento TRANSBORDADO na fila que a chamdada entrou(Destino do Transbordo) caso nao exista. EXITWITHTIMEOUT faz transbordo mas não insere o evento na fila de destino.
insert into ast_eventos_dacs(uid1,uid2,fila,evento, org_id)
select trunc(uniqueid::numeric),uniqueid,fila_destino, 'TRANSBORDADO' as evento, org_id from transbordo_saida a where not exists(select '' from ast_eventos_dacs where fila = a.fila_destino and uid2 = a.uniqueid and evento = 'TRANSBORDADO' and org_id = a.org_id);
--Procura todos os transbordo que foram gerados para um dispositivo diferente de uma fila.
drop table if exists transbordo_saida;
create temporary table transbordo_saida as
select distinct a.fila, a.uniqueid, a.org_id
from pbx_eventos_transbordo a
where a.data_reg::date = now()::date
and a.trbd_origem_destino_tipo <> 'filas'
and trbd_tipo = 'S'
;
-- Todas as chamadas transbordadas pelo transbordo assistido gera um evento abandon que precisa ser removido.
delete from ast_eventos_dacs a
where exists(select '' from transbordo_saida where uniqueid = a.uid2 and fila = a.fila and org_id = a.org_id)
and a.evento = 'ABANDON';
-- Insere o evento transbordando caso o mesmo nao exista na fila de origem.
insert into ast_eventos_dacs(uid1,uid2,fila,evento, org_id)
select trunc(uniqueid::numeric),uniqueid,fila, 'TRANSBORDANDO' as evento, org_id from transbordo_saida a where not exists(select '' from ast_eventos_dacs where fila = a.fila and uid2 = a.uniqueid and evento = 'TRANSBORDANDO' and org_id = a.org_id);
-- Apaga o evento \"EXITWITHTIMEOUT\" gerado pelo transbordo nativo.
delete from ast_eventos_dacs b using ast_bilhetes a where b.uid2 = a.uniqueid and a.calldate::date = now()::date and b.evento = 'EXITWITHTIMEOUT' and a.org_id = b.org_id;";
try {

Loading…
Cancel
Save