<?php class CT_ms_prod_car_line 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('ms_production/view_ms_prod_car_line');
	} 
	
	function view_new_item(){  
			$row_data=isset($_POST['row_data'])?$_POST['row_data']:null; 
	  		$data['row_data'] =$row_data;  
 			$this->load->view('ms_production/view_ms_prod_car_line_new',$data);
	} 
	 	 
		
	function view_item(){  
			$row_data=isset($_POST['row_data'])?$_POST['row_data']:null; 
	  		$data['row_data'] =$row_data;  
 			$this->load->view('ms_production/view_ms_prod_car_line_view_item',$data);
	} 
	 	 
			 
    function loaddata(){; 
		$def_col= array();    
		$spt='dbo.MG_MS_OUT_CAR_LINE_HEADER'; 
		$def_col['rID']=array("db" => "rID" ,"sc" => "rID","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r16","ctype"=>"int", "bypassvalue"=>"-100");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r4i']=array("db" => "r4i" ,"sc" => "r4i","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"=>"int", "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"=>"date", "bypassvalue"=>"");
		$def_col['r10']=array("db" => "r10" ,"sc" => "r10","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r11']=array("db" => "r11" ,"sc" => "r11","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r12']=array("db" => "r12" ,"sc" => "r12","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r13']=array("db" => "r13" ,"sc" => "r13","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r14']=array("db" => "r14" ,"sc" => "r14","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r17","ctype"=>"int", "bypassvalue"=>"");
 		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"int", "bypassvalue"=>"");
 		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","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 
  		$ms_type_id = isset($_POST['ms_type_id'])?$_POST['ms_type_id']:-1; // get the direction 
  	   
		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
 		 
		if (array_key_exists($sidx, $def_col)) {  
				$fsidx=$def_col[$sidx];
				$sidx=$fsidx['db'];
		}else{
				$sidx='rID'; //DEFAULT SORT KALU GA ADA
		}
        $sidx=$sidx.'='. $sord;
		  
		$xmldoc =  XMLbasic($spt); 
		paramViewJSON($xmldoc, $limit, $page,  $sidx, $sord); 
  		AddField($xmldoc ,'ms_type_id',$ms_type_id); 
		$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'])=='r1' || ($fcr['sc'])=='r16'){
										$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,'r16','-1','3','-1'); 
		}
  
  
		$str = $xmldoc->saveXML();   
		wh_exec_sp_json($xmldoc, $spt,$sts,$des,$rows,$detail);  
  		echo $rows; 
		}
		
				 
    function loaddata_detail(){; 
		$def_col= array();    
		$spt='dbo.MG_MS_OUT_CAR_LINE_DETAIL'; 
		$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"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3i']=array("db" => "r3i" ,"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"=>"int", "bypassvalue"=>"");
		$def_col['r5s']=array("db" => "r5s" ,"sc" => "r5s","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6r']=array("db" => "r6r" ,"sc" => "r6r","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"=>"int", "bypassvalue"=>"");
		$def_col['r_s']=array("db" => "r_s" ,"sc" => "r_s","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 
		
  		$header_id = isset($_POST['header_id'])?$_POST['header_id']:-1; // get the direction 
  	   
		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
 		 
		if (array_key_exists($sidx, $def_col)) {  
				$fsidx=$def_col[$sidx];
				$sidx=$fsidx['db'];
		}else{
				$sidx='rID'; //DEFAULT SORT KALU GA ADA
		}
        $sidx=$sidx.'='. $sord;
		  
		$xmldoc =  XMLbasic($spt); 
		paramViewJSON($xmldoc, $limit, $page,  $sidx, $sord); 
  		AddField($xmldoc ,'header_id',$header_id); 
		 
        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();   
		wh_exec_sp_json($xmldoc, $spt,$sts,$des,$rows,$detail);  
  		echo $rows; 
		}
					 
    function loaddata_detail_supply(){; 
		$def_col= array();    
			$spt='dbo.MG_MS_OUT_CAR_LINE_DETAIL_SUPPLY'; 
			$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"=>"text", "bypassvalue"=>"");
			$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"int", "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"=>"int", "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"=>"text", "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"=>"int", "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['r_in']=array("db" => "r_in" ,"sc" => "r_in","ctype"=>"int", "bypassvalue"=>"");
			$def_col['r_ua']=array("db" => "r_ua" ,"sc" => "r_ua","ctype"=>"int", "bypassvalue"=>"");
			$def_col['r_s']=array("db" => "r_s" ,"sc" => "r_s","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 
		
 		$ms_car_line_out_detail_id = isset($_POST['ms_car_line_out_detail_id'])?$_POST['ms_car_line_out_detail_id']:-1; // get the direction 
  		   
		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
 		 
		if (array_key_exists($sidx, $def_col)) {  
				$fsidx=$def_col[$sidx];
				$sidx=$fsidx['db'];
		}else{
				$sidx='rID'; //DEFAULT SORT KALU GA ADA
		}
        $sidx=$sidx.'='. $sord;
		  
		$xmldoc =  XMLbasic($spt); 
		paramViewJSON($xmldoc, $limit, $page,  $sidx, $sord); 
  		AddField($xmldoc ,'ms_car_line_out_detail_id',$ms_car_line_out_detail_id); 
		 
        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();
		wh_exec_sp_json($xmldoc, $spt,$sts,$des,$rows,$detail);  
  		echo $rows; 
		}
		
		
		
    function loaddata_source_available(){; 
		$def_col= array();    
		
		$spt='dbo.MG_MS_OUT_CAR_LINE_SOURCE_AVAILABLE'; 
		$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"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"int", "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"=>"int", "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"=>"int", "bypassvalue"=>"");
		$def_col['r15']=array("db" => "r15" ,"sc" => "r15","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r16']=array("db" => "r16" ,"sc" => "r16","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r17']=array("db" => "r17" ,"sc" => "r17","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r18']=array("db" => "r18" ,"sc" => "r18","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r19']=array("db" => "r19" ,"sc" => "r19","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r20']=array("db" => "r20" ,"sc" => "r20","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r21']=array("db" => "r21" ,"sc" => "r21","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r22']=array("db" => "r22" ,"sc" => "r22","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r23']=array("db" => "r23" ,"sc" => "r23","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r24']=array("db" => "r24" ,"sc" => "r24","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r25']=array("db" => "r25" ,"sc" => "r25","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r26']=array("db" => "r26" ,"sc" => "r26","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r_s']=array("db" => "r_s" ,"sc" => "r_s","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r_u']=array("db" => "r_u" ,"sc" => "r_u","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r_uq']=array("db" => "r_uq" ,"sc" => "r_uq","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r_ua']=array("db" => "r_ua" ,"sc" => "r_ua","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r_uid']=array("db" => "r_uid" ,"sc" => "r_uid","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 
		
  		$ms_car_line_out_detail_id = isset($_POST['ms_car_line_out_detail_id'])?$_POST['ms_car_line_out_detail_id']:-1; // get the direction 
  	   	$source_mode = isset($_POST['source_mode'])?$_POST['source_mode']:-1; // get the direction 
  	   
		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
 		 
		if (array_key_exists($sidx, $def_col)) {  
				$fsidx=$def_col[$sidx];
				$sidx=$fsidx['db'];
		}else{
				$sidx='rID'; //DEFAULT SORT KALU GA ADA
		}
        $sidx=$sidx.'='. $sord;
		  
		$xmldoc =  XMLbasic($spt); 
		paramViewJSON($xmldoc, $limit, $page,  $sidx, $sord); 
  		AddField($xmldoc ,'ms_car_line_out_detail_id',$ms_car_line_out_detail_id); 
  		AddField($xmldoc ,'source_mode',$source_mode); 
		 
        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();
		wh_exec_sp_json($xmldoc, $spt,$sts,$des,$rows,$detail);  
  		echo $rows; 
		}
	function save_header(){  
		   $header_id = isset($_POST['header_id'])?$_POST['header_id']:'-1'; // get the requested page 
		   $doc_no = isset($_POST['doc_no'])?$_POST['doc_no']:''; // get the requested page 
		   $doc_date = isset($_POST['doc_date'])?$_POST['doc_date']:''; // get the requested page 
		   $doc_info = isset($_POST['doc_info'])?$_POST['doc_info']:''; // get the requested page 
		   $type_prosses = isset($_POST['type_prosses'])?$_POST['type_prosses']:''; // get the requested page 
		   $car_line = isset($_POST['car_line'])?$_POST['car_line']:''; // get the requested page 
		   $teknisi = isset($_POST['teknisi'])?$_POST['teknisi']:''; // get the requested page 
			$teknisi_id = isset($_POST['teknisi_id'])?$_POST['teknisi_id']:''; // get the requested page 
		   $car_line_name = isset($_POST['car_line_name'])?$_POST['car_line_name']:''; // get the requested page 
		   
			$SPT=$header_id =='-1'?'dbo.MG_MS_OUT_CAR_LINE_HEADER_ADD':'dbo.MG_MS_OUT_CAR_LINE_HEADER_EDIT';

			$xmldoc =  XMLbasic('json');  
			AddField($xmldoc ,'ms_car_line_out_header_id',$header_id );
			AddField($xmldoc ,'doc_no',$doc_no );
			AddField($xmldoc ,'doc_date',$doc_date );
			AddField($xmldoc ,'doc_info',$doc_info );
			AddField($xmldoc ,'ms_type_prosses_name',$type_prosses );
			AddField($xmldoc ,'ms_car_line_no',$car_line ); 
			AddField($xmldoc ,'ms_car_line_no_name',$car_line_name ); 
			AddField($xmldoc ,'teknisi',$teknisi ); 
			AddField($xmldoc ,'teknisi_id',$teknisi_id ); 
			
			$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 auto_supply_all(){  
		    $header_id = isset($_POST['header_id'])?$_POST['header_id']:'-1'; // get the requested page 
		    $mode_supply = isset($_POST['mode_supply'])?$_POST['mode_supply']:'0'; // get the requested page 
		    $renew_supply = isset($_POST['renew_supply'])?$_POST['renew_supply']:'0'; // get the requested page 
		  
			$SPT='dbo.MG_MS_OUT_CAR_LINE_HEADER_AUTO_SUPPLY';

			$xmldoc =  XMLbasic('json');  
			AddField($xmldoc ,'ms_car_line_out_header_id',$header_id ); 
			AddField($xmldoc ,'mode_supply',$mode_supply ); 
			AddField($xmldoc ,'renew_supply',$renew_supply ); 
			
			$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 auto_supply(){  
		    $detail_id = isset($_POST['detail_id'])?$_POST['detail_id']:'-1'; // get the requested page 
		    $mode_supply = isset($_POST['mode_supply'])?$_POST['mode_supply']:'0'; // get the requested page 
		    $renew_supply = isset($_POST['renew_supply'])?$_POST['renew_supply']:'0'; // get the requested page 
		  
			$SPT='dbo.MG_MS_OUT_CAR_LINE_DETAIL_AUTO_SUPPLY';

			$xmldoc =  XMLbasic('json');  
			AddField($xmldoc ,'detail_id',$detail_id ); 
			AddField($xmldoc ,'mode_supply',$mode_supply ); 
			AddField($xmldoc ,'renew_supply',$renew_supply ); 
			
			$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 approve_header(){  
		   $header_id = isset($_POST['header_id'])?$_POST['header_id']:'-1'; // get the requested page 
		  
			$SPT='dbo.MG_MS_OUT_CAR_LINE_HEADER_APPROVE';

			$xmldoc =  XMLbasic('json');  
			AddField($xmldoc ,'ms_car_line_out_header_id',$header_id ); 
			
			$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(){  
		   $header_id = isset($_POST['header_id'])?$_POST['header_id']:'-1'; // get the requested page 
		   $info = isset($_POST['info'])?$_POST['info']:'-1'; // get the requested page 
		  
			$SPT='dbo.MG_MS_OUT_CAR_LINE_HEADER_CANCEL';

			$xmldoc =  XMLbasic('json');  
			AddField($xmldoc ,'ms_car_line_out_header_id',$header_id );
			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(){  
		$header_id = isset($_POST['header_id'])?$_POST['header_id']:'-1'; // get the requested page 
		$detail_id = isset($_POST['detail_id'])?$_POST['detail_id']:'-1'; // get the requested page 
		$ms_item_id = isset($_POST['ms_item_id'])?$_POST['ms_item_id']:'-1'; // get the requested page 
		$part_no = isset($_POST['part_no'])?$_POST['part_no']:''; // get the requested page 
		$quantity = isset($_POST['qty'])?$_POST['qty']:''; // get the requested page 
		$info = isset($_POST['info'])?$_POST['info']:''; // get the requested page 
		
		$SPT=$detail_id =='-1'?'dbo.MG_MS_OUT_CAR_LINE_DETAIL_ADD':'dbo.MG_MS_OUT_CAR_LINE_DETAIL_EDIT';
		
		$xmldoc =  XMLbasic('json');  
		AddField($xmldoc ,'header_id',$header_id );
		AddField($xmldoc ,'detail_id',$detail_id );
		AddField($xmldoc ,'ms_item_id',$ms_item_id );
		AddField($xmldoc ,'part_no',$part_no );
		AddField($xmldoc ,'quantity',$quantity );
		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 delete_detail(){  
	 	$detail_id = isset($_POST['detail_id'])?$_POST['detail_id']:'-1'; // get the requested page 
		
		$SPT='dbo.MG_MS_OUT_CAR_LINE_DETAIL_DELETE';
		
		$xmldoc =  XMLbasic('json');  
		AddField($xmldoc ,'detail_id',$detail_id );
		
		$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_supply(){  
		$ms_car_line_out_detail_id = isset($_POST['ms_car_line_out_detail_id'])?$_POST['ms_car_line_out_detail_id']:'-1'; // get the requested page 
		$ms_item_out_detail_id = isset($_POST['ms_item_out_detail_id'])?$_POST['ms_item_out_detail_id']:'-1'; // get the requested page 
	 	$ms_in_item_detail_id = isset($_POST['ms_in_item_detail_id'])?$_POST['ms_in_item_detail_id']:'-1'; // get the requested page 
	 	$quantity = isset($_POST['qty'])?$_POST['qty']:''; // get the requested page 
	 	$info = isset($_POST['info'])?$_POST['info']:''; // get the requested page 
	 	
		$SPT=$ms_item_out_detail_id =='-1'?'dbo.MG_MS_OUT_CAR_LINE_DETAIL_SUPPLY_ADD':'dbo.MG_MS_OUT_CAR_LINE_DETAIL_SUPPLY_EDIT';
		
		$xmldoc =  XMLbasic('json');  
		AddField($xmldoc ,'ms_car_line_out_detail_id',$ms_car_line_out_detail_id );
		AddField($xmldoc ,'ms_item_out_detail_id',$ms_item_out_detail_id );
		AddField($xmldoc ,'ms_in_item_detail_id',$ms_in_item_detail_id ); 
		AddField($xmldoc ,'quantity',$quantity ); 
		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 delete_supply(){  
		$ms_car_line_out_detail_id = isset($_POST['ms_car_line_out_detail_id'])?$_POST['ms_car_line_out_detail_id']:'-1'; // get the requested page 
		$ms_item_out_detail_id = isset($_POST['ms_item_out_detail_id'])?$_POST['ms_item_out_detail_id']:'-1'; // get the requested page 
	 	$ms_in_item_detail_id = isset($_POST['ms_in_item_detail_id'])?$_POST['ms_in_item_detail_id']:'-1'; // get the requested page 
	 	
		$SPT='MG_MS_OUT_CAR_LINE_DETAIL_SUPPLY_DELETE';
		
		$xmldoc =  XMLbasic('json');  
		AddField($xmldoc ,'ms_car_line_out_detail_id',$ms_car_line_out_detail_id );
		AddField($xmldoc ,'ms_item_out_detail_id',$ms_item_out_detail_id );
		AddField($xmldoc ,'ms_in_item_detail_id',$ms_in_item_detail_id );  
		
		$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 change_status(){  
	 	       $status_id = isset($_POST['status_id'])?$_POST['status_id']:'-1'; // get the requested page 
	  	       $status_info = isset($_POST['status_info'])?$_POST['status_info']:''; // get the requested page 
	  	       $ms_prod_car_line_id = isset($_POST['ms_prod_car_line_id'])?$_POST['ms_prod_car_line_id']:'-1'; // get the requested page 
	  	       
				$xmldoc =  XMLbasic('json'); 
		 		AddField($xmldoc ,'ms_prod_car_line_id',$ms_prod_car_line_id ); 
		 		AddField($xmldoc ,'status_id',$status_id );
		 		AddField($xmldoc ,'status_info',$status_info );
		 	
				$str = $xmldoc->saveXML();
			 	// print_r($str);die();
				 wh_exec_sp_array($xmldoc, 'dbo.MG_ms_prod_car_line_CHANGE_STATUS',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false)
				,'stsno' => $sts
				, 'stsmsg' => $des
				, 'detail' => $detail)
				); 
		}  
				
      	  
 }