Skip to main content
    $html .= "<table width='70%' align='center' border='1' cellspacing='0' cellpadding='0' style='background:#ffffff;border-collapse:collapse;font-family:verdana;font-size:12px;' bordercolor='#CCCCCC'>";

$html .= ""; $html .= ""; $html .= "JORNADA DE TRABALHO
".BuscaVeiculo($cd_veiculo)."

".$dt_ini." - ".$dt_fim.""; $html .= ""; $html .= ""; $html .= ""; // INI DETALHADO//// if($cka == 0){ $html .= ""; $html .= "Situação"; $html .= "Inicial"; $html .= "Fim"; $html .= "Tempo"; $html .= ""; $aa = 0; $pp = 0; $Inicio = $dt_ini; $Fim = $dt_fim; $Veiculo = $cd_veiculo; $Inicial = $dt_ini." 00:00"; $Final = $dt_fim." 23:59"; $Inicial = DtBrToDtEua($Inicial, 4); $Final = DtBrToDtEua($Final, 4);

$SQL$html .= "SELECT dt_hora as dt, ";"<tr>";
$SQL$html .= " (sqrt(((vl_latitude - (vl_lati_anterior))*(vl_latitude - (vl_lati_anterior))) + ((vl_longitude - (vl_long_anterior))*(vl_longitude - (vl_long_anterior))))*111)"<td aswidth='20%' distanciaalign='center'><img ";src='../../imagens/logop.png'></td>";
$SQL$html .= " from hist_posicao"<td wherealign='center'><font cd_veiculosize='3'><strong>JORNADA =DE '"TRABALHO<br>". $Veiculo BuscaVeiculo($cd_veiculo)."' ";
$SQL "</strong></font><br>".= $dt_ini." and dt_hora >=- '"". $Inicial $dt_fim."' and dt_hora <="</td>";
$html '".= $Final"</tr>";
$html ."'= ";"</table>";
$SQL$html .= ""<table orderwidth='70%' byalign='center' dt_horaborder='0' asccellspacing='1' ";cellpadding='1' style='font-family:verdana;font-size:11px;'>";
//echo $html .= $SQL;exit;
$RSS = mysql_query($SQL,INI $conexao);DETALHADO////
if(mysql_num_rows($RSS)$cka >== 0){
$html .= "<tr bgcolor='#DDD7CA'>";
$html .= "<td><strong>Situação</strong></td>";
$html .= "<td><strong>Inicial</strong></td>";
$html .= "<td><strong>Fim</strong></td>";
$html .= $RS"<td><strong>Tempo</strong></td>";
$html .= mysql_fetch_assoc($RSS);"</tr>";
    $st$aa = 0;
    $dia$pp = date("d", strtotime($RS["dt"]));0;
    if($RS["distancia"]$Inicio >= 0.3 && $RS["ig"] == 1){$ini = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st = 1;}$dt_ini;
    if($RS["distancia"]$Fim < 0.3 && $RS["ig"] == 0){$ini = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st = 2;}$dt_fim;
    if($cor$Veiculo == "#FFFFFF"){$cor = "#DDDDDD";}else{$cor = "#FFFFFF";}
  = $cd_veiculo;
 if(diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "1"$Inicial && diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "7")//se dia semana não= for$dt_ini." 100:00";
 nem 7
  $Final      {$corsm = "#ffff99";}else{$corsm  = "#33ff66";}//definição$dt_fim." para23:59";
 cor da linha para$Inicial final de semana e dia de semana
 = DtBrToDtEua($Inicial, 4);
 $html .= "<tr bgcolor='".$corsm."'><td$Final colspan='4' align='center'><b>".dsdiadasemana(date("d/m/Y", strtotime($RS["dt"])))." | ".date("d/m/Y", strtotime($RS["dt"]))."</b></td></tr>";//nome do dia da semana= eDtBrToDtEua($Final, data4);
    
    while($RS = mysql_fetch_array($RSS)){
      $SQL = $x"SELECT =dt_hora $xas +dt, 1;";
     $SQL .= " if($diasqrt(((vl_latitude !=- date("d",vl_lati_anterior))*(vl_latitude strtotime- ($RS["dt"]vl_lati_anterior))){
           + if($st(vl_longitude ==- 1(vl_long_anterior){
)*(vl_longitude - (vl_long_anterior))))*111) as distancia ";
    $SQL .= " from hist_posicao where cd_veiculo //echo= $ini'"." |$Veiculo ".$ultimo"' ."<br><br><br>";";
                $html$SQL .= "<tr bgcolor='".$cor."'><td>Andando</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $ultimo." 23:59"))."</td></tr>";
and dt_hora >= '". $Inicial ."' and dt_hora <= '". $Final ."' ";
    $andando$SQL .= $andando + datediff("n", $ini, $ultimo." 23:59");
 order by dt_hora asc ";
    //echo $html .= $SQL;exit;
    $aa$RSS = $aa + datediffmysql_query("n", $ini$SQL, $ultimo." 23:59"$conexao);
                if(diadasemana($ultimo) != "1" && diadasemanamysql_num_rows($ultimo$RSS) !=> "7"0)
            {        
 {$saa = $saa + datediff("n", $ini, $ultimo." 23:59");}else{$fsaa$RS = $fsaa + datediffmysql_fetch_assoc("n", $ini, $ultimo." 23:59"$RSS);}
            }
            if($st == 2){
                //echo $ini." | ".$ultimo ."<br>";         = 0;
                $html$dia .= "<tr bgcolor='".$cor."'><td>Parado</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediffdate("n", $ini"d", $ultimo." 23:59"strtotime($RS["dt"]))."</td></tr>";//header;
                $parado = $parado + datediffif("n",$RS["distancia"] $ini,>= $ultimo0." 23:59");
            3 && $RS["ig"] == $pp1){$ini = $pp + datediffdate("n", $ini"d/m/Y", $ultimostrtotime($RS["dt"]))." 2300:59");
     00"; $st = 1;}
        if(diadasemana($ultimo)$RS["distancia"] !=< "1"0.3 && diadasemana($ultimo)$RS["ig"] !=== "7"0)
                    {$spp = $spp + datediff("n", $ini, $ultimo." 23:59");}else{$fspp = $fspp + datediffdate("n", $ini"d/m/Y", $ultimostrtotime($RS["dt"]))." 2300:59");}
         00"; $st = 2;}
            $html .= "<tr bgcolor='".if($cor."'><td colspan='3'><b>Andando no== Dia</b></td><td><b>".MinToHrMin($andando"#FFFFFF")."</b></td></tr>";
            $html{$cor .= "<tr bgcolor='"."#DDDDDD";}else{$cor."'><td colspan='3'><b>Parado no= Dia</b></td><td><b>".MinToHrMin($parado)."</b></td></tr>";"#FFFFFF";}
            if(diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "1" && diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "7")
 //se dia semana não for 1 nem 7
            {$corsm = "#ffff99";}else{$corsm = "#33ff66";}
 //definição para cor da linha para final de semana e dia de semana
        $html .= "<tr bgcolor='".$corsm."'><td colspan='4' align='center'><b>".dsdiadasemana(date("d/m/Y", strtotime($RS["dt"])))." | ".date("d/m/Y", strtotime($RS["dt"]))."</b></td></tr>";
            
            if($cor//nome ==do "#FFFFFF"){$cordia =da "#DDDDDD";}else{$corsemana =e "#FFFFFF";}data
            $andando = 0;
            $paradowhile($RS = 0;mysql_fetch_array($RSS)){
            if($RS["distancia"] >= 0.3){$ini$x = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st$x =+ 1;}
            if($RS["distancia"] < 0.3){$ini$dia != date("d/m/Y""d", strtotime($RS["dt"]))." 00:00"; $st = 2;}
        }
        if($x > 1){
            if($RS["distancia"] >= 0.3){
                if($st == 1){
                    $fim//echo $ini." | ".$ultimo ."<br><br><br>";
                    $html .= date"<tr bgcolor='".$cor."'><td>Andando</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin("ddatediff("n", $ini, $ultimo." 23:59"))."</mtd></Ytr>";
 H                   $andando = $andando + datediff("n", $ini, $ultimo." 23:i"59");
                    $aa = $aa + datediff("n", strtotime$ini, $ultimo." 23:59");
                    if($RS["dt"]diadasemana($ultimo) != "1" && diadasemana($ultimo) != "7");
                    $st    {$saa = 1;$saa + datediff("n", $ini, $ultimo." 23:59");}else{$fsaa = $fsaa + datediff("n", $ini, $ultimo." 23:59");}
                }
                if($st == 2){
                    if(//echo $ini." !=| $fim){
".$ultimo ."<br>";          
                    $html .= "<tr bgcolor='".$cor."'><td>Parado</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $fim$ultimo." 23:59"))."</td></tr>";
                    }//header
                    $parado = $parado + datediff("n", $ini, $fim$ultimo." 23:59");
                    $pp = $pp + datediff("n", $ini, $fim$ultimo." 23:59");
                    if(diadasemana($fim$ultimo) != "1" && diadasemana($fim$ultimo) != "7")
                        {$spp = $spp + datediff("n", $ini, $fim$ultimo." 23:59");}else{$fspp = $fspp + datediff("n", $ini, $fim$ultimo." 23:59");}
                    $ini = $fim;
                    $st = 1;
                }
                $html .= "<tr bgcolor='".$cor."'><td colspan='3'><b>Andando no Dia</b></td><td><b>".MinToHrMin($andando)."</b></td></tr>";
                $html .= "<tr bgcolor='".$cor."'><td colspan='3'><b>Parado no Dia</b></td><td><b>".MinToHrMin($parado)."</b></td></tr>";
                if(diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "1" && diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "7")
                    {$corsm = "#ffff99";}else{$corsm = "#33ff66";}
                $html .= "<tr bgcolor='".$corsm."'><td colspan='4' align='center'><b>".dsdiadasemana(date("d/m/Y", strtotime($RS["dt"])))." | ".date("d/m/Y", strtotime($RS["dt"]))."</b></td></tr>";
                
                if($cor == "#FFFFFF"){$cor = "#DDDDDD";}else{$cor = "#FFFFFF";}
                $andando = 0;
                $parado = 0;
                if($RS["distancia"] >= 0.3){$ini = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st = 1;}
                if($RS["distancia"] < 0.3){$ini = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st = 2;}
            }
            if($RS["distancia"]$x <> 0.031){
                if($st$RS["distancia"] ==>= 10.3){
                    if($ini$st !=== $fim1){
                        $html$fim .= "<tr bgcolor='".$cor."'><td>Andando</td><td>".$ini."<date("d/td><td>".$fim."<m/td><td>".MinToHrMin(datediff("n",Y $iniH:i", $fimstrtotime($RS["dt"]))."</td></tr>";;
                        $st = 1;
                    }
                    $andandoif($st == 2){
                        if($ini != $andando$fim){
                            $html .= "<tr bgcolor='".$cor."'><td>Parado</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $fim))."</td></tr>";
                        }
                        $parado = $parado + datediff("n", $ini, $fim);
                    $aa    $pp = $aa$pp + datediff("n", $ini, $fim);
                        if(diadasemana($fim) != "1" && diadasemana($fim) != "7")
                            {$saa$spp = $saa$spp + datediff("n", $ini, $fim);}else{$fsaa$fspp = $fsaa$fspp + datediff("n", $ini, $fim);}
                        $ini = $fim;
                        $st = 2;1;
                    }
                }
                if($RS["distancia"] < 0.03){
                    if($st == 1){
                        if($ini != $fim){
                            $html .= "<tr bgcolor='".$cor."'><td>Andando</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $fim))."</td></tr>";
                        }
                        $andando = $andando + datediff("n", $ini, $fim);
                        $aa = $aa + datediff("n", $ini, $fim);
                        if(diadasemana($fim) != "1" && diadasemana($fim) != "7")
                            {$saa = $saa + datediff("n", $ini, $fim);}else{$fsaa = $fsaa + datediff("n", $ini, $fim);}
                        $ini = $fim;
                        $st = 2;
                    }
                    if($st == 2){
                        $fim = date("d/m/Y H:i", strtotime($RS["dt"]));
                        $st = 2;
                    }
                }
            }
            
            $dia    = date("d", strtotime($RS["dt"]));
            $ultimo = date("d/m/Y", strtotime($RS["dt"]));
        }
        
        $dia    = date("d", strtotime($RS["dt"]));
        $ultimo = date("d/m/Y", strtotime($RS["dt"]));
    }
    
    if($st == 1){
        $html .= "<tr bgcolor='".$cor."'><td>Andando</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $ultimo." 23:59"))."</td></tr>";
        $andando = $andando + datediff("n", $ini, $ultimo." 23:59");
        $aa = $aa + datediff("n", $ini, $ultimo." 23:59");
        if(diadasemana($ultimo) != "1" && diadasemana($ultimo) != "7")
            {$saa = $saa + datediff("n", $ini, $ultimo." 23:59");}else{$fsaa = $fsaa + datediff("n", $ini, $ultimo." 23:59");}
    }
    
    if($st == 2){
        $html .= "<tr bgcolor='".$cor."'><td>Parado</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $ultimo." 23:59"))."</td></tr>";
        //$teste = number_format((1439/60),1)-substr(number_format((1439/60),1),-2);
        //if($teste == 24){$teste = 23;}
        //echo $teste;
        //echo /*MinToHrMin(*/datediff("n", $ini, $ultimo." 23:59")/*)*/;
        $parado = $parado + datediff("n", $ini, $ultimo." 23:59");
        $pp = $pp + datediff("n", $ini, $ultimo." 23:59");
        if(diadasemana($ultimo) != "1" && diadasemana($ultimo) != "7")
            {$spp = $spp + datediff("n", $ini, $ultimo." 23:59");}else{$fspp = $fspp + datediff("n", $ini, $ultimo." 23:59");}
    }

if($st == 1){
    $html .= "<tr bgcolor='".$cor."'><td>Andando<"'><td colspan='3'><b>Andando no Dia</td><td>"b></td><td><b>".$iniMinToHrMin($andando)."</td><td>"b></td></tr>";
    $html .$fim= "<tr bgcolor='"."<$cor."'><td colspan='3'><b>Parado no Dia</td><td>"b></td><td><b>".MinToHrMin(datediff("n",$parado)."</b></td></tr>";
 $ini, $ultimo  $html ."= 23:59")"<tr bgcolor='#ffff99'><td colspan='3'><b>Total Andando no Período Semana</b></td><td><b>".MinToHrMin($saa)."</b></td></tr>";
    $andando$html .= $andando"<tr +bgcolor='#ffff99'><td datediff("n",colspan='3'><b>Total $ini,Parado $ultimo."no 23:59"Período Semana</b></td><td><b>".MinToHrMin($spp);."</b></td></tr>";
    $aa$html .= $aa"<tr +bgcolor='#33ff66'><td datediff("n",colspan='3'><b>Total $ini,Andando $ultimo."no 23:59"Período Final de Semana</b></td><td><b>".MinToHrMin($fsaa);."</b></td></tr>";
    if(diadasemana($ultimo)$html !.= "1""<tr &&bgcolor='#33ff66'><td diadasemanacolspan='3'><b>Total Parado no Período Final de Semana</b></td><td><b>".MinToHrMin($ultimo$fspp)."</b></td></tr>";
 !   $html .= "7")
"<tr bgcolor='#FFDFB0'><td colspan='3'><b>Total Andando no Período</b></td><td><b>".MinToHrMin($aa)."</b></td></tr>";
   {$saa $html .= $saa"<tr +bgcolor='#FFDFB0'><td datediff("n",colspan='3'><b>Total $ini,Parado $ultimo."no 23:59"Período</b></td><td><b>".MinToHrMin($pp);}else{$fsaa."</b></td></tr>";
    $html .= $fsaa"<tr><td +colspan='4' datediff("n",style='color:red' $ini,align='center'><b>* $ultimo."Entende-se 23por ANDANDO:59");}
} Deslocamento Maior 300 metros</b></td></tr>";

if($st == 2){
    $html .= "<tr bgcolor='".$cor."'><td>Parado</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $ultimo." 23:59"))."</td></tr>";
    //$teste = number_format((1439/60),1)-substr(number_format((1439/60),1),-2);
    //if($teste == 24){$teste = 23;}
    //echo $teste;
    //echo /*MinToHrMin(*/datediff("n", $ini, $ultimo." 23:59")/*)*/;
    $parado = $parado + datediff("n", $ini, $ultimo." 23:59");
    $pp = $pp + datediff("n", $ini, $ultimo." 23:59");
    if(diadasemana($ultimo) != "1" && diadasemana($ultimo) != "7")
        {$spp = $spp + datediff("n", $ini, $ultimo." 23:59");}else{$fspp = $fspp + datediff("n", $ini, $ultimo." 23:59");}table>";
}

$html .= "<tr bgcolor='".$cor."'><td colspan='3'><b>Andando no Dia</b></td><td><b>".MinToHrMin($andando)."</b></td></tr>";
$html .= "<tr bgcolor='".$cor."'><td colspan='3'><b>Parado no Dia</b></td><td><b>".MinToHrMin($parado)."</b></td></tr>";
$html .= "<tr bgcolor='#ffff99'><td colspan='3'><b>Total Andando no Período Semana</b></td><td><b>".MinToHrMin($saa)."</b></td></tr>";
$html .= "<tr bgcolor='#ffff99'><td colspan='3'><b>Total Parado no Período Semana</b></td><td><b>".MinToHrMin($spp)."</b></td></tr>";
$html .= "<tr bgcolor='#33ff66'><td colspan='3'><b>Total Andando no Período Final de Semana</b></td><td><b>".MinToHrMin($fsaa)."</b></td></tr>";
$html .= "<tr bgcolor='#33ff66'><td colspan='3'><b>Total Parado no Período Final de Semana</b></td><td><b>".MinToHrMin($fspp)."</b></td></tr>";
$html .= "<tr bgcolor='#FFDFB0'><td colspan='3'><b>Total Andando no Período</b></td><td><b>".MinToHrMin($aa)."</b></td></tr>";
$html .= "<tr bgcolor='#FFDFB0'><td colspan='3'><b>Total Parado no Período</b></td><td><b>".MinToHrMin($pp)."</b></td></tr>";
$html .= "<tr><td colspan='4' style='color:red' align='center'><b>* Entende-se por ANDANDO: Deslocamento Maior 300 metros</b></td></tr>";

$html .= ""; }

$html .= "<table width='70%' align='center' border='1' cellspacing='0' cellpadding='0' style='background:#ffffff;border-collapse:collapse;font-family:verdana;font-size:12px;' bordercolor='#CCCCCC'>";

$html .= ""; $html .= ""; $html .= "JORNADA DE TRABALHO
".BuscaVeiculo($cd_veiculo)."

".$dt_ini." - ".$dt_fim.""; $html .= ""; $html .= ""; $html .= ""; // INI DETALHADO//// if($cka == 0){ $html .= ""; $html .= "Situação"; $html .= "Inicial"; $html .= "Fim"; $html .= "Tempo"; $html .= ""; $aa = 0; $pp = 0; $Inicio = $dt_ini; $Fim = $dt_fim; $Veiculo = $cd_veiculo; $Inicial = $dt_ini." 00:00"; $Final = $dt_fim." 23:59"; $Inicial = DtBrToDtEua($Inicial, 4); $Final = DtBrToDtEua($Final, 4);

$SQL = "SELECT dt_hora as dt, ";
$SQL .= " (sqrt(((vl_latitude - (vl_lati_anterior))*(vl_latitude - (vl_lati_anterior))) + ((vl_longitude - (vl_long_anterior))*(vl_longitude - (vl_long_anterior))))*111) as distancia ";
$SQL .= " from hist_posicao where cd_veiculo = '". $Veiculo ."' ";
$SQL .= " and dt_hora >= '". $Inicial ."' and dt_hora <= '". $Final ."' ";
$SQL .= " order by dt_hora asc ";
//echo $html .= $SQL;exit;
$RSS = mysql_query($SQL, $conexao);
if(mysql_num_rows($RSS) > 0){       
    $RS = mysql_fetch_assoc($RSS);
    $st = 0;
    $dia = date("d", strtotime($RS["dt"]));
    if($RS["distancia"] >= 0.3 && $RS["ig"] == 1){$ini = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st = 1;}
    if($RS["distancia"] < 0.3 && $RS["ig"] == 0){$ini = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st = 2;}
    if($cor == "#FFFFFF"){$cor = "#DDDDDD";}else{$cor = "#FFFFFF";}
    if(diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "1" && diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "7")//se dia semana não for 1 nem 7
        {$corsm = "#ffff99";}else{$corsm = "#33ff66";}//definição para cor da linha para final de semana e dia de semana
    $html .= "<tr bgcolor='".$corsm."'><td colspan='4' align='center'><b>".dsdiadasemana(date("d/m/Y", strtotime($RS["dt"])))." | ".date("d/m/Y", strtotime($RS["dt"]))."</b></td></tr>";//nome do dia da semana e data
    
    while($RS = mysql_fetch_array($RSS)){
        $x = $x + 1;
        if($dia != date("d", strtotime($RS["dt"]))){
            if($st == 1){
                //echo $ini." | ".$ultimo ."<br><br><br>";
                $html .= "<tr bgcolor='".$cor."'><td>Andando</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $ultimo." 23:59"))."</td></tr>";
                $andando = $andando + datediff("n", $ini, $ultimo." 23:59");
                $aa = $aa + datediff("n", $ini, $ultimo." 23:59");
                if(diadasemana($ultimo) != "1" && diadasemana($ultimo) != "7")
                    {$saa = $saa + datediff("n", $ini, $ultimo." 23:59");}else{$fsaa = $fsaa + datediff("n", $ini, $ultimo." 23:59");}
            }
            if($st == 2){
                //echo $ini." | ".$ultimo ."<br>";          
                $html .= "<tr bgcolor='".$cor."'><td>Parado</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $ultimo." 23:59"))."</td></tr>";//header
                $parado = $parado + datediff("n", $ini, $ultimo." 23:59");
                $pp = $pp + datediff("n", $ini, $ultimo." 23:59");
                if(diadasemana($ultimo) != "1" && diadasemana($ultimo) != "7")
                    {$spp = $spp + datediff("n", $ini, $ultimo." 23:59");}else{$fspp = $fspp + datediff("n", $ini, $ultimo." 23:59");}
            }
            $html .= "<tr bgcolor='".$cor."'><td colspan='3'><b>Andando no Dia</b></td><td><b>".MinToHrMin($andando)."</b></td></tr>";
            $html .= "<tr bgcolor='".$cor."'><td colspan='3'><b>Parado no Dia</b></td><td><b>".MinToHrMin($parado)."</b></td></tr>";
            if(diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "1" && diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "7")
                 {$corsm = "#ffff99";}else{$corsm = "#33ff66";}
             $html .= "<tr bgcolor='".$corsm."'><td colspan='4' align='center'><b>".dsdiadasemana(date("d/m/Y", strtotime($RS["dt"])))." | ".date("d/m/Y", strtotime($RS["dt"]))."</b></td></tr>";
            
            if($cor == "#FFFFFF"){$cor = "#DDDDDD";}else{$cor = "#FFFFFF";}
            $andando = 0;
            $parado = 0;
            if($RS["distancia"] >= 0.3){$ini = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st = 1;}
            if($RS["distancia"] < 0.3){$ini = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st = 2;}
        }
        if($x > 1){
            if($RS["distancia"] >= 0.3){
                if($st == 1){
                    $fim = date("d/m/Y H:i", strtotime($RS["dt"]));
                    $st = 1;
                }
                if($st == 2){
                    if($ini != $fim){
                        $html .= "<tr bgcolor='".$cor."'><td>Parado</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $fim))."</td></tr>";
                    }
                    $parado = $parado + datediff("n", $ini, $fim);
                    $pp = $pp + datediff("n", $ini, $fim);
                    if(diadasemana($fim) != "1" && diadasemana($fim) != "7")
                        {$spp = $spp + datediff("n", $ini, $fim);}else{$fspp = $fspp + datediff("n", $ini, $fim);}
                    $ini = $fim;
                    $st = 1;
                }
            }
            if($RS["distancia"] < 0.03){
                if($st == 1){
                    if($ini != $fim){
                        $html .= "<tr bgcolor='".$cor."'><td>Andando</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $fim))."</td></tr>";
                    }
                    $andando = $andando + datediff("n", $ini, $fim);
                    $aa = $aa + datediff("n", $ini, $fim);
                    if(diadasemana($fim) != "1" && diadasemana($fim) != "7")
                        {$saa = $saa + datediff("n", $ini, $fim);}else{$fsaa = $fsaa + datediff("n", $ini, $fim);}
                    $ini = $fim;
                    $st = 2;
                }
                if($st == 2){
                    $fim = date("d/m/Y H:i", strtotime($RS["dt"]));
                    $st = 2;
                }
            }
        }
        
        $dia    = date("d", strtotime($RS["dt"]));
        $ultimo = date("d/m/Y", strtotime($RS["dt"]));
    }
}

if($st == 1){
    $html .= "<tr bgcolor='".$cor."'><td>Andando</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $ultimo." 23:59"))."</td></tr>";
    $andando = $andando + datediff("n", $ini, $ultimo." 23:59");
    $aa = $aa + datediff("n", $ini, $ultimo." 23:59");
    if(diadasemana($ultimo) != "1" && diadasemana($ultimo) != "7")
        {$saa = $saa + datediff("n", $ini, $ultimo." 23:59");}else{$fsaa = $fsaa + datediff("n", $ini, $ultimo." 23:59");}
}

if($st == 2){
    $html .= "<tr bgcolor='".$cor."'><td>Parado</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $ultimo." 23:59"))."</td></tr>";
    //$teste = number_format((1439/60),1)-substr(number_format((1439/60),1),-2);
    //if($teste == 24){$teste = 23;}
    //echo $teste;
    //echo /*MinToHrMin(*/datediff("n", $ini, $ultimo." 23:59")/*)*/;
    $parado = $parado + datediff("n", $ini, $ultimo." 23:59");
    $pp = $pp + datediff("n", $ini, $ultimo." 23:59");
    if(diadasemana($ultimo) != "1" && diadasemana($ultimo) != "7")
        {$spp = $spp + datediff("n", $ini, $ultimo." 23:59");}else{$fspp = $fspp + datediff("n", $ini, $ultimo." 23:59");}
}

$html .= "<tr bgcolor='".$cor."'><td colspan='3'><b>Andando no Dia</b></td><td><b>".MinToHrMin($andando)."</b></td></tr>";
$html .= "<tr bgcolor='".$cor."'><td colspan='3'><b>Parado no Dia</b></td><td><b>".MinToHrMin($parado)."</b></td></tr>";
$html .= "<tr bgcolor='#ffff99'><td colspan='3'><b>Total Andando no Período Semana</b></td><td><b>".MinToHrMin($saa)."</b></td></tr>";
$html .= "<tr bgcolor='#ffff99'><td colspan='3'><b>Total Parado no Período Semana</b></td><td><b>".MinToHrMin($spp)."</b></td></tr>";
$html .= "<tr bgcolor='#33ff66'><td colspan='3'><b>Total Andando no Período Final de Semana</b></td><td><b>".MinToHrMin($fsaa)."</b></td></tr>";
$html .= "<tr bgcolor='#33ff66'><td colspan='3'><b>Total Parado no Período Final de Semana</b></td><td><b>".MinToHrMin($fspp)."</b></td></tr>";
$html .= "<tr bgcolor='#FFDFB0'><td colspan='3'><b>Total Andando no Período</b></td><td><b>".MinToHrMin($aa)."</b></td></tr>";
$html .= "<tr bgcolor='#FFDFB0'><td colspan='3'><b>Total Parado no Período</b></td><td><b>".MinToHrMin($pp)."</b></td></tr>";
$html .= "<tr><td colspan='4' style='color:red' align='center'><b>* Entende-se por ANDANDO: Deslocamento Maior 300 metros</b></td></tr>";

$html .= ""; }

    $html .= "<table width='70%' align='center' border='1' cellspacing='0' cellpadding='0' style='background:#ffffff;border-collapse:collapse;font-family:verdana;font-size:12px;' bordercolor='#CCCCCC'>";
$html .= "<tr>";
$html .= "<td width='20%' align='center'><img src='../../imagens/logop.png'></td>";
$html .= "<td align='center'><font size='3'><strong>JORNADA DE TRABALHO<br>".BuscaVeiculo($cd_veiculo)."</strong></font><br>".$dt_ini." - ".$dt_fim."</td>";
$html .= "</tr>";
$html .= "</table>";
$html .= "<table width='70%' align='center' border='0' cellspacing='1' cellpadding='1' style='font-family:verdana;font-size:11px;'>";
// INI DETALHADO////
if($cka == 0){
$html .= "<tr bgcolor='#DDD7CA'>";
$html .= "<td><strong>Situação</strong></td>";
$html .= "<td><strong>Inicial</strong></td>";
$html .= "<td><strong>Fim</strong></td>";
$html .= "<td><strong>Tempo</strong></td>";
$html .= "</tr>";
    $aa = 0; $pp = 0;
    $Inicio         = $dt_ini;
    $Fim            = $dt_fim;
    $Veiculo        = $cd_veiculo;
    $Inicial        = $dt_ini." 00:00";
    $Final          = $dt_fim." 23:59";
    $Inicial        = DtBrToDtEua($Inicial, 4);
    $Final          = DtBrToDtEua($Final, 4);
    

    $SQL = "SELECT dt_hora as dt, ";
    $SQL .= " (sqrt(((vl_latitude - (vl_lati_anterior))*(vl_latitude - (vl_lati_anterior))) + ((vl_longitude - (vl_long_anterior))*(vl_longitude - (vl_long_anterior))))*111) as distancia ";
    $SQL .= " from hist_posicao where cd_veiculo = '". $Veiculo ."' ";
    $SQL .= " and dt_hora >= '". $Inicial ."' and dt_hora <= '". $Final ."' ";
    $SQL .= " order by dt_hora asc ";
    //echo $html .= $SQL;exit;
    $RSS = mysql_query($SQL, $conexao);
    if(mysql_num_rows($RSS) > 0){        
        $RS = mysql_fetch_assoc($RSS);
        $st = 0;
        $dia = date("d", strtotime($RS["dt"]));
        if($RS["distancia"] >= 0.3 && $RS["ig"] == 1){$ini = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st = 1;}
        if($RS["distancia"] < 0.3 && $RS["ig"] == 0){$ini = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st = 2;}
        if($cor == "#FFFFFF"){$cor = "#DDDDDD";}else{$cor = "#FFFFFF";}
        if(diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "1" && diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "7")//se dia semana não for 1 nem 7
            {$corsm = "#ffff99";}else{$corsm = "#33ff66";}//definição para cor da linha para final de semana e dia de semana
        $html .= "<tr bgcolor='".$corsm."'><td colspan='4' align='center'><b>".dsdiadasemana(date("d/m/Y", strtotime($RS["dt"])))." | ".date("d/m/Y", strtotime($RS["dt"]))."</b></td></tr>";//nome do dia da semana e data
        
        while($RS = mysql_fetch_array($RSS)){
            $x = $x + 1;
            if($dia != date("d", strtotime($RS["dt"]))){
                if($st == 1){
                    //echo $ini." | ".$ultimo ."<br><br><br>";
                    $html .= "<tr bgcolor='".$cor."'><td>Andando</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $ultimo." 23:59"))."</td></tr>";
                    $andando = $andando + datediff("n", $ini, $ultimo." 23:59");
                    $aa = $aa + datediff("n", $ini, $ultimo." 23:59");
                    if(diadasemana($ultimo) != "1" && diadasemana($ultimo) != "7")
                        {$saa = $saa + datediff("n", $ini, $ultimo." 23:59");}else{$fsaa = $fsaa + datediff("n", $ini, $ultimo." 23:59");}
                }
                if($st == 2){
                    //echo $ini." | ".$ultimo ."<br>";          
                    $html .= "<tr bgcolor='".$cor."'><td>Parado</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $ultimo." 23:59"))."</td></tr>";//header
                    $parado = $parado + datediff("n", $ini, $ultimo." 23:59");
                    $pp = $pp + datediff("n", $ini, $ultimo." 23:59");
                    if(diadasemana($ultimo) != "1" && diadasemana($ultimo) != "7")
                        {$spp = $spp + datediff("n", $ini, $ultimo." 23:59");}else{$fspp = $fspp + datediff("n", $ini, $ultimo." 23:59");}
                }
                $html .= "<tr bgcolor='".$cor."'><td colspan='3'><b>Andando no Dia</b></td><td><b>".MinToHrMin($andando)."</b></td></tr>";
                $html .= "<tr bgcolor='".$cor."'><td colspan='3'><b>Parado no Dia</b></td><td><b>".MinToHrMin($parado)."</b></td></tr>";
                if(diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "1" && diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "7")
                    {$corsm = "#ffff99";}else{$corsm = "#33ff66";}
                $html .= "<tr bgcolor='".$corsm."'><td colspan='4' align='center'><b>".dsdiadasemana(date("d/m/Y", strtotime($RS["dt"])))." | ".date("d/m/Y", strtotime($RS["dt"]))."</b></td></tr>";
                
                if($cor == "#FFFFFF"){$cor = "#DDDDDD";}else{$cor = "#FFFFFF";}
                $andando = 0;
                $parado = 0;
                if($RS["distancia"] >= 0.3){$ini = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st = 1;}
                if($RS["distancia"] < 0.3){$ini = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st = 2;}
            }
            if($x > 1){
                if($RS["distancia"] >= 0.3){
                    if($st == 1){
                        $fim = date("d/m/Y H:i", strtotime($RS["dt"]));
                        $st = 1;
                    }
                    if($st == 2){
                        if($ini != $fim){
                            $html .= "<tr bgcolor='".$cor."'><td>Parado</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $fim))."</td></tr>";
                        }
                        $parado = $parado + datediff("n", $ini, $fim);
                        $pp = $pp + datediff("n", $ini, $fim);
                        if(diadasemana($fim) != "1" && diadasemana($fim) != "7")
                            {$spp = $spp + datediff("n", $ini, $fim);}else{$fspp = $fspp + datediff("n", $ini, $fim);}
                        $ini = $fim;
                        $st = 1;
                    }
                }
                if($RS["distancia"] < 0.03){
                    if($st == 1){
                        if($ini != $fim){
                            $html .= "<tr bgcolor='".$cor."'><td>Andando</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $fim))."</td></tr>";
                        }
                        $andando = $andando + datediff("n", $ini, $fim);
                        $aa = $aa + datediff("n", $ini, $fim);
                        if(diadasemana($fim) != "1" && diadasemana($fim) != "7")
                            {$saa = $saa + datediff("n", $ini, $fim);}else{$fsaa = $fsaa + datediff("n", $ini, $fim);}
                        $ini = $fim;
                        $st = 2;
                    }
                    if($st == 2){
                        $fim = date("d/m/Y H:i", strtotime($RS["dt"]));
                        $st = 2;
                    }
                }
            }
            
            $dia    = date("d", strtotime($RS["dt"]));
            $ultimo = date("d/m/Y", strtotime($RS["dt"]));
        }
    }
    
    if($st == 1){
        $html .= "<tr bgcolor='".$cor."'><td>Andando</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $ultimo." 23:59"))."</td></tr>";
        $andando = $andando + datediff("n", $ini, $ultimo." 23:59");
        $aa = $aa + datediff("n", $ini, $ultimo." 23:59");
        if(diadasemana($ultimo) != "1" && diadasemana($ultimo) != "7")
            {$saa = $saa + datediff("n", $ini, $ultimo." 23:59");}else{$fsaa = $fsaa + datediff("n", $ini, $ultimo." 23:59");}
    }
    
    if($st == 2){
        $html .= "<tr bgcolor='".$cor."'><td>Parado</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $ultimo." 23:59"))."</td></tr>";
        //$teste = number_format((1439/60),1)-substr(number_format((1439/60),1),-2);
        //if($teste == 24){$teste = 23;}
        //echo $teste;
        //echo /*MinToHrMin(*/datediff("n", $ini, $ultimo." 23:59")/*)*/;
        $parado = $parado + datediff("n", $ini, $ultimo." 23:59");
        $pp = $pp + datediff("n", $ini, $ultimo." 23:59");
        if(diadasemana($ultimo) != "1" && diadasemana($ultimo) != "7")
            {$spp = $spp + datediff("n", $ini, $ultimo." 23:59");}else{$fspp = $fspp + datediff("n", $ini, $ultimo." 23:59");}
    }

    $html .= "<tr bgcolor='".$cor."'><td colspan='3'><b>Andando no Dia</b></td><td><b>".MinToHrMin($andando)."</b></td></tr>";
    $html .= "<tr bgcolor='".$cor."'><td colspan='3'><b>Parado no Dia</b></td><td><b>".MinToHrMin($parado)."</b></td></tr>";
    $html .= "<tr bgcolor='#ffff99'><td colspan='3'><b>Total Andando no Período Semana</b></td><td><b>".MinToHrMin($saa)."</b></td></tr>";
    $html .= "<tr bgcolor='#ffff99'><td colspan='3'><b>Total Parado no Período Semana</b></td><td><b>".MinToHrMin($spp)."</b></td></tr>";
    $html .= "<tr bgcolor='#33ff66'><td colspan='3'><b>Total Andando no Período Final de Semana</b></td><td><b>".MinToHrMin($fsaa)."</b></td></tr>";
    $html .= "<tr bgcolor='#33ff66'><td colspan='3'><b>Total Parado no Período Final de Semana</b></td><td><b>".MinToHrMin($fspp)."</b></td></tr>";
    $html .= "<tr bgcolor='#FFDFB0'><td colspan='3'><b>Total Andando no Período</b></td><td><b>".MinToHrMin($aa)."</b></td></tr>";
    $html .= "<tr bgcolor='#FFDFB0'><td colspan='3'><b>Total Parado no Período</b></td><td><b>".MinToHrMin($pp)."</b></td></tr>";
    $html .= "<tr><td colspan='4' style='color:red' align='center'><b>* Entende-se por ANDANDO: Deslocamento Maior 300 metros</b></td></tr>";

$html .= "</table>";
}
Fonte Link

Somar horas PHP e MySQL

Peguei um projeto em andamento, um sistema de rastreamento que possui calculo de jornada de trabalho. O sistema calcula certo, porém algumas vezes somando tempo do veiculo parado e andando soma 24 horas e 59 minutos.

Vou tentar colocar parte do código aqui

$html .= "<table width='70%' align='center' border='1' cellspacing='0' cellpadding='0' style='background:#ffffff;border-collapse:collapse;font-family:verdana;font-size:12px;' bordercolor='#CCCCCC'>";

$html .= ""; $html .= ""; $html .= "JORNADA DE TRABALHO
".BuscaVeiculo($cd_veiculo)."

".$dt_ini." - ".$dt_fim.""; $html .= ""; $html .= ""; $html .= ""; // INI DETALHADO//// if($cka == 0){ $html .= ""; $html .= "Situação"; $html .= "Inicial"; $html .= "Fim"; $html .= "Tempo"; $html .= ""; $aa = 0; $pp = 0; $Inicio = $dt_ini; $Fim = $dt_fim; $Veiculo = $cd_veiculo; $Inicial = $dt_ini." 00:00"; $Final = $dt_fim." 23:59"; $Inicial = DtBrToDtEua($Inicial, 4); $Final = DtBrToDtEua($Final, 4);

$SQL = "SELECT dt_hora as dt, ";
$SQL .= " (sqrt(((vl_latitude - (vl_lati_anterior))*(vl_latitude - (vl_lati_anterior))) + ((vl_longitude - (vl_long_anterior))*(vl_longitude - (vl_long_anterior))))*111) as distancia ";
$SQL .= " from hist_posicao where cd_veiculo = '". $Veiculo ."' ";
$SQL .= " and dt_hora >= '". $Inicial ."' and dt_hora <= '". $Final ."' ";
$SQL .= " order by dt_hora asc ";
//echo $html .= $SQL;exit;
$RSS = mysql_query($SQL, $conexao);
if(mysql_num_rows($RSS) > 0){       
    $RS = mysql_fetch_assoc($RSS);
    $st = 0;
    $dia = date("d", strtotime($RS["dt"]));
    if($RS["distancia"] >= 0.3 && $RS["ig"] == 1){$ini = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st = 1;}
    if($RS["distancia"] < 0.3 && $RS["ig"] == 0){$ini = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st = 2;}
    if($cor == "#FFFFFF"){$cor = "#DDDDDD";}else{$cor = "#FFFFFF";}
    if(diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "1" && diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "7")//se dia semana não for 1 nem 7
        {$corsm = "#ffff99";}else{$corsm = "#33ff66";}//definição para cor da linha para final de semana e dia de semana
    $html .= "<tr bgcolor='".$corsm."'><td colspan='4' align='center'><b>".dsdiadasemana(date("d/m/Y", strtotime($RS["dt"])))." | ".date("d/m/Y", strtotime($RS["dt"]))."</b></td></tr>";//nome do dia da semana e data
    
    while($RS = mysql_fetch_array($RSS)){
        $x = $x + 1;
        if($dia != date("d", strtotime($RS["dt"]))){
            if($st == 1){
                //echo $ini." | ".$ultimo ."<br><br><br>";
                $html .= "<tr bgcolor='".$cor."'><td>Andando</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $ultimo." 23:59"))."</td></tr>";
                $andando = $andando + datediff("n", $ini, $ultimo." 23:59");
                $aa = $aa + datediff("n", $ini, $ultimo." 23:59");
                if(diadasemana($ultimo) != "1" && diadasemana($ultimo) != "7")
                    {$saa = $saa + datediff("n", $ini, $ultimo." 23:59");}else{$fsaa = $fsaa + datediff("n", $ini, $ultimo." 23:59");}
            }
            if($st == 2){
                //echo $ini." | ".$ultimo ."<br>";          
                $html .= "<tr bgcolor='".$cor."'><td>Parado</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $ultimo." 23:59"))."</td></tr>";//header
                $parado = $parado + datediff("n", $ini, $ultimo." 23:59");
                $pp = $pp + datediff("n", $ini, $ultimo." 23:59");
                if(diadasemana($ultimo) != "1" && diadasemana($ultimo) != "7")
                    {$spp = $spp + datediff("n", $ini, $ultimo." 23:59");}else{$fspp = $fspp + datediff("n", $ini, $ultimo." 23:59");}
            }
            $html .= "<tr bgcolor='".$cor."'><td colspan='3'><b>Andando no Dia</b></td><td><b>".MinToHrMin($andando)."</b></td></tr>";
            $html .= "<tr bgcolor='".$cor."'><td colspan='3'><b>Parado no Dia</b></td><td><b>".MinToHrMin($parado)."</b></td></tr>";
            if(diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "1" && diadasemana(date("d/m/Y", strtotime($RS["dt"]))) != "7")
                {$corsm = "#ffff99";}else{$corsm = "#33ff66";}
            $html .= "<tr bgcolor='".$corsm."'><td colspan='4' align='center'><b>".dsdiadasemana(date("d/m/Y", strtotime($RS["dt"])))." | ".date("d/m/Y", strtotime($RS["dt"]))."</b></td></tr>";
            
            if($cor == "#FFFFFF"){$cor = "#DDDDDD";}else{$cor = "#FFFFFF";}
            $andando = 0;
            $parado = 0;
            if($RS["distancia"] >= 0.3){$ini = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st = 1;}
            if($RS["distancia"] < 0.3){$ini = date("d/m/Y", strtotime($RS["dt"]))." 00:00"; $st = 2;}
        }
        if($x > 1){
            if($RS["distancia"] >= 0.3){
                if($st == 1){
                    $fim = date("d/m/Y H:i", strtotime($RS["dt"]));
                    $st = 1;
                }
                if($st == 2){
                    if($ini != $fim){
                        $html .= "<tr bgcolor='".$cor."'><td>Parado</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $fim))."</td></tr>";
                    }
                    $parado = $parado + datediff("n", $ini, $fim);
                    $pp = $pp + datediff("n", $ini, $fim);
                    if(diadasemana($fim) != "1" && diadasemana($fim) != "7")
                        {$spp = $spp + datediff("n", $ini, $fim);}else{$fspp = $fspp + datediff("n", $ini, $fim);}
                    $ini = $fim;
                    $st = 1;
                }
            }
            if($RS["distancia"] < 0.03){
                if($st == 1){
                    if($ini != $fim){
                        $html .= "<tr bgcolor='".$cor."'><td>Andando</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $fim))."</td></tr>";
                    }
                    $andando = $andando + datediff("n", $ini, $fim);
                    $aa = $aa + datediff("n", $ini, $fim);
                    if(diadasemana($fim) != "1" && diadasemana($fim) != "7")
                        {$saa = $saa + datediff("n", $ini, $fim);}else{$fsaa = $fsaa + datediff("n", $ini, $fim);}
                    $ini = $fim;
                    $st = 2;
                }
                if($st == 2){
                    $fim = date("d/m/Y H:i", strtotime($RS["dt"]));
                    $st = 2;
                }
            }
        }
        
        $dia    = date("d", strtotime($RS["dt"]));
        $ultimo = date("d/m/Y", strtotime($RS["dt"]));
    }
}

if($st == 1){
    $html .= "<tr bgcolor='".$cor."'><td>Andando</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $ultimo." 23:59"))."</td></tr>";
    $andando = $andando + datediff("n", $ini, $ultimo." 23:59");
    $aa = $aa + datediff("n", $ini, $ultimo." 23:59");
    if(diadasemana($ultimo) != "1" && diadasemana($ultimo) != "7")
        {$saa = $saa + datediff("n", $ini, $ultimo." 23:59");}else{$fsaa = $fsaa + datediff("n", $ini, $ultimo." 23:59");}
}

if($st == 2){
    $html .= "<tr bgcolor='".$cor."'><td>Parado</td><td>".$ini."</td><td>".$fim."</td><td>".MinToHrMin(datediff("n", $ini, $ultimo." 23:59"))."</td></tr>";
    //$teste = number_format((1439/60),1)-substr(number_format((1439/60),1),-2);
    //if($teste == 24){$teste = 23;}
    //echo $teste;
    //echo /*MinToHrMin(*/datediff("n", $ini, $ultimo." 23:59")/*)*/;
    $parado = $parado + datediff("n", $ini, $ultimo." 23:59");
    $pp = $pp + datediff("n", $ini, $ultimo." 23:59");
    if(diadasemana($ultimo) != "1" && diadasemana($ultimo) != "7")
        {$spp = $spp + datediff("n", $ini, $ultimo." 23:59");}else{$fspp = $fspp + datediff("n", $ini, $ultimo." 23:59");}
}

$html .= "<tr bgcolor='".$cor."'><td colspan='3'><b>Andando no Dia</b></td><td><b>".MinToHrMin($andando)."</b></td></tr>";
$html .= "<tr bgcolor='".$cor."'><td colspan='3'><b>Parado no Dia</b></td><td><b>".MinToHrMin($parado)."</b></td></tr>";
$html .= "<tr bgcolor='#ffff99'><td colspan='3'><b>Total Andando no Período Semana</b></td><td><b>".MinToHrMin($saa)."</b></td></tr>";
$html .= "<tr bgcolor='#ffff99'><td colspan='3'><b>Total Parado no Período Semana</b></td><td><b>".MinToHrMin($spp)."</b></td></tr>";
$html .= "<tr bgcolor='#33ff66'><td colspan='3'><b>Total Andando no Período Final de Semana</b></td><td><b>".MinToHrMin($fsaa)."</b></td></tr>";
$html .= "<tr bgcolor='#33ff66'><td colspan='3'><b>Total Parado no Período Final de Semana</b></td><td><b>".MinToHrMin($fspp)."</b></td></tr>";
$html .= "<tr bgcolor='#FFDFB0'><td colspan='3'><b>Total Andando no Período</b></td><td><b>".MinToHrMin($aa)."</b></td></tr>";
$html .= "<tr bgcolor='#FFDFB0'><td colspan='3'><b>Total Parado no Período</b></td><td><b>".MinToHrMin($pp)."</b></td></tr>";
$html .= "<tr><td colspan='4' style='color:red' align='center'><b>* Entende-se por ANDANDO: Deslocamento Maior 300 metros</b></td></tr>";

$html .= ""; }