2
I developed an application that generates Holerites, and for this I need to process data from 4 tables.
Employees -> Companies -> Salaries -> Discounts
I want to show my user the following way for example:
Rafael works in the company X and has 10 salaries and 20 Discounts.
Code Example:
$total_vencimento= 0;
$total_desconto = 0;
// Aqui em funcionários realizei um join com empresas.
foreach ($funcionarios as $funcionario) {
foreach ($vencimentos as $vencimento) {
//VERIFICA SE PERTENCE AO FUNCIONARIO ATUAL E PRINTA
$total_vencimento += $vencimento->valor;
}
foreach ($descontos as $desconto) {
//VERIFICA SE PERTENCE AO FUNCIONARIO ATUAL E PRINTA
$total_desconto += $desconto->valor;
}
// Aqui apresentaria o valor liquido entra Vencimentos - Descontos
}
I would like to know how best to perform a query or procedure by PHP itself, to be able to generate these Holerites. I’ll generate the Holerites based on the company ID. The user will select the company and will generate the Holerites of all employees, decriminalizing the names of Salaries and Discounts and their values.
I am currently bringing all employees belonging to the company, and their respective salaries and discounts. I run all this on a foreach and Czech if that expiration/discount belongs to the current loop employee and printo.
Which structure of your tables? You can use JOIN
– Valdeir Psr
Join would bring all the records of salaries and discounts ? It does not bring only one ?
– Drealler
Utilize
Left Join
. It will bring several results. Depending on what you want, you don’t even need to make aforeach
, just add it all up with aquery sql
.– Valdeir Psr
I added a photo of how I want to show, I want to show the employee, the company he works for and discriminate each salary and discount.
– Drealler