<?php $r="../";
$id=$_GET['id'];
require_once($r."inc/funciones.php");
validNotSession($r);
$mysqli = connectDB($r);
$spe=$_SESSION['perfil'];if($spe!=$pad && $spe!=$psu){exit(header("Location:".$r."dashboard.php?error=Tu No Puedes Ingresar un Gasto"));} 
?>
<!DOCTYPE html>
<html lang="en">
  <?php include $r."inc/head.php"; ?>
<body class="fixed-nav sticky-footer  sidenav-toggled  bg-dark" id="page-top">
  <?php include $r."inc/nav.php"; ?>
  
  <div class="content-wrapper">
    <div class="container-fluid">
      <h2 class="text-center"><i class="fa fa-gift"></i> NUEVA INVERSIÓN</h2><hr/>
      <form id="formulario" name="gasto" action="acciones.php" method="POST"  enctype="multipart/form-data"><hr/>
        <div class="form-group row">
            <label for="tipo" class="col-sm-2 col-form-label"><span class="text-danger h5">*</span>Proveedor</label>
            <div class="col-sm-9">
            <select data-placeholder="Seleccionar el proveedor" class="form-control chosen-select" name="proveedor" id="proveedor">
                    <? $resultado = $mysqli->query("SELECT * FROM z_proveedores");
                  do{echo '<option value="'.$fila["id"].'"> '.$fila["nombre"].'</option>';
                    }while ($fila = $resultado->fetch_assoc()); ?>
              </select>
            </div>
        </div>
        <div class="form-group row">
            <label for="costo" class="col-sm-2 col-form-label"><span class="text-danger h5">*</span>Costo Inversión</label>
            <div class="col-sm-9">
                <input type="number" class="form-control" id="costo" name="costo" placeholder="Costo Inversión" autocomplete="off" required>
            </div>
        </div>
        <div class="form-group row">
            <label for="costo" class="col-sm-2 col-form-label">Codigo de Factura</label>
            <div class="col-sm-9">
                <input type="text" class="form-control" id="codigofactura" name="codigofactura" placeholder="Codigo de Factura" autocomplete="off">
            </div>
        </div>
        <div class="form-group row">
            <label for="costo" class="col-sm-2 col-form-label"><span class="text-danger h5">*</span>Archivo Adjunto</label>
            <div class="col-sm-9">
                <input type="file" class="form-control" id="archivo" name="archivo" accept=".png, .jpeg, .doc, .docx, .pdf">
            </div>
        </div>
        <div class="form-group row">
            <label for="costo" class="col-sm-2 col-form-label"><span class="text-danger h5">*</span>fecha de pago</label>
            <div class="col-sm-9">
                <input type="date" class="form-control" id="fecha" name="fecha" placeholder="Fecha Limite de pago" autocomplete="off" required>
            </div>
        </div>
        <script type="text/javascript">
           function changeFunc() {
            var estado = document.getElementById("estado");
            var selectedValue = estado.options[estado.selectedIndex].value;
            if(selectedValue==1){
                    $('#abono').html('<label for="costo" class="col-sm-2 col-form-label"><span class="text-danger h5">*</span>Abono</label><div class="col-sm-9"><input type="number" class="form-control" id="fecha" name="abono" placeholder="abono" autocomplete="off" required></div>').slideDown(400);
            }else{$('#abono').html('').slideDown(400);}
           }
        </script>
        <div class="form-group row">
            <label for="costo" class="col-sm-2 col-form-label"><span class="text-danger h5">*</span>Estado</label>
            <div class="col-sm-9">
            <select id="estado" class="form-control chosen-select" min="<? echo date("Y-m-d"); ?>" name="estado" id="estado" onchange="changeFunc();">
                <option>Seleccione el estado de la Factura</option>
                <option value="0">Se Debe</option>
                <option value="1">Se Abono</option>
                <option value="2">Se Pago</option>
            </select>
            </div>
        </div>
        <div id="abono" class="form-group row">
            
        </div>
        <div class="form-group row">
            <label for="nota" class="col-sm-2 col-form-label"><span class="text-danger h5">*</span>Nota Datallada del Gasto</label>
            <div class="col-sm-9">
                <textarea type="text" class="form-control" id="nota" name="nota" placeholder="Nota Detalla del Gasto" autocomplete="off" required></textarea>
            </div>
        </div>
            <input type="hidden" name="pago" value="pago">
            <hr/>
            <div class="text-center">
          <button type="submit" class="btn btn-success">Ingresar Gasto</button>
          <a href="javascript:history.back()" class="btn btn-primary">Atras</a></div>
      </form>
    </div>
  </div>
  <? include $r."inc/foot.php"; ?>
</body>
</html>