Relate 4 bank tables and perform accounts

1

Hello I have 4 tables: Officials, Companies, Salaries and Discounts. I would like to introduce a kind of Holerite. My initial idea was to bring all the information together and treat the view as follows:

(NOTE: I'm using laravel blade)

@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

From this view a PDF is being generated. This code is working fine, but I worry if this process can get heavy with the increase of employees in the company, is there a better solution?

Thank you.

    
asked by anonymous 04.01.2018 / 00:55

1 answer

1

Let's go at a few points, as the number of employees is clear it may slow down, but I think you should care less about the volume of data and more about how to look for and treat them. For example, there are ways to assemble queries that return Gigas of data in seconds, but what influences performance a lot is how to treat the data after the query in the database. I'll talk a little about good practices for MVC that will improve performance, nothing too technical in development ...

You mentioned: bring all the information together and treat in the view .

See the problem of doing this ... You are using an MVC framework (Model - View - Controller), one of the biggest sins one can commit is to "treat" the data in the view file, this is the Controllers, you will leave the data ready and only send to View, even if in the last case, try to minimize the loops of foreachs by sending more complete objects to View instead of traversing several arrays of objects inside it. You can solve this with some Joins in the controller query. After that you can test various forms of queries and treatments on the Controller, even using the Models to optimize the searches (Laravel makes that a lot easier). Using the basic good practices of an MVC frame will already give you a significant improvement in performance and in the end you will notice that the least worry will be the database's data volume.

This is a simple answer that can be complemented, additional suggestions are welcome.

    
04.01.2018 / 12:46