forked from SimplesIP/pabx-app
Claudio Zimmermann Junior
3 months ago
4 changed files with 1021 additions and 354 deletions
@ -0,0 +1,359 @@
|
||||
<?php |
||||
include_once 'util/relatoriosBase.php'; |
||||
|
||||
class EntrantesIntegracao extends Relatorios |
||||
{ |
||||
private $___telefone; |
||||
private $___metodo; |
||||
|
||||
public function __construct($idProg, $dbcon, $incDac) |
||||
{ |
||||
parent::__construct($idProg, $dbcon, $incDac); |
||||
$this->___telefone = isset($_REQUEST['telefone']) ? $_REQUEST['telefone'] : ''; |
||||
$this->___dataIni = IsPostBack() ? $_POST['dataIni'] : date('d/m/Y') . " 00:00"; |
||||
$this->___dataFim = IsPostBack() ? $_POST['dataFim'] : date('d/m/Y') . " 23:59"; |
||||
$this->___metodo = IsPostBack() ? $_POST['metodo'] : ''; |
||||
} |
||||
|
||||
// nao precisa validar. Tudo eh aceito aqui. |
||||
function ___ValidaForm() |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
function ___FiltrosRelatorio() |
||||
{ |
||||
$lkPrint = ''; |
||||
$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>'; |
||||
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_EXCEL, 'prt-xls.png'); |
||||
|
||||
if ($this->___media != MEDIA_PRINT_GRID) { |
||||
list($this->___dataIni, $this->___dataFim, $this->___metodo, $this->___telefone) = $_SESSION["SSstorageFiltros"]; |
||||
$fltCsv = array(); |
||||
$fltCsv[] = "Data Inicial: " . $this->___dataIni; |
||||
$fltCsv[] = "Data Final: " . $this->___dataFim; |
||||
$fltCsv[] = $this->___metodo ? "Metodo: " . $this->___metodo : ''; |
||||
$fltCsv[] = "Data Emissao: " . date('d/m/Y H:i:s'); |
||||
$fltCsv[] = "Emitido Por: " . GetLogin(); |
||||
return $fltCsv; |
||||
} |
||||
|
||||
/* |
||||
* Personalise esta função se necessitar de outras opções de filtro. |
||||
*/ |
||||
$filtro = '<table class="filtro" border="0" cellspacing="1" cellpadding="1">'; |
||||
/* |
||||
* Rotulos. |
||||
*/ |
||||
$filtro .= '<tr>'; |
||||
$filtro .= '<td> </td>'; |
||||
$filtro .= '<td>Data Inicial </td>'; |
||||
$filtro .= '<td>Data Final </td>'; |
||||
$filtro .= '<td>Metodo</td>'; |
||||
$filtro .= '<td>Telefone/Ramal</td>'; |
||||
$filtro .= '<td>'; |
||||
$filtro .= '<td align="center" valign="middle"> </td>'; |
||||
$filtro .= '</tr>'; |
||||
|
||||
/* |
||||
* Valores. |
||||
*/ |
||||
$filtro .= '<tr>' |
||||
. '<td> </td>'; |
||||
$filtro .= '<td><input name="dataIni" id="dataIni" type="text" size="15" maxlength="16" value="%s" onkeyup="formataDataHora(this)" title="dd/mm/aaaa HH:mm"></td>'; |
||||
$filtro .= '<td><input name="dataFim" id="dataFim" type="text" size="15" maxlength="16" value="%s" onkeyup="formataDataHora(this)" title="dd/mm/aaaa HH:mm"></td>'; |
||||
$filtro .= '<td><select name="metodo" type="text" id="metodo" value="%s" >'; |
||||
$filtro .= '<option value="">Todos</option>'; |
||||
foreach ($this->GetData()[1] as $value) { |
||||
$selected = $this->___metodo == $value['itgm_id'] ? 'selected' : ""; |
||||
$filtro .= sprintf('<option value="%s" %s >%s</option>', $value['itgm_id'], $selected, $value['itgm_nome']); |
||||
} |
||||
$filtro .= '</select></td>'; |
||||
$filtro .= '<td><input name="telefone" type="text" id="telefone" value="%s" /></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 emissao dos relatoios para impressao. |
||||
*/ |
||||
$_SESSION["SSstorageFiltros"] = array($this->___dataIni, $this->___dataFim, $this->___metodo, $this->___telefone); |
||||
|
||||
return sprintf($filtro, $this->___dataIni, $this->___dataFim, $this->___metodo, $this->___telefone, $lkPrint); |
||||
} |
||||
|
||||
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; |
||||
/* |
||||
* Esta variavel contém o nome das colunas do relatório |
||||
*/ |
||||
$dadosCabecalio = array('Data', 'Metodo', 'Resultado', 'Telefone', 'Cliente'); |
||||
|
||||
/* |
||||
* Valores correspondem a $key do array de dados retornado por GetData(); |
||||
*/ |
||||
$dadosField = array('reg_inicio', 'itgm_nome', 'reg_msg', 'reg_fone', 'reg_retorno'); |
||||
|
||||
/* |
||||
* Monta a linha de cabecalio. Dados que o primeiro elemento é "LABEL" |
||||
* na impressão será destacado com negrito. |
||||
*/ |
||||
$linha = array('LABEL'); |
||||
foreach ($dadosCabecalio as $value) { |
||||
$linha[] = $value; |
||||
} |
||||
$dataRel[] = $linha; |
||||
|
||||
/* |
||||
* Inicializa variáveis para sumarização. |
||||
*/ |
||||
$sum = 0; |
||||
|
||||
/* |
||||
* Linhas de dados. |
||||
*/ |
||||
foreach ($this->GetData()[0] as $row) { |
||||
/* |
||||
* Realiza soma ou outras funções como formatação de dados. |
||||
*/ |
||||
$sum++; |
||||
$linha = array('DADOS'); |
||||
$row['reg_inicio'] = date('d/m/Y H:i:s', strtotime($row['reg_inicio'])); |
||||
foreach ($dadosField as $key) { |
||||
$linha[] = $row["$key"]; |
||||
} |
||||
$dataRel[] = $linha; |
||||
} |
||||
/* |
||||
* Contem dados da impressão. |
||||
*/ |
||||
$this->___dataRel[] = $dataRel; |
||||
|
||||
// totalização |
||||
if (!$this->___metodo) |
||||
return; |
||||
|
||||
$dataRel = array(array('DADOS')); |
||||
$total = array(); |
||||
foreach ($this->GetData()[0] as $value) { |
||||
$total[$value['reg_msg']]++; |
||||
} |
||||
|
||||
//cabecalho |
||||
$header = array('LABEL'); |
||||
$data = array('DADOS'); |
||||
foreach ($total as $key => $value) { |
||||
$header[] = $key; |
||||
$data[] = $value; |
||||
} |
||||
$dataRel[] = $header; |
||||
$dataRel[] = $data; |
||||
$this->___dataRel[] = $dataRel; |
||||
} |
||||
|
||||
function ___PreparaCsv() |
||||
{; |
||||
} |
||||
|
||||
function ___PreparaGrid() |
||||
{ |
||||
$dataRel = array(); |
||||
$dataAgrup = array(); |
||||
|
||||
/* |
||||
* Cria o cabeçalio da tabela de dados. |
||||
*/ |
||||
$dadosCabecalio = array('Data' => 'align="center"', 'Método' => 'align="left"', 'Resultado' => 'align="left"', 'Telefone' => 'align="left"', 'Cliente' => 'align="left"'); |
||||
|
||||
/* |
||||
* Corresponde aos campos de dados retornados por GetData(). |
||||
*/ |
||||
$dadosField = array('reg_inicio' => 'align="center"', 'itgm_nome' => 'align="left"', 'reg_msg' => 'align="left"', 'reg_fone' => 'align="left"', 'reg_retorno' => 'align="left"'); |
||||
|
||||
/* |
||||
* Inicia o relatório. |
||||
*/ |
||||
$dataRel[] = '<table width="80%" 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; |
||||
} |
||||
|
||||
$sum = 0; |
||||
|
||||
/* |
||||
* Linhas de dados. |
||||
*/ |
||||
foreach ($this->GetData()[0] as $row) { |
||||
|
||||
$row['reg_inicio'] = date('d/m/Y H:i:s', strtotime($row['reg_inicio'])); |
||||
|
||||
$sum++; |
||||
|
||||
$row["coluna_1"] = SecondToStrTime(round($row["coluna_1"], 0)); |
||||
|
||||
// Formata linha de dados. |
||||
$linha = "<tr>"; |
||||
foreach ($dadosField as $key => $value) { |
||||
$linha .= sprintf("<td %s>%s</td>", $value, $row["$key"]); |
||||
} |
||||
$linha .= "</tr>"; |
||||
$dataRel[] = $linha; |
||||
} |
||||
|
||||
/* |
||||
* Fecha relatorio. |
||||
*/ |
||||
$dataRel[] = '</table>'; |
||||
$this->___dataRel[] = $dataRel; |
||||
|
||||
if (!$this->___metodo) |
||||
return; |
||||
/* |
||||
* Tabela de totalizacao. |
||||
*/ |
||||
$total = array(); |
||||
foreach ($this->GetData()[0] as $value) { |
||||
$total[$value['reg_msg']]++; |
||||
} |
||||
|
||||
$dataRel = array(); |
||||
$dataRel[] = '<table width="400px" cellpadding="2" class="grid">'; |
||||
$linha = '<tr><th align="center" colspan="2">Totalização</th></tr>'; |
||||
foreach ($total as $key => $value) { |
||||
$linha .= "<tr><th style=\"width:100px;\">$key</th><td style=\"width:100px;\" align=\"center\">$value</td></tr>"; |
||||
} |
||||
$linha .= "<tr><th style=\"width:100px\">TOTAL</th><th style=\"width:100px;\" align=\"center\">$sum</th></tr>"; |
||||
|
||||
|
||||
$dataRel[] = sprintf($linha, $sum); |
||||
$dataRel[] = '</table>'; |
||||
$this->___dataRel[] = $dataRel; |
||||
} |
||||
|
||||
function ___PreparaHtml() |
||||
{ |
||||
} |
||||
|
||||
function ___PreparaPdf() |
||||
{ |
||||
} |
||||
|
||||
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); |
||||
$metodo = $this->___metodo ? $this->___metodo : false; |
||||
$telefone = $this->___telefone ? $this->___telefone : false; |
||||
|
||||
//Query para buscar dados no relatorio |
||||
$query = "SELECT a.reg_id, a.reg_inicio, a.reg_id_metodo, a.reg_msg, a.reg_fone, a.reg_retorno, b.itgm_nome FROM pbx_integracao_reg a |
||||
INNER JOIN pbx_integracao_metodo b ON a.reg_id_metodo = b.itgm_id |
||||
WHERE reg_inicio >= '$dataIni' |
||||
AND reg_inicio <= '$dataFim'"; |
||||
if ($metodo) { |
||||
$query .= "AND reg_id_metodo = $metodo"; |
||||
} |
||||
if ($telefone) { |
||||
$query .= "AND reg_fone LIKE '%$telefone%'"; |
||||
} |
||||
$query .= "ORDER BY reg_inicio DESC;"; |
||||
|
||||
$result = $this->___GetQuery($query); |
||||
while ($row = pg_fetch_array($result, null, PGSQL_ASSOC)) { |
||||
$dataRel[] = $row; |
||||
} |
||||
$this->SetData($dataRel); |
||||
|
||||
// query para listar os metodos de integracao ativa |
||||
$query = "SELECT itgm_id, itgm_nome FROM pbx_integracao_metodo WHERE opcao = 'anuncios';"; |
||||
$result = $this->___GetQuery($query); |
||||
$methods = array(); |
||||
while ($row = pg_fetch_array($result, null, PGSQL_ASSOC)) { |
||||
$methods[] = $row; |
||||
} |
||||
$this->SetData($methods); |
||||
} |
||||
|
||||
public function ExecutaRelatorio() |
||||
{ |
||||
global $jsStartup, $jsJQuery, $smarty; |
||||
try { |
||||
/* |
||||
* Use esta função para validar dados do formulário. |
||||
* nesse caso, nao precisa validar. |
||||
*/ |
||||
//$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'); |
||||
} |
||||
} |
||||
|
||||
$relInt = new EntrantesIntegracao($idProg, $dbcon, 1); |
||||
$relInt->ExecutaRelatorio(); |
Loading…
Reference in new issue