<?php

include '../../../script/conexion.php';

$id_despacho = $_GET['id_despacho'];
$estado = $_GET['estado'];

$sqlt = "SELECT * FROM despacho WHERE id='$id_despacho'";
$queryt = $conn->query($sqlt);
$rowt = $queryt->fetch_assoc();

$sql1 = "UPDATE despacho SET estado='$estado' WHERE id='$id_despacho'";
if ($conn->query($sql1) === TRUE) {

    $sql2 = "UPDATE despacho_detalle SET estado='$estado' WHERE id_despacho='$id_despacho'";
    if ($conn->query($sql2) === TRUE) {

        $sql3 = "SELECT * FROM despacho_detalle WHERE  id_despacho='$id_despacho'";
        $query3 = $conn->query($sql3);
        if ($query3->num_rows > 0) {
            while ($row3 = $query3->fetch_assoc()) {


                $class_referencia = $row3['referencia_producto'];
                $class_talla = $row3['talla'];

                include '../../../clases/class-referencia.php';

                $class_nombre_tercero_cierre = $rowt['nombre_tercero'];
                $class_referencia_cierre = $row3['referencia_producto'];
                $class_talla_cierre = $row3['talla'];

                include '../../../clases/class-cierre.php';

                $class_referencia = $row3['referencia_producto'];
                $class_talla = $row3['talla'];

                include '../../../clases-fabrica/class-referencia.php';

                $class_nombre_tercero_cierre = $rowt['nombre_tercero'];
                $class_referencia_cierre = $row3['referencia_producto'];
                $class_talla_cierre = $row3['talla'];

                include '../../../clases-fabrica/class-cierre.php';
            }
        }


        echo '<script language = javascript>
                     self.location = "../despacho-detalle.php?id_despacho=' . $id_despacho . '"
                </script>';
    } else {
        echo "Error: " . $sql2 . "<br>" . $conn->error;
    }
} else {
    echo "Error: " . $sql1 . "<br>" . $conn->error;
}

