<?php
class MDL_bc23 extends CI_Model
{
	function __construct()
    {
        parent::__construct();
		
	}
	
	function bc23hdrdataAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("[id_bc_in_hdr]
			  ,[CAR]
			  ,[KdKpbc]
			  ,[Tujuan]
			  ,[JnsBarang]
			  ,[TujuanKirim]
			  ,[PasokNama]
			  ,[PasokAlmt]
			  ,[PasokNeg]
			  ,[UsahaId]
			  ,[UsahaNpwp]
			  ,[KdTPB]
			  ,[Registrasi]
			  ,[UsahaNama]
			  ,[UsahaAlmt]
			  ,[UsahaStatus]
			  ,[ApiKd]
			  ,[ApiNo]
			  ,[PpjkId]
			  ,[PpjkNpwp]
			  ,[PpjkNama]
			  ,[PpjkAlmt]
			  ,[PpjkNo]
			  ,[PpjkTg]
			  ,[IndId]
			  ,[IndNpwp]
			  ,[IndNama]
			  ,[IndAlmt]
			  ,[Moda]
			  ,[AngkutNama]
			  ,[AngkutNo]
			  ,[AngkutFl]
			  ,[PelBkr]
			  ,[PelMuat]
			  ,[PelTransit]
			  ,[BC23No]
			  ,CONVERT(varchar, [BC23Tg], 101) as BC23Tg
			  ,[KdKpbcBongkar]
			  ,[KdKpbcAwas]
			  ,[DokTupKd]
			  ,[DokTupNo]
			  ,CONVERT(varchar, [DokTupTg], 101) as DokTupTg 
			  ,[PosNo]
			  ,[PosSub]
			  ,[TmpTbn]
			  ,[KdVal]
			  ,[Ndpbm]
			  ,[NilInv]
			  ,[Freight]
			  ,[BTambahan]
			  ,[Diskon]
			  ,[KdAss]
			  ,[Asuransi]
			  ,[KdHrg]
			  ,[Fob]
			  ,[Cif]
			  ,[Bruto]
			  ,[Netto]
			  ,[JmCont]
			  ,[JmBrg]
			  ,[TglTtd]
			  ,[KotaTtd]
			  ,[Namattd]
			  ,[ContakPerson]
			  ,[NoPhone]
			  ,[NoFax]
			  ,[Email]
			  ,[Status]
			  ,[Snrf]
			  ,[Lengkap]
			  ,[PosSubSub]
			  ,[NoKontrak]
			  ,[TgKontrak]
			  ,[HargaRp]
			  ,[TmpPeriksaFisik]
			  ,[AlmtPeriksaFisik]
			  ,[TgPeriksaFisik]
			  ,[WkPeriksaFisik]
			  ,(case when (isnull(isnull(create_by, update_by), (select top 1 [createby] FROM [dbo].[v_bc_in_hdr_h_status] where id_bc_in_hdr=[tbl_bc_in_hdr].id_bc_in_hdr))) = 'admin' then 'nurhadi' else (isnull(isnull(create_by, update_by), (select top 1 [createby] FROM [dbo].[v_bc_in_hdr_h_status] where id_bc_in_hdr=[tbl_bc_in_hdr].id_bc_in_hdr))) end) as create_by
			  ,(case when (isnull(isnull(create_by, update_by), (select top 1 [createby] FROM [dbo].[v_bc_in_hdr_h_status] where id_bc_in_hdr=[tbl_bc_in_hdr].id_bc_in_hdr))) = 'admin' then 'nurhadi' else (isnull(isnull(create_by, update_by),  (select top 1 [createby] FROM [dbo].[v_bc_in_hdr_h_status] where id_bc_in_hdr=[tbl_bc_in_hdr].id_bc_in_hdr))) end) as update_by
			   ,convert(varchar, isnull(isnull(create_date, update_date),  (select top 1 create_date  FROM [dbo].[v_bc_in_hdr_h_status]  where id_bc_in_hdr=[tbl_bc_in_hdr].id_bc_in_hdr)), 103) as create_date
	           ,convert(varchar, isnull(isnull(create_date, update_date),  (select top 1 create_date  FROM [dbo].[v_bc_in_hdr_h_status]  where id_bc_in_hdr=[tbl_bc_in_hdr].id_bc_in_hdr)), 103) as update_date
			  ,[typedok]
			  ,[statusdok]
			  ,[noinv]
			  ,CONVERT(varchar, [tginv], 101) as tglinv
			  ,inv_hdr_id
			  ,nobl
			  ,CONVERT(varchar, [tglbl], 101) as tglbl
			  ,bc_in_from_in
			  ,CONVERT(varchar, tgaju, 101) as tgaju
			  ");
        $this->db->from("[tbl_bc_in_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 bc23hdrdataCountAll($where){
		$this->db->select("*");
        $this->db->from("tbl_bc_in_hdr");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	
	function updatebc23statusdok($data, $where){
		
		$this->db->where($where);
		$this->db->update('tbl_bc_in_hdr', $data);

	}
	
	function inserttomodul(){
	
	
	
	}
	
	function  bc23detildataAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("[id_bc_in_dtl]
			  ,[id_bc_in_hdr]
			  ,[CAR]
			  ,[Serial]
			  ,[JnsBarangDtl]
			  ,[TujuanKirimDtl]
			  ,[NoHs]
			  ,[SeriTrp]
			  ,[BrgUrai]
			  ,[Merk]
			  ,[Tipe]
			  ,[SpfLain]
			  ,[KdBrg]
			  ,[Penggunaan]
			  ,[KemasJn]
			  ,[KemasJm]
			  ,[KdFasDtl]
			  ,[BrgAsal]
			  ,[DNilInv]
			  ,[DCif]
			  ,[KdSat]
			  ,[JmlSat]
			  ,[NettoDtl]
			  ,[SatBmJm]
			  ,[SatCukJm]
			  ,[DtlOk]
			  ,[create_date]
			  ,[create_by]
			  ,[update_date]
			  ,[update_by]
			  
		");
        $this->db->from("[tbl_bc_in_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 bc23detildataCountAll($where){
		$this->db->select("*");
        $this->db->from("tbl_bc_in_dtl");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	
	function  bc23dokdataAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		  [id_bc_in_dok]
		  ,[id_bc_in_hdr]
		  ,[CAR]
		  ,[DokKd]
		  ,(select top 1 uraian from tbl_tabel where [KDTAB]='061' and [KDREC] = [tbl_bc_in_dok].[DokKd]) as uraian
		  ,[DokNo]
		  ,CONVERT(varchar, [DokTg], 101) as DokTg
			  
		");
        $this->db->from("[tbl_bc_in_dok]");
        $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 bc23dokdataCountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_bc_in_dok]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	
	function  bc23condataAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		  [id_bc_in_con]
		  ,[id_bc_in_hdr]
		  ,[CAR]
		  ,[ContNo]
		  ,[ContUkur]
		  ,[ContTipe]
			  
		");
        $this->db->from("[tbl_bc_in_con]");
        $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 bc23condataCountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_bc_in_con]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	
	function  bc23detilpartnameAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		  [id_bc_in_dtl_partnumber]
		  ,[inv_dtl]
		  ,[inv_hdr_id]
		  ,[noinv]
		  ,[car]
		  ,[nobc]
		  ,[tglbc]
		  ,[seri_detil]
		  ,[part_number]
		  ,[part_name]
		  ,[part_name_customs]
		  ,[qty]
		  ,[unit]
		  ,[harga]
		  ,[kdval]
		  ,[box]
		  ,[pack]
		");
		
		$this->db->from("[tbl_bc_in_dtl_partnumber]");
        $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 bc23detilpartnamecountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_bc_in_dtl_partnumber]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	
	function  bc23_mesin_sparepartAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		 [id_invoice_mesinsparepart]
		  ,[part_name]
		  ,[part_no]
		  ,[kode_barang]
		  ,[kode_supplier]
		  ,[maker]
		  ,[order_qty]
		  ,[order_no]
		  ,convert(varchar,[order_date],120) as order_date
		  ,convert(varchar,[req_eta_date],120) as req_eta_date
		  ,[shipping_by]
		  ,[invoice_no]
		  ,convert(varchar,[invoice_date],120) as invoice_date
		  ,[inv_qty]
		  ,[inv_unit]
		  ,[status_inv]
		  ,[rec_qty]
		  ,convert(varchar,[rec_date],120) as rec_date
		  ,[amount]
		  ,[remark]
		  ,[nobl]
		  ,[tglbl]
		  ,[nocar]
		  ,[tglaju]
		  ,[status_data]
		  ,[create_date]
		  ,[create_by]
		  ,[update_date]
		  ,[update_by]
		");
		
		$this->db->from("[tbl_invoice_mesinsparepart]");
        $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 bc23_mesin_sparepartCountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_invoice_mesinsparepart]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
    }
	
	function  bc23_mesin_sparepart_hdrAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		 [kode_supplier]
		  ,[invoice_no]
		  ,convert(varchar, [invoice_date], 120)  as invoice_date
		  ,order_no
		  ,convert(varchar,order_date, 120) as order_date
		  ,nobl
		  ,convert(varchar, tglbl, 120) as tglbl 
		  ,[status_data]
		");
		
		$this->db->from("[tbl_invoice_mesinsparepart]");
		$this->db->group_by(array("kode_supplier"
			  ,"invoice_no"
			  ,"invoice_date"
			  ,"order_no"
			  ,"order_date"
			  ,"status_data"
			  ,"nobl"
			  ,"tglbl"
			  )); 
        $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 bc23_mesin_sparepart_hdrCountAll($where){
		$this->db->select("
			count(*) as cnt
			
		");
        $this->db->from("[tbl_invoice_mesinsparepart]");
		$this->db->where($where);
		$this->db->group_by(array("kode_supplier"
			  ,"invoice_no"
			  ,"invoice_date"
			  ,"order_no"
			  ,"order_date"
			  ,"status_data")); 
       
        $query = $this->db->get();
		$rowcount = $query->num_rows();
        //die($this->db->last_query());
        return $rowcount;
    }


}