<?php class CT_ms_find 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_mater/view_ms_item');
	} 
	 
    function find_uom(){
		$findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
		$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit']:'';  
		$xmldata = XMLbasic('dbo.MG_MS_FIND_UOM');
		AddField($xmldata,'findtext',$findtext);   
		AddField($xmldata,'rows',$limit);  
		wh_exec_sp_xml($xmldata, 'dbo.MG_MS_FIND_UOM',$stsno,$stsdes,$rows,$detail);
		$i=0;
        foreach ($rows as $per_row) {
            $responce->rows[$i]['rID']=getXMLValue($per_row,'rID');
            $responce->rows[$i]['r1']=getXMLValue($per_row,'r1');   
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
   
    } 
	
    function find_base_part(){
		$findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
		$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit']:'';  
		$xmldata = XMLbasic('dbo.MG_MS_FIND_BASE_PART');
		AddField($xmldata,'findtext',$findtext);   
		AddField($xmldata,'rows',$limit);  
		wh_exec_sp_xml($xmldata, 'dbo.MG_MS_FIND_BASE_PART',$stsno,$stsdes,$rows,$detail);
		$i=0;
        foreach ($rows as $per_row) {
            $responce->rows[$i]['rID']=getXMLValue($per_row,'rID');
            $responce->rows[$i]['r1']=getXMLValue($per_row,'r1');   
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
   
    } 
	
   function find_valuta(){
        $findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
       $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit']:'';  
         $xmldata = XMLbasic('dbo.MG_MS_FIND_VALUTA');
        AddField($xmldata,'findtext',$findtext);   
        AddField($xmldata,'rows',$limit);  
      	wh_exec_sp_xml($xmldata, 'dbo.MG_MS_FIND_VALUTA',$stsno,$stsdes,$rows,$detail);
	       $i=0;
        foreach ($rows as $per_row) {
            $responce->rows[$i]['rID']=getXMLValue($per_row,'rID');
            $responce->rows[$i]['r1']=getXMLValue($per_row,'r1');   
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
   
    } 
	
	  function find_valuta_value(){
		  
	    $ID_HEADER = isset($_REQUEST['ID_HEADER']) ? $_REQUEST['ID_HEADER']:'-1';  
        $VALUTA = isset($_REQUEST['VALUTA']) ? $_REQUEST['VALUTA']:'';  
        $DATE_KURS = isset($_REQUEST['DATE_KURS']) ? $_REQUEST['DATE_KURS']:'';  
		
        $xmldata = XMLbasic('dbo.MG_MS_BC_IN_GET_KURS_INFO_NOW');
		
        AddField($xmldata,'ID_HEADER',$ID_HEADER);   
	    AddField($xmldata,'VALUTA',$VALUTA);   
        AddField($xmldata,'DATE_KURS',$DATE_KURS);  
	 	wh_exec_sp_array($xmldata, 'dbo.MG_MS_BC_IN_GET_KURS_INFO_NOW',$stsno,$stsdes,$rows,$detail);
	  	echo json_encode(array('valid'=>($stsno=='00'?true:false)
			,'stsno' => $stsno
			, 'stsmsg' => $stsdes
			, 'detail' => $detail)
			); 
   
    } 
   function find_port_ln(){
        $findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
       $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit']:'';  
         $xmldata = XMLbasic('dbo.MG_MS_FIND_PORT_LN');
        AddField($xmldata,'findtext',$findtext);   
        AddField($xmldata,'rows',$limit);  
      	wh_exec_sp_xml($xmldata, 'dbo.MG_MS_FIND_PORT_LN',$stsno,$stsdes,$rows,$detail);
	       $i=0;
        foreach ($rows as $per_row) {
            $responce->rows[$i]['rID']=getXMLValue($per_row,'rID');
            $responce->rows[$i]['r1']=getXMLValue($per_row,'r1');   
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
   
    } 
   function find_port_dn(){
        $findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
      $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit']:'';  
          $xmldata = XMLbasic('dbo.MG_MS_FIND_PORT_DN');
        AddField($xmldata,'findtext',$findtext);   
        AddField($xmldata,'rows',$limit);  
      	wh_exec_sp_xml($xmldata, 'dbo.MG_MS_FIND_PORT_DN',$stsno,$stsdes,$rows,$detail);
	       $i=0;
        foreach ($rows as $per_row) {
            $responce->rows[$i]['rID']=getXMLValue($per_row,'rID');
            $responce->rows[$i]['r1']=getXMLValue($per_row,'r1');   
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
   
    } 
   function find_package(){
        $findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
       $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit']:'';  
         $xmldata = XMLbasic('dbo.MG_MS_FIND_PACKAGE');
        AddField($xmldata,'findtext',$findtext);   
        AddField($xmldata,'rows',$limit);  
      	wh_exec_sp_xml($xmldata, 'dbo.MG_MS_FIND_PACKAGE',$stsno,$stsdes,$rows,$detail);
	       $i=0;
        foreach ($rows as $per_row) {
            $responce->rows[$i]['rID']=getXMLValue($per_row,'rID');
            $responce->rows[$i]['r1']=getXMLValue($per_row,'r1');   
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
   
    } 
	  	 
  function find_country(){
        $findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
        $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit']:'';  
        $xmldata = XMLbasic('dbo.MG_MS_FIND_COUNTRY');
        AddField($xmldata,'findtext',$findtext);   
        AddField($xmldata,'rows',$limit);  
      	wh_exec_sp_xml($xmldata, 'dbo.MG_MS_FIND_COUNTRY',$stsno,$stsdes,$rows,$detail);
	       $i=0;
        foreach ($rows as $per_row) {
            $responce->rows[$i]['rID']=getXMLValue($per_row,'rID');
            $responce->rows[$i]['r1']=getXMLValue($per_row,'r1');   
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
   
    } 
	  	 	 
  function find_kpbc(){
        $findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
        $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit']:'';  
        $xmldata = XMLbasic('dbo.MG_MS_FIND_KPBC');
        AddField($xmldata,'findtext',$findtext);   
        AddField($xmldata,'rows',$limit);  
      	wh_exec_sp_xml($xmldata, 'dbo.MG_MS_FIND_KPBC',$stsno,$stsdes,$rows,$detail);
	       $i=0;
        foreach ($rows as $per_row) {
            $responce->rows[$i]['rID']=getXMLValue($per_row,'rID');
            $responce->rows[$i]['r1']=getXMLValue($per_row,'r1');   
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
   
    } 
	  	 
  function find_supplier(){
        $findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
        $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit']:'';  
        $xmldata = XMLbasic('dbo.MG_MS_FIND_SUPPLIER');
        AddField($xmldata,'findtext',$findtext);   
        AddField($xmldata,'rows',$limit);  
      	wh_exec_sp_xml($xmldata, 'dbo.MG_MS_FIND_SUPPLIER',$stsno,$stsdes,$rows,$detail);
	       $i=0;
        foreach ($rows as $per_row) {
            $responce->rows[$i]['rID']=getXMLValue($per_row,'rID');
            $responce->rows[$i]['r1']=getXMLValue($per_row,'r1');   
            $responce->rows[$i]['r2']=getXMLValue($per_row,'r2');   
            $responce->rows[$i]['r3']=getXMLValue($per_row,'r3');   
            $responce->rows[$i]['r4']=getXMLValue($per_row,'r4');   
            $responce->rows[$i]['r5']=getXMLValue($per_row,'r5');   
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
   
    } 
	 
    function find_uom2(){
        $findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
        $xmldata = XMLbasic('dbo.MG_MS_FIND_UOM');
        AddField($xmldata,'findtext',$findtext);   
        AddField($xmldata,'rows','10');  
      	wh_exec_sp_xml($xmldata, 'dbo.MG_MS_FIND_UOM',$stsno,$stsdes,$rows,$detail);
	       $i=0;
        foreach ($rows as $per_row) {
            $responce->rows[$i]['rID']=getXMLValue($per_row,'rID');
            $responce->rows[$i]['r1']=getXMLValue($per_row,'r1');   
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
   
    } 
	  	
  function find_item(){
        $findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
        $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit']:'';  
        $allow_item = isset($_REQUEST['allow_item']) ? $_REQUEST['allow_item']:'';  
        $xmldata = XMLbasic('dbo.MG_MS_FIND_ITEM');
        AddField($xmldata,'findtext',$findtext);   
        AddField($xmldata,'rows',$limit);  
        AddField($xmldata,'allow_item',$allow_item);  
	
		$str = $xmldata->saveXML();   
		//print_r($str);die();
      	wh_exec_sp_xml($xmldata, 'dbo.MG_MS_FIND_ITEM',$stsno,$stsdes,$rows,$detail);
	    $i=0;
		    
        foreach ($rows as $per_row) {
            $responce->rows[$i]['rID']=getXMLValue($per_row,'rID');
            $responce->rows[$i]['r1']=getXMLValue($per_row,'r1');   
            $responce->rows[$i]['r2']=getXMLValue($per_row,'r2');   
            $responce->rows[$i]['r3']=getXMLValue($per_row,'r3');   
            $responce->rows[$i]['r4']=getXMLValue($per_row,'r4');   
            $responce->rows[$i]['r5']=getXMLValue($per_row,'r5');   
            $responce->rows[$i]['hs1']=getXMLValue($per_row,'hs1');   
            $responce->rows[$i]['hs2']=getXMLValue($per_row,'hs2');   
            $responce->rows[$i]['hs3']=getXMLValue($per_row,'hs3');   
            $responce->rows[$i]['hs4']=getXMLValue($per_row,'hs4');   
            $responce->rows[$i]['hs5']=getXMLValue($per_row,'hs5');   
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
   
    } 
	  	
   function find_item_to_production(){
        $findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
        $xmldata = XMLbasic('dbo.MG_MS_FIND_ITEM_TO_PRODUCTION');
        AddField($xmldata,'findtext',$findtext);   
        AddField($xmldata,'rows','10');  
      	wh_exec_sp_xml($xmldata, 'dbo.MG_MS_FIND_ITEM_TO_PRODUCTION',$stsno,$stsdes,$rows,$detail);
	       $i=0;
        foreach ($rows as $per_row) {
            $responce->rows[$i]['rID']=getXMLValue($per_row,'rID');
            $responce->rows[$i]['r1']=getXMLValue($per_row,'r1');   
            $responce->rows[$i]['r2']=getXMLValue($per_row,'r2');   
            $responce->rows[$i]['r3']=getXMLValue($per_row,'r3');   
            $responce->rows[$i]['r4']=getXMLValue($per_row,'r4');   
            $responce->rows[$i]['r5']=getXMLValue($per_row,'r5');   
            $responce->rows[$i]['hs1']=getXMLValue($per_row,'hs1');   
            $responce->rows[$i]['hs2']=getXMLValue($per_row,'hs2');   
            $responce->rows[$i]['hs3']=getXMLValue($per_row,'hs3');   
            $responce->rows[$i]['hs4']=getXMLValue($per_row,'hs4');   
            $responce->rows[$i]['hs5']=getXMLValue($per_row,'hs5');   
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
   
    }   
	
   function find_car_line_group(){
        $findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
        $xmldata = XMLbasic('dbo.MG_MS_FIND_CAR_LINE_GROUP');
        AddField($xmldata,'findtext',$findtext);   
        AddField($xmldata,'rows','10');  
      	wh_exec_sp_xml($xmldata, 'dbo.MG_MS_FIND_CAR_LINE_GROUP',$stsno,$stsdes,$rows,$detail);
	       $i=0;
        foreach ($rows as $per_row) {
            $responce->rows[$i]['rID']=getXMLValue($per_row,'rID');
            $responce->rows[$i]['r1']=getXMLValue($per_row,'r1');   
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
   
    }    	
 }