Índice Nível de serviço [INS]: É calculado pela relação entre chamadas atendidas até 30s pela soma total das chamadas atendidas no pa + o total de abandonadas. atendidas_30 / (atendidas-pa + abandonadas) * 100.0; $atendida30Total = $atendidas30; $atdPaAbd = $atendidas + $abandonadas; $ins = $atdPaAbd > 0 ? ($atendida30Total / $atdPaAbd) * 100.0 : 0; $ins = round($ins, 2); //NS REPRESENTADA POR: $row['ins'] = $cr == 0 ? 0 : round((($row["atendidas_30"] / $cr) * 100.0), 2); -> Indice de abandono [IAB]: É o simples percentual de chamadas abandonadas em relacao as ofereciadas. $iab = $oferTotal > 0 ? ($abdTotal / $oferTotal) * 100.0 : 0; $iab = round($iab, 2); * REPRESENTADA POR: $row['iab'] = ($row["atendidas_30"] + $row["abandonadas31"]) == 0 ? 0 : round((($row["abandonadas31"] / ($row["atendidas_30"] + $row["abandonadas31"])) * 100.0), 2); -> Indice de Chamadas Oferecidas [ICO]: Foi representado por 0. * ************************************************************************* * Copyright (c) 2018, Simples IP * *************************************************************************/ include_once 'util/relatoriosBase.php'; require_once("desvioPadrao.php"); class RelMetricasDiariaAneel extends Relatorios { public function __construct($idProg, $dbcon, $incDac) { parent::__construct($idProg, $dbcon, $incDac); $this->___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0; } function ___ValidaForm() { if (!IsPostBack()) { return; } if ($this->GetIncDac() && !StrToIntDef($this->___dac)) { GeraExcept('Informe uma Fila!'); } if (!is_date($this->___dataIni)) { GeraExcept('A "Data" informada é inválida!'); } } function ___FiltrosRelatorio() { if ($this->___media != MEDIA_PRINT_GRID) { /* * Recupera os filtros da sessão do usuário. */ list($this->___dac, $this->___dataIni) = $_SESSION["SSstorageFiltros"]; $fltCsv = array(); if ($this->GetIncDac()) { $fltCsv[] = 'Fila:' . GetDacDesc($this->GetDbCon(), $this->___dac); } $fltCsv[] = "Data Inicial:" . $this->___dataIni; $fltCsv[] = "Data Final:" . $this->___dataIni; $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->___dac > 0) { $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 .= ''; /* * Valores. */ $filtro .= ''; if ($this->GetIncDac()) $filtro .= sprintf('', $dacs); $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
FilaData  
%s%s
'; /* * Guarda os filtros passados para recuperar na emiss�o dos relat?ios para impress�o. */ $_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___dataIni); return sprintf($filtro, $this->___dataIni, $lkPrint); } protected function ___GetDadosDb() { $data = FormatDtMssql($this->___dataIni); $dac = $this->___dac; $query = "SELECT coalesce(I.data,'$data') as data ,h.hora_ini ,case when(h.hora_fim = '23:59:59')then '00:00:00' else h.hora_fim end as hora_fim ,h.periodo ,COALESCE(I.OFERECIDAS,0) AS OFERECIDAS ,COALESCE(I.ATENDIDAS_URA,0) AS ATENDIDAS_URA ,COALESCE(I.ABANDONADAS,0) AS ABANDONADAS ,COALESCE(I.ABANDONADAS30,0) AS ABANDONADAS30 ,COALESCE(I.ABANDONADAS31,0) AS ABANDONADAS31 ,COALESCE(I.ATENDIDAS_PA,0) AS ATENDIDAS_PA ,COALESCE(I.ATENDIDAS_30,0) AS ATENDIDAS_30 ,COALESCE(I.ATENDIDAS_31,0) AS ATENDIDAS_31 ,COALESCE(I.TRANSFERIDAS,0) AS TRANSFERIDAS ,COALESCE(I.ESPERA,0) AS ESPERA ,COALESCE(round( CASE WHEN(I.ATENDIDAS_PA = 0)THEN 0 ELSE (I.TEMPO_ATENDIMENTO / I.ATENDIDAS_PA)END),0) * INTERVAL '1 SECOND' AS TMA ,0 AS OCUPADAS ,0 AS RECEBIDAS_PESSOALMENTE ,0 AS ATENDIMENTO_URA ,0 AS ICO ,COALESCE(I.TEMPO_ESPERA,0) AS TEMPO_ESPERA ,COALESCE(I.TEMPO_ATENDIMENTO,0) AS TEMPO_ATENDIMENTO ,COALESCE(I.TEMPO_ABANDONO,0) AS TEMPO_ABANDONO ,COALESCE(I.num_agente,0) AS num_agente FROM pbx_hora_dia h left outer join ( SELECT calldate as data, hora_ini ,hora_fim ,periodo ,SUM (CASE WHEN EVENTO = 'ENTERQUEUE' THEN 1 ELSE 0 END) AS OFERECIDAS ,SUM (CASE WHEN EVENTO = 'ENTERQUEUE' THEN 1 ELSE 0 END) AS ATENDIDAS_URA ,SUM (CASE WHEN((EVENTO = 'ABANDON'))THEN 1 ELSE 0 END) AS ABANDONADAS ,SUM (CASE WHEN((EVENTO = 'ABANDON') AND (param3::int <= 30) )THEN 1 ELSE 0 END) AS ABANDONADAS30 ,SUM (CASE WHEN((EVENTO = 'ABANDON') AND (param3::int > 30) )THEN 1 ELSE 0 END) AS ABANDONADAS31 ,SUM (CASE WHEN EVENTO IN ('COMPLETEAGENT','COMPLETECALLER') THEN 1 ELSE 0 END) AS ATENDIDAS_PA ,SUM (CASE WHEN EVENTO IN ('COMPLETEAGENT','COMPLETECALLER') AND to_number(param1,'999999999') <= '30' THEN 1 ELSE 0 END) AS ATENDIDAS_30 ,SUM (CASE WHEN EVENTO IN ('COMPLETEAGENT','COMPLETECALLER') AND to_number(param1,'999999999') > '30' THEN 1 ELSE 0 END) AS ATENDIDAS_31 ,SUM (CASE WHEN EVENTO IN ('TRANSFER') THEN 1 ELSE 0 END) AS TRANSFERIDAS ,SUM (CASE WHEN EVENTO IN ('CONNECT') AND to_number(param1,'999999999') > '3' THEN 1 ELSE 0 END) AS ESPERA ,SUM (CASE WHEN EVENTO IN ('CONNECT') AND to_number(param1,'999999999') > '1' THEN to_number(param1,'999999999') ELSE 0 END) AS TEMPO_ESPERA ,SUM (CASE WHEN EVENTO IN ('COMPLETEAGENT','COMPLETECALLER') AND to_number(param2,'999999999') > '1' THEN to_number(param2,'999999999') ELSE 0 END) AS TEMPO_ATENDIMENTO ,SUM (CASE WHEN( (EVENTO = 'ABANDON') ) THEN to_number(param3,'999999999') ELSE 0 END) AS TEMPO_ABANDONO ,count(distinct agente) as num_agente FROM ( SELECT c.hora_ini, c.hora_fim, c.periodo, a.calldate,b.fila,b.evento,b.param1,b.param2,b.param3,b.param4, case when(b.agente = 'NONE')THEN NULL ELSE b.agente END AS agente FROM pbx_hora_dia c INNER JOIN pbx_bilhetes a on cast(a.calldate as time) >= c.hora_ini and cast(a.calldate as time) < c.hora_fim and a.lastapp <> 'Transferred Call' INNER JOIN pbx_eventos_dacs b on b.uid2 = a.uniqueid INNER JOIN pbx_dacs d on d.nome = b.fila WHERE b.evento in ('ABANDON','COMPLETEAGENT','COMPLETECALLER', 'CONNECT','ENTERQUEUE','TRANSFER') AND a.data_bilhete = '$data' AND d.id = $dac ) AS DADOS GROUP BY calldate, hora_ini, hora_fim, periodo ) AS I on I.periodo = h.periodo ORDER BY 4"; $result = $this->___GetQuery($query); $row = pg_fetch_all($result); $this->SetData($row ? $row : array()); } protected function ___PreparaCsv() { global $dbcon; $dataRel = array(); $filtro = $this->___FiltrosRelatorio(); /* * Inicia o relatório. */ $dataRel[] = GenerateCsvFromArray($filtro); $dadosCabecalio = array( $this->___dataIni, 'TIP' ,'CA <= 30','CA > 30','AB <= 30','AB > 30','CO','COF','INS', 'IAB','ICO','TMA','AT' ); $dadosField = array( 'data','tip','atendidas_30','atendidas_31','abandonadas30', 'abandonadas31','co','oferecidas','ins','iab','ico','tma','num_agente' ); /* * Monta a linha de cabecalio. */ $dataRel[] = GenerateCsvFromArray($dadosCabecalio); $ca30 = 0; $ca31 = 0; $ab30 = 0; $ab31 = 0; $cof = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $row['co'] = 0; $cr = $row["atendidas_pa"] + $row["abandonadas"]; $row['ins'] = $cr == 0 ? 0 : round((($row["atendidas_30"] / $cr) * 100.0), 2); $row['iab'] = ($row["atendidas_30"] + $row["abandonadas31"]) == 0 ? 0 : round((($row["abandonadas31"] / ($row["atendidas_30"] + $row["abandonadas31"])) * 100.0), 2); $row['ico'] = $row['oferecidas'] == 0 ? 0 : round(((0 / $row['oferecidas']) * 100.0), 2); $mediaCalc = 0; $desvio = round(GetDesvio(GetDadosDia($dbcon, $this->___dac, $row["data"], $row['periodo']), $mediaCalc)); $mediaCalc = round($mediaCalc); $row['tip'] = "-"; if ($row['oferecidas'] > 0) { $diaTipico = 1; if (($row['oferecidas'] > ($mediaCalc + ($desvio * 2)))) { $diaTipico = 0; $row['tip'] = 'ATIPICO'; } else if (($row['oferecidas'] < ($mediaCalc - ($desvio * 2)))) { $diaTipico = 0; $row['tip'] = 'ATIPICO'; } else { $row['tip'] = 'TIPICO'; } } if ($diaTipico) { $mediaIns += ($cr * $row['ins']); $pesoIns += $cr; } if ($diaTipico) { $mediaIab += ($cr * $row['iab']); $pesoIab += $cr; } if($row['data']){ $row['data'] = $row['hora_ini'].' as '.$row['hora_fim']; } $tins = $pesoIns == 0 ? 0 : round($mediaIns / $pesoIns, 2); $tiab = $pesoIab == 0 ? 0 : round($mediaIab / $pesoIab, 2); $tico = 0; $ca30 += $row['atendidas_30']; $ca31 += $row['atendidas_31']; $ab30 += $row['abandonadas30']; $ab31 += $row['abandonadas31']; $cof += $row['oferecidas']; // Formata linha de dados. $linha = array(); foreach ($dadosField as $value) { $linha[] = $row["$value"]; } $dataRel[] = GenerateCsvFromArray($linha); } $dataRel[] = GenerateCsvFromArray(array('Total ','-' ,$ca30, $ca31, $ab30, $ab31, 0,$cof,'INS','IAB','ICO','-','-')); $dataRel[] = GenerateCsvFromArray(array('Media Ponderada ', '-', '-', '-', '-', '-','-','-',$tins, $tiab, $tico,'-','-')); $dataRel[] = GenerateCsvFromArray(array('')); $dataRel[] = GenerateCsvFromArray(array('INS', 'IAB', 'ICO','CO','COF')); $dataRel[] = GenerateCsvFromArray(array('Indice de Nivel de Servico', 'Indice Abandonadas', 'Indice de Chamadas Oferecidas','Oferecidas','Oferecidas na Fila')); $this->___dataRel[] = $dataRel; } protected function ___PreparaExcel() { global $dbcon; $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( $this->___dataIni, 'TIP' ,'CA <= 30','CA > 30','AB <= 30','AB > 30','CO','COF','INS', 'IAB','ICO','TMA','AT' ); $dadosField = array( 'data','tip','atendidas_30','atendidas_31','abandonadas30', 'abandonadas31','co','oferecidas','ins','iab','ico','tma','num_agente' ); /* * Monta a linha de cabecalio. */ $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; $ca30 = 0; $ca31 = 0; $ab30 = 0; $ab31 = 0; $cof = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $row['co'] = 0; $cr = $row["atendidas_pa"] + $row["abandonadas"]; $row['ins'] = $cr == 0 ? 0 : round((($row["atendidas_30"] / $cr) * 100.0), 2); $row['iab'] = ($row["atendidas_30"] + $row["abandonadas31"]) == 0 ? 0 : round((($row["abandonadas31"] / ($row["atendidas_30"] + $row["abandonadas31"])) * 100.0), 2); $row['ico'] = $row['oferecidas'] == 0 ? 0 : round(((0 / $row['oferecidas']) * 100.0), 2); $mediaCalc = 0; $desvio = round(GetDesvio(GetDadosDia($dbcon, $this->___dac, $row["data"], $row['periodo']), $mediaCalc)); $mediaCalc = round($mediaCalc); $row['tip'] = "-"; if ($row['oferecidas'] > 0) { $diaTipico = 1; if (($row['oferecidas'] > ($mediaCalc + ($desvio * 2)))) { $diaTipico = 0; $row['tip'] = 'ATIPICO'; } else if (($row['oferecidas'] < ($mediaCalc - ($desvio * 2)))) { $diaTipico = 0; $row['tip'] = 'ATIPICO'; } else { $row['tip'] = 'TIPICO'; } } if ($diaTipico) { $mediaIns += ($cr * $row['ins']); $pesoIns += $cr; } if ($diaTipico) { $mediaIab += ($cr * $row['iab']); $pesoIab += $cr; } if($row['data']){ $row['data'] = $row['hora_ini'].' as '.$row['hora_fim']; } $tins = $pesoIns == 0 ? 0 : round($mediaIns / $pesoIns, 2); $tiab = $pesoIab == 0 ? 0 : round($mediaIab / $pesoIab, 2); $tico = 0; $ca30 += $row['atendidas_30']; $ca31 += $row['atendidas_31']; $ab30 += $row['abandonadas30']; $ab31 += $row['abandonadas31']; $cof += $row['oferecidas']; // Formata linha de dados. $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; } $dataRel[] = array('LABEL', 'Total ','-' ,$ca30, $ca31, $ab30, $ab31, 0,$cof,'INS','IAB','ICO','-','-'); $dataRel[] = array('LABEL', 'Media Ponderada ', '-', '-', '-', '-', '-','-','-',$tins, $tiab, $tico,'-','-'); $dataRel[] = array('DADOS', ''); $dataRel[] = array('LABEL', 'INS', 'IAB', 'ICO','CO','COF'); $dataRel[] = array('DADOS', 'Indice de Nivel de Servico', 'Indice Abandonadas', 'Indice de Chamadas Oferecidas','Oferecidas','Oferecidas na Fila'); $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $dataRel = array(); global $dbcon; $dadosCabecalio = array( $this->___dataIni => 'align="center"', 'TIP' => 'align="center"', 'CA <= 30' => 'align="center"', 'CA > 30' => 'align="center"', 'AB <= 30' => 'align="center"', 'AB > 30' => 'align="center"', 'CO' => 'align="center"', 'COF' => 'align="center"', 'INS' => 'align="center"', 'IAB' => 'align="center"', 'ICO' => 'align="center"', 'TMA' => 'align="center"', 'AT' => 'align="center"' ); $dadosField = array( 'data' => 'align="center"', 'tip' => 'align="center"', 'atendidas_30' => 'align="center"', 'atendidas_31' => 'align="center"', 'abandonadas30' => 'align="center"', 'abandonadas31' => 'align="center"', 'co' => 'align="center"', 'oferecidas' => 'align="center"', 'ins' => 'align="center"', 'iab' => 'align="center"', 'ico' => 'align="center"', 'tma' => 'align="center"', 'num_agente' => 'align="center"' ); /* * 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; } $ca30 = 0; $ca31 = 0; $ab30 = 0; $ab31 = 0; $cof = 0; $mediaIns = 0; $pesoIns = 0; $mediaIab = 0; $pesoIab = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $row['co'] = 0; $cr = $row["atendidas_pa"] + $row["abandonadas"]; $row['ins'] = $cr == 0 ? 0 : round((($row["atendidas_30"] / $cr) * 100.0), 2); $row['iab'] = ($row["atendidas_30"] + $row["abandonadas31"]) == 0 ? 0 : round((($row["abandonadas31"] / ($row["atendidas_30"] + $row["abandonadas31"])) * 100.0), 2); $row['ico'] = $row['oferecidas'] == 0 ? 0 : round(((0 / $row['oferecidas']) * 100.0), 2); $mediaCalc = 0; $desvio = round(GetDesvio(GetDadosDia($dbcon, $this->___dac, $row["data"], $row['periodo']), $mediaCalc)); $mediaCalc = round($mediaCalc); $row['tip'] = "-"; if ($row['oferecidas'] > 0) { $diaTipico = 1; if (($row['oferecidas'] > ($mediaCalc + ($desvio * 2)))) { $diaTipico = 0; $row['tip'] = sprintf("ATÍPICO", $row['oferecidas']); } else if (($row['oferecidas'] < ($mediaCalc - ($desvio * 2)))) { $diaTipico = 0; $row['tip'] = sprintf("ATÍPICO", $row['oferecidas']); } else { $row['tip'] = sprintf("TÍPICO", $row['oferecidas']); } } if ($diaTipico) { $mediaIns += ($cr * $row['ins']); $pesoIns += $cr; } if ($diaTipico) { $mediaIab += ($cr * $row['iab']); $pesoIab += $cr; } $tins = $pesoIns == 0 ? 0 : round($mediaIns / $pesoIns, 2); $tiab = $pesoIab == 0 ? 0 : round($mediaIab / $pesoIab, 2); $tico = 0; $ca30 += $row['atendidas_30']; $ca31 += $row['atendidas_31']; $ab30 += $row['abandonadas30']; $ab31 += $row['abandonadas31']; $cof += $row['oferecidas']; // Formata linha de dados. $linha = ""; foreach ($dadosField as $key => $value) { if ($key == 'data') { $linha .= sprintf("%s", $value, $row['hora_ini'] . ' às ' . $row['hora_fim']); } else { $linha .= sprintf("%s", $value, $row["$key"]); } } $linha .= ""; $dataRel[] = $linha; } /* * Linha de totalizacao. */ $linha = 'Total%s%s%s%s%s%sINSIABICO'; $dataRel[] = sprintf($linha, $ca30, $ca31, $ab30, $ab31, 0, $cof); $linha = 'Média Ponderada%s%s%s'; $linha .= ""; $dataRel[] = sprintf($linha, $tins, $tiab, $tico); /* * Fecha relatorio. */ $linha = '
'; $linha .= ""; $linha .= "" . "" . "" . "" . "" . "" . "" . "" . "" . "" . ""; $linha .= '
Legenda
COOferecidas
COFOferecidas na Fila
INSÍndice de Nível de Serviço
IABÍndice de Abandono
ICOÍndice de Chamadas Oferecidas
'; $dataRel[] = $linha; $this->___dataRel[] = $dataRel; } protected function ___PreparaHtml() { } protected function ___PreparaPdf() { list($this->___dac, $this->___dataIni) = $_SESSION["SSstorageFiltros"]; $this->___dataFim = $this->___dataIni; $dataRel = array(); $dados = $this->GetData()[0]; global $dbcon; $dadosCabecalio = array( $this->___dataIni => 'C', 'TIP' => 'C', 'CA <= 30' => 'C', 'CA > 30' => 'C', 'AB <= 30' => 'C', 'AB > 30' => 'C', 'CO' => 'C', 'COF' => 'C', 'INS' => 'C', 'IAB' => 'C', 'ICO' => 'C', 'TMA' => 'C', 'AT' => 'C' ); $dadosField = array( 'data' => 'C', 'tip' => 'C', 'atendidas_30' => 'C', 'atendidas_31' => 'C', 'abandonadas30' => 'C', 'abandonadas31' => 'C', 'co' => 'C', 'oferecidas' => 'C', 'ins' => 'C', 'iab' => 'C', 'ico' => 'C', 'tma' => 'C', 'num_agente' => 'C' ); $x = 0; foreach ($dados as $row) { $dados[$x]['co'] = 0; $cr = $row["atendidas_pa"] + $row["abandonadas"]; $dados[$x]['ins'] = $cr == 0 ? 0 : round((($row["atendidas_30"] / $cr) * 100.0), 2); $dados[$x]['iab'] = ($row["atendidas_30"] + $row["abandonadas31"]) == 0 ? 0 : round((($row["abandonadas31"] / ($row["atendidas_30"] + $row["abandonadas31"])) * 100.0), 2); $dados[$x]['ico'] = $row['oferecidas'] == 0 ? 0 : round(((0 / $row['oferecidas']) * 100.0), 2); $mediaCalc = 0; $desvio = round(GetDesvio(GetDadosDia($dbcon, $this->___dac, $row["data"], $row['periodo']), $mediaCalc)); $mediaCalc = round($mediaCalc); $dados[$x]['tip'] = "-"; if ($row['oferecidas'] > 0) { $diaTipico = 1; if (($row['oferecidas'] > ($mediaCalc + ($desvio * 2)))) { $diaTipico = 0; $dados[$x]['tip'] = "ATÍPICO"; } else if (($row['oferecidas'] < ($mediaCalc - ($desvio * 2)))) { $diaTipico = 0; $dados[$x]['tip'] = "ATÍPICO"; } else { $dados[$x]['tip'] = "TÍPICO"; } } if ($diaTipico) { $mediaIns += ($cr * $dados[$x]['ins']); $pesoIns += $cr; } if ($diaTipico) { $mediaIab += ($cr * $dados[$x]['iab']); $pesoIab += $cr; } if($row['data']){ $dados[$x]['data'] = $row['hora_ini'].' às '.$row['hora_fim']; } $tins = $pesoIns == 0 ? 0 : round($mediaIns / $pesoIns, 2); $tiab = $pesoIab == 0 ? 0 : round($mediaIab / $pesoIab, 2); $tico = 0; $ca30 += $row['atendidas_30']; $ca31 += $row['atendidas_31']; $ab30 += $row['abandonadas30']; $ab31 += $row['abandonadas31']; $cof += $row['oferecidas']; $x++; } $widthHeader = array(30, 15, 15, 15, 15, 15, 12, 12, 12, 12, 12, 15, 12); $totaliza = array('Total', '-', $ca30, $ca31, $ab30, $ab31, 0, $cof, 'INS', 'IAB', 'ICO', '-', '-'); //Monta o array para passar para o prepara; Necessário passar 6 parametros $table = array($dadosCabecalio, $dadosField, $dados, $widthHeader, $totaliza, 0); $total = array('Média Ponderada', '-', '-', '-', '-', '-', '-', '-', $tins, $tiab,$tico, '-', '-'); $totalHeader = array(30, 15, 15, 15, 15, 15, 12, 12, 12, 12, 12, 15, 12); $table1 = array('', '', '', $totalHeader, $total, 0); $legendaCabecalio = array( "INS" => 'C', "IAB" => 'C', 'ICO' => 'C', 'CO' => 'C', 'COF' => 'C' ); $legendaField = array( 1 => 'C', 2 => 'C', 3 => 'C', 4 => 'C', 5 => 'C' ); $legDadosField = array(array( 1 => 'Nível de Serviço', 2 => 'Índice de Abandono', 3 => 'Índice de Chamadas Oferecidas', 4 => 'Oferecidas', 5 => 'Oferecidas na Fila' ) ); $legendaHeader = array(30,30,40,30,30); $table2 = array($legendaCabecalio, $legendaField, $legDadosField, $legendaHeader, 0, 1); $this->___dataRel = array($table,$table1,$table2); } public function ExecutaRelatorio() { global $jsStartup, $jsJQuery, $smarty; try { /* * Formata as linha da função date */ //setlocale(LC_ALL, "pt_BR", "pt_BR.iso-8859-1", "pt_BR.utf-8", "portuguese"); /* * 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'); } } $relMetricasDiariaAneel = new RelMetricasDiariaAneel($idProg, $dbcon, 1); $relMetricasDiariaAneel->ExecutaRelatorio(); /* require_once("bd.php"); require_once("desvioPadrao.php"); $isValid = 1; $msg = ''; //variaveis para manter o estado $_SESSION["listaDacs"] = isset($_POST["listaDacs"]) ? $_POST["listaDacs"] : GetIdDacPadrao($dbcon, $_SESSION["SSidUser"]); $_SESSION["data"] = isset($_POST["dataIni"]) ? $_POST["dataIni"] : date('d/m/Y'); //carrega dacs $dacs = GetDac($dbcon, $_SESSION["listaDacs"]); $_SESSION[SSdacDesc] = GetDacDesc($dbcon, $_SESSION["listaDacs"]); //sumarização do relatorio $dac = $_SESSION["listaDacs"]; $codMes = FormatDtMssql($_SESSION["data"]); if (IsPostBack()) { if (!$_SESSION["listaDacs"]) { $jsStartup[] = "alert('Selecione um Dispositivo!');"; $msg = "Selecione um Dispositivo!"; } else { //importa dados para calcular o desvio padrao ImportaDadosDesvioDia($dbcon); //print GetDesvio('2009-09-17', $dbcon) . "
"; $linhas = ""; $linhaTmp = ""; $result = pg_query($dbcon, GetQuery($dac, $codMes)); $i = 0; $dados = array(); while ($row = @pg_fetch_array($result)) { $dia = substr($row["hora_ini"], 0, 5) . " às " . substr($row["hora_fim"], 0, 5); $data = $row["data"]; $atendidas30 = $row["atendidas_30"]; $atendidasM = $row["atendidas_31"]; $abandonadas = $row["abandonadas"]; $abandonadas30 = $row["abandonadas30"]; $abandonadasM = $row["abandonadas31"]; $atendidas = $row["atendidas_pa"]; $recebidas = $row["oferecidas"]; $tma = $row["tma"]; $agt = $row["num_agente"]; $periodo = $row["periodo"]; $caIab = $atendidas; // + $abandonadasM; $co = 0; $cr = $atendidas + $abandonadas; $tca += $atendidas30; $tcam += $atendidasM; $tab += $abandonadas30; $tabm += $abandonadasM; $tco += 0; $tcof += $recebidas; $ins = $cr == 0 ? 0 : round((($atendidas30 / $cr) * 100.0), 2); $iab = ($atendidas + $abandonadasM) == 0 ? 0 : round((($abandonadasM / ($atendidas + $abandonadasM)) * 100.0), 2); $ico = $recebidas == 0 ? 0 : round((($co / $recebidas) * 100.0), 2); //print "rec " . $recebidas . " desvio " . $desvio . " media " . $mediaCalc . " media x desvio " . ($mediaCalc + ($desvio * 2)) . "
" ; $mediaCalc = 0; $desvio = round(GetDesvio(GetDadosDia($dbcon, $dac, $data, $periodo), $mediaCalc)); $mediaCalc = round($mediaCalc); //print "rec " . $recebidas . " desvio " . $desvio . " media " . $mediaCalc . " media x desvio " . ($mediaCalc + ($desvio * 2)) . "
" ; $tipico = "-"; if ($recebidas > 0) { $diaTipico = 1; if (($recebidas > ($mediaCalc + ($desvio * 2)))) { $diaTipico = 0; $tipico = " ATÍPICO "; } else if (($recebidas < ($mediaCalc - ($desvio * 2)))) { $diaTipico = 0; $tipico = " ATÍPICO "; } else { $tipico = " TÍPICO "; } } if ($diaTipico) { $mediaIns += ($cr * $ins); $pesoIns += $cr; } if ($diaTipico) { $mediaIab += ($cr * $iab); $pesoIab += $cr; } $linhaTmp = " $dia $tipico $atendidas30 $atendidasM $abandonadas30 $abandonadasM 0 $recebidas $ins $iab $ico $tma $agt "; $dados[$i] = $linhaTmp; $linhas .= $linhaTmp; $i++; } } } $_SESSION["SSdadosRd"] = $dados; $_SESSION["totalRegMd"] = $i; $tins = $pesoIns == 0 ? 0 : round($mediaIns / $pesoIns, 2); $tiab = $pesoIab == 0 ? 0 : round($mediaIab / $pesoIab, 2); $tico = 0; $linhaTotal = " Total   $tca $tcam $tab $tabm $tco $tcof INS IAB ICO     Média Poderada $tins $tiab $tico     "; $_SESSION["linhaTotalMd"] = " Total   $tca $tcam $tab $tabm $tco $tcof INS IAB ICO     Média Ponderada $tins $tiab $tico     "; if (IsPostBack()) { $erro = ""; if (($msg == '') && pg_last_error($dbcon)) $erro = "Ocorreram erros durante a operação. Erro: " . pg_last_error($dbcon); } $smarty->assign('imp', $i); $smarty->assign('ano', $ano); $smarty->assign('dacs', $dacs); $smarty->assign('data', $_SESSION["data"]); $smarty->assign('linhas', $linhas); $smarty->assign('linhaTotal', $linhaTotal); $smarty->assign('erro', $erro); GetTemplate($smarty, 'callcenter/relatorios/metas/relMetricaAneelDia.tpl'); function GetQuery($dac, $codMes) { // listaDacs=6&listaAgente=1000&dataIni=&dataFim=&btConsulta=Consultar $query = "SELECT coalesce(I.data,'$codMes') as data ,h.hora_ini ,case when(h.hora_fim = '23:59:59')then '00:00:00' else h.hora_fim end as hora_fim ,h.periodo ,COALESCE(I.OFERECIDAS,0) AS OFERECIDAS ,COALESCE(I.ATENDIDAS_URA,0) AS ATENDIDAS_URA ,COALESCE(I.ABANDONADAS,0) AS ABANDONADAS ,COALESCE(I.ABANDONADAS30,0) AS ABANDONADAS30 ,COALESCE(I.ABANDONADAS31,0) AS ABANDONADAS31 ,COALESCE(I.ATENDIDAS_PA,0) AS ATENDIDAS_PA ,COALESCE(I.ATENDIDAS_30,0) AS ATENDIDAS_30 ,COALESCE(I.ATENDIDAS_31,0) AS ATENDIDAS_31 ,COALESCE(I.TRANSFERIDAS,0) AS TRANSFERIDAS ,COALESCE(I.ESPERA,0) AS ESPERA ,COALESCE(round( CASE WHEN(I.ATENDIDAS_PA = 0)THEN 0 ELSE (I.TEMPO_ATENDIMENTO / I.ATENDIDAS_PA)END),0) * INTERVAL '1 SECOND' AS TMA ,0 AS OCUPADAS ,0 AS RECEBIDAS_PESSOALMENTE ,0 AS ATENDIMENTO_URA ,0 AS ICO ,COALESCE(I.TEMPO_ESPERA,0) AS TEMPO_ESPERA ,COALESCE(I.TEMPO_ATENDIMENTO,0) AS TEMPO_ATENDIMENTO ,COALESCE(I.TEMPO_ABANDONO,0) AS TEMPO_ABANDONO ,COALESCE(I.num_agente,0) AS num_agente FROM pbx_hora_dia h left outer join ( SELECT calldate as data, hora_ini ,hora_fim ,periodo ,SUM (CASE WHEN EVENTO = 'ENTERQUEUE' THEN 1 ELSE 0 END) AS OFERECIDAS ,SUM (CASE WHEN EVENTO = 'ENTERQUEUE' THEN 1 ELSE 0 END) AS ATENDIDAS_URA ,SUM (CASE WHEN((EVENTO = 'ABANDON'))THEN 1 ELSE 0 END) AS ABANDONADAS ,SUM (CASE WHEN((EVENTO = 'ABANDON') AND (param3::int <= 30) )THEN 1 ELSE 0 END) AS ABANDONADAS30 ,SUM (CASE WHEN((EVENTO = 'ABANDON') AND (param3::int > 30) )THEN 1 ELSE 0 END) AS ABANDONADAS31 ,SUM (CASE WHEN EVENTO IN ('COMPLETEAGENT','COMPLETECALLER') THEN 1 ELSE 0 END) AS ATENDIDAS_PA ,SUM (CASE WHEN EVENTO IN ('COMPLETEAGENT','COMPLETECALLER') AND to_number(param1,'999999999') <= '30' THEN 1 ELSE 0 END) AS ATENDIDAS_30 ,SUM (CASE WHEN EVENTO IN ('COMPLETEAGENT','COMPLETECALLER') AND to_number(param1,'999999999') > '30' THEN 1 ELSE 0 END) AS ATENDIDAS_31 ,SUM (CASE WHEN EVENTO IN ('TRANSFER') THEN 1 ELSE 0 END) AS TRANSFERIDAS ,SUM (CASE WHEN EVENTO IN ('CONNECT') AND to_number(param1,'999999999') > '3' THEN 1 ELSE 0 END) AS ESPERA ,SUM (CASE WHEN EVENTO IN ('CONNECT') AND to_number(param1,'999999999') > '1' THEN to_number(param1,'999999999') ELSE 0 END) AS TEMPO_ESPERA ,SUM (CASE WHEN EVENTO IN ('COMPLETEAGENT','COMPLETECALLER') AND to_number(param2,'999999999') > '1' THEN to_number(param2,'999999999') ELSE 0 END) AS TEMPO_ATENDIMENTO ,SUM (CASE WHEN( (EVENTO = 'ABANDON') ) THEN to_number(param3,'999999999') ELSE 0 END) AS TEMPO_ABANDONO ,count(distinct agente) as num_agente FROM ( SELECT c.hora_ini, c.hora_fim, c.periodo, a.calldate,b.fila,b.evento,b.param1,b.param2,b.param3,b.param4, case when(b.agente = 'NONE')THEN NULL ELSE b.agente END AS agente FROM pbx_hora_dia c INNER JOIN pbx_bilhetes a on cast(a.calldate as time) >= c.hora_ini and cast(a.calldate as time) < c.hora_fim and a.lastapp <> 'Transferred Call' INNER JOIN pbx_eventos_dacs b on b.uid2 = a.uniqueid INNER JOIN pbx_dacs d on d.nome = b.fila WHERE b.evento in ('ABANDON','COMPLETEAGENT','COMPLETECALLER', 'CONNECT','ENTERQUEUE','TRANSFER') AND a.data_bilhete = '$codMes' AND d.id = '$dac' ) AS DADOS GROUP BY calldate, hora_ini, hora_fim, periodo ) AS I on I.periodo = h.periodo ORDER BY 4"; //se adicionado bate os resultados com o relatorio enviado pelo //pablo para conferencia //AND date_part( 'dow', a.calldate) not in(0,6) // if(IsAdmin()) print $query; return $query; } */ ?>