0

Please I really need help! I have a laravel blade where there is a button that sends the form data to the controller and then a search is made in the database from this data received in the controller. The data is, company name, employee name or all employees of this company and a date range. So the search returns all the time clock markings of one or all employees of the same company. I am managing to generate normally in a pdf this information obtained. But if my search was made to have results for all employees of the company and not just one, the result is a list of all employees on a single page of the pdf. I would really like that when getting the result of all employees, this result was separated by page in the pdf according to the name of the employee. For example, employee X on one page, employee Y on another page, and employee Z on another page. How can I do this?

Form itens

My controller used to receive form data, search the database and generate the pdf in the "admin.attendance-pdf" view:

public function getPDF(Request $request)
{
if (permission::permitted('attendance')=='fail'){ return redirect()->route('denied'); }


$emp_id = $request->emp_id;
$start = date('Y-m-d', strtotime($request->start));
$end = date('Y-m-d', strtotime($request->end));
$time_format = table::settings()->value("time_format");



$attendance = table::attendance()->where('employee', $emp_id)->whereBetween('date', ["$start", "$end"])->orderBy('date', 'asc')->get();

view()->share ('time_format', $time_format);
$pdf = PDF ::loadView('admin.attendance-pdf', array('attendance' => $attendance));
return $pdf->stream();

}

The table present in the "admin.attendance-pdf" view:

<table width="100%" id="tableExportToPDF"  data-order='[[ 1, "asc"]]' style="font-size:7pt; text-align:center; margin-top:100px">
    <thead>
        <tr>
            <th>{{ __('Date') }}</th>
            <th>{{ __('Employee') }}</th>
            <th>{{ __('Clock In') }}</th>
            <th>{{ __('Clock Out') }}</th>
            <th>{{ __('Status') }} ({{ __("In") }}/{{ __("Out") }})</th>
            <th>{{ __('Start Interv') }}</th>
            <th>{{ __('End Interv') }}</th>
            <th>{{ __('Total Hours') }}</th>
        </tr>
    </thead>
    <tbody>
        @isset($attendance)
        @foreach ($attendance as $data)
        <tr>
            <td>@php echo e(date('d-m-Y', strtotime($data->date))) @endphp </td>
            <td>{{ $data->employee }}</td>
            <td>
            @php 
            if($time_format == 12) {
                echo e(date('h:i:s A', strtotime($data->timein)));
                } else {
                echo e(date('H:i:s', strtotime($data->timein)));
                }
            @endphp
            </td>
            <td>
            @isset($data->timeout)
            @php 
            if($time_format == 12) {
                echo e(date('h:i:s A', strtotime($data->timeout)));
                } else {
                echo e(date('H:i:s', strtotime($data->timeout)));
                }
            @endphp
            @endisset
            </td>
            <td>
            @if($data->status_timein !== null && $data->status_timeout !== null)
                <span class="@if($data->status_timein == 'Late In') text-warning @else text-primary @endif">{{ $data->status_timein }}</span>
                <span class="@if($data->status_timeout == 'Early Out') text-danger @else text-success @endif">{{ $data->status_timeout }}</span> 
            @elseif($data->status_timein == 'Late In')
                <span class="text-warning">{{ $data->status_timein }}</span>
            @else
                <span class="text-primary">{{ $data->status_timein }}</span>
            @endif
            </td>
            <td>
            @php
                $yesterday = date('Y-m-d',strtotime("-1 days"));
                $teste = (date('H:i:s', strtotime($data->breakstart)));
            if ($teste == "21:00:00"){
                echo "";
                } else
                echo e(date('H:i:s', strtotime($data->breakstart)));
            @endphp
            </td>
            <td>
            @isset($data->breakend)
            @php 
            if($time_format == 12) {
                echo e(date('h:i:s A', strtotime($data->breakend)));
                } else {
                echo e(date('H:i:s', strtotime($data->breakend)));
                }
            @endphp
            @endisset
            </td>
            <td>
            @isset($data->totalhours)
            @if($data->totalhours != null) 
            @php
            if(stripos($data->totalhours, ".") === false) {
                $h = $data->totalhours;
                } else {
                $HM = explode('.', $data->totalhours); 
                $h = $HM[0]; 
                $m = $HM[1];
                }
            @endphp
            @endif
            @if($data->totalhours != null)
            @if(stripos($data->totalhours, ".") === false)
                {{ $h }} hr
            @else 
                {{ $h }} hr {{ $m }} mins
            @endif
            @endif
            @endisset
            </td>
        </tr>
        @endforeach
        @endisset
    </tbody>
</table>

Result:

The result of the search for all employees of the same company returns on the same page of the pdf. I would like you to return each employee on a pdf page in the same pdf file.

Tiago
  • 1
  • Does this answer your question? [DOMpdf, adding a new page to PDF](https://stackoverflow.com/questions/22746958/dompdf-adding-a-new-page-to-pdf) – KIKO Software Mar 05 '23 at 16:16

0 Answers0