<?php error_reporting(E_ALL ^ E_NOTICE);
if(isset($list)){	
	$val=$list;
}
?>
<?php
$cekdup=($type=='New' ? ',ajax[ajaxcekcode]' : '');
?>
    
<div class="row">
	
    <div class="box col-md-12">
    <div class="box-inner">
    
    	<div class="box-content">
       <form id="form" method="post" enctype="multipart/form-data" action="<?php echo base_url($this->utama)?>/submit" class="form-horizontal formular" role="form">
		   
		   <?php echo form_hidden('id',isset($val['id']) ? $val['id'] : '')?>
		   <?php echo form_hidden('param','in')?>
			
		   
		   <div class="form-group">
			   
			   <?php $nm_f="code";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Code</label>
				   </div><div class="col-sm-9">
				   <input type="text" name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>_master_produk" value="<?php echo $a= (isset($val[$nm_f]) ? $val[$nm_f] : '') ?>" class="col-sm-4 validate[required<?php echo $cekdup?>]">
			   </div>
		   </div>
		   <div class="form-group">
			   
			   <?php $nm_f="brand";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Merk</label>
				   </div><div class="col-sm-9">
				   <!--input type="text" name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>" value="<?php echo $a= (isset($val[$nm_f]) ? $val[$nm_f] : '') ?>" class="col-sm-4"-->
				   <?php echo form_dropdown($nm_f,$opt_brand,(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class="select2" id="'.$nm_f.'" onchange="gantiproduk(this.value)" '); ?>
			   </div>
		   </div>
		   <div class="form-group">
			   
			   <?php $nm_f="jenis_produk";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Jenis Produk</label>
				   </div><div class="col-sm-9" id="jenis_produks">
				   <!--input type="text" name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>" value="<?php echo $a= (isset($val[$nm_f]) ? $val[$nm_f] : '') ?>" class="col-sm-4"-->
				   <?php echo form_dropdown($nm_f,$opt_jenis,(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class=" select2" id="'.$nm_f.'" onchange="gantijenis(this.value)"'); ?>
			   </div>
		   </div>
		   <div class="form-group">
			   
			   <?php $nm_f="produk";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Produk</label>
				   </div><div class="col-sm-9" id="produks">
				   <?php echo form_dropdown($nm_f,$opt_produk,(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class=" select2" id="'.$nm_f.'" '); ?>
			   </div>
		   </div>
           
                   <div class="form-group">
			   
			   <?php $nm_f="gudang_awal";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Lokasi Gudang Awal</label>
				   </div><div class="col-sm-9" id="produks">
				   <?php echo form_dropdown($nm_f,$opt_gudang,(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class=" select2" id="'.$nm_f.'" '); ?>
			   </div>
		   </div>
            <div class="form-group">
			   
			   <?php $nm_f="part_number";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Part Number</label>
				   </div><div class="col-sm-9">
				   <input type="text" name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>_master_produk" value="<?php echo $a= (isset($val[$nm_f]) ? $val[$nm_f] : '') ?>" class="col-sm-4 validate[required<?php echo $cekdup?>]">
			   </div>
		   </div>
           <div class="form-group">
			   
			   <?php $nm_f="lot_number";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Lot Number</label>
				   </div><div class="col-sm-9">
				   <input type="text" name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>_master_produk" value="<?php echo $a= (isset($val[$nm_f]) ? $val[$nm_f] : '') ?>" class="col-sm-4 validate[required<?php echo $cekdup?>]">
			   </div>
		   </div>
                   <div class="form-group">
			   
			   <?php $nm_f="total";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Jumlah Keluar</label>
				   </div><div class="col-sm-9">
				   <input type="text" name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>" value="<?php echo $a= (isset($val[$nm_f]) ? $val[$nm_f] : '') ?>" class="col-sm-4 validate[required]">
			   </div>
		   </div>
		   <div class="form-group">
			   
			   <?php $nm_f="satuan";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Satuan</label>
				   </div><div class="col-sm-9" id="satuan">
				   <?php echo form_dropdown($nm_f,$opt_satuan,(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class=" select2" id="'.$nm_f.'" '); ?>
			   </div>
		   </div>
                   <div class="form-group">
			   
			   <?php $nm_f="tgl";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Tanggal Pindah Lokasi</label>
				   </div><div class="col-sm-9">
				   <input type="text" name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>" value="<?php echo $a= (isset($val[$nm_f]) ? $val[$nm_f] : '') ?>" class="col-sm-4 validate[required] date-picker">
			   </div>
		   </div>
                   <div class="form-group">
			   
			   <?php $nm_f="tgl_tiba";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Tanggal Tiba</label>
				   </div><div class="col-sm-9">
				   <input type="text" name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>" value="<?php echo $a= (isset($val[$nm_f]) ? $val[$nm_f] : '') ?>" class="col-sm-4 validate[required] date-picker">
			   </div>
		   </div>
                   <div class="form-group">
			   
			   <?php $nm_f="gudang_akhir";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Lokasi Gudang Akhir</label>
				   </div><div class="col-sm-9" id="produks">
				   <?php echo form_dropdown($nm_f,$opt_gudang,(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class=" select2" id="'.$nm_f.'" '); ?>
			   </div>
		   </div>
		   <!--div class="form-group">
			   
			   <?php $nm_f="link";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Link</label>
				   </div><div class="col-sm-9">
				   <input type="text" name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>" value="<?php echo $a= (isset($val[$nm_f]) ? $val[$nm_f] : '') ?>" class="col-sm-4">
			   </div>
		   </div>
		   <div class="form-group">
			   
			   <?php $nm_f="currency";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Currency</label>
				   </div><div class="col-sm-9">
				   <?php echo form_dropdown($nm_f,$opt_currency,(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class="select2" id="'.$nm_f.'" '); ?>
			   </div>
		   </div>
		   <div class="form-group">
			   
			   <?php $nm_f="harga_satuan";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Harga Satuan</label>
				   </div><div class="col-sm-9">
				   <input type="text" name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>" value="<?php echo $a= (isset($val[$nm_f]) ? $val[$nm_f] : '') ?>" class="col-sm-4">
			   </div>
		   </div>
		   <div class="form-group">
			   
			   <?php $nm_f="satuan";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Satuan</label>
				   </div><div class="col-sm-9">
				   <?php echo form_dropdown($nm_f,$opt_metric,(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class="select2" id="'.$nm_f.'" '); ?>
			   </div>
		   </div>
		   <div class="form-group">
			   
			   <?php $nm_f="minimum_order";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Minimum Order</label>
				   </div><div class="col-sm-9">
				   <input type="text" name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>" value="<?php echo $a= (isset($val[$nm_f]) ? $val[$nm_f] : '') ?>" class="col-sm-4">
			   </div>
		   </div>
		   <div class="form-group">
			   
			   <?php $nm_f="waktu_pengiriman";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Waktu Pengiriman</label>
				   </div><div class="col-sm-9">
				   <input type="text" name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>" value="<?php echo $a= (isset($val[$nm_f]) ? $val[$nm_f] : '') ?>" class="col-sm-4">
			   </div>
		   </div>
		   <div class="form-group">
			   
			   <?php $nm_f="spesifikasi";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Spesifikasi</label>
				   </div><div class="col-sm-9">
				   <?php echo form_textarea($nm_f,(isset($val[$nm_f]) ? $val[$nm_f] : ''),"class='col-sm-4' id='$nm_f'");?>
				   
			   </div>
		   </div>
		   <div class="form-group">
			   
			   <?php $nm_f="klasifikasi";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Klasifikasi</label>
				   </div><div class="col-sm-9">
				    <?php echo form_dropdown($nm_f,$opt_klasifikasi,(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class=" select2" id="'.$nm_f.'" '); ?>
				   
			   </div>
		   </div>
		   <div class="form-group">
			   
			   <?php $nm_f="tag";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Tag</label>
				   </div><div class="col-sm-9">
				   <input type="text" name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>" value="<?php echo $a= (isset($val[$nm_f]) ? $val[$nm_f] : '') ?>" class="col-sm-4">
			   </div>
		   </div>
		   <div class="form-group">
			   
			   <?php $nm_f="catatan";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Note</label>
				   </div><div class="col-sm-9">
                                       <?php echo form_textarea($nm_f,(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class="validate[required]"');?>
				   <!--input type="text" name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>" value="<?php echo $a= (isset($val[$nm_f]) ? $val[$nm_f] : '') ?>" class="col-sm-4"-->
			   </div>
		   </div-->
    		<div class="form-group">
            <button type="submit" class="btn pull-right">Submit</button>
            
             </div>
			 </form>
    	</div>
    </div>
    </div>
</div>
<script>
    function cariexpired(){
        var pr=$('#produk').val();
        //alert(pr);
        $.post('<?php echo base_url() ?>stok_in/load_expired',{p:pr},function(e){
            
            if(e!=0){
            $('#exp').val(e);
            
            //$('#exp').attr('readonly',true);
            }
        });
        
    }
    function gantiproduk(v){
        $('#jenis_produks').load('<?php echo base_url().$this->utama?>/loadjenis',{v:v});
    }
    function gantijenis(v){
        $('#produks').load('<?php echo base_url().$this->utama?>/loadproduk',{v:v});
    }
	$('#target').mask('9.99');
	$('#comission').mask('9.99');
        
$(document).ready(function(e){
        cariexpired();
        $("#form").validate({
            submitHandler: function(form) {
    form.submit();
  },
           ignore: [],      
            rules: {
                'title': {required:true},
                'jenis_produk': {required:true},
                'brand': {required:true}
            }
            , 
            messages: {
                'title': 'Wajib diisi',
                'jenis_produk': 'Wajib diisi',
                'brand': 'Wajib diisi'
            }
            });
    });
</script>