Foreach with the mPDF library

0

Hello! I have a chatinho problem that I can not solve. I need to include a foreach in my report using the mPDF library, however I did not find a way to do this in the middle of the HTML code that I enter. 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();
    }
    
asked by anonymous 05.09.2018 / 21:45

1 answer

0

Just make out of the parameters by concatenating in a variable, then pass the variable in the parameter. And you do not need to make $ this-> recipes as $ this-> recipe ... Just say $ this-> recipes as $ recipe_unica

 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();
        }
    
05.09.2018 / 22:03