1
Hello I have 4 tables: Employees, Companies, Salaries and Discounts. I would like to present a kind of Holerite. My initial idea was to bring all the information together and treat the view as follows:
(OBS: I’m using Laravel Slide)
@foreach ($funcionarios as $funcionario)
@php
$total_vencimentos = 0;
$total_descontos = 0;
$total_liquido = 0;
@endphp
@foreach ($vencimentos as $vencimento)
@if ($funcionario->id == $vencimento->funcionario_id)
imprime os vencimentos
@endif
@php $total_vencimentos += $vencimento->valor_adicionado @endphp
@endforeach
@foreach ($descontos as $desconto)
@if ($funcionario->id == $desconto->funcionario_id)
imprime os vencimentos
@endif
@php $total_vencimentos += $desconto->valor_descontado @endphp
@endforeach
@php
$total_liquido = ($total_vencimentos - $total_descontos);
@endphp
@endforeach
This view is generating a PDF. This code is working well, but I worry if this process can get heavy with the increase of employees in the company, there is a better solution ?
Thank you.
Thanks for the recommendations, I’ll bring the logic to the controller. But in the matter of functioning I was still a little confused. After all if I perform the query using Join, only one line each employee would return and what I need is the employee -> company -> ALL salaries and ALL discounts. For this reason called separate. It is possible to make this query in a single query ?
– Drealler
If Voce has a key in common in the tables is possible yes, in this case I believe it has a field with id of the company or employee in all tables then it would be much easier, if you need help in the assembly of the query I think would fit until open another topic to help us.
– Darlei Fernando Zillmer
I have the key, and yes the doubt was really on how to mount. I will open a new Question. Thank you...
– Drealler