Foreach with the mPDF library

Asked

Viewed 131 times

0

Hello! I’ve got a boring problem I can’t seem to solve. I need to include a foreach in my report using the mPDF library, but I couldn’t find a way to do this in the middle of the HTML code I had inserted. This is my code:

public function gerarpdf() {
    $mpdf = new \Mpdf\Mpdf();
    $mpdf->WriteHTML(
            '<table>
            <tr>
                <td>'.$this->title.'- Receitas</td>
                <td>Filtros:</td>
                <td>'.$this->filtros.'</td>
            </tr>
            <tr>
                <td>Rubrica</td>
                <td>Descrição</td>
                <td>Previsão inicial</td>
                <td>Arrec. no Mês</td>
                <td>Arrec. no Ano</td>
                <td>Por arrecadar</td>
            </tr>            
            <tr>
                <td>'.$this->receita->cod_natreceita.'</td>
                <td>'.$this->receita->desc_natreceita.'</td>
                <td>'.$this->receita->valor_previsto.'</td>
                <td>'.$this->receita->valorreceita.'</td>
                <td>'.$this->receita->valoracreceita.'</td>
                <td>'.($this->receita->valor_previsto - $this->receita- >valoracreceita).'
                </td>
            </tr>
            '.(foreach ($this->receitas as $this->receita) :).'             
            <tr>
                <td></td>
                <td></td>
                <td><strong>Total previsto</strong></td>
                <td><strong>'.$this->totalPrevisto.'</strong></td>
                <td><strong>Total arrecadado no mês</strong></td>
                <td><strong>'.$this->totalMes.'</strong></td>
                <td><strong>Total acumulado no ano</strong></td>
                <td><strong>'.$this->totalAcumulado.'</strong></td>
            </tr>
            '.endforeach.'
            </table>');
$mpdf->Output();
    }

1 answer

0


Just do outside the parameters by concatenating into a variable, then pass the variable in the parameter. And do not need to make $this->recipes as $this->recipe... Only speaks $this->recipes as $receipts

 public function gerarpdf() {
        $mpdf = new \Mpdf\Mpdf();
        $html = '<table>
                <tr>
                    <td>'.$this->title.'- Receitas</td>
                    <td>Filtros:</td>
                    <td>'.$this->filtros.'</td>
                </tr>
                <tr>
                    <td>Rubrica</td>
                    <td>Descrição</td>
                    <td>Previsão inicial</td>
                    <td>Arrec. no Mês</td>
                    <td>Arrec. no Ano</td>
                    <td>Por arrecadar</td>
                </tr>            
                <tr>
                    <td>'.$this->receita->cod_natreceita.'</td>
                    <td>'.$this->receita->desc_natreceita.'</td>
                    <td>'.$this->receita->valor_previsto.'</td>
                    <td>'.$this->receita->valorreceita.'</td>
                    <td>'.$this->receita->valoracreceita.'</td>
                    <td>'.($this->receita->valor_previsto - $this->receita- >valoracreceita).'
                    </td>
                </tr>';
    foreach ($this->receitas as $receita_unica):             
           $html .='<tr>
                    <td></td>
                    <td></td>
                    <td><strong>Total previsto</strong></td>
                    <td><strong>'.$receita_unica->totalPrevisto.'</strong></td>
                    <td><strong>Total arrecadado no mês</strong></td>
                    <td><strong>'.$receita_unica->totalMes.'</strong></td>
                    <td><strong>Total acumulado no ano</strong></td>
                    <td><strong>'.$receita_unica->totalAcumulado.'</strong></td>
                </tr>';
    endforeach;
    $html.='</table>';

    $mpdf->WriteHTML($html);
    $mpdf->Output();
        }

Browser other questions tagged

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