|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/* * ***************************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* GERA PDF
|
|
|
|
|
* Autor
|
|
|
|
|
* Lucas Awade
|
|
|
|
|
*
|
|
|
|
|
* ***************************************************************************************
|
|
|
|
|
* Defini<EFBFBD><EFBFBD>es do Projeto
|
|
|
|
|
* Nome: GerarPDF
|
|
|
|
|
* Data in<EFBFBD>cio: 02/08/2018
|
|
|
|
|
* Equipe: Amarildo Pereira
|
|
|
|
|
* Descri<EFBFBD><EFBFBD>o:
|
|
|
|
|
* O objetivo desta Classe <EFBFBD> processar e retornar arquivos em PDF, para isso <EFBFBD> necess<EFBFBD>rio
|
|
|
|
|
* instanciar o Objeto da classe com os seus atributos. Ap<EFBFBD>s o preenchimendo dos atributos
|
|
|
|
|
* <EFBFBD> importante formatar a fonte e criar uma p<EFBFBD>gina inicial para o preenchimento dos dados.
|
|
|
|
|
*
|
|
|
|
|
* Exemplo formata<EFBFBD><EFBFBD>o:
|
|
|
|
|
* $pdf->SetFont('Arial', '', 6); Parametros ('FONTE', '(B | I | '')','TAMANHO')
|
|
|
|
|
* $pdf->AddPage(); Adiciona a primeira p<EFBFBD>gina
|
|
|
|
|
* $pdf->Ln(5); Pula linhas
|
|
|
|
|
*
|
|
|
|
|
* Para gerar a tabela no PDF <EFBFBD> necess<EFBFBD>rio a popula<EFBFBD><EFBFBD>o de dados <EFBFBD> feita apartir de um array
|
|
|
|
|
* que engloba 4 arrays multidimensionais um Array comun e uma variavel boolean.
|
|
|
|
|
*
|
|
|
|
|
* Exemplo de gera<EFBFBD><EFBFBD>o:
|
|
|
|
|
* $pdf->Table(Array 1, Array 2, Array 3, Array 4, Array 5, boolean);
|
|
|
|
|
*
|
|
|
|
|
* Array 1 = Array para o cabe<EFBFBD>alho(Header) [MULTIDIMENSIONAL];
|
|
|
|
|
* Array 2 = Array para os dados do cabe<EFBFBD>alho [MULTIDIMENSIONAL];
|
|
|
|
|
* Array 3 = Array de dados para o preencimento das linhas [MULTIDIMENSIONAL]
|
|
|
|
|
* Array 4 = Array para o tamanho dos cabe<EFBFBD>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<EFBFBD> %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<EFBFBD>gina ' . $this->PageNo(), 0, 0, 'R');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|