<?php

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

  if( $documento ){

    //Ventas
    $Query = "
      SELECT
        ven.Id, ven.Documento
      FROM KB_Ventas ven
      WHERE
        ven.Documento = '$documento'
    ";
    $Result = mysqli_query($mysqli, $Query);
    $Ven    = mysqli_fetch_assoc($Result);
    if( $Ven[Id] ){

      $Query = "
        UPDATE KB_Ventas
        SET
          Fk_Estatus = '$status'
        WHERE Id = '$Ven[Id]'
      ";
      $Result = mysqli_query($mysqli, $Query);

      //Respuesta
      $Data = array(
        'action'    => 'ok',
        'msn'       => 'actualizado'
      );
      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);

    }

  }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);

  }
?>
