GENERATE PHP REPORT

Asked

Viewed 3,783 times

-1

I have a database in which there are two tables:

CUSTOMERS

inserir a descrição da imagem aqui

BILLETS

inserir a descrição da imagem aqui

In my VIEW (Codeigniter), the user will select a period (Ex. 01/03/2018 to 31/03/2018) to generate a report of all billets that were paid within this period.

In this report, I need all the information of that period to be in the report but ordering by group, for example:

inserir a descrição da imagem aqui

I’m using Codeigniter3 and thinking about using mPDF for the reports. Could someone help me with that logic?

  • mPDF is good, but for safety think about generating in XLS format because companies need to manipulate the data, and with pdf becomes complicated.

1 answer

1

Below an example working with mPDF with codeigniter, in case I import PDF controller, and send $data to the views report/pdf/body and report/pdf/body, where I store the PHP that will generate the HTML view with my information. Then just write to the file.

Detail $result is a Codeigniter Query result

$this->load->library('pdf');
$pdf = $this->pdf->load();
$data['titulo_relatorio'] = 'Relatório';
$header = $this->load->view('relatorio/pdf/header', $data, true);
$pdf->SetHTMLHeader($header);
$pdf->SetFooter('Titulo Relatório' . '|Página {PAGENO}|' . date("d.m.Y") . '   ');

$dataResult['result'] = $result;
$pdf->WriteHTML($this->load->view('relatorio/pdf/body', $dataResult, true));
$pdf->Output($pdfFilePath, 'I');

And below an example of the view code

<div>
    <table>
        <tr>
            <th>COLUNA 1</th>
            <th>COLUNA 2/th>
        </tr>
        <?php 
            foreach ($result as $row) {
        ?>
            <tr>
                <td><?php echo $row['campo1']; ?></td>
                <td><?php echo $row['campo2']; ?></td>
            </tr>
        <?php
            }
        ?>
    </table>
</div>

In short, basically you will generate HTML and write it in a PDF file

  • Sveen, Thank you for your reply. My question would be how to generate the template of this report, ie I want to show all the results, but they should be separated by group, in which each group will have a subtotal.... as shown in the image.

Browser other questions tagged

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