Path: C:\
<?php
ini_set('max_execution_time',1200);
date_default_timezone_set('America/Sao_Paulo');
$dateadded = date("d-m-Y");
$dia = date("d/m/Y");
$dia=date('Ymd', strtotime($dateadded. ' - 1 days'));
require_once("conexao_srvtms.php");
$query = sqlsrv_query( $conn, "SELECT a.id_Manifesto as manifesto
,c.ds_Pessoa as motorista
,d.cd_Placa as placa
,f.ds_TipoVeiculo as veiculo
,g.ds_Tipo as tipo
,e.cd_Placa as carreta
,convert(varchar(10),a.dt_PrevisaoSaida,105) as dt_prevista
,a.hr_PrevisaoSaida as hr_prevista
,convert(varchar(10),a.dt_Saida,105) as dt_saida
,a.hr_Saida as hr_saida
,a.cm_Manifesto as coment
,a.ds_Ajudante as ajudante
,a.ds_CidadeDestino as destino
,b.ds_Cidade as final
,a.ds_Clientes as cliente
FROM tbdManifesto as a
left JOIN tbdCidade AS b ON a.id_CidadeFinalEntrega = b.id_Cidade
left JOIN tbdPessoa AS c ON a.id_Motorista = c.id_Pessoa
left JOIN tbdVeiculo AS d ON a.id_Veiculo = d.id_Veiculo
left JOIN tbdVeiculo AS e ON a.id_Carreta = e.id_Veiculo
left JOIN tbdTipoVeiculo AS f ON d.id_TipoVeiculo = f.id_TipoVeiculo
left JOIN tbdManifestoMovimento AS g ON a.id_Manifesto = g.id_Manifesto
WHERE a.dt_PrevisaoSaida>='".$dia."' AND a.dt_Saida>='".$dia."'
ORDER BY dt_prevista, hr_prevista, manifesto, tipo ASC", array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
$z=0; $manifANT='';$dataANT='';
while ($res = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC))
{
if ($dataANT<>$res['dt_prevista']){$z++; $x[$z]=1; $manifANT='';$dataANT=$res['dt_prevista'];}
$data[$z]=$res['dt_prevista'];
$manifesto[$z][$x[$z]]=$res['manifesto'];
$tipox=trim($res['tipo']);
if ($manifANT<>$manifesto[$z][$x[$z]])
{
$linha[$z][$x[$z]][13]=0;$linha[$z][$x[$z]][14]=0;$linha[$z][$x[$z]][15]=0;
if ($tipox=='ENTREGA'){$linha[$z][$x[$z]][13]++;}else{if ($tipox=='COLETA'){$linha[$z][$x[$z]][14]++;}else{$linha[$z][$x[$z]][15]++;}}
$linha[$z][$x[$z]][1]=trim($res['motorista']);
$linha[$z][$x[$z]][3]=trim($res['placa']);
$linha[$z][$x[$z]][2]=current(str_word_count($res['veiculo'],2,'3/4'));
$linha[$z][$x[$z]][4]=trim($res['carreta']);
$dt_prevista[$z][$x[$z]][16]=trim($res['dt_prevista']);
$linha[$z][$x[$z]][9]=trim($res['hr_prevista']);
$dt_saida[$z][$x[$z]][17]=$res['dt_saida'];
$linha[$z][$x[$z]][10]=$res['hr_saida'];
$linha[$z][$x[$z]][12]=str_replace(',', ' ', trim($res['coment']));
$linha[$z][$x[$z]][11]=trim($res['ajudante']);
$linha[$z][$x[$z]][7]=str_replace('/', ' / ', $res['destino']);
$linha[$z][$x[$z]][8]=trim($res['final']);
$linha6=str_replace(',', '/', $res['cliente']);
$linha[$z][$x[$z]][6]=str_replace('/', ' / ', $linha6);
$manifANT=$manifesto[$z][$x[$z]];$x[$z]++;
}else
{
if ($tipox=='ENTREGA'){$linha[$z][$x[$z]-1][13]++;}else{if ($tipox=='COLETA'){$linha[$z][$x[$z]-1][14]++;}else{$linha[$z][$x[$z]-1][15]++;}}
}
}
?>
<!DOCTYPE html>
<html lang='pt-br'>
<head>
<meta charset='utf-8'/>
<meta http-equiv="pragma" content="no-cache">
<meta content='width=device-width, initial-scale=1, maximum-scale=1' name='viewport'>
<title>PROGRAMAÇÃO</title>
<link rel='icon' type='image/png' href='images/favicon.ico'>
<script src='js/jquery-2.1.3.min.js'></script>
<script src='js/tabelas.js'></script>
</head>
<style>
body{
font:1.2em normal Arial,sans-serif;
color:#34495E;
}
h1{
text-align:center;
text-transform:uppercase;
letter-spacing:-2px;
font-size:2.0em;
margin:20px 0;
}
.container{
width:100%;
margin:auto;
}
table.blue { table-layout:fixed; }
table.blue td, th { overflow: hidden; }
table{
border-collapse:collapse;
width:100%;
}
.blue{
border:2px solid #0174DF;
}
.blue thead{
background:#0174DF;
}
.purple{
border:2px solid #9B59B6;
}
.purple thead{
background:#9B59B6;
}
thead{
color:white;
background:#0174DF;
}
tr {
font-size:12px;
}
th,td{
text-align:center;
padding:5px 0;
}
td{
border-right:1px #797979 solid;
}
th {
letter-spacing:1px;
}
tbody tr:nth-child(even){
background:#BDC3C7;
}
tbody tr:hover{
background:yellow;
color:red;
}
.fixed{
top:0;
position:fixed;
width:99%;
display:none;
border:none;
}
.scrollMore{
margin-top:600px;
}
.up{
cursor:pointer;
}
</style>
<body>
<?php
for ($q=1; $q <= $z; $q++) {
echo '
<h1>Programação Operacional de: <span STYLE="color: red;">'.$data[$q].'</span></h1>
<table class="blue" >
<col width="15%" />
<col width="5%" />
<col width="5%" />
<col width="5%" />
<col width="7%" />
<col width="20%" />
<col width="11%" />
<col width="5%" />
<col width="5%" />
<col width="10%" />
<col width="12%" />
<thead>
<tr>
<th>Motorista</th>
<th>Veículo</th>
<th>Placa</th>
<th>Carreta</th>
<th>Tipo</th>
<th>Clientes</th>
<th>Destinos</th>
<th>Saída Prevista</th>
<th>Saída Real</th>
<th>Ajudante</th>
<th>Observação</th>
</tr>
</thead>
<tbody>';
for ($k=1; $k < $x[$q]; $k++) {
$linha[$q][$k][5]='';
if ($linha[$q][$k][13]>=1){$linha[$q][$k][5]='ENTREGA('.$linha[$q][$k][13].')';}
if ($linha[$q][$k][14]>=1){if ($linha[$q][$k][5]==''){$linha[$q][$k][5]='COLETA('.$linha[$q][$k][14].')';}else{$linha[$q][$k][5]=$linha[$q][$k][5].' '.'COLETA('.$linha[$q][$k][14].')';}}
if ($linha[$q][$k][15]>=1){if ($linha[$q][$k][5]==''){$linha[$q][$k][5]='VIAGEM('.$linha[$q][$k][15].')';}else{$linha[$q][$k][5]=$linha[$q][$k][5].' '.'VIAGEM('.$linha[$q][$k][15].')';}}
if ($k % 2 == 0) { $bg="#e6e6e6";} else {$bg="#ffffff";}
echo '<tr>';
for ( $i = 1; $i <= 12; $i ++ ) {if ($i<>8){if ($i==1 or $i>=11){echo '<td align="left">';} else {if ($i==7 or $i==9 or $i==10){echo '<td align="center" >';}else {echo '<td align="center">';}}
echo $linha[$q][$k][$i] . '</td>';
}}echo '</tr>';
}
echo '</tbody></table>';}
echo '<h1 class="up">↑ Subir ↑</h1>';
?>
</body>
</html>