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.
473 lines
19 KiB
473 lines
19 KiB
<?php |
|
|
|
include_once 'util/relatoriosBase.php'; |
|
|
|
class SaintesMaisDiscados extends Relatorios { |
|
|
|
private $___tempoDuracao; |
|
|
|
public function __construct($idProg, $dbcon, $incDac) { |
|
parent::__construct($idProg, $dbcon, $incDac); |
|
$this->___tempoDuracao = isset($_POST["tempoDuracao"]) ? $_POST["tempoDuracao"] : 1; |
|
$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 (!IsPostBack()) { |
|
return; |
|
} |
|
|
|
if (!$this->___tempoDuracao) { |
|
GeraExcept('Informe um tempo de duração!'); |
|
} |
|
} |
|
|
|
function ___FiltrosRelatorio() { |
|
global $dbcon; |
|
if ($this->___media != MEDIA_PRINT_GRID) { |
|
/* |
|
* Recupera os filtros da sess�o do usu�rio. |
|
*/ |
|
list($this->___dataIni, $this->___dataFim, $this->___tempoDuracao) = $_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[] = "Data Emissao: " . date('d/m/Y H:i:s'); |
|
$fltCsv[] = "Emitido Por: " . GetLogin(); |
|
return $fltCsv; |
|
} |
|
|
|
$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> </td>'; |
|
$filtro .= '<td>Data Inicial </td>'; |
|
$filtro .= '<td>Data Final </td>'; |
|
$filtro .= '<td>Duração</td>'; |
|
$filtro .= '<td align="center" valign="middle"> </td>'; |
|
$filtro .= '</tr>'; |
|
|
|
/* |
|
* Valores. |
|
*/ |
|
$filtro .= '<tr>'; |
|
$filtro .= '<td> </td>'; |
|
$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(>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 .= '<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); |
|
|
|
return sprintf($filtro, $this->___dataIni, $this->___dataFim, $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); |
|
$duracao = $this->___tempoDuracao; |
|
|
|
$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, |
|
d.evento, |
|
b.tplg_descricao |
|
FROM pbx_bilhetes a |
|
INNER JOIN pbx_tipo_ligacao b ON b.tplg_codigo = a.tipo_chamada |
|
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) |
|
WHERE b.tplg_tipo = 3 |
|
AND a.calldate::timestamp >= '%s' |
|
AND a.calldate::timestamp <= '%s' |
|
AND a.lastapp <> 'Transferred Call'", $dataIni, $dataFim); |
|
if ($duracao == 2) |
|
$query .= " AND a.billsec > 0 "; |
|
if ($duracao == 3) |
|
$query .= " AND a.billsec = 0 "; |
|
$query .= "ORDER BY a.src"; |
|
|
|
$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( |
|
'Ramal' => 'align="center"', |
|
'Destino' => 'align="center"', |
|
'Quantidade' => 'align="right"', |
|
'Duracao' => 'align="right"' |
|
); |
|
$dadosField = array( |
|
'ramal' => 'align="center"', |
|
'dst' => 'align="center"', |
|
'quantidade' => 'align="right"', |
|
'duracao' => 'align="right"' |
|
); |
|
|
|
$dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio)); |
|
|
|
$somaTempo = 0; |
|
$somaQuantidade = 0; |
|
|
|
/* |
|
* Inicia o relat�rio. |
|
*/ |
|
$dadosDiscTotal = array(); |
|
$x = 1; |
|
foreach ($this->GetData()[0] as $row) { |
|
$chave = null; |
|
|
|
foreach ($dadosDiscTotal as $key => $value) { |
|
if ($value['ramal'] == $row['src'] && $value['dst'] == $row['dst']) { |
|
$chave = $key; |
|
} |
|
} |
|
|
|
if ($chave) { |
|
$dadosDiscTotal[$chave]['quantidade'] ++; |
|
$dadosDiscTotal[$chave]['duracao'] += $row['tempo_atendimento']; |
|
} else { |
|
$dadosDiscTotal[$x]['ramal'] = $row['src']; |
|
$dadosDiscTotal[$x]['dst'] = $row['dst']; |
|
$dadosDiscTotal[$x]['quantidade'] ++; |
|
$dadosDiscTotal[$x]['duracao'] += $row['tempo_atendimento']; |
|
$x++; |
|
} |
|
|
|
$somaTempo += $row["tempo_atendimento"]; |
|
$somaQuantidade ++; |
|
} |
|
|
|
foreach ($dadosDiscTotal as $row) { |
|
$linha = array(); |
|
foreach ($dadosField as $key => $value) { |
|
$linha[] = $key == "duracao" ? SecondToStrTime($row["$key"]) : $row["$key"]; |
|
} |
|
$dataRel[] = GenerateCsvFromArray($linha); |
|
} |
|
|
|
$dataRel[] = $linha; |
|
|
|
$linha1 = array('Total: ' . count($dadosDiscTotal), '', 'Registros: ' . $somaQuantidade, 'Duracao: ' . SecondToStrTime($somaTempo)); |
|
$dataRel[] = GenerateCsvFromArray($linha1); |
|
$dataRel[] = $linha1; |
|
|
|
$this->___dataRel[] = $dataRel; |
|
} |
|
|
|
protected function ___PreparaExcel() { |
|
$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('Ramal', 'Destino', 'Quantidade', 'Duracao'); |
|
$dadosField = array('ramal', 'dst', 'quantidade', 'duracao'); |
|
|
|
/* |
|
* Monta a linha de cabecalio. |
|
*/ |
|
$linha = array('LABEL'); |
|
foreach ($dadosCabecalio as $value) { |
|
$linha[] = $value; |
|
} |
|
$dataRel[] = $linha; |
|
|
|
$somaTempo = 0; |
|
$somaQuantidade = 0; |
|
/* |
|
* Linhas de dados. |
|
*/ |
|
$dadosDiscTotal = array(); |
|
$x = 1; |
|
foreach ($this->GetData()[0] as $row) { |
|
$chave = null; |
|
|
|
foreach ($dadosDiscTotal as $key => $value) { |
|
if ($value['ramal'] == $row['src'] && $value['dst'] == $row['dst']) { |
|
$chave = $key; |
|
} |
|
} |
|
|
|
if ($chave) { |
|
$dadosDiscTotal[$chave]['quantidade'] ++; |
|
$dadosDiscTotal[$chave]['duracao'] += $row['tempo_atendimento']; |
|
} else { |
|
$dadosDiscTotal[$x]['ramal'] = $row['src']; |
|
$dadosDiscTotal[$x]['dst'] = $row['dst']; |
|
$dadosDiscTotal[$x]['quantidade'] ++; |
|
$dadosDiscTotal[$x]['duracao'] += $row['tempo_atendimento']; |
|
$x++; |
|
} |
|
|
|
$somaTempo += $row["tempo_atendimento"]; |
|
$somaQuantidade ++; |
|
} |
|
|
|
foreach ($dadosDiscTotal as $row) { |
|
$linha = array('DADOS'); |
|
foreach ($dadosField as $key) { |
|
$linha[] = $key == "duracao" ? SecondToStrTime($row["$key"]) : $row["$key"]; |
|
} |
|
$dataRel[] = $linha; |
|
} |
|
|
|
$linha = array('LABEL', 'Total: ' . count($dadosDiscTotal), '', 'Registros: ' . $somaQuantidade, 'Duracao: ' . SecondToStrTime($somaTempo)); |
|
|
|
$dataRel[] = $linha; |
|
|
|
$this->___dataRel[] = $dataRel; |
|
} |
|
|
|
protected function ___PreparaGrid() { |
|
$nomeDac = ""; |
|
$dataRel = array(); |
|
$dataAgrup = array(); |
|
|
|
|
|
$dadosCabecalio = array('Ramal' => 'align="center"', 'Destino' => 'align="center"', 'Quantidade' => 'align="right"', 'Duração' => 'align="right"'); |
|
$dadosField = array('ramal' => 'align="center"', 'dst' => 'align="center"', 'quantidade' => 'align="right"', 'duracao' => 'align="right"'); |
|
/* |
|
* Inicia o relat�rio. |
|
*/ |
|
$dataRel[] = '<table width="800" cellpadding="2" class="grid">'; |
|
|
|
/* |
|
* Monta a linha de cabecalio. |
|
*/ |
|
$linha1 = "<tr>"; |
|
foreach ($dadosCabecalio as $key => $value) { |
|
$linha1 .= sprintf("<th %s>%s</th>", $value, $key); |
|
} |
|
$linha1 .= "</tr>"; |
|
$dataRel[] = $linha1; |
|
|
|
/* |
|
* 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. |
|
*/ |
|
$dadosContaTotal = array(); |
|
$x = 1; |
|
foreach ($this->GetData()[0] as $row) { |
|
$chave = null; |
|
|
|
foreach ($dadosContaTotal as $key => $value) { |
|
if ($value['ramal'] == $row['src'] && $value['dst'] == $row['dst']) { |
|
$chave = $key; |
|
} |
|
} |
|
|
|
if ($chave) { |
|
$dadosContaTotal[$chave]['quantidade'] ++; |
|
$dadosContaTotal[$chave]['duracao'] += $row['tempo_atendimento']; |
|
} else { |
|
$dadosContaTotal[$x]['ramal'] = ocultarTelefone($row['src']); |
|
$dadosContaTotal[$x]['dst'] = $row['dst']; |
|
$dadosContaTotal[$x]['quantidade'] ++; |
|
$dadosContaTotal[$x]['duracao'] += $row['tempo_atendimento']; |
|
$x++; |
|
} |
|
|
|
$somaTempo += $row["tempo_atendimento"]; |
|
$somaQuantidade ++; |
|
} |
|
foreach ($dadosContaTotal as $row) { |
|
$linha .= "<tr>"; |
|
foreach ($dadosField as $key => $value) { |
|
if($key == 'dst'){ |
|
$linha .= sprintf("<td %s>%s</td>", $value, ocultarTelefone($row["$key"])); |
|
}else{ |
|
$linha .= sprintf("<td %s>%s</td>", $value, $key == "duracao" ? SecondToStrTime($row["$key"]) : $row["$key"]); |
|
} |
|
} |
|
$linha .= "</tr>"; |
|
} |
|
|
|
$dataRel[] = $linha; |
|
/* |
|
* Linha de totalizacao. |
|
*/ |
|
$linha = '<tr><th colspan="2" align="left">Total: %s</th><th align="right">Registros: %s</th><th align="right">Duração: %s</th>'; |
|
$dataRel[] = sprintf($linha, count($dadosContaTotal), $somaQuantidade, SecondToStrTime($somaTempo)); |
|
|
|
/* |
|
* Fecha relatorio. |
|
*/ |
|
$dataRel[] = '</table>'; |
|
$this->___dataRel[] = $dataRel; |
|
} |
|
|
|
protected function ___PreparaHtml() { |
|
|
|
} |
|
|
|
protected function ___PreparaPdf() { |
|
list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"]; |
|
|
|
$somaTempo = 0; |
|
$somaQtd = 0; |
|
|
|
$dadosDiscTotal = array(); |
|
$x = 1; |
|
foreach ($this->GetData()[0] as $row) { |
|
$chave = null; |
|
|
|
foreach ($dadosDiscTotal as $key => $value) { |
|
if ($value['ramal'] == $row['src'] && $value['dst'] == $row['dst']) { |
|
$chave = $key; |
|
} |
|
} |
|
|
|
if ($chave) { |
|
$dadosDiscTotal[$chave]['quantidade'] ++; |
|
$dadosDiscTotal[$chave]['duracao'] += $row['tempo_atendimento']; |
|
} else { |
|
$dadosDiscTotal[$x]['ramal'] = $row['src']; |
|
$dadosDiscTotal[$x]['dst'] = $row['dst']; |
|
$dadosDiscTotal[$x]['quantidade'] ++; |
|
$dadosDiscTotal[$x]['duracao'] += $row['tempo_atendimento']; |
|
$x++; |
|
} |
|
|
|
$somaTempo += $row["tempo_atendimento"]; |
|
$somaQtd ++; |
|
} |
|
|
|
foreach ($dadosDiscTotal as $key => $val) { |
|
$dadosDiscTotal[$key]['duracao'] = SecondToStrTime($val['duracao']); |
|
} |
|
|
|
//HEADER DA TABELA DO PDF -> DADOS EM ARRAY |
|
$header = array( |
|
'Ramal' => 'C', |
|
'Destino' => 'C', |
|
'Quantidade' => 'R', |
|
'Duração' => 'R' |
|
); |
|
$dataHeader = array( |
|
'ramal' => 'C', |
|
'dst' => 'C', |
|
'quantidade' => 'R', |
|
'duracao' => 'R' |
|
); |
|
$widthHeader = array(45, 50, 45, 50); |
|
$totaliza = array('Total: ' . count($dadosDiscTotal), '', "Registros: " . $somaQtd, "Duração: " . SecondToStrTime($somaTempo)); |
|
|
|
//Monta o array para passar para o prepara; Necessário passar 6 parametros |
|
$table1 = array($header, $dataHeader, $dadosDiscTotal, $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'); |
|
} |
|
|
|
} |
|
|
|
$relSaintes = new SaintesMaisDiscados($idProg, $dbcon, null); |
|
$relSaintes->ExecutaRelatorio(); |
|
|
|
?>
|
|
|