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

$('#tbdetail').tabs({
	width:'100%',	
	height:theight,
	fit:true,
	border:false,
	plain:true,
	onSelect:function(title,index){
		if(index==0){
			setDgDet();
		}else if(index == 1){
			setDgDetKon();
		}else if(index== 2){
			setDgDetDok();
		}else if(index== 3){
			setDgDetJaminan();
		}
	}
});
// Journal Debit FG Out --ir
$('#accountd_id').combogrid({ 
	panelWidth:500,  	
	url: '<?=site_url('general/gridOutFgJournalD'); ?>',  
	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);
	}
});
// Journal Credit FG Out --ir
$('#accountc_id').combogrid({ 
	panelWidth:500,  	
	url: '<?=site_url('general/gridOutFgJournalC'); ?>',  
	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);
	}
});
// Journal Debit Mat Out --ir
$('#accountd_id2').combogrid({ 
	panelWidth:500,  	
	url: '<?=site_url('general/gridOutMatJournalD'); ?>',  
	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);
	}
});
// Journal Credit Mat Out --ir
$('#accountc_id2').combogrid({ 
	panelWidth:500,  	
	url: '<?=site_url('general/gridOutMatJournalC'); ?>',  
	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);
	}
});
$('#tb').tabs({
	width:'100%',	
	height:theight,
	fit:true,
	border:false,
	plain:true,
	onSelect:function(title,index){
		if(index==1){
			setDgHdrDet();
		}
	}
});
$('#matout_type').combobox({
	mode:'remote', 
	url:'<?=site_url('general/gridOutType'); ?>',  
	valueField:'matout_type',  
	textField:'matout_name'  
});
$('#npo_id').textbox({
	panelWidth:250
});
$('#proses').combogrid({
	panelWidth:400,
	mode:'remote', 
	url: '<?=site_url('general/gridLine')?>',  
	idField:'ket',
	valueField:'ket',  
	textField:'ket',
	fitColumns: true,
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	columns:[[  
		{field:'ket',title:'WIP Type',width:60},
		{field:'nm_line',title:'Proses WIP',width:60}
	]]
});
$('#cust').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'  
});
$('#kurs').numberbox({  
    min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.'
});
$('#HargaSerah').numberbox({  
    min:-1000, 
	precision:4, 
	groupSeparator:',',
	decimalSeparator:'.'
});
$('#KdInco').combogrid({
	panelWidth:250,
	mode:'remote', 
	url: '<?=site_url('general/gridInco')?>',  
	idField:'KdInco',
	valueField:'KdInco',  
	textField:'Incomterm',
	fitColumns: true,
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	columns:[[  
		{field:'Incomterm',title:'Incoterm',width:100}
	]]
});
$('#ref_no').combogrid({
	panelWidth:650,  
	url: '<?=site_url('general/gridPO')?>',  
	idField:'po_no',  
	textField:'po_no',  
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	columns:[[  
		{field:'po_no',title:'REF No.',width:200},
		{field:'po_date',title:'REF Date',width:50},
		{field:'NmPrshn',title:'Costumer',width:150}
	]],
	onClickRow:function(index,row){
		checkSupplier(row)
	}
});
$('#cust').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);
	},
});


$('#KdJnsDok2').combobox({  
	width:100,
	mode:'remote', 
	url:'<?=site_url('general/gridJnsDokOut'); ?>',  
	valueField:'KdJnsDok',  
	textField:'UrJnsDok'  
});
$('#KdJnsDok').combobox({  
	width:100,
	mode:'remote', 
	url:'<?=site_url('general/gridJnsDokOut'); ?>',  
	valueField:'KdJnsDok',  
	textField:'UrJnsDok',
		onChange:function(newValue,oldValue){
			$('#matout_type').combobox({
	mode:'remote', 
	url:'<?=site_url('general/gridOutType'); ?>/' + newValue,   
	valueField:'matout_type',  
	textField:'matout_name'  
});
        fetchCorrespondingNo();

		},  onSelect: function(record) {
      updateFieldAccess(record.value);
    }
});

$('#Bruto, #Netto').numberbox({  
    min:0, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.',
});
$('#mat_id').combogrid({  
	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 Desc',width:60},
		{field:'Sat',title:'UOM',width:50}
	]],
	onClickRow:function(index,row){
		//console.log(row);
		insert_det(row)
	}  
});


$('#mat_ids').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:'PartNo',title:'Size',width:150},
		{field:'CF',title:'CF',width:50},
		{field:'NmBarang',title:'Item Desc',width:60},
		{field:'Sat',title:'UOM',width:50}
	]],
	onClickRow:function(index,row){
		//console.log(row);
		insert_det(row)
	}  
});
$('#mat_idng').combogrid({  
	width:150,
	panelWidth:500,  	
	url: '<?=site_url('general/gridBarangNGOUT')?>',
	idField:'KdBarang',
	textField:'KdBarang',  
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	columns:[[  
		{field:'KdBarang',title:'Item Code',width:60},
		{field:'PartNo',title:'Size',width:150},
		{field:'CF',title:'CF',width:50},
		{field:'NmBarang',title:'Item Desc',width:60},
		{field:'Sat',title:'UOM',width:50}
	]],
	onClickRow:function(index,row){
		//console.log(row);
		insert_det(row)
	}  
});
$('#mat_idngmat').combogrid({  
	width:150,
	panelWidth:500,  	
	url: '<?=site_url('general/gridBarangNGOUTMAT')?>',
	idField:'KdBarang',
	textField:'KdBarang',  
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	columns:[[  
		{field:'KdBarang',title:'Item Code',width:60},
		{field:'PartNo',title:'Size',width:150},
		{field:'CF',title:'CF',width:50},
		{field:'NmBarang',title:'Item Desc',width:60},
		{field:'Sat',title:'UOM',width:50}
	]],
	onClickRow:function(index,row){
		//console.log(row);
		insert_det(row)
	}  
});

$('#scrap_id').combogrid({  
	panelWidth:500,  	
	url: '<?=site_url('general/gridBarangScrap/'.$this->tp_barang)?>',  
	idField:'NmBarang',  
	textField:'NmBarang',  
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	columns:[[  
		{field:'KdBarang',title:'Item Code',width:60},
		{field:'NmBarang',title:'Item Description',width:100},
		{field:'Sat',title:'UOM',width:50}
	]],  
});

$('#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}
	]],
});
$('#Sat').combobox({  
	mode:'remote', 
	url:'<?=site_url('uom/gridAll'); ?>',  
	valueField:'KdSat',  
	textField:'KdSat',
	pagination:true   
});
$('#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:'.'
});
$('#ng_qty').numberbox({  
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.'
});
$('#ng_qty2').numberbox({  
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.'
});
$('#tot_qty').numberbox({  
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.'
});
$('#qty').numberbox({  
	min:-1000, 
	// max: $('#Bqty').numberbox('getValue'),
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.'
});
$('#adj_qty').numberbox({  
    min:-10000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.',
});
$('#adj_ref').textbox({  
});
$('#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:4, 
	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:'.',
});
$('#poqty22').numberbox({  
	hidden: true,
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.',
});
$('#Dqty33').numberbox({  
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.'
});
$("#tdpoqty2").hide()
$('#qty2').numberbox({ 
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.', 
	onChange:function(newValue,oldValue){
		price=$('#price2').numberbox('getValue');
		qty2=$('#qty2').numberbox('getValue');
		amount = newValue*price;
		$('#amount2').numberbox('setValue',amount);
		$('#poqty22').numberbox('setValue',qty2);
		$('#Dqty33').numberbox('setValue',qty2);
	}
});
$('#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({  
});

$('#kodePelabuhanTujuan').textbox({  
	onChange:function(){
		var bongkar = $('#kodePelabuhanTujuan').textbox('getValue');
		$('#kodePelabuhanBongkar').textbox('setValue',bongkar);
		$('#kodePelabuhanMuat').textbox('setValue',"IDTPP");
		$('#kodePelabuhanEkspor').textbox('setValue',"IDTPP");

	}
});

$('#cif').textbox({  
});
$('#Netto').textbox({  
});
$('#po_dispacth').textbox({  
});
$('#po_discharge').textbox({  
});
$('#fo_destination').textbox({  
});
$('#fdr_name').textbox({  
});
$('#insured').textbox({  
});
$('#shipping').textbox({  
});
$('#vpd').textbox({  
});
$('#NmBarang').textbox({  
  rowStyler:function(index,row){
  	return 'background-color:pink;color:blue;font-weight:bold;';
  }
});
setDgHdr();
setDgDet();
setDgDetJaminan();
setDgDetKon();
setDgDetDok();
$('#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*/
$('#btnTbh').click(function(){
	tambah();
});

$('#btnCeisa').click(function(){
	tambahCeisa();
});

$('#btnEdit_jaminan').click(function(){
	ubahJaminan();

});

$('#btnTbh_jaminan').click(function(){
	tambahJaminan();

});


$('#btnSim2jaminan').click(function(){
	simpan2jaminan();
});

$('#btnDlt_jaminan').click(function(){
	hapus2jaminan();
});

$('#btnUpload').click(function(){
	upload();
});
$('#btnUbh').click(function(){
	ubah();
});
$('#btnHps').click(function(){
	hapus();
});
$('#btnSim').click(function(){
	simpan();
});
$('#btnPrintBc').click(function(){
	printSlip();
});
$('#btnPrintinv').click(function(){
	printSlip2();
});
$('#btnPrintpack').click(function(){
	printSlip3();
});
$('#btnPrint2').click(function(){
	aksi('print');
});
$('#btnExcel').click(function(){
	aksi('xls');
});
$('#btnExcelCeisa').click(function(){
	excelCeisa();
});
$('#btnSubmit').click(function(){
	simpan();
});
$('#btnReset').click(function(){
	$('#fm').form('clear');
});
/*Button2 Event*/
$('#btnTbh2').click(function(){
	tambah2();
});
$('#btnUbh2').click(function(){	
	ubah2();
});
$('#btnAdj').click(function(){	
	saveAdj();
});
$('#btnUbh3').click(function(){	
	ubah3();
});
$('#btnResetQty2').click(function(){		
	reset2();
});
$('#btnRst2').click(function(){	
	rst2();
});
$('#btnSpr2').click(function(){	
	var row = $('#dg_det').datagrid('getSelected');
	if(row.all_out === "yes"){
		rst2();
	}else{
		spr2();
	}
});
$('#btnRst2All').click(function(){	
	rst2All();
});
$('#btnSpr2All').click(function(){	
	spr2All();
});
$('#btnLock2').click(function(){	
	lock2();
});
$('#btnHps2').click(function(){
	hapus2();
});

$('#btnTbh_kon').click(function(){
	tambahKon();
	
});
$('#btnEdit_kon').click(function(){
	ubahKon();
	
});


$('#KODE_JENIS_KONTAINER').combobox({  

mode:'remote', 
url:'<?=site_url('general/gridJenisKon'); ?>',  
valueField:'KODE_JENIS_KONTAINER',  
textField:'NAMA_JENIS_KONTAINER'  
});
$('#KODE_TIPE_KONTAINER').combobox({  

mode:'remote', 
url:'<?=site_url('general/gridTipeKon'); ?>',  
valueField:'kode_tipe_kontainer',  
textField:'nama_tipe_kontainer'  
});
$('#KODE_UKURAN_KONTAINER').combobox({  

mode:'remote', 
url:'<?=site_url('general/gridUkuranKon'); ?>',  
valueField:'kode_ukuran_kontainer',  
textField:'nama_ukuran_kontainer'  
});



$('#btnEdit_dok').click(function(){
	ubahDok();
	
});

$('#seri_dok').combobox({  

mode:'remote', 
url:'<?=site_url('general/gridDok'); ?>',  
valueField:'KdKdJnsDok',  
textField:'UrKdJnsDok'  
});

$('#kodeKantorBongkar').combobox({  

mode:'remote', 
url:'<?=site_url('general/gridKantor'); ?>',  
valueField:'kodeKantor',  
textField:'namaKantor'  
});



$('#kodeKantor').combobox({  

mode:'remote', 
url:'<?=site_url('general/gridKantor'); ?>',  
valueField:'kodeKantor',  
textField:'namaKantor'  
});



$('#kodeKantorTujuan').combobox({  

mode:'remote', 
url:'<?=site_url('general/gridKantor'); ?>',  
valueField:'kodeKantor',  
textField:'namaKantor'  
});



$('#kodekantorExpor').combobox({  

mode:'remote', 
url:'<?=site_url('general/gridKantor'); ?>',  
valueField:'kodeKantor',  
textField:'namaKantor'  
});



$('#kodeKantorPeriksa').combobox({  

mode:'remote', 
url:'<?=site_url('general/gridKantor'); ?>',  
valueField:'kodeKantor',  
textField:'namaKantor'  
});


$('#bendera').combobox({  

mode:'remote', 
url:'<?=site_url('general/gridbendera'); ?>',  
valueField:'kodeNegara',  
textField:'namaNegara'  
});


$('#negaraTujuan').combobox({  

mode:'remote', 
url:'<?=site_url('general/gridbendera'); ?>',  
valueField:'kodeNegara',  
textField:'namaNegara'  
});





$('#btnSim2kon').click(function(){
	simpan2kon();
});
$('#btnSim2dok').click(function(){
	simpan2dok();
});

$('#btnTbh_dok').click(function(){
	tambahDok();
	
});

$('#btnDlt_kon').click(function(){
	hapus2kon();
});

$('#btnDlt_dok').click(function(){
	hapus2dok();
});




$('#btnSim2').click(function(){
	simpan2();
});
$('#btnSubmit2').click(function(){
	simpan2();
});
$('#btnReset2').click(function(){
	$('#fm2').form('clear');
});
$('#btnJournal').click(function(){
	createJournal();
});
$('#btnTransferCeisa').click(function(){
	transferCeisa();
});
});//Akhir Document Ready
</script>