<?php
include_once 'util/relatoriosBase.php';
class RelClassificacaoDetalhes extends Relatorios {
private $___classificacao;
private $___classItem;
private $___agente;
private $___servico;
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0;
$this->___classificacao = isset($_POST['listaClas']) ? $_POST['listaClas'] : 0;
$this->___classItem = isset($_POST['listaItem']) ? $_POST['listaItem'] : 0;
$this->___agente = isset($_POST["listaAgente"]) ? $_POST["listaAgente"] : null;
$this->___servico = isset($_POST["listaServico"]) ? $_POST["listaServico"] : 0;
}
function ___FiltrosRelatorio() {
if ($this->___media != MEDIA_PRINT_GRID) {
/*
* Recupera os filtros da sess<EFBFBD> o do usu<EFBFBD> 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<EFBFBD> tico' : 'Sint<EFBFBD> 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"';
if ($this->___dataIni & & $this->___dataFim) {
$agentes = $this->retornaAgente();
}
/*
* Personalise esta fun<EFBFBD> <EFBFBD> o se necessitar de outras opera<EFBFBD> <EFBFBD> es de filtro.
*/
$filtro = '< table border = "0" cellspacing = "1" cellpadding = "1" > ';
/*
* Rotulos.
*/
$filtro .= '< tr > ';
$filtro .= $this->GetIncDac() ? '< td > Fila< / td > ' : '';
$filtro .= GetUsoServico() ? '< td > Servi<EFBFBD> o< / td > ' : '';
$filtro .= '< td > Data Inicial< / td > ';
$filtro .= '< td > Data Final < / td > ';
$filtro .= '< td > Agente < / td > ';
$filtro .= '< td > Classifica<EFBFBD> <EFBFBD> o < / td > ';
$filtro .= '< td > Classifica<EFBFBD> <EFBFBD> o Item < / td > ';
$filtro .= '< td align = "center" valign = "middle" > < / td > ';
$filtro .= '< / tr > ';
/*
* Valores.
*/
global $dbcon;
$filtro .= '< tr > ';
$filtro .= $this->GetIncDac() ? sprintf('< td > %s< / td > ', $dacs) : '';
if (GetUsoServico()) {
$filtro .= sprintf('< td > %s< / td > ', GetIdentRota(false, $this->___servico));
}
$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 > $agentes< / td > ";
$filtro .= sprintf('< td > %s< / td > ', GetClassificacao($dbcon, $this->___classificacao, $this->___dac));
$filtro .= sprintf('< td > %s< / td > ', GetItem($dbcon, $this->___classificacao, $this->___classItem));
$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<EFBFBD> o dos relat<EFBFBD> rios para impress<EFBFBD> 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;
$classificacao = $this->___classificacao;
$classificaItem = $this->___classItem;
$agente = $this->___agente ? $this->___agente : 0;
$srv = $this->___servico;
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
$query = "SELECT " . ( $mostraColunaServicos ? "coalesce(s.serv_id, 'N<EFBFBD> o Informado') as serv_id," : "" ) . " calldate, apelido, src AS origem, dst AS destino, f.nome, clas_descricao, clit_descricao,tplg_descricao,
CASE WHEN (g.conf_uid < > '' AND g.conf_discado = 1) THEN 'S' ELSE 'N' END AS discador
FROM pbx_bilhetes a
INNER JOIN pbx_tipo_ligacao h ON h.tplg_codigo = a.tipo_chamada
INNER JOIN pbx_classifica_reg b ON a.uniqueid = b.id_bilhetes AND a.calldate = (SELECT MAX(calldate) FROM pbx_bilhetes WHERE uniqueid = b.id_bilhetes)
INNER JOIN pbx_classifica_atendimento c ON c.clas_id = b.clas_id
INNER JOIN pbx_classifica_item d ON d.clit_id = b.clit_id
INNER JOIN pbx_usuarios e ON e.matricula = b.matricula
INNER JOIN pbx_dacs f ON f.id = b.id_dac ";
if (GetUsoServico()) {
$query .= "\nleft join pbx_servicos_registra s on s.uniqueid = a.uniqueid ";
}
$query .= "\n LEFT JOIN pbx_campanha_contato_fone g ON a.uniqueid = g.conf_uid
WHERE data_bilhete >= '%s' AND data_bilhete < = '%s'
AND a.lastapp < > 'Transferred Call'
AND b.id_dac = %s";
if ($classificacao) {
$query .= "AND b.clas_id = $classificacao";
}
if ($classificaItem) {
$query .= "AND b.clit_id = $classificaItem";
}
if ($agente) {
$query .= "AND apelido = '$agente'";
}
if (GetUsoServico() & & $srv) {
$query .= "\nand s.serv_id = '{$srv}'";
}
$query .= $mostraColunaServicos ? "ORDER BY s.serv_id, calldate" : "ORDER BY calldate";
$query = sprintf($query, $dataIni, $dataFim, $dac);
$subQuery = "SELECT count(1) as chmd FROM pbx_bilhetes a
INNER JOIN pbx_eventos_dacs b ON b.uid2 = a.uniqueid AND b.evento in('COMPLETEAGENT','COMPLETECALLER', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL','BUSY','NOANSWER', 'COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG','BUSYS','NOANSWERS')
INNER JOIN pbx_usuarios c ON c.matricula = substring(b.agente, 7, 4)
INNER JOIN pbx_dacs d ON d.nome = b.fila";
if (GetUsoServico()) {
$subQuery .= "\nleft join pbx_servicos_registra s on s.uniqueid = a.uniqueid ";
}
$subQuery .= "\nWHERE data_bilhete >= '%s' AND data_bilhete < = '%s'
AND d.id = %s
AND a.lastapp < > 'Transferred Call'";
if (GetUsoServico() & & $srv) {
$subQuery .= "\nand s.serv_id = '{$srv}'";
}
$subQuery = sprintf($subQuery, $dataIni, $dataFim, $dac);
$result = $this->___GetQuery($query);
$row = pg_fetch_all($result);
$this->SetData($row ? $row : array());
$subResult = $this->___GetQuery($subQuery);
$subRow = pg_fetch_assoc($subResult);
$this->SetData($subRow ? $subRow : array());
$this->SetData($this->___agente ? $this->___agente : 0);
}
protected function ___PreparaCsv() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
/*
* Inicia o relat<EFBFBD> rio.
*/
$dataRel[] = GenerateCsvFromArray($filtro);
$dadosCabecalio = array(
'Data/Hora',
'Origem',
'Agente',
'Classificacao',
'Item',
'Tipo',
'Discador',
);
$dadosField = array(
'calldate',
'origem',
'apelido',
'clas_descricao',
'clit_descricao',
'tplg_descricao',
'discador',
);
if (GetUsoServico() == RELATORIO_SERVICOS_HABILITA) {
$dadosCabecalio = array_merge(['Servico'], $dadosCabecalio);
$dadosField = array_merge(['serv_id'], $dadosField);
}
/*
* Monta a linha de cabecalio.
*/
$dataRel[] = GenerateCsvFromArray($dadosCabecalio);
$somaReg = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaReg ++;
$row['clit_descricao'] = RemoveAcentos($row['clit_descricao']);
$row['clas_descricao'] = RemoveAcentos($row['clas_descricao']);
$row['tplg_descricao'] = explode(' ', $row['tplg_descricao'])[0];
$row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate']));
// Formata linha de dados.
$linha = array();
foreach ($dadosField as $value) {
$linha[] = $row["$value"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
$dataRel[] = GenerateCsvFromArray(array('Total Chamadas: ' . $this->GetData()[1]['chmd'], '', '', '', 'Registros: ' . $somaReg));
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaExcel() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
/*
* Inicia o relat<EFBFBD> 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(
'Data/Hora',
'Origem',
'Agente',
'Classificacao',
'Item',
'Tipo',
'Discador'
);
$dadosField = array(
'calldate',
'origem',
'apelido',
'clas_descricao',
'clit_descricao',
'tplg_descricao',
'discador'
);
if (GetUsoServico() == RELATORIO_SERVICOS_HABILITA) {
$dadosCabecalio = array_merge(['Servico'], $dadosCabecalio);
$dadosField = array_merge(['serv_id'], $dadosField);
}
/*
* Monta a linha de cabecalio.
*/
$linha = array('LABEL');
foreach ($dadosCabecalio as $value) {
$linha[] = $value;
}
$dataRel[] = $linha;
$somaChmTotal = 0;
foreach ($this->GetData()[0] as $row) {
$somaChmTotal += $row['chmd'];
}
$somaReg = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaReg ++;
$row['clit_descricao'] = RemoveAcentos($row['clit_descricao']);
$row['clas_descricao'] = RemoveAcentos($row['clas_descricao']);
$row['tplg_descricao'] = explode(' ', $row['tplg_descricao'])[0];
$row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate']));
// Formata linha de dados.
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
$dataRel[] = array('LABEL', 'Total Chamadas: ' . $this->GetData()[1]['chmd'], '', '', '', 'Registros: ' . $somaReg);
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaGrid() {
$dataRel = array();
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
$dadosCabecalio = array(
'Data/Hora' => 'align="center"',
'Origem' => 'align="left"',
'Agente' => 'align="left"',
'Classifica<EFBFBD> <EFBFBD> o' => 'align="left"',
'Item' => 'align="center"',
'Tipo' => 'align="center"',
'Discador' => 'align="Center"',
);
$dadosField = array(
'calldate' => 'align="center"',
'origem' => 'align="left"',
'apelido' => 'align="left"',
'clas_descricao' => 'align="left"',
'clit_descricao' => 'align="center"',
'tplg_descricao' => 'align="center"',
'discador' => 'align="Center"'
);
if ($mostraColunaServicos) {
$dadosCabecalio = array_merge(['Servi<EFBFBD> o' => 'align="center"'], $dadosCabecalio);
$dadosField = array_merge(['serv_id' => 'align="left"'], $dadosField);
}
/*
* Inicia o relat<EFBFBD> rio.
*/
$dataRel[] = '< table width = "90%" 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;
}
$somaReg = 0;
$somaServico = 0;
$srv = '';
$oldSrv = '';
$agrupaServico = function($row) use(& $somaServico, & $dataRel, & $srv, & $oldSrv) {
$style = 'style="font-weight: bold; padding: 0; margin: 0; padding-left: 6px; padding-right: 6px; background-color: #4F71C0 !important"';
$srv = $row["serv_id"];
if (!$oldSrv) {
$oldSrv = $srv;
}
if ((($srv != $oldSrv)) || !$row) {
$dataRel[] = sprintf("< tr > < th colspan = \"7\" align = \"center\" { $ style } > Total [%s] < / th > < th colspan = \"1\" align = \"right\" { $ style } > %s< / th > < / tr > ", $oldSrv, $somaServico);
$oldSrv = $srv;
$somaServico = 0;
}
$somaServico++;
};
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
if ($mostraColunaServicos) {
$agrupaServico($row);
}
$somaReg ++;
$row["calldate"] = date('d/m/Y H:i:s', strtotime($row["calldate"]));
$row['tplg_descricao'] = explode(' ', $row['tplg_descricao'])[0];
$row['origem'] = ocultarTelefone($row['origem']);
// 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.
*/
$colspan = 5;
if ($mostraColunaServicos) {
$agrupaServico(false);
$colspan = 6;
}
$linha = '< tr > < th colspan = "' .$colspan . '" align = "left" > Total [ Chamadas Periodo ]: %s< / th > < th colspan = "2" align = "right" > Registros: %s< / th > < / tr > ';
$dataRel[] = sprintf($linha, $this->GetData()[1]['chmd'], $somaReg);
/*
* Fecha relatorio.
*/
$dataRel[] = '< / table > ';
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaHtml() {
}
protected function ___PreparaPdf() {
list($this->___dac, $this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"];
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
/**
* TABELA DADOS PRINCIPAIS
*/
//HEADER DA TABELA DO PDF -> DADOS EM ARRAY
$dadosCabecalio = array(
'Data/Hora' => 'C',
'Origem' => 'C',
'Agente' => 'C',
'Classifica<EFBFBD> <EFBFBD> o' => 'C',
'Item' => 'C',
'Tipo' => 'C',
'Discador' => 'C',
);
$dadosField = array(
'calldate' => 'C',
'origem' => 'C',
'apelido' => 'C',
'clas_descricao' => 'C',
'clit_descricao' => 'C',
'tplg_descricao' => 'C',
'discador' => 'C',
);
if ($mostraColunaServicos) {
$dadosCabecalio = array_merge(['Servi<EFBFBD> o' => 'C'], $dadosCabecalio);
$dadosField = array_merge(['serv_id' => 'C'], $dadosField);
}
$somaReg = 0;
$somaServico = 0;
$srv = '';
$oldSrv = '';
$dadosTable = [];
$agrupaServico = function($row) use(& $somaServico, & $dadosTable, & $srv, & $oldSrv) {
$style = 'style="font-weight: bold; padding: 0; margin: 0; padding-left: 6px; padding-right: 6px; background-color: #4F71C0 !important"';
$srv = $row["serv_id"];
if (!$oldSrv) {
$oldSrv = $srv;
}
if ((($srv != $oldSrv)) || !$row) {
$perc = !$somaChmTotal ? 0 : (($somaServico / $somaChmTotal) * 100.0);
$data = [];
$data['serv_id'] = "TOTAL[$oldSrv]";
$data['calldate'] = ' ';
$data['origem'] = ' ';
$data['apelido'] = ' ';
$data['clas_descricao'] = ' ';
$data['clit_descricao'] = ' ';
$data['tplg_descricao'] = ' ';
$data['discador'] = $somaServico;
$data['cor_linha_dados'] = 225;
$dadosTable[] = $data;
$oldSrv = $srv;
$oldSrv = $srv;
$somaServico = 0;
}
$somaServico ++;
};
foreach ($this->GetData()[0] as $row) {
if ($mostraColunaServicos) {
$agrupaServico($row);
}
$somaReg ++;
$row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate']));
$row['tplg_descricao'] = explode(' ', $row['tplg_descricao'])[0];
$dadosTable[] = $row;
}
if ($mostraColunaServicos) {
$agrupaServico(false);
$widthHeader = array(30, 20, 15, 30, 30, 30, 20, 15);
$totalizador = array('Total Chamadas: ' . $this->GetData()[1]['chmd'], '', '','', '', 'Registros: ' . $somaReg, '', '',);
} else {
$widthHeader = array(30, 15, 30, 40, 40, 20, 15);
$totalizador = array('Total Chamadas: ' . $this->GetData()[1]['chmd'], '', '', '', 'Registros: ' . $somaReg, '', '',);
}
//Monta o array para passar para o prepara; Necess<EFBFBD> rio passar 6 parametros
$table = array($dadosCabecalio, $dadosField, $dadosTable, $widthHeader, $totalizador, 0);
$this->___dataRel = array($table);
}
protected function retornaAgente() {
global $dbcon;
$codSel = $this->GetData()[2] ? $this->GetData()[2] : '';
$agentes = "< select name = \"listaAgente\" id = \"listaAgente\" size = \"1\" > ";
$agentes .= "< option value = \"0\" $ sel > Todos< / option > ";
$query = sprintf("SELECT apelido AS nome
FROM pbx_usuarios u
WHERE EXISTS(SELECT '' FROM pbx_eventos_agentes WHERE id_dac = %s
AND matricula = u.matricula
AND CAST(login as date) >= '%s'
AND CAST(login as date) < = '%s')
", $this->___dac, FormatDtMssql($this->___dataIni), FormatDtMssql($this->___dataFim));
$result = pg_query($dbcon, $query);
if(!$result) {
return '< select name = \"listaAgente\" > < option value = \"0\" > ----- < / option > < / select > ';
}
while ($dados = pg_fetch_row($result)) {
if ($codSel == $dados[0]) {
$sel = "selected";
$i = 1;
} else {
$sel = "";
}
$agentes .= "< option value = \"$dados[0]\" $ sel > $dados[0]< / option > ";
}
$agentes .= "< / select > ";
return $agentes;
}
public function ExecutaRelatorio() {
global $jsStartup, $jsJQuery, $smarty;
try {
/*
* Use esta fun<EFBFBD> <EFBFBD> o para validar dados do formul<EFBFBD> rio.
*/
$this->___ValidaForm();
/*
* Recupera os dados do banco.
*/
$this->___ConteudoRelatorio();
/*
* Imprime relat<EFBFBD> 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<EFBFBD> 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');
}
}
$relClassDetalhes = new RelClassificacaoDetalhes($idProg, $dbcon, 1);
$relClassDetalhes->ExecutaRelatorio();
/*
* *************************************************************************
* BACKUP DAS QUERYS ANTIGAS
* *************************************************************************
$query = "select distinct c.matricula, c.apelido as nome
from pbx_classifica_reg a, pbx_bilhetes b, pbx_usuarios c
where b.uniqueid = a.id_bilhetes
and c.matricula = a.matricula
and b.lastapp < > 'Transferred Call'
and a.id_dac = $idDac
and b.data_bilhete >= '$dataInicial'
and b.data_bilhete < = '$dataFinal'
order by 2
";
if ($total) {
$query = "select count(1) as chmd
from pbx_bilhetes d, pbx_eventos_dacs e, pbx_usuarios f, pbx_dacs a
where e.uid2 = d.uniqueid
and e.evento in('COMPLETEAGENT','COMPLETECALLER', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL','BUSY','NOANSWER', 'COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG','BUSYS','NOANSWERS')
and a.nome = e.fila
and f.matricula = substring(e.agente, 7, 4)
and d.lastapp < > 'Transferred Call'
and coalesce(a.id, 0) = case when($dac > 0)then $dac else coalesce(a.id, 0) end
and b.data_bilhete >= '$dataInicial'
and b.data_bilhete < = '$dataFinal'
";
} else {
$query .= "from pbx_classifica_reg a, pbx_classifica_atendimento b, pbx_classifica_item c,
pbx_bilhetes d, pbx_usuarios e, pbx_dacs f
where b.clas_id = a.clas_id
and c.clit_id = a.clit_id
and d.uniqueid = a.id_bilhetes
and e.matricula = a.matricula
and f.id = a.id_dac
and d.lastapp < > 'Transferred Call'
and coalesce(a.id_dac, 0) = case when($dac > 0)then $dac else coalesce(a.id_dac, 0) end
and b.data_bilhete >= '$dataInicial'
and b.data_bilhete < = '$dataFinal'";
}
*/
?>