File "RegistrosAudi.php"

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

<?php
session_start();
header("Cache-control: private"); // Arregla IE 6

//*******Datos de Conexion Base de Datos************
include("conexion.php");
$FECHA = date("Y-m-d");

$USUARIO=$_SESSION['nomUser'];
$USUARIOA=$USUARIO."A";
//$USUARIOA="TAB02";
$UBICACION=$_SESSION['ubicacion'];
$DCTO=$_SESSION['dcto'];
$TKILOS = 0;
$TUNI = 0;
$TCANASTAS = 0;
$TBULTOS = 0;
$TCAJAS = 0;
$TBASES = 0;
$N = 0;
$D1 = "";
$D2 = "";
$D3 = "";

//***A TODAS LAS UBICACIONES 

//AAA => Consulta todas las ubicaciones todos los codigos y todos los planilladores 
//ABA => Consulta todas las ubicaciones según el producto
//AAB => Consulta todas las ubicaciones todos los productos segun digitador
//BAA => Consulta todas una ubicacion especial con todos los codigos y planilladores 

// Consulta SQL
$sql = "SELECT SUM(CANTIDAD) AS CANTIDAD, SUM(CANTEMPAQ) AS UNIDADES, SUM(CNASTAPLL) AS CANASTAS, SUM(CAJAS) AS CAJAS, SUM(BULTOS) AS BULTOS, SUM(BASES) AS BASES FROM mvdcto WHERE USUARIO='$USUARIO' AND TPDCTO='$DCTO' AND CODUBI='$UBICACION' AND ESTADO<>'PESO ELIMINADO'";
$result = mysqli_query($conexion, $sql);
if ($result) {
    $row = mysqli_fetch_assoc($result);
    $cantidad = $row['CANTIDAD'] ?? 0;
    $unidades = $row['UNIDADES'] ?? 0;
    $canastas = $row['CANASTAS'] ?? 0;
    $cajas = $row['CAJAS'] ?? 0;
    $bultos = $row['BULTOS'] ?? 0;
    $bases = $row['BASES'] ?? 0;
} else {
    echo "Error en la consulta: " . mysqli_error($conexion);
}

// Consulta SQL
$sql1 = "SELECT SUM(CANTIDAD) AS CANTIDAD, SUM(CANTEMPAQ) AS UNIDADES, SUM(CNASTAPLL) AS CANASTAS, SUM(CAJAS) AS CAJAS, SUM(BULTOS) AS BULTOS, SUM(BASES) AS BASES FROM mvdcto WHERE USUARIO='$USUARIOA' AND TPDCTO='$DCTO' AND CODUBI='$UBICACION' AND ESTADO<>'PESO ELIMINADO'";
$result1 = mysqli_query($conexion, $sql1);
if ($result1) {
    $row1 = mysqli_fetch_assoc($result1);
    $cantidad1 = $row1['CANTIDAD'] ?? 0;
    $unidades1 = $row1['UNIDADES'] ?? 0;
    $canastas1 = $row1['CANASTAS'] ?? 0;
    $cajas1 = $row1['CAJAS'] ?? 0;
    $bultos1 = $row1['BULTOS'] ?? 0;
    $bases1 = $row1['BASES'] ?? 0;
} else {
    $cantidad1 = 0;
    $unidades1 = 0;
    $canastas1 = 0;
    $cajas1 = 0;
    $bultos1 = 0;
    $bases1 = 0;
}


// Validaciones de acta

// Validaciones de acta

// Validaciones de acta
$ACANTIDAD = ($cantidad1 == $cantidad) ? "OK" : "ERROR";
$AUNIDADES = ($unidades1 == $unidades) ? "OK" : "ERROR";
$ACANASTAS = ($canastas1 == $canastas) ? "OK" : "ERROR";
$ACAJAS = ($cajas1 == $cajas) ? "OK" : "ERROR";
$ABULTOS = ($bultos1 == $bultos) ? "OK" : "ERROR";
$ABASES = ($bases1 == $bases) ? "OK" : "ERROR";

$_SESSION['ESTADO']=$ACANTIDAD.$AUNIDADES.$ACANASTAS.$ACAJAS.$ABASES;


?>


<!DOCTYPE html>
<html lang="es">

<head>
    <meta charset="UTF-8">
    <title>Acta de Registros Inventarios</title>
    <link rel="icon" type="image/png" href="img/icon.png">
    <style>
    /* General */
    body {
        font-family: Arial, sans-serif;
        background-color: #cacacaff;
        margin: 0;
        padding: 20px;
        color: #333;
    }

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

    /* Logo */
    .logo {
        text-align: center;
        margin-bottom: 20px;
    }

    /* Formularios */
    form p {
        margin: 12px 0;
    }

    label {
        font-weight: bold;
        margin-right: 8px;
    }

    .textbox {
        padding: 8px;
        border-radius: 6px;
        border: 1px solid #ccc;
        width: 250px;
        transition: border-color 0.2s;
    }

    .textbox:focus {
        border-color: #21bd35ff;
        outline: none;
    }

    /* Tablas */
    table {
        width: 100%;
        border-collapse: collapse;
        margin: 20px 0;
        font-size: 14px;
        text-align: center;
    }

    th {
        background-color: #3ab116ff;
        color: #fff;
        padding: 10px;
        text-transform: uppercase;
    }

    td {
        padding: 8px;
        border: 1px solid #ddd;
    }

    tr:nth-child(even) {
        background-color: #f9f9f9;
    }

    tr:hover {
        background-color: #f1f1f1;
    }

    /* Firmas */
    canvas {
        border: 2px dashed #46c71fff;
        border-radius: 8px;
        margin: 10px 0;
        display: block;
        background-color: #ffffffa6;
    }

    button {
        background-color: #007bff;
        color: white;
        border: none;
        padding: 10px 16px;
        margin-top: 10px;
        border-radius: 6px;
        cursor: pointer;
        transition: background 0.2s;
    }

    button:hover {
        background-color: #15c00fff;
    }
    </style>
</head>

<body>
    <div class="container">
        <div class="logo">
            <img src="logo.png" alt="avicampo Logo" width="200">
        </div>
        <form method="post" action="process_form.php">
            <center>
                <p><strong>Acta de Control de Registros Inventario General AVICAMPO PEREIRA</strong></p>
                <p>Fecha: <?php echo $FECHA; ?></p>
                <p>Consecutivo: <?php echo $DCTO; ?></p>
                <div class="vertical-fields">
                    <p><label for="nombre_planillador">Nombre Planillador:</label>
                        <input type="text" class="textbox" name="nombre_planillador" id="nombre_planillador" required>
                    </p>

                    <p><label for="nombre_auditor">Nombre Auditor:</label>
                        <input type="text" class="textbox" name="nombre_auditor" id="nombre_auditor" required>
                    </p>

                    <p><label for="nombre_pesador">Nombre Pesador:</label>
                        <input type="text" class="textbox" name="nombre_pesador" id="nombre_pesador" required>
                    </p>
                </div>
                <table style="margin-bottom:30px">
                    <tr class="header">
                        <th width="50%">Ubicación</th>
                        <th width="28%">Usuario</th>
                        <th width="22%">Usuario Audita</th>
                    </tr>
                    <tr>
                        <td><?php echo $UBICACION; ?></td>
                        <td><?php echo $USUARIO; ?></td>
                        <td><?php echo $USUARIOA; ?></td>
                    </tr>
                </table>
                <p><strong>Totales Registrador por el usuario Planillador</strong></p>
                <div style="overflow-x:auto; margin-bottom:50px">
                    <table style="width:100%; border-collapse: collapse;">
                        <tr class="data">
                            <th>Reg</th>
                            <th>Descripción Ubicación</th>
                            <th>Kilos</th>
                            <th>Unidades</th>
                            <th>Canastas</th>
                            <th>Cajas</th>
                            <th>Bultos</th>
                            <th>Bases</th>
                        </tr>
                        <tr class="totals">
                            <td>1</td>
                            <td align="right">
                                <?PHP echo $UBICACION;?>
                            </td>
                            <td align="right">
                                <?PHP echo number_format($cantidad,2);?>
                            </td>
                            <td align="right">
                                <?PHP echo number_format($unidades,2);?>
                            </td>
                            <td align="right">
                                <?PHP echo number_format($canastas,2);?>
                            </td>
                            <td align="right">
                                <?PHP echo $cajas;?>
                            </td>
                            <td align="right">
                                <?PHP echo number_format($bultos,2);?>
                            </td>
                            <td align="right">
                                <?PHP echo number_format($bases,2);?>
                            </td>
                        </tr>
                    </table>
                </div>
                <legend style="border: solid 1px">
                </legend>
                <p><strong>Totales Registrados por el usuario Auditor</strong></p>
                <div style="overflow-x:auto; margin-bottom:50px">
                    <table style="width:100%; border-collapse: collapse;">
                        <tr class="data">
                            <th>Reg</th>
                            <th>Descripción Ubicación</th>
                            <th>Kilos</th>
                            <th>Unidades</th>
                            <th>Canastas</th>
                            <th>Cajas</th>
                            <th>Bultos</th>
                            <th>Bases</th>
                        </tr>
                        <?php
        // Aquí iría la lógica para llenar la tabla con los datos de la base de datos
        ?>
                        <tr class="totals">
                            <td>1</td>
                            <td align="right">
                                <?PHP echo $UBICACION;?>
                            </td>
                            <td align="right">
                                <?PHP echo number_format($cantidad1,2);?>
                            </td>
                            <td align="right">
                                <?PHP echo number_format($unidades1,2);?>
                            </td>
                            <td align="right">
                                <?PHP echo number_format($canastas1,2);?>
                            </td>
                            <td align="right">
                                <?PHP echo $cajas1;?>
                            </td>
                            <td align="right">
                                <?PHP echo number_format($bultos1,2);?>
                            </td>
                            <td align="right">
                                <?PHP echo number_format($bases1,2);?>
                            </td>
                        </tr>
                    </table>
                </div>
                <legend style="border: solid 1px"></legend>
                <p><strong>Resultado de la Auditoria</strong></p>
                <div style="overflow-x:auto;">
                    <table style="width:100%; border-collapse: collapse;">
                        <tr class="data">
                            <th>Reg</th>
                            <th>Descripción Ubicación</th>
                            <th>Kilos</th>
                            <th>Unidades</th>
                            <th>Canastas</th>
                            <th>Cajas</th>
                            <th>Bultos</th>
                            <th>Bases</th>
                        </tr>
                        <?php
        // Aquí iría la lógica para llenar la tabla con los datos de la base de datos
        ?>
                        <tr class="totals">
                            <td>1</td>
                            <td align="right">
                                <?PHP echo $UBICACION;?>
                            </td>
                            <td align="right">
                                <?PHP echo $ACANTIDAD;?>
                            </td>
                            <td align="right">
                                <?PHP echo $AUNIDADES;?>
                            </td>
                            <td align="right">
                                <?PHP echo $ACANASTAS;?>
                            </td>
                            <td align="right">
                                <?PHP echo $ACAJAS;?>
                            </td>
                            <td align="right">
                                <?PHP echo $ABULTOS;?>
                            </td>
                            <td align="right">
                                <?PHP echo $ABASES;?>
                            </td>
                        </tr>
                    </table>
                </div>
                <p>&nbsp;</p>
                <p><strong>Firma Planillador:</strong></p>
                <canvas id="signatureCanvasPlanillador" width="500" height="200"></canvas>
                <button type="button" onclick="clearCanvas('signatureCanvasPlanillador')"
                    style="margin-bottom:30px">Limpiar</button>
                <input type="hidden" name="signaturePlanillador" id="signaturePlanillador">

                <p><strong>Firma Auditor:</strong></p>
                <canvas id="signatureCanvasAuditor" width="500" height="200"></canvas>
                <button type="button" onclick="clearCanvas('signatureCanvasAuditor')"
                    style="margin-bottom:30px">Limpiar</button>
                <input type="hidden" name="signatureAuditor" id="signatureAuditor">

                <p><strong>Firma Pesador:</strong></p>
                <canvas id="signatureCanvasPesador" width="500" height="200"></canvas>
                <button type="button" onclick="clearCanvas('signatureCanvasPesador')">Limpiar</button>
                <input type="hidden" name="signaturePesador" id="signaturePesador">

                <button type="submit">Continuar</button>
            </center>
        </form>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/signature_pad@2.3.2/dist/signature_pad.min.js"></script>
    <script>
    function initializeSignaturePad(canvasId, hiddenInputId) {
        var canvas = document.getElementById(canvasId);
        var signaturePad = new SignaturePad(canvas, {
            backgroundColor: 'rgba(255, 255, 255, 0)',
            penColor: 'black'
        });

        function resizeCanvas() {
            var ratio = Math.max(window.devicePixelRatio || 1, 1);
            canvas.width = canvas.offsetWidth * ratio;
            canvas.height = canvas.offsetHeight * ratio;
            canvas.getContext('2d').scale(ratio, ratio);
            signaturePad.clear(); // otherwise isEmpty() might return incorrect value
        }

        window.addEventListener('resize', resizeCanvas);
        resizeCanvas();

        canvas.addEventListener('mouseup', function() {
            document.getElementById(hiddenInputId).value = signaturePad.toDataURL();
        });
    }

    function clearCanvas(canvasId) {
        var canvas = document.getElementById(canvasId);
        var signaturePad = new SignaturePad(canvas);
        signaturePad.clear();
        document.getElementById(canvasId.replace('Canvas', '')).value = '';
    }

    initializeSignaturePad('signatureCanvasPlanillador', 'signaturePlanillador');
    initializeSignaturePad('signatureCanvasAuditor', 'signatureAuditor');
    initializeSignaturePad('signatureCanvasPesador', 'signaturePesador');

    // Validar firmas obligatorias antes de enviar
    document.getElementById("miFormulario").addEventListener("submit", function(e) {
        let firmas = [{
                canvasId: "signatureCanvasPlanillador",
                inputId: "signaturePlanillador"
            },
            {
                canvasId: "signatureCanvasAuditor",
                inputId: "signatureAuditor"
            },
            {
                canvasId: "signatureCanvasPesador",
                inputId: "signaturePesador"
            }
        ];

        let valido = true;
        let mensaje = [];

        firmas.forEach(firma => {
            let canvas = document.getElementById(firma.canvasId);
            let signaturePad = new SignaturePad(canvas);

            if (signaturePad.isEmpty()) {
                valido = false;
                mensaje.push(firma.inputId.replace("signature", "Firma de "));
            }
        });

        if (!valido) {
            e.preventDefault();
            alert("⚠️ Debes completar todas las firmas antes de guardar.\nFaltan: " + mensaje.join(", "));
        }
    });
    </script>
</body>

</html>