<script type="text/javascript">  
theight=$( document ).height()-50; 
function setdg(){
	$('#dg').datagrid({  	
		height:theight,
		toolbar:"#toolbar",
		fit:true,
		fitColumns:true,
		rownumbers:true,		
		pagination:true,
		pageSize:100,
		pageList:[100,200,300,400,500],
		frozenColumns:[[  
			{field:'KdBarang',title:'Kode Barang',width:60},
			{field:'PartNo',title:'Size',width:100},
			{field:'NmBarang',title:'Nama Barang',width:80},   
			{field:'Sat',title:'Sat.',width:50}, 
		]],
		columns:[[  					
			{field:'qty_beg',title:'Saldo Awal',width:60,align:'right'},
			{field:'qty_in',title:'Pemasukan',width:60,align:'right'},
			{field:'qty_out',title:'Pengeluaran',width:60,align:'right'},
			{field:'qty_bal',title:'Penyesuaian (Adjustment)',width:90,align:'right'},
			{field:'qty_end',title:'Saldo Akhir',width:60,align:'right',formatter: function(value,row,index){				
				qty_beg=parseFloat(row.qty_beg);
				qty_in=parseFloat(row.qty_in);
				qty_out=parseFloat(row.qty_out);
				qty_akhir=qty_beg+qty_in-qty_out;
				qty_bal=parseFloat(row.qty_bal);
				qty=parseFloat(row.qty);
				if (qty_akhir>qty){
					qty_end=qty_akhir-qty_bal;
				} else {
					qty_end=qty_akhir+qty_bal;
				}
				return qty_end;
			}},
			{field:'qty',title:'Stock Opname',width:90,align:'right'},
			{field:'qty_diff',title:'Selisih',width:90,align:'right'},
			{field:'ket',title:'Keterangan',width:80}
		]],	
		onBeforeLoad: function (data) {
		  var panel = $(this).datagrid("getPanel");
		  // here is to add the css style
		  panel.css("border","0");
		}		
	});
}
function aksi(cmd){
	var opts = $('#dg').datagrid('options');
	dtdari=$('#dtdari').datebox('getValue');
	dtsampai=$('#dtsampai').datebox('getValue');
	kd_cmpy='';
	// kd_cmpy=$('#kd_cmpy').combobox('getValue');
	q=$("#q").val();
	
	if (dtdari!="" && dtsampai!=""){
		if (cmd=='cari'){		
			$('#dg').datagrid({
				url: '<?=site_url($this->modul.'/aksi/cari')?>',
				queryParams:{			
					dtdari:$('#dtdari').datebox('getValue'),
					dtsampai:$('#dtsampai').datebox('getValue'),
					kd_cmpy:kd_cmpy,
					q:q
				}		
			});
		} else if (cmd=='print'){
			var win = window.open("<?=site_url($this->modul)?>/aksi/cetak?dtdari="+dtdari+"&dtsampai="+dtsampai+"&kd_cmpy="+kd_cmpy+"&q="+q+"&page="+opts.pageNumber+"&rows="+opts.pageSize,"Popup","toolbar=no, location=no,status=no,menubar=no,scrollbars=yes,resizable=no");
			win.print();
		} else if (cmd=='xls'){
			openurl("<?=site_url($this->modul)?>/aksi/excel?dtdari="+dtdari+"&dtsampai="+dtsampai+"&kd_cmpy="+kd_cmpy+"$q="+q+"&page="+opts.pageNumber+"&rows="+opts.pageSize);
		}
	}
}
</script>	