@ -6,7 +6,8 @@ use PhpOffice\PhpSpreadsheet\Writer\Xls;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
abstract class Relatorios {
abstract class Relatorios
{
/*
* Valores globais para dados de formul?rio.
*/
@ -27,14 +28,16 @@ abstract class Relatorios {
private $idProg;
private $dbcon;
public function __construct($idProg, $dbcon, $incDac) {
public function __construct($idProg, $dbcon, $incDac)
{
$this->idProg = $idProg;
$this->dbcon = $dbcon;
$this->___incDac = $incDac;
$this->___InicializaForm();
}
protected function ___GetQuery($query) {
protected function ___GetQuery($query)
{
$result = pg_query($query);
if (!$result) {
GeraExcept("Não foi possível executar a consulta no banco de dados!");
@ -42,7 +45,8 @@ abstract class Relatorios {
return $result;
}
public function ___ValidaForm() {
public function ___ValidaForm()
{
if (!IsPostBack())
return;
@ -69,7 +73,8 @@ abstract class Relatorios {
}
}
protected function ___InicializaForm() {
protected function ___InicializaForm()
{
/*
* Dados de formul?rio.
*/
@ -113,7 +118,8 @@ abstract class Relatorios {
$this->___pathLog = sprintf("/var/log/asterisk/relatorio_%s.log", $scrpName);
}
protected function ___FiltrosRelatorio() {
protected function ___FiltrosRelatorio()
{
if ($this->___media != MEDIA_PRINT_GRID) {
/*
* Recupera os filtros da sess�o do usu�rio.
@ -184,7 +190,8 @@ abstract class Relatorios {
return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint);
}
public function ___ConteudoRelatorio() {
public function ___ConteudoRelatorio()
{
if ($this->___media == MEDIA_PRINT_GRID) {
$this->___GetDadosDb();
SaveVarToFile($this->___data, $this->___dataFile);
@ -197,20 +204,26 @@ abstract class Relatorios {
$this->___dataCount = count($this->___data[0] ?? []);
}
public function ___ImprimeRelatorio() {
public function ___ImprimeRelatorio()
{
switch ($this->___media) {
//case MEDIA_PRINT_HTML: return $this->___ImprimeHtml();
case MEDIA_PRINT_HTML: return $this->___ImprimePdf("I");
case MEDIA_PRINT_PDF: return $this->___ImprimePdf("D");
case MEDIA_PRINT_EXCEL: return $this->___ImprimeExcel();
case MEDIA_PRINT_CSV: return $this->___ImprimeCsv();
case MEDIA_PRINT_HTML:
return $this->___ImprimePdf("I");
case MEDIA_PRINT_PDF:
return $this->___ImprimePdf("D");
case MEDIA_PRINT_EXCEL:
return $this->___ImprimeExcel();
case MEDIA_PRINT_CSV:
return $this->___ImprimeCsv();
default:
return $this->___ImprimeGrid();
}
}
protected function ___GravaLog($erro = true) {
protected function ___GravaLog($erro = true)
{
$erroSys = error_get_last();
$erroSys = sprintf("Msg: %s Line: %s", $erroSys['message'], $erroSys['line']);
$erroBd = pg_last_error();
@ -220,7 +233,8 @@ abstract class Relatorios {
fclose($arq);
}
private function ___GetScptName() {
private function ___GetScptName()
{
$query = sprintf("select arquivo from pbx_funcoes_internas where id_prog = '%s'", $this->idProg);
$result = pg_query($query);
$row = pg_fetch_row($result);
@ -228,20 +242,26 @@ abstract class Relatorios {
return $path['filename'];
}
private function ___PreparaData() {
private function ___PreparaData()
{
switch ($this->___media) {
// case MEDIA_PRINT_HTML: $this->___PreparaHtml();
// break;
case MEDIA_PRINT_HTML: $this->___PreparaPdf();
case MEDIA_PRINT_HTML:
$this->___PreparaPdf();
break;
case MEDIA_PRINT_PDF: $this->___PreparaPdf();
case MEDIA_PRINT_PDF:
$this->___PreparaPdf();
break;
case MEDIA_PRINT_EXCEL: $this->___PreparaExcel();
case MEDIA_PRINT_EXCEL:
$this->___PreparaExcel();
break;
case MEDIA_PRINT_CSV: $this->___PreparaCsv();
case MEDIA_PRINT_CSV:
$this->___PreparaCsv();
break;
default:
case MEDIA_PRINT_GRID: $this->___PreparaGrid();
case MEDIA_PRINT_GRID:
$this->___PreparaGrid();
break;
}
}
@ -256,7 +276,8 @@ abstract class Relatorios {
abstract protected function ___PreparaGrid();
private function ___ImprimeGrid() {
private function ___ImprimeGrid()
{
$fh = fopen('php://memory', 'rw');
$numTable = 0;
@ -280,7 +301,8 @@ abstract class Relatorios {
return stream_get_contents($fh);
}
private function ___ImprimeHtml() {
private function ___ImprimeHtml()
{
$fh = fopen('php://memory', 'rw');
$numTable = 0;
@ -313,10 +335,12 @@ abstract class Relatorios {
exit(0);
}
private function ___GetTemplate($filtros, $conteudoRelatorio) {
private function ___GetTemplate($filtros, $conteudoRelatorio)
{
$pathTpl = $_SESSION[PATH_ABSOLUTO] . 'templates/relbasehtml.tpl';
$vars = array('tituloPage' => GetDispProgSel($this->idProg),
$vars = array(
'tituloPage' => GetDispProgSel($this->idProg),
'logoRel' => GetLogoRel(),
'REL_HEAD_NIVEL1' => GetHeadRel(REL_HEAD_NIVEL1),
'tituloRelatorio' => GetDispProgSel($this->idProg),
@ -333,7 +357,8 @@ abstract class Relatorios {
return $content;
}
private function ___ImprimePdf($target) {
private function ___ImprimePdf($target)
{
$pdf = new GerarPDF();
//Informações do Filtro do Relatório
@ -360,7 +385,8 @@ abstract class Relatorios {
$pdf->Output(GetDispProgSel($this->GetIdProg()) . ".pdf", $target);
}
private function ___ImprimeExcel() {
private function ___ImprimeExcel()
{
$fileName = sprintf("%s.xls", substr(LimpaString(GetDispProgSel($this->idProg)), 0, 32));
$objPHPExcel = new Spreadsheet();
$objPHPExcel->setActiveSheetIndex(0);
@ -418,7 +444,8 @@ abstract class Relatorios {
$this->___SendFile($fh, $fileName);
}
private function ___ImprimeExcelOld() {
private function ___ImprimeExcelOld()
{
$fileName = sprintf("%s.xls", substr(LimpaString(GetDispProgSel($this->idProg)), 0, 32));
$fh = fopen('php://memory', 'rw');
@ -475,7 +502,8 @@ abstract class Relatorios {
$this->___SendFile($fh, $fileName);
}
private function ___ImprimeCsv() {
private function ___ImprimeCsv()
{
$fileName = sprintf("%s.csv", substr(LimpaString(GetDispProgSel($this->idProg)), 0, 32));
$fh = fopen('php://memory', 'rw');
@ -489,7 +517,8 @@ abstract class Relatorios {
$this->___SendFile($fh, $fileName);
}
private function ___SendFile($data, $fileName) {
private function ___SendFile($data, $fileName)
{
ob_end_clean();
ob_start();
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
@ -504,39 +533,48 @@ abstract class Relatorios {
exit(0);
}
protected function GetData() {
protected function GetData()
{
return $this->___data;
}
protected function SetData($data) {
protected function SetData($data)
{
$this->___data[] = ($data ?? []);
}
protected function GetIdProg() {
protected function GetIdProg()
{
return $this->idProg;
}
protected function GetDbCon() {
protected function GetDbCon()
{
return $this->dbcon;
}
protected function GetMsg() {
protected function GetMsg()
{
return $this->___msg;
}
protected function GetIncDac() {
protected function GetIncDac()
{
return $this->___incDac;
}
protected function SetMsg($msg) {
protected function SetMsg($msg)
{
$this->___msg = $msg;
}
function getType() {
function getType()
{
return $this->___type;
}
function setType($___type) {
function setType($___type)
{
$this->___type = $___type;
}
@ -544,5 +582,3 @@ abstract class Relatorios {
abstract public function ExecutaRelatorio();
}
?>