Loop(For) doubt with information coming from the database

Asked

Viewed 23 times

-1

E ae personal blz ?

I’m having a big problem executing a code of my own.

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

The report is incomplete. I’m not getting the programming logic to work 100% the way I want it to.

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

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

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

inserir a descrição da imagem aqui

I’m unable to do is to go back to printing where you left off when there is a list of more than 16 employees per department.

Could someone help me ?

Follow my code below:

<!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>

1 answer

0

I believe that one solution will be you group by department and so go through the two loops (departments, members by department).

Something more or less like this:

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

I hope I’ve helped!

Browser other questions tagged

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