Código PHP:
<?php
include_once "../Class/conexion2.php";
@$f = $_REQUEST['datepicker'];
$sql="SELECT s.Grupo,
ROUND(SUM(v.VentaActual) / 1000, 3) AS VentaActual,
ROUND(SUM(v.VentaDiaAnt) / 1000, 3) AS VentaDiaAnt,
ROUND(SUM(v.VentaSemAnt) / 1000, 3) AS VentaSemAnt,
ROUND(SUM(v.VentaAnoAnt) / 1000, 3) AS VentaAnoAnt,
ROUND(SUM(v.VentaBisAnt) / 1000, 3) AS VentaBisAnt
FROM VentasSucursal v
JOIN Sucursal s ON v.Sucursal = s.Sucursal
WHERE v.FechaEmision = '$f'
GROUP BY s.Grupo
ORDER BY 2";
$resultado=odbc_exec($conn,$sql);
if($rest=odbc_fetch_array($resultado) == NULL)
{
echo "<tr>
<td width=50><font SIZE=2 color=white>No existen registros para la fecha: ",$f,"</td>
<td width=50><font SIZE=2 color=white>No existen registros para la fecha: ",$f,"</td>
<td width=50><font SIZE=2 color=white>No existen registros para la fecha: ",$f,"</td>
<td width=50><font SIZE=2 color=white>No existen registros para la fecha: ",$f,"</td>
<td width=50><font SIZE=2 color=white>No existen registros para la fecha: ",$f,"</td>
<td width=50><font SIZE=2 color=white>No existen registros para la fecha: ",$f,"</td>
<td width=50><font SIZE=2 color=white>No existen registros para la fecha: ",$f,"</td>
<td width=50><font SIZE=2 color=white>No existen registros para la fecha: ",$f,"</td>
</tr>";
}
else
{
while($row=odbc_fetch_array($resultado))
{
$x = $row['VentaBisAnt'];
$y = $row['VentaAnoAnt'];
$z = $row['VentaActual'];
$rs = $y - $x;
@$rs2 = (1-$x/$y)*100;
$rs3=$z-$y;
@$cr = (1-$y/$z)*100;
//Suma
@$sumaVB = $sumaVB + $x;
@$sumaVAA = $sumaVAA + $y;
@$sumaVA = $sumaVA + $z;
@$sumaDF1 = $sumaDF1 + $rs;
@$sumaDF1P = $sumaDF1P + $rs2;
@$sumaDF2 = $sumaDF2 + $rs3;
@$sumaDF2P = $sumaDF2P + $cr;
//Suma
echo "<tr>";
echo "<td><font SIZE=2 color=white>",$row['Grupo'],"</td>";
echo "<td><p align=right><font SIZE=2 color=white>",round($row['VentaBisAnt'],2),"</td>";
echo "<td><p align=right><font SIZE=2 color=white>",round($row['VentaAnoAnt'],2),"</td>";
echo "<td><p align=right><font SIZE=2 color=white>",round($row['VentaActual'],2),"</td>";
if($rs >= 0)
{
echo "<td><p align=right><font SIZE=2 color=white>",round($rs,2),"</td>";
}
else
{
echo "<td><p align=right><font SIZE=2 color=red>",round($rs,2),"</font></td>";
}
if($rs2 >= 0)
{
echo "<td><p align=right><font SIZE=2 color=white>",round($rs2,2),"</td>";
}
else
{
echo "<td><p align=right><font SIZE=2 color=red>",round($rs2,2),"</font></td>";
}
if($rs3 >= 0)
{
echo "<td><p align=right><font SIZE=2 color=white>",round($rs3,2),"</td>";
}
else
{
echo "<td><p align=right><font color=red>",round($rs3,2),"</font></td>";
}
if($cr >= 0)
{
echo "<td><p align=right><font SIZE=2 color=white>",round($cr,2),"</td>";
}
else
{
echo "<td><p align=right><font SIZE=2 color=red>",round($cr,2),"</font></td>";
}
echo "</tr>";
}
}
?>