<?php  
$queryclose = mysqli_query($mysqli, "SELECT apertura FROM apertura_cierre where id = 1") 
or die('error: '.mysqli_error($mysqli));
$rows  = mysqli_num_rows($queryclose);
$data  = mysqli_fetch_assoc($queryclose);
$bandera = $data['apertura'];
/*print_r($bandera);
die();*/

if ($bandera == 'CERRADO') {
    echo '<script>
                alert("EL ALMACEN SE ENCUENTRA CERRADO POR INVENTARIO DEL SUPERVISOR");
                // Obtener el nombre del servidor y construir la URL base
                var serverUrl = "http://" + window.location.hostname;
                var url = serverUrl + "/main.php?module=closed";
                window.location = url;
          </script>';
    return;
}  
if ($_GET['form']=='add') { ?> 

  <section class="content-header">
    <h1>
      <i class="fa fa-edit icon-title"></i> Agregar productos
    </h1>
    <ol class="breadcrumb">
      <li><a href="?module=start"><i class="fa fa-home"></i> Inicio </a></li>
      <li><a href="?module=medicines"> productos </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/perfil/proses.php?act=insert" method="POST">
            <div class="box-body">
			<?php  
          
              $query_id = mysqli_query($mysqli, "SELECT id FROM perfil
                                                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">Empresa</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="nombre_empresa"  required>
                </div>
              </div>

              <div class="form-group">
                <label class="col-sm-2 control-label">Direccion</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="direccion" autocomplete="off" required>
                </div>
              </div>
			  
			  <div class="form-group">
                <label class="col-sm-2 control-label">Email</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="email" autocomplete="off" required>
                </div>
              </div>
			  
			    <div class="form-group">
                <label class="col-sm-2 control-label">SERIE REM</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="folio1" autocomplete="off" required>
                </div>
              </div>
			  
			  <div class="form-group">
                <label class="col-sm-2 control-label">SERIE SAL/ENT </label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="folio" autocomplete="off" required>
                </div>
              </div>
			  
			   <div class="form-group">
                <label class="col-sm-2 control-label">Almacen</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="almacen" autocomplete="off" required>
                </div>
              </div>
			  
			   <div class="form-group">
                <label class="col-sm-2 control-label">Almacenista</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="almacenista" autocomplete="off" required>
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label">CarpetaImagen</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="imagen" autocomplete="off" required>
                </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=medicines" 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 * from perfil 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> Modificar Empresa
    </h1>
    <ol class="breadcrumb">
      <li><a href="?module=start"><i class="fa fa-home"></i> Inicio </a></li>
      <li><a href="?module=medicines"> Empresa </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/catalogos/perfil/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">Empresa</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="nombre_empresa" value="<?php echo $data['nombre_empresa']; ?>" required>
                </div>
              </div>

              <div class="form-group">
                <label class="col-sm-2 control-label">Direccion</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="direccion" autocomplete="off" value="<?php echo $data['direccion']; ?>" required>
                </div>
				</div>
				
				  <div class="form-group">
                <label class="col-sm-2 control-label">Email</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="email" autocomplete="off" value="<?php echo $data['email']; ?>" required>
                </div>
				</div>
				
				  <div class="form-group">
                <label class="col-sm-2 control-label">SERIE REM</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="folio2" autocomplete="off" value="<?php echo $data['folio2']; ?>" required>
                </div>
				</div>
				
				  <div class="form-group">
                <label class="col-sm-2 control-label">SERIE SAL/ENT</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="folio" autocomplete="off" value="<?php echo $data['folio']; ?>" required>
                </div>
				</div>
				 <div class="form-group">
                <label class="col-sm-2 control-label">Almacen</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="almacen" autocomplete="off" value="<?php echo $data['almacen']; ?>" required>
                </div>
				</div>
				
				 <div class="form-group">
                <label class="col-sm-2 control-label">Almacenista</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="almacenista" autocomplete="off" value="<?php echo $data['almacenista']; ?>" required>
                </div>
				</div>
				
				<div class="form-group">
                <label class="col-sm-2 control-label">CarpetaImagen</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="imagen" autocomplete="off" value="<?php echo $data['imagen']; ?>" required>
                </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=medicines" class="btn btn-default btn-reset">Cancelar</a>
                </div>
              </div>
            </div><!-- /.box footer -->
          </form>
        </div><!-- /.box -->
      </div><!--/.col -->
    </div>   <!-- /.row -->
  </section><!-- /.content -->
<?php
}


