Create new tab when changing ID

Asked

Viewed 51 times

0

Good afternoon, I’m generating a report on PDF and I need to generate a new page when changing user code


Is generating so

Relatório atualmente.

At the moment it is only inserting the line of the items and ignoring the order, it needs to mount the same as the ones above that are correct, creating in a new page a new header (Aspecto físico, habilidade motora e Inteligencia de jogo) and inserting the items in their proper place.


PHP

 for ($i=0; $i < count($area_avaliar); $i++) {
        if ($area_avaliar_tecnica[$i]->descricao_tecnica != $area_avaliar_tecnica[$i-1]->descricao_tecnica) {
            $this->pdf->Ln();
            $this->pdf->SetFillColor(195, 195, 195);
            $this->pdf->SetTextColor(0);
            $this->pdf->SetDrawColor(51, 51, 51);
            $this->pdf->SetLineWidth(0.3);
            $this->pdf->SetFont('', 'B', 24);
            $this->pdf->Multicell(175, 5, $area_avaliar_tecnica[$i]->descricao_tecnica, 1, 'L', 1);
        }
        $this->pdf->SetFillColor(255, 255, 255);
        $this->pdf->SetTextColor(0);
        $this->pdf->SetDrawColor(51, 51, 51);
        $this->pdf->SetLineWidth(0.3);
        $this->pdf->SetFont('', 'N', 12);
        $this->pdf->Multicell(175, 5, $area_avaliar[$i]->desc_area_avaliar_item.' = '.$area_avaliar[$i]->avaliacao, 1, 'L', 1);
    }

This report that I am generating is dynamic, at the moment I have 3 headers (Aspecto físico, habilidade motora e Inteligencia de jogo) and some items inside them, I need to go through the $area_avaliar (variable that receives all data) and generate the 3 headers and their items, and each time you change the ID, create a new page. $this->pdf->AddPage(); but I don’t know how I can do this, since at the moment I have several items on $area_avaliar and it’s hard to go through and print the way I need to.

1 answer

0


I ended up being able to do what I needed in the following way.

$ultimo_header = '';
    for ($i=0; $i < count($area_avaliar); $i++) {
        if ($i == 0 || $area_avaliar[$i]->cod_atleta_area_avaliar != $area_avaliar[$i-1]->cod_atleta_area_avaliar) {
            $this->pdf->AddPage();
            $this->pdf->SetFillColor(255, 255, 255);
            $this->pdf->SetFont('', 'B', 18);
            $this->pdf->Multicell(175, 6, $area_avaliar[$i]->dt_avaliacao, 0, 'C', 1);
            $this->pdf->Ln();
            $this->pdf->SetTextColor(0);
            $this->pdf->SetFont('', 'N', 14);
            $this->pdf->Multicell(175, 6, 'Relatorio: '.$area_avaliar[$i]->relatorio, 0, 'L', 0);
            $this->pdf->Multicell(175, 6, 'Treinador: '.$area_avaliar[$i]->treinador, 0, 'L', 0);
            $this->pdf->Multicell(175, 6, 'Preparador Fisico: '.$area_avaliar[$i]->preparador_fisico, 0, 'L', 1);
            $this->pdf->Multicell(175, 6, 'Supervisor: '.$area_avaliar[$i]->supervisor, 0, 'L', 1);
            $this->pdf->Multicell(175, 6, 'Coordenador Técnico: '.$area_avaliar[$i]->coordenador_tecnico, 0, 'L', 1);
        }
        if ($i == 0 || $area_avaliar[$i]->descricao != $ultimo_header && $area_avaliar[$i]->descricao != null) {
            $this->pdf->Ln();
            $this->pdf->SetFillColor(195, 195, 195);
            $this->pdf->SetTextColor(0);
            $this->pdf->SetDrawColor(51, 51, 51);
            $this->pdf->SetLineWidth(0.3);

            $this->pdf->SetFont('', 'B', 24);
            $this->pdf->Multicell(175, 5, $area_avaliar[$i]->descricao, 1, 'L', 1);
            $ultimo_header = $area_avaliar[$i]->descricao;
        }
        $this->pdf->SetFillColor(255, 255, 255);
        $this->pdf->SetTextColor(0);
        $this->pdf->SetDrawColor(51, 51, 51);
        $this->pdf->SetLineWidth(0.3);
        $this->pdf->SetFont('', 'N', 12);
        $this->pdf->Multicell(175, 5, $area_avaliar[$i]->desc_area_avaliar_item.': '.$area_avaliar[$i]->avaliacao, 1, 'L', 1);

    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.