<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class CT_datapart_load 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');
        }
		
		$this->load->model("production/mdl_production", 'mdl_production');
		
    }
    
    
    function index()
    {
        $this->load->view('datapart/view_planprod');
    }

  

    function view_rak(){  
  
         $this->load->view('pasi_datapart/view_rak');
    } 
   
    function view_sparepart(){    
  
        $this->load->view('pasi_datapart/view_sparepart'); 
   } 

    function view_rak_new(){	
        $data['x'] ='';
        $data['id_rak'] = isset($_POST['id_rak'])?$_POST['id_rak']:'-1';
        $this->load->view('pasi_datapart/view_rak_new',$data);
    } 

    function view_sparepart_new(){	
        $data['x'] ='';
        $data['id_sparepart'] = isset($_POST['id_sparepart'])?$_POST['id_sparepart']:'-1';
        $this->load->view('pasi_datapart/view_sparepart_new',$data);
    } 
    function view_sparepart_use(){	
     
        $this->load->view('pasi_datapart/view_sparepart_use');
    } 
    function view_sparepart_use_new(){	
        $data['x'] ='';
        $data['id_use'] = isset($_POST['id_use'])?$_POST['id_use']:'-1';
        $this->load->view('pasi_datapart/view_sparepart_use_newx',$data);
    } 

    function view_sparepart_use_item(){	
        $data['header_id'] = isset($_POST['header_id'])?$_POST['header_id']:'-1';
        $this->load->view('pasi_datapart/view_sparepart_use_item',$data);
    } 
    function view_rak_edit(){	
       
        $id_rak         = isset($_POST['id_rak'])?$_POST['id_rak']:die('Pilih Dokumen ');   
        $kode_rak       = isset($_POST['kode_rak'])?$_POST['kode_rak']:'';  //1 add
        $nama_rak       = isset($_POST['nama_rak'])?$_POST['nama_rak']:'';  //1 add
        $lantai         = isset($_POST['lantai'])?$_POST['lantai']:'';  //1 add
        $nomor_rak      = isset($_POST['nomor_rak'])?$_POST['nomor_rak']:'';  //1 add
        $posisi         = isset($_POST['posisi'])?$_POST['posisi']:'';  //1 add
        $note           = isset($_POST['note'])?$_POST['note']:'';  //1 add
        $max_stock      = isset($_POST['max_stock'])?$_POST['max_stock']:'';  //1 add
        $min_stock      = isset($_POST['min_stock'])?$_POST['min_stock']:'';  //1 add

        $data['id_rak'] = $id_rak;
        $data['kode_rak'] = $kode_rak; 
        $data['nama_rak'] = $nama_rak;
        $data['lantai'] = $lantai;
        $data['nomor_rak'] = $nomor_rak;
        $data['posisi'] = $posisi;
        $data['note'] = $note;
        $data['max_stock'] = $max_stock;
        $data['min_stock'] = $min_stock;
        $this->load->view('pasi_datapart/view_rak_edit',$data);
    } 

    function find_supplier(){
		$findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
		$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit']:'';  
		$xmldata = XMLbasic('dbo.SPX_FIND_SUPPLIER');
		AddField($xmldata,'findtext',$findtext);   
		AddField($xmldata,'rows',$limit);  
		exec_sp_xml($xmldata, 'dbo.SPX_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');   
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
   
    } 

    function find_mesin(){
		$findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
		$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit']:'';  
		$xmldata = XMLbasic('dbo.SPX_FIND_MESIN');
		AddField($xmldata,'findtext',$findtext);   
		AddField($xmldata,'rows',$limit);  
		exec_sp_xml($xmldata, 'dbo.SPX_FIND_MESIN',$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');   
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
   
    } 

    function find_sparepart(){
		$findtext = isset($_REQUEST['findtext']) ? $_REQUEST['findtext']:'';  
		$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit']:'';  
		$xmldata = XMLbasic('dbo.SPX_FIND_SPAREPART');
		AddField($xmldata,'findtext',$findtext);   
		AddField($xmldata,'rows',$limit);  
		exec_sp_xml($xmldata, 'dbo.SPX_FIND_SPAREPART',$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');   
            $i++; 
        }
         if ($i==0)
		{
		 die('empty data'); 
  		}
        echo json_encode($responce);
   
    } 

    function view_sparepart_edit(){	
       
        $id_sparepart       = isset($_POST['id_sparepart'])?$_POST['id_sparepart']:die('Pilih Dokumen ');   
        $kode_sparepart		=isset($_POST['kode_sparepart'])?$_POST['kode_sparepart']:'';     
        $nama_sparepart		=isset($_POST['nama_sparepart'])?$_POST['nama_sparepart']:'';     
        $item_no			=isset($_POST['item_no'])?$_POST['item_no']:''; 
        $satuan				=isset($_POST['satuan'])?$_POST['satuan']:'';    
        $model				=isset($_POST['model'])?$_POST['model']:'';    
        $lokasi				=isset($_POST['lokasi'])?$_POST['lokasi']:'';    
        $maker				=isset($_POST['maker'])?$_POST['maker']:'';   
        $suppno				=isset($_POST['suppno'])?$_POST['suppno']:'';   
        $suppname			=isset($_POST['suppname'])?$_POST['suppname']:'';  
        $note1				=isset($_POST['note1'])?$_POST['note1']:'';    
        $note2				=isset($_POST['note2'])?$_POST['note2']:'';      
        $note3				=isset($_POST["note3"])?$_POST["note3"]:'';
    

        $data['id_sparepart'] = $id_sparepart;
        $data['kode_sparepart'] = $kode_sparepart; 
        $data['nama_sparepart'] = $nama_sparepart;
        $data['item_no'] = $item_no;
        $data['satuan'] = $satuan;
        $data['model'] = $model;
        $data['lokasi'] = $lokasi;
        $data['maker'] = $maker;
        $data['suppno'] = $suppno;
        $data['suppname'] = $suppname;
        $data['note1'] = $note1;
        $data['note2'] = $note2;
        $data['note3'] = $note3;
        $this->load->view('pasi_datapart/view_sparepart_edit',$data);
    } 
//-----------------------------------------------------------
 

}    