2
I have a billing system for hours which I am trying to make charges for fractions of 15 min. It takes the difference of the time of entry and exit and adds the remaining time, example:
- Check-in 09:00 - Check-out 09:11
- Real time: 00:11 - Billing time: 00:15.
And so successively every 15.
I put together a code that works for up to 60 minutes, however, my question lies in after this time passes. It does not add fractions, but normal minutes.
Is there any way to recognize that after 01:00:01 you must add the fraction of 15 successively? Below follows the code:
<?php
$horaInicial = $_POST['inicio'];
$horaFinal = $_POST['final'];
$fator15 = 900;
$fator30 = 1800;
$fator45 = 2700;
$fator60 = 3600;
$horaMais = 3600;
$horaInicial = strtotime($horaInicial);
$horaFinal = strtotime($horaFinal);
$totalSegundos = ($horaFinal - $horaInicial);
switch($totalSegundos){
case ($totalSegundos < $fator15):
while($totalSegundos < $fator15){
$totalSegundos++;
}
break;
case ($totalSegundos > $fator15 && $totalSegundos < $fator30):
while($totalSegundos < $fator30){
$totalSegundos++;
}
break;
case ($totalSegundos > $fator30 && $totalSegundos < $fator45):
while($totalSegundos < $fator45){
$totalSegundos++;
}
break;
case ($totalSegundos > $fator45 && $totalSegundos < $fator60):
while($totalSegundos < $fator60){
$totalSegundos++;
}
break;
case($totalSegundos > $fator60):
while($totalSegundos < $fator15){
$totalSegundos++;
}
}
$resultado = gmdate("H:i", $totalSegundos);
echo "Total: ".$resultado;
?>
Not an answer is a real lesson. I am very grateful for the help.I will implement in the code and put the result. I hope one day to reach your level!
– ricardojfsp