Loop Doubt (For) with information coming from the database

-1

What about personal blz?

I'm having a big problem running my code.

I have a web application made in laravel, which is running local. In this application I need to generate a report that is being done using DOMPDF.

The report is incomplete. I can not do programming logic for it to work 100% the way I want it.

I will explain below the scenario for you to understand better to help me.

I have to generate a report where I print all the month attendance data for company employees. Therefore, each page is required to have a header for the responsible signature. In addition, it is necessary to divide the employees by department, that is, if I have 100 employees and 10 departments, I need every time the employee changes with a different department to start a new page, or when I reach the number of 16 per page.

EX: Same as Image below, the report would have to print employees 1 through 16, page break and start printing from 17 to 21, new page break because the employee changed department and so on.

Icannotdoisreprintwhereyouleftoffwhenthereisalistofmorethan16employeesperdepartment.

Couldanyonehelpme?

Hereismycodebelow:

<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Relatório Geral</title>
    <style>

        body {
            margin-top: -20px;
            margin-left: -20px;
            margin-right: -5px;
            padding:0
        }

        .borda3 {
            border:1px solid #999;
            padding: 5px;
        }

        #borda2 td {
            border: 1px solid #999;
            border-collapse: collapse;
            width: auto;

        }

        .centro {
            text-align: center;
        }

        .tabela {
            width: 100%;
        }

        span {
            font-size: 100px;
        }

        td {
            font-size: 11px;
        }

        html {
            font-family: sans-serif;
        }

        #customers {
            font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
            border-collapse: collapse;
            width: 100%;
        }

        #customers td, #customers th {
            border: 1px solid #ddd;

        }

        #customers tr:nth-child(even){background-color: #f2f2f2;}

        #customers tr:hover {background-color: #ddd;}

        #customers th {
            text-align: center;
            font-size: 9px;
        }

        #customers td {
            text-align: left;
            font-size: 10px;
        }

        #customers a {
            font-size: 10px;
        }

        .nome{
            width: 180px;
        }

        .matricula{
            width: 15px;
        }

        .numeros{
            width: 15px;
        }

        .logo{
            padding-left: 50px;

        }

        .logo a strong{
            font-size: 15px;
            text-align: center;
        }

        .logo a{
            font-size: 12px;
        }

        .assinatura{
            font-size: 9px;
            margin-left: 60px;

        }
    </style>
</head>
@for($i=0; $i< $aux; $i++)
    @php
    {{$j=0;}}
    @endphp
    <body>
        <table class="tabela borda3">
            <tr>
                <td width="40%" class="centro">
                    <table class="logo">
                        <tr>
                            <td>
                                <img style="margin-left:20px; margin-top: -20px;width:220px; height: 65px;" src="img/logo_sarh.jpg">
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <label for=""><a><strong> </strong></a></label><br>
                            </td>
                        </tr>
                        <tr>
                            <td><a>Referência:</a></td>
                        </tr>
                        <tr>
                            <td><a>Período:</a></td>
                        </tr>
                    </table>
                </td>
                <td width="40%" class="centro">
                    <table class="assinatura">
                        <tr>
                            <td style="height: 30px; text-align: left"><label for="">Em: _____/ _____/___________</label></td>
                        </tr>
                        <tr>
                            <td style="padding-bottom: -20px; height: 50px; text-align: center">
                                <label for="">____________________________________________</label><br>
                             <label style="font-size: 10px" for=""> SUPERVISOR</label>
                            </td>
                        </tr>
                        <tr>
                            <td style="height: 30px; text-align: left"><label for="">VISTO</label></td>
                        </tr>
                        <tr>
                            <td style="padding-bottom: -10px; height: 50px; text-align: center">
                                <label for="">____________________________________________</label><br>
                                <label style="font-size: 10px" for=""> SECRETÁRIO(A)</label>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
        <br>
        <table id="customers">
            <tr>
                <th class="nome">Nome</th>
                <th class="matricula">Matrícula</th>
                <th class="numeros">Dias</th>
                <th class="numeros">Faltas</th>
                <th class="numeros">Vac</th>
                <th class="numeros">LSV</th>
                <th class="numeros">L M</th>
                <th class="numeros">Aci. Trab</th>
                <th class="numeros">Adi. Not</th>
                <th class="numeros">H.E Normal D</th>
                <th class="numeros">H.E Normal N</th>
                <th class="numeros">H.E Dom/Fer. D</th>
                <th class="numeros">H.E Dom/Fer. N</th>
                <th class="numeros">Ins.</th>
            </tr>

            @foreach ($servidores[$i] as $servidor)
                <tr>
                    <td style="height: 20px;"><a>{{$servidor->nm_servidor}}</a></td>
                    <td style="height: 20px;"><a>{{$servidor->cd_departamento}}</a></td>
                    <td style="height: 20px;"><a>30</a></td>
                    <td style="height: 20px;"><a>2</a></td>
                    <td style="height: 20px;"><a>2</a></td>
                    <td style="height: 20px;"><a>2</a></td>
                    <td style="height: 20px;"><a>2</a></td>
                    <td style="height: 20px;"><a>2</a></td>
                    <td style="height: 20px;"><a>2</a></td>
                    <td style="height: 20px;"><a>20,02</a></td>
                    <td style="height: 20px;"><a>20,02</a></td>
                    <td style="height: 20px;"><a>20,02</a></td>
                    <td style="height: 20px;"><a>20,02</a></td>
                    <td style="height: 20px;"><a>20</a></td>
                </tr>
                <tr>
                    <td style="height: 20px;" colspan="14">Observação:</td>
                </tr>
                @if($j == 16)
                    @break
                @endif
                @php
                    {{$j++;}}
                @endphp
            @endforeach
        </table>
    </body>
@endfor
</html>
    
asked by anonymous 29.08.2018 / 16:06

1 answer

0

I believe that one solution is for you to group by department and thus go through the two loops (departments, members by department).

Something like this:

@foreach ($departamentos as $departamento)
   @foreach ($departamento->funcionarios as $funcionario)
     <html>
   @endforeach
@endforeach

I hope I have helped!

    
29.08.2018 / 17:44