0

Olá! Estou com um problema chatinho que eu não estou conseguindo resolver. Preciso incluir um foreach no meu relatório utilizando a biblioteca mPDF, porém não achei uma maneira de fazer isso no meio do código HTML que eu mando inserir. Esse é meu código:

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 Resposta 1

0

Apenas faça fora dos parametros concatenando em uma variavel, depois passe a variavel no parametro. E não precisa fazer $this->receitas as $this->receita... Só fala $this->receitas as $receita_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();
        }

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .