<?php error_reporting(E_ALL ^ E_NOTICE);

if(isset($list)){	
	$val=$list;
}

//print_mz($val);
?>
<?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_masuk" class="form-horizontal formular" role="form">
		   <?php
                   $son=GetValue('so_number', 'sv_stok_pengiriman',array('id'=>'where/'.$id));
                   $kon=GetValue('kode_order', 'sv_stok_pengiriman',array('id'=>'where/'.$id));
                   $ket=GetValue('keterangan', 'sv_stok_pengiriman',array('id'=>'where/'.$id));
                   ?>
		   <?php echo form_hidden('id',isset($id) ? $id : '')?>
		   <?php echo form_hidden('param','in')?>
           <div class="form-group">
               <div class="col-sm-3">
                   <label for="<?php echo $nm_f?>">SO Number</label>
                            </div>
               <div class="col-sm-9">
                   <label for="<?php echo $nm_f?>"><?php echo form_input('so', $son,'class="form-control" readonly') ?></label>
                            </div>
            
             </div>
           <div class="form-group">
               <div class="col-sm-3">
                   <label for="<?php echo $nm_f?>">PO Number</label>
                            </div>
               <div class="col-sm-9">
                   <label for="<?php echo $nm_f?>"><?php echo form_input('kode_order', $kon,'class="form-control" readonly') ?></label>
                            </div>
            
             </div>
           <div class="form-group">
               <div class="col-sm-3">
                   <label for="<?php echo $nm_f?>">Keterangan</label>
                            </div>
               <div class="col-sm-9">
                   <label for="<?php echo $nm_f?>"><?php echo form_textarea('keterangan', $ket,'class="form-control" readonly') ?></label>
                            </div>
            
             </div>
                   <?php foreach($list as $ls){
                       
                   $gdg=GetValue('gudang', 'sv_stok_pabrikasi_detail',array('id'=>'where/'.$ls['id']));
                   $tiba=GetValue('tgl_tiba', 'sv_stok_pabrikasi_detail',array('id'=>'where/'.$ls['id']));
                   $sudahdikirim=$this->db->query("SELECT SUM(total) as total FROM sv_stok_in WHERE pengiriman_id='".$ls['pengiriman_id']."' AND pengiriman_detail_id='".$ls['id']."'")->row_array();
                   //lastq();
                   $sudahdikirim=($sudahdikirim['total']==NULL ? 0 : $sudahdikirim['total']);
                   //die($sudahdikirim);
                   $totals=$ls['total']-$sudahdikirim;
                   //echo $totals;
                   //die();
                       ?>
                   
		   <?php echo form_hidden('id_pengiriman_detail[]',$ls['id'])?>
		   <?php echo form_hidden('id_pengiriman[]',$ls['pengiriman_id'])?>
		   <?php echo form_hidden('brand[]',$ls['brand'])?>
		   <?php echo form_hidden('jenis_produk[]',$ls['jenis_produk'])?>
		   <?php echo form_hidden('produk[]',$ls['produk'])?>
		   <?php echo form_hidden('satuan[]',$ls['satuan'])?>
		   <?php echo form_hidden('so_number[]',$son)?>
		   <?php echo form_hidden('kode_order[]',$kon)?>
                   <div class="form-group">
			   
			   <?php $nm_f="gudang[]";?>
                       <div class="col-sm-1">
				   <label for="<?php echo $nm_f?>"><?php echo GetValue('title','master_brand',array('id'=>'where/'.$ls['brand'])) ?></label>
                            </div>
                       <div class="col-sm-2">
				   <label for="<?php echo $nm_f?>"><?php echo GetValue('title','master_jenis_produk',array('id'=>'where/'.$ls['jenis_produk'])) ?></label>
                            </div>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>"><?php echo GetValue('title','master_produk',array('id'=>'where/'.$ls['produk'])) ?></label>
                            </div>
			   <div class="col-sm-1">
                               <?php $tform=array(
                                   'name'=>'total[]',
                                   'value'=>$totals,
                                   'class'=>'form-control',
                                   'id'=>$nm_f,
                                   'type'=>'number',
                                   'max'=>$totals
                               );?>
                                   <?php echo form_input($tform); ?>
                                   <label for="<?php echo $nm_f?>"><?php echo GetValue('title','ref_satuan',array('id'=>'where/'.$ls['satuan'])) ?></label>
                            </div>
			   <div class="col-sm-1">
				   <label for="<?php echo $nm_f?>"><?php echo $ls['keterangan'] ?></label>
                            </div>
                            
                            <div class="col-sm-3" >
				   <!--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_gudang,($gdg!=0 ? $gdg : ''),'class=" select2 form-control" id="'.$nm_f.'" required '); ?>
			   </div>
                           <div class="col-sm-2">
                               
			   <?php $nm_f="tanggal_tiba[]";?>
                               <input type="text" name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>" value="<?php echo $a= ($tiba!=0 ? $tiba : '') ?>" class="form-control date-picker" placeholder="Tanggal Tiba" required>
				   <?php //echo form_dropdown($nm_f,$opt_gudang,(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class=" select2" id="'.$nm_f.'" '); ?>
			   </div>
		   </div>
                   <?php }?>
		   
    		<div class="form-group">
            <button type="submit" class="btn pull-right">Submit</button>
            
             </div>
			 </form>
    	</div>
    </div>
    </div>
</div>
<script>
    $('.select2').css('width','100%').select2({matcher: function(params,data){
                                    return matchStart(params, data);
                                },});
    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>