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

$('#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'  
});
$('#matinsk_type').combobox({
	mode:'remote', 
	url:'<?=site_url('general/gridInTypeSk'); ?>',  
	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'  
});
$('#kurs').numberbox({  
    min:-1000, 
	precision:4, 
	groupSeparator:',',
	decimalSeparator:'.'
});
$('#HargaSerah').numberbox({  
    min:-1000, 
	precision:4, 
	groupSeparator:',',
	decimalSeparator:'.'
});
$('#po_no').combogrid({
	panelWidth:500,  	
	url: '<?=site_url('general/gridPO/')?>',  
	idField:'po_no',  
	textField:'po_no',  
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	multiple: true,
	columns:[[  
		{field:'po_no',title:'PO No.',width:150},
		{field:'po_date',title:'PO Date',width:50},
		{field:'NmPrshn',title:'Supplier',width:150}
	]],
	onClickRow:function(index,row){
		checkSupplier(row)
	}  
});
$('#scraf_no').combogrid({
	panelWidth:500,  	
	url: '<?=site_url('general/gridPOSc/')?>',  
	idField:'KdBarang',  
	textField:'KdBarang',  
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	columns:[[  
		{field:'KdBarang',title:'No Scrap.',width:60}
	]]
});
$('#po_nomc').combogrid({
	panelWidth:500,  	
	url: '<?=site_url('general/gridPOmc/')?>',  
	idField:'po_no',  
	textField:'po_no',  
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	columns:[[  
		{field:'po_no',title:'PO No.',width:150},
		{field:'po_date',title:'PO Date',width:50},
		{field:'NmPrshn',title:'Supplier',width:150}
	]],
	onClickRow:function(index,row){
		$('#po_id').val(row.po_id);
		$('#supplier').combobox('setValue',row.supplier);
		$('#currency').combobox('setValue',row.currency);
		$('#kurs').numberbox('setValue',row.kurs);
		$('#JmlBarang').textbox('setValue',row.jmlbrg);
	}  
});
$('#po_norms').combogrid({
	panelWidth:500,  	
	url: '<?=site_url('general/gridPOrms/')?>',  
	idField:'po_no',  
	textField:'po_no',  
	mode:'remote',  
	rownumbers:true,
	fitColumns:true,
	pagination:true,
	columns:[[  
		{field:'po_no',title:'PO No.',width:150},
		{field:'po_date',title:'PO Date',width:50},
		{field:'NmPrshn',title:'Supplier',width:150}
	]],
	onClickRow:function(index,row){
		$('#po_id').val(row.po_id);
		$('#supplier').combobox('setValue',row.supplier);
		$('#currency').combobox('setValue',row.currency);
		$('#kurs').numberbox('setValue',row.kurs);
		$('#JmlBarang').textbox('setValue',row.jmlbrg);
	}  
});
$('#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:'Process Code',width:60},
		{field:'nm_line',title:'Proses Name',width:100}
	]]
});
$('#KdInco').combogrid({
	panelWidth:400,
	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}
	]]
});
$('#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',
    onChange: function(newValue, oldValue) {
        $('#matin_type').combobox({
            mode: 'remote', 
            url: '<?=site_url('general/gridInType'); ?>/' + newValue,  
            valueField: 'matin_type',  
            textField: 'matin_name'  
        });

        $('#KdJnsDok2').combobox('setValue', newValue);

        fetchCorrespondingNo();
    }
});

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

		}
});


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




$('#seri_dok').combobox({  

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


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


$('#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:'PartNo',title:'Size',width:160},
		{field:'CF',title:'CF',width:40},
		{field:'NmBarang',title:'Item Description',width:60},
		{field:'Sat',title:'UOM',width:40}
	]],
	onClickRow:function(index,row){
		//console.log(row);
		insert_det(row)
	}  
}); 

$('#mat_idFGIN').combogrid({  
	panelWidth:500,  	
	url: '<?=site_url('general/gridBarangFGIN/')?>',  
	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:160},
		{field:'CF',title:'CF',width:40},
		{field:'NmBarang',title:'Item Description',width:60},
		{field:'Sat',title:'UOM',width:40}
	]],
	onClickRow:function(index,row){
		//console.log(row);
		insert_det(row)
	}  
}); 

$('#mat_idFGINP').combogrid({  
	panelWidth:500,  	
	url: '<?=site_url('general/gridBarangFGINP/')?>',  
	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:160},
		{field:'CF',title:'CF',width:40},
		{field:'NmBarang',title:'Item Description',width:60},
		{field:'Sat',title:'UOM',width:40}
	]],
	onClickRow:function(index,row){
		//console.log(row);
		insert_det(row)
	}  
}); 

$('#mat_idFGIN_NP').combogrid({  
	panelWidth:500,  	
	url: '<?=site_url('general/gridBarangFGIN_NP/')?>',  
	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:160},
		{field:'CF',title:'CF',width:40},
		{field:'NmBarang',title:'Item Description',width:60},
		{field:'Sat',title:'UOM',width:40}
	]],
	onClickRow:function(index,row){
		//console.log(row);
		insert_det(row)
	}  
}); 
$('#mat_ids').combogrid({  
	panelWidth:500,  	
	url: '<?=site_url('general/gridBarangScrap/')?>',  
	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:160},
		{field:'CF',title:'CF',width:40},
		{field:'NmBarang',title:'Item Description',width:60},
		{field:'Sat',title:'UOM',width:40}
	]],
	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   
});
$('#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:'.'
});
$('#ng_qty').numberbox({  
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.'
});
$('#tot_qty').numberbox({  
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.'
});
$('#tot_amount').numberbox({  
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.'
});
$('#Dqty2').numberbox({  
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.',
});
$('#Bqty').numberbox({  
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.'
});
// Bqty=$('#Bqty').numberbox('getValue');
// $('#qty').numberbox('options').max = 1000;
$('#qty').numberbox({  
	min:-1000, 
	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:'.',
});
$('#poqty2').numberbox({  
	hidden: true,
	min:-1000, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.',
});
$('#Dqty3').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);
		$('#poqty2').numberbox('setValue',qty2);
		$('#Dqty3').numberbox('setValue',qty2);
	}
});
$('#price2').numberbox({  
    min:-1000, 
	precision:4, 
	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, #Netto').numberbox({  
    min:0, 
	precision:2, 
	groupSeparator:',',
	decimalSeparator:'.',
});
$('#Bruto').textbox({  
});
$('#cif').textbox({  
});
$('#Netto').textbox({  
});
setDgHdr();
setDgDet();
setDgDetDok();
setDgDetJaminan();
setDgDetKon();
$('#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();
	
});

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

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

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

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

});

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

});


// $('#btnTbh').click(function(){
// 	$.messager.progress({
//         title: 'Processing',   // Title of the loading dialog
//         msg: 'Please wait...', // Message displayed in the loading dialog
//     });
	
//     $.ajax({
//         url: 'https://'+window.location.hostname+':8080/processCSVInOut',
//         type: 'GET',  // Assuming it's a GET request, you can change it to POST if needed
//         success: function() {
// 			$('#dg_hdr').datagrid('reload');
//            Alert('Cron job triggered successfully:');

//             // You can add further actions after the cron job is triggered if needed
//         },
//         error: function(xhr, status, error) {
// 			$.messager.progress('close');
// 			$('#dg_hdr').datagrid('reload');
//         }
//     });
// });


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

$('#btnReset4').click(function(){
	$('#fm4').form('clear');
});
/*Button2 Event*/
$('#btnTbh2').click(function(){
	tambah2();
});
$('#btnCeisa').click(function(){
	tambahCeisa();
});

$('#btnUpload').click(function(){
	upload();
});

$('#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_in === "yes"){
		rst2();
	}else{
		spr2();
	}
});
$('#btnRst2All').click(function(){	
	rst2All();
});
$('#btnSpr2All').click(function(){	
	spr2All();
});
$('#btnLock2').click(function(){	
	lock2();
});
$('#btnHps2').click(function(){
	hapus2();
});

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

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

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

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

$('#btnDaftarCeisa').click(function(){
	daftarCeisa();
});

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