<script type="text/javascript">
$(function(){
window.parent.$('#content_title').panel('setTitle', '<?=$this->title?>');

theight=window.parent.$('#content').height()-30;	

$('#tb').tabs({
	width:'100%',	
	height:theight,
	fit:true,
	border:false,
	plain:true,
	onSelect:function(title,index){
		if(index==1){
			setDgHdrDet();
		}
	}
});

var typebp 	= $("#typebp");
var typecp 	= $("#typecp");
var bp = document.getElementById('typebp');
var cp = document.getElementById('typecp');
$('#showbp').hide();
$('#showcp').hide();
$('#shownothing').show();

typebp.change(function() {
	if (bp.checked) {
		$('#accountc_id_bp').combogrid({ 
			panelWidth:500,  	
			url: '<?=site_url('general/gridBP'); ?>',  
			idField:'acctnum',  
			textField:'acctnum',  
			mode:'remote',  
			rownumbers:true,
			fitColumns:true,
			pagination:true,
			columns:[[  
				{field:'acctnum',title:'DO No.',width:60},
				{field:'acctname',title:'acctname',width:100}
			]],
			onClickRow:function(index,row){
				$('#acctnamec').textbox('setValue', row.acctname);
				$('#accountc_id').textbox('setValue', row.acctnum);
			}
		});
		$('#showbp').show();
		$('#showcp').hide();
		$('#shownothing').hide();
		$('#acctnamed').textbox('setValue', "");
		$('#accountd_id').textbox('setValue', "");
	}
});

typecp.change(function() {
	if (cp.checked) {
		$('#accountc_id_cp').combogrid({ 
			panelWidth:500,  	
			url: '<?=site_url('general/gridCP'); ?>',  
			idField:'acctnum',  
			textField:'acctnum',  
			mode:'remote',  
			rownumbers:true,
			fitColumns:true,
			pagination:true,
			columns:[[
				{field:'acctnum',title:'Acct Number',width:60},  
				{field:'acctname',title:'Acct Name',width:100}
			]],
			onClickRow:function(index,row){
				$('#acctnamec').textbox('setValue', row.acctname);
				$('#accountc_id').textbox('setValue', row.acctnum);
			}
		});
		$('#showbp').hide();
		$('#showcp').show();
		$('#shownothing').hide();
		$('#acctnamed').textbox('setValue', "");
		$('#accountd_id').textbox('setValue', "");
	}
});

$('#nothing').combogrid({ 
	panelWidth:500,
	idField:'acctnum',  
	textField:'acctnum',  
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	columns:[[  
		{field:'acctnum',title:'DO No.',width:60},
		{field:'acctname',title:'acctname',width:100}
	]]
});

$('#accountd_id').combogrid({ 
	panelWidth:500,  	
	url: '<?=site_url('general/gridInv'); ?>',  
	idField:'acctnum',  
	textField:'acctnum',  
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	columns:[[  
		{field:'acctnum',title:'Acct Number',width:60},
		{field:'acctname',title:'Acct Name',width:100}
	]],
	onClickRow:function(index,row){
		$('#acctnamed').textbox('setValue', row.acctname);
	}
});

$('#ref_id').combogrid({
	panelWidth:500,  	
	url: '<?=site_url('general/gridAPList/')?>',  
	idField:'id',  
	textField:'no',  
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	columns:[[
		{field:'supl_inv',title:'Invoice No.',width:60},  
		{field:'no',title:'AP No.',width:60},
		{field:'date',title:'AP Date',width:50},
		{field:'NmPrshn',title:'Customer',width:150}
	]],
	onClickRow:function(index,row){
		$('#description').textbox('setValue',row.description);
		$('#tot_amount').numberbox('setValue',row.tot_amount);
		$('#tax').textbox('setValue',row.tax);
		$('#supplier').textbox('setValue',row.NmPrshn);
		$('#currency').textbox('setValue',row.currency);
		$('#rate').textbox('setValue',row.rate);
		$('#tax_amount').textbox('setValue',row.tax_amount);
		$('#aftertax_amount').textbox('setValue',row.after_tax);
		$('#accountd_id').textbox('setValue',row.accountc_id);
		$('#acctnamed').textbox('setValue',row.acctnamec);
	}  
});

$('#rate').numberbox({  
    min:0, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.'
});

$('#item_id').combogrid({  
	width:150,
	panelWidth:500,  	
	url: '<?=site_url('general/gridBarang/'.$this->tp_barang)?>',  
	idField:'KdBarang',  
	textField:'KdBarang',  
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	columns:[[  
		{field:'KdBarang',title:'Item Code',width:60},
		{field:'NmBarang',title:'Item Description',width:150},
		{field:'Sat',title:'UOM',width:50}
	]],
	onClickRow:function(index,row){
		//console.log(row);
		insert_det(row)
	}  
}); 

$('#Sat').combobox({  
	mode:'remote', 
	url:'<?=site_url('uom/gridAll'); ?>',  
	valueField:'KdSat',  
	textField:'KdSat',
	pagination:true   
});

$('#qty').numberbox({  
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.',
	onChange:function(newValue,oldValue){
		price=$('#price').numberbox('getValue');
		amount = newValue*price;
		$('#amount').numberbox('setValue',amount);
	}
});


$('#price').numberbox({  
    min:-1000, 
	precision:4, 
	groupSeparator:',',
	decimalSeparator:'.',
	onChange:function(newValue,oldValue){
		qty=$('#qty').numberbox('getValue');
		amount = newValue*qty;
		$('#amount').numberbox('setValue',amount);
	}
});

$('#amount,#tot_amount,#aftertax_amount,#tax_amount').numberbox({  
    min:-10000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.',
});

setDgHdr();
setDgDet();
$('#toolbar_det').hide();

$('#q').searchbox({
	width:200,
	searcher:function(value,name){  
		///alert(value + "," + name)  
		cari(value);
	},
	prompt:'Cari...'  
});

$('#q2').searchbox({
	width:200,
	searcher:function(value,name){  
		///alert(value + "," + name)  
		cari2(value);
	},
	prompt:'Cari...'  
});  

$('#q_det').searchbox({
	width:200,
	searcher:function(value,name){  
		// alert(value + "," + name);  
		cari_det(value);
	},
	prompt:'Cari...'  
});

/*Button Event*/
$('#btnBarScan').click(function(){
	barScan();
});

$('#btnTbh').click(function(){
	tambah();
});

$('#btnUbh').click(function(){	
	ubah();
});

$('#btnHps').click(function(){
	hapus();
});

$('#btnSim').click(function(){
	simpan();
});

$('#btnPrint').click(function(){
	printSlip();
});

$('#btnPrint2').click(function(){
	aksi('print');
});

$('#btnExcel').click(function(){
	aksi('xls');
});


$('#btnSubmit').click(function(){
	simpan();
});

$('#btnReset').click(function(){
	$('#fm').form('clear');
});

/*Button2 Event*/
$('#btnTbh2').click(function(){
	tambah2();
});

$('#btnUbh2').click(function(){	
	ubah2();
});

$('#btnHps2').click(function(){
	hapus2();
});

$('#btnSim2').click(function(){
	simpan2();
});

$('#btnSubmit2').click(function(){
	simpan2();
});

$('#btnReset2').click(function(){
	$('#fm2').form('clear');
});


$('#btnSim3').click(function(){
	simpan3();
});

$('#btnSubmit2').click(function(){
	simpan3();
});

$('#btnReset2').click(function(){
	$('#fm3').form('clear');
});

$('#btnJournal').click(function(){
	createJournal();
});
$('#btnresetJ').click(function(){
	resetJournal();
});

});//Akhir Document Ready
</script>