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.
 
 
 
 
 
 

579 lines
21 KiB

<?php
include_once 'util/relatoriosBase.php';
$tpLayout = 1;
class AbandonadasFilaDetalhes extends Relatorios {
private $___uid;
private $___servico;
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___dac = isset($_GET['dacDesc']) ? $_GET['dacDesc'] : '';
$this->___uid = isset($_GET['uid']) ? base64_decode($_GET['uid']) : '';
$this->___dataIni = isset($_GET['dataIni']) ? $_GET['dataIni'] : date('d/m/Y');
$this->___dataFim = isset($_GET['dataFim']) ? $_GET['dataFim'] : date('d/m/Y');
$this->___servico = isset($_GET['serv_id']) ? $_GET['serv_id'] : '0';
}
function ___ValidaForm() {
parent::___ValidaForm();
if (!IsPostBack()) {
return;
}
if ($this->GetIncDac() && !StrToIntDef($this->___dac)) {
GeraExcept('Informe uma Fila!');
}
}
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) = $_SESSION["SSstorageFiltros"];
// if ($this->___media == MEDIA_PRINT_HTML) {
// $fila = $this->GetIncDac() ? 'Fila: ' . GetDacDesc($this->GetDbCon(), $this->GetIdProg() . ' ') : '';
// return sprintf("%s Data Inicial: %s Data Final: %s ", $fila, $this->___dataIni, $this->___dataFim);
// }
$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;
}
$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<EFBFBD><EFBFBD>o se necessitar de outras op<EFBFBD><EFBFBD>es de filtro.
*/
$filtro = '<table border="0" cellspacing="1" cellpadding="1" class="grid">';
/*
* Rotulos.
*/
$filtro .= '<tr>';
$filtro .= '<th align="center">Dac</th>';
if ($this->___servico) {
$filtro .= '<th align="center">Servi<EFBFBD>o</th>';
}
$filtro .= '<th align="center">Data Inicial </th>';
$filtro .= '<th align="center">Data Final </th>';
$filtro .= '<th align="center">&nbsp;</th>';
$filtro .= '</tr>';
/*
* Valores.
*/
$filtro .= '<tr>';
$filtro .= '<td align="center"><h2>%s</h2></th>';
if ($this->___servico) {
$filtro .= '<td align="center"><h2>%s</h2></th>';
}
$filtro .= '<td align="center"><h2>%s</h2></td>';
$filtro .= '<td align="center"><h2>%s</h2></td>';
$filtro .= '<td align="center">%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->___dataIni, $this->___dataFim,$this->___tipoRel);
if ($this->___servico) {
return sprintf($filtro, $this->___dac, $this->___servico, date('d/m/Y H:i:s', strtotime($this->___dataIni)), date('d/m/Y H:i:s', strtotime($this->___dataFim)), $lkPrint);
} else {
return sprintf($filtro, $this->___dac, date('d/m/Y H:i:s', strtotime($this->___dataIni)), date('d/m/Y H:i:s', strtotime($this->___dataFim)), $lkPrint);
}
}
protected function ___GetDadosDb() {
$dataIni = $this->___dataIni;
$dataFim = $this->___dataFim;
$uid = $this->___uid;
$srv = $this->___servico;
if ($uid) {
$query = "SELECT data_bilhete AS data, a.matricula, apelido AS agente, a.status,d.nome AS fila,
CASE WHEN (disponivel = 1)THEN 'DISPONIVEL' ELSE 'INDISPONIVEL' END AS disponivel,
CASE WHEN (classificado = -1) THEN 'NAO OBRIGATORIO'
WHEN (classificado = 0) THEN 'NAO CLASSIFICADO'
WHEN (classificado = 1 OR classificado = 2) THEN 'CLASSIFICADO' END AS classificado,
motivo_pausa AS motivo, login AS hora_login, logoff AS hora_logoff
FROM pbx_abandonadas_status a
INNER JOIN pbx_bilhetes e ON e.uniqueid = a.uniqueid
INNER JOIN pbx_eventos_agentes b ON b.matricula = a.matricula";
if (GetUsoServico()) {
$query .= "\nleft join pbx_servicos_registra s on s.uniqueid = a.uniqueid ";
}
$query .= "\nINNER JOIN pbx_usuarios c ON c.matricula = a.matricula
INNER JOIN pbx_dacs d ON d.id = b.id_dac
WHERE login <= '$dataIni' AND logoff >= '$dataFim' AND a.uniqueid = '{$uid}' AND d.nome = '$this->___dac'";
if (GetUsoServico() && $srv) {
$query .= "\nand s.serv_id = '{$srv}'";
}
$query .= " GROUP BY data_bilhete,a.matricula,apelido,a.status,d.nome,disponivel,classificado,motivo_pausa, login, logoff ORDER BY login";
} else {
$query = "SELECT '{$this->___dataIni}' AS data, a.matricula, apelido AS agente, d.nome AS fila,
login AS hora_login, logoff AS hora_logoff
FROM pbx_abandonadas_status a
INNER JOIN pbx_bilhetes e ON e.uniqueid = a.uniqueid
INNER JOIN pbx_eventos_agentes b ON b.matricula = a.matricula";
if (GetUsoServico()) {
$query .= "\nleft join pbx_servicos_registra s on s.uniqueid = a.uniqueid ";
}
$query .= "\nINNER JOIN pbx_usuarios c ON c.matricula = a.matricula
INNER JOIN pbx_dacs d ON d.id = b.id_dac
WHERE login <= '$dataIni' AND logoff >= '$dataFim' AND d.id = '$this->___dac'";
if (GetUsoServico() && $srv) {
$query .= "\nand s.serv_id = '{$srv}'";
}
$query .= " GROUP BY a.matricula,apelido,d.nome, login, logoff
ORDER BY login";
}
$result = $this->___GetQuery($query);
$row = pg_fetch_all($result);
$this->SetData($row ? $row : array());
$this->SetData(array(
array(
'logado' => $_GET['logado'],
'pausa' => $_GET['pausa'],
'ocupado' => $_GET['ocupado'],
'indisponivel' => $_GET['indisponivel'],
'classificacao' => $_GET['classificacao'],
'pos_chegada' => $_GET['pos_chegada'],
'pos_abandono' => $_GET['pos_saida'],
'agtRet' => $_GET['agtRet'],
'dtRet' => $_GET['dtRet']
)));
}
protected function ___PreparaCsv() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
/*
* Inicia o relat<EFBFBD>rio.
*/
$dataRel[] = GenerateCsvFromArray($filtro);
$dadosCabecalio = array(
'Data',
'Agente',
'Matricula',
'Login',
'Logoff',
'Status',
'Disponivel Fila',
'Classificacao',
'Motivo Pausa');
$dadosField = array(
'data',
'agente',
'matricula',
'hora_login',
'hora_logoff',
'status',
'disponivel',
'classificado',
'motivo');
/*
* Monta a linha de cabecalio.
*/
$dataRel[] = GenerateCsvFromArray($dadosCabecalio);
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$row["data"] = date('d/m/Y', strtotime($row["data"]));
$row["hora_login"] = date('H:m:i', strtotime($row["hora_login"]));
$row["hora_logoff"] = date('H:m:i', strtotime($row["hora_logoff"]));
// Formata linha de dados.
$linha = array();
foreach ($dadosField as $key => $value) {
$linha[] = $row["$value"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
$dadosCabecalio1 = array('Logado', 'Pausa', 'Ocupado', 'Indisponivel', 'Nao Classificado', 'Pos. Chegada', 'Pos. Abandono', 'Agente Retorno', 'Data Retorno');
$dadosField1 = array('logado', 'pausa', 'ocupado', 'indisponivel', 'classificacao', 'pos_chegada', 'pos_abandono', 'agtRet', 'dtRet');
$dataRel[] = GenerateCsvFromArray($dadosCabecalio1);
foreach ($this->GetData()[1] as $row) {
// Formata linha de dados.
$linha = array();
foreach ($dadosField1 as $key => $value) {
if ($key == 'dtRet') {
$row['dtRet'] = $row['dtRet'] ? date('d/m/Y', strtotime($row['dtRet'])) : '-';
}
$linha[] = $row["$value"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
$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',
'Agente',
'Matricula',
'Login',
'Logoff',
'Status',
'Disponivel Fila',
'Classificacao',
'Motivo Pausa');
$dadosField = array(
'data',
'agente',
'matricula',
'hora_login',
'hora_logoff',
'status',
'disponivel',
'classificado',
'motivo');
/*
* Monta a linha de cabecalio.
*/
$linha = array('LABEL');
foreach ($dadosCabecalio as $value) {
$linha[] = $value;
}
$dataRel[] = $linha;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$row["data"] = date('d/m/Y', strtotime($row["data"]));
$row["hora_login"] = date('H:m:i', strtotime($row["hora_login"]));
$row["hora_logoff"] = date('H:m:i', strtotime($row["hora_logoff"]));
// Formata linha de dados.
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
$this->___dataRel[] = $dataRel;
/*
* Agrupamento
*/
$dadosCabecalio1 = array(
'Logado', 'Pausa', 'Ocupado', 'Indisponivel', 'Nao Classificado',
'Pos. Chegada', 'Pos. Abandono', 'Agente Retorno', 'Data Retorno'
);
$dadosField1 = array(
'logado', 'pausa', 'ocupado', 'indisponivel', 'classificacao',
'pos_chegada', 'pos_abandono', 'agtRet', 'dtRet'
);
$linha = array('LABEL');
foreach ($dadosCabecalio1 as $value) {
$linha[] = $value;
}
$dataRel1[] = $linha;
foreach ($this->GetData()[1] as $row) {
// Formata linha de dados.
$linha = array('DADOS');
foreach ($dadosField1 as $key) {
if ($key == 'dtRet') {
$row['dtRet'] = $row['dtRet'] ? date('d/m/Y', strtotime($row['dtRet'])) : '-';
}
$linha[] = $row["$key"];
}
$dataRel1[] = $linha;
}
$this->___dataRel[] = $dataRel1;
}
protected function ___PreparaGrid() {
$dadosCabecalio = array(
'Data' => 'align="center"',
'Agente' => 'align="left"',
'Matricula' => 'align="left"',
'Login' => 'align="center"',
'Logoff' => 'align="center"',
'Status' => 'align="left"',
'Dispon<EFBFBD>vel Fila' => 'align="center"',
'Classifica<EFBFBD><EFBFBD>o' => 'align="center"',
'Motivo Pausa' => 'align="left"'
);
$dadosField = array(
'data' => 'align="center"',
'agente' => 'align="left"',
'matricula' => 'align="left"',
'hora_login' => 'align="center"',
'hora_logoff' => 'align="center"',
'status' => 'align="left"',
'disponivel' => 'align="center"',
'classificado' => 'align="center"',
'motivo' => 'align="left"');
/*
* Inicia o relat<EFBFBD>rio.
*/
$dataRel[] = '<table width="100%" cellpadding="2" class="grid">';
/*
* Monta a linha de cabecalio.
*/
$linhaH = '<tr>';
foreach ($dadosCabecalio as $key => $value) {
$linhaH .= sprintf("<th %s>%s</th>", $value, $key);
}
$linhaH .= "</tr>";
$dataRel[] = $linhaH;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$row["data"] = date('d/m/Y', strtotime($row["data"]));
$row["hora_login"] = date('H:i:s', strtotime($row["hora_login"]));
$row["hora_logoff"] = date('H:i:s', strtotime($row["hora_logoff"]));
$row["disponivel"] = $row["disponivel"] ? $row["disponivel"] : '-';
$row["classificado"] = $row["classificado"] ? $row["classificado"] : '-';
$row["motivo"] = $row["motivo"] ? $row["motivo"] : '-';
// Formata linha de dados.
$linha = "<tr>";
foreach ($dadosField as $key => $value) {
$linha .= sprintf("<td %s>%s</td>", $value, $row["$key"]);
}
$linha .= "</tr>";
$dataRel[] = $linha;
}
$dataRel[] = '</table>';
$this->___dataRel[] = $dataRel;
/*
* Linha de totalizacao.
*/
$dadosCabecalio1 = array(
'Logado' => 'align="right"',
'Pausa' => 'align="right"',
'Ocupado' => 'align="right"',
'Indisponivel' => 'align="right"',
'N<EFBFBD>o Classificado' => 'align="right"',
'Pos. Chegada' => 'align="right"',
'Pos. Abandono' => 'align="right"',
'Agente Retorno' => 'align="center"',
'Data Retorno' => 'align="center"'
);
if ($this->___uid) {
$dataRel1[] = '<table cellpadding="4" cellspacing="0" class="grid">';
$linhaH1 = '<tr>';
foreach ($dadosCabecalio1 as $key => $value) {
$linhaH1 .= sprintf("<th %s>%s</th>", $value, $key);
}
$linhaH1 .= "</tr>";
$dataRel1[] = $linhaH1;
$linhaH2 = sprintf('<tr>'
. '<td>%s</td>'
. '<td>%s</td>'
. '<td>%s</td>'
. '<td>%s</td>'
. '<td>%s</td>'
. '<td>%s</td>'
. '<td>%s</td>'
. '<td>%s</td>'
. '<td>%s</td>'
. '</tr>', $_GET['logado'], $_GET['pausa'], $_GET['ocupado'], $_GET['indisponivel'], $_GET['classificacao'], $_GET['pos_chegada'], $_GET['pos_saida'], $_GET['agtRet'], $_GET['dtRet'] ? date('d/m/Y', strtotime($_GET['dtRet'])) : '-');
$dataRel1[] = $linhaH2;
/*
* Fecha relatorio.
*/
$dataRel1[] = '</table>';
}
$this->___dataRel[] = $dataRel1;
}
protected function ___PreparaHtml() {
}
protected function ___PreparaPdf() {
list($this->___dac, $this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"];
$dados = $this->GetData()[0];
$x = 0;
$y = 0;
foreach ($dados as $row) {
$dados[$x]["data"] = date('d/m/Y', strtotime($row["data"]));
$dados[$x]["hora_login"] = date('H:m:i', strtotime($row["hora_login"]));
$dados[$x]["hora_logoff"] = date('H:m:i', strtotime($row["hora_logoff"]));
$x++;
}
$header = array(
'Data' => 'C',
'Agente' => 'C',
'Matricula' => 'C',
'Login' => 'C',
'Logoff' => 'C',
'Status' => 'C',
'Dispon<EFBFBD>vel Fila' => 'C',
'Classifica<EFBFBD><EFBFBD>o' => 'C',
'Motivo Pausa' => 'C'
);
$dataHeader = array(
'data' => 'C',
'agente' => 'C',
'matricula' => 'C',
'hora_login' => 'C',
'hora_logoff' => 'C',
'status' => 'C',
'disponivel' => 'C',
'classificado' => 'C',
'motivo' => 'C'
);
$widthHeader = array(20, 20, 20, 20, 20, 20, 25, 25, 25);
$table1 = array($header, $dataHeader, $dados, $widthHeader, '', 0);
$headerTotal = array(
'Logado' => 'C',
'Pausa' => 'C',
'Ocupado' => 'C',
'Indispon<EFBFBD>vel' => 'C',
'N<EFBFBD>o Classificado' => 'C',
'Pos. Chegada' => 'C',
'Pos Abandono' => 'C',
'Agente Retorno' => 'C',
'Data Retorno' => 'C'
);
$dataTotal = array(
'logado' => 'C',
'pausa' => 'C',
'ocupado' => 'C',
'indisponivel' => 'C',
'classificacao' => 'C',
'pos_chegada' => 'C',
'pos_abandono' => 'C',
'agtRet' => 'C',
'dtRet' => 'C'
);
$dadosAgt = $this->GetData()[1];
foreach ($dadosAgt as $rowAgt) {
$dadosAgt[$y]['dtRet'] = $rowAgt['dtRet'] ? date('d/m/Y', strtotime($rowAgt['dtRet'])) : '-';
$y++;
}
$widthHeaderTotal = array(20, 20, 20, 20, 25, 25, 25, 20, 20);
$table2 = array($headerTotal, $dataTotal, $dadosAgt, $widthHeaderTotal, '', 1);
$this->___dataRel = array($table1, $table2);
}
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');
}
}
$relChmEntG = new AbandonadasFilaDetalhes($idProg, $dbcon, 1);
$relChmEntG->ExecutaRelatorio();
?>