indicador2 es una vista, bastante sencilla, solamente devuleve los campos cantidad,fecha y hora asi sencillo sin mas nada.. el errror que genera el script es division por cero, en el porcentaje y ambas consultas son totalmente funcionales ya que devuelve correctamente las sumatorias pero no puedo operar ese resulatado para totalizar.
en si lo que esto deberia mostrar son las ventas por horas laborales. ¿como puedo manipular el tipo currency de postgres? o debo hacer un cast?
Código PHP:
function reporte2($inicio,$fin)
{
$conexion=pg_connect("host=localhost port=5432,dbname=phip user=phip password=phip");
for ($i=8;$i<17;$i++)
{
$sql="select sum(cantidad) as venta from indicador2 where (fecha between '".$inicio."' and '".$fin."')"." and (hora between '".$i.":00:00' and '".($i+1).":00:00')";
$venta=pg_query($conexion,$sql);
$row=pg_fetch_array($venta);
$sqlVentaTotal="select sum(cantidad) as total from indicador2 where (fecha between '".$inicio."' and '".$fin."')";
$total=pg_query($conexion,$sqlVentaTotal);
$row2=pg_fetch_array($total);
echo "<table border='1'>
<tr>
<th>Hora</th>
<th>Total Venta</th>
<th>Porcentaje</th>
</tr>
";
if ($row['venta']==null)
{
echo " <tr>
<td>$i:00:00/".($i+1).":00:00</td>".
"<td>$0</td>
<td>0%</td>
</tr>
";
}
else
{
echo " <tr>
<td>$i:00:00/".($i+1).":00:00</td>".
"<td>".$row['venta']."</td>".
"<td>".(($row['venta']*100)/ $row2['total'])."%</td>
</tr>
";
}
echo "</table><br><br>";
}
}
