<?php
class MDL_invoice extends CI_Model
{
	function __construct()
    {
        parent::__construct();
		
	}
	
	function inv_all($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			a.[inv_hdr_id]
			  ,a.[r1]
			  ,a.[r2]
			  ,a.[r3]
			  ,a.[r4]
			  ,a.[r5]
			  ,a.[r6]
			  ,a.[r7]
			  ,a.[r8]
			  ,a.[r9]
			  ,a.[r10]
			  ,a.[r11]
			  ,a.[r12]
			  ,a.[r13]
			  ,a.[r14]
			  ,a.[r15]
			  ,a.[r16]
			  ,a.[r17]
			  ,a.[r18]
			  ,a.[r19]
			  ,a.[r20]
			  ,convert(varchar, a.[date_create], 101) as date_create
			  ,a.[status_inv]
			  ,a.[nobl]
			  ,a.[tgbl]
			  ,b.supplier_name
			  
			");
		$this->db->from("tbl_inv_hdr as a");
		$this->db->join("dbo.tbl_data_supplier AS b" , "a.r2 = b.subcode_as400", "INNER");
		//$this->db->join("dbo.tbl_inv_dtl as c" , "a.inv_hdr_id = c.inv_hdr_id", "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 inv_CountAll($where){
		$this->db->select(" count(*) as cnt ");
        $this->db->from("tbl_inv_hdr as a");
		$this->db->join("dbo.tbl_data_supplier AS b" , "a.r2 = b.subcode_as400", "INNER");
		$this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        //return $result;
		//$query = $this->db->get();
		//$rowcount = $query->num_rows();
		//die($this->db->last_query());
        return $result;
    }
	
	function inv_all_dtl($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			a.[inv_dtl]
			,a.[inv_hdr_id]
			,a.[r1]
			,a.[r2]
			,a.[r3]
			,a.[r4]
			,a.[r5]
			,a.[r6]
			,a.[r7]
			,a.[r8]
			,a.[r9]
			,a.[r10]
			,a.[r11]
			,a.[r12]
			,a.[r13]
			,a.[r14]
			,a.[r15]
			,b.part_name
			,isnull(b.part_name_customs,a.[r15]) as part_name_customs
			,a.qty
			,a.amount
			,a.kdval
			,a.box
			,a.pack
			,(a.qty * a.amount)  as totalamount
			");
		$this->db->from("v_detil_invoice as a");
		$this->db->join("dbo.tbl_data_part_hs AS b" , "a.r15 = b.part_no", "LEFT OUTER");
		$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 inv_CountAll_dtl($where){
		$this->db->select("*");
        $this->db->join("dbo.tbl_data_part_hs AS b" , "a.r15 = b.part_no", "LEFT OUTER");
		$this->db->from("v_detil_invoice as a");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	
	function inv_all_dtl_summary($limit,$start,$sidx,$sord, $where){
		$this->db->select("
						
			isnull(dbo.tbl_data_part_hs.part_name, 'DATA UNKNOWN')  as part_name,
			SUM(dbo.v_noinv_dtl.qty) as sumqty,
			dbo.v_noinv_dtl.r7 as r7,
			SUM(dbo.v_noinv_dtl.amount) as sumamount,
			SUM(dbo.v_noinv_dtl.qty * dbo.v_noinv_dtl.amount) as sumamountqty,
			SUM(dbo.v_noinv_dtl.box) as sumbox,
			SUM(dbo.v_noinv_dtl.pack) as sumpack,
			dbo.tbl_data_part_hs.kode_barang as kode_barang
			
		");
		$this->db->from("dbo.tbl_inv_hdr");
		$this->db->join("dbo.v_noinv_dtl" , "dbo.tbl_inv_hdr.inv_hdr_id = dbo.v_noinv_dtl.inv_hdr_id", "INNER");
		$this->db->join("dbo.tbl_data_part_hs" , "dbo.v_noinv_dtl.partnumber = dbo.tbl_data_part_hs.part_no", "INNER");
		$this->db->where($where);
		$this->db->group_by(array("dbo.tbl_data_part_hs.part_name", "dbo.v_noinv_dtl.r7", "dbo.tbl_data_part_hs.kode_barang")); 
        $this->db->limit($limit,$start);
        $this->db->order_by($sidx,$sord);
        $result = $this->db->get()->result();
		//die($this->db->last_query());	
        return $result;
	
	}
	function inv_CountAll_dtl_summary($where){
		$this->db->select("
			count(*) as cnt
			
		");
		$this->db->from("dbo.tbl_inv_hdr");
		$this->db->join("dbo.v_noinv_dtl" , "dbo.tbl_inv_hdr.inv_hdr_id = dbo.v_noinv_dtl.inv_hdr_id", "INNER");
		$this->db->join("dbo.tbl_data_part_hs" , "dbo.v_noinv_dtl.partnumber = dbo.tbl_data_part_hs.part_no", "INNER");
		$this->db->where($where);
		$this->db->group_by(array("dbo.tbl_data_part_hs.part_name", "dbo.v_noinv_dtl.r7")); 
        $query = $this->db->get();
		$rowcount = $query->num_rows();
		//die($this->db->last_query());
        return $rowcount;
	}
	
	function dataparths_all($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   [id]
		  ,[part_no]
		  ,[part_name]
		  ,[part_name_customs]
		  ,[hs_code]
		  ,[bm]
		  ,[cek_price]
		  ,[part_no2]
			
		");
		$this->db->from("tbl_data_part_hs");
		$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 dataparths_countAll($where){
		$this->db->select("*");
        $this->db->from("tbl_data_part_hs");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function bc23datanonhibhdrAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   [id_nonhib_hdr]
		  ,[from_file_name]
		  ,[totalitemfile]
		  ,convert(varchar, [exec_date], 101) as exec_date
		  ,[status]
		  ,[itemcount]
		  ,[noinv]
		  ,[tglinv]
		  ,[tglinv2]
		  ,nobl
		  ,convert(varchar, tgbl,101) as tgbl
		  ,vendor
		
		");
		$this->db->from("[tbl_nonhib]");
        $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 bc23datanonhibhdrcountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_nonhib]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	  
	function bc23datanonhibdtlAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		      [id_nonhib_dtl]
			  ,[id_nonhib_hdr]
			  ,[INVOICE_NO]
			  ,[INVDATE]
			  ,[invdate2]
			  ,[partnumberx] as partnumber
			  ,[partnamecustoms]
			  ,[partname]
			  ,[ITEMNUMBER]
			  ,[ITEMNUMBER2]
			  ,[CONTNO]
			  ,[INVQTY]
			  ,[PACK]
			  ,[UOMPFX]
			  ,[CNO]
			  ,[ORDERNO]
			  ,[VENDOR]
		
		");
		$this->db->from("[v_nonhib_inv_dtl]");
        $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 bc23datanonhibdtlcountAll($where){
		$this->db->select("*");
        $this->db->from("[v_nonhib_inv_dtl]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	
	
	function datanonhibsummary_all($limit,$start,$sidx,$sord, $where){
	
		$this->db->select("
			partname
			,INVOICE_NO
			, SUM(INVQTY) AS sumqty
			, SUM(PACK) AS sumpack
		");

		$this->db->from("v_nonhib_inv_dtl");
		//$this->db->join("tbl_data_part_hs" , "tbl_vgi_dtl.part_number = tbl_data_part_hs.part_no", "LEFT OUTER");
		$this->db->where($where);
		$this->db->group_by(array("partname", "INVOICE_NO")); 
        $this->db->limit($limit,$start);
        $this->db->order_by($sidx,$sord);
        $result = $this->db->get()->result(); 
        //die($this->db->last_query());
        return $result;
	
	
	}
	
	function datanonhibsummary_CountAll($where){
	
		$this->db->select("
			partname
		");
		$this->db->from("v_nonhib_inv_dtl");
		//$this->db->join("tbl_data_part_hs" , "tbl_vgi_dtl.part_number = tbl_data_part_hs.part_no", "LEFT OUTER");
		$this->db->where($where);
		$this->db->group_by(array("partname", "INVOICE_NO"));
        $query = $this->db->get();
		$rowcount = $query->num_rows();
		return $rowcount;
			
	}
	
	function cek_file_upload_inv($where){
	
		$this->db->select("
			filename
		");
        $this->db->from(" [dbo].[tbl_upload_invoice] ");
        $this->db->where($where);
		$this->db->last_query();
        $result = $this->db->count_all_results(); 
	    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_invoice', $data);
	  return $this->db->insert_id();
	}
	
	function update_file($id_invoice_upload, $username)
	{
		$data = array(
               'status_upload'       => 'Deleted',
			   'update_by'       => $username,
			   'update_date'  => date("Y-m-d H:i:s")
            );

		$this->db->where('id_invoice_upload', $id_invoice_upload);
		$this->db->update('tbl_upload_invoice', $data); 
	
	}
	
	function upload_invoiceAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		     [id_invoice_upload]
			  ,convert(varchar, [date_upload], 103) as date_upload
			  ,[filename]
			  ,[tipe]
			  ,[status_upload]
			  ,convert(varchar, [create_date], 103) as create_date
			  ,[create_by]
			  ,convert(varchar, [update_date], 103) as update_date
			  ,[update_by]
			  ,[catatan]
		
		");
		$this->db->from("[tbl_upload_invoice]");
        $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_invoicecountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_upload_invoice]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	
	function updatecatatan($id, $catatan){
		$data = array(
               'catatan' => $catatan
            );

		$this->db->where('[id_invoice_upload]', $id);
		$this->db->update('[tbl_upload_invoice]', $data); 
	   
		return 'Updated';
	}
	
	function upload_bc30All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
		   [id_bc30_upload]
		  ,convert(varchar, [date_upload], 103) as date_upload
		  ,[filename]
		  ,[tipe]
		  ,[status_upload]
		  ,convert(varchar, [create_date], 103) as create_date
		  ,[create_by]
		  ,convert(varchar, [update_date], 103) as update_date
		  ,[update_by]
			
		");
		$this->db->from("[tbl_upload_bc30]");
		$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_bc30countAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_upload_bc30]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function upload_bc25All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
		   [id_bc25_upload]
		  ,convert(varchar, [date_upload], 103) as date_upload
		  ,[filename]
		  ,[tipe]
		  ,[status_upload]
		  ,convert(varchar,[create_date],103) as create_date
		  ,[create_by]
		  ,convert(varchar, [update_date], 103) as update_date
		  ,[update_by]
			
		");
		$this->db->from("[tbl_upload_bc25]");
		$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_bc25countAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_upload_bc25]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function upload_bc27All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
		   [id_bc27_upload]
		  ,convert(varchar, [date_upload], 103) as date_upload
		  ,[filename]
		  ,[tipe]
		  ,[status_upload]
		  ,convert(varchar, [create_date], 103) as create_date
		  ,[create_by]
		  ,convert(varchar, [update_date], 103) as update_date
		  ,[update_by]
			
		");
		$this->db->from("[tbl_upload_bc27]");
		$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_bc27countAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_upload_bc27]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function upload_invoicebc40All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id_invoice_uploadbc40]
			,convert(varchar, [date_upload], 103) as date_upload
			,[filename]
			,[tipe]
			,[filepath]
			,[status_upload]
			,convert(varchar, [create_date], 103) as create_date
			,[create_by]
			,convert(varchar, [update_date], 103) as update_date
			,[update_by]
		
		");
		$this->db->from("[tbl_upload_invoicebc40]");
        $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_invoicebc40countAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_upload_invoicebc40]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	
	function upload_invoicempkAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id_invoice_uploadmpk]
			,convert(varchar, [date_upload], 103) as date_upload
			,[filename]
			,[tipe]
			,[filepath]
			,[status_upload]
			,convert(varchar, [create_date], 103) as create_date
			,[create_by]
			,convert(varchar, [update_date], 103) as update_date
			,[update_by]
		
		");
		$this->db->from("[tbl_upload_invoicempk]");
        $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_invoicempkcountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_upload_invoicempk]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	
	function upload_kurirAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
		   [id_kurir_upload]
		  ,convert(varchar, [date_upload], 103) as date_upload
		  ,[filename]
		  ,[tipe]
		  ,[status_upload]
		  ,convert(varchar,[create_date],103) as create_date
		  ,[create_by]
		  ,convert(varchar, [update_date], 103) as update_date
		  ,[update_by]
			
		");
		$this->db->from("[tbl_upload_kurir]");
		$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_kurircountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_upload_kurir]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function upload_cooAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
		   [id_coo_upload]
		  ,convert(varchar, [date_upload], 103) as date_upload
		  ,[filepath]
		  ,[filename]
		  ,[tipe]
		  ,[status_upload]
		  ,convert(varchar,[create_date],103) as create_date
		  ,[create_by]
		  ,convert(varchar, [update_date], 103) as update_date
		  ,[update_by]
			
		");
		$this->db->from("[tbl_upload_coo]");
		$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_coocountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_upload_coo]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function cek_file_upload_coo($where){
	
		$this->db->select("
			filename
		");
        $this->db->from(" [dbo].[tbl_upload_coo] ");
        $this->db->where($where);
		//$this->db->last_query();
        $result = $this->db->count_all_results(); 
	    return  $result; 
	}
	
	function insert_file_coo($filename,$filepath, $username, $tipe)
	{
	  $data = array(
		 'filename'     => $filename,
		 'filepath'     => $filepath,
		 '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_coo', $data);
	  return $this->db->insert_id();
	}
	
	function tbl_coo_dataAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id_coo_data]
      ,[vendor]
      ,[no_invoice]
      ,[tgl_invoice]
      ,[item_count]
      ,[file_name]
      ,[status_inv]
      ,[type_bc]
      ,[car]
      ,[nobc]
      ,[tglbc]
      ,[nobl]
      ,[tgbl]
      ,[upload_by]
      ,[upload_date]
      ,[supplier_name]
      ,[supplier_address]
      ,[supplier_country]
      ,[subcode_as400]
		
		");
		$this->db->from("[v_coo_data_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 tbl_coo_data_countAll($where){
		$this->db->select("*");
        $this->db->from("[v_coo_data_hdr]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	
	function tbl_coo_dataAll2($limit,$start,$sidx,$sord, $where){
		$this->db->select("
	 v_coo_data_hdr.[id_coo_data]
      ,v_coo_data_hdr.[vendor]
      ,v_coo_data_hdr.[no_invoice]
      ,v_coo_data_hdr.[tgl_invoice]
      ,v_coo_data_hdr.[item_count]
      ,v_coo_data_hdr.[file_name]
      ,v_coo_data_hdr.[status_inv]
      ,v_coo_data_hdr.[type_bc]
      ,v_coo_data_hdr.[car]
      ,v_coo_data_hdr.[nobc]
      ,v_coo_data_hdr.[tglbc]
      ,v_coo_data_hdr.[nobl]
      ,v_coo_data_hdr.[tgbl]
      ,v_coo_data_hdr.[upload_by]
      ,v_coo_data_hdr.[upload_date]
      ,v_coo_data_hdr.[supplier_name]
      ,v_coo_data_hdr.[supplier_address]
      ,v_coo_data_hdr.[supplier_country]
      ,v_coo_data_hdr.[subcode_as400]
	, sum(v_coo_data.PRICE) as PRICE, sum(v_coo_data.amount) as amount, sum(v_coo_data.NET_WEIGHT) as NET_WEIGHT, sum(v_coo_data.ARRIV_PLAN_NUMBER) as ARRIV_PLAN_NUMBER
		");
		$this->db->from("[v_coo_data_hdr]");
		$this->db->join("dbo.v_coo_data" , "dbo.v_coo_data_hdr.id_coo_data = dbo.v_coo_data.id_coo_data", "LEFT OUTER");
        $this->db->where($where);
        $this->db->group_by(" v_coo_data_hdr.id_coo_data, v_coo_data_hdr.vendor, v_coo_data_hdr.no_invoice2, v_coo_data_hdr.tgl_invoice, v_coo_data_hdr.item_count, v_coo_data_hdr.file_name, v_coo_data_hdr.status_inv, 
                         v_coo_data_hdr.type_bc, v_coo_data_hdr.car, v_coo_data_hdr.nobc, v_coo_data_hdr.tglbc, v_coo_data_hdr.nobl, v_coo_data_hdr.tgbl, v_coo_data_hdr.upload_by, v_coo_data_hdr.upload_date, 
                         v_coo_data_hdr.supplier_name, v_coo_data_hdr.supplier_address, v_coo_data_hdr.supplier_country, v_coo_data_hdr.subcode_as400, v_coo_data_hdr.no_faktur, v_coo_data_hdr.tgl_faktur, 
                         v_coo_data_hdr.no_invoice");
		$this->db->limit($limit,$start);
        $this->db->order_by($sidx,$sord);
        $result = $this->db->get()->result(); 
        //die($this->db->last_query());
        return $result;
	
	}
	
	function tbl_coo_data_countAll2($where){
		$this->db->select("*");
        $this->db->from("[v_coo_data_hdr]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	
	function tbl_coo_data_dtlAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id_coo]
      ,[id_coo_data]
      ,[VENDOR]
      ,[INVOICE_NO]
      ,[CONTIANER_NO]
      ,[INVOICE_DATE]
      ,[ETD_VEBDER]
      ,[ETD_PORT]
      ,[ETA_PORT]
      ,[ETA_FACT]
      ,[TRANSPORT_WAY]
      ,[CARA_BAYAR]
      ,[ONEROUS]
      ,[SHIP_FROM]
      ,[VIA]
      ,[SHIP_TO]
      ,[PAY_BY]
      ,[SEAL_NO]
      ,[SHIP_NAME]
      ,[SHIP_COMPANY]
      ,[ORDER_NO]
      ,[ITEM_NUMBER]
      ,[DESCRIPTION]
      ,[ARRIV_PLAN_NUMBER]
      ,[UOM]
      ,[PRICE]
      ,[CURRENT_MONEY]
      ,[CTN_NO_PREFIX]
      ,[CTN_NO_FROM]
      ,[CTN_NO_TO]
      ,[CTN_QUANTITY]
      ,[PACKING_QTY]
      ,[NET_WEIGHT]
      ,[GROSS_WEIGHT]
      ,[WEIGHT_UOM]
      ,[VOLUME]
      ,[VOLUME_UOM]
      ,[BL_DATE]
      ,[BL_NO]
      ,[FREIGHT]
      ,[EURO_NO]
      ,[PALET_NO]
      ,[HS_CODE]
      ,[COUNTRY_OF]
      ,[AKHIR]
      ,[create_by]
      ,[create_date]
      ,[status_inv]
      ,[car]
      ,[nobc]
      ,[tglbc]
      ,[nobl]
      ,[tgbl]
		
		");
		$this->db->from("[tbl_coo_data_dtl]");
        $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 tbl_coo_data_dtl_countAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_coo_data_dtl]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	
	function v_coo_dataAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id_coo_data]
      ,[VENDOR]
      ,[INVOICE_NO]
      ,[CONTIANER_NO]
      ,[INVOICE_DATE]
      ,[ETD_VEBDER]
      ,[ETD_PORT]
      ,[ETA_PORT]
      ,[ETA_FACT]
      ,[TRANSPORT_WAY]
      ,[CARA_BAYAR]
      ,[ONEROUS]
      ,[SHIP_FROM]
      ,[VIA]
      ,[SHIP_TO]
      ,[PAY_BY]
      ,[SEAL_NO]
      ,[SHIP_NAME]
      ,[SHIP_COMPANY]
      ,[ORDER_NO]
      ,[ITEM_NUMBER]
      ,[DESCRIPTION]
      ,[ARRIV_PLAN_NUMBER]
      ,[UOM]
      ,[PRICE]
      ,[CURRENT_MONEY]
      ,[CTN_NO_PREFIX]
      ,[CTN_NO_FROM]
      ,[CTN_NO_TO]
      ,[CTN_QUANTITY]
      ,[PACKING_QTY]
      ,[NET_WEIGHT]
      ,[GROSS_WEIGHT]
      ,[WEIGHT_UOM]
      ,[VOLUME]
      ,[VOLUME_UOM]
      ,[BL_DATE]
      ,[BL_NO]
      ,[FREIGHT]
      ,[EURO_NO]
      ,[PALET_NO]
      ,[HS_CODE]
      ,[COUNTRY_OF]
      ,[AKHIR]
      ,[file_name]
      ,[status_inv]
      ,[type_bc]
      ,[car]
      ,[nobc]
      ,[tglbc]
      ,[nobl]
      ,[tgbl]
      ,[upload_by]
      ,[upload_date]
      ,[id_coo]
      ,[part_no]
      ,[part_name]
      ,[part_name_customs]
      ,[hskode]
      ,[kode_barang]
      ,[supplier_name]
      ,[supplier_address]
      ,[subcode_as400]
      ,[supplier_country]
      ,[kd_negara]
      ,[kd_negara2]
      ,[kd_neg]
	  ,[amount]
		");
		$this->db->from("[v_coo_data]");
        $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 v_coo_data_countAll($where){
		$this->db->select("*");
        $this->db->from("[v_coo_data]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
    
    function tbl_coo_negaraAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id_negara]
      ,[country_code]
      ,[country_name]
      ,[kd_negara]
      ,[nama_negara]
		");
		$this->db->from("[tbl_coo_negara]");
        $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 tbl_coo_negara_countAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_coo_negara]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
    
     function tbl_coo_peldnAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			 [id_peldn]
      ,[kd_pel]
      ,[nama_pel]
      ,[kd_pel_bc]
      ,[nama_pel_bc]
		");
		$this->db->from("[tbl_coo_peldn]");
        $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 tbl_coo_peldn_countAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_coo_peldn]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
    
     function tbl_coo_pellnAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			  [id_pelln]
      ,[kd_pel]
      ,[nama_pel]
      ,[kd_pel_bc]
      ,[nama_pel_bc]
		");
		$this->db->from("[tbl_coo_pelln]");
        $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 tbl_coo_pelln_countAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_coo_pelln]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	function tbl_coo_satAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			  [id_sat]
      ,[kode_sat_coo]
      ,[nama_sat_coo]
      ,[kdsat]
      ,[nama_sat]
		");
		$this->db->from("[tbl_coo_satuan]");
        $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 tbl_coo_sat_countAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_coo_satuan]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	
	function data_file_cooAll($limit,$start,$sidx,$sord, $where, $tipe, $filename,$ext){
		$this->db->select("
		   
		    [datanama]
      ,[file_name]
      ,[ukuran]
       ,datecreate
			
		  
			
		");
		$this->db->from("[dbo].[f_upload_coo]('$tipe','$filename','$ext') ");
		$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_file_coocountAll($where, $tipe, $filename,$ext){
		$this->db->select("*");
        $this->db->from("[dbo].[f_upload_coo]('$tipe','$filename','$ext') ");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	
	
}

?>