File "audita.php"

Full Path: C:/wamp64/www/INVENTAPP/audita.php
File size: 11.57 KB
MIME-type: text/x-php
Charset: utf-8

<?PHP
session_start();
header("Cache-control: private");
include("conexion.php");
$conexion->set_charset("utf8");
$FECHA = date("Y-m-d");
$doc = $_SESSION['dcto'];
?>

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>Comparativo Inventario por Usuario</title>
    <link rel="icon" type="image/png" href="img/icon.png">
    <style>
    body {
        font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
        background: #e6b42dff;
        margin: 0;
        padding: 0;
        color: #333;
    }

    .container {
        max-width: 1200px;
        margin: 20px auto;
        background: #ffffffff;
        padding: 25px;
        border-radius: 12px;
        box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.1);
    }

    header h1 {
        text-align: center;
        font-size: 1.8rem;
        margin-bottom: 20px;
        color: #004085;
    }

    form {
        background: #a09f9fff;
        padding: 20px;
        border-radius: 10px;
        box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.1);
        margin-bottom: 25px;
    }

    form p {
        font-size: 1.1rem;
        font-weight: bold;
        margin-bottom: 15px;
        color: #000000ff;
    }

    .form-group {
        display: flex;
        flex-direction: column;
        margin-bottom: 15px;
    }

    .form-group label {
        font-weight: bold;
        margin-bottom: 6px;
        color: #444;
    }

    .form-group select {
        padding: 8px 10px;
        border: 1px solid #ccc;
        border-radius: 6px;
        font-size: 0.95rem;
        transition: 0.3s;
    }

    .form-group select:focus {
        outline: none;
        border-color: #007bff;
        box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
    }

    .form-actions {
        text-align: center;
        margin-top: 20px;
    }

    .form-actions input[type="submit"] {
        background: linear-gradient(45deg, #28a745, #218838);
        color: #fff;
        border: none;
        padding: 12px 20px;
        border-radius: 8px;
        cursor: pointer;
        font-size: 1rem;
        font-weight: bold;
        transition: background 0.3s ease;
    }

    .form-actions input[type="submit"]:hover {
        background: linear-gradient(45deg, #218838, #1e7e34);
    }


    .user1 {
        background: #e3f2fd;
        color: #0d47a1;
        font-weight: bold;
    }

    .user2 {
        background: #fce4ec;
        color: #880e4f;
        font-weight: bold;
    }

    input[type="submit"] {
        background: linear-gradient(45deg, #28a745, #218838);
        color: white;
        font-weight: bold;
        border: none;
        padding: 12px 20px;
        border-radius: 8px;
        cursor: pointer;
        transition: 0.3s ease;
    }

    input[type="submit"]:hover {
        background: linear-gradient(45deg, #218838, #1e7e34);
    }

    h3 {
        margin-top: 20px;
        color: #dc3545;
    }

    ul {
        padding-left: 20px;
        color: #b02a37;
    }

    p[style*="color:green"] {
        font-weight: bold;
        color: #155724 !important;
        background: #d4edda;
        padding: 10px;
        border-radius: 6px;
    }

    .table-responsive {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        /* scroll suave en móvil */
    }

    .table-responsive table {
        white-space: nowrap;
    }
    </style>

</head>

<body>
    <div class="container">
        <header>
            <h1>Control de Registros Inventario General AVICAMPO PEREIRA</h1>
        </header>

        <form class="form-horizontal" method="post">
            <p><strong>PARAMETROS DE CONSULTA</strong></p>

            <div class="form-group">
                <label for="CON">Consecutivo</label>
                <select name="CON" id="CON">
                    <?PHP
            $tabla = $conexion->query("SELECT * FROM documento;");
            while ($row_consulta_form = $tabla->fetch_array()) {
                $NOMBREP = $row_consulta_form['dcto'];
                echo '<option value="' . $NOMBREP . '">' . $NOMBREP . '</option>';
            }
            ?>
                </select>
            </div>

            <div class="form-group">
                <label for="CON4">Ubicación</label>
                <select name="CON4" id="CON4">
                    <option>Todas</option>
                    <?PHP
            $tabla = $conexion->query("SELECT DISTINCT CODUBI FROM mvdcto WHERE TPDCTO='$doc';");
            while ($row_consulta_form = $tabla->fetch_array()) {
                $ubi = $row_consulta_form['CODUBI'];
                echo '<option value="' . $ubi . '">' . $ubi . '</option>';
            }
            ?>
                </select>
            </div>

            <div class="form-group">
                <label for="CON6">Usuario</label>
                <select name="CON6" id="CON6">
                    <option>Todos</option>
                    <?PHP
            $tabla = $conexion->query("SELECT DISTINCT USUARIO FROM mvdcto WHERE TPDCTO='$doc';");
            while ($row_consulta_form = $tabla->fetch_array()) {
                $USERT = $row_consulta_form['USUARIO'];
                echo '<option value="' . $USERT . '">' . $USERT . '</option>';
            }
            ?>
                </select>
            </div>

            <div class="form-actions">
                <input type="submit" name="enviar" id="enviar" value="*** CONSULTAR INFORMACIÓN ***" />
            </div>
        </form>

        <?php
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $CON = $_POST['CON'];
            $UBI = $_POST['CON4'];
            $PLAN = trim($_POST['CON6']);
            $PLAN1 = $PLAN . "A";

            if ($PLAN == "Todos") {
                echo "<p style='color:red;'>Por favor seleccione un usuario específico.</p>";
                exit;
            }

            $whereUbi = ($UBI == "Todas") ? "" : "AND CODUBI='$UBI'";
            $tabla = $conexion->query("SELECT DISTINCT CODPROD, CODUBI, NPROD FROM mvdcto WHERE TPDCTO='$CON' $whereUbi ORDER BY CODUBI ASC;");

            echo "<p>Comparando Usuario 1: <strong>$PLAN</strong> con Usuario 2: <strong>$PLAN1</strong></p>";

            // Inicializar totales
            $totals = array_fill_keys(['K1', 'U1', 'CN1', 'CJ1', 'B1', 'BS1', 'K2', 'U2', 'CN2', 'CJ2', 'B2', 'BS2'], 0);
            $diferencias = [];
echo '<div class="table-responsive">'; 
echo '<table class="table table-bordered table-striped">';
echo '<thead>
<tr>
    <th>Cod Ubicación</th>
    <th>Producto</th>
    <th>Descripción</th>
    <th>Kilos ' . $PLAN . '</th><th>Unids ' . $PLAN . '</th><th>Canastas ' . $PLAN . '</th><th>Cajas ' . $PLAN . '</th><th>Bultos ' . $PLAN . '</th><th>Canastillas ' . $PLAN . '</th>
    <th>Kilos ' . $PLAN1 . '</th><th>Unids ' . $PLAN1 . '</th><th>Canastas ' . $PLAN1 . '</th><th>Cajas ' . $PLAN1 . '</th><th>Bultos ' . $PLAN1 . '</th><th>Canastillas ' . $PLAN1 . '</th>
</tr>
</thead>
<tbody>';

            while ($row = $tabla->fetch_array()) {
                $CODIGO = $row['CODPROD'];
                $UBICACION = $row['CODUBI'];
                $NOMBREP = $row['NPROD'];

                $query1 = $conexion->query("SELECT 
            SUM(CANTIDAD) AS KILOS, SUM(CANTEMPAQ) AS UNDS, SUM(CNASTAPLL) AS CANASTAS,
            SUM(CAJAS) AS CAJAS, SUM(BULTOS) AS BULTOS, SUM(CNASTILLAPLL) AS BASES 
            FROM mvdcto 
            WHERE TPDCTO='$CON' $whereUbi AND CODPROD='$CODIGO' AND USUARIO='$PLAN' AND ESTADO<>'PESO ELIMINADO';");
                $res1 = $query1->fetch_array();

                $query2 = $conexion->query("SELECT 
            SUM(CANTIDAD) AS KILOS, SUM(CANTEMPAQ) AS UNDS, SUM(CNASTAPLL) AS CANASTAS,
            SUM(CAJAS) AS CAJAS, SUM(BULTOS) AS BULTOS, SUM(CNASTILLAPLL) AS BASES 
            FROM mvdcto 
            WHERE TPDCTO='$CON' $whereUbi AND CODPROD='$CODIGO' AND USUARIO='$PLAN1' AND ESTADO<>'PESO ELIMINADO';");
                $res2 = $query2->fetch_array();

                // Acumuladores
                $totals['K1'] += $res1['KILOS'] ?? 0;
                $totals['U1'] += $res1['UNDS'] ?? 0;
                $totals['CN1'] += $res1['CANASTAS'] ?? 0;
                $totals['CJ1'] += $res1['CAJAS'] ?? 0;
                $totals['B1'] += $res1['BULTOS'] ?? 0;
                $totals['BS1'] += $res1['BASES'] ?? 0;
                $totals['K2'] += $res2['KILOS'] ?? 0;
                $totals['U2'] += $res2['UNDS'] ?? 0;
                $totals['CN2'] += $res2['CANASTAS'] ?? 0;
                $totals['CJ2'] += $res2['CAJAS'] ?? 0;
                $totals['B2'] += $res2['BULTOS'] ?? 0;
                $totals['BS2'] += $res2['BASES'] ?? 0;

                // Comparar diferencias
                if (
                    ($res1['KILOS'] ?? 0) != ($res2['KILOS'] ?? 0) ||
                    ($res1['UNDS'] ?? 0) != ($res2['UNDS'] ?? 0) ||
                    ($res1['CANASTAS'] ?? 0) != ($res2['CANASTAS'] ?? 0) ||
                    ($res1['CAJAS'] ?? 0) != ($res2['CAJAS'] ?? 0) ||
                    ($res1['BULTOS'] ?? 0) != ($res2['BULTOS'] ?? 0) ||
                    ($res1['BASES'] ?? 0) != ($res2['BASES'] ?? 0)
                ) {
                    $diferencias[] = "Diferencia en producto $CODIGO ($NOMBREP) - Ubicación: $UBICACION";
                }

                echo "<tr>
        <td>$UBICACION</td><td>$CODIGO</td><td>$NOMBREP</td>
        <td class='user1'>" . number_format($res1['KILOS'] ?? 0, 2) . "</td>
        <td class='user1'>" . ($res1['UNDS'] ?? 0) . "</td>
        <td class='user1'>" . ($res1['CANASTAS'] ?? 0) . "</td>
        <td class='user1'>" . ($res1['CAJAS'] ?? 0) . "</td>
        <td class='user1'>" . ($res1['BULTOS'] ?? 0) . "</td>
        <td class='user1'>" . ($res1['BASES'] ?? 0) . "</td>
        <td class='user2'>" . number_format($res2['KILOS'] ?? 0, 2) . "</td>
        <td class='user2'>" . ($res2['UNDS'] ?? 0) . "</td>
        <td class='user2'>" . ($res2['CANASTAS'] ?? 0) . "</td>
        <td class='user2'>" . ($res2['CAJAS'] ?? 0) . "</td>
        <td class='user2'>" . ($res2['BULTOS'] ?? 0) . "</td>
        <td class='user2'>" . ($res2['BASES'] ?? 0) . "</td>
        </tr>";
            }

            // Mostrar totales
            echo "<tr style='font-weight:bold; background-color:#dff0d8'>
    <td colspan='3'>TOTAL</td>
    <td class='user1'>" . number_format($totals['K1'], 2) . "</td>
    <td class='user1'>" . $totals['U1'] . "</td>
    <td class='user1'>" . $totals['CN1'] . "</td>
    <td class='user1'>" . $totals['CJ1'] . "</td>
    <td class='user1'>" . $totals['B1'] . "</td>
    <td class='user1'>" . $totals['BS1'] . "</td>
    <td class='user2'>" . number_format($totals['K2'], 2) . "</td>
    <td class='user2'>" . $totals['U2'] . "</td>
    <td class='user2'>" . $totals['CN2'] . "</td>
    <td class='user2'>" . $totals['CJ2'] . "</td>
    <td class='user2'>" . $totals['B2'] . "</td>
    <td class='user2'>" . $totals['BS2'] . "</td>
    </tr>";

            echo '</tbody></table>';
            echo '</div>';


            // Mostrar diferencias
            if (!empty($diferencias)) {
                echo "<h3>Diferencias encontradas:</h3><ul>";
                foreach ($diferencias as $dif) {
                    echo "<li>$dif</li>";
                }
                echo "</ul>";
            } else {
                echo "<p style='color:green;'>No se encontraron diferencias entre los usuarios.</p>";
            }
        }
        ?>
    </div>
</body>

</html>