I'm having trouble paging.
I get the data from the report in array format, so I have to do a foreach to scan the data, I happen to be doing it within 2 for, and the data keeps repeating, as I solve it, I tried to use some breaks, but not it works ?
namespace Helpers;
require_once 'Fpdf/fpdf.php';
require_once 'FormataData.php';
require_once 'C:xampp/htdocs/pim_dev/DAO/EstoqueDAO.php';
use \FPDF;
class RelatorioPorEntrada {
public function gerar($dataOne, $dataTwo, $dados)
{
$logo = "c:xampp/htdocs/pim_dev/content/img/relat4.png";
$data = date('j/m/Y');
$por_pagina = 3;
$row = count($dados);
$paginas = ceil($row/$por_pagina);
$pdf = new FPDF("P", "cm", "A4");
$linha_atual = 0;
$inicio = 0;
for($x=1; $x<=$paginas; $x++)
{
$inicio = $linha_atual;
$fim = $linha_atual + $por_pagina;
if($fim > $row) $fim = $row;
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont("arial");
$pdf->Image($logo, 0,0);
$pdf->SetTitle("Relatorio");
$pdf->Ln(1);
$pdf->SetFontSize(14);
$pdf->Cell(0,3, utf8_decode("Relatório Mensal"),0,0,"C");
$pdf->SetFontSize(10);
$pdf->Cell(0, 5, utf8_decode("Página $x de $paginas"),0, 0, "R");
$pdf->Ln(1);
$pdf->Cell(0,3, "Data:".$data,0,0,"E");
$pdf->Ln(1);
$dateFormat = new FormataData();
$novaDataone = $dateFormat->dateToBr($dataOne);
$novaDataTwo = $dateFormat->dateToBr($dataTwo);
$pdf->Cell(0,3,utf8_decode("Periodo:".$novaDataone." "."até ".$novaDataTwo),0,0,"E");
$pdf->SetFontSize(8);
$pdf->Ln(3);
$pdf->SetDrawColor(57,181,74);
$pdf->SetFillColor(57,181,74);
$pdf->SetTextColor(255, 255, 255);
$pdf->Cell(1,1, "ID", 1,0,"C",true);
$pdf->Cell(3,1, "Produto", 1,0,"C",true);
$pdf->Cell(3,1, "Date de Entrada", 1,0,"C",true);
$pdf->Cell(2,1, utf8_decode("Valor Unitário"), 1,0,"C",true);
$pdf->Cell(2,1, "Quantidade", 1,0,"C",true);
$pdf->Cell(2,1, "Valor Total", 1,0,"C",true);
$pdf->SetTextColor(0,0,0);
for($i=$inicio; $i<$fim; $i++)
{
foreach($dados as $values)
{
$pdf->Ln(1);
$pdf->Cell(1,1, $dados[0], 1,0,"C");
$pdf->Cell(3,1, $dados[1], 1,0,"C");
$pdf->Cell(3,1, $dados[2], 1,0,"C");
$pdf->Cell(2,1, $dados[3], 1,0,"C");
$pdf->Cell(2,1, $dados[4], 1,0,"C");
$pdf->Cell(2,1, $dados[5], 1,0,"C");
}
$linha_atual++;
}
}
return $pdf->Output("relatorio.pdf", "I");
}
}