___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�o do usu�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ítico' : 'Sinté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 = 'Clique aqui para imprimir!'; $prtHtml = "\"Clique"; $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 op��es de filtro. */ $filtro = ''; /* * Rotulos. */ $filtro .= ''; if ($this->GetIncDac()) $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ $filtro .= ''; if ($this->GetIncDac()) $filtro .= sprintf('', $dacs); $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
FilaData InicialData Final Analítico 
%s%s
'; /* * Guarda os filtros passados para recuperar na emiss�o dos relat?ios para impress�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ó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ó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ório. */ $dataRel[] = ''; /* * Monta a linha de cabecalio. */ $linha = ''; foreach ($dadosCabecalio as $key => $value) { $linha .= sprintf("", $value, $key); } $linha .= ""; $dataRel[] = $linha; /* * Verifica se retornou dados */ if (!IsPostBack() || !count($this->GetData()[0])) { $dataRel[] = sprintf("
%s
%s
", 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 = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } /* * Linha de totalizacao. */ $linha = 'Registros Totais: %s'; $dataRel[] = sprintf($linha, $somaReg); /* * Fecha relatorio. */ $dataRel[] = ''; } 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ório. */ $dataRel[] = ''; /* * Monta a linha de cabecalio. */ $linha = ''; foreach ($dadosCabecalio as $key => $value) { $linha .= sprintf("", $value, $key); } $linha .= ""; $dataRel[] = $linha; /* * Verifica se retornou dados */ if (!IsPostBack() || !count($this->GetData()[0])) { $dataRel[] = sprintf("
%s
%s
", 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 = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } /* * Linha de totalizacao. */ $linha = 'Registros Total: %s'; $dataRel[] = sprintf($linha, $somaReg); /* * Fecha relatorio. */ $dataRel[] = ''; } $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ïçã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'); } } $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("%s", 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álida!"); } else if (!is_date($dataFim)) { GeraExcept("Data final inválida!"); } $result = pg_query($dbcon, GetQuery($dataIni, $dataFim, $dac, $analitico)); if (!$result) { GeraExcept("Não foi possí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 .= " $data $contextoCorrente $txt\n"; $somaQuant += $analitico ? 1 : $row["numero_entrada"]; $imp++; } if ($imp) { $linhaFoot = sprintf("%s%s", 2, "Total", $somaQuant); } else { $linhaFoot = sprintf("%s", 3, "Nenhum registro encontrado!"); } } catch (Exception $ex) { $jsStartup[] = sprintf("alert('%s');", $ex->getMessage()); $linhaFoot = sprintf("%s", 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 = ""; return $str; } */ ?>