4
I need to perform the sum of positive and negative hours for a virtual electronic point control. However, I am having difficulties to accomplish the sum, because the hours are not being correctly added up, and when it is added up, the hours of the day are being parameterized and not the total hours.
My code already brings me the hours of each electronic point beat and I can rescue the beat times of each day and print on screen without problems. What I cannot do is add up the hours that have exceeded the working hours of the employees (the logic for calculating excess hours also works perfectly).
Let’s get to the problem. 1- This is the HTML table that prints the values:
ID | Excedentes |
1 | - 03:00 |
2 | + 00:14 |
3 | + 00:20 |
4 | - 01:24 |
5 | - 00:02 |
6 | + 00:01 |
---|------------|
Total Positivo que está trazendo: + 00:01
//O correto seria trazer + 00:35 (com base nestes dados informados)
Total Negativo que está trazendo: - 11:26
//O correto seria trazer - 04:26 (com base nestes dados informados)
It is worth mentioning that the hours can exceed 24 hours, because I need to know the total sum.
2- This is the code that stores the rescued time from the database (I used a global variable to make it easier to rescue on screen in the PHP tag):
/*Acima desse código existe todas as tratativas que funciona corretamente
para armazenar, resgatar e imprimir os dados na tela, apenas crio uma
variável global para armazenar o valor (pois o mesmo está dentro de um loop,
e cada vez que passa pelo loop, naturalmente o valor muda)*/
$GLOBALS['negativas'] = 0;
$GLOBALS['positivas'] = 0;
if($sinal == "- "){
$GLOBALS['negativas'] = ($horas.':'.$minutos);
}
if($sinal == "+ "){
$GLOBALS['positivas'] = ($horas.':'.$minutos);
}
//Retorna na tela as horas excedidas juntamente com o sinal + ou - em horas
/* (este return também já está correto, pois ele é a tabela que demonstrei
anteriormente).*/
return '<span style="color:'.$style.'">'.$sinal.$horas.':'.$minutos.'<input hidden value="'.$sinal.$horas.':'.$minutos.'"></span>';
3- Here, is the code I’m trying to accomplish on screen to print the total:
<?php //imprime as horas excedidas do dia
echo $somatorio->horasExcedidasDia($intervals, $expediente,$registro->getDiaSemana(), $registro->getMarcacoes(), $funcionario->getHorario()->getId());
$positivas = strtotime($GLOBALS['positivas']);
$negativas += strtotime($GLOBALS['negativas']);
<td>+ <strong><?php echo date('H:i',$positivas) ?></strong></td>
<td colspan="2">- <strong><?php echo date('H:i', $negativas); ?></strong></td>
?>
4- I made a var_dump
(only in the negative hours) on the screen so that you can view the sum that PHP is doing (which by the way is incorrect).
ID | Excedentes | VAR_DUMP |
1 | - 03:00 | 03:00 ok |
2 | + 00:14 | - |
3 | + 00:20 | - |
4 | - 01:24 | 08:24 err|
5 | - 00:02 | 11:26 err|
6 | + 00:01 | - |
---|------------|----------|
NOTE: The values that are in the column SURPLUS, is exactly the values that I am passing to the global.
Thank you very much, I was able to understand perfectly and it was clear the understanding of the code and application.
– Aiden Pearce