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.

102 lines
2.8 KiB

<?php
$tpLayout = 1;
$org_id = $_SESSION['SSEmpresaPadrao'];
$matricula = $_GET["matricula"];
$nomeTpl = 'relAgtMotivoPausa.tpl';
$linha = ' <tr align="center">
<td nowrap align="center" class="headData">%s</td>
<td nowrap align="center" class="headData">%s</td>
<td nowrap align="center" class="headData">%s</td>
<td nowrap align="center" class="headData">%s</td>
<td nowrap align="center" class="headData">%s</td>
<td align="left" class="headData">%s</td>
</tr>';
$query = " SELECT
a.entrada_pausa,
a.saida_pausa,
(COALESCE(a.saida_pausa,
now()) - a.entrada_pausa) AS duracao,
b.id,
b.motivo,
a.org_id,
EXTRACT(EPOCH
FROM
(a.saida_pausa - a.entrada_pausa)) AS dura_segundos,
CASE
WHEN(
(a.id = (
SELECT
max(id)
FROM
pbx_eventos_agentes
WHERE
entrada_pausa::date = a.entrada_pausa::date
AND matricula = a.matricula
AND id_dac = a.id_dac
AND org_id = a.org_id
))
AND ((
SELECT
count(*)
FROM
pbx_supervisor_agentes
WHERE
matricula = '$matricula'
AND org_id = a.org_id
AND status = 'PAUSA') > 0)
)THEN 1
ELSE 0
END AS em_pausa,
a.pausa_produtiva,
a.pausa_produtiva_obs
FROM
pbx_eventos_agentes a,
pbx_motivos_pausas b
WHERE
b.id = a.id_motivo_pausa
AND entrada_pausa::date = now()::date
AND matricula = '$matricula'
AND a.org_id = $org_id;";
//if(IsAdmin()) echo $query;
$result = pg_query($dbcon, $query);
$numrow = 0;
$linhas = "";
$duracaoTotal = 0;
$duraProd = 0;
$duraNormal = 0;
$numProd = 0;
$numNormal = 0;
while ($row = pg_fetch_array($result)) {
$linhas .= sprintf($linha, $row["entrada_pausa"], $row["saida_pausa"], $row["duracao"], ($row["em_pausa"] ? ('*' . $row["motivo"]) : $row["motivo"]), $row["pausa_produtiva"] ? 'Sim' : 'N<EFBFBD>o', $row["pausa_produtiva_obs"]);
$duracaoTotal += $row["dura_segundos"];
if ($row["pausa_produtiva"]) {
$duraProd += $row["dura_segundos"];
$numProd++;
} else {
$duraNormal += $row["dura_segundos"];
$numNormal++;
}
$numrow++;
}
$duracaoTotal = SecondToStrTime($duracaoTotal);
$duraProd = SecondToStrTime($duraProd);
$duraNormal = SecondToStrTime($duraNormal);
$linha = " <tr align=\"center\">
<th nowrap align=\"center\">Totaliza<EFBFBD><EFBFBD>o</th>
<th nowrap colspan=\"5\" align=\"center\">[ Produtiva: $duraProd ($numProd) ] [ N<EFBFBD>o Produtiva: $duraNormal ($numNormal) ] [ Total: $duracaoTotal ($numrow) ]</th>
</tr>
<tr align=\"center\">
<td nowrap align=\"left\" colspan=\"7\" >*Em pausa neste momento</td>
</tr>";
$linhas .= $linha;
$smarty->assign('linhas', $linhas);
GetTemplate($smarty, $nomeTpl);
?>