PABX da Simples IP
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.
 
 
 
 
 
 

484 lines
22 KiB

<?php
include_once 'util/relatoriosBase.php';
class ChamadasEntrantesGeral extends Relatorios {
private $___tipoAtendimento;
private $___tempoDuracao;
private $___telefone;
private $___tipoRecepcao;
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___tipoAtendimento = isset($_REQUEST['tipoAtendimento']) ? $_REQUEST['tipoAtendimento'] : 1;
$this->___tempoDuracao = isset($_REQUEST['tempoDuracao']) ? $_REQUEST['tempoDuracao'] : 1;
$this->___tipoRecepcao = isset($_REQUEST['tipoRecepcao']) ? $_REQUEST['tipoRecepcao'] : 1;
$this->___telefone = isset($_REQUEST['telefone']) ? $_REQUEST['telefone'] : '';
$this->___dataIni = IsPostBack() ? $_POST['dataIni'] : date('d/m/Y')." 00:00";
$this->___dataFim = IsPostBack() ? $_POST['dataFim'] : date('d/m/Y')." 23:59";
}
function ___ValidaForm() {
parent::___ValidaForm();
if (empty($this->___tipoAtendimento)) {
GeraExcept('Informe um tipo de atendimento!');
}
if (empty($this->___tempoDuracao)) {
GeraExcept('Informe um tempo de duração!');
}
if (empty($this->___tipoRecepcao)) {
GeraExcept('Informe um tipo de recepção!');
}
if ($this->___telefone) {
if (!soNumero($this->___telefone)) {
GeraExcept('Informe apenas números no campo de Telefone!');
}
}
}
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->___telefone) = $_SESSION["SSstorageFiltros"];
if ($this->___media == MEDIA_PRINT_HTML) {
return sprintf("Data Inicial: %s Data Final: %s ", $this->___dataIni, $this->___dataFim);
}
$fltCsv = array();
$fltCsv[] = "Data Inicial: " . $this->___dataIni;
$fltCsv[] = "Data Final: " . $this->___dataFim;
//$fltCsv[] = $this->___telefone ? "Telefone: " . $this->___telefone : '';
$fltCsv[] = "Data Emissao: " . date('d/m/Y H:i:s');
$fltCsv[] = "Emitido Por: " . GetLogin();
return $fltCsv;
}
$dacs = GetDac($this->GetDbCon(), $this->___dac, "", 0, 1, 0, 0, 1);
$lkPrint = "";
if ($this->___dataCount) {
$prt = '<a href="index.php?idProg=%s&media=%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', '%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, substr(LimpaString(GetDispProgSel($this->GetIdProg())), 0, 20), 'print.gif');
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_EXCEL, 'prt-xls.png');
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_PDF, 'prt-pdf.png');
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_CSV, 'prt-csv.png');
}
/*
* Personalise esta função se necessitar de outras opções de filtro.
*/
$filtro = '<table class="filtro" border="0" cellspacing="1" cellpadding="1">';
/*
* Rotulos.
*/
$filtro .= '<tr>';
$filtro .= '<td>&nbsp</td>';
$filtro .= '<td>Fila</td>';
$filtro .= '<td>Data Inicial </td>';
$filtro .= '<td>Data Final </td>';
$filtro .= '<td>Duração</td>';
$filtro .= '<td>Tipo Atendimento</td>';
$filtro .= '<td>';
$filtro .= sprintf('<input name="tipoRecepcao" class="clean" type="radio" value="1" %s>Origem'
. '<input type="radio" class="clean" name="tipoRecepcao" value="2" %s>Destino'
. '<input type="radio" class="clean" name="tipoRecepcao" value="3" %s>Ambos'
. '</td>', $this->___tipoRecepcao == 1 ? 'checked' : '', $this->___tipoRecepcao == 2 ? 'checked' : '', $this->___tipoRecepcao == 3 ? 'checked' : '');
$filtro .= '<td align="center" valign="middle">&nbsp;</td>';
$filtro .= '</tr>';
/*
* Valores.
*/
$filtro .= '<tr>';
$filtro .= '<td>&nbsp;</td>';
$filtro .= sprintf('<td>%s</td>', $dacs);
$filtro .= '<td><input name="dataIni" id="dataIni" type="text" size="15" maxlength="16" value="%s" onkeyup="formataDataHora(this)" title="dd/mm/aaaa HH:mm"></td>';
$filtro .= '<td><input name="dataFim" id="dataFim" type="text" size="15" maxlength="16" value="%s" onkeyup="formataDataHora(this)" title="dd/mm/aaaa HH:mm"></td>';
$filtro .= '<td><div class="geral"> ';
$filtro .= sprintf('<input name="tempoDuracao" class="clean" type="radio" id="tempoDuracao" value="1" %s>Todos'
. '<input name="tempoDuracao" class="clean" type="radio" id="tempoDuracao" value="2" %s>maior que(&gt;0)'
. '<input name="tempoDuracao" class="clean" type="radio" id="tempoDuracao" value="3" %s>Igual a 0 (= 0)', $this->___tempoDuracao == 1 ? 'checked' : '', $this->___tempoDuracao == 2 ? 'checked' : '', $this->___tempoDuracao == 3 ? 'checked' : '');
$filtro .= '</div></td>';
$filtro .= sprintf('<td><div class="geral"> '
. '<input name="tipoAtendimento" class="clean" type="radio" id="tipoAtendimento" value="1" %s>Ambos'
. '<input name="tipoAtendimento" class="clean" type="radio" id="tipoAtendimento" value="2" %s>Atendida'
. '<input name="tipoAtendimento" class="clean" type="radio" id="tipoAtendimento" value="3" %s>Não Atendida'
. '</div></td>', $this->___tipoAtendimento == 1 ? 'checked' : '', $this->___tipoAtendimento == 2 ? 'checked' : '', $this->___tipoAtendimento == 3 ? 'checked' : '');
$filtro .= '<td><input name="telefone" type="text" id="telefone" value="%s" /></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?ios para impress�o.
*/
$_SESSION["SSstorageFiltros"] = array($this->___dataIni, $this->___dataFim, $this->___telefone);
return sprintf($filtro, $this->___dataIni, $this->___dataFim, $this->___telefone, $lkPrint);
}
protected function ___GetDadosDb() {
$dataIni = strlen($this->___dataIni) == 10 ? FormatDtMssql($this->___dataIni) . " 00:00": FormatDtMssql(substr($this->___dataIni, 0, 10)). substr($this->___dataIni, 10, 16);
$dataFim = strlen($this->___dataFim) == 10 ? FormatDtMssql($this->___dataFim) . " 23:59": FormatDtMssql(substr($this->___dataFim, 0, 10)). substr($this->___dataFim, 10, 16);
$telefone = $this->___telefone;
$duracao = $this->___tempoDuracao;
$tipoAtendimento = $this->___tipoAtendimento;
$fonePesquisa = $this->___tipoRecepcao;
$query = sprintf("SELECT a.uniqueid, a.calldate, a.src, a.dst,
CASE WHEN(d.evento = 'ABANDON')THEN strtoint(d.param3) ELSE a.billsec END AS tempo_atendimento, COALESCE(d.fila, '-') AS fila, coalesce(e.apelido, '-') AS agente,
d.evento, CASE WHEN(tplg_codigo IN(23,24))THEN 'MÓVEL' ELSE c.nome_municipio END AS nome_municipio, c.uf, b.tplg_descricao,
CASE WHEN((d.evento IN('COMPLETEAGENT','COMPLETECALLER') AND (strtoint(d.param2) > 3) ) OR ((d.evento is null) AND (billsec > 3)))THEN 'ATENDIDA' ELSE 'N ATENDIDA' END AS status
FROM pbx_bilhetes a
INNER JOIN pbx_tipo_ligacao b ON b.tplg_codigo = a.tipo_chamada
LEFT JOIN pbx_municipios c ON c.id = a.id_municipio
LEFT JOIN pbx_eventos_dacs d ON d.uid2 = a.uniqueid AND d.evento IN('COMPLETEAGENT','COMPLETECALLER','ABANDON')
LEFT JOIN pbx_usuarios e ON e.matricula = SUBSTRING(d.agente,7,4)
LEFT JOIN pbx_queues_grupos f ON f.nome = d.fila
WHERE b.tplg_tipo = 2
AND a.calldate::timestamp >= '%s'
AND a.calldate::timestamp <= '%s'
AND a.lastapp <> 'Transferred Call' ", $dataIni, $dataFim);
$query .= $this->___dac ? " AND f.id = '{$this->___dac}' " : '';
if (!empty($telefone) && ($fonePesquisa == 1))
$query .= sprintf(" AND a.src LIKE '%s' ", PreparaLike($telefone));
else if (!empty($telefone) && ($fonePesquisa == 2))
$query .= sprintf(" AND a.dst LIKE '%s' ", PreparaLike($telefone));
else if (!empty($telefone) && ($fonePesquisa == 3))
$query .= sprintf(" AND (a.dst LIKE '%s' OR src LIKE '%s') ", PreparaLike($telefone), PreparaLike($telefone));
if ($duracao == 2) {
$query .= " AND a.billsec > 0 ";
}
if ($duracao == 3) {
$query .= " AND a.billsec = 0 ";
}
if ($tipoAtendimento == 2) {
$query .= "AND ((d.evento IN('COMPLETEAGENT','COMPLETECALLER') AND (billsec > 3) ) OR ((d.evento is null) AND (billsec > 3)))";
}
if ($tipoAtendimento == 3) {
$query .= "AND ((d.evento NOT IN('COMPLETEAGENT','COMPLETECALLER')) OR (billsec <= 3))";
}
$query .= " ORDER BY a.calldate";
$result = $this->___GetQuery($query);
$row = pg_fetch_all($result);
$this->SetData($row ? $row : array());
}
protected function ___PreparaCsv() {
$nomeDac = "";
$dataRel = array();
$dataAgrup = array();
$filtro = $this->___FiltrosRelatorio();
$dataRel[] = GenerateCsvFromArray($filtro);
$dadosCabecalio = array('Data/Hora', 'Origem', 'Destino', 'Tipo', 'Duracao', 'Atendida', 'Fila', 'Agente', 'Municipio', 'UF');
$dadosField = array('calldate', 'src', 'dst', 'tplg_descricao', 'tempo_atendimento', 'status', 'fila', 'agente', 'nome_municipio', 'uf');
$dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio));
$somaTempo = 0;
$somaQuantidade = 0;
/*
* Inicia o relat�rio.
*/
foreach ($this->GetData()[0] as $row) {
$row['src'] = ocultarTelefone($row['src']);
$row["calldate"] = date('d/m/Y H:i', strtotime($row["calldate"]));
$row["tplg_descricao"] = str_replace("Entrada", "", $row["tplg_descricao"]);
$row["status"] = $row["status"] == 'ATENDIDA' ? 'S' : 'N';
$somaTempo += $row["tempo_atendimento"];
$row["tempo_atendimento"] = SecondToStrTime($row["tempo_atendimento"]);
$row["nome_municipio"] = $row['nome_municipio'] == "CHAMADAS NAO IDENTIFICADAS" ? 'NI' : RemoveAcentos($row['nome_municipio']);
$somaQuantidade ++;
$linha = array();
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
$linha = array('Total', '', '', 'Registros: '.$somaQuantidade, 'Duracao: '.SecondToStrTime($somaTempo));
$dataRel[] = GenerateCsvFromArray($linha);
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaExcel() {
//list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"];
$dataRel = array();
$dataAgrup = 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('Data/Hora', 'Origem', 'Destino', 'Tipo', 'Duracao', 'Atendida', 'Fila', 'Agente', 'Municipio', 'UF');
$dadosField = array('calldate', 'src', 'dst', 'tplg_descricao', 'tempo_atendimento', 'status', 'fila', 'agente', 'nome_municipio', 'uf');
/*
* Monta a linha de cabecalio.
*/
$linha = array('LABEL');
foreach ($dadosCabecalio as $value) {
$linha[] = $value;
}
$dataRel[] = $linha;
$somaTempo = 0;
$somaQuantidade = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$row['src'] = ocultarTelefone($row['src']);
$row["calldate"] = date('d/m/Y H:i', strtotime($row["calldate"]));
$row["tplg_descricao"] = str_replace("Entrada", "", $row["tplg_descricao"]);
$row["status"] = $row["status"] == 'ATENDIDA' ? 'S' : 'N';
$somaTempo += $row["tempo_atendimento"];
$row["tempo_atendimento"] = SecondToStrTime($row["tempo_atendimento"]);
$row["nome_municipio"] = $row['nome_municipio'] == "CHAMADAS NAO IDENTIFICADAS" ? 'NI' : RemoveAcentos($row['nome_municipio']);
$somaQuantidade ++;
// Formata linha de dados.
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
$linha = array('LABEL', 'Total', '', '', 'Registros: '.$somaQuantidade, 'Duracao: '.SecondToStrTime($somaTempo));
$dataRel[] = $linha;
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaGrid() {
$dadosCabecalio = array(
'Data/Hora' => 'align="center"',
'Origem' => 'align="left"',
'Destino' => 'align="left"',
'Tipo' => 'align="left"',
'Duração' => 'align="center"',
'Atendida' => 'align="center"',
'Fila' => 'align="left"',
'Agente' => 'align="left"',
'Município' => 'align="left"',
'UF' => 'align="center"'
);
$dadosField = array(
'calldate' => 'align="center"',
'src' => 'align="left"',
'dst' => 'align="left"',
'tplg_descricao' => 'align="left"',
'tempo_atendimento' => 'align="center"',
'status' => 'align="center"',
'fila' => 'align="left"',
'agente' => 'align="left"',
'nome_municipio' => 'align="left"',
'uf' => 'align="center"'
);
/*
* Inicia o relat�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;
}
$somaTempo = 0;
$somaQuantidade = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$row['src'] = ocultarTelefone($row['src']);
$row["calldate"] = date('d/m/Y H:i', strtotime($row["calldate"]));
$row["tplg_descricao"] = str_replace("Fixo Entrada", "", $row["tplg_descricao"]);
$row["status"] = $row["status"] == 'ATENDIDA' ? 'S' : 'N';
$somaTempo += $row["tempo_atendimento"];
$row["tempo_atendimento"] = SecondToStrTime($row["tempo_atendimento"]);
$somaQuantidade ++;
// 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="2" align="left">Total</th><th align="left" colspan="2">Registros: %s</th><th align="left" colspan="6">Duração: %s</th></tr>';
$dataRel[] = sprintf($linha, $somaQuantidade, SecondToStrTime($somaTempo));
/*
* Fecha relatorio.
*/
$dataRel[] = '</table>';
$dataRel[] = '<table width="50%">';
$dataRel[] = '<tr><td><b>* CHAMADAS ABANDONADAS OU NÃO ATENDIDAS, NO CAMPO DESTINO SERÁ APRESENTADO O NÚMERO DA FILA!</b></td></tr>';
$dataRel[] = '</table>';
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaHtml() {
}
protected function ___PreparaPdf() {
list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"];
$dados = array();
$x = 0;
$somaQtd = 0;
$somaTempo = 0;
foreach ($this->GetData()[0] as $row) {
$dados[$x]["calldate"] = date('d/m/Y H', strtotime($row["calldate"]));
$dados[$x]["src"] = ocultarTelefone($row['src']);
$dados[$x]["dst"] = $row["dst"];
$dados[$x]["tplg_descricao"] = str_replace('Entrada', '', $row["tplg_descricao"]);
$somaTempo += $row["tempo_atendimento"];
$dados[$x]["tempo_atendimento"] = SecondToStrTime($row["tempo_atendimento"]);
$dados[$x]["status"] = $row["status"] == 'ATENDIDA' ? 'S' : 'N';
$dados[$x]["fila"] = $row["fila"];
$dados[$x]["agente"] = $row["agente"];
$dados[$x]["nome_municipio"] = $row['nome_municipio'] == "CHAMADAS NAO IDENTIFICADAS" ? 'NI' : $row['nome_municipio'];
$dados[$x]["uf"] = $row['uf'];
$somaQtd ++;
$x++;
}
//HEADER DA TABELA DO PDF -> DADOS EM ARRAY
$header = array(
'Data/Hora' => 'C',
'Origem' => 'L',
'Destino' => 'L',
'Tipo' => 'L',
'Duração' => 'C',
'Atend.' => 'C',
'Fila' => 'L',
'Agente' => 'L',
'Município' => 'L',
'UF' => 'C');
$dataHeader = array(
'calldate' => 'C',
'src' => 'L',
'dst' => 'L',
'tplg_descricao' => 'L',
'tempo_atendimento' => 'C',
'status' => 'C',
'fila' => 'L',
'agente' => 'L',
'nome_municipio' => 'L',
'uf' => 'C'
);
$widthHeader = array(20, 25, 15, 25, 15, 10, 20, 20, 30, 10);
$totaliza = array('Total', "Registros: " , $somaQtd, 'Duração:', SecondToStrTime($somaTempo), '', '', '', '', '');
//Monta o array para passar para o prepara; Necessário passar 6 parametros
$table1 = array($header, $dataHeader, $dados, $widthHeader, $totaliza, 0);
$this->___dataRel = array($table1);
}
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');
}
}
$relChmEntG = new ChamadasEntrantesGeral($idProg, $dbcon, 0);
$relChmEntG->ExecutaRelatorio();
?>