forked from bruno/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.
199 lines
5.9 KiB
199 lines
5.9 KiB
<?php |
|
|
|
/* * *************************************************************************************** |
|
* |
|
* GERA PDF |
|
* Autor |
|
* Lucas Awade |
|
* |
|
* *************************************************************************************** |
|
* Definições do Projeto |
|
* Nome: GerarPDF |
|
* Data início: 02/08/2018 |
|
* Equipe: Amarildo Pereira |
|
* Descrição: |
|
* O objetivo desta Classe é processar e retornar arquivos em PDF, para isso é necessário |
|
* instanciar o Objeto da classe com os seus atributos. Após o preenchimendo dos atributos |
|
* é importante formatar a fonte e criar uma página inicial para o preenchimento dos dados. |
|
* |
|
* Exemplo formatação: |
|
* $pdf->SetFont('Arial', '', 6); Parametros ('FONTE', '(B | I | '')','TAMANHO') |
|
* $pdf->AddPage(); Adiciona a primeira página |
|
* $pdf->Ln(5); Pula linhas |
|
* |
|
* Para gerar a tabela no PDF é necessário a população de dados é feita apartir de um array |
|
* que engloba 4 arrays multidimensionais um Array comun e uma variavel boolean. |
|
* |
|
* Exemplo de geração: |
|
* $pdf->Table(Array 1, Array 2, Array 3, Array 4, Array 5, boolean); |
|
* |
|
* Array 1 = Array para o cabeçalho(Header) [MULTIDIMENSIONAL]; |
|
* Array 2 = Array para os dados do cabeçalho [MULTIDIMENSIONAL]; |
|
* Array 3 = Array de dados para o preencimento das linhas [MULTIDIMENSIONAL] |
|
* Array 4 = Array para o tamanho dos cabeçalhos [COMUM] |
|
* boolean = 0 sem grid | 1 com grid |
|
* |
|
* Por fim para gerar o PDF em arquivo para download ou via browser adicione a linha Output |
|
* com uma target de arquivo. |
|
* |
|
* Exemplo: |
|
* $pdf->Output(NOMEPDF .".pdf", 'target'); |
|
* |
|
* Targets = 'D' para Download | 'I' via browser | 'F' Salva local | 'S' Retorna String |
|
* |
|
* Para saber e adicionar mais recursos na classe e importante verificar a classe FPDF. |
|
* |
|
* ************************************************************************************** |
|
* Copyright (c) 2018, Simples IP |
|
* ************************************************************************************* */ |
|
|
|
require('fpdf.php'); |
|
|
|
class GerarPDF extends FPDF { |
|
|
|
private $nomeRel; |
|
private $dataRel; |
|
private $userRel; |
|
private $logoRel; |
|
private $filtroRelIni; |
|
private $filtroRelFim; |
|
private $filtroRelDac; |
|
private $type; |
|
|
|
function getLogoRel() { |
|
return $this->logoRel; |
|
} |
|
|
|
function setLogoRel($logoRel) { |
|
$this->logoRel = $logoRel; |
|
} |
|
|
|
function getNomeRel() { |
|
return $this->nomeRel; |
|
} |
|
|
|
function setNomeRel($nomeRel) { |
|
$this->nomeRel = $nomeRel; |
|
} |
|
|
|
function getDataRel() { |
|
return $this->dataRel; |
|
} |
|
|
|
function getUserRel() { |
|
return $this->userRel; |
|
} |
|
|
|
function setDataRel($dataRel) { |
|
$this->dataRel = $dataRel; |
|
} |
|
|
|
function setUserRel($userRel) { |
|
$this->userRel = $userRel; |
|
} |
|
|
|
function getFiltroRelIni() { |
|
return $this->filtroRelIni; |
|
} |
|
|
|
function getFiltroRelFim() { |
|
return $this->filtroRelFim; |
|
} |
|
|
|
function setFiltroRelIni($filtroRelIni) { |
|
$this->filtroRelIni = $filtroRelIni; |
|
} |
|
|
|
function setFiltroRelFim($filtroRelFim) { |
|
$this->filtroRelFim = $filtroRelFim; |
|
} |
|
|
|
function getFiltroRelDac() { |
|
return $this->filtroRelDac; |
|
} |
|
|
|
function setFiltroRelDac($filtroRelDac) { |
|
$this->filtroRelDac = $filtroRelDac; |
|
} |
|
|
|
function getType() { |
|
return $this->type; |
|
} |
|
|
|
function setType($type) { |
|
$this->type = $type; |
|
} |
|
|
|
function Header() { |
|
// Logo |
|
|
|
$this->Image(file_exists($this->getLogoRel()) ? $this->getLogoRel() : LOGO_HEADER_RELATORIO, 10, 13, 30); |
|
$this->SetFont('Arial', 'B', 13); |
|
$this->Cell(80); |
|
// Titulo |
|
$this->Cell($this->type == "L" ? 120 : 30, 5, $this->getNomeRel(), 0, 0, 'C'); |
|
$this->Ln(1); |
|
$this->SetFont('Arial', 'B', 9); |
|
$this->Cell(0, 18, sprintf("Datas Filtradas: %s até %s", $this->getFiltroRelIni(), $this->getFiltroRelFim()), 0, 0, 'C'); |
|
$this->Ln(5); |
|
$this->getFiltroRelDac() ? $this->Cell(0, 18, sprintf("Fila: %s", $this->getFiltroRelDac()), 0, 0, 'C') : ''; |
|
$this->Ln(15); |
|
} |
|
|
|
function Table($header, $dataRow, $dataDB, $headerW, $totaliza, $gridRow = 0) { |
|
$this->SetFillColor(200); |
|
$this->SetLineWidth(.1); |
|
$this->SetFont('Arial', 'B'); |
|
$this->Ln(2); |
|
$i = 0; |
|
foreach ($header as $keyH => $dataH) { |
|
$this->Cell($headerW[$i], 7, $keyH, $gridRow, 0, $dataH, true); |
|
$i++; |
|
} |
|
$this->Ln(); |
|
// Cor das linhas da tabela |
|
$this->SetFillColor(255); |
|
|
|
$this->SetFont(''); |
|
$fill = false; |
|
foreach ($dataDB as $keyD => $data) { |
|
$x = 0; |
|
|
|
// Cor das linhas da tabela |
|
$this->SetFillColor(255); |
|
$setFill = 0; |
|
if (array_key_exists('cor_linha_dados', $data)) { |
|
$this->SetFillColor((int) $data['cor_linha_dados']); |
|
$setFill = 1; |
|
} |
|
|
|
foreach ($dataRow as $keyR => $row) { |
|
$this->Cell($headerW[$x], 7, $data[$keyR] ? $data[$keyR] : "0", $gridRow, 0, $row, ($setFill ? $setFill : $fill)); |
|
$x++; |
|
} |
|
|
|
$this->Ln(); |
|
$fill = !$fill; |
|
} |
|
$this->Ln(3); |
|
if ($totaliza) { |
|
$this->SetFont('Arial', 'B'); |
|
$this->SetFillColor(235); |
|
for ($t = 0; $t < count($totaliza); $t++) { |
|
$this->Cell($headerW[$t], 7, $totaliza[$t], 0, 0, 'C', true); |
|
} |
|
} |
|
$this->Ln(6); |
|
$this->Cell(array_sum($headerW), 0, '', ''); |
|
} |
|
|
|
function Footer() { |
|
$this->SetY(-15); |
|
$this->SetFont('Arial', '', 8); |
|
$this->Cell(0, 15, 'Emitido em: ' . $this->dataRel . " | Gerado por: " . $this->userRel, 0, 0, 'L'); |
|
$this->Cell(0, 15, 'Página ' . $this->PageNo(), 0, 0, 'R'); |
|
} |
|
|
|
} |
|
|
|
?>
|
|
|