forked from SimplesIP/pabx-app
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.
742 lines
31 KiB
742 lines
31 KiB
<?php |
|
|
|
/** ************************************************************************ |
|
* |
|
* RELATÓRIO AGENTE HORAS |
|
* Autor |
|
* Lucas Awade |
|
* |
|
* ************************************************************************* |
|
* Definições do Projeto |
|
* Nome: RelAgenteHoras |
|
* Data início: 03/08/2018 |
|
* Equipe: Amarildo Pereira |
|
* Descrição: Gera relatório de acordo com o tempo que o agente ficou logado |
|
* no sistema, relacionando seus momentos de saída e entrada. |
|
* |
|
* Pré-requisito: As querys de banco de dados tem que retornar com ordenagem |
|
* de acordo com os apelidos dos agentes para que o relatório tipo análitico |
|
* tenha a formatação correta; |
|
* Solução do pré-requisito: Colocar a query com ORDER BY apelido; |
|
* |
|
* ************************************************************************* |
|
* Copyright (c) 2018, Simples IP |
|
* ************************************************************************* |
|
*/ |
|
include_once 'util/relatoriosBase.php'; |
|
|
|
class RelAgenteHoras extends Relatorios { |
|
|
|
private $___tipoRelatorio; |
|
private $___agente; |
|
|
|
public function __construct($idProg, $dbcon, $incDac) { |
|
parent::__construct($idProg, $dbcon, $incDac); |
|
$this->___tipoRelatorio = isset($_REQUEST['relTipo']) ? $_REQUEST['relTipo'] : 0; |
|
$this->___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0; |
|
$this->___agente = isset($_POST["listaAgente"]) ? $_POST["listaAgente"] : null; |
|
} |
|
|
|
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 = '<a href="index.php?idProg=%s&media=%s&tipoRelatorio=%s"><img src="imgSite/%s" alt="Clique aqui para imprimir!" width="24" height="24" border="0"></a>'; |
|
$prtHtml = "<a href=\"javaScript:NovaJanela('index.php?idProg=%s&media=%s&tipoRelatorio=%s', '%s', '720', '700', 'scrollbars=YES');\"><img src=\"imgSite/%s\" alt=\"Clique aqui para imprimir!\" width=\"24\" height=\"24\" border=\"0\"></a>"; |
|
$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"'; |
|
|
|
if ($this->___dataIni && $this->___dataFim) { |
|
$agentes = $this->retornaAgente(); |
|
} |
|
/* |
|
* Personalise esta função se necessitar de outras operações de filtro. |
|
*/ |
|
$filtro = '<table border="0" cellspacing="1" cellpadding="1">'; |
|
/* |
|
* Rotulos. |
|
*/ |
|
$filtro .= '<tr>'; |
|
if ($this->GetIncDac()) |
|
$filtro .= '<td>Fila</td>'; |
|
$filtro .= '<td>Data Inicial</td>'; |
|
$filtro .= '<td>Data Final </td>'; |
|
$filtro .= '<td>Agente </td>'; |
|
$filtro .= '<td> <input name="relTipo" type="checkbox" id="relTipo" value="1" %s />Analítico</td>'; |
|
$filtro .= '<td align="center" valign="middle"> </td>'; |
|
$filtro .= '</tr>'; |
|
|
|
/* |
|
* Valores. |
|
*/ |
|
$filtro .= '<tr>'; |
|
if ($this->GetIncDac()) |
|
$filtro .= sprintf('<td>%s</td>', $dacs); |
|
$filtro .= '<td><input name="dataIni" id="dataIni" type="text" size="15" maxlength="10" value="%s" onkeyup="formataData(this)" title="dd/mm/aaaa"></td>'; |
|
$filtro .= '<td><input name="dataFim" id="dataFim" type="text" size="15" maxlength="10" value="%s" onkeyup="formataData(this)" title="dd/mm/aaaa"></td>'; |
|
$filtro .= "<td>$agentes</td>"; |
|
$filtro .= '<td><input type="submit" name="btConsulta" id="btConsulta" value="Consultar"></td>'; |
|
$filtro .= '<td>%s</td>'; |
|
$filtro .= '</tr>'; |
|
$filtro .= '</table>'; |
|
|
|
/* |
|
* Guarda os filtros passados para recuperar na emissão dos relatórios 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() { |
|
$dt = FormatDtMssql($this->___dataIni); |
|
$dtFim = FormatDtMssql($this->___dataFim); |
|
$dac = $this->___dac; |
|
$agente = $this->___agente ? QuotedStr($this->___agente) : "null"; |
|
|
|
$query = "CREATE TEMPORARY TABLE agente_operacao_Ciosp ( |
|
id_dac int, |
|
fila varchar(50) not null, |
|
apelido varchar(30), |
|
matricula varchar(4) not null, |
|
data date not null, |
|
login timestamp, |
|
logoff timestamp, |
|
tempoLogin int, |
|
num_pausa int, |
|
tempo_pausa int, |
|
num_pausa_prod int, |
|
tempo_pausa_prod int, |
|
CONSTRAINT \"pkAgtOpera\" PRIMARY KEY( fila, matricula, data )); |
|
|
|
insert into agente_operacao_Ciosp |
|
select c.id as id_dac, c.nome as fila, b.apelido, a.matricula, cast(a.login as date) as data, min(login) as login, |
|
max(logoff) as logoff, sum(EXTRACT(epoch from ((logoff) - (login)))) as tempoLogin, |
|
0 as num_pausa, 0 as tempo_pausa, 0 as num_pausa_prod, 0 as tempo_pausa_prod |
|
from pbx_eventos_agentes a, pbx_usuarios b, pbx_dacs c |
|
where b.matricula = a.matricula |
|
and c.id = a.id_dac |
|
and a.id_dac = coalesce('$dac', a.id_dac) |
|
and cast(a.login as date) >= '$dt' |
|
and cast(a.login as date) <= '$dtFim' |
|
and b.matricula = coalesce($agente, b.matricula) |
|
group by 1, 2, 3, 4, 5; |
|
|
|
CREATE TEMPORARY TABLE agente_pausa_Ciosp AS |
|
select a.id_dac, b.apelido, cast(a.entrada_pausa as date) as data, |
|
sum(case when(a.pausa_produtiva = 0)then 1 else 0 end) as num_pausa, |
|
sum(case when(a.pausa_produtiva = 1)then 1 else 0 end) as num_pausa_prod, |
|
sum(EXTRACT(epoch from ( case when(a.pausa_produtiva = 0)then saida_pausa - entrada_pausa else '00:00:00' end ))) as tempo_pausa, |
|
sum(EXTRACT(epoch from ( case when(a.pausa_produtiva = 1)then saida_pausa - entrada_pausa else '00:00:00' end ))) as tempo_pausa_prod |
|
from pbx_eventos_agentes a, pbx_usuarios b |
|
where b.matricula = a.matricula |
|
and a.id_dac = coalesce('$dac', a.id_dac) |
|
and cast(a.entrada_pausa as date) >= '$dt' |
|
and cast(a.entrada_pausa as date) <= '$dtFim' |
|
and b.matricula = coalesce($agente, b.matricula) |
|
group by a.id_dac, b.apelido, cast(a.entrada_pausa as date); |
|
|
|
update agente_operacao_Ciosp |
|
set num_pausa = b.num_pausa, |
|
tempo_pausa = b.tempo_pausa, |
|
num_pausa_prod = b.num_pausa_prod, |
|
tempo_pausa_prod = b.tempo_pausa_prod |
|
from agente_pausa_Ciosp as b |
|
where agente_operacao_Ciosp.apelido = b.apelido |
|
and agente_operacao_Ciosp.data = b.data |
|
and agente_operacao_Ciosp.id_dac = b.id_dac;"; |
|
|
|
if ($this->___tipoRelatorio) { |
|
$query .= "select id_dac, fila, apelido, matricula, data, login, logoff, tempologin, |
|
num_pausa, tempo_pausa,num_pausa_prod, tempo_pausa_prod |
|
from agente_operacao_Ciosp order by apelido, data"; |
|
} else { |
|
$query .= "select id_dac, fila, apelido, matricula, sum(tempologin) as tempologin |
|
from agente_operacao_Ciosp group by 1,2,3,4 order by apelido"; |
|
} |
|
$result = $this->___GetQuery($query); |
|
$row = pg_fetch_all($result); |
|
|
|
$this->SetData($row ? $row : array()); |
|
$this->SetData($this->___agente ? $this->___agente : 0); |
|
} |
|
|
|
protected function ___PreparaCsv() { |
|
$dataRel = array(); |
|
$filtro = $this->___FiltrosRelatorio(); |
|
|
|
/* |
|
* Inicia o relatório. |
|
*/ |
|
$dataRel[] = GenerateCsvFromArray($filtro); |
|
|
|
if (!$this->___tipoRelatorio) { |
|
$dadosCabecalio = array('Agente' => 'align="center"', 'Duracao' => 'align="center"'); |
|
$dadosField = array('apelido' => 'align="center"', 'tempologin' => 'align="center"'); |
|
|
|
/* |
|
* Monta a linha de cabecalio. |
|
*/ |
|
$dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio)); |
|
|
|
$somaTempo = 0; |
|
$somaQuantidade = 0; |
|
/* |
|
* Linhas de dados. |
|
*/ |
|
foreach ($this->GetData()[0] as $row) { |
|
$somaTempo += $row["tempologin"]; |
|
$somaQuantidade ++; |
|
$row["tempologin"] = SecondToStrTime($row["tempologin"]); |
|
|
|
// Formata linha de dados. |
|
$linha = array(); |
|
foreach ($dadosField as $key => $value) { |
|
$linha[] = $row["$key"]; |
|
} |
|
|
|
$dataRel[] = GenerateCsvFromArray($linha); |
|
} |
|
$this->___dataRel[] = $dataRel; |
|
|
|
$linhaTotal = array(); |
|
$linhaTotal[] = 'Total: ' . $somaQuantidade; |
|
$linhaTotal[] = 'Duracao: ' . SecondToStrTime($somaTempo); |
|
$dataRelTotal[] = GenerateCsvFromArray($linhaTotal); |
|
$this->___dataRel[] = $dataRelTotal; |
|
} else { |
|
$dadosCabecalio = array('Agente' => 'align="center"', 'Inicio' => 'align="center"', 'Termino' => 'align="center"', 'Duracao' => 'align="center"'); |
|
$dadosField = array('apelido' => 'align="center"', 'login' => 'align="center"', 'logoff' => 'align="center"', 'tempologin' => 'align="center"'); |
|
$linhaTotal = array(); |
|
$dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio)); |
|
|
|
$ultApelido = ''; |
|
$somaTempo = 0; |
|
$somaQuantidade = 0; |
|
|
|
foreach ($this->GetData()[0] as $row) { |
|
$count++; |
|
|
|
if ($count != 1) { |
|
if ($ultApelido != $row['apelido']) { |
|
$linhaTotal = array('Total: ' . $somaQuantidade, '', '', 'Duracao: ' . SecondToStrTime($somaTempo)); |
|
$dataRel[] = GenerateCsvFromArray($linhaTotal); |
|
|
|
unset($linhaTotal); |
|
unset($somaTempo); |
|
unset($somaQuantidade); |
|
|
|
$linhaVoid = array('', '', '', ''); |
|
$dataRel[] = GenerateCsvFromArray($linhaVoid); |
|
unset($linhaVoid); |
|
$dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio)); |
|
} |
|
} |
|
|
|
$somaTempo += $row["tempologin"]; |
|
$somaQuantidade ++; |
|
$row["tempologin"] = SecondToStrTime($row["tempologin"]); |
|
$row["login"] = date('d/m/Y H:i:s', strtotime($row["login"])); |
|
$row["logoff"] = date('d/m/Y H:i:s', strtotime($row["logoff"])); |
|
|
|
// Formata linha de dados. |
|
$linha = array(); |
|
foreach ($dadosField as $key => $value) { |
|
$linha[] = $row["$key"]; |
|
} |
|
$dataRel[] = GenerateCsvFromArray($linha); |
|
$ultApelido = $row['apelido']; |
|
|
|
if (count($this->GetData()[0]) == $count) { |
|
$linhaTotal = array('Total: ' . $somaQuantidade, '', '', 'Duracao: ' . SecondToStrTime($somaTempo)); |
|
$dataRel[] = GenerateCsvFromArray($linhaTotal); |
|
} |
|
} |
|
$this->___dataRel[] = $dataRel; |
|
} |
|
} |
|
|
|
protected function ___PreparaExcel() { |
|
$nomeDac = ""; |
|
$dataRel = array(); |
|
$dataAgrup = 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) { |
|
$dadosCabecalio = array('Agente', 'Duracao'); |
|
$dadosField = array('apelido', 'tempologin'); |
|
|
|
/* |
|
* Monta a linha de cabecalio. |
|
*/ |
|
$linha = array('LABEL'); |
|
foreach ($dadosCabecalio as $value) { |
|
$linha[] = $value; |
|
} |
|
$dataRel[] = $linha; |
|
|
|
$somaTempo = 0; |
|
$somaQuantidade = 0; |
|
/* |
|
* Linhas de dados. |
|
*/ |
|
foreach ($this->GetData()[0] as $row) { |
|
$somaTempo += $row["tempologin"]; |
|
$somaQuantidade ++; |
|
$row["tempologin"] = SecondToStrTime($row['tempologin']); |
|
|
|
// Formata linha de dados. |
|
$linha = array('DADOS'); |
|
foreach ($dadosField as $key) { |
|
$linha[] = $row["$key"]; |
|
} |
|
$dataRel[] = $linha; |
|
} |
|
|
|
$linha = array('LABEL', 'Total: ' . $somaQuantidade, SecondToStrTime($somaTempo)); |
|
$dataRel[] = $linha; |
|
|
|
$this->___dataRel[] = $dataRel; |
|
} else { |
|
$dadosCabecalio = array('Agente', 'Inicio', 'Termino', 'Duracao'); |
|
$dadosField = array('apelido', 'login', 'logoff', 'tempologin'); |
|
$ultApelido = ''; |
|
/* |
|
* Monta a linha de cabecalio. |
|
*/ |
|
$linha = array('LABEL'); |
|
foreach ($dadosCabecalio as $value) { |
|
$linha[] = $value; |
|
} |
|
$dataRel[] = $linha; |
|
|
|
$somaTempo = 0; |
|
$somaQuantidade = 0; |
|
/* |
|
* Linhas de dados. |
|
*/ |
|
foreach ($this->GetData()[0] as $row) { |
|
$count++; |
|
|
|
if ($count != 1) { |
|
if ($ultApelido != $row['apelido']) { |
|
$linha1 = array('LABEL', 'Total: ' . $somaQuantidade, '', '', 'Duracao: ' . SecondToStrTime($somaTempo)); |
|
$dataRel[] = $linha1; |
|
$linha2 = array('LABEL', '', '', '', ''); |
|
$dataRel[] = $linha2; |
|
|
|
$linha = array('LABEL'); |
|
foreach ($dadosCabecalio as $value) { |
|
$linha[] = $value; |
|
} |
|
$dataRel[] = $linha; |
|
|
|
unset($somaTempo); |
|
unset($somaQuantidade); |
|
} |
|
} |
|
$somaTempo += $row["tempologin"]; |
|
$somaQuantidade ++; |
|
$row["tempologin"] = SecondToStrTime($row['tempologin']); |
|
$row["login"] = date('d/m/Y H:i:s', strtotime($row["login"])); |
|
$row["logoff"] = date('d/m/Y H:i:s', strtotime($row["logoff"])); |
|
|
|
$linha = array('DADOS'); |
|
foreach ($dadosField as $key) { |
|
$linha[] = $row["$key"]; |
|
} |
|
$dataRel[] = $linha; |
|
$ultApelido = $row['apelido']; |
|
|
|
if (count($this->GetData()[0]) == $count) { |
|
$linha1 = array('LABEL', 'Total: ' . $somaQuantidade, '', '', 'Duracao: ' . SecondToStrTime($somaTempo)); |
|
$dataRel[] = $linha1; |
|
} |
|
} |
|
|
|
$this->___dataRel[] = $dataRel; |
|
} |
|
} |
|
|
|
protected function ___PreparaGrid() { |
|
|
|
if (!$this->___tipoRelatorio) { |
|
$dadosCabecalio = array( |
|
'Agente' => 'align="left"', |
|
'Duração' => 'align="center"' |
|
); |
|
|
|
$dadosField = array( |
|
'apelido' => 'align="left"', |
|
'tempologin' => 'align="center"' |
|
); |
|
|
|
$dataRel[] = '<table width="70%" cellpadding="2" class="grid">'; |
|
|
|
/* |
|
* Monta a linha de cabecalio. |
|
*/ |
|
$linha = '<tr>'; |
|
foreach ($dadosCabecalio as $key => $value) { |
|
$linha .= sprintf("<th %s>%s</th>", $value, $key); |
|
} |
|
$linha .= "</tr>"; |
|
$dataRel[] = $linha; |
|
|
|
/* |
|
* Verifica se retornou dados |
|
*/ |
|
if (!IsPostBack() || !count($this->GetData()[0])) { |
|
$dataRel[] = sprintf("<tr><td align=\"center\" colspan=\"%s\">%s<td></tr></table>", count($dadosCabecalio) - 1, (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!')); |
|
$this->___dataRel[] = $dataRel; |
|
return; |
|
} |
|
|
|
$somaTempo = 0; |
|
$somaQuantidade = 0; |
|
/* |
|
* Linhas de dados. |
|
*/ |
|
foreach ($this->GetData()[0] as $row) { |
|
$somaTempo += $row["tempologin"]; |
|
$somaQuantidade ++; |
|
$row["tempologin"] = SecondToStrTime($row["tempologin"]); |
|
|
|
// Formata linha de dados. |
|
$linha = "<tr>"; |
|
foreach ($dadosField as $key => $value) { |
|
$linha .= sprintf("<td %s>%s</td>", $value, $row["$key"]); |
|
} |
|
$linha .= "</tr>"; |
|
$dataRel[] = $linha; |
|
} |
|
/* |
|
* Linha de totalizacao. |
|
*/ |
|
$linha = '<tr><th align="left">Total: %s</th><th align="center" >Duração: %s</th></tr>'; |
|
$dataRel[] = sprintf($linha, $somaQuantidade, SecondToStrTime($somaTempo)); |
|
|
|
/* |
|
* Fecha relatorio. |
|
*/ |
|
$dataRel[] = '</table>'; |
|
$this->___dataRel[] = $dataRel; |
|
} else { |
|
/* * ************************************************************ |
|
* ************************************************************* |
|
* IMPRESSÃO DE RELÁTÓRIO AGENTES HORAS TIPO ANÁLITICO |
|
* ************************************************************* |
|
* ************************************************************* |
|
*/ |
|
|
|
|
|
$dadosCabecalio = array( |
|
'Agente' => 'align="left"', |
|
'Início' => 'align="center"', |
|
'Término' => 'align="center"', |
|
'Duração' => 'align="center"' |
|
); |
|
|
|
$dadosField = array( |
|
'apelido' => 'align="left"', |
|
'login' => 'align="center"', |
|
'logoff' => 'align="center"', |
|
'tempologin' => 'align="center"' |
|
); |
|
|
|
$dataRel[] = '<table width="70%" cellpadding="2" class="grid">'; |
|
|
|
/* |
|
* Monta a linha de cabecalio. |
|
*/ |
|
$linha = '<tr>'; |
|
foreach ($dadosCabecalio as $key => $value) { |
|
$linha .= sprintf("<th %s>%s</th>", $value, $key); |
|
} |
|
$linha .= "</tr>"; |
|
$dataRel[] = $linha; |
|
|
|
/* |
|
* Verifica se retornou dados |
|
*/ |
|
if (!IsPostBack() || !count($this->GetData()[0])) { |
|
$dataRel[] = sprintf("<tr><td align=\"center\" colspan=\"%s\">%s<td></tr></table>", count($dadosCabecalio) - 1, (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!')); |
|
$this->___dataRel[] = $dataRel; |
|
return; |
|
} |
|
|
|
$somaTempo = 0; |
|
$somaQuantidade = 0; |
|
$ultApelido = ''; |
|
$z = 0; |
|
/* |
|
* Linhas de dados. |
|
*/ |
|
foreach ($this->GetData()[0] as $row) { |
|
$tempo = $row["tempologin"]; |
|
|
|
|
|
$row["tempologin"] = SecondToStrTime($row["tempologin"]); |
|
$row["login"] = date('d/m/Y H:i:s', strtotime($row["login"])); |
|
$row["logoff"] = date('d/m/Y H:i:s', strtotime($row["logoff"])); |
|
|
|
// Formata linha de dados. |
|
$linha = "<tr>"; |
|
if ($row['apelido'] != $ultApelido) { |
|
if ($z != 0) { |
|
$linhaTotal = '<tr><th align="left" colspan="3">Total %s: %s</th><th align="center" >Duração: %s</th></tr>'; |
|
$dataRel[] = sprintf($linhaTotal, $ultApelido, $somaQuantidade, SecondToStrTime($somaTempo)); |
|
unset($somaQuantidade); |
|
unset($somaTempo); |
|
$linha .= sprintf("<td colspan=\"%s\"> </td>", count($dadosField)); |
|
$linha .= "</tr><tr>"; |
|
} |
|
} |
|
|
|
$somaTempo += $tempo; |
|
$somaQuantidade ++; |
|
|
|
foreach ($dadosField as $key => $value) { |
|
$linha .= sprintf("<td %s>%s</td>", $value, $row["$key"]); |
|
} |
|
if (count($this->GetData()[0]) == $z + 1) { |
|
$linha .= "</tr><tr>"; |
|
$linha .= sprintf('<th align="left" colspan="3">Total %s: %s</th><th align="center" >Duração: %s</th>', $row['apelido'], $somaQuantidade, SecondToStrTime($somaTempo)); |
|
} |
|
|
|
$linha .= "</tr>"; |
|
$ultApelido = $row['apelido']; |
|
$z++; |
|
|
|
$dataRel[] = $linha; |
|
} |
|
|
|
/* |
|
* Fecha relatorio. |
|
*/ |
|
$dataRel[] = '</table>'; |
|
$this->___dataRel[] = $dataRel; |
|
} |
|
} |
|
|
|
protected function ___PreparaHtml() { |
|
|
|
} |
|
|
|
protected function ___PreparaPdf() { |
|
$nomeDac = ""; |
|
list($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio) = $_SESSION["SSstorageFiltros"]; |
|
/** |
|
* TABELA DADOS PRINCIPAIS |
|
*/ |
|
$somaQtd = 0; |
|
$somaTempo = 0; |
|
$dados = array(); |
|
$ultApelido = ''; |
|
$x = 0; |
|
|
|
|
|
if (!$this->___tipoRelatorio) { |
|
foreach ($this->GetData()[0] as $row) { |
|
$somaQtd ++; |
|
$somaTempo += $row["tempologin"]; |
|
$dados[$x]['apelido'] = $row["apelido"]; |
|
$dados[$x]['tempologin'] = SecondToStrTime($row["tempologin"]); |
|
$x++; |
|
} |
|
|
|
//HEADER DA TABELA DO PDF -> DADOS EM ARRAY |
|
$header = array( |
|
'Agente' => 'C', |
|
'Duração' => 'C' |
|
); |
|
$dataHeader = array( |
|
'apelido' => 'C', |
|
'tempologin' => 'C' |
|
); |
|
$widthHeader = array(100, 80); |
|
$totaliza = array( |
|
"Total: $somaQtd", "Duração: " . SecondToStrTime($somaTempo)); |
|
|
|
//Monta o array para passar para o prepara; Necessário passar 6 parametros |
|
$table1 = array($header, $dataHeader, $dados, $widthHeader, $totaliza, 0); |
|
|
|
$this->___dataRel = array($table1); |
|
} else { |
|
$pass = 0; |
|
$t = 0; |
|
$tables = array(); |
|
//HEADER DA TABELA DO PDF -> DADOS EM ARRAY |
|
$header = array( |
|
'Agente' => 'L', |
|
'Início' => 'C', |
|
'Término' => 'C', |
|
'Duração' => 'C' |
|
); |
|
$dataHeader = array( |
|
'apelido' => 'L', |
|
'login' => 'C', |
|
'logoff' => 'C', |
|
'tempologin' => 'C' |
|
); |
|
$widthHeader = array(45, 45, 45, 45); |
|
|
|
foreach ($this->GetData()[0] as $row) { |
|
|
|
if ($x != 0) { |
|
if ($row['apelido'] != $ultApelido) { |
|
$totaliza = array("Total: $somaQtd", '', '', "Duração: " . SecondToStrTime($somaTempo)); |
|
${"table" . $t} = array($header, $dataHeader, $dados, $widthHeader, $totaliza, 0); |
|
array_push($tables, ${"table" . $t}); |
|
$t++; |
|
unset($somaQtd); |
|
unset($somaTempo); |
|
unset($x); |
|
unset($dados); |
|
} |
|
} |
|
|
|
$somaTempo += $row["tempologin"]; |
|
$somaQtd++; |
|
$dados[$x]["tempologin"] = SecondToStrTime($row["tempologin"]); |
|
$dados[$x]["login"] = date('d/m/Y H:i:s', strtotime($row["login"])); |
|
$dados[$x]["logoff"] = date('d/m/Y H:i:s', strtotime($row["logoff"])); |
|
$dados[$x]["apelido"] = $row['apelido']; |
|
$ultApelido = $row['apelido']; |
|
$x++; |
|
$arQtd ++; |
|
|
|
//PREENCHE OS DADOS DA ULTIMA LINHA DO ARRAY DO BANCO DE DADOS |
|
if (count($this->GetData()[0]) == $arQtd) { |
|
$totaliza = array("Total: $somaQtd", '', '', "Duração: " . SecondToStrTime($somaTempo)); |
|
${"table" . $t} = array($header, $dataHeader, $dados, $widthHeader, $totaliza, 0); |
|
array_push($tables, ${"table" . $t}); |
|
} |
|
} |
|
|
|
$this->___dataRel = $tables; |
|
} |
|
} |
|
|
|
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'); |
|
} |
|
|
|
protected function retornaAgente() { |
|
global $dbcon; |
|
|
|
$codSel = $this->GetData()[1] ? $this->GetData()[1] : ''; |
|
$agentes = "<select name=\"listaAgente\" id=\"listaAgente\" size=\"1\">"; |
|
$agentes .= "<option value=\"0\" $sel>Todos</option>"; |
|
|
|
$query = sprintf("SELECT matricula, apelido AS nome |
|
FROM pbx_usuarios u |
|
WHERE EXISTS(SELECT '' FROM pbx_eventos_agentes WHERE id_dac = %s |
|
AND matricula = u.matricula |
|
AND CAST(login as date) >= '%s' |
|
AND CAST(login as date) <= '%s') |
|
ORDER BY 2", $this->___dac, FormatDtMssql($this->___dataIni), FormatDtMssql($this->___dataFim)); |
|
|
|
$result = @pg_query($dbcon, $query); |
|
|
|
while ($dados = pg_fetch_row($result)) { |
|
if ($codSel == $dados[0]) { |
|
$sel = "selected"; |
|
$i = 1; |
|
} else { |
|
$sel = ""; |
|
} |
|
$agentes .= "<option value=\"$dados[0]\" $sel>$dados[1]</option>"; |
|
} |
|
$agentes .= "</select>"; |
|
return $agentes; |
|
} |
|
|
|
} |
|
|
|
$relAgtHoras = new RelAgenteHoras($idProg, $dbcon, 1); |
|
$relAgtHoras->ExecutaRelatorio(); |
|
|
|
|