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.
425 lines
17 KiB
425 lines
17 KiB
<?php |
|
|
|
$tpLayout = 1; |
|
include_once 'util/relatoriosBase.php'; |
|
|
|
class TotalizadorCentroCustoDetalhesAgp extends Relatorios { |
|
|
|
private $___nomeDpto; |
|
private $___nomeEmp; |
|
private $___codEmpresa; |
|
private $___codDptos; |
|
private $___tempoDuracao; |
|
private $___site; |
|
|
|
public function __construct($idProg, $dbcon, $incDac) { |
|
parent::__construct($idProg, $dbcon, $incDac); |
|
$this->___dataIni = isset($_GET["dtIni"]) ? $_GET["dtIni"] : date('d/m/Y'); |
|
$this->___dataFim = isset($_GET["dtFim"]) ? $_GET["dtFim"] : date('d/m/Y'); |
|
$this->___codEmpresa = isset($_GET["codEmp"]) ? $_GET["codEmp"] : ''; |
|
$this->___codDptos = isset($_GET["codDepto"]) ? $_GET["codDepto"] : 0; |
|
$this->___tempoDuracao = 1; |
|
$this->___nomeEmp = isset($_GET["empresa"]) ? $_GET["empresa"] : ''; |
|
$this->___nomeDpto = isset($_GET["depto"]) ? $_GET["depto"] : ''; |
|
$this->___site = isset($_GET["site"]) ? $_GET["site"] : ''; |
|
} |
|
|
|
function ___ValidaForm() { |
|
parent::___ValidaForm(); |
|
if (!IsPostBack()) { |
|
return; |
|
} |
|
|
|
if ($this->___codDptos < 0) { |
|
GeraExcept('Informe o código departamento!'); |
|
} |
|
if (!$this->___codEmpresa) { |
|
GeraExcept('Informe o código empresa!'); |
|
} |
|
if (!$this->___nomeDpto) { |
|
GeraExcept('Informe o nome do departamento!'); |
|
} |
|
if (!$this->___nomeEmp) { |
|
GeraExcept('Informe o nome da empresa!'); |
|
} |
|
if (!$this->___site) { |
|
GeraExcept('Informe um dispositivo!'); |
|
} |
|
} |
|
|
|
function ___FiltrosRelatorio() { |
|
if ($this->___media != MEDIA_PRINT_GRID) { |
|
/* |
|
* Recupera os filtros da sess�o do usu�rio. |
|
*/ |
|
list($this->___dataIni, $this->___dataFim, $this->___codDptos, $this->___codEmpresa, $this->___tempoDuracao) = $_SESSION["SSstorageFiltros"]; |
|
if ($this->___media == MEDIA_PRINT_HTML) { |
|
return sprintf("Data Inicial: %s Data Final: %s ", $this->___dataIni, $this->___dataFim); |
|
} |
|
|
|
$fltCsv = array(); |
|
$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; |
|
} |
|
|
|
$lkPrint = ""; |
|
if ($this->___dataCount) { |
|
$prt = '<a href="index.php?idProg=%s&media=%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', '%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, substr(LimpaString(GetDispProgSel($this->GetIdProg())), 0, 20), 'print.gif'); |
|
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_EXCEL, 'prt-xls.png'); |
|
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_PDF, 'prt-pdf.png'); |
|
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_CSV, 'prt-csv.png'); |
|
} |
|
|
|
/* |
|
* Personalise esta função se necessitar de outras opções de filtro. |
|
*/ |
|
$filtro = '<table class="grid" border="0" cellspacing="1" cellpadding="1">'; |
|
/* |
|
* Rotulos. |
|
*/ |
|
$filtro .= '<tr>'; |
|
$filtro .= '<th align="center">Dispositivo</th>'; |
|
$filtro .= '<th align="center">Data Inicial</th>'; |
|
$filtro .= '<th align="center">Data Final</th>'; |
|
$filtro .= '<th align="center">Empresa</th>'; |
|
$filtro .= '<th align="center">Departamento</th>'; |
|
$filtro .= '<th align="center">Impressão</th>'; |
|
$filtro .= '</tr>'; |
|
|
|
/* |
|
* Valores. |
|
*/ |
|
$filtro .= '<tr>'; |
|
$filtro .= sprintf('<td align="center">%s</td>', $this->___site); |
|
$filtro .= '<td align="center">%s</td>'; |
|
$filtro .= '<td align="center">%s</td>'; |
|
$filtro .= sprintf('<td align="center">%s</td>', $this->___nomeEmp); |
|
$filtro .= sprintf('<td align="center">%s</td>', $this->___nomeDpto); |
|
$filtro .= '<td align="center">%s</td>'; |
|
$filtro .= '</tr>'; |
|
$filtro .= '</table>'; |
|
|
|
/* |
|
* Guarda os filtros passados para recuperar na emiss�o dos relat?ios para impress�o. |
|
*/ |
|
$_SESSION["SSstorageFiltros"] = array($this->___dataIni, $this->___dataFim); |
|
|
|
return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint); |
|
} |
|
|
|
protected function ___GetDadosDb() { |
|
$dataIni = strlen($this->___dataIni) == 10 ? FormatDtMssql($this->___dataIni) . " 00:00": FormatDtMssql(substr($this->___dataIni, 0, 10)). substr($this->___dataIni, 10, 16); |
|
$dataFim = strlen($this->___dataFim) == 10 ? FormatDtMssql($this->___dataFim) . " 23:59": FormatDtMssql(substr($this->___dataFim, 0, 10)). substr($this->___dataFim, 10, 16); |
|
$emp = $this->___codEmpresa; |
|
$depto = $this->___codDptos; |
|
$duracao = $this->___tempoDuracao; |
|
|
|
$query = "select c.matricula, c.nome, c.apelido, d.id as codigo_empresa, d.nome as nome_empresa, |
|
e.id as codigo_departamento, e.nome_depto, sum(case when a.lastdata like ('CONTASENHA%') then 0 else a.billsec end) as duracao, count(*) as qtde |
|
from pbx_bilhetes a, pbx_bilhetes_complemento b, pbx_usuarios_cs c, pbx_empresa d, pbx_departamentos e |
|
where b.uniqueid2 = a.uniqueid |
|
and c.id = b.id_usuario |
|
and e.id = c.departamento |
|
and e.empresa = c.empresa |
|
and d.id = e.empresa |
|
and a.id_bilhetes = (select max (l.id_bilhetes) from pbx_bilhetes l where l.uniqueid = a.uniqueid and l.lastapp <> 'Transferred Call' ) |
|
and coalesce(trim(b.dac), '') = '' |
|
and a.calldate::timestamp >= '$dataIni' |
|
and a.calldate::timestamp <= '$dataFim' "; |
|
if ($emp) { |
|
$query .= " and d.id = $emp "; |
|
} |
|
if ($depto) { |
|
$query .= " and e.id = $depto "; |
|
} |
|
if ($duracao == 2) { |
|
$query .= " and a.billsec > 0 and a.lastdata not like ('CONTASENHA%') "; |
|
} |
|
if ($duracao == 3) { |
|
$query .= " and (a.billsec = 0 or a.lastdata like ('CONTASENHA%'))"; |
|
} |
|
$query .= "group by c.matricula, c.nome, c.apelido, d.id, d.nome, |
|
e.id, e.nome_depto"; |
|
//if(IsAdmin ()) echo $sql; |
|
$result = $this->___GetQuery($query); |
|
$row = pg_fetch_all($result); |
|
|
|
$this->SetData($row ? $row : array()); |
|
} |
|
|
|
protected function ___PreparaCsv() { |
|
$nomeDac = ""; |
|
$dataRel = array(); |
|
$filtro = $this->___FiltrosRelatorio(); |
|
|
|
$dataRel[] = GenerateCsvFromArray($filtro); |
|
|
|
$dadosCabecalio = array( |
|
'Conta' => 'align="center"', |
|
'Usuario' => 'align="center"', |
|
'Quantidade' => 'align="center"', |
|
'Duracao' => 'align="left"' |
|
); |
|
$dadosField = array( |
|
'matricula' => 'align="center"', |
|
'apelido' => 'align="center"', |
|
'qtde' => 'align="center"', |
|
'duracao' => 'align="left"' |
|
); |
|
|
|
$dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio)); |
|
|
|
$somaTempo = 0; |
|
$somaReg = 0; |
|
|
|
/* |
|
* Inicia o relat�rio. |
|
*/ |
|
foreach ($this->GetData()[0] as $row) { |
|
$somaTempo += $row["duracao"]; |
|
$somaReg += $row['qtde']; |
|
|
|
$row["duracao"] = SecondToStrTime($row["duracao"]); |
|
|
|
$linha = array(); |
|
foreach ($dadosField as $key => $value) { |
|
$linha[] = $row["$key"]; |
|
} |
|
|
|
$dataRel[] = GenerateCsvFromArray($linha); |
|
} |
|
|
|
$dataRel[] = $linha; |
|
|
|
$linha1 = array('Total', '', 'Registros: ' . $somaReg, 'Duracao: ' . SecondToStrTime($somaTempo)); |
|
$dataRel[] = GenerateCsvFromArray($linha1); |
|
$dataRel[] = $linha1; |
|
|
|
$this->___dataRel[] = $dataRel; |
|
} |
|
|
|
protected function ___PreparaExcel() { |
|
$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; |
|
|
|
$dadosCabecalio = array('Conta', 'Usuario', 'Quantidade', 'Duracao'); |
|
$dadosField = array('matricula', 'apelido', 'qtde', 'duracao'); |
|
|
|
/* |
|
* Monta a linha de cabecalio. |
|
*/ |
|
$linha = array('LABEL'); |
|
foreach ($dadosCabecalio as $value) { |
|
$linha[] = $value; |
|
} |
|
$dataRel[] = $linha; |
|
|
|
$somaTempo = 0; |
|
$somaReg = 0; |
|
/* |
|
* Linhas de dados. |
|
*/ |
|
foreach ($this->GetData()[0] as $row) { |
|
$somaTempo += $row["duracao"]; |
|
$somaReg += $row['qtde']; |
|
|
|
$row["duracao"] = SecondToStrTime($row["duracao"]); |
|
|
|
// Formata linha de dados. |
|
$linha = array('DADOS'); |
|
foreach ($dadosField as $key) { |
|
$linha[] = $row["$key"]; |
|
} |
|
|
|
$dataRel[] = $linha; |
|
} |
|
|
|
$linha = array('LABEL', 'Total', '', 'Registros: ' . $somaReg, 'Duracao: ' . SecondToStrTime($somaTempo)); |
|
|
|
$dataRel[] = $linha; |
|
|
|
$this->___dataRel[] = $dataRel; |
|
} |
|
|
|
protected function ___PreparaGrid() { |
|
$dadosCabecalio = array( |
|
'Conta' => 'align="left"', |
|
'Usuário' => 'align="left"', |
|
'Quantidade' => 'align="right"', |
|
'Duração' => 'align="right"' |
|
); |
|
|
|
$dadosField = array( |
|
'matricula' => 'align="left"', |
|
'apelido' => 'align="left"', |
|
'qtde' => 'align="right"', |
|
'duracao' => 'align="right"' |
|
); |
|
/* |
|
* Inicia o relat�rio. |
|
*/ |
|
$dataRel[] = '<table width="90%" 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; |
|
$somaReg = 0; |
|
|
|
/* |
|
* Linhas de dados. |
|
*/ |
|
foreach ($this->GetData()[0] as $row) { |
|
$somaReg += $row['qtde']; |
|
$somaTempo += $row['duracao']; |
|
$row["duracao"] = SecondToStrTime($row["duracao"]); |
|
|
|
// 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 colspan="2" align="left">Total</th><th align="right">Registros: %s</th><th align="right">Duração: %s</th></tr>'; |
|
$dataRel[] = sprintf($linha, $somaReg, SecondToStrTime($somaTempo)); |
|
|
|
/* |
|
* Fecha relatorio. |
|
*/ |
|
$dataRel[] = '</table>'; |
|
$this->___dataRel[] = $dataRel; |
|
} |
|
|
|
protected function ___PreparaHtml() { |
|
|
|
} |
|
|
|
protected function ___PreparaPdf() { |
|
list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"]; |
|
|
|
$dados = array(); |
|
$x = 0; |
|
$somaReg = 0; |
|
$somaTempo = 0; |
|
foreach ($this->GetData()[0] as $row) { |
|
$somaReg += $row['qtde']; |
|
$somaTempo += $row['duracao']; |
|
$dados[$x]["matricula"] = $row["matricula"]; |
|
$dados[$x]["apelido"] = $row["apelido"]; |
|
$dados[$x]["qtde"] = $row["qtde"]; |
|
$dados[$x]["apelido"] = $row["apelido"]; |
|
$dados[$x]["duracao"] = SecondToStrTime($row["duracao"]); |
|
$x++; |
|
} |
|
|
|
//HEADER DA TABELA DO PDF -> DADOS EM ARRAY |
|
$header = array( |
|
'Conta' => 'L', |
|
'Usuário' => 'L', |
|
'Quantidade' => 'R', |
|
'Duração' => 'R' |
|
); |
|
$dataHeader = array( |
|
'matricula' => 'L', |
|
'apelido' => 'L', |
|
'qtde' => 'R', |
|
'duracao' => 'R' |
|
); |
|
$widthHeader = array(45, 45, 45, 45); |
|
$totaliza = array('Total', '', "Registros: " . $somaReg, "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); |
|
} |
|
|
|
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'); |
|
} |
|
|
|
} |
|
|
|
$relSaintes = new TotalizadorCentroCustoDetalhesAgp($idProg, $dbcon, null); |
|
$relSaintes->ExecutaRelatorio(); |
|
?>
|