<?php

  if( $Action == 'Edit' ){

  }else{
    $Position   = '../../../';
    require_once($Position.'config/config.php');
    require_once($Position.'config/conexion.php');
    require_once($Position.'config/user.php');
    require_once($Position.'funciones/funciones.php');
  }

  if( $_POST[cli] ){
    $Cli = $_POST[cli];
  }elseif( $Prefac[Fk_Cliente] ){
    $Cli = $Prefac[Fk_Cliente];
  }

  //Cliente
  $Query = "
    SELECT
      cli.Id, cli.Fk_FacturaUso, cli.Email, cli.Nombre, cli.Rfc,
      cli.Calle, cli.NoExterior, cli.NoInterior,
      cli.CodigoPostal, cli.Colonia,
      mun.Nombre AS Municipio,
      est.Nombre AS Estado,
      pai.Nombre AS Pais
    FROM CatalogoClientes cli
    LEFT JOIN Municipios mun ON mun.Id = cli.Fk_Municipio
    LEFT JOIN Estados est ON est.Id = cli.Fk_Estado
    LEFT JOIN Paises pai ON pai.Id = cli.Fk_Pais
    WHERE cli.Id = '$Cli' AND cli.Fk_Cuenta = '$Cuenta[Id]'
  ";
  $Result = mysqli_query($mysqli, $Query);
  $Cli = mysqli_fetch_assoc($Result);

  //Usos
  $Query = "
    SELECT
      uso.Id, uso.Clave, uso.Uso
    FROM FacturasUsos uso
    WHERE ( uso.Pre = 'P' OR uso.Pre = 'G' OR uso.Pre = 'I' )
    ORDER BY uso.Clave ASC
  ";
  $Usos = $mysqli->query($Query);

?>

<!-- Uso de la Factura -->
<div class="form-group col-sm-12">
  <label>Uso de la Factura</label>
  <select id="Uso" name="Uso" class="form-control chosen-select">
    <option></option>
    <?php
    mysqli_data_seek($Usos, 0);
    while($Uso = mysqli_fetch_array($Usos)) {
    ?>
      <option
        <?php
          if( $Action == 'Edit' ){
            if( $Prefac[Fk_Uso] == $Uso[Id] ){
              echo 'selected="selected"';
            }
          }else{
            if( $Uso['Id'] == $Cli['Fk_FacturaUso'] ){
              echo 'selected="selected"';
            }
          }
        ?>
        value="<?php echo $Uso['Id']; ?>"
      >
        <?php echo $Uso['Clave'].' - '.$Uso['Uso']; ?>
      </option>
    <?php } ?>
  </select>
</div>
<!-- End Uso de la Factura -->

<?php if( $ShowData == 1 ){ ?>
  <!-- RFC -->
  <div class="form-group col-sm-6">
    <label>RFC</label>
    <input class="form-control form-disabled" value="<?php echo $Cli[Rfc]; ?>" disabled>
  </div>
  <!-- End RFC -->

  <!-- Email -->
  <div class="form-group col-sm-6">
    <label>Email</label>
    <input class="form-control form-disabled" value="<?php echo $Cli[Email]; ?>" disabled>
  </div>
  <!-- End Email -->

  <!-- Calle -->
  <div class="form-group col-sm-12">
    <label>Calle</label>
    <input class="form-control form-disabled" value="<?php echo $Cli[Calle]; ?>" disabled>
  </div>
  <!-- End Calle -->

  <!-- NoExterior -->
  <div class="form-group col-sm-6">
    <label>Número Exterior</label>
    <input class="form-control form-disabled" value="<?php echo $Cli[NoExterior]; ?>" disabled>
  </div>
  <!-- End NoExterior -->

  <!-- NoInterior -->
  <div class="form-group col-sm-6">
    <label>Número Inteior</label>
    <input class="form-control form-disabled" value="<?php echo $Cli[NoInterior]; ?>" disabled>
  </div>
  <!-- End NoInterior -->

  <!-- Colonia -->
  <div class="form-group col-sm-12">
    <label>Colonia</label>
    <input class="form-control form-disabled" value="<?php echo $Cli[Colonia]; ?>" disabled>
  </div>
  <!-- End Colonia -->

  <!-- Pais -->
  <div class="form-group col-sm-4">
    <label>Pais</label>
    <input class="form-control form-disabled" value="<?php echo $Cli[Pais]; ?>" disabled>
  </div>
  <!-- End Pais -->

  <!-- Estado -->
  <div class="form-group col-sm-4">
    <label>Estado</label>
    <input class="form-control form-disabled" value="<?php echo $Cli[Estado]; ?>" disabled>
  </div>
  <!-- End Estado -->

  <!-- Municipio -->
  <div class="form-group col-sm-4">
    <label>Municipio</label>
    <input class="form-control form-disabled" value="<?php echo $Cli[Municipio]; ?>" disabled>
  </div>
  <!-- End Municipio -->

<?php } ?>

<?php
  require_once($Position.'config/cerrarconexion.php');
?>
