<div class="col-md-12">
<button data-toggle="collapse" data-target="#demo" class="btn-danger btn">Search</button>
<fieldset style="border:1px solid #D4011B; padding-bottom:10px; border-radius:5px;" class="col-md-12 collapse <?php if(isset($_POST['search'])) echo "in"?>" id="demo"> 
	
	<form enctype="multipart/form-data" method="get" action="<?php echo base_url() ?>stok_out">
            <div class="col-sm-12 col-md-12" style="margin-top:10px">
                           <div class="col-sm-6 col-md-6"  style="float:none!important;margin:0 auto;">
                               <div class="col-md-12" id="sbrand">
                           <?php echo form_dropdown('brand',$opt_brand,$_GET['brand'],'class="select2" onchange="gantiproduk(this.value)"')?> &nbsp; &nbsp; &nbsp;</div>
                               <br/>
                           <div class="col-md-12" id="sjp" style="margin-top:10px;">
                           <?php echo form_dropdown('jenis_produk',GetOptAll('master_jenis_produk','-Semua Jenis Produk-',array('brand'=>'where/'.$_GET['brand'])),$_GET['jenis_produk'],'class="select2" onChange=gantijenis(this.value)')?>  &nbsp; &nbsp; &nbsp;</div>
                               <br/>
                           <div class="col-md-12" id="sp" style="margin-top:10px;">
                           <?php echo form_dropdown('produk',GetOptAll('master_produk','-Semua Produk-',array('jenis_produk'=>'where/'.$_GET['jenis_produk'])),$_GET['produk'],'class="select2"')?></div>
                           <div class="col-md-12" style="margin-top:10px;">
                    <?php echo form_dropdown('gudang',GetOptAll('master_gudang','-Gudang-'),$_GET['gudang'],'class=" select2" id="'.$nm_f.'" '); ?>
                
            </div>
                           
            <div class="col-md-12" style="margin-top:10px;">
                    <?php echo form_input('tanggal',$_GET['tanggal'],'class="date-picker" id="'.$nm_f.'" placeholder="Tanggal" '); ?>
                
            </div>
                           </div>
            </div>
            
			<?php echo form_hidden('lastq',$lastq);?>
            <div class="col-sm-12 col-md-12"><div class="col-sm-12 col-md-12"><button type="submit" value="" >Search</button>&nbsp;<!--input type="submit" value="Export" name="export"--></div></div>
	<div class="col-sm-12" style="margin-top:10px"></div>
	
	</form>

</fieldset>
</div>
<br/>
<div class="col-md-12">

<?php
error_reporting(0);
 echo $js_grid; ?>
<!--input type="button" value="Tambah" onclick="window.location = '<?//= base_url() ?>index.php/ms_con/add'"/-->
<script type="text/javascript">
    function gantiproduk(v){
        $('#sjp').load('<?php echo base_url().$this->utama?>/loadjenis',{v:v});
    }
    function gantijenis(v){
        $('#sp').load('<?php echo base_url().$this->utama?>/loadproduk',{v:v});
    }
    $(document).ready(function(e){
    
                           $('.select2').css('max-width','100%').select2({});
});
var _base_url = '<?php echo  base_url() ?>';
var controller = '<?php echo $this->utama?>/';
function del(id) { 
  i = confirm('Hapus : ' + id + ' ?');
  if (i) {
    window.location = _base_url + controller + 'delete/' + id;
  }
}
//$('.flex1').flexigrid({height:'auto',width:'auto',striped:false});

function edit(id) {
  window.location = _base_url + controller + 'input/' + id;
}

function detail(id) {
  window.location = _base_url + controller + 'form/' + id;
}
function btn(com,grid)
{
    if (com == 'add' ) {
		window.location = _base_url + controller + 'form/';
    }
	
    if (com == 'select' )
    {
		$('.bDiv tbody tr',grid).addClass('trSelected');
    }

    if (com == 'deselect')
    {
		$('.bDiv tbody tr',grid).removeClass('trSelected');
    }
	if(com=='edit'){
		if($('.trSelected',grid).length==1){ 
    			var abbr = [];
    				$('.hDiv th', flex).each( function(index){
       			 abbr[index] = $(this).attr('abbr');
  				  });
		//var items = $('.trSelected',grid);
 		 window.location = _base_url + controller + 'form/' + $('td:nth-child('+ (1+$.inArray('idnya',abbr)) +')>div', '.trSelected',grid).text();
			} else {
				return false;
			} 
	}
	if (com=='delete')
    {
           if($('.trSelected',grid).length>0){
			   if(confirm('Delete ' + $('.trSelected',grid).length + ' items?')){
		        var flex = $(grid).closest('.flexigrid');
    			var abbr = [];
    				$('.hDiv th', flex).each( function(index){
       			 abbr[index] = $(this).attr('abbr');
  				  });
    	
   				 $('.res').html('');//div.res - area for display result
		            var items = $('.trSelected',grid);
		            var itemlist ='';
		        	for(i=0;i<items.length;i++){
					//itemlist+=items[i].id+",";
					//var iteming=$('td:"no_reg" >div', items[i]).text();
					itemlist+=$('td:nth-child('+ (1+$.inArray('idnya',abbr)) +')>div', items[i]).text()+",";
					}
					  	
					$.ajax({
					   type: "POST",
					   url: "<?php echo site_url($this->utama."/deletec");?>",
					   data: "items="+itemlist,
					   success: function(data){
					   	$('#flex1').flexReload();
						//alert(data);
						if(data=='ok'){
						alert('Sukses!');}
						else{
							alert('Failed to Delete Data');
						}
					   }
					});
				}
			} else {
				return false;
			} 
      }
	if (com=='surat jalan')
    {
           if($('.trSelected',grid).length==1){
			   if(confirm('Cetak Surat Jalan untuk ' + $('.trSelected',grid).length + ' items?')){
		        var flex = $(grid).closest('.flexigrid');
    			var abbr = [];
    				$('.hDiv th', flex).each( function(index){
       			 abbr[index] = $(this).attr('abbr');
  				  });
    	
   				 $('.res').html('');//div.res - area for display result
		            var items = $('.trSelected',grid);
		            var itemlist ='';
                            var itemarr = [];
		        	for(i=0;i<items.length;i++){
					//itemlist+=items[i].id+",";
					//var iteming=$('td:"no_reg" >div', items[i]).text();
					//itemlist+=$('td:nth-child('+ (1+$.inArray('idnya',abbr)) +')>div', items[i]).text()+"%";
                                        
                                        itemarr.push($('td:nth-child('+ (1+$.inArray('idnya',abbr)) +')>div', items[i]).text());
					}
                                        var energy = itemarr.join('%');
					  	window.location = '<?php echo site_url($this->utama."/suratjalan");?>/true/'+energy+'';
					/*$.ajax({
					   type: "POST",
					   url: "<?php echo site_url($this->utama."/suratjalan");?>",
					   data: "items="+itemlist,
					   success: function(data){
					   	$('#flex1').flexReload();
						//alert(data);
						if(data=='ok'){
						alert('Sukses!');}
						else{
							alert('Failed to Delete Data');
						}
					   }
					});*/
				}
			} else {
				return false;
			} 
      }
      if (com=='surat jalans')
    {
        var abbr = [];
    	$('.hDiv th', flex).each( function(index){
            abbr[index] = $(this).attr('abbr');
  	});
        
           if($('.trSelected',grid).length>0){
                        if($('.trSelected',grid).length==1){
                            window.location = '<?php echo site_url($this->utama."/suratjalan");?>/'+$('td:nth-child('+ (1+$.inArray('idnya',abbr)) +')>div', '.trSelected',grid).text()+'/true';
                        }
			   
			} else {
				return false;
			} 
      }
}
setInterval("$('#flex1').flexReload()",50000 );
</script>
<div class="layout-grid">
	<table id="flex1" style="display:none; "></table>
</div>
</div>