<?php class CT_pasi_ceisa_bc_out_from_sa 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';   
				$mode = isset($_POST['mode'])?$_POST['mode']:'0';   
				$data['cust_code'] = $cust_code;
				$data['id_header'] = $id_header;
				$data['bc_prefix'] = $bc_prefix;
				$data['mode'] = $mode;
				
				$data['use_kurs'] = '0';
				if ($bc_prefix=='27' || $bc_prefix=='25')
					$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_out/view_pasi_ceisa_bc_out_from_sa', $data);
	}   
	
	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_sa(){	 
				$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
				$status_module = isset($_POST['status_module'])?$_POST['status_module']:'';  //1 add
				$status = isset($_POST['status'])?$_POST['status']:'';  //1 add
				$status_name = isset($_POST['status_name'])?$_POST['status_name']:'';  //1 add
				$is_get = isset($_POST['is_get'])?$_POST['is_get']:'';  //1 add
				$mode = isset($_POST['mode'])?$_POST['mode']:'0';   
			
				$data['cust_code'] = $cust_code;
				$data['id_header'] = $id_header;
				$data['bc_prefix'] = $bc_prefix;
				$data['status_module'] = $status_module;
				$data['status'] = $status;
				$data['status_name'] = $status_name;
				$data['is_get'] = $is_get;
				$data['mode'] = $mode;
			
				$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_out/view_pasi_ceisa_bc_out_from_sa_sa_data', $data);
	}   
	
	function view_notul(){	 
				$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:'-1';   
				$id_header = isset($_POST['id_header'])?$_POST['id_header']:die('Pilih Dokumen ');    
				$data['id_header'] = $id_header;
				$data['bc_prefix'] = $bc_prefix;
				  
			 	$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_out/view_pasi_ceisa_bc_out_from_sa_notul_data', $data);
	}  

	function view_sa_suai(){	 
				$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_out/view_pasi_ceisa_bc_out_from_sa_sa_data_suai', $data);
	}  
	

	
		
	function view_item(){	 
				$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
				$is_get = isset($_POST['is_get'])?$_POST['is_get']:'';  //1 add
				$data['cust_code'] = $cust_code;
				$data['id_header'] = $id_header;
				$data['bc_prefix'] = $bc_prefix;
				$data['is_get'] = $is_get;
				$this->load->view('pasi_ceisa_bc_out/view_pasi_ceisa_bc_out_from_sa_item_data', $data);
	}   
	
		function view_item_compare_ceisa(){	
	
				$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
				$is_get = isset($_POST['is_get'])?$_POST['is_get']:'';  //1 add
				$cr=''. number_format('1234.56', 2); 
				$data['thousandsSeparator'] = substr($cr,1,1);
				$data['decimalSeparator'] = substr($cr,5,1);
				$data['cust_code'] = $cust_code;
				$data['id_header'] = $id_header;
				$data['bc_prefix'] = $bc_prefix;
				$data['is_get'] = $is_get;
				$this->load->view('pasi_ceisa_bc_out/view_pasi_ceisa_bc_item_compare_ceisa_info', $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_out/view_pasi_ceisa_bc_out_from_sa_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_out/view_pasi_ceisa_bc_out_header_module', $data);
	}     
    function loaddata_cust(){; 
		$def_col= array(); 
		$spt='dbo.SP_T_CUST_SA'; 
		$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_CUST_SA',$sts,$des,$rows,$detail);  
  		echo $rows; 
		}
		
		
	    function loaddata_sa(){; 
		$def_col= array(); 
		$spt='dbo.SP_T_SA'; 
		$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"=>"int", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","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 
		$mode = isset($_POST['mode'])?$_POST['mode']:'0';   
  	  
		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_SA',$sts,$des,$rows,$detail);  
  		echo $rows; 
		}
		
	    function loaddata_item(){; 
		$def_col= array(); 
		$spt='dbo.SP_T_BC_FROM_SA_VIEW_BARANG'; 
		$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"=>"int", "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"=>"int", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"text", "bypassvalue"=>"");
 		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"int", "bypassvalue"=>"");
		$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"=>"");
 		$def_col['im']=array("db" => "im" ,"sc" => "im","ctype"=>"int", "bypassvalue"=>"-100");
		
 		$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_SA_VIEW_BARANG',$sts,$des,$rows,$detail);  
  		echo $rows; 
		}
		
		function loaddata_item_compare_ceisa(){; 
		$def_col= array(); 
		$spt='dbo.SP_T_BC_FROM_SA_VIEW_COMPARE_CEISA'; 
		$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"=>"-100");
		$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"=>"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"=>"text", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","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 
		$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();   
	 	// print_r($str);die();
				exec_sp_json($xmldoc, 'dbo.SP_T_BC_FROM_SA_VIEW_COMPARE_CEISA',$sts,$des,$rows,$detail);  
  		echo $rows; 
		}
		
		
	    function loaddata_dokumen(){; 
		$def_col= array(); 
	 	$spt='dbo.SP_T_BC_FROM_SA_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_SA_VIEW_DOKUMEN',$sts,$des,$rows,$detail);  
  		echo $rows; 
		}
		
	    function load_header_module_for_import(){; 
		$def_col= array(); 
	 	$spt='dbo.SP_T_HEADER_BC_OUT_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['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"=>"");
  		$def_col['ri']=array("db" => "ri" ,"sc" => "ri","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_HEADER_BC_OUT_MODULE',$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']:'1'; // get the requested page 
		        $bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']: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(pasi_db_name('.').'dbo.SP_T_BC_FROM_SA_CREATE'); 
				AddField($xmldoc ,'cust_code',$cust_code);
				AddField($xmldoc ,'bc_prefix',$bc_prefix);
				AddField($xmldoc ,'ndpdm',$kurs);
				
				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_CREATE',$sts,$des,$rows,$detail); 
				 connectwebservice($xmldoc->saveXML(), '',$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 edit_notul(){
			    $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();  
		//		print_r($str );die();
				 exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_SA_NOTUL',$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(pasi_db_name('.').'dbo.SP_T_BC_FROM_SA_CANCEL'); 
				AddField($xmldoc ,'id_header',$id_header);
				AddField($xmldoc ,'status_info',$status_info );
				$str = $xmldoc->saveXML();
				connectwebservice($xmldoc->saveXML(), '',$sts,$des,$rows,$detail); 
 	//		 exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_SA_CANCEL',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		
	    // function change_package(){ 
			    // $id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen yang akan di cancel');; // get the requested page 
				// $data_package              = isset($_POST['data_package'])?$_POST['data_package']:'';  
   	 
				// $xmldoc =  XMLbasic(pasi_db_name('.').'dbo.SP_T_BC_FROM_SA_CHANGE_PACKAGE'); 
				// AddField($xmldoc ,'id_header',$id_header); 
					
				// for ($i = 0; $i <  count($data_package); $i++) {
					  // $this->add_package_list($xmldoc,$data_package[$i]['rID'],$data_package[$i]['r13']);
				// }
				// $str = $xmldoc->saveXML();
				// var_dump($str);die();
				// exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_SA_CHANGE_PACKAGE',$sts,$des,$rows,$detail); 
				// echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		// }
		
		
		
	    function change_package(){ 
			    $id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen yang akan di cancel');; // get the requested page 
				$data_package              = isset($_POST['data_package'])?$_POST['data_package']:'';  
   	 
				$xmldoc =  XMLbasic(pasi_db_name('.').'dbo.SP_T_BC_FROM_SA_CHANGE_PACKAGE'); 
				AddField($xmldoc ,'id_header',$id_header); 
					
				for ($i = 0; $i <  count($data_package); $i++) {
					  $this->add_package_list($xmldoc,$data_package[$i]['rID'],$data_package[$i]['r13'],$data_package[$i]['r14']);
				}
				$str = $xmldoc->saveXML();
				//var_dump($str);die();
				exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_SA_CHANGE_PACKAGE',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		
	    function clear_package(){ 
			    $id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen yang akan di cancel');; // get the requested page 
				$data_package              = isset($_POST['data_package'])?$_POST['data_package']:'';  
   	 
				$xmldoc =  XMLbasic(pasi_db_name('.').'dbo.SP_T_BC_FROM_SA_CLEAR_PACKAGE'); 
				AddField($xmldoc ,'id_header',$id_header);  
				$str = $xmldoc->saveXML(); 
				exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_SA_CLEAR_PACKAGE',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		
	   function add_package_list(&$doc
		,$rid
		,$package_qty
		,$package_code
		)
		{
		 
		$node = $doc->getElementsByTagName('param')->item(0);
		$field = $node->getElementsByTagName('field')->item(0);
		
		if ($field->getElementsByTagName('package')->item(0)!=null){
			$dtl_bahan = $field->getElementsByTagName('package')->item(0);
		 
		}
		else {
			$dtl_bahan = $doc->createElement('package', '');
			$field->appendChild($dtl_bahan);
		};

			$element = $doc->createElement('lst', '');
			$element->setAttribute('rID',$rid); 
			$element->setAttribute('r13',$package_qty); 
			$element->setAttribute('r14',$package_code); 
				
			$dtl_bahan->appendChild($element);
		
		 
		
	}
		
	   // function add_package_list(&$doc
		// ,$rid
		// ,$package
		// )
		// {
		 
		// $node = $doc->getElementsByTagName('param')->item(0);
		// $field = $node->getElementsByTagName('field')->item(0);
		
		// if ($field->getElementsByTagName('package')->item(0)!=null){
			// $dtl_bahan = $field->getElementsByTagName('package')->item(0);
		 
		// }
		// else {
			// $dtl_bahan = $doc->createElement('package', '');
			// $field->appendChild($dtl_bahan);
		// };

			// $element = $doc->createElement('lst', '');
			// $element->setAttribute('rID',$rid); 
			// $element->setAttribute('r13',$package); 
				
			// $dtl_bahan->appendChild($element);
		
		 
		
	// }
 		
	    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_SA_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_SA_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_SA_MAPPING_CUSTOMER',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		
		
		 function update_mapping_item_manual(){ 
			    $tpb_out_barang_id = isset($_POST['tpb_out_barang_id'])?$_POST['tpb_out_barang_id']:die('pilih item yang akan di mapping manual');; // get the requested page 
			    $map_item_id = isset($_POST['map_item_id'])?$_POST['map_item_id']:die('pilih customer mapping');; // get the requested page 
				$map_type_item_id = isset($_POST['map_type_item_id'])?$_POST['map_type_item_id']:die('pilih customer mapping');; // get the requested page 
		 		$xmldoc =  XMLbasic('json'); 
				AddField($xmldoc ,'tpb_out_barang_id',$tpb_out_barang_id);
				AddField($xmldoc ,'map_item_id',$map_item_id);
				AddField($xmldoc ,'map_type_item_id',$map_type_item_id);
		  		$str = $xmldoc->saveXML();
			 	// print_r($str);die();
				 exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_SA_MAPPING_ITEM_MANUAL',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		
	    function update_mapping_item_auto(){ 
			    $id_header = isset($_POST['id_header'])?$_POST['id_header']:die('pilih dokumen yang akan di mapping Auto');; // 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_SA_MAPPING_ITEM_AUTO',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		  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 
		        $compare_data = isset($_POST['compare_data'])?$_POST['compare_data']:'1'; // get the requested page 
				
				$surat_jalan_no = isset($_POST['surat_jalan_no'])?$_POST['surat_jalan_no']:'';; // get the requested page 
		        $surat_jalan_date = isset($_POST['surat_jalan_date'])?$_POST['surat_jalan_date']:'01-01-1900';; // get the requested page 
			  
				$xmldoc =  XMLbasic('json'); 
				AddField($xmldoc ,'id_header',$id_header);
		 		AddField($xmldoc ,'compare_data',$compare_data);
				AddField($xmldoc ,'surat_jalan_no',$surat_jalan_no);
		 		AddField($xmldoc ,'surat_jalan_date',$surat_jalan_date);
		 		$str = $xmldoc->saveXML();
			 	//print_r($str);die();
				 exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_SA_FINISH',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		
		
		function get_surat_jalan_finish(){
			$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();  
			exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_SA_GET_SURAT_JALAN_FINISH',$sts,$des,$rows,$detail);  
			echo json_encode(
			array('valid'=>($sts=='00'?true:false)
			,'stsno' => $sts
			, 'stsmsg' => $des
			, 'data' => $detail
			)); 
	}
	
	function get_surat_jalan(){
			$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();  
			exec_sp_array($xmldoc, 'dbo.SP_T_BC_FROM_SA_GET_SURAT_JALAN',$sts,$des,$rows,$detail);  
			echo json_encode(
			array('valid'=>($sts=='00'?true:false)
			,'stsno' => $sts
			, 'stsmsg' => $des
			, 'data' => $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 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 import_data_from_module(){
			    $bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']: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','0');
			 	
				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_GET_FROM_MODULE',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		
		
 }