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.

122 lines
4.2 KiB

<?php
$tpLayout = 1;
$dataIni = $_GET["dataIni"];
$dataFim = $_GET["dataFim"];
$dacs = $_GET["dacs"];
$listas = $_GET["listas"];
$agente = $_GET["agente"];
$cmpId = $_GET["cmpId"];
$listId = $_GET["listId"];
$matricula = $_GET["matricula"];
$totalPausa = $_GET["totalPausa"];
$erro = '';
$_SESSION["dataIni"] = $dataIni;
$_SESSION["dataFim"] = $dataFim;
$_SESSION["dac"] = $dacs;
$templateName = 'discador/desempenhoDiscadorPausas.tpl';
$linha = "";
$linhas = "";
$rows = array();
$query = GetQuery($cmpId, $listId, $dataIni, $dataFim, $matricula);
$result = pg_query($dbcon, $query);
$qtPausa = 0;
$somaTempo = 0;
$imp = 0;
$buffDados = array();
while ($dados = pg_fetch_array($result)) {
$inicio = FormataDBDataHora($dados["entrada_pausa"]);
$fim = $dados["saida_pausa"] ? FormataDBDataHora($dados["saida_pausa"]) : FormataDBDataHora($dados["entrada_pausa"]);
$motivo = $dados["motivo"];
$tempo = $dados["tempo_operacao"];
$somaTempo += $tempo;
$qtPausa++;
$imp++;
$displayTempo = SecondToStrTime($tempo);
$linha = "<tr>
<td align=\"center\">$inicio</td>
<td align=\"center\">$fim</td>
<td align=\"center\"> $motivo</td>
<td align=\"center\">$displayTempo</td>
</tr>";
$buffDados[] = $linha;
$linhas .= $linha;
}
$displayTempo = SecondToStrTime($somaTempo);
$linha = "<tr>
<th align=\"center\">Quantidade</th>
<td align=\"center\">$qtPausa</td>
<th align=\"center\"> Tempo</th>
<td align=\"center\">$displayTempo</td>
</tr>";
$buffDados[] = $linha;
$linhas .= $linha;
$_SESSION["SSlinhasPausasDiscador"] = $buffDados;
//agrupado
$query = GetQuery($cmpId, $listId, $dataIni, $dataFim, $matricula, 1);
$result = pg_query($dbcon, $query);
$linhaAgrup = "";
while ($dados = pg_fetch_array($result)) {
$motivo = $dados["motivo"];
$tempo = $dados["tempo_operacao"];
$qtAgrup = $dados["qtde"];
$displayTempoAgrup = SecondToStrTime($tempo);
$linhaAgrup .= "<tr>
<td align=\"center\"> $motivo</td>
<td align=\"center\"> $qtAgrup</td>
<td align=\"center\">$displayTempoAgrup</td>
</tr>";
}
$_SESSION["SSlinhasPausasDiscadorAgp"] = $linhaAgrup;
//Atualiza template
$smarty->assign("dacs", $dacs);
$smarty->assign("agente", $agente);
$smarty->assign("listas", $listas);
$smarty->assign('dataIni', $dataIni);
$smarty->assign('dataFim', $dataFim);
$smarty->assign("linha", $linhas);
$smarty->assign("linhaAgrupado", $linhaAgrup);
$smarty->assign("imp", $imp);
//Seta o template
GetTemplate($smarty, $templateName);
function GetQuery($cmpId, $listId, $dtIni, $dtFim, $matricula, $tipo = 0) {
$idSessao = session_id();
if ($tipo == 0) {
$ret = " select a.matricula, a.inicio_operacao as entrada_pausa, a.final_oepracao as saida_pausa, c.apelido, a.operacao as motivo, extract(epoch from ((a.final_oepracao - a.inicio_operacao))) as tempo_operacao
from pbx_desempenho_discador a, pbx_usuarios c
where c.matricula = a.matricula
and a.operacao not in('livre', 'atendimento')
and id_dac = '$cmpId'
and a.id_sessao = '$idSessao'
and a.matricula = case when('$matricula' = '0')then a.matricula else '$matricula' end
order by 1, 2;";
} else {
$ret = "select a.matricula, a.operacao as motivo, count(*) as qtde, sum( extract(epoch from ((a.final_oepracao - a.inicio_operacao)))) as tempo_operacao
from pbx_desempenho_discador a, pbx_usuarios c
where c.matricula = a.matricula
and a.operacao not in('livre', 'atendimento')
and id_dac = '$cmpId'
and a.id_sessao = '$idSessao'
and a.matricula = case when('$matricula' = '0')then a.matricula else '$matricula' end
group by a.matricula, a.operacao
order by 3 desc";
}
return $ret;
}
?>