I have my system created, but in systems it does not show the data of a table when stp.deposito_id = '25', when it is any other deposit it shows me the data that this deposit contains, otherwise it shows me the message "No records were found ".
The string I get from using the var_dump and running it on Workbench shows me the data, but on the system it doesn't.
CLARIFICATION: As shown in the image, the data would have to come out, that is another deposit that does show. The depot that doesn't show me is Gamma City.
query($sql); while ($data = $res->fetch_object()) { $total += $data->Price * $data->existing_quantity; } return $total; } function Return_Deposit_Name($id) { global $mysqli; $sql = "SELECT name FROM repositoryworks WHERE id = '$id'"; $res = $mysqli->query($sql); $obj = $res->fetch_object(); return $obj->name; } ?> .legend { width: 2%; border: 1px solid #999; text-align: center; padding: 2px; display:inline-block; } .right { text-align: right !important; Legend Deposit A B C<table class="table-list">
<thead>
<tr>
<td>Código Artículo</td>
<td>Nombre Artículo</td>
<td>Stock Actual * Precio</td>
<td>Unidad</td>
<td>%</td>
<td>Acumulado</td>
<td>Categoría</td>
<td>Stock Actual</td>
<td>Precio</td>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT
res.codigoArticulo,
res.articulo,
res.unidad,
res.Precio,
res.cantidad_existente
FROM
(
SELECT
stp.cod_articulo as codigoArticulo,
art.nombre as articulo,
stp.stock as cantidad_existente,
art.unidad as unidad,
IFNULL(ROUND((
SELECT dp.precio
FROM detalle_pedidos as dp
INNER JOIN pedidos p ON p.num_pedido = dp.num_pedido
WHERE p.estado != 'ANULADA' AND dp.cod_articulo = stp.cod_articulo
ORDER BY dp.num_pedido DESC
LIMIT 1
), 2), 0) as Precio
FROM
stock_tareaprogramada as stp
INNER JOIN
articulos as art ON stp.cod_articulo = art.cod_articulo
WHERE
stp.deposito_id = '{$_POST['deposito']}'
AND stp.cod_articulo = art.cod_articulo
AND stp.stock > 0
AND art.estado != 'BAJA'
AND art.stockeable = 'SI'
) as res
ORDER BY res.Precio * res.cantidad_existente DESC";
/*var_dump($sql)*/
$res = $mysqli->query($sql);
if ($res->num_rows > 0) {
$total = Retornar_Total($sql);
------------------------------------------------------------
while ($dato = $res->fetch_object()) {
$cantidadPorPrecio = $dato->cantidad_existente * $dato->Precio;
$porcentaje = ($cantidadPorPrecio * 100) / $total;
$acumulado = $acumulado + $porcentaje;
if ($acumulado < 80 ) {
$categoria = "A";
$bgcolor = "#BEF781";
} elseif ($acumulado < 95 ) {
$categoria = "B";
$bgcolor = "#F3E2A9";
} else {
$categoria = "C";
$bgcolor = "#FA5882";
}
?>
<tr>
<td><?php echo "[" . $dato->codigoArticulo. "]" ?></td>
<td><?php echo $dato->articulo ?></td>
<td class="right"><?php echo number_format($cantidadPorPrecio, 2, ",", ".") ?></td>
<td><?php echo $dato->unidad ?></td>
<td class="right"><?php echo "%" . number_format($porcentaje, 2, ',' , ".") ?></td>
<td class="right"><?php echo "%" . number_format($acumulado, 2, ',' , '.') ?></td>
<td bgcolor="<?php echo $bgcolor ?>"><?php echo $categoria ?></td>
<td class="right"><?php echo number_format($dato->cantidad_existente, 2, ",", ".") ?></td>
<td class="right"><?php echo number_format($dato->Precio, 2, ",", ".") ?></td>
</tr>
<?
}
------------------------------------------------------------
} else {
?>
<tr class="tr-no-data">
<td colspan="9">No se encontraron registros.</td>
</tr>
<?php
}
?>
</tbody>
<tfoot>
<tr>
<td><strong>TOTAL</strong></td>
<td> </td>
<td class="right"><?php echo number_format($total, 2, ",", ".") ?></td>
<td> </td>
<td class="right"><?php echo "%" . number_format($acumulado, 2, ",", ".") ?></td>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="9" style="text-align:right"><strong>Cantidad de Resultados:</strong> <?php echo $res->num_rows ?></td>
</tr>
<tr>
<td colspan="9" style="text-align:right"><strong>Fecha de Emisión:</strong> <?php echo date("d/m/Y h:m:s") ?></td>
</tr>
</tfoot>
</table>
</body>
If someone ever has the same problem, the solution I found was to add at the beginning of the code (after opening php), the following:
In other words, the problem was the execution time since the table was very heavy.