 <?php  

if ($_GET['form']=='add') { ?> 

  <section class="content-header">
    <h1>
      <i class="fa fa-edit icon-title"></i> Apertura $ Cierre
    </h1>
    <ol class="breadcrumb">
      <li><a href="?module=start"><i class="fa fa-home"></i> Inicio </a></li>
      <li><a href="?module=medicines"> Cierre de inventario </a></li>
      <li class="active"> Más </li>
    </ol>
  </section>

  <!-- Main content -->
  <section class="content">
    <div class="row">
      <div class="col-md-12">
        <div class="box box-primary">
          <!-- form start -->
          <form role="form" class="form-horizontal" action="modules/trade/catalogos/correos/proses.php?act=insert" method="POST">
            <div class="box-body">
              <?php  
          
              $query_id = mysqli_query($mysqli, "SELECT id FROM apertura_cierre
                                                ORDER BY id DESC LIMIT 1")
                                                or die('error '.mysqli_error($mysqli));

              $count = mysqli_num_rows($query_id);

              if ($count <> 0) {
            
                  $data_id = mysqli_fetch_assoc($query_id);
                  $id    = $data_id['id']+1;
              } else {
                  $id = 1;
              }


              $buat_id   = str_pad($id, 0, "0", STR_PAD_LEFT);
              $id = "$buat_id";
              ?>

              <div class="form-group">
                <label class="col-sm-2 control-label">id</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="id" value="<?php echo $id; ?>" readonly required>
                </div>
              </div>

              <div class="form-group">
                <label class="col-sm-2 control-label">NOMBRE</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="nombre" autocomplete="off" required>
                </div>
              </div>
			  
			   <div class="form-group">  
                <label class="col-sm-2 control-label">ESTADO DE INVENTARIO</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="apertura" data-placeholder="-- Seleccionar motivo --" onchange="tampil_obat(this)" autocomplete="off" required>
                    <option value=""></option>
                    <?php
                      $query_cierre = mysqli_query($mysqli, "SELECT name,tipo FROM condiciones_cierre ORDER BY name ASC")
                                                            or die('error '.mysqli_error($mysqli));
                      while ($data_cierre = mysqli_fetch_assoc($query_cierre)) {
                         echo"<option value=\"$data_cierre[tipo]\"> $data_cierre[tipo] | $data_cierre[name] </option>";
                      }
                    ?>
                  </select>
                </div>
              </div>
			  
		

 


            </div><!-- /.box body -->

            <div class="box-footer">
              <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                  <input type="submit" class="btn btn-primary btn-submit" name="Guardar" value="Guardar">
                  <a href="?module=catalogo_motivos" class="btn btn-default btn-reset">Cancelar</a>
                </div>
              </div>
            </div><!-- /.box footer -->
          </form>
        </div><!-- /.box -->
      </div><!--/.col -->
    </div>   <!-- /.row -->
  </section><!-- /.content -->
<?php
}

elseif ($_GET['form']=='edit') { 
  if (isset($_GET['id'])) {

      $query = mysqli_query($mysqli, "SELECT id,nombre,apertura FROM apertura_cierre WHERE id='$_GET[id]'") 
                                      or die('error: '.mysqli_error($mysqli));
      $data  = mysqli_fetch_assoc($query);
    }
?>

  <section class="content-header">
    <h1>
      <i class="fa fa-edit icon-title"></i> Generar cierre o apertura
    </h1>
    <ol class="breadcrumb">
      <li><a href="?module=start"><i class="fa fa-home"></i> Inicio </a></li>
      <li><a href="?module=catalogo_correos">  </a></li>
      <li class="active"> Modificar </li>
    </ol>
  </section>

  <!-- Main content -->
  <section class="content">
    <div class="row">
      <div class="col-md-12">
        <div class="box box-primary">
          <!-- form start -->
          <form role="form" class="form-horizontal" action="modules/trade/apertura/proses.php?act=update" method="POST">
            <div class="box-body">
              
              <div class="form-group">
                <label class="col-sm-2 control-label">id</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="id" value="<?php echo $data['id']; ?>" readonly required>
                </div>
              </div>

              <div class="form-group">
                <label class="col-sm-2 control-label">NOMBRE</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="nombre" autocomplete="off" value="<?php echo $data['nombre']; ?>" required>
                </div>
				</div>
				
				<div class="form-group">  
                <label class="col-sm-2 control-label">ESTADO DE INVENTARIO</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="apertura" data-placeholder="-- Seleccionar motivo --" onchange="tampil_obat(this)" autocomplete="off" required>
                    <!--<option value=""></option>-->
					<option value="<?php echo $data['nombre']; ?>"><?php echo $data['apertura']; ?></option>
                    <?php
                      $query_cierre = mysqli_query($mysqli, "SELECT name,tipo FROM condiciones_cierre ORDER BY name ASC")
                                                            or die('error '.mysqli_error($mysqli));
                      while ($data_cierre = mysqli_fetch_assoc($query_cierre)) {
                         echo"<option value=\"$data_cierre[name]\"> $data_cierre[name] </option>";
                      }
                    ?>
                  </select>
                </div>
              </div>
				
			
   




            </div><!-- /.box body -->

            <div class="box-footer">
              <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                  <input type="submit" class="btn btn-primary btn-submit" name="Guardar" value="Guardar">
                  <a href="?module=catalogo_motivos" class="btn btn-default btn-reset">Cancelar</a>
                </div>
              </div>
            </div><!-- /.box footer -->
          </form>
        </div><!-- /.box -->
      </div><!--/.col -->
    </div>   <!-- /.row -->
  </section><!-- /.content -->
<?php
}


