<?php

  $debugin              = $decoded['debug'];
  $clave                = $decoded['clave'];

  //Muestra Producto
  $Query = "
    SELECT
      pro.Id,
      pro.Clave, pro.Nombre
    FROM KB_Productos pro
    WHERE
      pro.Clave = '$clave'
  ";
  $Result = mysqli_query($mysqli, $Query);
  $Pro = mysqli_fetch_assoc($Result);
  if( $Pro[Id] ){

    //Delete Empaques_Precios
    $Query = "
      DELETE FROM KB_Productos_Empaques_Precios
      WHERE Fk_Producto = '$Pro[Id]'
    ";
    $Result = mysqli_query($mysqli, $Query);

    //Delete Empaques
    $Query = "
      DELETE FROM KB_Productos_Empaques
      WHERE Fk_Producto = '$Pro[Id]'
    ";
    $Result = mysqli_query($mysqli, $Query);

    //Delete Impuestos
    $Query = "
      DELETE FROM KB_Productos_Impuestos
      WHERE Fk_Producto = '$Pro[Id]'
    ";
    $Result = mysqli_query($mysqli, $Query);

    //Delete Precios
    $Query = "
      DELETE FROM KB_Productos_Precios
      WHERE Fk_Producto = '$Pro[Id]'
    ";
    $Result = mysqli_query($mysqli, $Query);

    //Delete Precios
    $Query = "
      DELETE FROM KB_Productos
      WHERE Id = '$Pro[Id]'
    ";
    $Result = mysqli_query($mysqli, $Query);

    //Respuesta
    $Data = array(
      'action'              => 'ok',
      'clave'               => "$Pro[Clave]",
    );
    echo json_encode($Data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);

  }else{

    //Error
    $Query = "
      SELECT
        err.Id, err.error, err.msn
      FROM KB_Api_Errores err
      WHERE err.error = 'pro-3'
    ";
    $Result = mysqli_query($mysqli, $Query);
    $Error = mysqli_fetch_assoc($Result);

    $Data = array(
      'action'      => 'error',
      'error'       => $Error[error],
      'error_msn'   => $Error[msn]
    );
    echo json_encode($Data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);

  }
?>
