<?php
class MDL_production extends CI_Model
{
	function __construct()
    {
        parent::__construct();
		
	}
	
	function databom_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			id_bom_hdr
		  ,[ASSY_CODE]
		  ,[ASSY_NO]
		  ,[filename]
		  ,[itemcount]
		  ,convert(varchar,[dateexec],101) as dateexec
				
		");
		$this->db->from("[tbl_bom_hdr]");
        $this->db->where($where);
        $this->db->limit($limit,$start);
        $this->db->order_by($sidx,$sord);
        $result = $this->db->get()->result(); 
        //die($this->db->last_query());
        return $result;
	
	}
	
	function databom_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tbl_bom_hdr]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function databomdtl_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			  dbo.tbl_bom_dtl.id_bom,
			  dbo.tbl_bom_dtl.ASSY_CODE,
			  dbo.tbl_bom_dtl.ASSY_NO,
			  dbo.tbl_bom_dtl.PART_NO,
			  dbo.tbl_bom_dtl.PARTNO2,
			  dbo.tbl_bom_dtl.QTY,
			  dbo.tbl_bom_dtl.FLAG,
			  dbo.tbl_bom_dtl.STATUS,
			  dbo.tbl_bom_dtl.status_bom,
			  dbo.tbl_bom_dtl.id_part_number,
			  dbo.tbl_data_part_hs.part_name as part_name
			
		");
		$this->db->from("dbo.tbl_bom_dtl");
		$this->db->join("dbo.tbl_data_part_hs" , "dbo.tbl_data_part_hs.id = dbo.tbl_bom_dtl.id_part_number", "LEFT OUTER");
		$this->db->where($where);
		//$this->db->group_by(array("a.inv_hdr_id", "b.part_name_customs","a.r7")); 
        $this->db->limit($limit,$start);
        $this->db->order_by($sidx,$sord);
        $result = $this->db->get()->result();
		//die($this->db->last_query());	
        return $result;
	
	}
	
	function databomdtl_CountAll($where){
	
		$this->db->select("
			dbo.tbl_bom_dtl.id_bom
			
		");
		$this->db->from("dbo.tbl_bom_dtl");
		$this->db->join("dbo.tbl_data_part_hs" , "dbo.tbl_data_part_hs.id = dbo.tbl_bom_dtl.id_part_number", "LEFT OUTER");
		$this->db->where($where);
		//$this->db->group_by(array("a.inv_hdr_id", "b.part_name_customs","a.r7")); 
        $query = $this->db->get();
		$rowcount = $query->num_rows();
		//die($this->db->last_query());
        return $rowcount;
	}
	
	function upload_vgiAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		     [id_vgi_upload]
			  ,[date_upload]
			  ,[filename]
			  ,[tipe]
			  ,[status_upload]
			  ,[create_date]
			  ,[create_by]
			  ,[update_date]
			  ,[update_by]
		
		");
		$this->db->from("[tbl_upload_vgi]");
        $this->db->where($where);
        $this->db->limit($limit,$start);
        $this->db->order_by($sidx,$sord);
        $result = $this->db->get()->result(); 
        //die($this->db->last_query());
        return $result;
	
	}
	
	function upload_vgicountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_upload_vgi]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	
	function insert_file($filename, $username, $tipe)
	{
	  $data = array(
		 'filename'     => $filename,
		 'tipe'     => $tipe,
		 'status_upload'       => 'sukses',
		 'date_upload'  => date("Y-m-d H:i:s"),
		 'create_by'       => $username,
		 'create_date'  => date("Y-m-d H:i:s"),
		 'update_by'       => $username,
		 'update_date'  => date("Y-m-d H:i:s")
		 
	  );
	  $this->db->insert('tbl_upload_vgi', $data);
	  return $this->db->insert_id();
	}
	
	function update_file($id_vgi_upload, $username)
	{
		$data = array(
               'status_upload'       => 'Deleted',
			   'update_by'       => $username,
			   'update_date'  => date("Y-m-d H:i:s")
            );

		$this->db->where('id_vgi_upload', $id_vgi_upload);
		$this->db->update('tbl_upload_vgi', $data); 
	
	}
	
	
	
	
}
	
