<?php 
class CT_produksi_save extends CI_Controller{
	function __construct()
	{
	  parent::__construct();
		if (!$this->dx_auth->is_logged_in()) {
			header('HTTP/1.1 401 Unauthorize');die('expire'); 
		}
		
		$uid = $this->session->userdata('DX_user_id');
		
		if(!permissionAuth(2) && $uid != RID){ 
			header('HTTP/1.1 401 Unauthorize');die('noaccess');
		} 
	} 
	function index(){	 
				$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:'-1';   
				$cust_code = isset($_POST['cust_code'])?$_POST['cust_code']:'';  //1 add
				$id_header = isset($_POST['id_header'])?$_POST['id_header']:'-1';   
				$data['cust_code'] = $cust_code;
				$data['id_header'] = $id_header;
				$data['bc_prefix'] = $bc_prefix;
				
				$data['use_kurs'] = '0';
				if ($bc_prefix=='27')
					$data['use_kurs'] = '1';
			
				$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:'-1';   
			 	$xmldoc =  XMLbasic('json'); 
				AddField($xmldoc ,'bc_prefix',$bc_prefix); 
				$str = $xmldoc->saveXML();  
			    exec_sp_array($xmldoc, 'dbo.GET_SETTING_DEFAULT_CEISA',$sts,$des,$rows,$detail);   
		 		if ($sts=='00'){
					$data['KURS'] = $detail['KURS'];
					$data['VALID_KURS'] = $detail['VALID_KURS'];
					$data['KURS_DATE'] = $detail['KURS_DATE']; 
				}
				else
				{
					$data['KURS'] =1;  
					$data['VALID_KURS'] =0; 
					$data['KURS_DATE'] =''; 
				}
		
				$this->load->view('pasi_ceisa_invoice/view_invoice_beli_import', $data);
	}   
	

	function save_proses_produksi_new(){ 
	   $operator = isset($_POST['OPERATOR'])?$_POST['OPERATOR']:die('pilih penyusun Dokument');; // get the requested page 
	   $tanggal_produksi = isset($_POST['TANGGAL_PROCESS'])?$_POST['TANGGAL_PROCESS']:die('pilih penyusun Dokument');; // get the requested page 
	   $posisi_proses = isset($_POST['posisi_proses'])?$_POST['posisi_proses']:die('pilih penyusun Dokument');; // get the requested page 
	
	
	   $xmldoc =  XMLbasic('json'); 
		
		AddField($xmldoc ,'operator',$operator);
		AddField($xmldoc ,'posisi_proses',$posisi_proses);
		AddField($xmldoc ,'tanggal_produksi',$tanggal_produksi);
		AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));
	//	for ($i = 0; $i <  count($lstsa); $i++) {
	//		$this->_insert_sa_to_field($xmldoc,$lstsa);
	//	} 
	   $str = $xmldoc->saveXML();  
	   //  print_r($str);die();
		exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_NEW_ADD',$sts,$des,$rows,$detail); 
	   echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
	}
	

	function save_proses_produksi_rdd(){ 
		$replace_if_exists = isset($_POST['replace_if_exists'])?$_POST['replace_if_exists']:die('Type BC tidak di ketahui');; // get the requested page 
		$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih penyusun Dokument');; // get the requested page 
	 

		$xmldoc =  XMLbasic('json'); 
		 AddField($xmldoc ,'replace_if_exists',$replace_if_exists);
		 AddField($xmldoc ,'id_header',$id_header);
		 
		 AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));
	//	for ($i = 0; $i <  count($lstsa); $i++) {
	//		$this->_insert_sa_to_field($xmldoc,$lstsa);
	//	} 
		$str = $xmldoc->saveXML();  
		 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_RDD_ADD',$sts,$des,$rows,$detail); 
		echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
	}

	function save_proses_produksi_rdd2(){ 
 		$operator = isset($_POST['OPERATOR'])?$_POST['OPERATOR']:die('pilih penyusun Dokument');; // get the requested page 
		$tanggal_produksi = isset($_POST['TANGGAL_PROCESS'])?$_POST['TANGGAL_PROCESS']:die('pilih penyusun Dokument');; // get the requested page 
	 

		$xmldoc =  XMLbasic('json'); 
		 
		 AddField($xmldoc ,'operator',$operator);
		 AddField($xmldoc ,'tanggal_produksi',$tanggal_produksi);
		 AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));
	//	for ($i = 0; $i <  count($lstsa); $i++) {
	//		$this->_insert_sa_to_field($xmldoc,$lstsa);
	//	} 
		$str = $xmldoc->saveXML();  
		//  print_r($str);die();
		 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_RDD_ADD2',$sts,$des,$rows,$detail); 
		echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
	}

	function save_proses_produksi_mdd(){ 
		$operator = isset($_POST['OPERATOR'])?$_POST['OPERATOR']:die('pilih penyusun Dokument');; // get the requested page 
	   $tanggal_produksi = isset($_POST['TANGGAL_PROCESS'])?$_POST['TANGGAL_PROCESS']:die('pilih penyusun Dokument');; // get the requested page 
	

	   $xmldoc =  XMLbasic('json'); 
		
		AddField($xmldoc ,'operator',$operator);
		AddField($xmldoc ,'tanggal_produksi',$tanggal_produksi);
		AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));
   //	for ($i = 0; $i <  count($lstsa); $i++) {
   //		$this->_insert_sa_to_field($xmldoc,$lstsa);
   //	} 
	   $str = $xmldoc->saveXML();  
	   //  print_r($str);die();
		exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_MDD_ADD',$sts,$des,$rows,$detail); 
	   echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
   }


   function save_proses_produksi_mld(){ 
	$operator = isset($_POST['OPERATOR'])?$_POST['OPERATOR']:die('pilih penyusun Dokument');; // get the requested page 
   $tanggal_produksi = isset($_POST['TANGGAL_PROCESS'])?$_POST['TANGGAL_PROCESS']:die('pilih penyusun Dokument');; // get the requested page 


   $xmldoc =  XMLbasic('json'); 
	
	AddField($xmldoc ,'operator',$operator);
	AddField($xmldoc ,'tanggal_produksi',$tanggal_produksi);
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));
//	for ($i = 0; $i <  count($lstsa); $i++) {
//		$this->_insert_sa_to_field($xmldoc,$lstsa);
//	} 
   $str = $xmldoc->saveXML();  
   //  print_r($str);die();
	exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_MLD_ADD',$sts,$des,$rows,$detail); 
   echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}

function save_proses_produksi_dbc(){ 
	$operator = isset($_POST['OPERATOR'])?$_POST['OPERATOR']:die('pilih penyusun Dokument');; // get the requested page 
   $tanggal_produksi = isset($_POST['TANGGAL_PROCESS'])?$_POST['TANGGAL_PROCESS']:die('pilih penyusun Dokument');; // get the requested page 


   $xmldoc =  XMLbasic('json'); 
	
	AddField($xmldoc ,'operator',$operator);
	AddField($xmldoc ,'tanggal_produksi',$tanggal_produksi);
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));
//	for ($i = 0; $i <  count($lstsa); $i++) {
//		$this->_insert_sa_to_field($xmldoc,$lstsa);
//	} 
   $str = $xmldoc->saveXML();  
   //  print_r($str);die();
	exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_DBC_ADD',$sts,$des,$rows,$detail); 
   echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}

function save_proses_produksi_sbc(){ 
	$operator = isset($_POST['OPERATOR'])?$_POST['OPERATOR']:die('pilih penyusun Dokument');; // get the requested page 
   $tanggal_produksi = isset($_POST['TANGGAL_PROCESS'])?$_POST['TANGGAL_PROCESS']:die('pilih penyusun Dokument');; // get the requested page 


   $xmldoc =  XMLbasic('json'); 
	
	AddField($xmldoc ,'operator',$operator);
	AddField($xmldoc ,'tanggal_produksi',$tanggal_produksi);
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));
//	for ($i = 0; $i <  count($lstsa); $i++) {
//		$this->_insert_sa_to_field($xmldoc,$lstsa);
//	} 
   $str = $xmldoc->saveXML();  
   //  print_r($str);die();
	exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_SBC_ADD',$sts,$des,$rows,$detail); 
   echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}

function save_proses_produksi_ext(){ 
	$operator = isset($_POST['OPERATOR'])?$_POST['OPERATOR']:die('pilih penyusun Dokument');; // get the requested page 
   $tanggal_produksi = isset($_POST['TANGGAL_PROCESS'])?$_POST['TANGGAL_PROCESS']:die('pilih penyusun Dokument');; // get the requested page 


   $xmldoc =  XMLbasic('json'); 
	
	AddField($xmldoc ,'operator',$operator);
	AddField($xmldoc ,'tanggal_produksi',$tanggal_produksi);
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));
//	for ($i = 0; $i <  count($lstsa); $i++) {
//		$this->_insert_sa_to_field($xmldoc,$lstsa);
//	} 
   $str = $xmldoc->saveXML();  
   //  print_r($str);die();
	exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_EXT_ADD',$sts,$des,$rows,$detail); 
   echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function save_proses_produksi_wire(){ 
	$operator = isset($_POST['OPERATOR'])?$_POST['OPERATOR']:die('pilih penyusun Dokument');; // get the requested page 
   $tanggal_produksi = isset($_POST['TANGGAL_PROCESS'])?$_POST['TANGGAL_PROCESS']:die('pilih penyusun Dokument');; // get the requested page 


   $xmldoc =  XMLbasic('json'); 
	
	AddField($xmldoc ,'operator',$operator);
	AddField($xmldoc ,'tanggal_produksi',$tanggal_produksi);
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));
//	for ($i = 0; $i <  count($lstsa); $i++) {
//		$this->_insert_sa_to_field($xmldoc,$lstsa);
//	} 
   $str = $xmldoc->saveXML();  
   //  print_r($str);die();
	exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_WIRE_ADD',$sts,$des,$rows,$detail); 
   echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}

	function save_proses_produksi_tube(){ 
		$replace_if_exists = isset($_POST['replace_if_exists'])?$_POST['replace_if_exists']:die('Type BC tidak di ketahui');; // get the requested page 
		$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih penyusun Dokument');; // get the requested page 
	 

		$xmldoc =  XMLbasic('json'); 
		 AddField($xmldoc ,'replace_if_exists',$replace_if_exists);
		 AddField($xmldoc ,'id_header',$id_header);
		 
		 AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));
	//	for ($i = 0; $i <  count($lstsa); $i++) {
	//		$this->_insert_sa_to_field($xmldoc,$lstsa);
	//	} 
		$str = $xmldoc->saveXML();  
		 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_TUBE_ADD',$sts,$des,$rows,$detail); 
		echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
	}

	function save_proses_produksi_all(){
		$replace_if_exists = isset($_POST['replace_if_exists'])?$_POST['replace_if_exists']:die('Type BC tidak di ketahui');; // get the requested page 
		$id_header = isset($_POST['id_header'])?$_POST['id_header']:'';; // get the requested page 
		$posisi = isset($_POST['posisi'])?$_POST['posisi']:'';; // get the requested page 
		$id_bom = isset($_POST['id_bom'])?$_POST['id_bom']:'';; // get the requested page 
	 

		$xmldoc =  XMLbasic('json'); 
		 AddField($xmldoc ,'replace_if_exists',$replace_if_exists);
		 AddField($xmldoc ,'id_header',$id_header);
		 AddField($xmldoc ,'id_bom',$id_bom);
		 AddField($xmldoc ,'posisi', $posisi);
		 AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));
	//	for ($i = 0; $i <  count($lstsa); $i++) {
	//		$this->_insert_sa_to_field($xmldoc,$lstsa);
	//	} 
		$str = $xmldoc->saveXML();  
		 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_ALL_ADD',$sts,$des,$rows,$detail); 
		echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
	}



function save_barang_in_bc27(){
	$bc_prefix = "BC27"; // isset($_POST['bc_prefix'])?$_POST['bc_prefix']:die('Type BC tidak di ketahui');; // get the requested page 
	$replace_if_exists = isset($_POST['replace_if_exists'])?$_POST['replace_if_exists']:die('Type BC tidak di ketahui');; // get the requested page 
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');; // get the requested page 

	$xmldoc =  XMLbasic('json'); 
	 AddField($xmldoc ,'bc_prefix',$bc_prefix);
	 AddField($xmldoc ,'replace_if_exists',$replace_if_exists);
	 
	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 
	$str = $xmldoc->saveXML();  
	 exec_sp_array($xmldoc, 'dbo.SPX_GUDANG_IN_BC27_ADD',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}

function save_barang_in_bc40(){
	$bc_prefix = "BC40"; // isset($_POST['bc_prefix'])?$_POST['bc_prefix']:die('Type BC tidak di ketahui');; // get the requested page 
	$replace_if_exists = isset($_POST['replace_if_exists'])?$_POST['replace_if_exists']:die('Type BC tidak di ketahui');; // get the requested page 
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');; // get the requested page 

	$xmldoc =  XMLbasic('json'); 
	 AddField($xmldoc ,'bc_prefix',$bc_prefix);
	 AddField($xmldoc ,'replace_if_exists',$replace_if_exists);
	 
	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 
	$str = $xmldoc->saveXML();  
	 exec_sp_array($xmldoc, 'dbo.SPX_GUDANG_IN_BC40_ADD',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}





	function edit_qty_bom(){ 
		$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen yang akan di cancel');; // get the requested page 
		$jumlah_qty = isset($_POST['jumlah_qty'])?$_POST['jumlah_qty']:''; // get the requested page 
		$keterangan = isset($_POST['keterangan'])?$_POST['keterangan']:''; // get the requested page 
		$xmldoc =  XMLbasic('json'); 
		AddField($xmldoc ,'id_header',$id_header);
		AddField($xmldoc ,'jumlah_qty',$jumlah_qty );
		AddField($xmldoc ,'keterangan',$keterangan );

		$str = $xmldoc->saveXML();
		 // print_r($str);die();
		 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_QTY_BOM',$sts,$des,$rows,$detail); 
		echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}

function save_pilih_mesin(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen yang akan di cancel');; // get the requested page 
	$kode_mesin = isset($_POST['kode_mesin'])?$_POST['kode_mesin']:''; // get the requested page 
	$nama_mesin = isset($_POST['nama_mesin'])?$_POST['nama_mesin']:''; // get the requested page 
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'kode_mesin',$kode_mesin );
	AddField($xmldoc ,'nama_mesin',$nama_mesin );

	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_RDD_MACHINE_EDIT',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}

function edit_qty_material(){ 
	$id_detail = isset($_POST['id_detail'])?$_POST['id_detail']:die('pilih dokumen dahulu');; // get the requested page 
	$qty_actual = isset($_POST['qty_actual'])?$_POST['qty_actual']:''; // get the requested page 

	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_detail',$id_detail);
	AddField($xmldoc ,'qty_actual',$qty_actual );
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_QTY_BOM',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}

function edit_qty_output(){ 
	$id_detail = isset($_POST['id_detail'])?$_POST['id_detail']:die('pilih dokumen dahulu');; // get the requested page 
	$qty_actual = isset($_POST['qty_actual'])?$_POST['qty_actual']:''; // get the requested page 
	$satuan = isset($_POST['satuan'])?$_POST['satuan']:''; // get the requested page 
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_detail',$id_detail);
	AddField($xmldoc ,'qty_actual',$qty_actual );
	AddField($xmldoc ,'satuan',$satuan );
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_RDD_QTY_OUTPUT',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function request_material_to_gudang(){ 
	$id_detail = isset($_POST['id_detail'])?$_POST['id_detail']:die('pilih dokumen dahulu');; // get the requested page 
	$qty_request = isset($_POST['qty_request'])?$_POST['qty_request']:''; // get the requested page 
	$satuan = isset($_POST['satuan'])?$_POST['satuan']:''; // get the requested page 
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_detail',$id_detail);
	AddField($xmldoc ,'qty_request',$qty_request );
	AddField($xmldoc ,'satuan',$satuan );
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));
	AddField($xmldoc,'modetrx','material');
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_REQUEST_MATERIAL_TO_GUDANG',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}
  

function finish_mdd_to_dbc(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');
	$noproduksi = isset($_POST['noproduksi'])?$_POST['noproduksi']:''; // get the requested page 
//	$satuan = isset($_POST['satuan'])?$_POST['satuan']:''; // get the requested page 
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'noproduksi',$noproduksi );
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));
	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_MDD_FINISH_TO_DBC',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function finish_mdd_to_output(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');
	$noproduksi = isset($_POST['noproduksi'])?$_POST['noproduksi']:''; // get the requested page 
//	$satuan = isset($_POST['satuan'])?$_POST['satuan']:''; // get the requested page 
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'noproduksi',$noproduksi );
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));
	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_MDD_FINISH_TO_OUTPUT',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function finish_produksi_to_output(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');
	$noproduksi = isset($_POST['noproduksi'])?$_POST['noproduksi']:''; // get the requested page 
//	$satuan = isset($_POST['satuan'])?$_POST['satuan']:''; // get the requested page 
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'noproduksi',$noproduksi );
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));
	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_FINISH_TO_OUTPUT',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function finish_produksi_to_output_mld(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');
	$noproduksi = isset($_POST['noproduksi'])?$_POST['noproduksi']:''; // get the requested page 
//	$satuan = isset($_POST['satuan'])?$_POST['satuan']:''; // get the requested page 
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'noproduksi',$noproduksi );
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));
	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_FINISH_TO_OUTPUT_MLD',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function finish_rdd_to_mdd(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');
	$noproduksi = isset($_POST['noproduksi'])?$_POST['noproduksi']:die('pilih penyusun Dokument');

	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'noproduksi',$noproduksi);
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_RDD_FINISH_TO_MDD',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function finish_rdd_to_output(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');
	$noproduksi = isset($_POST['noproduksi'])?$_POST['noproduksi']:die('pilih penyusun Dokument');

	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'noproduksi',$noproduksi);
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_RDD_FINISH_TO_OUTPUT',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}

function finish_rdd_to_mld(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');
	$noproduksi = isset($_POST['noproduksi'])?$_POST['noproduksi']:die('pilih penyusun Dokument');
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'noproduksi',$noproduksi);
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 

	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_RDD_FINISH_TO_MLD',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function finish_dbc_to_ext(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');
	$noproduksi = isset($_POST['noproduksi'])?$_POST['noproduksi']:die('pilih penyusun Dokument');
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'noproduksi',$noproduksi);
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_DBC_FINISH_TO_EXT',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function finish_dbc_to_output(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');
	$noproduksi = isset($_POST['noproduksi'])?$_POST['noproduksi']:die('pilih penyusun Dokument');
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'noproduksi',$noproduksi);
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_DBC_FINISH_TO_OUTPUT',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function finish_mld_to_sbc(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');
	$noproduksi = isset($_POST['noproduksi'])?$_POST['noproduksi']:die('pilih penyusun Dokument');

	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'noproduksi',$noproduksi);
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_MLD_FINISH_TO_SBC',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function finish_mld_to_output(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');
	$noproduksi = isset($_POST['noproduksi'])?$_POST['noproduksi']:die('pilih penyusun Dokument');

	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'noproduksi',$noproduksi);
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_MLD_FINISH_TO_OUTPUT',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function finish_sbc_to_ext(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');
	$noproduksi = isset($_POST['noproduksi'])?$_POST['noproduksi']:die('pilih penyusun Dokument');
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'noproduksi',$noproduksi);
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_SBC_FINISH_TO_EXT',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function finish_sbc_to_output(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');
	$noproduksi = isset($_POST['noproduksi'])?$_POST['noproduksi']:die('pilih penyusun Dokument');
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'noproduksi',$noproduksi);
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_SBC_FINISH_TO_OUTPUT',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}

function finish_ext_to_wire(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$qty_akhir = isset($_POST['qty_akhir'])?$_POST['qty_akhir']:''; // get the requested page 
	$satuan = isset($_POST['satuan'])?$_POST['satuan']:''; // get the requested page 
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'qty_akhir',$qty_akhir );
	AddField($xmldoc ,'satuan',$satuan );
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_EXT_FINISH_TO_WIRE',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function finish_ext_to_output(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$qty_akhir = isset($_POST['qty_akhir'])?$_POST['qty_akhir']:''; // get the requested page 
	$satuan = isset($_POST['satuan'])?$_POST['satuan']:''; // get the requested page 
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'qty_akhir',$qty_akhir );
	AddField($xmldoc ,'satuan',$satuan );
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_EXT_FINISH_TO_OUTPUT',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function finish_ext_to_good(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$qty_akhir = isset($_POST['qty_akhir'])?$_POST['qty_akhir']:''; // get the requested page 
	$satuan = isset($_POST['satuan'])?$_POST['satuan']:''; // get the requested page 
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'qty_akhir',$qty_akhir );
	AddField($xmldoc ,'satuan',$satuan );
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_EXT_FINISH_TO_GOOD',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function finish_wire_to_sbc(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$qty_akhir = isset($_POST['qty_akhir'])?$_POST['qty_akhir']:''; // get the requested page 
	$satuan = isset($_POST['satuan'])?$_POST['satuan']:''; // get the requested page 
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'qty_akhir',$qty_akhir );
	AddField($xmldoc ,'satuan',$satuan );
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_WIRE_FINISH_TO_SBC',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function finish_wire_to_output(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$qty_akhir = isset($_POST['qty_akhir'])?$_POST['qty_akhir']:''; // get the requested page 
	$satuan = isset($_POST['satuan'])?$_POST['satuan']:''; // get the requested page 
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'qty_akhir',$qty_akhir );
	AddField($xmldoc ,'satuan',$satuan );
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_WIRE_FINISH_TO_OUTPUT',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}

function finish_tube_to_vo(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$qty_akhir = isset($_POST['qty_akhir'])?$_POST['qty_akhir']:''; // get the requested page 
	$satuan = isset($_POST['satuan'])?$_POST['satuan']:''; // get the requested page 
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'qty_akhir',$qty_akhir );
	AddField($xmldoc ,'satuan',$satuan );
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_TUBE_TO_VO',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function finish_tube_to_cot(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen dahulu');; // get the requested page 
	$qty_akhir = isset($_POST['qty_akhir'])?$_POST['qty_akhir']:''; // get the requested page 
	$satuan = isset($_POST['satuan'])?$_POST['satuan']:''; // get the requested page 
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'qty_akhir',$qty_akhir );
	AddField($xmldoc ,'satuan',$satuan );
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_TUBE_TO_COT',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}



function save_material_lotaaaaaaaaaa(){ 
	$id_detail = isset($_POST['id_detail'])?$_POST['id_detail']:die('pilih dokumen dahulu');; // get the requested page 
	$id_item_lot = isset($_POST['id_item_lot'])?$_POST['id_item_lot']:die('pilih dokumen dahulu');; // get the requested page 
	$kodebarang = isset($_POST['kodebarang'])?$_POST['kodebarang']:''; // get the requested page 
	$namabarang = isset($_POST['namabarang'])?$_POST['namabarang']:''; // get the requested page 
	$itemno = isset($_POST['itemno'])?$_POST['itemno']:''; // get the requested page 
	$nomorlot = isset($_POST['nomorlot'])?$_POST['nomorlot']:''; // get the requested page 
	$jumlah = isset($_POST['jumlah'])?$_POST['jumlah']:''; // get the requested page 
	$satuan = isset($_POST['satuan'])?$_POST['satuan']:''; // get the requested page 
	$petugas = isset($_POST['petugas'])?$_POST['petugas']:'';
	$tanggal = isset($_POST['tanggal'])?$_POST['tanggal']:'';


	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_detail',$id_detail);
	AddField($xmldoc ,'id_item_lot',$id_item_lot);
	AddField($xmldoc ,'kodebarang',$kodebarang );
	AddField($xmldoc ,'namabarang',$namabarang );
	AddField($xmldoc ,'itemno',$itemno );
	AddField($xmldoc ,'nomorlot',$nomorlot );
	AddField($xmldoc ,'jumlah',$jumlah );
	AddField($xmldoc ,'satuan',$satuan );
	AddField($xmldoc ,'petugas',$petugas );
	AddField($xmldoc ,'tanggal',$tanggal );
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

	$str = $xmldoc->saveXML();
	//  print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_ALL_MATERIAL_LOT',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}



function save_material_lot(){ 
	$id_detail = isset($_POST['id_detail'])?$_POST['id_detail']:die('pilih penyusun Dokument');
	$petugas = isset($_POST['petugas'])?$_POST['petugas']:'';
	$tanggal = isset($_POST['tanggal'])?$_POST['tanggal']:'';
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');


	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_detail',$id_detail );
	AddField($xmldoc ,'petugas',$petugas );
	AddField($xmldoc ,'tanggal',$tanggal );
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 



	$str = $xmldoc->saveXML();
	//  print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_ALL_MATERIAL_LOT',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}
 


function save_material_lot_mld(){ 
	$id_detail = isset($_POST['id_detail'])?$_POST['id_detail']:die('pilih penyusun Dokument');
	$petugas = isset($_POST['petugas'])?$_POST['petugas']:'';
	$tanggal = isset($_POST['tanggal'])?$_POST['tanggal']:'';
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');


	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_detail',$id_detail );
	AddField($xmldoc ,'petugas',$petugas );
	AddField($xmldoc ,'tanggal',$tanggal );
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 



	$str = $xmldoc->saveXML();
	//  print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_ALL_MATERIAL_LOT_MLD',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}
 


function save_material_lot_rdd(){ 
	$id_detail = isset($_POST['id_detail'])?$_POST['id_detail']:die('pilih penyusun Dokument');
	$petugas = isset($_POST['petugas'])?$_POST['petugas']:'';
	$tanggal = isset($_POST['tanggal'])?$_POST['tanggal']:'';
	$nomorlot = isset($_POST['nomorlot'])?$_POST['nomorlot']:die('pilih penyusun Dokument');


	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_detail',$id_detail );
	AddField($xmldoc ,'petugas',$petugas );
	AddField($xmldoc ,'tanggal',$tanggal );
	AddField($xmldoc ,'nomorlot',$nomorlot );
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

//	for ($i = 0; $i <  count($lstsa); $i++) {
//		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
//	} 



	$str = $xmldoc->saveXML();
	//  print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_GUDANG_OUT_FOR_RDD',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}
 


function save_material_get(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih penyusun Dokument');
	$lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih penyusun Dokument');


	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header );
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

	for ($i = 0; $i <  count($lstsa); $i++) {
		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
	} 



	$str = $xmldoc->saveXML();
	//  print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_ALL_MATERIAL_GET',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}
 




function save_ganti_lot_rdd(){ 
	$id_detail_pengganti = isset($_POST['id_detail_pengganti'])?$_POST['id_detail_pengganti']:die('pilih penyusun Dokument');
	$nolotpengganti = isset($_POST['nolotpengganti'])?$_POST['nolotpengganti']:'';
	$kodebarangpengganti = isset($_POST['kodebarangpengganti'])?$_POST['kodebarangpengganti']:'';
	$namabarangpengganti = isset($_POST['namabarangpengganti'])?$_POST['namabarangpengganti']:die('pilih penyusun Dokument');
	$itemnopengganti = isset($_POST['itemnopengganti'])?$_POST['itemnopengganti']:'';

	$id_detail_diganti = isset($_POST['id_detail_diganti'])?$_POST['id_detail_diganti']:'';
	$nolotdiganti = isset($_POST['nolotdiganti'])?$_POST['nolotdiganti']:die('pilih penyusun Dokument');
	$kodebarangdiganti = isset($_POST['kodebarangdiganti'])?$_POST['kodebarangdiganti']:'';
	$namabarangdiganti = isset($_POST['namabarangdiganti'])?$_POST['namabarangdiganti']:die('pilih penyusun Dokument');
	$itemnodiganti = isset($_POST['itemnodiganti'])?$_POST['itemnodiganti']:die('pilih penyusun Dokument');
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih penyusun Dokument');
	$posisi = isset($_POST['posisi'])?$_POST['posisi']:die('pilih penyusun Dokument');
 
	$hasil = isset($_POST['hasil'])?$_POST['hasil']:die('pilih penyusun Dokument');
 

	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_detail_pengganti',$id_detail_pengganti );
	AddField($xmldoc ,'nolotpengganti',$nolotpengganti );
	AddField($xmldoc ,'kodebarangpengganti',$kodebarangpengganti );
	AddField($xmldoc ,'namabarangpengganti',$namabarangpengganti );
	AddField($xmldoc ,'itemnopengganti',$itemnopengganti );

	AddField($xmldoc ,'id_detail_diganti',$id_detail_diganti );
	AddField($xmldoc ,'nolotdiganti',$nolotdiganti );
	AddField($xmldoc ,'kodebarangdiganti',$kodebarangdiganti );	
	AddField($xmldoc ,'namabarangdiganti',$namabarangdiganti );
	AddField($xmldoc ,'itemnodiganti',$itemnodiganti );
	AddField($xmldoc ,'id_header',$id_header );		
	AddField($xmldoc ,'posisi',$posisi );		
	AddField($xmldoc ,'hasil',$hasil );		
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

//	for ($i = 0; $i <  count($lstsa); $i++) {
//		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
//	} 



	$str = $xmldoc->saveXML();
	//  print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_GANTI_LOT_RDD',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}






function save_ganti_lot_non_rdd(){ 
	$id_detail_pengganti = isset($_POST['id_detail_pengganti'])?$_POST['id_detail_pengganti']:die('pilih penyusun Dokument');
	$nolotpengganti = isset($_POST['nolotpengganti'])?$_POST['nolotpengganti']:'';
	$kodebarangpengganti = isset($_POST['kodebarangpengganti'])?$_POST['kodebarangpengganti']:'';
	$namabarangpengganti = isset($_POST['namabarangpengganti'])?$_POST['namabarangpengganti']:die('pilih penyusun Dokument');
	$itemnopengganti = isset($_POST['itemnopengganti'])?$_POST['itemnopengganti']:'';

	$id_detail_diganti = isset($_POST['id_detail_diganti'])?$_POST['id_detail_diganti']:'';
	$nolotdiganti = isset($_POST['nolotdiganti'])?$_POST['nolotdiganti']:die('pilih penyusun Dokument');
	$kodebarangdiganti = isset($_POST['kodebarangdiganti'])?$_POST['kodebarangdiganti']:'';
	$namabarangdiganti = isset($_POST['namabarangdiganti'])?$_POST['namabarangdiganti']:die('pilih penyusun Dokument');
	$itemnodiganti = isset($_POST['itemnodiganti'])?$_POST['itemnodiganti']:die('pilih penyusun Dokument');
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih penyusun Dokument');
	$posisi = isset($_POST['posisi'])?$_POST['posisi']:die('pilih penyusun Dokument');
 
	$hasil = isset($_POST['hasil'])?$_POST['hasil']:die('pilih penyusun Dokument');
 

	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_detail_pengganti',$id_detail_pengganti );
	AddField($xmldoc ,'nolotpengganti',$nolotpengganti );
	AddField($xmldoc ,'kodebarangpengganti',$kodebarangpengganti );
	AddField($xmldoc ,'namabarangpengganti',$namabarangpengganti );
	AddField($xmldoc ,'itemnopengganti',$itemnopengganti );

	AddField($xmldoc ,'id_detail_diganti',$id_detail_diganti );
	AddField($xmldoc ,'nolotdiganti',$nolotdiganti );
	AddField($xmldoc ,'kodebarangdiganti',$kodebarangdiganti );	
	AddField($xmldoc ,'namabarangdiganti',$namabarangdiganti );
	AddField($xmldoc ,'itemnodiganti',$itemnodiganti );
	AddField($xmldoc ,'id_header',$id_header );		
	AddField($xmldoc ,'posisi',$posisi );		
	AddField($xmldoc ,'hasil',$hasil );		
	AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

//	for ($i = 0; $i <  count($lstsa); $i++) {
//		$this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
//	} 



	$str = $xmldoc->saveXML();
	//  print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_GANTI_LOT_NON_RDD',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}





























































    function finddata_supp_po(){
        $findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
		
        $xmldata = XMLbasic('dbo.SP_T_SUPP_PO_FIND');
        AddField($xmldata,'findtext',$findtext);   
        AddField($xmldata,'rows','10');  
      	exec_sp_xml($xmldata, 'dbo.SP_T_SUPP_PO_FIND',$stsno,$stsdes,$rows,$detail);
	       $i=0;
        foreach ($rows as $per_row) {
            $responce->rows[$i]['rID']=getXMLValue($per_row,'rID');
            $responce->rows[$i]['r1']=getXMLValue($per_row,'r1');
            $responce->rows[$i]['r2']=getXMLValue($per_row,'r2');     
            $responce->rows[$i]['r3']=getXMLValue($per_row,'r3');     
            $responce->rows[$i]['r4']=getXMLValue($per_row,'r4');     
            $responce->rows[$i]['r5']=getXMLValue($per_row,'r5');     
            $responce->rows[$i]['r6']=getXMLValue($per_row,'r6');     
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
    // echo '{"totalResultsCount":389,"geonames":[{"adminCode2":"079","countryName":"United States","adminCode1":"TN","fclName":"city, village,...","elevation":130,"score":36.80937194824219,"countryCode":"US","lng":-88.2580969,"adminName2":"Henry County","adminName3":"","fcodeName":"populated place","adminName4":"","timezone":{"dstOffset":-5,"gmtOffset":-6,"timeZoneId":"America/Chicago"},"toponymName":"India","fcl":"P","continentCode":"NA","name":"India","fcode":"PPL","geonameId":4050654,"lat":36.3325568,"adminName1":"Tennessee","population":0},{"adminCode2":"131","countryName":"United States","adminCode1":"MS","fclName":"city, village,...","elevation":61,"score":16.04806137084961,"countryCode":"US","lng":-89.1111595,"adminName2":"Stone County","adminName3":"","fcodeName":"populated place","adminName4":"","timezone":{"dstOffset":-5,"gmtOffset":-6,"timeZoneId":"America/Chicago"},"toponymName":"India","fcl":"P","continentCode":"NA","name":"India","fcode":"PPL","geonameId":4430906,"lat":30.8171338,"adminName1":"Mississippi","population":0},{"adminCode2":"139","countryName":"United States","adminCode1":"TX","fclName":"city, village,...","elevation":135,"score":15.832294464111328,"countryCode":"US","lng":-96.6161027,"adminName2":"Ellis County","adminName3":"","fcodeName":"populated place","adminName4":"","timezone":{"dstOffset":-5,"gmtOffset":-6,"timeZoneId":"America/Chicago"},"toponymName":"India","fcl":"P","continentCode":"NA","name":"India","fcode":"PPL","geonameId":4699848,"lat":32.5251375,"adminName1":"Texas","population":0},{"adminCode2":"129","countryName":"United States","adminCode1":"PA","fclName":"city, village,...","elevation":339,"score":15.832294464111328,"countryCode":"US","lng":-79.1194757,"adminName2":"Westmoreland County","adminName3":"","fcodeName":"populated place","adminName4":"","timezone":{"dstOffset":-4,"gmtOffset":-5,"timeZoneId":"America/New_York"},"toponymName":"India","fcl":"P","continentCode":"NA","name":"India","fcode":"PPL","geonameId":5194768,"lat":40.3764599,"adminName1":"Pennsylvania","population":0},{"adminCode2":"017","countryName":"United States","adminCode1":"AR","fclName":"city, village,...","elevation":41,"score":15.832294464111328,"countryCode":"US","lng":-91.2895572,"adminName2":"Chicot County","adminName3":"","fcodeName":"populated place","adminName4":"","timezone":{"dstOffset":-5,"gmtOffset":-6,"timeZoneId":"America/Chicago"},"toponymName":"Indian","fcl":"P","continentCode":"NA","name":"Indian","fcode":"PPL","geonameId":4115851,"lat":33.0526231,"adminName1":"Arkansas","population":0}]}';


    }    
	function load_setting_default(){
			$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:'-1';   
			$xmldoc =  XMLbasic('json'); 
			AddField($xmldoc ,'bc_prefix',$bc_prefix); 
			$str = $xmldoc->saveXML();  
			exec_sp_array($xmldoc, 'dbo.GET_SETTING_DEFAULT_CEISA',$sts,$des,$rows,$detail);  
			echo json_encode(
			array('valid'=>($sts=='00'?true:false)
			,'stsno' => $sts
			, 'stsmsg' => $des
			, 'data' => $detail
			)); 
	}
		
	function view_po(){	 
				$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:'-1';   
				$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('Pilih Dokumen ');   
				$cust_code = isset($_POST['cust_code'])?$_POST['cust_code']:'';  //1 add
				$data['cust_code'] = $cust_code;
				$data['id_header'] = $id_header;
				$data['bc_prefix'] = $bc_prefix;
				
				$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:'-1';   
			 	$xmldoc =  XMLbasic('json'); 
				AddField($xmldoc ,'bc_prefix',$bc_prefix); 
				$str = $xmldoc->saveXML();  
			    exec_sp_array($xmldoc, 'dbo.GET_SETTING_DEFAULT_CEISA',$sts,$des,$rows,$detail);   
				//print_r($detail);die();
				if ($sts=='00')
				$data['KURS'] = $detail['KURS'];
				else
				$data['KURS'] =1;
			
				$this->load->view('pasi_ceisa_bc_in/view_pasi_ceisa_bc_in_from_po_sa_data', $data);
	}   
	

	function view_dokumen(){	 
				$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:'-1';   
				$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('Pilih Dokumen ');   
				$cust_code = isset($_POST['cust_code'])?$_POST['cust_code']:'';  //1 add
				$data['cust_code'] = $cust_code;
				$data['id_header'] = $id_header;
				$data['bc_prefix'] = $bc_prefix;
				$this->load->view('pasi_ceisa_bc_in/view_pasi_ceisa_bc_in_from_po_dokumen_data', $data);
	}   
	
	function view_header_module_for_import(){	 
				$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:'-1';   
				$data['bc_prefix'] = $bc_prefix;
				$this->load->view('pasi_ceisa_bc_in/view_pasi_ceisa_bc_in_header_module', $data);
	}     

	function view_header_po_for_import(){	 
		$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:'-1';   
		$data['bc_prefix'] = $bc_prefix;
		$this->load->view('pasi_ceisa_bc_in/view_pasi_ceisa_bc_in_get_po_bc23', $data);
}     
	
    function loaddata_cust(){; 
		$def_col= array(); 
		$spt='dbo.SP_T_SUPP_PO'; 
		$def_col['rID']=array("db" => "rID" ,"sc" => "rID","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"int", "bypassvalue"=>"");
		
 		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
	 	 
        $page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'rID'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 
  	  
		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
 		 
		if (array_key_exists($sidx, $def_col)) {  
				$fsidx=$def_col[$sidx];
				$sidx=$fsidx['db'];
		}else{
				$sidx='rID'; //DEFAULT SORT KALU GA ADA
		}
        $sidx=$sidx.'='. $sord;
		  
		$xmldoc =  XMLbasic($spt); 
		paramViewJSON($xmldoc, $limit, $page,  $sidx, $sord); 
  		 
        if ($search == 'true'){ 
            if (!empty($filters)){ 
				$array = json_decode($filters); 
                foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
	 					if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue'])  
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1');  
			 					  
							} 
							elseif ($fcr['ctype']=='text'){ 
					        	$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
							     addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
                 } 
             } 
	   }  
  
  
		$str = $xmldoc->saveXML();   
		 exec_sp_json($xmldoc, 'dbo.SP_T_SUPP_PO',$sts,$des,$rows,$detail);  
  		echo $rows; 
		}
		
		
	    function load_header_module_for_import(){; 
		$def_col= array(); 
	 	$spt='dbo.SP_T_HEADER_BC_IN_MODULE'; 
		$def_col['rID']=array("db" => "rID" ,"sc" => "rID","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['rsc']=array("db" => "rsc" ,"sc" => "rsc","ctype"=>"text", "bypassvalue"=>"");
		$def_col['rs']=array("db" => "rs" ,"sc" => "rs","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"date", "bypassvalue"=>"");
		$def_col['ri']=array("db" => "ri" ,"sc" => "ri","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"int", "bypassvalue"=>"");
  		
 		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
	 	 
        $page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'rID'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 
		$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:'-1';   
		 
		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
 		 
		 if (array_key_exists($sidx, $def_col)) {  
				$fsidx=$def_col[$sidx];
				$sidx=$fsidx['db'];
		}else{
				$sidx='rID'; //DEFAULT SORT KALU GA ADA
		}
        $sidx=$sidx.'='. $sord;
		  
		$xmldoc =  XMLbasic($spt); 
		paramViewJSON($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc ,'bc_prefix',$bc_prefix);
		 
        if ($search == 'true'){ 
            if (!empty($filters)){ 
				$array = json_decode($filters); 
                foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
	 					if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue'])  
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1');  
			 					  
							} 
							elseif ($fcr['ctype']=='text'){ 
					        	$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
							     addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
                 } 
             } 
	   }  
  
  
		$str = $xmldoc->saveXML();   
		 exec_sp_json($xmldoc, 'dbo.SP_T_HEADER_BC_IN_MODULE',$sts,$des,$rows,$detail);  
  		echo $rows; 
		}
				
	    function load_header_po_for_import(){; 
			$def_col= array(); 
			 $spt='dbo.SP_T_IMPORT_BELI_PO_BC23'  ;   
			$def_col['rID']=array("db" => "rID" ,"sc" => "rID","ctype"=>"int", "bypassvalue"=>"");
			$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
			$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
			$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"date", "bypassvalue"=>"");
			$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"text", "bypassvalue"=>"");
			$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
			$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
			$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");

			  
			 $search = isset($_POST['_search'])?$_POST['_search']:false; 
			$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
			$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
			$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
			  
			$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
			$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
			$sidx = isset($_POST['sidx'])?$_POST['sidx']:'rID'; // get index row - i.e. user click to sort 
			$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 
			$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:'-1';   
			 
			if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
			  
			 if (array_key_exists($sidx, $def_col)) {  
					$fsidx=$def_col[$sidx];
					$sidx=$fsidx['db'];
			}else{
					$sidx='rID'; //DEFAULT SORT KALU GA ADA
			}
			$sidx=$sidx.'='. $sord;
			  
			$xmldoc =  XMLbasic($spt); 
			paramViewJSON($xmldoc, $limit, $page,  $sidx, $sord); 
			AddField($xmldoc ,'bc_prefix',$bc_prefix);
			 
			if ($search == 'true'){ 
				if (!empty($filters)){ 
					$array = json_decode($filters); 
					foreach($array->rules as $arr=>$k){ 
							$fcr=$def_col[$k->field]; 
							 if ($fcr != null) 
							{ 
								if ($fcr['ctype']=='int'){ 
									$searchString = $k->data; 
									if ($searchString!=$fcr['bypassvalue'])  
										addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1');  
									   
								} 
								elseif ($fcr['ctype']=='text'){ 
									$searchString = $k->data; 
									if ($searchString!=$fcr['bypassvalue']) 
									 addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
								}  
								elseif ($fcr['ctype']=='date'){ 
									$searchString = $k->data; 
									if (trim($searchString) != '' ){ 
										$dateArray=explode('/',$searchString);  
										$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
									} 
									 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
								}  
							} 
					 } 
				 } 
		   }  
	  
	  
			$str = $xmldoc->saveXML();   
			 exec_sp_json($xmldoc, 'dbo.SP_T_IMPORT_BELI_PO_BC23',$sts,$des,$rows,$detail);  
			  echo $rows; 
			}

	    function loaddata_invoice_beli(){; 
		$def_col= array(); 
		$spt='dbo.SP_X_IMPORT_BELI'; 
		$def_col['id']=array("db" => "id" ,"sc" => "id","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r27']=array("db" => "r27" ,"sc" => "r27","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r28']=array("db" => "r28" ,"sc" => "r28","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r29']=array("db" => "r29" ,"sc" => "r29","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r30']=array("db" => "r30" ,"sc" => "r30","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r31']=array("db" => "r31" ,"sc" => "r31","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r32']=array("db" => "r32" ,"sc" => "r32","ctype"=>"text", "bypassvalue"=>"");
 		$def_col['ru']=array("db" => "ru" ,"sc" => "ru","ctype"=>"int", "bypassvalue"=>"");
		$def_col['rg']=array("db" => "rg" ,"sc" => "rg","ctype"=>"int", "bypassvalue"=>"-100");
		$def_col['i1']=array("db" => "i1" ,"sc" => "i1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['i2']=array("db" => "i2" ,"sc" => "i2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['i3']=array("db" => "i3" ,"sc" => "i3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['i4']=array("db" => "i4" ,"sc" => "i4","ctype"=>"text", "bypassvalue"=>"");
		
 		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
	 	 
        $page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'rID'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'asc'; // get the direction 
		
  		$kurs = isset($_POST['kurs'])?$_POST['kurs']:''; // get the direction 
  		$supp_code = isset($_POST['supp_code'])?$_POST['supp_code']:''; // get the direction 
  	 	$supp_code_len = isset($_POST['len_supp_code'])?$_POST['len_supp_code']:'3'; // get the direction 
  	  
		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
 		 
		 if (array_key_exists($sidx, $def_col)) {  
				$fsidx=$def_col[$sidx];
				$sidx=$fsidx['db'];
		}else{
				$sidx='rID'; //DEFAULT SORT KALU GA ADA
		}
        $sidx=$sidx.'='. $sord;
		  
		$xmldoc =  XMLbasic($spt); 
	 	paramViewJSON($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc ,'supp_code', substr($supp_code,0,$supp_code_len)); 
		AddField($xmldoc ,'kurs',$kurs); 
		 
        if ($search == 'true'){ 
            if (!empty($filters)){ 
				$array = json_decode($filters); 
                foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
	 					if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue'])  
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1');  
			 					  
							} 
							elseif ($fcr['ctype']=='text'){ 
					        	$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
							     addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
                 } 
             } 
	   }  
  
  
		$str = $xmldoc->saveXML() ;
		//print_r($str);die();
		exec_sp_json($xmldoc, 'dbo.SP_X_IMPORT_BELI',$sts,$des,$rows,$detail);  
  		echo $rows; 
		}
		

	    function loaddata_dokumen(){; 
		$def_col= array(); 
	 	$spt='dbo.SP_T_BC_FROM_PO_VIEW_DOKUMEN'; 
		$def_col['rID']=array("db" => "rID" ,"sc" => "rID","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"int", "bypassvalue"=>"");
 		
 		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
	 	 
        $page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'rID'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 
		$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('Pilih Dokumen');; // get the requested page 
	 
		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
 		 
		 if (array_key_exists($sidx, $def_col)) {  
				$fsidx=$def_col[$sidx];
				$sidx=$fsidx['db'];
		}else{
				$sidx='rID'; //DEFAULT SORT KALU GA ADA
		}
        $sidx=$sidx.'='. $sord;
		  
		$xmldoc =  XMLbasic($spt); 
		paramViewJSON($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc ,'id_header',$id_header);
			 
        if ($search == 'true'){ 
            if (!empty($filters)){ 
				$array = json_decode($filters); 
                foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
	 					if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue'])  
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1');  
			 					  
							} 
							elseif ($fcr['ctype']=='text'){ 
					        	$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
							     addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
                 } 
             } 
	   }  
  
  
		$str = $xmldoc->saveXML();   
		 exec_sp_json($xmldoc, 'dbo.SP_T_BC_FROM_PO_VIEW_DOKUMEN',$sts,$des,$rows,$detail);  
  		echo $rows; 
		}
		
	    function create_header_bc(){
		        $cust_code = isset($_POST['cust_code'])?$_POST['cust_code']:die('Pilih Customer');; // get the requested page 
		        $kurs = isset($_POST['kurs'])?$_POST['kurs']:''; // get the requested page 
		        $bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:die('Type BC tidak di ketahui');; // get the requested page 
		        $lstpoitem = isset($_POST['lstpoitem'])?$_POST['lstpoitem']:die('pilih PO ITEM penyusun Dokument');; // get the requested page 
	 	 
				$xmldoc =  XMLbasic('json'); 
				AddField($xmldoc ,'cust_code',$cust_code);
				AddField($xmldoc ,'bc_prefix',$bc_prefix);
				AddField($xmldoc ,'valuta_code',$kurs); 
				
				for ($i = 0; $i <  count($lstpoitem); $i++) { 
				    $this->_insert_po_to_field($xmldoc,$lstpoitem[$i][0],$lstpoitem[$i][1]);
				} 
				$str = $xmldoc->saveXML();  
				 exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_PO_CREATE',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		
	    function add_sa(){
		        $id_header = isset($_POST['id_header'])?$_POST['id_header']:die('Pilih Dokumen');; // get the requested page 
		         $lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih SA');; // get the requested page 
	 	 
				$xmldoc =  XMLbasic('json'); 
				AddField($xmldoc ,'id_header',$id_header);
				for ($i = 0; $i <  count($lstsa); $i++) {
				    $this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
				} 
				$str = $xmldoc->saveXML();  
				 exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_SA_SA_ADD',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		
		
	    function delete_sa(){
		        $id_header = isset($_POST['id_header'])?$_POST['id_header']:die('Pilih Dokumen');; // get the requested page 
	 	        $lstsa = isset($_POST['lstsa'])?$_POST['lstsa']:die('pilih SA');; // get the requested page 
	 	 
				$xmldoc =  XMLbasic('json');  
				AddField($xmldoc ,'id_header',$id_header);
				for ($i = 0; $i <  count($lstsa); $i++) {
				    $this->_insert_sa_to_field($xmldoc,$lstsa[$i]);
				} 
				$str = $xmldoc->saveXML();  
				 exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_SA_SA_DELETE',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		
		
	    function cancel_document(){ 
			    $id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen yang akan di cancel');; // get the requested page 
		        $status_info = isset($_POST['status_info'])?$_POST['status_info']:''; // get the requested page 
	 	 
				$xmldoc =  XMLbasic('json'); 
				AddField($xmldoc ,'id_header',$id_header);
				AddField($xmldoc ,'status_info',$status_info );
				$str = $xmldoc->saveXML();
			 	// print_r($str);die();
				 exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_PO_CANCEL',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}


	
	function save_header_gudang_in(){ 
		$id_header = isset($_POST['ID_HEADER'])?$_POST['ID_HEADER']:'-1'; //die('pilih dokumen yang akan di cancel');; // get the requested page 
		$NOMOR_PENERIMAAN = isset($_POST['NOMOR_PENERIMAAN'])?$_POST['NOMOR_PENERIMAAN']:''; // get the requested page 
		$NOMOR_SURATJALAN = isset($_POST['NOMOR_SURATJALAN'])?$_POST['NOMOR_SURATJALAN']:''; // get the requested page 
		$TANGGAL_PENERIMAAN = isset($_POST['TANGGAL_PENERIMAAN'])?$_POST['TANGGAL_PENERIMAAN']:''; // get the requested page 
		$TANGGAL_SURATJALAN = isset($_POST['TANGGAL_SURATJALAN'])?$_POST['TANGGAL_SURATJALAN']:''; // get the requested page 
		
		$xmldoc =  XMLbasic('json'); 
		AddField($xmldoc ,'id_header',$id_header);
		AddField($xmldoc ,'NOMOR_PENERIMAAN',$NOMOR_PENERIMAAN );
		AddField($xmldoc ,'NOMOR_SURATJALAN',$NOMOR_SURATJALAN );
		AddField($xmldoc ,'TANGGAL_PENERIMAAN',$TANGGAL_PENERIMAAN );
		AddField($xmldoc ,'TANGGAL_SURATJALAN',$TANGGAL_SURATJALAN );
		$str = $xmldoc->saveXML();

	//	 print_r($str);die();
		 exec_sp_array($xmldoc, 'dbo.SPX_GUDANG_IN_SAVE_HEADER',$sts,$des,$rows,$detail); 
		echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}
	
function save_header_bc27(){ 
	$id_header = isset($_POST['ID_HEADER'])?$_POST['ID_HEADER']:'-1'; //die('pilih dokumen yang akan di cancel');; // get the requested page 
	$NOMOR_PENERIMAAN = isset($_POST['NOMOR_PENERIMAAN'])?$_POST['NOMOR_PENERIMAAN']:''; // get the requested page 
	$NOMOR_SURATJALAN = isset($_POST['NOMOR_SURATJALAN'])?$_POST['NOMOR_SURATJALAN']:''; // get the requested page 
	$TANGGAL_PENERIMAAN = isset($_POST['TANGGAL_PENERIMAAN'])?$_POST['TANGGAL_PENERIMAAN']:''; // get the requested page 
	$TANGGAL_SURATJALAN = isset($_POST['TANGGAL_SURATJALAN'])?$_POST['TANGGAL_SURATJALAN']:''; // get the requested page 
	
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'NOMOR_PENERIMAAN',$NOMOR_PENERIMAAN );
	AddField($xmldoc ,'NOMOR_SURATJALAN',$NOMOR_SURATJALAN );
	AddField($xmldoc ,'TANGGAL_PENERIMAAN',$TANGGAL_PENERIMAAN );
	AddField($xmldoc ,'TANGGAL_SURATJALAN',$TANGGAL_SURATJALAN );
	$str = $xmldoc->saveXML();

//	 print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_GUDANG_BC27_SAVE_HEADER',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function save_header_bc40(){ 
	$id_header = isset($_POST['ID_HEADER'])?$_POST['ID_HEADER']:'-1'; //die('pilih dokumen yang akan di cancel');; // get the requested page 
	$NOMOR_PENERIMAAN = isset($_POST['NOMOR_PENERIMAAN'])?$_POST['NOMOR_PENERIMAAN']:''; // get the requested page 
	$NOMOR_SURATJALAN = isset($_POST['NOMOR_SURATJALAN'])?$_POST['NOMOR_SURATJALAN']:''; // get the requested page 
	$TANGGAL_PENERIMAAN = isset($_POST['TANGGAL_PENERIMAAN'])?$_POST['TANGGAL_PENERIMAAN']:''; // get the requested page 
	$TANGGAL_SURATJALAN = isset($_POST['TANGGAL_SURATJALAN'])?$_POST['TANGGAL_SURATJALAN']:''; // get the requested page 
	
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'NOMOR_PENERIMAAN',$NOMOR_PENERIMAAN );
	AddField($xmldoc ,'NOMOR_SURATJALAN',$NOMOR_SURATJALAN );
	AddField($xmldoc ,'TANGGAL_PENERIMAAN',$TANGGAL_PENERIMAAN );
	AddField($xmldoc ,'TANGGAL_SURATJALAN',$TANGGAL_SURATJALAN );
	$str = $xmldoc->saveXML();

//	 print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_GUDANG_BC40_SAVE_HEADER',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}



	    function send_to_module(){ 
			    $id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen yang akan di kirim ke module');; // get the requested page 
			    $tdd_date = isset($_POST['tdd_date'])?$_POST['tdd_date']:''; // get the requested page 
			    $tdd_name = isset($_POST['tdd_name'])?$_POST['tdd_name']:''; // get the requested page 
			    $tdd_jabatan = isset($_POST['tdd_jabatan'])?$_POST['tdd_jabatan']:''; // get the requested page 
		  
				$xmldoc =  XMLbasic('json'); 
				AddField($xmldoc ,'id_header',$id_header);
				AddField($xmldoc ,'tdd_date',$tdd_date);
				AddField($xmldoc ,'tdd_name',$tdd_name);
				AddField($xmldoc ,'tdd_jabatan',$tdd_jabatan);
		 		$str = $xmldoc->saveXML();
			 	// print_r($str);die();
				 exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_PO_SEND_TO_MODULE',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		
	    function update_from_module(){ 
			    $id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen yang akan di kirim ke module');; // get the requested page 
		   
				$xmldoc =  XMLbasic('json'); 
				AddField($xmldoc ,'id_header',$id_header);
		  		$str = $xmldoc->saveXML();
			 	// print_r($str);die();
				exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_PO_UPDATE_FROM_MODULE',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		

		
		function update_mapping_customer(){ 
			    $id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen yang akan di kirim ke module');; // get the requested page 
			    $cust_code = isset($_POST['cust_code'])?$_POST['cust_code']:die('pilih customer mapping');; // get the requested page 
		   
				$xmldoc =  XMLbasic('json'); 
				AddField($xmldoc ,'id_header',$id_header);
				AddField($xmldoc ,'cust_code',$cust_code);
		  		$str = $xmldoc->saveXML();
			 	// print_r($str);die();
				 exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_PO_MAPPING_CUSTOMER',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		
			
		function get_receive(){
			$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen');; // get the requested page 
			$xmldoc =  XMLbasic('json'); 
			AddField($xmldoc ,'id_header',$id_header); 
			$str = $xmldoc->saveXML();  
			exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_PO_GET_RECIEVE',$sts,$des,$rows,$detail);  
			echo json_encode(
			array('valid'=>($sts=='00'?true:false)
			,'stsno' => $sts
			, 'stsmsg' => $des
			, 'data' => $detail
			)); 
	}
	    function finish_document(){ 
			    $id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen yang akan di kirim ke module');; // get the requested page 
		        $receive_no = isset($_POST['receive_no'])?$_POST['receive_no']:die('Nomor Penerimaan tidak boleh kosong');; // get the requested page 
		        $receive_date = isset($_POST['receive_date'])?$_POST['receive_date']:die('Tanggal Penerimaan tidak boleh kosong');; // get the requested page 
		   
				$xmldoc =  XMLbasic('json'); 
				AddField($xmldoc ,'id_header',$id_header);
		 		AddField($xmldoc ,'receive_no',$receive_no);
		 		AddField($xmldoc ,'receive_date',$receive_date);
		  		$str = $xmldoc->saveXML();
			 	// print_r($str);die();
				 exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_PO_FINISH',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		
		function _insert_po_to_field($doc,$id,$qty){
			$param = $doc->getElementsByTagName('param')->item(0);
			$field = $param->getElementsByTagName('field')->item(0);
			$lst = $doc->createElement("lstpo","");
			$field->appendChild($lst); 
			$tmp = $doc->createElement("id",$id);
			$lst->appendChild($tmp); 
			$tmp = $doc->createElement("qty",$qty);
			$lst->appendChild($tmp); 
		}
		
	    function update_kurs(){ 
	 	        $kurs = isset($_POST['kurs'])?$_POST['kurs']:'1'; // get the requested page 
		        $bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:die('Type BC tidak di ketahui');; // get the requested page 
	 	 
				$xmldoc =  XMLbasic('json'); 
		 		AddField($xmldoc ,'kurs',$kurs );
		 		AddField($xmldoc ,'bc_prefix',$bc_prefix );
				$str = $xmldoc->saveXML();
			 	// print_r($str);die();
				 exec_sp_array($xmldoc, 'dbo.UPDATE_CEISA_KURS',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false)
				,'stsno' => $sts
				, 'stsmsg' => $des
				, 'detail' => $detail)
				); 
		} 
		

		
		function _insert_sa_to_field($doc,$id){
			$param = $doc->getElementsByTagName('param')->item(0);
			$field = $param->getElementsByTagName('field')->item(0);
			$lst = $doc->createElement("lstsa","");
			$field->appendChild($lst); 
			$tmp = $doc->createElement("id",$id);
			$lst->appendChild($tmp); 
		}

		function cancel_produksi(){ 
			$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen yang akan di cancel');; // get the requested page 
			$status_info = isset($_POST['status_info'])?$_POST['status_info']:''; // get the requested page 
			$posisi_proses = isset($_POST['posisi_proses'])?$_POST['posisi_proses']:'';
			$xmldoc =  XMLbasic('json'); 
			AddField($xmldoc ,'id_header',$id_header);
			AddField($xmldoc ,'status_info',$status_info );
			AddField($xmldoc ,'posisi_proses',$posisi_proses );
			$str = $xmldoc->saveXML();
			 // print_r($str);die();
			 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_CANCEL',$sts,$des,$rows,$detail); 
			echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
	}


	function cancel_produksi_tube(){ 
		$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen yang akan di cancel');; // get the requested page 
		$status_info = isset($_POST['status_info'])?$_POST['status_info']:''; // get the requested page 
		$posisi_proses = isset($_POST['posisi_proses'])?$_POST['posisi_proses']:'';
		$xmldoc =  XMLbasic('json'); 
		AddField($xmldoc ,'id_header',$id_header);
		AddField($xmldoc ,'status_info',$status_info );
		AddField($xmldoc ,'posisi_proses',$posisi_proses );
		$str = $xmldoc->saveXML();
		 // print_r($str);die();
		 exec_sp_array($xmldoc, 'dbo.SPX_PRODUKSI_TUBE_CANCEL',$sts,$des,$rows,$detail); 
		echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}

 }