<?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 Booking</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.'" onchange="caritgl()"'); ?>
			   </div>
		   </div>
           
                   <div class="form-group">
			   
			   <?php $nm_f="total";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Jumlah Booking</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="satuanan">
				   <?php echo form_dropdown($nm_f,$opt_satuan,(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class="" id="'.$nm_f.'" '); ?>
			   </div>
		   </div>
                   
                   <div class="form-group">
			   
			   <?php $nm_f="petugas";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Petugas</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="customer";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Customer</label>
				   </div><div class="col-sm-9" >
				   <?php echo form_dropdown($nm_f,$opt_customer,(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class=" select2" id="'.$nm_f.'" '); ?>
			   </div>
		   </div>
           <div class="form-group">
			   
			   <?php $nm_f="catatan";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Catatan</label>
				   </div><div class="col-sm-9">
                                       <textarea name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>"class="col-sm-4 validate[required]"><?php echo $val[$nm_f] ?></textarea>
			   </div>
		   </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);
            }
        });
        caritgl();
        //caristok()
        
    }
    function gantiproduk(v){
        $('#jenis_produks').load('<?php echo base_url().$this->utama?>/loadjenis',{v:v});
        //caristok()
    }
    function gantijenis(v){
        $('#produks').load('<?php echo base_url().$this->utama?>/loadproduk',{v:v});
        //caristok()
    }
    function caritgl(){
        $('#tgl_tiba_div').empty();
        var pr=$('#produk').val();
        var gdg=$('#gudang').val();
        $('#tgl_tiba_div').load('<?php echo base_url().$this->utama?>/cari_tanggal/<?php echo $val['tgl_tiba'] ?>',{v:pr,g:gdg});
        //caristok()
    }
//    function caristok(){
//       // alert('caristok');
//        
//        var pr=$('#produk').val();
//        var gdg=$('#gudang').val();
//        var tgl=$('#tgl_tiba').val();
//        $.post('<?php echo base_url() ?>stok_out/cari_stok',{v:pr,t:tgl,g:gdg},function(e){
//            //alert('caristok');
//            var stoks=JSON.parse(e);
//            if(stoks.stok==null){
//            stoks.stok=0;    
//            }
//            $('#max-stok').empty();
//            $('#max-stok').append('Jumlah Stok : '+stoks.stok);
//            $('#total').prop('max',stoks.stok);
//            //alert(stoks.satuan);
//            $('#satuan').val(stoks.satuan);
//            $('#satuan').prop('readonly',true);
//            console.log(e);
//        });
//    }
	$('#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>