|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
include_once 'util/relatoriosBase.php';
|
|
|
|
|
|
|
|
|
|
class RelFilaContexto extends Relatorios {
|
|
|
|
|
|
|
|
|
|
private $___tipoRelatorio;
|
|
|
|
|
|
|
|
|
|
public function __construct($idProg, $dbcon, $incDac) {
|
|
|
|
|
parent::__construct($idProg, $dbcon, $incDac);
|
|
|
|
|
$this->___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0;
|
|
|
|
|
$this->___tipoRelatorio = isset($_REQUEST['tipoRelatorio']) ? $_REQUEST['tipoRelatorio'] : 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"';
|
|
|
|
|
/*
|
|
|
|
|
* Personalise esta fun<EFBFBD><EFBFBD>o se necessitar de outras op<EFBFBD><EFBFBD>es de filtro.
|
|
|
|
|
*/
|
|
|
|
|
$filtro = '<table border="0" cellspacing="1" cellpadding="1">';
|
|
|
|
|
/*
|
|
|
|
|
* Rotulos.
|
|
|
|
|
*/
|
|
|
|
|
$filtro .= '<tr>';
|
|
|
|
|
if ($this->GetIncDac())
|
|
|
|
|
$filtro .= '<td>Fila</td>';
|
|
|
|
|
$filtro .= '<td>Data Inicial</td>';
|
|
|
|
|
$filtro .= '<td>Data Final </td>';
|
|
|
|
|
$filtro .= '<td> <input name="tipoRelatorio" type="checkbox" id="tipoRelatorio" value="1" %s />Analítico</td>';
|
|
|
|
|
$filtro .= '<td align="center" valign="middle"> </td>';
|
|
|
|
|
$filtro .= '</tr>';
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Valores.
|
|
|
|
|
*/
|
|
|
|
|
$filtro .= '<tr>';
|
|
|
|
|
if ($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<EFBFBD>o dos relat?ios para impress<EFBFBD>o.
|
|
|
|
|
*/
|
|
|
|
|
$_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio);
|
|
|
|
|
|
|
|
|
|
return sprintf($filtro, $tipoRel, $this->___dataIni, $this->___dataFim, $lkPrint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function ___GetDadosDb() {
|
|
|
|
|
$dataIni = FormatDtMssql($this->___dataIni);
|
|
|
|
|
$dataFim = FormatDtMssql($this->___dataFim);
|
|
|
|
|
$dac = $this->___dac;
|
|
|
|
|
|
|
|
|
|
$select = "";
|
|
|
|
|
$group = "";
|
|
|
|
|
|
|
|
|
|
if ($this->___tipoRelatorio) {
|
|
|
|
|
$select = "SELECT d.context AS contexto, a.calldate AS data, a.src AS origem";
|
|
|
|
|
} else {
|
|
|
|
|
$select = "SELECT d.context AS contexto, a.data_bilhete AS data, count(*) AS numero_entrada";
|
|
|
|
|
$group = "GROUP BY a.data_bilhete, d.context";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$query = "$select
|
|
|
|
|
FROM pbx_bilhetes a
|
|
|
|
|
INNER JOIN pbx_eventos_dacs b ON b.uid2 = a.uniqueid AND b.evento = 'ENTERQUEUE'
|
|
|
|
|
INNER JOIN pbx_bilhetes_complemento c ON c.uniqueid2 = b.uid2
|
|
|
|
|
INNER JOIN pbx_queues_grupos d ON d.context = c.direcao
|
|
|
|
|
INNER JOIN pbx_dacs e ON e.nome = b.fila
|
|
|
|
|
WHERE a.data_bilhete >= '$dataIni'
|
|
|
|
|
AND a.data_bilhete <= '$dataFim'
|
|
|
|
|
AND e.id = $dac
|
|
|
|
|
AND calldate = (SELECT MAX(calldate) FROM pbx_bilhetes WHERE uniqueid = uid2)
|
|
|
|
|
$group
|
|
|
|
|
ORDER BY 1,2";
|
|
|
|
|
|
|
|
|
|
$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<EFBFBD>rio.
|
|
|
|
|
*/
|
|
|
|
|
$dataRel[] = GenerateCsvFromArray($filtro);
|
|
|
|
|
|
|
|
|
|
if (!$this->___tipoRelatorio) {
|
|
|
|
|
$tipo = "Quantidade";
|
|
|
|
|
$dadoTipo = 'numero_entrada';
|
|
|
|
|
}else{
|
|
|
|
|
$tipo = "Origem";
|
|
|
|
|
$dadoTipo = 'origem';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$dadosCabecalio = array(
|
|
|
|
|
'Data',
|
|
|
|
|
'Contexto',
|
|
|
|
|
$tipo
|
|
|
|
|
);
|
|
|
|
|
$dadosField = array(
|
|
|
|
|
'data',
|
|
|
|
|
'contexto',
|
|
|
|
|
$dadoTipo
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Monta a linha de cabecalio.
|
|
|
|
|
*/
|
|
|
|
|
$dataRel[] = GenerateCsvFromArray($dadosCabecalio);
|
|
|
|
|
|
|
|
|
|
$somaReg = 0;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Linhas de dados.
|
|
|
|
|
*/
|
|
|
|
|
foreach ($this->GetData()[0] as $row) {
|
|
|
|
|
$somaReg ++;
|
|
|
|
|
$row["data"] = !$this->___tipoRelatorio ? date('d/m/Y', strtotime($row["data"])) : date('d/m/Y H:i:s', strtotime($row["data"]));
|
|
|
|
|
// Formata linha de dados.
|
|
|
|
|
$linha = array();
|
|
|
|
|
foreach ($dadosField as $value) {
|
|
|
|
|
$linha[] = $row["$value"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$dataRel[] = GenerateCsvFromArray($linha);
|
|
|
|
|
}
|
|
|
|
|
$dataRel[] = GenerateCsvFromArray(array('Registros Totais: ', $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;
|
|
|
|
|
|
|
|
|
|
if (!$this->___tipoRelatorio) {
|
|
|
|
|
$tipo = "Quantidade";
|
|
|
|
|
$dadoTipo = 'numero_entrada';
|
|
|
|
|
}else{
|
|
|
|
|
$tipo = "Origem";
|
|
|
|
|
$dadoTipo = 'origem';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$dadosCabecalio = array('Data', 'Contexto', $tipo);
|
|
|
|
|
$dadosField = array('data', 'contexto', $dadoTipo);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Monta a linha de cabecalio.
|
|
|
|
|
*/
|
|
|
|
|
$linha = array('LABEL');
|
|
|
|
|
foreach ($dadosCabecalio as $value) {
|
|
|
|
|
$linha[] = $value;
|
|
|
|
|
}
|
|
|
|
|
$dataRel[] = $linha;
|
|
|
|
|
|
|
|
|
|
$somaReg = 0;
|
|
|
|
|
/*
|
|
|
|
|
* Linhas de dados.
|
|
|
|
|
*/
|
|
|
|
|
foreach ($this->GetData()[0] as $row) {
|
|
|
|
|
$somaReg ++;
|
|
|
|
|
$row["data"] = !$this->___tipoRelatorio ? date('d/m/Y', strtotime($row["data"])) : date('d/m/Y H:i:s', strtotime($row["data"]));
|
|
|
|
|
|
|
|
|
|
// Formata linha de dados.
|
|
|
|
|
$linha = array('DADOS');
|
|
|
|
|
foreach ($dadosField as $key) {
|
|
|
|
|
$linha[] = $row["$key"];
|
|
|
|
|
}
|
|
|
|
|
$dataRel[] = $linha;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$dataRel[] = array('LABEL', 'Registros Totais: ', $somaReg, '');
|
|
|
|
|
|
|
|
|
|
$this->___dataRel[] = $dataRel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function ___PreparaGrid() {
|
|
|
|
|
$dataRel = array();
|
|
|
|
|
|
|
|
|
|
if (!$this->___tipoRelatorio) {
|
|
|
|
|
|
|
|
|
|
$dadosCabecalio = array(
|
|
|
|
|
'Data' => 'align="center"',
|
|
|
|
|
'Contexto' => 'align="left"',
|
|
|
|
|
'Quantidade' => 'align="right"'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$dadosField = array(
|
|
|
|
|
'data' => 'align="center"',
|
|
|
|
|
'contexto' => 'align="left"',
|
|
|
|
|
'numero_entrada' => 'align="right"'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Inicia o relat<EFBFBD>rio.
|
|
|
|
|
*/
|
|
|
|
|
$dataRel[] = '<table width="800" 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;
|
|
|
|
|
/*
|
|
|
|
|
* Linhas de dados.
|
|
|
|
|
*/
|
|
|
|
|
foreach ($this->GetData()[0] as $row) {
|
|
|
|
|
|
|
|
|
|
$somaReg ++;
|
|
|
|
|
$row["data"] = date('d/m/Y', strtotime($row["data"]));
|
|
|
|
|
|
|
|
|
|
// 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="3" align="left">Registros Totais: %s</th></tr>';
|
|
|
|
|
$dataRel[] = sprintf($linha, $somaReg);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Fecha relatorio.
|
|
|
|
|
*/
|
|
|
|
|
$dataRel[] = '</table>';
|
|
|
|
|
} else {
|
|
|
|
|
$dadosCabecalio = array(
|
|
|
|
|
'Data/Hora' => 'align="center"',
|
|
|
|
|
'Contexto' => 'align="left"',
|
|
|
|
|
'Origem' => 'align="left"'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$dadosField = array(
|
|
|
|
|
'data' => 'align="center"',
|
|
|
|
|
'contexto' => 'align="left"',
|
|
|
|
|
'origem' => 'align="left"'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Inicia o relat<EFBFBD>rio.
|
|
|
|
|
*/
|
|
|
|
|
$dataRel[] = '<table width="800" 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;
|
|
|
|
|
/*
|
|
|
|
|
* Linhas de dados.
|
|
|
|
|
*/
|
|
|
|
|
foreach ($this->GetData()[0] as $row) {
|
|
|
|
|
|
|
|
|
|
$somaReg ++;
|
|
|
|
|
$row["data"] = date('d/m/Y H:i:s', strtotime($row["data"]));
|
|
|
|
|
|
|
|
|
|
// 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="3" align="left">Registros Total: %s</th></tr>';
|
|
|
|
|
$dataRel[] = sprintf($linha, $somaReg);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Fecha relatorio.
|
|
|
|
|
*/
|
|
|
|
|
$dataRel[] = '</table>';
|
|
|
|
|
}
|
|
|
|
|
$this->___dataRel[] = $dataRel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function ___PreparaHtml() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function ___PreparaPdf() {
|
|
|
|
|
$nomeDac = "";
|
|
|
|
|
list($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio) = $_SESSION["SSstorageFiltros"];
|
|
|
|
|
/**
|
|
|
|
|
* TABELA DADOS PRINCIPAIS
|
|
|
|
|
*/
|
|
|
|
|
$somaReg = 0;
|
|
|
|
|
$dados = array();
|
|
|
|
|
|
|
|
|
|
if (!$this->___tipoRelatorio) {
|
|
|
|
|
//HEADER DA TABELA DO PDF -> DADOS EM ARRAY
|
|
|
|
|
$header = array(
|
|
|
|
|
'Data' => 'C',
|
|
|
|
|
'Contexto' => 'C',
|
|
|
|
|
'Quantidade' => 'R'
|
|
|
|
|
);
|
|
|
|
|
$dataHeader = array(
|
|
|
|
|
'data' => 'C',
|
|
|
|
|
'contexto' => 'C',
|
|
|
|
|
'numero_entrada' => 'R'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
foreach ($this->GetData()[0] as $row) {
|
|
|
|
|
$somaReg ++;
|
|
|
|
|
$dados[$somaReg]["data"] = date('d/m/Y', strtotime($row["data"]));
|
|
|
|
|
$dados[$somaReg]["contexto"] = $row["contexto"];
|
|
|
|
|
$dados[$somaReg]["numero_entrada"] = $row["numero_entrada"];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$header = array(
|
|
|
|
|
'Data' => 'C',
|
|
|
|
|
'Contexto' => 'C',
|
|
|
|
|
'Origem' => 'L'
|
|
|
|
|
);
|
|
|
|
|
$dataHeader = array(
|
|
|
|
|
'data' => 'C',
|
|
|
|
|
'contexto' => 'C',
|
|
|
|
|
'origem' => 'L'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
foreach ($this->GetData()[0] as $row) {
|
|
|
|
|
$somaReg ++;
|
|
|
|
|
$dados[$somaReg]["data"] = date('d/m/Y', strtotime($row["data"]));
|
|
|
|
|
$dados[$somaReg]["contexto"] = $row["contexto"];
|
|
|
|
|
$dados[$somaReg]["origem"] = $row["origem"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$totaliza = array("Registro Totais: " . $somaReg, '', '');
|
|
|
|
|
$widthHeader = array(70, 60, 60);
|
|
|
|
|
$table = array($header, $dataHeader, $dados, $widthHeader, $totaliza, 0);
|
|
|
|
|
$this->___dataRel = array($table);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function ExecutaRelatorio() {
|
|
|
|
|
global $jsStartup, $jsJQuery, $smarty;
|
|
|
|
|
try {
|
|
|
|
|
/*
|
|
|
|
|
* Use esta fun<EFBFBD><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');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$relFilaContxt = new RelFilaContexto($idProg, $dbcon, 1);
|
|
|
|
|
$relFilaContxt->ExecutaRelatorio();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
$dac = IsPostBack() ? $_POST["listaDacs"] : GetIdDacPadrao($dbcon, $_SESSION["SSidUser"], 1);
|
|
|
|
|
$dataIni = IsPostBack() ? $_POST["dataIni"] : date('d/m/Y');
|
|
|
|
|
$dataFim = IsPostBack() ? $_POST["dataFim"] : date('d/m/Y');
|
|
|
|
|
$analitico = IsPostBack() ? (isset($_POST["relTipo"]) ? 1 : 0) : 0;
|
|
|
|
|
|
|
|
|
|
$imp = 0;
|
|
|
|
|
$dacs = GetDac($dbcon, $dac, "", 0, 1, 0, 0, 1);
|
|
|
|
|
//$contextos = GetFilaContextos($dac, $dataIni, $dataFim, $contexto);
|
|
|
|
|
$linhaFoot = sprintf("<tr><th align=\"center\" colspan=\"%s\">%s</th></tr>", 3, "Selecione os parametros e clique em consultar!");
|
|
|
|
|
|
|
|
|
|
if (IsPostBack()) {
|
|
|
|
|
try {
|
|
|
|
|
if (!$dac) {
|
|
|
|
|
GeraExcept("Selecione um Dispositivo!");
|
|
|
|
|
} else if (!is_date($dataIni)) {
|
|
|
|
|
GeraExcept("Data inicial inv<EFBFBD>lida!");
|
|
|
|
|
} else if (!is_date($dataFim)) {
|
|
|
|
|
GeraExcept("Data final inv<EFBFBD>lida!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$result = pg_query($dbcon, GetQuery($dataIni, $dataFim, $dac, $analitico));
|
|
|
|
|
if (!$result) {
|
|
|
|
|
GeraExcept("N<EFBFBD>o foi poss<EFBFBD>vel realizar a consulta na base de dados!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$linhas = '';
|
|
|
|
|
$somaQuant = 0;
|
|
|
|
|
|
|
|
|
|
while ($row = @pg_fetch_array($result)) {
|
|
|
|
|
$data = $analitico ? FormataDBDataHora($row["data"]) : substr(FormataDBDataHora($row["data"]), 0, 10);
|
|
|
|
|
$contextoCorrente = $row["contexto"];
|
|
|
|
|
$txt = $analitico ? $row["origem"] : $row["numero_entrada"];
|
|
|
|
|
$txtAl = $analitico ? 'left' : 'right';
|
|
|
|
|
$linhas .= "<tr>
|
|
|
|
|
<td align=\"center\" class=\"headData\">$data</td>
|
|
|
|
|
<td align=\"left\" class=\"headData\">$contextoCorrente</td>
|
|
|
|
|
<td align=\"$txtAl\" class=\"headData\">$txt</td>\n";
|
|
|
|
|
$somaQuant += $analitico ? 1 : $row["numero_entrada"];
|
|
|
|
|
$imp++;
|
|
|
|
|
}
|
|
|
|
|
if ($imp) {
|
|
|
|
|
$linhaFoot = sprintf("<tr><th align=\"center\" colspan=\"%s\" align=\"center\">%s</th><th align=\"right\">%s</th></tr>", 2, "Total", $somaQuant);
|
|
|
|
|
} else {
|
|
|
|
|
$linhaFoot = sprintf("<tr><th align=\"center\" colspan=\"%s\">%s</th></tr>", 3, "Nenhum registro encontrado!");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
|
$jsStartup[] = sprintf("alert('%s');", $ex->getMessage());
|
|
|
|
|
$linhaFoot = sprintf("<tr><th align=\"center\" colspan=\"%s\">%s</th></tr>", 3, $ex->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$jsJQuery[] = "\$('#dataIni').keypress(function(){formataDataHora(this);}) ";
|
|
|
|
|
$jsJQuery[] = "\$('#dataFim').keypress(function(){formataDataHora(this);}) ";
|
|
|
|
|
|
|
|
|
|
$smarty->assign('imp', $imp);
|
|
|
|
|
$smarty->assign('dataIni', $dataIni);
|
|
|
|
|
$smarty->assign('dataFim', $dataFim);
|
|
|
|
|
$smarty->assign('dac', $dacs);
|
|
|
|
|
$smarty->assign('relTipo', $analitico);
|
|
|
|
|
$smarty->assign('linhas', ($linhas .= $linhaFoot));
|
|
|
|
|
|
|
|
|
|
GetTemplate($smarty, 'callcenter/relatorios/geral/filaContexto.tpl');
|
|
|
|
|
|
|
|
|
|
function GetQuery($dataIni, $dataFim, $dac, $analitico) {
|
|
|
|
|
$dataIni = FormatDtMssql($dataIni);
|
|
|
|
|
$dataFim = FormatDtMssql($dataFim);
|
|
|
|
|
|
|
|
|
|
$select = "";
|
|
|
|
|
$group = "";
|
|
|
|
|
|
|
|
|
|
if ($analitico) {
|
|
|
|
|
$select = "SELECT a.calldate as data, a.src as origem, d.context as contexto";
|
|
|
|
|
} else {
|
|
|
|
|
$select = "SELECT a.data_bilhete AS data, d.context AS contexto, count(*) AS numero_entrada";
|
|
|
|
|
$group = "GROUP BY a.data_bilhete, d.context";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$query = "$select
|
|
|
|
|
FROM ast_bilhetes a
|
|
|
|
|
INNER JOIN ast_eventos_dacs b ON b.uid2 = a.uniqueid AND b.evento = 'ENTERQUEUE'
|
|
|
|
|
INNER JOIN pbx_bilhetes_complemento c ON c.uniqueid2 = b.uid2
|
|
|
|
|
INNER JOIN pbx_queues_grupos d ON d.context = c.direcao
|
|
|
|
|
INNER JOIN pbx_dacs e ON e.nome = b.fila
|
|
|
|
|
WHERE a.data_bilhete >= '$dataIni'
|
|
|
|
|
AND a.data_bilhete <= '$dataFim'
|
|
|
|
|
AND e.id = $dac
|
|
|
|
|
AND calldate = (SELECT MAX(calldate) FROM ast_bilhetes WHERE uniqueid = uid2)
|
|
|
|
|
$group
|
|
|
|
|
ORDER BY d.context, a.calldate";
|
|
|
|
|
|
|
|
|
|
//if(IsAdmin()){ echo $sql; exit(); }
|
|
|
|
|
return $query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function GetFilaContextos($dac, $dataIni, $dataFim, $contexto) {
|
|
|
|
|
$dataIni = FormatDtMssql($dataIni);
|
|
|
|
|
$dataFim = FormatDtMssql($dataFim);
|
|
|
|
|
$query = " select context from pbx_queues_grupos where id = '$dac' and trim(coalesce(context, '')) <> ''
|
|
|
|
|
union
|
|
|
|
|
select distinct d.nome
|
|
|
|
|
from pbx_bilhetes a
|
|
|
|
|
inner join pbx_eventos_dacs b on b.uid2 = a.uniqueid and b.evento = 'ENTERQUEUE'
|
|
|
|
|
inner join pbx_queues_grupos c on c.nome = b.fila
|
|
|
|
|
inner join pbx_contextos d on d.nome = c.context
|
|
|
|
|
where a.data_bilhete >= '$dataIni'
|
|
|
|
|
and a.data_bilhete <= '$dataFim'
|
|
|
|
|
and c.id = '$dac' order by 1";
|
|
|
|
|
$result = pg_query($query);
|
|
|
|
|
//if(IsAdmin()){ echo $query; exit(); }
|
|
|
|
|
$str = "<select name=\"contexto\" id=\"contexto\" size=\"1\">";
|
|
|
|
|
|
|
|
|
|
$str .= Sprintf("<option value=\"\"%s>Todos</option>", $contexto ? " selected " : '');
|
|
|
|
|
while ($dados = pg_fetch_row($result)) {
|
|
|
|
|
$sel = ($contexto == $dados[0]) ? ' selected ' : '';
|
|
|
|
|
$str .= sprintf('<option value="%s"%s>%s</option>', $dados[0], $sel, $dados[0]);
|
|
|
|
|
}
|
|
|
|
|
$str .= "</select>";
|
|
|
|
|
return $str;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
?>
|