<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();
		}
	}
});

$('#accountd_id').combogrid({ 
	panelWidth:500,  	
	url: '<?=site_url('general/gridIncFgJournalD'); ?>',  
	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);
	}
});

$('#accountc_id').combogrid({ 
	panelWidth:500,  	
	url: '<?=site_url('general/gridIncFgJournalC'); ?>',  
	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);
	}
});
$('#accountd_id_wip').combogrid({ 
	panelWidth:500,  	
	url: '<?=site_url('general/gridWipJournalD'); ?>',  
	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_wip').textbox('setValue', row.acctname);
	}
});
$('#accountc_id_wip').combogrid({ 
	panelWidth:500,  	
	url: '<?=site_url('general/gridWipJournalC'); ?>',  
	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_wip').textbox('setValue', row.acctname);
	}
});
$('#matin_type').combobox({
	mode:'remote', 
	url:'<?=site_url('general/gridInType'); ?>',  
	valueField:'matin_type',  
	textField:'matin_name'  
});

$('#supplier').combobox({
	panelWidth:250,
	mode:'remote', 
	url: '<?=site_url('company/gridAll')?>',  
	valueField:'KdPrshn',  
	textField:'NmPrshn',
	fitColumns: true,
	onSelect:function(rowdata){
		//console.log(rowdata.Valuta);
		$('#currency').combobox('setValue',rowdata.Valuta);
	},
});

$('#currency').combobox({ 
	mode:'remote', 
	url:'<?=site_url('general/gridValuta'); ?>',  
	valueField:'KdVal',  
	textField:'KdVal'  
});

$('#po_id').combogrid({
	panelWidth:500,  	
	url: '<?=site_url('general/gridPO/')?>',  
	idField:'po_id',  
	textField:'po_no',  
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	columns:[[  
		{field:'po_no',title:'PO No.',width:60},
		{field:'po_date',title:'PO Date',width:50},
		{field:'NmPrshn',title:'Supplier',width:150}
	]],
	onClickRow:function(index,row){
		$('#po_no').val(row.po_no);
		$('#supplier').combobox('setValue',row.supplier);
		$('#currency').combobox('setValue',row.currency);
		$('#JmlBarang').textbox('setValue',row.jmlbrg);
	}  
});

$('#bom_id').combogrid({
	panelWidth:500,  	
	url: '<?=site_url('general/gridBomWipIn/')?>',  
	idField:'bom_id',  
	textField:'bom_no',  
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	columns:[[  
		{field:'bom_no',title:'BOM No.',width:120},
		{field:'bom_date',title:'BOM Date',width:120},
		{field:'fg_id',title:'FG Code',width:70},
		{field:'NmBarang',title:'FG Nama',width:200},
		{field:'Sat',title:'UOM',width:60}
	]],
	onClickRow:function(index,row){
		$('#bom_no').val(row.bom_no);
		$('#fg_name').val('setValue',row.fg_name);
		$('#fg_id').val('setValue',row.fg_id);
		$('#bom_date').val('setValue',row.bom_date);
		$('#Sat').val('setValue',row.Sat);
	}  
});

$('#KdJnsDok').combobox({  
	width:100,
	mode:'remote', 
	url:'<?=site_url('general/gridJnsDokIn'); ?>',  
	valueField:'KdJnsDok',  
	textField:'UrJnsDok'  
});

$('#KdJnsDok2').combobox({  
	width:100,
	mode:'remote', 
	url:'<?=site_url('general/gridJnsDokIn'); ?>',  
	valueField:'KdJnsDok',  
	textField:'UrJnsDok'  
});

$('#mat_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)
	}  
}); 

$('#namaPengangkut').combobox({
               valueField: 'value',
               textField: 'text',
               panelHeight: 'auto',
               editable: false
           });

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

$('#packing').combogrid({ 
	panelWidth:400,  	
	url: '<?=site_url('general/gridPacking'); ?>',  
	idField:'KODE_KEMASAN',  
	textField:'URAIAN_KEMASAN',  
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	columns:[[  
		{field:'KODE_KEMASAN',title:'Kode Kemasan',width:60},
		{field:'URAIAN_KEMASAN',title:'Uraian Kemasan',width:200}
	]],
});

$('#poqty').numberbox({  
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.',
});

$('#Dqty').numberbox({  
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.'
});

$('#Dqty2').numberbox({  
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.',
});

$('#Bqty').numberbox({  
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.'
});

$('#qty').numberbox({  
	min:-1000, 
	// max: $('#Bqty').numberbox('getValue'),
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.'
});

$('#qty').numberbox({  
	onChange:function(newValue,oldValue){
		poqty=$('#poqty').numberbox('getValue');
		qty= $('#qty').numberbox('getValue');
		Dqty2= $('#Dqty2').numberbox('getValue');
		Dqty= $('#Dqty').numberbox('getValue');
		Dqty2 = Dqty2 - 0;
		Dqty = newValue - 0 + (Dqty2-0);
		$('#Dqty').numberbox('setValue',Dqty);
		Bqty = poqty-Dqty;
		$('#Bqty').numberbox('setValue',Bqty);
		price=$('#price').numberbox('getValue');
		amount = newValue*price;
		$('#amount').numberbox('setValue',amount);
	}
});

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

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

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

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

$('#amount2').numberbox({  
    min:-10000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.',
});

$('#Bruto').textbox({  
});

$('#cif').textbox({  
});

$('#Netto').textbox({  
});


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();
});
$('#btnCeisa').click(function(){
	tambahCeisa();
});


$('#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');
});

$('#btnExcelCeisa').click(function(){
	excelCeisa();
});

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

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

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

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

$('#btnTransferCeisa').click(function(){
	transferCeisa();
});

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