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

  <section class="content-header">
    <h1>
      <i class="fa fa-edit icon-title"></i> Agregar
    </h1>
    <ol class="breadcrumb">
      <li><a href="?module=start"><i class="fa fa-home"></i> Inicio </a></li>
      <li><a href="?module=remision"> Remision </a></li>
      <li class="active"> Agregar </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/remision/proses.php?act=insert" method="POST" name="formObatMasuk">
            <div class="box-body">
              <?php              
                $tahun = date("Y");
              ?>


              <div class="form-group">
                <label class="col-sm-2 control-label">Fecha</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control date-picker" data-date-format="dd-mm-yyyy" name="fecha_a" autocomplete="off" value="<?php echo date("d-m-Y"); ?>" readonly required>
                </div>
              </div>

             

              <div class="form-group">  
                <label class="col-sm-2 control-label">Producto</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="codigo" data-placeholder="-- Seleccionar Productos --" onchange="tampil_obat(this)" autocomplete="off" required>
                    <option value=""></option>
                    <?php
                       $query_obat = mysqli_query($mysqli, "SELECT codigo, nombre FROM medicamentos where stock >= 1  ORDER BY nombre ASC")
                                                            or die('error '.mysqli_error($mysqli));
                      while ($data_obat = mysqli_fetch_assoc($query_obat)) {
                        echo"<option value=\"$data_obat[codigo]\"> $data_obat[codigo] | $data_obat[nombre] </option>";
                      }
                    ?>
                  </select>
                </div>
              </div>
			  
			 
			  
			    <span id='stok'>
              <div class="form-group">
                <label class="col-sm-2 control-label">Stock</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" id="stok" name="stock" readonly required>
                </div>
              </div>
              </span>
			  
			    <div class="form-group">
                <label class="col-sm-2 control-label">Transacción</label>
                <div class="col-sm-5">
                  <select name="transaccion" id="transaccion" required class='form-control' readonly>
					          <option value="Remision">Remision</option>					
				          </select>
                </div>
              </div>

			   <div class="form-group">
                <label class="col-sm-2 control-label">Cantidad</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" id="jumlah_masuk" name="num" autocomplete="off" onKeyPress="return goodchars(event,'0123456789',this)" required>
                </div>
              </div>
			  
			  
			<!--  <div class="form-group">  
                <label class="col-sm-2 control-label">Motivo</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="observaciones" data-placeholder="-- Seleccionar motivo --" onchange="tampil_obat(this)" autocomplete="off" required>
                    <option value=""></option>
                    <?php
                      $query_motivo = mysqli_query($mysqli, "SELECT nombre,tipo FROM motivo where tipo = 'SALIDA' ORDER BY nombre ASC")
                                                            or die('error '.mysqli_error($mysqli));
                      while ($data_motivo = mysqli_fetch_assoc($query_motivo)) {
                         echo"<option value=\"$data_motivo[nombre]\"> $data_motivo[tipo] | $data_motivo[nombre] </option>";
                      }
                    ?>
                  </select>
                </div>
              </div>
			  
			  
			       <div class="form-group">
                <label class="col-sm-2 control-label">Motivo</label>
                <div class="col-sm-5">
				<select name="observaciones" id="observaciones" required class='form-control' onchange="hitung_total_stok();">
					<option value="POR EVENTO LOCAL">POR EVENTO LOCAL</option>
					<option value="POR EVENTO FORANEO">POR EVENTO FORANEO</option>
					<option value="POR AJUSTE DE INVENTARIO">POR AJUSTE DE INVENTARIO</option>
					<option value="OTROS">OTROS</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=remision" class="btn btn-default btn-reset">Cancelar</a>
                </div>
              </div>
            </div><!-- /.box footer -->
          </form>
        </div><!-- /.box -->
      </div><!--/.col -->
    </div>   <!-- /.row -->
  </section><!-- /.content -->
<?php
}
?>
<script type="text/javascript">
  function tampil_obat(input){
    var num = input.value;

    $.post("modules/trade/remision/medicines.php", {
      dataidobat: num,
    }, function(response) {      
      $('#stok').html(response)

      document.getElementById('jumlah_masuk').focus();
    });
  }

</script>