<?php
class CT_gudang_out_data 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(){
		
		$this->load->view('pasi_ceisa_gudang/view_gudang');
	} 
	
	function loaddata_gudang_out(){; 
		$def_col= array();  //SP_T_HEADER_BC_23 //SP_T_HEADER_BELI
		$spt='dbo.SPX_GUDANG_OUT_ALL'; 
		$def_col['rID']=array("db" => "rID" ,"sc" => "rID","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"-100");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"-100");
		$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"=>"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"=>"text", "bypassvalue"=>"");
		$def_col['r100']=array("db" => "r100" ,"sc" => "r100","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 
  	  
		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); 
  		$adaSearchStatus=0;
		
        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');  
									  if (($fcr['sc'])=='r2' || ($fcr['sc'])=='r1'){
										$adaSearchStatus=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'); 
							}  
						} 
                 } 
             } 
	   }  
  
		if ($adaSearchStatus==0){
			addSearchNum($xmldoc,'r1','-1','3','-1'); 
		}
		$str = $xmldoc->saveXML(); 
	//	 print_r($adaSearchStatus);		SP_T_HEADER_BELI
	//	 print_r($str);die(); SP_T_HEADER_BC_23
	 	 exec_sp_json($xmldoc, 'dbo.SPX_GUDANG_OUT_ALL',$sts,$des,$rows,$detail);  
	 	echo $rows; 
		}


  
		function loaddata_gudang_out_lot(){; 
			$def_col= array();  //SP_T_HEADER_BC_23 //SP_T_HEADER_BELI
			$spt='dbo.SPX_GUDANG_OUT_LOT'; 
			$def_col['rID']=array("db" => "rID" ,"sc" => "rID","ctype"=>"int", "bypassvalue"=>"");
			$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"-100");
			$def_col['r2']=array("db" => "r2" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"-100");
			$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"=>"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"=>"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 
			
			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); 
			  $adaSearchStatus=0;
			
			  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');  
										  if (($fcr['sc'])=='r4' || ($fcr['sc'])=='r1'){
											$adaSearchStatus=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'); 
								}  
							} 
					 } 
				 } 
		   }  
	  
			if ($adaSearchStatus==0){
				addSearchNum($xmldoc,'r1','-1','3','-1'); 
			}
			$str = $xmldoc->saveXML(); 
		//	 print_r($adaSearchStatus);		SP_T_HEADER_BELI
		//	 print_r($str);die(); //SP_T_HEADER_BC_23
			  exec_sp_json($xmldoc, 'dbo.SPX_GUDANG_OUT_LOT',$sts,$des,$rows,$detail);  
			 echo $rows; 
			}
	
			












	    function loaddata_material(){; 
			$def_col= array(); 
			$spt='dbo.SPX_LIST_MATERIAL'; 
			$def_col['rID']=array("db" => "rID" ,"sc" => "rID","ctype"=>"int", "bypassvalue"=>"");
			$def_col['ri']=array("db" => "ri" ,"sc" => "ri","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"=>"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"=>"text", "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"=>"");
			$def_col['i5']=array("db" => "i5" ,"sc" => "i5","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 
		 
			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.SPX_LIST_MATERIAL',$sts,$des,$rows,$detail);  
			  echo $rows; 
			}
			



	
		
		


	

function __purpose($bc_prefix){; 
	$spt='dbo.MG_MS_CMB_PURPOSE'; 
	$xmldoc =  XMLbasic($spt); 
		AddField($xmldoc ,'bc_prefix',$bc_prefix); 
		
	$str = $xmldoc->saveXML(); 
	// print_r($adaSearchStatus);		
	// print_r($str);die();
		wh_exec_sp_json($xmldoc, $spt,$sts,$des,$rows,$detail);  
		return $rows; 
	}
	

function __type_item($bc_prefix){; 
	$spt='dbo.MG_MS_CMB_PURPOSE'; 
	$xmldoc =  XMLbasic($spt); 
		AddField($xmldoc ,'bc_prefix',$bc_prefix); 
		
	$str = $xmldoc->saveXML(); 
	// print_r($adaSearchStatus);		
	// print_r($str);die();
		wh_exec_sp_json($xmldoc, $spt,$sts,$des,$rows,$detail);  
		return $rows; 
	}
	
function __type_price($bc_prefix){; 
	$spt='dbo.MG_MS_CMB_TYPE_PRICE'; 
	$xmldoc =  XMLbasic($spt); 
		AddField($xmldoc ,'bc_prefix',$bc_prefix); 
		
	$str = $xmldoc->saveXML(); 
	// print_r($adaSearchStatus);		
	// print_r($str);die();
		wh_exec_sp_json($xmldoc, $spt,$sts,$des,$rows,$detail);  
		return $rows; 
	}
		
				

	function save_header(){  
		

		$ID_HEADER 					= isset($_POST['ID_HEADER'])?$_POST['ID_HEADER']:'-1'; // get the requested page 
		$NOMOR_PO 					= isset($_POST['NOMOR_PO'])?$_POST['NOMOR_PO']:''; // get the requested page 
		$NOMOR_DO 					= isset($_POST['NOMOR_DO'])?$_POST['NOMOR_DO']:''; // get the requested page 
		$TANGGAL_DO		 			= isset($_POST['TANGGAL_DO'])?$_POST['TANGGAL_DO']:''; // get the requested page 
		$NOMOR_INVOICE 					= isset($_POST['NOMOR_INVOICE'])?$_POST['NOMOR_INVOICE']:''; // get the requested page 
		$NOMOR_EFAKTUR 					= isset($_POST['NOMOR_EFAKTUR'])?$_POST['NOMOR_EFAKTUR']:''; // get the requested page 
		$SUPPLIER_CODE				= isset($_POST['SUPPLIER_CODE'])?$_POST['SUPPLIER_CODE']:''; // get the requested page 
		$SUPPLIER_NAME				= isset($_POST['SUPPLIER_NAME'])?$_POST['SUPPLIER_NAME']:''; // get the requested page 
  		



			
				$SPT='SP_T_BELI_ADD'; //'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_PO',$NOMOR_PO); // get the requested page 
				AddField($xmldoc ,'NOMOR_DO',$NOMOR_DO); // get the requested page 
				AddField($xmldoc ,'TANGGAL_DO',$TANGGAL_DO); // get the requested page 
				AddField($xmldoc ,'NOMOR_INVOICE',$NOMOR_INVOICE); // get the requested page 
				AddField($xmldoc ,'NOMOR_EFAKTUR',$NOMOR_EFAKTUR); // get the requested page 
				AddField($xmldoc ,'SUPPLIER_CODE',$SUPPLIER_CODE); // get the requested page 
				AddField($xmldoc ,'SUPPLIER_NAME',$SUPPLIER_NAME); // get the requested page 
  				AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));


				
				$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)
				); 
		}
		
	 function finish_header(){  
	
	
			$ID_HEADER 				= isset($_POST['ID_HEADER'])?$_POST['ID_HEADER']:'-1'; // get the requested page 
			$receive_no 					= isset($_POST['receive_no'])?$_POST['receive_no']:''; // get the requested page 
			$receive_date 			= isset($_POST['receive_date'])?$_POST['receive_date']:''; // get the requested page 
	
			$ndpbm_usd 			= isset($_POST['ndpbm_usd'])?$_POST['ndpbm_usd']:'0'; // get the requested page 
			$ndpbm_hdr 			= isset($_POST['ndpbm_hdr'])?$_POST['ndpbm_hdr']:'0'; // get the requested page 
		
			$finish_date 			= isset($_POST['finish_date'])?$_POST['finish_date']:''; // get the requested page 
			$finish_time 			= isset($_POST['finish_time'])?$_POST['finish_time']:''; // get the requested page 
						
			$SPT='MG_MS_BC_IN_FINISH';
			
			$xmldoc =  XMLbasic('json');  
			AddField($xmldoc ,'ID_HEADER',$ID_HEADER );
			AddField($xmldoc ,'receive_no',$receive_no );
			AddField($xmldoc ,'receive_date',$receive_date );
			AddField($xmldoc ,'ndpbm_usd',$ndpbm_usd );
			AddField($xmldoc ,'ndpbm_hdr',$ndpbm_hdr );
			AddField($xmldoc ,'finish_date',$finish_date );
			AddField($xmldoc ,'finish_time',$finish_time );
				
			$str = $xmldoc->saveXML();
				// print_r($str);die();
				wh_exec_sp_array($xmldoc, $SPT ,$sts,$des,$rows,$detail); 
			echo json_encode(array('valid'=>($sts=='00'?true:false)
			,'stsno' => $sts
			, 'stsmsg' => $des
			, 'detail' => $detail)
			); 
	}
					
	 function cancel_header(){  
					
	
			$ID_HEADER 				= isset($_POST['ID_HEADER'])?$_POST['ID_HEADER']:'-1'; // get the requested page 
			$info 					= isset($_POST['info'])?$_POST['info']:''; // get the requested page 
						
			$SPT='MG_MS_BC_IN_CANCEL';
			
			$xmldoc =  XMLbasic('json');  
			AddField($xmldoc ,'ID_HEADER',$ID_HEADER );
			AddField($xmldoc ,'info',$info ); 
				
			$str = $xmldoc->saveXML();
				// print_r($str);die();
				wh_exec_sp_array($xmldoc, $SPT ,$sts,$des,$rows,$detail); 
			echo json_encode(array('valid'=>($sts=='00'?true:false)
			,'stsno' => $sts
			, 'stsmsg' => $des
			, 'detail' => $detail)
			); 
	}
	
	function save_detail(){  
					
		
		$ID_HEADER 				= isset($_POST['ID_HEADER'])?$_POST['ID_HEADER']:'-1'; // get the requested page 
		$ID_BARANG 				= isset($_POST['ID_BARANG'])?$_POST['ID_BARANG']:'-1'; // get the requested page 

		$HARGA_PENYERAHAN 		= isset($_POST['HARGA_PENYERAHAN'])?$_POST['HARGA_PENYERAHAN']:''; // get the requested page 
		$JUMLAH_KEMASAN 		= isset($_POST['JUMLAH_KEMASAN'])?$_POST['JUMLAH_KEMASAN']:''; // get the requested page 
		$JUMLAH_SATUAN 			= isset($_POST['JUMLAH_SATUAN'])?$_POST['JUMLAH_SATUAN']:''; // get the requested page 
		$KODE_KEMASAN 			= isset($_POST['KODE_KEMASAN'])?$_POST['KODE_KEMASAN']:'0'; // get the requested page 
		$NETTO 					= isset($_POST['NETTO'])?$_POST['NETTO']:'0'; // get the requested page 
		$POS_TARIF 				= isset($_POST['POS_TARIF'])?$_POST['POS_TARIF']:'0'; // get the requested page 
		$SERI_BARANG 			= isset($_POST['SERI_BARANG'])?$_POST['SERI_BARANG']:'0'; // get the requested page 
		$VOLUME 				= isset($_POST['VOLUME'])?$_POST['VOLUME']:''; // get the requested page 
		$ms_item_id 			= isset($_POST['ms_item_id'])?$_POST['ms_item_id']:'-1'; // get the requested page 
		$KODE_NEGARA_ASAL 		= isset($_POST['KODE_NEGARA_ASAL'])?$_POST['KODE_NEGARA_ASAL']:''; // get the requested page 
			
		$BM 			 		= isset($_POST['BM'])?$_POST['BM']:''; // get the requested page 
		$PPNBM 					= isset($_POST['PPNBM'])?$_POST['PPNBM']:''; // get the requested page 
		$PPH 					= isset($_POST['PPH'])?$_POST['PPH']:''; // get the requested page 
		$PPN 					= isset($_POST['PPN'])?$_POST['PPN']:''; // get the requested page 
		$series 				= isset($_POST['series'])?$_POST['series']:''; // get the requested page 
		$TAHUN_PEMBUATAN 		= isset($_POST['TAHUN_PEMBUATAN'])?$_POST['TAHUN_PEMBUATAN']:''; // get the requested page 
		$po_no 					= isset($_POST['po_no'])?$_POST['po_no']:''; // get the requested page 
		$po_date 				= isset($_POST['po_date'])?$_POST['po_date']:''; // get the requested page 
		
		$SPT=($ID_BARANG=='-1')?'MG_MS_BC_IN_ITEM_ADD':'MG_MS_BC_IN_ITEM_EDIT';
		
		$xmldoc =  XMLbasic('json');  
		AddField($xmldoc ,'ID_HEADER',$ID_HEADER );
		AddField($xmldoc ,'ID_BARANG',$ID_BARANG );
		AddField($xmldoc ,'HARGA_PENYERAHAN',$HARGA_PENYERAHAN );
		AddField($xmldoc ,'JUMLAH_KEMASAN',$JUMLAH_KEMASAN );
		AddField($xmldoc ,'JUMLAH_SATUAN',$JUMLAH_SATUAN ); 
		AddField($xmldoc ,'KODE_KEMASAN',$KODE_KEMASAN ); 
		AddField($xmldoc ,'NETTO',$NETTO ); 
		AddField($xmldoc ,'POS_TARIF',$POS_TARIF ); 
		AddField($xmldoc ,'SERI_BARANG',$SERI_BARANG ); 
		AddField($xmldoc ,'VOLUME',$VOLUME ); 
		AddField($xmldoc ,'ms_item_id',$ms_item_id ); 
		AddField($xmldoc ,'KODE_NEGARA_ASAL',$KODE_NEGARA_ASAL ); 
		AddField($xmldoc ,'BM',$BM ); 
		AddField($xmldoc ,'PPNBM',$PPNBM ); 
		AddField($xmldoc ,'PPH',$PPH ); 
		AddField($xmldoc ,'PPN',$PPN );  ; 
		AddField($xmldoc ,'series',$series ); 
		AddField($xmldoc ,'TAHUN_PEMBUATAN',$TAHUN_PEMBUATAN );  
		AddField($xmldoc ,'po_no',$po_no ); 
		AddField($xmldoc ,'po_date',$po_date );  
		
		$str = $xmldoc->saveXML();
		// print_r($str);die();
			wh_exec_sp_array($xmldoc, $SPT ,$sts,$des,$rows,$detail); 
		echo json_encode(array('valid'=>($sts=='00'?true:false)
		,'stsno' => $sts
		, 'stsmsg' => $des
		, 'detail' => $detail)
		); 
		}
		
		
	function delete_detail(){  
		
		
		$ID_HEADER 				= isset($_POST['ID_HEADER'])?$_POST['ID_HEADER']:'-1'; // get the requested page 
		$ID_BARANG 				= isset($_POST['ID_BARANG'])?$_POST['ID_BARANG']:'-1'; // get the requested page 
	
		$SPT='MG_MS_BC_IN_ITEM_DELETE';
		
		$xmldoc =  XMLbasic('json');  
		AddField($xmldoc ,'ID_HEADER',$ID_HEADER );
		AddField($xmldoc ,'ID_BARANG',$ID_BARANG );
		
		$str = $xmldoc->saveXML();
		// print_r($str);die();
			wh_exec_sp_array($xmldoc, $SPT ,$sts,$des,$rows,$detail); 
		echo json_encode(array('valid'=>($sts=='00'?true:false)
		,'stsno' => $sts
		, 'stsmsg' => $des
		, 'detail' => $detail)
		); 
		}
		
		
			function mapping_all_item(){   
				$ID_HEADER 				= isset($_POST['ID_HEADER'])?$_POST['ID_HEADER']:'-1'; // get the requested page 
					$SPT='MG_MS_BC_IN_ITEM_MAPPING_AUTO';
				
				$xmldoc =  XMLbasic('json');  
				AddField($xmldoc ,'ID_HEADER',$ID_HEADER ); 
					
				$str = $xmldoc->saveXML();
					// print_r($str);die();
					wh_exec_sp_array($xmldoc, $SPT ,$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false)
				,'stsno' => $sts
				, 'stsmsg' => $des
				, 'detail' => $detail)
				); 
		}
		
					
	function create_bc_molts(){
			$supplier_id = isset($_POST['supplier_id'])?$_POST['supplier_id']:die('Pilih Customer');; // get the requested page 
				$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:die('Type BC tidak di ketahui');; // get the requested page 
			$lst_id = isset($_POST['lst_id'])?$_POST['lst_id']:die('pilih SA penyusun Dokument');; // get the requested page 
		
			$xmldoc =  XMLbasic('json'); 
			AddField($xmldoc ,'ms_supplier_customer_id',$supplier_id);
			AddField($xmldoc ,'bc_prefix',$bc_prefix); 
			
			for ($i = 0; $i <  count($lst_id); $i++) {
				$this->_insert_id_to_field($xmldoc,$lst_id[$i]);
			} 
			$str = $xmldoc->saveXML();  
		//print_r($str);die();
			wh_exec_sp_array($xmldoc, 'dbo.MG_MS_BC_IN_IMPORT_FROM_MOLTS',$sts,$des,$rows,$detail); 
			echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
	}
		
		
	function create_bc_invoce(){
			$supplier_id = isset($_POST['supplier_id'])?$_POST['supplier_id']:die('Pilih Customer');; // get the requested page 
				$bc_prefix = isset($_POST['bc_prefix'])?$_POST['bc_prefix']:die('Type BC tidak di ketahui');; // get the requested page 
			$lst_id = isset($_POST['lst_id'])?$_POST['lst_id']:die('pilih SA penyusun Dokument');; // get the requested page 
			$ms_manual_invoice_type_id = isset($_POST['invoice_prefix_id'])?$_POST['invoice_prefix_id']:'-1'; // get the direction 
				$KODE_VALUTA = isset($_POST['KODE_VALUTA'])?$_POST['KODE_VALUTA']:'-1'; // get the direction 
		
			$xmldoc =  XMLbasic('json'); 
			AddField($xmldoc ,'ms_supplier_customer_id',$supplier_id);
			AddField($xmldoc ,'bc_prefix',$bc_prefix); 
			AddField($xmldoc ,'ms_manual_invoice_type_id',$ms_manual_invoice_type_id); 
			AddField($xmldoc ,'KODE_VALUTA',$KODE_VALUTA); 
			
			for ($i = 0; $i <  count($lst_id); $i++) {
				$this->_insert_id_to_field($xmldoc,$lst_id[$i]);
			} 
			$str = $xmldoc->saveXML();  
			wh_exec_sp_array($xmldoc, 'dbo.MG_MS_BC_IN_IMPORT_FROM_INVOICE',$sts,$des,$rows,$detail); 
			echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
	}
 }