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.
 
 
 
 
 
 

229 lines
11 KiB

<?php
require("jpgraph/jpgraph.php");
require("jpgraph/jpgraph_line.php");
//variaveis para manter o estado
$listaDacs = isset($_REQUEST["listaDacs"]) ? $_REQUEST["listaDacs"] : GetIdDacPadrao($dbcon, GetIdUser());
$dataIni = isset($_REQUEST["dataIni"]) ? $_REQUEST["dataIni"] : date('d/m/Y');
$dataFim = isset($_REQUEST["dataFim"]) ? $_REQUEST["dataFim"] : date('d/m/Y');
$tipoChamada = isset($_REQUEST["tipoChamada"]) ? $_REQUEST["tipoChamada"] : 1;
$listaServico = isset($_REQUEST["listaServico"]) ? $_REQUEST["listaServico"] : 0;
$cssBlock = "<style>
@media print {
.headSite, #rodapeSite, .filtro {
display: none;
}
}
</style>";
$linkGraph = '';
$printGraph = isset($_REQUEST['printGraph']) ? 1 : 0;
if ($printGraph) {
ob_clean();
$query = GetQuery($dataIni, $dataFim, $listaDacs, $listaServico);
$result = pg_query($query);
$abandonadas = array(0, 0, 0, 0, 0, 0, 0, 0);
$atendidas = array(0, 0, 0, 0, 0, 0, 0, 0);
$espera = array(0, 0, 0, 0, 0, 0, 0, 0);
$arLabel = array('TE<=10', '10<TE<=20', '20<TE<=30', '30<TE<=60', '60<TE<=120', '120<TE<=180', '180<TE<=300', '300<TE');
$dac = "";
// oferecidas originadas abandonadas nao_atendidas nao_atendidas atendidas efetuadas transbordadas
// total_oferecidas total_originadas total_abandonadas total_nao_atendidas total_atendidas total_efetuadas total_transbordadas
while ($row = pg_fetch_array($result, null, PGSQL_ASSOC)) {
$tipo = $row['tipo'];
if ($tipo == 'ab') {
$abandonadas = array($row['ate_10'], $row['ate_20'], $row['ate_30'], $row['ate_60'], $row['ate_120'], $row['ate_180'], $row['ate_300'], $row['ate_maior']);
} else if ($tipo == 'at') {
$atendidas = array($row['ate_10'], $row['ate_20'], $row['ate_30'], $row['ate_60'], $row['ate_120'], $row['ate_180'], $row['ate_300'], $row['ate_maior']);
} else if ($tipo == 'ie') {
$espera = array($row['ate_10'], $row['ate_20'], $row['ate_30'], $row['ate_60'], $row['ate_120'], $row['ate_180'], $row['ate_300'], $row['ate_maior']);
}
}
$totalAtd = array_sum($atendidas);
$totalAbd = array_sum($abandonadas);
$totalEsp = array_sum($espera);
for ($i = 0; $i < count($atendidas); $i++) {
$value = $atendidas[$i];
$atendidas[$i] = !$totalAtd ? 0 : round(($value / $totalAtd) * 100.0);
$value = $abandonadas[$i];
$abandonadas[$i] = !$totalAbd ? 0 : round(($value / $totalAbd) * 100.0);
$value = $espera[$i];
$espera[$i] = !$totalEsp ? 0 : round(($value / $totalEsp) * 100.0);
}
$graph = new Graph(1080, 650);
$graph->SetMargin(40, 20, 40, 40);
$graph->SetScale("textint");
$graph->img->SetAntiAliasing(false);
$graph->title->Set(sprintf("%s De: %s At<EFBFBD>: %s\nDac: %s Servi<EFBFBD>o: %s Emitido: %s Usu<EFBFBD>rio: %s", "Per<EFBFBD>odo", $dataIni, $dataFim, GetNomeDac($listaDacs), (!$listaServico ? 'Todos' : $listaServico), date("d/m/Y H:i:s"), GetLogin()));
$graph->SetBox(false);
$graph->img->SetAntiAliasing();
$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false, false);
$graph->yaxis->title->Set('Percentual');
$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xaxis->SetTickLabels($arLabel);
$graph->xgrid->SetColor('#E3E3E3');
$graph->xaxis->title->Set(sprintf("\nTotal Atendidas [ %s ] Total Abandonadas [ %s ] Total Espera [ %s ] ", FormataValor($totalAtd, 0), FormataValor($totalAbd, 0), FormataValor($totalEsp, 0)));
/*
* Constru<EFBFBD><EFBFBD>o das linhas.
*/
$atdPlot = new LinePlot($atendidas);
$graph->Add($atdPlot);
$atdPlot->SetColor("green");
$atdPlot->SetLegend('Chamadas Atendidas');
$abdPlot = new LinePlot($abandonadas);
$graph->Add($abdPlot);
$abdPlot->SetColor("red");
$abdPlot->SetLegend('Chamadas Abandonadas');
$espPlot = new LinePlot($espera);
$graph->Add($espPlot);
$espPlot->SetColor("orange");
$espPlot->SetLegend('Chamadas em Espera');
$graph->legend->SetFrameWeight(1);
$graph->Stroke();
exit;
} else if (IsPostBack()) {
if (!is_date($dataIni)) {
$jsStartup[] = "alert('Data inicial inv<EFBFBD>lida!');";
} else if (!is_date($dataFim)) {
$jsStartup[] = "alert('Data final inv<EFBFBD>lida!');";
} else {
$linkGraph = sprintf('<img id="relGrafico" src="index.php?idProg=301&dataIni=%s&dataFim=%s&listaDacs=%s&listaServico=%s&printGraph=1" border="0">', $dataIni, $dataFim, $listaDacs, $listaServico);
}
//echo GetQuery($dataIni, $dataFim, $listaDacs, $listaServico);
}
// Carrega servicos.
$listaServico = GetIdentRota($dbcon, $listaServico);
//carrega dacs
$dacs = GetDac($dbcon, $listaDacs, '', 1);
$smarty->assign('imp', $i);
$smarty->assign('dacs', $dacs);
$smarty->assign('dataIni', $dataIni);
$smarty->assign('dataFim', $dataFim);
$smarty->assign('erro', $erro);
$smarty->assign('tipoChamada', $tipoChamada);
$smarty->assign('linkGraph', $linkGraph);
$smarty->assign('listaServico', $listaServico);
GetTemplate($smarty, 'analise/desempenhoServico.tpl');
function GetQuery($dataIni, $dataFim, $dac, $serv) {
$dataIni = FormatDtMssql($dataIni);
$dataFim = FormatDtMssql($dataFim);
$query = "SELECT 'ab' as tipo
,SUM (CASE WHEN( (strtoint(param3) <= 10)) THEN 1 ELSE 0 END) as ate_10
,SUM (CASE WHEN( (strtoint(param3) > 10) AND (strtoint(param3) <= 20) ) THEN 1 ELSE 0 END) as ate_20
,SUM (CASE WHEN( (strtoint(param3) > 20) AND (strtoint(param3) <= 30) ) THEN 1 ELSE 0 END) as ate_30
,SUM (CASE WHEN( (strtoint(param3) > 30) AND (strtoint(param3) <= 60) ) THEN 1 ELSE 0 END) as ate_60
,SUM (CASE WHEN( (strtoint(param3) > 60) AND (strtoint(param3) <= 120) ) THEN 1 ELSE 0 END) as ate_120
,SUM (CASE WHEN( (strtoint(param3) > 120) AND (strtoint(param3) <= 180) ) THEN 1 ELSE 0 END) as ate_180
,SUM (CASE WHEN( (strtoint(param3) > 180) AND (strtoint(param3) <= 300) ) THEN 1 ELSE 0 END) as ate_300
,SUM (CASE WHEN( (strtoint(param3) > 300) ) THEN 1 ELSE 0 END) as ate_MAIOR
FROM (
SELECT to_char(a.calldate,'YYYY-MM-DD') AS DATA
,a.calldate
,b.fila
,b.evento
,b.param1
,b.param2
,b.param3
,b.param4
FROM pbx_eventos_dacs b, pbx_bilhetes a, pbx_dacs c, pbx_servicos_registra d
where a.uniqueid = b.uid2
and c.nome = b.fila
and d.uniqueid = b.uid2
and a.lastapp <> 'Transferred Call'
and b.evento = 'ABANDON'
and a.data_bilhete >= '$dataIni'
and a.data_bilhete <= '$dataFim'\n";
if ($dac)
$query .= " AND c.id = '$dac'\n";
if ($serv)
$query .= " AND d.serv_id = '$serv'\n";
$query .= " ) AS DADOS
UNION ALL
SELECT 'at' as tipo
,SUM (CASE WHEN( (strtoint(param1) <= 10)) THEN 1 ELSE 0 END) as ate_10
,SUM (CASE WHEN( (strtoint(param1) > 10) AND (strtoint(param1) <= 20) ) THEN 1 ELSE 0 END) as ate_20
,SUM (CASE WHEN( (strtoint(param1) > 20) AND (strtoint(param1) <= 30) ) THEN 1 ELSE 0 END) as ate_30
,SUM (CASE WHEN( (strtoint(param1) > 30) AND (strtoint(param1) <= 60) ) THEN 1 ELSE 0 END) as ate_60
,SUM (CASE WHEN( (strtoint(param1) > 60) AND (strtoint(param1) <= 120) ) THEN 1 ELSE 0 END) as ate_120
,SUM (CASE WHEN( (strtoint(param1) > 120) AND (strtoint(param1) <= 180) ) THEN 1 ELSE 0 END) as ate_180
,SUM (CASE WHEN( (strtoint(param1) > 180) AND (strtoint(param1) <= 300) ) THEN 1 ELSE 0 END) as ate_300
,SUM (CASE WHEN( (strtoint(param1) > 300) ) THEN 1 ELSE 0 END) as ate_MAIOR
FROM (
SELECT to_char(a.calldate,'YYYY-MM-DD') AS DATA, a.calldate,b.fila,
b.evento,b.param1,b.param2,b.param3,b.param4
FROM pbx_eventos_dacs b, pbx_bilhetes a, pbx_dacs c, pbx_servicos_registra d
WHERE a.uniqueid = b.uid2
and c.nome = b.fila
and d.uniqueid = b.uid2
and a.lastapp <> 'Transferred Call'
AND b.evento IN ('COMPLETEAGENT','COMPLETECALLER','TRANSFER')
AND a.data_bilhete >= '$dataIni'
AND a.data_bilhete <= '$dataFim'\n";
if ($dac)
$query .= " AND c.id = '$dac'\n";
if ($serv)
$query .= " AND d.serv_id = '$serv'\n";
$query .= " ) AS DADOS
UNION ALL
SELECT 'ie' as tipo
,SUM (CASE WHEN( (strtoint(param1) <= 10)) THEN 1 ELSE 0 END) as ate_10
,SUM (CASE WHEN( (strtoint(param1) > 10) AND (strtoint(param1) <= 20) ) THEN 1 ELSE 0 END) as ate_20
,SUM (CASE WHEN( (strtoint(param1) > 20) AND (strtoint(param1) <= 30) ) THEN 1 ELSE 0 END) as ate_30
,SUM (CASE WHEN( (strtoint(param1) > 30) AND (strtoint(param1) <= 60) ) THEN 1 ELSE 0 END) as ate_60
,SUM (CASE WHEN( (strtoint(param1) > 60) AND (strtoint(param1) <= 120) ) THEN 1 ELSE 0 END) as ate_120
,SUM (CASE WHEN( (strtoint(param1) > 120) AND (strtoint(param1) <= 180) ) THEN 1 ELSE 0 END) as ate_180
,SUM (CASE WHEN( (strtoint(param1) > 180) AND (strtoint(param1) <= 300) ) THEN 1 ELSE 0 END) as ate_300
,SUM (CASE WHEN( (strtoint(param1) > 300) ) THEN 1 ELSE 0 END) as ate_MAIOR
FROM (
SELECT to_char(a.calldate,'YYYY-MM-DD') AS DATA, a.calldate,b.fila,
b.evento,b.param1,b.param2,b.param3,b.param4
FROM pbx_eventos_dacs b, pbx_bilhetes a, pbx_dacs c, pbx_servicos_registra d
WHERE a.uniqueid = b.uid2
and c.nome = b.fila
and d.uniqueid = b.uid2
and a.lastapp <> 'Transferred Call'
and b.evento = 'CONNECT'
AND strtoint(param1) > 3
AND a.data_bilhete >= '$dataIni'
AND a.data_bilhete <= '$dataFim'";
if ($dac)
$query .= " AND c.id = '$dac'\n";
if ($serv)
$query .= " AND d.serv_id = '$serv'\n";
$query .= " ) AS DADOS ORDER BY 1 ";
//if(IsAdmin()){ echo $query; exit; }
return $query;
}