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.
 
 
 
 
 
 

599 lines
28 KiB

<?php
/***************************************************************************
*
* Recebidas Por DDD
* Autor
* Lucas Awade
*
* *************************************************************************
* Definições do Projeto
* Nome: RelRecebidasDDD
* Data início: 08/08/2018
* Equipe: Amarildo Pereira
* Descrição:
* O objetivo deste relatório é apresentar informações das chamdas de
* Entrada e Saída, com base no DDD de cada chamada, assim foi relacionadas
* tabelas que possui essas informações e eventos que filtrara ocorrecias
* não desejadas.
*
* Tabelas utilizadas:
*
* -> pbx_bilhetes = Chamadas realizadas;
* -> pbx_eventos_dacs = Filtrar eventos de chamadas;
* -> pbx_municipios = Coletar DDD UF e REGIAO;
* -> pbx_tipo_ligacao = Verificar o tipo da chamada;
* -> pbx_dacs = Relacionar com a fila;
*
* A totalização é feita de modo estruturado onde contém informações fixas
* para o tratamento e contagem.Sua estrutura foi adptada para ser utilizado
* no modulos de impressão. Seus relacionamentos é apenas com os tipo de
* ligacao.
*
* Tipo de ligação em contagem:
*
* -> Fixo Interurbano
* -> Fixo Local
* -> Movel Local
* -> Movel Interurbano
* -> Total = Contagem de todos os demais modos;
*
* OBS: Para corrigir ou adicionar informações no relatório atentar com essa
* estrutura.
*
* *************************************************************************
* Copyright (c) 2018, Simples IP
* ************************************************************************/
include_once 'util/relatoriosBase.php';
class RelRecebidasDDD extends Relatorios {
private $___tiposLigacao = null;
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0;
$this->___tiposLigacao = array(
0 => array('descricao' => 'Fixo Interurbano', 'tempo' => 0, 'quantidade' => 0, 'duracao' => 0),
1 => array('descricao' => 'Fixo Local', 'tempo' => 0, 'quantidade' => 0, 'duracao' => 0),
2 => array('descricao' => 'Movel Local', 'tempo' => 0, 'quantidade' => 0, 'duracao' => 0),
3 => array('descricao' => 'Movel Interurbano', 'tempo' => 0, 'quantidade' => 0, 'duracao' => 0),
4 => array('descricao' => 'C.I.E.I.V', 'tempo' => 0, 'quantidade' => 0, 'duracao' => 0),
5 => array('descricao' => 'Total', 'tempo' => 0, 'quantidade' => 0, 'duracao' => 0)
);
}
function ___FiltrosRelatorio() {
if ($this->___media != MEDIA_PRINT_GRID) {
/*
* Recupera os filtros da sessão do usuário.
*/
list($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio) = $_SESSION["SSstorageFiltros"];
if ($this->___media == MEDIA_PRINT_HTML) {
$fila = $this->GetIncDac() ? 'Fila: ' . GetDacDesc($this->GetDbCon(), $this->GetIdProg() . ' ') : '';
return sprintf("%sData Inicial: %s Data Final: %s Tipo: %s", $fila, $this->___dataIni, $this->___dataFim, ($this->___tipoRelatorio ? 'Analítico' : 'Sintético'));
}
$fltCsv = array();
if ($this->GetIncDac()) {
$fltCsv[] = 'Fila:' . GetDacDesc($this->GetDbCon(), $this->___dac);
}
$fltCsv[] = "Data Inicial:" . $this->___dataIni;
$fltCsv[] = "Data Final:" . $this->___dataFim;
$fltCsv[] = "Data Emissao:" . date('d/m/Y H:i:s');
$fltCsv[] = "Emitido Por:" . GetLogin();
return $fltCsv;
}
if ($this->GetIncDac()) {
$dacs = GetDac($this->GetDbCon(), $this->___dac, "", 0, 1, 0, 0, 1);
}
$lkPrint = "";
if ($this->___dataCount) {
$prt = '<a href="index.php?idProg=%s&media=%s&tipoRelatorio=%s"><img src="imgSite/%s" alt="Clique aqui para imprimir!" width="24" height="24" border="0"></a>';
$prtHtml = "<a href=\"javaScript:NovaJanela('index.php?idProg=%s&media=%s&tipoRelatorio=%s', '%s', '720', '700', 'scrollbars=YES');\"><img src=\"imgSite/%s\" alt=\"Clique aqui para imprimir!\" width=\"24\" height=\"24\" border=\"0\"></a>";
$lkPrint .= sprintf($prtHtml, $this->GetidProg(), MEDIA_PRINT_HTML, $this->___tipoRelatorio, substr(LimpaString(GetDispProgSel($this->GetIdProg())), 0, 20), 'print.gif');
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_EXCEL, $this->___tipoRelatorio, 'prt-xls.png');
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_PDF, $this->___tipoRelatorio, 'prt-pdf.png');
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_CSV, $this->___tipoRelatorio, 'prt-csv.png');
}
$tipoRel = !$this->___tipoRelatorio ? '' : 'checked="checked"';
/*
* Personalise esta função se necessitar de outras operações de filtro.
*/
$filtro = '<table border="0" cellspacing="1" cellpadding="1">';
/*
* Rotulos.
*/
$filtro .= '<tr>';
$this->GetIncDac() ? $filtro .= '<td>Fila</td>' : '';
$filtro .= '<td>Data Inicial</td>';
$filtro .= '<td>Data Final </td>';
$filtro .= '<td align="center" valign="middle">&nbsp;</td>';
$filtro .= '</tr>';
/*
* Valores.
*/
$filtro .= '<tr>';
$this->GetIncDac() ? $filtro .= sprintf('<td>%s</td>', $dacs) : '';
$filtro .= '<td><input name="dataIni" id="dataIni" type="text" size="15" maxlength="10" value="%s" onkeyup="formataData(this)" title="dd/mm/aaaa"></td>';
$filtro .= '<td><input name="dataFim" id="dataFim" type="text" size="15" maxlength="10" value="%s" onkeyup="formataData(this)" title="dd/mm/aaaa"></td>';
$filtro .= '<td><input type="submit" name="btConsulta" id="btConsulta" value="Consultar"></td>';
$filtro .= '<td>%s</td>';
$filtro .= '</tr>';
$filtro .= '</table>';
/*
* Guarda os filtros passados para recuperar na emissão dos relatórios para impressão.
*/
$_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio);
return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint);
}
protected function ___GetDadosDb() {
$dataIni = FormatDtMssql($this->___dataIni);
$dataFim = FormatDtMssql($this->___dataFim);
$dac = $this->___dac;
$query = sprintf("SELECT b.fila,c.codigo_ddd AS ddd, c.uf,
CASE WHEN(tplg_codigo IN(23,24,33,34))THEN 'MÓVEL' ELSE c.nome_municipio END AS nome_municipio,
tplg_descricao,count(*) AS qtde, SUM(a.billsec) AS duracao
FROM pbx_bilhetes a
INNER JOIN pbx_eventos_dacs b ON a.uniqueid = b.uid2 AND b.evento IN('COMPLETEAGENT','COMPLETECALLER','COMPLETAAGENT','COMPLETECALLERRAMAL','COMPLETEAGENTRAMAL')
INNER JOIN pbx_municipios c ON a.id_municipio = c.id
INNER JOIN pbx_tipo_ligacao d ON a.tipo_chamada = d.tplg_codigo
INNER JOIN pbx_dacs e ON e.nome = b.fila
WHERE a.data_bilhete >= '%s'
AND a.data_bilhete <= '%s'
AND e.id = %s
AND a.lastapp <> 'Transferred Call'
GROUP BY 1,2,3,4,5
ORDER BY c.uf", $dataIni, $dataFim, $dac);
$result = $this->___GetQuery($query);
$row = pg_fetch_all($result);
$this->SetData($row ? $row : array());
}
protected function ___PreparaCsv() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
/*
* Inicia o relatório.
*/
$dataRel[] = GenerateCsvFromArray($filtro);
$dadosCabecalio = array('DDD', 'UF', 'Regiao', 'Tipo', 'Duracao', 'TMO', 'Quantidade');
$dadosField = array('ddd', 'uf', 'nome_municipio', 'tplg_descricao', 'duracao', 'tmo', 'qtde');
/*
* Monta a linha de cabecalio.
*/
$dataRel[] = GenerateCsvFromArray($dadosCabecalio);
$somaTempo = 0;
$somaQtde = 0;
$somaReg = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaQtde ++;
$somaTempo += $row["duracao"];
$somaReg += $row['qtde'];
$descricao = explode(" ", $row['tplg_descricao']);
$this->___verificaTipoLigacao($descricao[1] . ' ' . $descricao[2], $row["duracao"]);
$row['tmo'] = SecondToStrTime(round($row["duracao"] / $row['qtde']));
$row["duracao"] = SecondToStrTime($row["duracao"]);
// Formata linha de dados.
$linha = array();
foreach ($dadosField as $value) {
$linha[] = $row["$value"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
$dataRel[] = GenerateCsvFromArray(array('Total: ' . $somaQtde, '', '', '', 'Duracao: ' . SecondToStrTime($somaTempo), 'TMO: ' . SecondToStrTime(round($somaTempo / $somaReg)), $somaQtde));
$dataRel[] = GenerateCsvFromArray(array('', '', '', ''));
$totalCabecalio = array('Tipo', 'Quantidade', 'Tempo');
$dataRel[] = GenerateCsvFromArray($totalCabecalio);
foreach ($this->___tiposLigacao as $value) {
$dataRel[] = GenerateCsvFromArray(array($value['descricao'], $value['quantidade'], $value['duracao']));
}
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaExcel() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
/*
* Inicia o relatório.
*/
/*
* Cria os filtros
*/
$linha = array('LABEL');
foreach ($filtro as $values) {
list($label, $value) = explode(":", $values);
$linha[] = $label;
}
$dataRel[] = $linha;
$linha = array('DADOS');
foreach ($filtro as $values) {
list($label, $value) = explode(":", $values);
$linha[] = $value;
}
$dataRel[] = $linha;
$dadosCabecalio = array('DDD', 'UF', 'Regiao', 'Tipo', 'Duracao', 'TMO', 'Quantidade');
$dadosField = array('ddd', 'uf', 'nome_municipio', 'tplg_descricao', 'duracao', 'tmo', 'qtde');
/*
* Monta a linha de cabecalio.
*/
$linha = array('LABEL');
foreach ($dadosCabecalio as $value) {
$linha[] = $value;
}
$dataRel[] = $linha;
$somaTempo = 0;
$somaQtde = 0;
$somaReg = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaQtde ++;
$somaTempo += $row["duracao"];
$somaReg += $row['qtde'];
$descricao = explode(" ", $row['tplg_descricao']);
$this->___verificaTipoLigacao($descricao[1] . ' ' . $descricao[2], $row["duracao"]);
$row['tmo'] = SecondToStrTime(round($row["duracao"] / $row['qtde']));
$row["duracao"] = SecondToStrTime($row["duracao"]);
// Formata linha de dados.
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
$dataRel[] = array('LABEL', 'Total: ' . $somaQtde, '', '', '', 'Duracao: ' . SecondToStrTime($somaTempo), 'TMO: ' . SecondToStrTime(round($somaTempo / $somaQtde)), 'Registros: ' . $somaQtde);
$dataRel[] = array('LABEL', '', '', '', '', '', '');
$totalCabecalio = array('Tipo', 'Quantidade', 'Tempo');
$linhaTotal = array('LABEL');
foreach ($totalCabecalio as $value) {
$linhaTotal[] = $value;
}
$dataRel[] = $linhaTotal;
$linhaTotal = array('DADOS');
foreach ($this->___tiposLigacao as $key => $value) {
$dataRel[] = array('DADOS', $value['descricao'], $value['quantidade'], $value['duracao']);
}
$dataRel[] = $linhaTotal;
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaGrid() {
$dataRel = array();
$dadosCabecalio = array(
'DDD' => 'align="center"',
'UF' => 'align="center"',
'Região' => 'align="left"',
'Tipo' => 'align="left"',
'Duração' => 'align="center"',
'TMO' => 'align="center"',
'Quantidade' => 'align="center"'
);
$dadosField = array(
'ddd' => 'align="center"',
'uf' => 'align="center"',
'nome_municipio' => 'align="left"',
'tplg_descricao' => 'align="left"',
'duracao' => 'align="center"',
'tmo' => 'align="center"',
'qtde' => 'align="center"'
);
/*
* Inicia o relatório.
*/
$dataRel[] = '<table width="70%" cellpadding="2" class="grid">';
/*
* Monta a linha de cabecalio.
*/
$linha = '<tr>';
foreach ($dadosCabecalio as $key => $value) {
$linha .= sprintf("<th %s>%s</th>", $value, $key);
}
$linha .= "</tr>";
$dataRel[] = $linha;
/*
* Verifica se retornou dados
*/
if (!IsPostBack() || !count($this->GetData()[0])) {
$dataRel[] = sprintf("<tr><td align=\"center\" colspan=\"%s\">%s<td></tr></table>", count($dadosCabecalio) - 1, (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!'));
$this->___dataRel[] = $dataRel;
return;
}
$somaTempo = 0;
$somaReg = 0;
$somaQtde = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaTempo += $row["duracao"];
$somaQtde++;
$somaReg += $row['qtde'];
$descricao = explode(" ", $row['tplg_descricao']);
$this->___verificaTipoLigacao($descricao[1] . ' ' . $descricao[2], $row["duracao"]);
$row["tmo"] = SecondToStrTime(round($row["duracao"] / $row['qtde']));
$row["duracao"] = SecondToStrTime($row["duracao"]);
// Formata linha de dados.
$linha = "<tr>";
foreach ($dadosField as $key => $value) {
$linha .= sprintf("<td %s>%s</td>", $value, $row["$key"]);
}
$linha .= "</tr>";
$dataRel[] = $linha;
}
/*
* Linha de totalizacao.
*/
$linha = '<tr><th colspan="4" align="left">Total: %s</th><th align="center">Duração: %s</th><th align="center">TMO: %s</th><th align="center">Registros: %s</th></tr>';
$dataRel[] = sprintf($linha, $somaQtde, SecondToStrTime($somaTempo), SecondToStrTime(round($somaTempo / $somaReg)), $somaReg);
/*
* Fecha relatorio.
*/
$dataRel[] = '</table>';
$linhaTotalizador = "<table width=\"70%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" class=\"grid\">";
$linhaTotalizador .= "<tr><th colspan=\"3\" align=\"center\">Totaliza&ccedil;&atilde;o por Tipo</th></tr>";
$linhaTotalizador .= "<tr><th align=\"center\">Tipo</th><th align=\"center\">Quantidade</th><th align=\"center\">Tempo</th></tr>";
$linhaTotalizador .= sprintf("<tr><th align=\"left\" width=\"250\">Chamadas Interurbano</th><td align=\"center\">%s</td><td align=\"center\">%s</td></tr>", $this->___tiposLigacao[0]['quantidade'], SecondToStrTime($this->___tiposLigacao[0]['tempo']));
$linhaTotalizador .= sprintf("<tr><th align=\"left\">Chamadas Interurbano Móvel</th><td align=\"center\">%s</td><td align=\"center\">%s</td></tr>", $this->___tiposLigacao[3]['quantidade'], SecondToStrTime($this->___tiposLigacao[3]['tempo']));
$linhaTotalizador .= sprintf("<tr><th align=\"left\">Chamadas Local</th><td align=\"center\">%s</td><td align=\"center\">%s</td></tr>", $this->___tiposLigacao[1]['quantidade'], SecondToStrTime($this->___tiposLigacao[1]['tempo']));
$linhaTotalizador .= sprintf("<tr><th align=\"left\">Chamadas Local Móvel</th><td align=\"center\">%s</td><td align=\"center\">%s</td></tr>", $this->___tiposLigacao[2]['quantidade'], SecondToStrTime($this->___tiposLigacao[2]['tempo']));
$linhaTotalizador .= sprintf("<tr><th align=\"left\">C.I.E.I.V</th><td align=\"center\">%s</td align=\"center\"><td align=\"center\">%s</td></tr>", $this->___tiposLigacao[4]['quantidade'], SecondToStrTime($this->___tiposLigacao[4]['tempo']));
$linhaTotalizador .= sprintf("<tr><th align=\"left\">Total Chamadas DDD</th><td align=\"center\">%s</td align=\"center\"><td align=\"center\">%s</td></tr>", $this->___tiposLigacao[5]['quantidade'], SecondToStrTime($this->___tiposLigacao[5]['tempo']));
$linhaTotalizador .= "</table>";
$dataRel[] = $linhaTotalizador;
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaHtml() {
}
protected function ___PreparaPdf() {
list($this->___dac, $this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"];
/**
* TABELA DADOS PRINCIPAIS
*/
$somaQtde = 0;
$somaTempo = 0;
$somaReg = 0;
$dados = array();
$x = 0;
//HEADER DA TABELA DO PDF -> DADOS EM ARRAY
$header = array(
'DDD' => 'C',
'UF' => 'C',
'Região' => 'C',
'Tipo' => 'C',
'Duração' => 'C',
'TMO' => 'C',
'Quantidade' => 'C'
);
$dataHeader = array(
'ddd' => 'C',
'uf' => 'C',
'nome_municipio' => 'C',
'tplg_descricao' => 'C',
'duracao' => 'C',
'tmo' => 'C',
'qtde' => 'C'
);
foreach ($this->GetData()[0] as $row) {
$somaTempo += $row["duracao"];
$somaQtde++;
$somaReg += $row['qtde'];
$descricao = explode(" ", $row['tplg_descricao']);
$this->___verificaTipoLigacao($descricao[1] . ' ' . $descricao[2], $row["duracao"]);
$dados[$x]["tmo"] = SecondToStrTime(round($row["duracao"] / $row['qtde']));
$dados[$x]["duracao"] = SecondToStrTime($row["duracao"]);
$dados[$x]["ddd"] = $row["ddd"];
$dados[$x]["uf"] = $row["uf"];
$dados[$x]["nome_municipio"] = $row["nome_municipio"];
$dados[$x]["qtde"] = $row["qtde"];
$dados[$x]["tplg_descricao"] = $row["tplg_descricao"];
$x++;
}
$widthHeader = array(20, 20, 45, 30, 25, 25);
//Monta o array para passar para o prepara; Necessário passar 6 parametros
$table1 = array($header, $dataHeader, $dados, $widthHeader, 0, 0);
//Tabela do Totalizador com os Dados
$headerTotal = array(
'Tipo' => 'C',
'Quantidade' => 'C',
'Tempo' => 'C'
);
$dataHdTotal = array(
'descricao' => 'C',
'quantidade' => 'C',
'duracao' => 'C'
);
$widthTotal = array(63, 63, 63);
$table2 = array($headerTotal, $dataHdTotal, $this->___tiposLigacao, $widthTotal, 0, 0);
$this->___dataRel = array($table1, $table2);
}
/*
* Função para não ser reescrita não operações de impressões, além de varer e calcular os tipos de ligações
* compostas no totalizador!
*/
protected function ___verificaTipoLigacao($tipo, $tempo) {
switch (strtoupper($tipo)) {
case "FIXO INTERURBANO":
$this->___tiposLigacao[0]['quantidade'] ++;
$this->___tiposLigacao[0]['tempo'] += $tempo;
$this->___tiposLigacao[0]['duracao'] = SecondToStrTime($this->___tiposLigacao[0]['tempo']);
break;
case "FIXO LOCAL":
$this->___tiposLigacao[1]['quantidade'] ++;
$this->___tiposLigacao[1]['tempo'] += $tempo;
$this->___tiposLigacao[1]['duracao'] = SecondToStrTime($this->___tiposLigacao[1]['tempo']);
break;
case "MOVEL LOCAL":
$this->___tiposLigacao[2]['quantidade'] ++;
$this->___tiposLigacao[2]['tempo'] += $tempo;
$this->___tiposLigacao[2]['duracao'] = SecondToStrTime($this->___tiposLigacao[2]['tempo']);
break;
case "MOVEL INTERURBANO":
$this->___tiposLigacao[3]['quantidade'] ++;
$this->___tiposLigacao[3]['tempo'] += $tempo;
$this->___tiposLigacao[3]['duracao'] = SecondToStrTime($this->___tiposLigacao[3]['tempo']);
break;
default :
$this->___tiposLigacao[4]['quantidade'] ++;
$this->___tiposLigacao[4]['tempo'] += $tempo;
$this->___tiposLigacao[4]['duracao'] = SecondToStrTime($this->___tiposLigacao[4]['tempo']);
break;
}
$this->___tiposLigacao[5]['quantidade'] ++;
$this->___tiposLigacao[5]['tempo'] += $tempo;
$this->___tiposLigacao[5]['duracao'] = SecondToStrTime($this->___tiposLigacao[5]['tempo']);
}
public function ExecutaRelatorio() {
global $jsStartup, $jsJQuery, $smarty;
try {
/*
* Use esta fun��o para validar dados do formul�rio.
*/
$this->___ValidaForm();
/*
* Recupera os dados do banco.
*/
$this->___ConteudoRelatorio();
/*
* Imprime relat�rio de acordo com a media passada.
*/
$conteudoRelatorio = $this->___ImprimeRelatorio();
} catch (Exception $exc) {
$this->SetMsg($exc->getMessage());
$jsStartup[] = sprintf("alert('%s');", $this->GetMsg());
$this->___GravaLog();
}
/*
* Inclua os scripts necess�rios aqui.
*/
$jsJQuery[] = "\$('#dataIni').keypress(function(){formataDataHora(this);}) ";
$jsJQuery[] = "\$('#dataFim').keypress(function(){formataDataHora(this);}) ";
$smarty->assign('filtros', $this->___FiltrosRelatorio());
$smarty->assign('conteudo', $conteudoRelatorio);
$smarty->assign('msg', $this->GetMsg());
GetTemplate($smarty, 'relatoriosGrid.tpl');
}
}
$relRcbDDD = new RelRecebidasDDD($idProg, $dbcon, 1);
$relRcbDDD->ExecutaRelatorio();
/*
############################################################################
##################### BACKUP DA QUERY ANTERIOR #####################
############################################################################
$sql = "create temporary table totalizador_ddd as
select c.id as idDac,
c.nome as nomeDac,
case when(b.evento in('COMPLETEAGENT', 'COMPLETECALLER','TRANSFER'))then sonumero(a.src) else sonumero(a.dst) end as fone,
b.evento,
a.billsec,
get_prefixo_fone('$dddDef', case when(b.evento in('COMPLETEAGENT', 'COMPLETECALLER','TRANSFER'))then a.src else a.dst end) as prefixo,
cast(0 as int) as faixa
from pbx_bilhetes a, pbx_eventos_dacs b, pbx_dacs c
where b.uid2 = a.uniqueid
and c.nome = b.fila
and a.data_bilhete >= '$dataIin'
and a.data_bilhete <= '$dataFim'
and b.evento in('COMPLETEAGENT', 'COMPLETECALLER','TRANSFER', 'COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG') -- 'CONNECT'
and c.id = case when($dac = 0)then c.id else $dac end
and a.lastapp <> 'Transferred Call'
and a.id_bilhetes = (select max (l.id_bilhetes) from pbx_bilhetes l where l.uniqueid = a.uniqueid and l.lastapp <> 'Transferred Call' );
update totalizador_ddd set faixa = case when(length(fone) >= 8)then strtoint( substring(fone, '....$')) else 0 end;
select idDac,
nomeDac,
coalesce(b.codigo_ddd, case when(gettipoligacao(fone, $dddDef) in('Local Fixo','Local Móvel'))then $dddDef else 0 end) as ddd,
upper( coalesce(b.uf, case when(gettipoligacao(fone, $dddDef) in('Local Fixo','Local Móvel'))then '$ufPadrao' else 'ni' end)) as uf,
upper(coalesce(b.nome_municipio, case when(gettipoligacao(fone, $dddDef) in('Local Fixo'))then '$munDef' else gettipoligacao(fone, $dddDef) end)) as nome_municipio,
sum( case when(a.evento in('COMPLETEAGENT', 'COMPLETECALLER','TRANSFER'))then billsec else 0 end )as tempo_entrante,
sum( case when(a.evento in('COMPLETEAGENT', 'COMPLETECALLER','TRANSFER'))then 1 else 0 end )as qtde_entrante,
sum( case when(a.evento in('COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG'))then billsec else 0 end)as tempo_sainte,
sum( case when(a.evento in('COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG'))then 1 else 0 end)as qtde_sainte
from totalizador_ddd a
left join pbx_consulta_ddd b on b.prefixo = a.prefixo and b.inicial <= a.faixa and b.final >= a.faixa
where 1=1
group by 1,2,3,4,5
order by 4,5 ";
*/
?>