<?php 
class CT_pasi_ceisa_bc_in_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_bc_in/view_pasi_ceisa_bc_in_from_po', $data);
	}   
	 
	function view_header_invoice_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_invoice_bc40', $data);
}     



function load_header_invoice_for_import(){; 
	$def_col= array(); 
	 $spt='dbo.SPX_VIEW_BELI_BC40_HEADER'  ;   
	$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.SPX_VIEW_BELI_BC40_HEADER',$sts,$des,$rows,$detail);  
	  echo $rows; 
	}


	function import_data_bc40_save(){
		$bc_prefix = 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 SA 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_IMPORT_INVOICE_BELI_BC40_ADD',$sts,$des,$rows,$detail); 
		echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}

function import_data_bc23_save(){
	$bc_prefix = 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 SA 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_IMPORT_INVOICE_BELI_BC23_ADD',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}

function import_data_bc27_save(){
	$bc_prefix = 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 SA 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_IMPORT_INVOICE_BELI_BC27_ADD',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


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 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 create_header_bc23(){
	$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_BC23',$sts,$des,$rows,$detail); 
	echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}


function create_header_bc27(){
	$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_BC27',$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 
	$username = isset($_POST['username'])?$_POST['username']:'-1'; //die('pilih dokumen yang akan di cancel');; // get the requested page 
	$bagian = 'BC-IN'; //die('pilih dokumen yang akan di cancel');; // get the requested page 

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

function cancel_document_bc23(){ 
	$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 
	$username = isset($_POST['username'])?$_POST['username']:'-1'; //die('pilih dokumen yang akan di cancel');; // get the requested page 
	$bagian = 'BC-IN'; //die('pilih dokumen yang akan di cancel');; // get the requested page 

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

function cancel_document_bc27(){ 
	$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 
	$username = isset($_POST['username'])?$_POST['username']:'-1'; //die('pilih dokumen yang akan di cancel');; // get the requested page 
	$bagian = 'BC-IN'; //die('pilih dokumen yang akan di cancel');; // get the requested page 

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

function cancel_document_bc40(){ 
	$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 
	$username = isset($_POST['username'])?$_POST['username']:'-1'; //die('pilih dokumen yang akan di cancel');; // get the requested page 
	$bagian = 'BC-IN'; //die('pilih dokumen yang akan di cancel');; // get the requested page 

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

function edit_qty_actual_bc_in(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen yang akan di cancel');; // get the requested page 
	$qty_actual = isset($_POST['qty_actual'])?$_POST['qty_actual']:''; // get the requested page 

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

function edit_qty_actual_bc27(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen yang akan di cancel');; // get the requested page 
	$qty_actual = isset($_POST['qty_actual'])?$_POST['qty_actual']:''; // get the requested page 

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

function edit_qty_actual_bc40(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen yang akan di cancel');; // get the requested page 
	$qty_actual = isset($_POST['qty_actual'])?$_POST['qty_actual']:''; // get the requested page 

	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'qty_actual',$qty_actual );
	$str = $xmldoc->saveXML();
	 // print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_BC_IN_BC40_VAL_QTY',$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 save_nomor_daftar(){ 
	$id_header = isset($_POST['id_header'])?$_POST['id_header']:'-1'; //die('pilih dokumen yang akan di cancel');; // get the requested page 
	$NOMOR_AJU = isset($_POST['NOMOR_AJU'])?$_POST['NOMOR_AJU']:''; // get the requested page 
	$NOMOR_DAFTAR = isset($_POST['NOMOR_DAFTAR'])?$_POST['NOMOR_DAFTAR']:''; // get the requested page 
	$TANGGAL_DAFTAR = isset($_POST['TANGGAL_DAFTAR'])?$_POST['TANGGAL_DAFTAR']:''; // get the requested page 
	
	$xmldoc =  XMLbasic('json'); 
	AddField($xmldoc ,'id_header',$id_header);
	AddField($xmldoc ,'NOMOR_AJU',$NOMOR_AJU );
	AddField($xmldoc ,'NOMOR_DAFTAR',$NOMOR_DAFTAR );
	AddField($xmldoc ,'TANGGAL_DAFTAR',$TANGGAL_DAFTAR );
 
	$str = $xmldoc->saveXML();

//	 print_r($str);die();
	 exec_sp_array($xmldoc, 'dbo.SPX_BC_IN_NO_DAFTAR',$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'; // get the requested page 
	$NOMOR_AJU 					= isset($_POST['NOMOR_AJU'])?$_POST['NOMOR_AJU']:''; // get the requested page 
	$PJT 						= isset($_POST['PJT'])?$_POST['PJT']:''; // get the requested page 
	$NOMOR_DAFTAR 				= isset($_POST['NOMOR_DAFTAR'])?$_POST['NOMOR_DAFTAR']:''; // get the requested page 
	$TANGGAL_DAFTAR 			= isset($_POST['TANGGAL_DAFTAR'])?$_POST['TANGGAL_DAFTAR']:''; // get the requested page 
	$NOMOR_BILLING				= isset($_POST['NOMOR_BILLING'])?$_POST['NOMOR_BILLING']:''; // get the requested page 
	$TANGGAL_BILLING 			= isset($_POST['TANGGAL_BILLING'])?$_POST['TANGGAL_BILLING']:''; // get the requested page 
	$KODE_PELA_BONGKAR 			= isset($_POST['KODE_PELA_BONGKAR'])?$_POST['KODE_PELA_BONGKAR']:''; // get the requested page 
	$KODE_KANTOR_BONGKAR 		= isset($_POST['KODE_KANTOR_BONGKAR'])?$_POST['KODE_KANTOR_BONGKAR']:''; // get the requested page 
	$KODE_TUJUAN 				= isset($_POST['KODE_TUJUAN'])?$_POST['KODE_TUJUAN']:''; // get the requested page 
	$ID_PEMASOK					= isset($_POST['ID_PEMASOK'])?$_POST['ID_PEMASOK']:'';
	$KODE_ID_PEMASOK			= isset($_POST['KODE_ID_PEMASOK'])?$_POST['KODE_ID_PEMASOK']:'';
	$NAMA_PEMASOK				= isset($_POST['NAMA_PEMASOK'])?$_POST['NAMA_PEMASOK']:'';
	$ALAMAT_PEMASOK				= isset($_POST['ALAMAT_PEMASOK'])?$_POST['ALAMAT_PEMASOK']:'';
	$KODE_NEGARA_PEMASOK		= isset($_POST['KODE_NEGARA_PEMASOK'])?$_POST['KODE_NEGARA_PEMASOK']:'';
	$ID_PENERIMA_BARANG			= isset($_POST['ID_PENERIMA_BARANG'])?$_POST['ID_PENERIMA_BARANG']:'';
	$KODE_ID_PENERIMA_BARANG	= isset($_POST['KODE_ID_PENERIMA_BARANG'])?$_POST['KODE_ID_PENERIMA_BARANG']:'';
	$NAMA_PENERIMA_BARANG		= isset($_POST['NAMA_PENERIMA_BARANG'])?$_POST['NAMA_PENERIMA_BARANG']:'';
	$NOMOR_IJIN_TPB_PENERIMA	= isset($_POST['NOMOR_IJIN_TPB_PENERIMA'])?$_POST['NOMOR_IJIN_TPB_PENERIMA']:'';				
	$KODE_JENIS_API_PENERIMA	= isset($_POST['KODE_JENIS_API_PENERIMA'])?$_POST['KODE_JENIS_API_PENERIMA']:'';
	$ID_PEMILIK 				= isset($_POST['ID_PEMILIK'])?$_POST['ID_PEMILIK']:'';
	$KODE_ID_PEMILIK			= isset($_POST['KODE_ID_PEMILIK'])?$_POST['KODE_ID_PEMILIK']:'';
	$NAMA_PEMILIK				= isset($_POST['NAMA_PEMILIK'])?$_POST['NAMA_PEMILIK']:'';
	$ALAMAT_PEMILIK				= isset($_POST['ALAMAT_PEMILIK'])?$_POST['ALAMAT_PEMILIK']:'';
	$KODE_JENIS_API_PEMILIK		= isset($_POST['KODE_JENIS_API_PEMILIK'])?$_POST['KODE_JENIS_API_PEMILIK']:'';
	$ID_PPJK	 				= isset($_POST['ID_PPJK'])?$_POST['ID_PPJK']:'';
	$KODE_ID_PPJK				= isset($_POST['KODE_ID_PPJK'])?$_POST['KODE_ID_PPJK']:'';
	$NAMA_PPJK					= isset($_POST['NAMA_PPJK'])?$_POST['NAMA_PPJK']:'';
	$ALAMAT_PPJK				= isset($_POST['ALAMAT_PPJK'])?$_POST['ALAMAT_PPJK']:'';
	$CARA_ANGKUT				= isset($_POST['CARA_ANGKUT'])?$_POST['CARA_ANGKUT']:'';
	$SARANA_ANGKUT 				= isset($_POST['SARANA_ANGKUT'])?$_POST['SARANA_ANGKUT']:'';
	$NOMOR_VOY_FLIGHT			= isset($_POST['NOMOR_VOY_FLIGHT'])?$_POST['NOMOR_VOY_FLIGHT']:'';
	$KODE_NEGARA_TUJUAN			= isset($_POST['KODE_NEGARA_TUJUAN'])?$_POST['KODE_NEGARA_TUJUAN']:'';
	$KODE_PEL_MUAT 				= isset($_POST['KODE_PEL_MUAT'])?$_POST['KODE_PEL_MUAT']:'';
	$KODE_PEL_TRANSIT			= isset($_POST['KODE_PEL_TRANSIT'])?$_POST['KODE_PEL_TRANSIT']:'';
	$KODE_PEL_BONGKAR 			= isset($_POST['KODE_PEL_BONGKAR'])?$_POST['KODE_PEL_BONGKAR']:'';
	$KODE_FASILITAS				= isset($_POST['KODE_FASILITAS'])?$_POST['KODE_FASILITAS']:'';
	$KODE_LC					= isset($_POST['KODE_LC'])?$_POST['KODE_LC']:'';
	$KODE_AWB					= isset($_POST['KODE_AWB'])?$_POST['KODE_AWB']:'';
	$KODE_BC11					= isset($_POST['KODE_BC11'])?$_POST['KODE_BC11']:'';
	$TANGGAL_BC11				= isset($_POST['TANGGAL_BC11'])?$_POST['TANGGAL_BC11']:'';
	$SUBPOS_BC11				= isset($_POST['SUBPOS_BC11'])?$_POST['SUBPOS_BC11']:'';
	$SUBSUBPOS_BC11				= isset($_POST['SUBSUBPOS_BC11'])?$_POST['SUBSUBPOS_BC11']:'';
	$PENIMBUNAN					= isset($_POST['PENIMBUNAN'])?$_POST['PENIMBUNAN']:'';
	$KODE_VALUTA				= isset($_POST['KODE_VALUTA'])?$_POST['KODE_VALUTA']:''; // get the requested page 
	$NDPBM						= isset($_POST['NDPBM'])?$_POST['NDPBM']:'0'; // get the requested page 
	$FOB						= isset($_POST['FOB'])?$_POST['FOB']:'0';
	$FREIGHT 					= isset($_POST['FREIGHT'])?$_POST['FREIGHT']:'0'; // get the requested page 
	$KODE_ASURANSI 				= isset($_POST['KODE_ASURANSI'])?$_POST['KODE_ASURANSI']:''; // get the requested page 
	$ASURANSI 					= isset($_POST['ASURANSI'])?$_POST['ASURANSI']:'0'; // get the requested page 
	$CIF 						= isset($_POST['CIF'])?$_POST['CIF']:'0';
	$CIF_RUPIAH 				= isset($_POST['CIF_RUPIAH'])?$_POST['CIF_RUPIAH']:'0';
	$JUMLAH_KONTAINER			= isset($_POST['JUMLAH_KONTAINER'])?$_POST['JUMLAH_KONTAINER']:'0'; // get the requested page 
	$JUMLAH_KEMASAN				= isset($_POST['JUMLAH_KEMASAN'])?$_POST['JUMLAH_KEMASAN']:'0';
	$JUMLAH_BARANG 				= isset($_POST['JUMLAH_BARANG'])?$_POST['JUMLAH_BARANG']:'0'; // get the requested page 
	$BRUTO		 				= isset($_POST['BRUTO'])?$_POST['BRUTO']:'0'; // get the requested page 
	$NETTO						= isset($_POST['NETTO'])?$_POST['NETTO']:'0'; // get the requested page 
	$VOLUME						= isset($_POST['VOLUME'])?$_POST['VOLUME']:'0'; // get the requested page 
	$KEMASAN	 				= isset($_POST['KEMASAN'])?$_POST['KEMASAN']:''; // get the requested page 
	$KODE_DOKUMEN_PABEAN		= isset($_POST['KODE_DOKUMEN_PABEAN'])?$_POST['KODE_DOKUMEN_PABEAN']:''; // get the requested page 
		



		
			
			$xmldoc =  XMLbasic('json');  
			AddField($xmldoc ,'ID_HEADER',$ID_HEADER);// get the requested page 
			AddField($xmldoc ,'NOMOR_AJU',$NOMOR_AJU); // get the requested page 
			AddField($xmldoc ,'PJT',$PJT); // get the requested page 
			AddField($xmldoc ,'NOMOR_DAFTAR',$NOMOR_DAFTAR); // get the requested page 
			AddField($xmldoc ,'TANGGAL_DAFTAR',$TANGGAL_DAFTAR); // get the requested page 
			AddField($xmldoc ,'NOMOR_BILLING',$NOMOR_BILLING); // get the requested page 
			AddField($xmldoc ,'TANGGAL_BILLING',$TANGGAL_BILLING); // get the requested page 
			AddField($xmldoc ,'KODE_ASAL_BARANG',$KODE_PELA_BONGKAR); // get the requested page 
			AddField($xmldoc ,'KODE_KANTOR_BONGKAR',$KODE_KANTOR_BONGKAR); // get the requested page 
			AddField($xmldoc ,'KODE_TUJUAN',$KODE_TUJUAN); // get the requested page 
			AddField($xmldoc ,'ID_PEMASOK',$ID_PEMASOK);
			AddField($xmldoc ,'KODE_ID_PEMASOK',$KODE_ID_PEMASOK);
			AddField($xmldoc ,'NAMA_PEMASOK',$NAMA_PEMASOK);
			AddField($xmldoc ,'ALAMAT_PEMASOK',$ALAMAT_PEMASOK);
			AddField($xmldoc ,'KODE_NEGARA_PEMASOK',$KODE_NEGARA_PEMASOK);
			AddField($xmldoc ,'ID_PENERIMA_BARANG',$ID_PENERIMA_BARANG);
			AddField($xmldoc ,'KODE_ID_PENERIMA_BARANG',$KODE_ID_PENERIMA_BARANG);
			AddField($xmldoc ,'NAMA_PENERIMA_BARANG',$NAMA_PENERIMA_BARANG);
			AddField($xmldoc ,'NOMOR_IJIN_TPB_PENERIMA',$NOMOR_IJIN_TPB_PENERIMA);				
			AddField($xmldoc ,'KODE_JENIS_API_PENERIMA',$KODE_JENIS_API_PENERIMA);
			AddField($xmldoc ,'ID_PEMILIK',$ID_PEMILIK);
			AddField($xmldoc ,'KODE_ID_PEMILIK',$KODE_ID_PEMILIK);
			AddField($xmldoc ,'NAMA_PEMILIK',$NAMA_PEMILIK);
			AddField($xmldoc ,'ALAMAT_PEMILIK',$ALAMAT_PEMILIK);
			AddField($xmldoc ,'KODE_JENIS_API_PEMILIK',$KODE_JENIS_API_PEMILIK);
			AddField($xmldoc ,'ID_PPJK',$ID_PPJK);
			AddField($xmldoc ,'KODE_ID_PPJK',$KODE_ID_PPJK);
			AddField($xmldoc ,'NAMA_PPJK',$NAMA_PPJK);
			AddField($xmldoc ,'ALAMAT_PPJK',$ALAMAT_PPJK);
			AddField($xmldoc ,'CARA_ANGKUT',$CARA_ANGKUT);
			AddField($xmldoc ,'SARANA_ANGKUT',$SARANA_ANGKUT);
			AddField($xmldoc ,'NOMOR_VOY_FLIGHT',$NOMOR_VOY_FLIGHT);
			AddField($xmldoc ,'KODE_NEGARA_TUJUAN',$KODE_NEGARA_TUJUAN);
			AddField($xmldoc ,'KODE_PEL_MUAT',$KODE_PEL_MUAT);
			AddField($xmldoc ,'KODE_PEL_TRANSIT',$KODE_PEL_TRANSIT);
			AddField($xmldoc ,'KODE_PEL_BONGKAR',$KODE_PEL_BONGKAR);
			AddField($xmldoc ,'KODE_FASILITAS',$KODE_FASILITAS);
			AddField($xmldoc ,'KODE_LC',$KODE_LC);
			AddField($xmldoc ,'KODE_AWB',$KODE_AWB);
			AddField($xmldoc ,'KODE_BC11',$KODE_BC11);
			AddField($xmldoc ,'TANGGAL_BC11',$TANGGAL_BC11);
			AddField($xmldoc ,'SUBPOS_BC11',$SUBPOS_BC11);
			AddField($xmldoc ,'SUBSUBPOS_BC11',$SUBSUBPOS_BC11);
			AddField($xmldoc ,'PENIMBUNAN',$PENIMBUNAN);
			AddField($xmldoc ,'KODE_VALUTA',$KODE_VALUTA); // get the requested page 
			AddField($xmldoc ,'NDPBM',$NDPBM); // get the requested page 
			AddField($xmldoc ,'FOB',$FOB);
			AddField($xmldoc ,'FREIGHT',$FREIGHT); // get the requested page 
			AddField($xmldoc ,'KODE_ASURANSI',$KODE_ASURANSI); // get the requested page 
			AddField($xmldoc ,'ASURANSI',$ASURANSI); // get the requested page 
			AddField($xmldoc ,'CIF',$CIF);
			AddField($xmldoc ,'CIF_RUPIAH',$CIF_RUPIAH);
			AddField($xmldoc ,'JUMLAH_KONTAINER',$JUMLAH_KONTAINER); // get the requested page 
			AddField($xmldoc ,'JUMLAH_KEMASAN',$JUMLAH_KEMASAN);
			AddField($xmldoc ,'JUMLAH_BARANG',$JUMLAH_BARANG); // get the requested page 
			AddField($xmldoc ,'BRUTO',$BRUTO); // get the requested page 
			AddField($xmldoc ,'NETTO',$NETTO); // get the requested page 
			AddField($xmldoc ,'VOLUME',$VOLUME); // get the requested page 
			AddField($xmldoc ,'KEMASAN',$KEMASAN); // get the requested page 
			AddField($xmldoc ,'KODE_DOKUMEN_PABEAN',$KODE_DOKUMEN_PABEAN); // get the requested page 
			AddField($xmldoc ,'bc_prefix','40'); // get the requested page 

		 

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

		$ID_HEADER 					= isset($_POST['ID_HEADER'])?$_POST['ID_HEADER']:'-1'; // get the requested page 
		$NOMOR_AJU 					= isset($_POST['NOMOR_AJU'])?$_POST['NOMOR_AJU']:''; // get the requested page 
		$PJT 						= isset($_POST['PJT'])?$_POST['PJT']:''; // get the requested page 
		$NOMOR_DAFTAR 				= isset($_POST['NOMOR_DAFTAR'])?$_POST['NOMOR_DAFTAR']:''; // get the requested page 
		$TANGGAL_DAFTAR 			= isset($_POST['TANGGAL_DAFTAR'])?$_POST['TANGGAL_DAFTAR']:''; // get the requested page 
		$NOMOR_BILLING				= isset($_POST['NOMOR_BILLING'])?$_POST['NOMOR_BILLING']:''; // get the requested page 
		$TANGGAL_BILLING 			= isset($_POST['TANGGAL_BILLING'])?$_POST['TANGGAL_BILLING']:''; // get the requested page 
		$KODE_PELA_BONGKAR 			= isset($_POST['KODE_PELA_BONGKAR'])?$_POST['KODE_PELA_BONGKAR']:''; // get the requested page 
		$KODE_KANTOR_BONGKAR 		= isset($_POST['KODE_KANTOR_BONGKAR'])?$_POST['KODE_KANTOR_BONGKAR']:''; // get the requested page 
		$KODE_TUJUAN 				= isset($_POST['KODE_TUJUAN'])?$_POST['KODE_TUJUAN']:''; // get the requested page 
		$ID_PEMASOK					= isset($_POST['ID_PEMASOK'])?$_POST['ID_PEMASOK']:'';
		$KODE_ID_PEMASOK			= isset($_POST['KODE_ID_PEMASOK'])?$_POST['KODE_ID_PEMASOK']:'';
		$NAMA_PEMASOK				= isset($_POST['NAMA_PEMASOK'])?$_POST['NAMA_PEMASOK']:'';
		$ALAMAT_PEMASOK				= isset($_POST['ALAMAT_PEMASOK'])?$_POST['ALAMAT_PEMASOK']:'';
		$KODE_NEGARA_PEMASOK		= isset($_POST['KODE_NEGARA_PEMASOK'])?$_POST['KODE_NEGARA_PEMASOK']:'';
		$ID_PENERIMA_BARANG			= isset($_POST['ID_PENERIMA_BARANG'])?$_POST['ID_PENERIMA_BARANG']:'';
		$KODE_ID_PENERIMA_BARANG	= isset($_POST['KODE_ID_PENERIMA_BARANG'])?$_POST['KODE_ID_PENERIMA_BARANG']:'';
		$NAMA_PENERIMA_BARANG		= isset($_POST['NAMA_PENERIMA_BARANG'])?$_POST['NAMA_PENERIMA_BARANG']:'';
		$NOMOR_IJIN_TPB_PENERIMA	= isset($_POST['NOMOR_IJIN_TPB_PENERIMA'])?$_POST['NOMOR_IJIN_TPB_PENERIMA']:'';				
		$KODE_JENIS_API_PENERIMA	= isset($_POST['KODE_JENIS_API_PENERIMA'])?$_POST['KODE_JENIS_API_PENERIMA']:'';
		$ID_PEMILIK 				= isset($_POST['ID_PEMILIK'])?$_POST['ID_PEMILIK']:'';
		$KODE_ID_PEMILIK			= isset($_POST['KODE_ID_PEMILIK'])?$_POST['KODE_ID_PEMILIK']:'';
		$NAMA_PEMILIK				= isset($_POST['NAMA_PEMILIK'])?$_POST['NAMA_PEMILIK']:'';
		$ALAMAT_PEMILIK				= isset($_POST['ALAMAT_PEMILIK'])?$_POST['ALAMAT_PEMILIK']:'';
		$KODE_JENIS_API_PEMILIK		= isset($_POST['KODE_JENIS_API_PEMILIK'])?$_POST['KODE_JENIS_API_PEMILIK']:'';
		$ID_PPJK	 				= isset($_POST['ID_PPJK'])?$_POST['ID_PPJK']:'';
		$KODE_ID_PPJK				= isset($_POST['KODE_ID_PPJK'])?$_POST['KODE_ID_PPJK']:'';
		$NAMA_PPJK					= isset($_POST['NAMA_PPJK'])?$_POST['NAMA_PPJK']:'';
		$ALAMAT_PPJK				= isset($_POST['ALAMAT_PPJK'])?$_POST['ALAMAT_PPJK']:'';
		$CARA_ANGKUT				= isset($_POST['CARA_ANGKUT'])?$_POST['CARA_ANGKUT']:'';
		$SARANA_ANGKUT 				= isset($_POST['SARANA_ANGKUT'])?$_POST['SARANA_ANGKUT']:'';
		$NOMOR_VOY_FLIGHT			= isset($_POST['NOMOR_VOY_FLIGHT'])?$_POST['NOMOR_VOY_FLIGHT']:'';
		$KODE_NEGARA_TUJUAN			= isset($_POST['KODE_NEGARA_TUJUAN'])?$_POST['KODE_NEGARA_TUJUAN']:'';
		$KODE_PEL_MUAT 				= isset($_POST['KODE_PEL_MUAT'])?$_POST['KODE_PEL_MUAT']:'';
		$KODE_PEL_TRANSIT			= isset($_POST['KODE_PEL_TRANSIT'])?$_POST['KODE_PEL_TRANSIT']:'';
		$KODE_PEL_BONGKAR 			= isset($_POST['KODE_PEL_BONGKAR'])?$_POST['KODE_PEL_BONGKAR']:'';
		$KODE_FASILITAS				= isset($_POST['KODE_FASILITAS'])?$_POST['KODE_FASILITAS']:'';
		$KODE_LC					= isset($_POST['KODE_LC'])?$_POST['KODE_LC']:'';
		$KODE_AWB					= isset($_POST['KODE_AWB'])?$_POST['KODE_AWB']:'';
		$KODE_BC11					= isset($_POST['KODE_BC11'])?$_POST['KODE_BC11']:'';
		$TANGGAL_BC11				= isset($_POST['TANGGAL_BC11'])?$_POST['TANGGAL_BC11']:'';
		$SUBPOS_BC11				= isset($_POST['SUBPOS_BC11'])?$_POST['SUBPOS_BC11']:'';
		$SUBSUBPOS_BC11				= isset($_POST['SUBSUBPOS_BC11'])?$_POST['SUBSUBPOS_BC11']:'';
		$PENIMBUNAN					= isset($_POST['PENIMBUNAN'])?$_POST['PENIMBUNAN']:'';
		$KODE_VALUTA				= isset($_POST['KODE_VALUTA'])?$_POST['KODE_VALUTA']:''; // get the requested page 
		$NDPBM						= isset($_POST['NDPBM'])?$_POST['NDPBM']:'0'; // get the requested page 
		$FOB						= isset($_POST['FOB'])?$_POST['FOB']:'0';
		$FREIGHT 					= isset($_POST['FREIGHT'])?$_POST['FREIGHT']:'0'; // get the requested page 
		$KODE_ASURANSI 				= isset($_POST['KODE_ASURANSI'])?$_POST['KODE_ASURANSI']:''; // get the requested page 
		$ASURANSI 					= isset($_POST['ASURANSI'])?$_POST['ASURANSI']:'0'; // get the requested page 
		$CIF 						= isset($_POST['CIF'])?$_POST['CIF']:'0';
		$CIF_RUPIAH 				= isset($_POST['CIF_RUPIAH'])?$_POST['CIF_RUPIAH']:'0';
		$JUMLAH_KONTAINER			= isset($_POST['JUMLAH_KONTAINER'])?$_POST['JUMLAH_KONTAINER']:'0'; // get the requested page 
		$JUMLAH_KEMASAN				= isset($_POST['JUMLAH_KEMASAN'])?$_POST['JUMLAH_KEMASAN']:'0';
		$JUMLAH_BARANG 				= isset($_POST['JUMLAH_BARANG'])?$_POST['JUMLAH_BARANG']:'0'; // get the requested page 
		$BRUTO		 				= isset($_POST['BRUTO'])?$_POST['BRUTO']:'0'; // get the requested page 
		$NETTO						= isset($_POST['NETTO'])?$_POST['NETTO']:'0'; // get the requested page 
		$VOLUME						= isset($_POST['VOLUME'])?$_POST['VOLUME']:'0'; // get the requested page 
		$KEMASAN	 				= isset($_POST['KEMASAN'])?$_POST['KEMASAN']:''; // get the requested page 
		$KODE_DOKUMEN_PABEAN		= isset($_POST['KODE_DOKUMEN_PABEAN'])?$_POST['KODE_DOKUMEN_PABEAN']:''; // get the requested page 
			



			
				$SPT='SPX_HEADER_BC23_UPDATE'; //'SP_T_BC_FROM_PO_CREATEX';  //($ID_HEADER=='-1')?'SP_T_BC_FROM_PO_CREATEX':'SP_T_BC_FROM_PO_CREATEX';
				
				$xmldoc =  XMLbasic('json');  
				AddField($xmldoc ,'ID_HEADER',$ID_HEADER);// get the requested page 
				AddField($xmldoc ,'NOMOR_AJU',$NOMOR_AJU); // get the requested page 
				AddField($xmldoc ,'PJT',$PJT); // get the requested page 
				AddField($xmldoc ,'NOMOR_DAFTAR',$NOMOR_DAFTAR); // get the requested page 
				AddField($xmldoc ,'TANGGAL_DAFTAR',$TANGGAL_DAFTAR); // get the requested page 
				AddField($xmldoc ,'NOMOR_BILLING',$NOMOR_BILLING); // get the requested page 
				AddField($xmldoc ,'TANGGAL_BILLING',$TANGGAL_BILLING); // get the requested page 
				AddField($xmldoc ,'KODE_ASAL_BARANG',$KODE_PELA_BONGKAR); // get the requested page 
				AddField($xmldoc ,'KODE_KANTOR_BONGKAR',$KODE_KANTOR_BONGKAR); // get the requested page 
				AddField($xmldoc ,'KODE_TUJUAN',$KODE_TUJUAN); // get the requested page 
				AddField($xmldoc ,'ID_PEMASOK',$ID_PEMASOK);
				AddField($xmldoc ,'KODE_ID_PEMASOK',$KODE_ID_PEMASOK);
				AddField($xmldoc ,'NAMA_PEMASOK',$NAMA_PEMASOK);
				AddField($xmldoc ,'ALAMAT_PEMASOK',$ALAMAT_PEMASOK);
				AddField($xmldoc ,'KODE_NEGARA_PEMASOK',$KODE_NEGARA_PEMASOK);
				AddField($xmldoc ,'ID_PENERIMA_BARANG',$ID_PENERIMA_BARANG);
				AddField($xmldoc ,'KODE_ID_PENERIMA_BARANG',$KODE_ID_PENERIMA_BARANG);
				AddField($xmldoc ,'NAMA_PENERIMA_BARANG',$NAMA_PENERIMA_BARANG);
				AddField($xmldoc ,'NOMOR_IJIN_TPB_PENERIMA',$NOMOR_IJIN_TPB_PENERIMA);				
				AddField($xmldoc ,'KODE_JENIS_API_PENERIMA',$KODE_JENIS_API_PENERIMA);
				AddField($xmldoc ,'ID_PEMILIK',$ID_PEMILIK);
				AddField($xmldoc ,'KODE_ID_PEMILIK',$KODE_ID_PEMILIK);
				AddField($xmldoc ,'NAMA_PEMILIK',$NAMA_PEMILIK);
				AddField($xmldoc ,'ALAMAT_PEMILIK',$ALAMAT_PEMILIK);
				AddField($xmldoc ,'KODE_JENIS_API_PEMILIK',$KODE_JENIS_API_PEMILIK);
				AddField($xmldoc ,'ID_PPJK',$ID_PPJK);
				AddField($xmldoc ,'KODE_ID_PPJK',$KODE_ID_PPJK);
				AddField($xmldoc ,'NAMA_PPJK',$NAMA_PPJK);
				AddField($xmldoc ,'ALAMAT_PPJK',$ALAMAT_PPJK);
				AddField($xmldoc ,'CARA_ANGKUT',$CARA_ANGKUT);
				AddField($xmldoc ,'SARANA_ANGKUT',$SARANA_ANGKUT);
				AddField($xmldoc ,'NOMOR_VOY_FLIGHT',$NOMOR_VOY_FLIGHT);
				AddField($xmldoc ,'KODE_NEGARA_TUJUAN',$KODE_NEGARA_TUJUAN);
				AddField($xmldoc ,'KODE_PEL_MUAT',$KODE_PEL_MUAT);
				AddField($xmldoc ,'KODE_PEL_TRANSIT',$KODE_PEL_TRANSIT);
				AddField($xmldoc ,'KODE_PEL_BONGKAR',$KODE_PEL_BONGKAR);
				AddField($xmldoc ,'KODE_FASILITAS',$KODE_FASILITAS);
				AddField($xmldoc ,'KODE_LC',$KODE_LC);
				AddField($xmldoc ,'KODE_AWB',$KODE_AWB);
				AddField($xmldoc ,'KODE_BC11',$KODE_BC11);
				AddField($xmldoc ,'TANGGAL_BC11',$TANGGAL_BC11);
				AddField($xmldoc ,'SUBPOS_BC11',$SUBPOS_BC11);
				AddField($xmldoc ,'SUBSUBPOS_BC11',$SUBSUBPOS_BC11);
				AddField($xmldoc ,'PENIMBUNAN',$PENIMBUNAN);
				AddField($xmldoc ,'KODE_VALUTA',$KODE_VALUTA); // get the requested page 
				AddField($xmldoc ,'NDPBM',$NDPBM); // get the requested page 
				AddField($xmldoc ,'FOB',$FOB);
				AddField($xmldoc ,'FREIGHT',$FREIGHT); // get the requested page 
				AddField($xmldoc ,'KODE_ASURANSI',$KODE_ASURANSI); // get the requested page 
				AddField($xmldoc ,'ASURANSI',$ASURANSI); // get the requested page 
				AddField($xmldoc ,'CIF',$CIF);
				AddField($xmldoc ,'CIF_RUPIAH',$CIF_RUPIAH);
				AddField($xmldoc ,'JUMLAH_KONTAINER',$JUMLAH_KONTAINER); // get the requested page 
				AddField($xmldoc ,'JUMLAH_KEMASAN',$JUMLAH_KEMASAN);
				AddField($xmldoc ,'JUMLAH_BARANG',$JUMLAH_BARANG); // get the requested page 
				AddField($xmldoc ,'BRUTO',$BRUTO); // get the requested page 
				AddField($xmldoc ,'NETTO',$NETTO); // get the requested page 
				AddField($xmldoc ,'VOLUME',$VOLUME); // get the requested page 
				AddField($xmldoc ,'KEMASAN',$KEMASAN); // get the requested page 
				AddField($xmldoc ,'KODE_DOKUMEN_PABEAN',$KODE_DOKUMEN_PABEAN); // get the requested page 
				AddField($xmldoc ,'bc_prefix','23'); // get the requested page 


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

 }