<?php
class MDL_return extends CI_Model
{	
	
	function __construct()
    {
        parent::__construct();
		
	}
	
	function upload_returnAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
		[id_return_upload]
		,[date_upload]
		,[filename]
		,[filepath]
		,[tipe]
		,[status_upload]
		,[create_date]
		,[create_by]
		,[update_date]
		,[update_by]
			
		");
		$this->db->from("[tbl_upload_return]");
		$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_returnCountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_upload_return]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function data_return_hdrAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		[id_return_hdr]
      ,[from_file_name]
      ,convert(varchar(10), [exec_date], 126) as exec_date 
      ,[status]
      ,[RETURN_NO]
      ,[RETURN_DATE]
      ,[itemcount]
      ,convert(varchar(10), [create_date], 126) as create_date
      ,[create_by]
      ,convert(varchar(10), [update_date], 126) as update_date 
      ,[update_by]
			
		");
		$this->db->from("[dbo].[tbl_return_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 data_return_hdrcountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_return_hdr]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function data_returnAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		[id_return_hdr]
      ,[from_file_name]
      ,[exec_date]
      ,[status]
      ,[RETURN_NO]
      ,[RETURN_DATE]
      ,[itemcount]
      ,[PART_NO]
      ,[ISSUE_QTY]
      ,[create_date]
      ,[create_by]
      ,[update_date]
      ,[update_by]
      ,[PLACE_TO]
      ,[REASON]
      ,[id_return_dtl]
      ,[part_number]
      ,[part_name]
      ,[part_name_customs]
		");
		$this->db->from("[dbo].[v_return]");
		$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 data_returncountAll($where){
		$this->db->select("*");
        $this->db->from("[v_return]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function data_stocktransfer_dtl_all($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id_data_out_dtl]
			  ,tbl_data_out_dtl.[id_data_out_hdr]
			  ,[id_part_number]
			  ,[out_date]
			  ,[part_name_customs]
			  ,[part_number]
			  ,[qty]
			  ,[qty_supply]
			  ,[unit_out]
			  ,[unit_konversi]
			  ,[pengali]
			  ,[box]
			  ,[pack]
			  ,[assy_code]
			  ,tbl_data_out_hdr.doc_out_no
			 ,[no_return]
			  ,[tgl_return]
			  ,[qty_return]
			  ,[status_return]
			 
		");

		$this->db->from("[tbl_data_out_dtl]");
		$this->db->join("tbl_data_out_hdr" , "tbl_data_out_dtl.id_data_out_hdr = tbl_data_out_hdr.id_data_out_hdr", "INNER");
		$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 data_stocktransfer_dtl_CountAll($where){
	
		$this->db->select("*");
			$this->db->from("[tbl_data_out_dtl]");
		$this->db->join("tbl_data_out_hdr" , "tbl_data_out_dtl.id_data_out_hdr = tbl_data_out_hdr.id_data_out_hdr", "INNER");
		$this->db->where($where);
			$result = $this->db->count_all_results(); 
			return $result;
	
			
	}
	
	
}
	