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.
 
 
 
 
 
 

488 lines
18 KiB

<?php
/* * ************************************************************************
*
* RELATÓRIO CLASSIFICAÇÃO MENSAL
* Autor
* Lucas Awade
*
* *************************************************************************
* Definições do Projeto
* Nome: RelClassificacaoMensal
* Data início: 10/08/2018
* Equipe: Amarildo Pereira
* Descrição: Gera relatório de classificação realizadas no mês e cadastrada
* no banco de dados. As impressões é feito de acordo com o retorno com a
* query do banco de dados que possui na pesquisa o mês e ano e a fila(DAC);
*
* Pré-requisito: As querys de banco de dados tem que retornar com ordenação
* de acordo com os classificações;
*
* OBS: Atenção ao realizar manutenção nos itens de impressão pois os dados
* apresentados são estruturados.
*
* *************************************************************************
* Copyright (c) 2018, Simples IP
* ************************************************************************ */
include_once 'util/relatoriosBase.php';
class RelClassificacaoMensal extends Relatorios {
private $___ano;
private $___mes;
private $___servico;
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0;
$this->___mes = isset($_POST['listaMes']) ? $_POST['listaMes'] : date('m');
$this->___ano = isset($_POST['listaAno']) ? $_POST['listaAno'] : 0;
$this->___servico = isset($_POST["listaServico"]) ? $_POST["listaServico"] : 0;
}
public function ___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ão do usuário.
*/
list($this->___dac, $this->___ano, $this->___mes, $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ítico' : 'Sintético'));
}
$fltCsv = array();
if ($this->GetIncDac()) {
$fltCsv[] = 'Fila:' . GetDacDesc($this->GetDbCon(), $this->___dac);
}
$fltCsv[] = "Ano:" . $this->___ano;
$fltCsv[] = "Mes:" . $this->___mes;
$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ção se necessitar de outras operações de filtro.
*/
$filtro = '<table border="0" cellspacing="1" cellpadding="1">';
/*
* Rotulos.
*/
$filtro .= '<tr>';
$filtro .= $this->GetIncDac() ? '<td>Fila</td>' : '';
$filtro .= GetUsoServico() ? '<td>Serviço</td>' : '';
$filtro .= '<td>Mês</td>';
$filtro .= '<td>Ano</td>';
$filtro .= '<td align="center" valign="middle">&nbsp;</td>';
$filtro .= '</tr>';
/*
* Valores.
*/
$filtro .= '<tr>';
$filtro .= $this->GetIncDac() ? sprintf('<td>%s</td>', $dacs) : '';
if (GetUsoServico()) {
$filtro .= sprintf('<td>%s</td>', GetIdentRota(false, $this->___servico));
}
$filtro .= sprintf("<td>%s</td>", GetMes($this->___mes, '', 1));
$filtro .= sprintf('<td>%s</td>', GetAno($this->___ano, 1));
$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órios para impressão.
*/
$_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___ano, $this->___mes, $this->___tipoRelatorio);
return sprintf($filtro, $lkPrint);
}
protected function ___GetDadosDb() {
$ano = $this->___ano;
$mes = $this->___mes;
$dac = $this->___dac;
$srv = $this->___servico;
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
$query = $mostraColunaServicos ? "select clas_descricao, clit_descricao," : "select clas_descricao, clit_descricao,";
$query .= " (select count(*) from pbx_classifica_reg d
inner join pbx_bilhetes e on e.uniqueid = d.id_bilhetes
inner join pbx_eventos_dacs f on f.uid2 = e.uniqueid ";
if (GetUsoServico()) {
$query .= "\nleft join pbx_servicos_registra s on s.uniqueid = e.uniqueid";
}
$query .= "\n where e.lastapp <> 'Transferred Call'
and date_part('year',e.data_bilhete) = '$ano'
and date_part('month',e.data_bilhete) = '$mes'
and f.evento in('COMPLETEAGENT','COMPLETECALLER', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL','BUSY','NOANSWER', 'COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG','BUSYS','NOANSWERS')
and d.clas_id = c.clas_id
and d.clit_id = c.clit_id
and d.id_dac = dac.id_dac";
if (GetUsoServico() && $srv) {
$query .= "\nand s.serv_id = '{$srv}'";
}
$query .= " ) as qtde,
(select count(distinct d.id_bilhetes) from pbx_classifica_reg d
inner join pbx_bilhetes e on e.uniqueid = d.id_bilhetes
inner join pbx_eventos_dacs f on f.uid2 = e.uniqueid ";
if (GetUsoServico()) {
$query .= "\nleft join pbx_servicos_registra s on s.uniqueid = e.uniqueid";
}
$query .= "\nwhere e.lastapp <> 'Transferred Call'
and date_part('year', e.data_bilhete) = '$ano'
and date_part('month', e.data_bilhete) = '$mes'
and f.evento in('COMPLETEAGENT','COMPLETECALLER', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL','BUSY','NOANSWER', 'COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG','BUSYS','NOANSWERS')
and d.clas_id = c.clas_id
and d.clit_id = c.clit_id
and d.id_dac = dac.id_dac";
if (GetUsoServico() && $srv) {
$query .= "\nand s.serv_id = '{$srv}'";
}
$query .= ") as chmd
from pbx_classifica_atendimento a
inner join pbx_classifica_item c on c.clas_id = a.clas_id
inner join pbx_classifica_dacs dac on dac.clas_id = a.clas_id
where dac.id_dac = '$dac'
order by clas_descricao, clit_descricao";
$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ório.
*/
$dataRel[] = GenerateCsvFromArray($filtro);
$ultClass = '';
$somaReg = 0;
foreach ($this->GetData()[0] as $row) {
$count++;
$row['clas_descricao'] = RemoveAcentos($row['clas_descricao']);
if ($count != 1) {
if ($ultClass != $row['clas_descricao']) {
$dataRel[] = GenerateCsvFromArray(array("Total [$ultClass]", $somaReg));
$dataRel[] = GenerateCsvFromArray(array('', ''));
unset($somaReg);
$dataRel[] = GenerateCsvFromArray(array($row['clas_descricao'], 'Classificacoes'));
}
} else {
$dataRel[] = GenerateCsvFromArray(array($row['clas_descricao'], 'Classificacoes'));
}
$somaReg += $row["qtde"];
$row['clit_descricao'] = RemoveAcentos($row['clit_descricao']);
// Formata linha de dados.
$dataRel[] = GenerateCsvFromArray(array($row['clit_descricao'], $row['qtde']));
$ultClass = $row['clas_descricao'];
if (count($this->GetData()[0]) == $count) {
$dataRel[] = GenerateCsvFromArray(array("Total [$ultClass]", $somaReg));
}
}
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaExcel() {
$dataRel = 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('Descricao', 'Quantidade');
$dadosField = array('clit_descricao', 'qtde');
$linha = array('LABEL');
foreach ($dadosCabecalio as $value) {
$linha[] = $value;
}
$dataRel[] = $linha;
$ultClass = '';
$somaReg = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$count++;
$row['clas_descricao'] = RemoveAcentos($row['clas_descricao']);
if ($count != 1) {
if ($ultClass != $row['clas_descricao']) {
$dataRel[] = array('LABEL', "Total [$ultClass]", $somaReg);
$dataRel[] = array('LABEL', '', '');
unset($somaReg);
$dataRel[] = array('LABEL', $row['clas_descricao'], 'Classificacoes');
}
} else {
$dataRel[] = array('LABEL', $row['clas_descricao'], 'Classificacoes');
}
$somaReg += $row["qtde"];
$row['clit_descricao'] = RemoveAcentos($row['clit_descricao']);
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
$ultClass = $row['clas_descricao'];
if (count($this->GetData()[0]) == $count) {
$dataRel[] = array('LABEL', "Total [$ultClass]", $somaReg);
}
}
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaGrid() {
$dataRel = array();
$dadosCabecalio = array(
'Data' => 'align="center"',
'Hora' => 'align="center"',
'Origem' => 'align="center"',
'TMA' => 'align="center"',
'Agente' => 'align="center"',
'Status' => 'align="center"'
);
/*
* Inicia o relatório.
*/
$dataRel[] = '<table width="70%" cellpadding="2" class="grid">';
/*
* Monta a linha de cabecalio.
*/
$linha = '<tr>';
$linha .= sprintf("<th colspan = \"2\" %s>%s</th>", 'align="center"', 'Relatório Classificação Mensal');
$linha .= "</tr>";
$dataRel[] = $linha;
/*
* Verifica se retornou dados
*/
//$dadosCabecalio
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;
$ultClass = "";
$pass = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$count ++;
if ($ultClass != $row['clas_descricao']) {
if ($pass) {
$linha = '<tr><th align="left">Total [ %s ]</th><th align="right">%s</th></tr>';
$dataRel[] = sprintf($linha, $ultClass, $somaReg);
$dataRel[] = '<tr><td>&nbsp;</td></tr>';
unset($somaReg);
}
$linha = '<tr>';
$linha .= sprintf("<th %s>%s</th>", 'align="left"', $row['clas_descricao']);
$linha .= sprintf("<th %s>%s</th>", 'align="right"', 'Classificações');
$linha .= "</tr>";
$dataRel[] = $linha;
}
$ultClass = $row['clas_descricao'];
$somaReg += $row['qtde'];
// Formata linha de dados.
$linha = "<tr>";
$linha .= sprintf("<td aling=\"left\">%s</td>", $row['clit_descricao']);
$linha .= sprintf("<td align=\"right\">%s</td>", $row['qtde']);
$linha .= "</tr>";
$dataRel[] = $linha;
$pass = 1;
if (count($this->GetData()[0]) == $count) {
$linha = '<tr><th align="left">Total [ %s ]</th><th align="right">%s</th></tr>';
$dataRel[] = sprintf($linha, $ultClass, $somaReg);
unset($somaReg);
}
}
/*
* Fecha relatorio.
*/
$dataRel[] = '</table>';
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaHtml() {
}
protected function ___PreparaPdf() {
list($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio) = $_SESSION["SSstorageFiltros"];
$dados = array();
$tables = array();
$header = null;
$x = 0;
$t = 0;
$ultClass = "";
$somaReg = 0;
$dataHeader = array('clit_descricao' => 'C', 'qtde' => 'C');
$widthHeader = array(130, 60);
foreach ($this->GetData()[0] as $row) {
$count ++;
if ($x) {
if ($ultClass != $row['clas_descricao']) {
$totalizador = array("Total [ $ultClass ] ", $somaReg);
${'table' . $t} = array($header, $dataHeader, $dados, $widthHeader, $totalizador, 0);
array_push($tables, ${"table" . $t});
$t++;
unset($somaReg);
unset($dados);
$x = 0;
$header = array($row['clas_descricao'] => 'C', "Classificações" => 'C');
}
} else {
$header = array($row['clas_descricao'] => 'C', "Classificações" => 'C');
}
$somaReg += $row['qtde'];
$ultClass = $row['clas_descricao'];
$dados[$x]["clit_descricao"] = $row["clit_descricao"];
$dados[$x]["qtde"] = $row['qtde'];
$x++;
$z++;
if (count($this->GetData()[0]) == $count) {
$totalizador = array("Total [ $ultClass ] ", $somaReg);
${'table' . $t} = array($header, $dataHeader, $dados, $widthHeader, $totalizador, 0);
array_push($tables, ${"table" . $t});
}
}
$this->___dataRel = $tables;
}
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');
}
}
$relClassMensal = new RelClassificacaoMensal($idProg, $dbcon, 1);
$relClassMensal->ExecutaRelatorio();
?>