<?php
class MDL_settings extends CI_Model
{
	function __construct()
    {
        parent::__construct();
		
	}
	
	function datasupplier_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id]
		  ,[supplier_code]
		  ,[supplier_name]
		  ,[supplier_address]
		  ,[supplier_address1]
		  ,[supplier_country]
		  ,[base_price]
		  ,[copper_base_reff]
		  ,[subgct]
		  ,[subcode_as400]
		  ,[NPWP]
		,[NOIJIN]
		,[NOKONTRAK]
		,[TGLIJIN]
		,[TGLKONTRAK]	
		");
		$this->db->from("[tbl_data_supplier]");
        $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 datasupplier_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("tbl_data_supplier");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function datapart_hs_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			id, part_no, part_name, part_name_customs, hs_code, bm, cek_price, part_no2, kode_barang
			
		");
		$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 datapart_hs_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("tbl_data_part_hs");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function dataitemlist_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id_item_list]
		  ,[PART_NO]
		  ,[PART_NAME]
		  ,[CUST_PNO]
		  ,[CUST_NAME]
		  ,[SUPP_PNO]
		  ,[SUPP_CODE]
		  ,[PCT_SUP]
		  ,[BAL_FAC]
		  ,[WEIGTH]
		  ,[ASS_STAGE]
		  ,[MIN_PACK]
		  ,[UNIT]
		  ,[CURRENCY]
		  ,[WASTE]
		  ,[ORG_CTRY]
		  ,[SUPP_STAT]
		  ,[CLASS] as clas
		  ,[LOCATION]
		  ,[MIN_ORDQTY]
		  ,[BEG_BAL]
		  ,[TOTAL_IN]
		  ,[TOTAL_OUT]
		  ,[CUMM_REQ]
		  ,[CUMM_IN]
		  ,[PART_CODE]
		  ,[QTY1BOXROL]
		  ,[QTY1PALLET]
		  ,[FOB]
		  ,[CIF]
		  ,[FOBNI]
		  ,[CIFNI]
		  ,[QUOTEFOB]
		  ,[QUOTECIF]
		  ,[QUOTEFOBNI]
		  ,[QUOTECIFNI]
		  ,[QUOTE_CURR]
		  ,[NFOB]
		  ,[NCIF]
		  ,[NFOBNI]
		  ,[NCIFNI]
		  ,[NQUOTEFOB]
		  ,[NQUOTECIF]
		  ,[NQUOTEFOBNI]
		  ,[NQUOTECIFNI]
		  ,[FINAL_PRE]
		  ,[PARTNO2]
		  ,[PERIODE]
		  ,[PERIODE1]
		  ,[PRICE]
		  ,[SUPP_NAME]
		  ,[AMOUNT]
		  ,[COST]
		  ,[FREIGHT]
		  ,[INVOICE]
		  ,[FLAG]
		  ,[NFLAG]
		  ,[MAKER_CODE]
		  ,[RACK_LOC]
		  ,[CREATED_BY]
		  ,CONVERT(varchar, CREATED_DATE, 101) AS CREATED_DATE
		  ,CONVERT(varchar, MODIFIED_BY, 101) AS MODIFIED_BY
		  ,[MODIFIED_DATE]
		  ,[NON_GSP_STATUS]
		  ,[COMODITY_CODE]
		  ,[PARTNO3]
		  ,[filename]
		  ,convert(varchar,[execdate], 101) as execdate
			
		");
		$this->db->from("[tbl_item_list]");
        $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 dataitemlist_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tbl_item_list]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	
	function dataitemfinishgood_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id_assy_list]
		  ,[ASSY_CODE]
		  ,[ASSY_NO]
		  ,[LINE_NO]
		  ,[CUT_PCS]
		  ,[CRIMP_PCS]
		  ,[JOINT_PCS]
		  ,[CUT_SHLD]
		  ,[CRIMP_SHLD]
		  ,[JOINT_SHLD]
		  ,[ASSY_UMH]
		  ,[ASSY_UMHN]
		  ,[ACTIVESTAT]
		  ,[L_MONTH_QTY]
		  ,[FLAG_VALIDATE_PLIST]
		  ,[DESC_CARLINE]
		  ,[CONV_DATE]
		  ,[CCT]
		  ,[CRIMP_ACCS]
		  ,[CRIMP_DBL]
		  ,[CUT_TUBE]
		  ,[JOINT_BCHL]
		  ,[MOULDING]
		  ,[WOS]
		  ,[LOADING_LINE]
		  ,[HISTORY_CLINE1]
		  ,[HISTORY_CLINE2]
		  ,[HISTORY_CLINE3]
		  ,[PREV_CODE]
		  ,[CUST_KEY]
		  ,[PREVSTAT]
		  ,[ASSY_NO1]
		  ,[QTY_BOX]
		  ,[QTY_SET]
		  ,[IF_ORDER_QTY]
		  ,[STOCK_MIN_P]
		  ,[STOCK_MINQTY]
		  ,[NON_GSP]
		  ,[AIR_BAG]
		  ,[GROUPCODE]
		  ,[PACKSTD_SF]
		  ,[PACKSTD_AF]
		  ,[CTN_TYPE]
		  ,[QTYBOX_SF]
		  ,[QTYBOX_AF]
		  ,[PRICE]
		  ,[NET_KGS]
		  ,[GROSS_KGS]
		  ,[VOL]
		  ,[CUMM]
		  ,[CTN_TYPE_ME]
		  ,[CTN_KGS_SF]
		  ,[CTN_KGS_AF]
		  ,[CTN_VOL_SF]
		  ,[CTN_VOL_AF]
		  ,[PALET_KGS]
		  ,[PALET_VOL]
		  ,[CTN_URUT]
		  ,[GSP]
		  ,[QTY_BOX_AF]
		  ,[CTN_NO]
		  ,[L_MONTH_ACT]
		  ,[CUST_CODE]
		  ,[BOTTOM]
		  ,[TOP]
		  ,[LSEGI3]
		  ,[LSEGI4]
		  ,[LSEGI7]
		  ,[LSEGI8]
		  ,[LKERTAS]
		  ,[LINNING]
		  ,[GRP]
		  ,[GR3000]
		  ,[LDCUT]
		  ,[TOPDALAM]
		  ,[LINNINGSPCA]
		  ,[LINNINGSPCB]
		  ,[TYPE]
		  ,[DESIGN_CHANGE]
		  ,[DESC_ASSY]
		  ,[GENDATE_PLIST]
		  ,[PRICE_LSEGI3]
		  ,[PRICE_LSEGI4]
		  ,[PRICE_LSEGI7]
		  ,[PRICE_LSEGI8]
		  ,[PRICE_LABEL]
		  ,[PRICE_STICKER]
		  ,[PRICE_LINNING]
		  ,[LABEL]
		  ,[STICKER]
		  ,[PRICE2]
		  ,[FBP]
		  ,[PRICE_TOP]
		  ,[PRICE_BOTTOM]
		  ,[PRICE_GRP]
		  ,[PRICE_TOPDALAM]
		  ,[PRICE_LINNINGSPCA]
		  ,[PRICE_LINNINGSPCB]
		  ,[PRICE_FBP]
		  ,[CTN_BOX]
		  ,[PRICE_CTN_BOX]
		  ,[FLAG_PACKING]
		  ,[FOB]
		  ,[FOBN]
		  ,[COSTING]
		  ,[COSTINGN]
		  ,[BOTTOM_AF]
		  ,[TOP_AF]
		  ,[LSEGI3_AF]
		  ,[LSEGI4_AF]
		  ,[LSEGI7_AF]
		  ,[LSEGI8_AF]
		  ,[LINNING_AF]
		  ,[GRP_AF]
		  ,[FBP_AF]
		  ,[TOPDALAM_AF]
		  ,[LINNINGSPCA_AF]
		  ,[LINNINGSPCB_AF]
		  ,[CTN_TYPE_AF]
		  ,[LABEL_AF]
		  ,[STICKER_AF]
		  ,[CTN_BOX_AF]
		  ,[STATUS]
		  ,[PRICE_LSEGI3_2]
		  ,[PRICE_LSEGI4_2]
		  ,[PRICE_LSEGI7_2]
		  ,[PRICE_LSEGI8_2]
		  ,[PRICE_LABEL_2]
		  ,[PRICE_STICKER_2]
		  ,[PRICE_LINNING_2]
		  ,[PRICE_TOP_2]
		  ,[PRICE_BOTTOM_2]
		  ,[PRICE_GRP_2]
		  ,[PRICE_TOPDALAM_2]
		  ,[PRICE_LINNINGSPCA_2]
		  ,[PRICE_LINNINGSPCB_2]
		  ,[PRICE_FBP_2]
		  ,[PRICE_CTN_BOX_2]
		  ,[CELL_DEVIDERA]
		  ,[CELL_DEVIDERB]
		  ,[LSEGI3A]
		  ,[LSEGI3B]
		  ,[CELL_DEVIDERA_AF]
		  ,[CELL_DEVIDERB_AF]
		  ,[LSEGI3A_AF]
		  ,[LSEGI3B_AF]
		  ,[PRICE_LSEGI3A]
		  ,[PRICE_LSEGI3B]
		  ,[PRICE_CELL_DEVIDERA]
		  ,[PRICE_CELL_DEVIDERB]
		  ,[PRICE_LSEGI3A_2]
		  ,[PRICE_LSEGI3B_2]
		  ,[PRICE_CELL_DEVIDERA_2]
		  ,[PRICE_CELL_DEVIDERB_2]
		  ,[TYPE_PALLET]
		  ,[DATE_UMH]
		  ,[DATE_UMHN]
		  ,[DATE_PART]
		  ,[CUST_PNO1]
		  ,[status_aktif]			
		");
		$this->db->from("[tbl_assy_list]");
        $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 dataitemfinishgood_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tbl_assy_list]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	
	function datakurs_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id_kurs]
		  ,[KdKurs]
		  ,convert(varchar, [TgAwal], 101)  as TgAwal
		  ,convert(varchar,[TgAkhir],  101) as TgAkhir
		  ,[Nilai]
		  ,[Ket]
				
		");
		$this->db->from("[tblKurs]");
        $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 datakurs_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tblKurs]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function upload_parthsAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
			[id_parths_upload]
			,[date_upload]
			,[filename]
			,[tipe]
			,[status_upload]
			,[create_date]
			,[create_by]
			,[update_date]
			,[update_by]
			
		");
		$this->db->from("[tbl_uploadparths]");
		$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_parthscountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_uploadparths]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function upload_itemlistAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
			[id_itemlist_upload]
			,[date_upload]
			,[filename]
			,[tipe]
			,[status_upload]
			,[create_date]
			,[create_by]
			,[update_date]
			,[update_by]
			
		");
		$this->db->from("[tbl_uploaditemlist]");
		$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_itemlistcountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_uploaditemlist]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	
	function upload_bahanpenolongAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
			[id_uploadbahanpenolong_upload]
			,convert(DATE, [date_upload], 126) as date_upload
			,[filename]
			,[tipe]
			,[filepath]
			,[status_upload]
			,convert(DATE, [create_date], 126) as create_date
			,[create_by]
			,[update_date]
			,[update_by]
			
		");
		$this->db->from("[tbl_uploadbahanpenolong]");
		$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_bahanpenolongcountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_uploadbahanpenolong]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function upload_supplierAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
			[id_supplier_upload]
			,[date_upload]
			,[filename]
			,[tipe]
			,[status_upload]
			,[create_date]
			,[create_by]
			,[update_date]
			,[update_by]
			
		");
		$this->db->from("[tbl_uploadsupplier]");
		$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_suppliercountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_uploadsupplier]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function upload_modulsupplierAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
			[PasokNama]
			,[PasokAlmt]
			,[PasokNeg]
			
		");
		$this->db->from("[tblSupplier]");
		$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_modulsuppliercountAll($where){
		$this->db->select("*");
        $this->db->from("[tblSupplier]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function stockawal_bahanbaku_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id_stock_awal]
		  ,[date_stock]
		  ,[part_no]
		  ,[part_name_customs]
		  ,[part_name]
		  ,[qty]
		  ,[unit]
		  ,[unit_konversi]
		  ,[pengali]
		  ,[netto]
		  ,[brutto]
		  ,[typebahan]
		  ,[create_date]
		  ,[create_by]
		  ,[update_date]
		  ,[update_by]
		");
		$this->db->from("[tbl_stock_awal]");
        $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 stockawal_bahanbaku_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tbl_stock_awal]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function upload_stockawalAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		  [id_stockawal_upload]
		  ,[date_upload]
		  ,[filename]
		  ,[filepath]
		  ,[tipe]
		  ,[status_upload]
		  ,[create_date]
		  ,[create_by]
		  ,[update_date]
		  ,[update_by]
			
		");
		$this->db->from("[tbl_upload_stockawal]");
        $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_stockawalcountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tbl_upload_stockawal]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function upload_assylistAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
			[id_assylist_upload]
			,CONVERT(VARCHAR(24),  [date_upload], 113) as  [date_upload]
			,[filename]
			,[tipe]
			,[status_upload]
			,CONVERT(VARCHAR(24),  [create_date], 113) as  [create_date]
			,[create_by]
			,CONVERT(VARCHAR(24),  [update_date], 113) as  [update_date]
			,[update_by]
			
		");
		$this->db->from("[tbl_uploadassylist]");
		$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_assylistcountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_uploadassylist]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function uploadmesindanalatktrAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
		[id_mesin_upload]
		,[date_upload]
		,[filename]
		,[filepath]
		,[tipe]
		,[status_upload]
		,[create_date]
		,[create_by]
		,[update_date]
		,[update_by]
			
		");
		$this->db->from("[tbl_uploadmesindanalatktr]");
		$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 uploadmesindanalatktrCountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_uploadmesindanalatktr]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	
	function data_uploadmesindanalatktr_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id_mesin]
		  ,[part_no]
		  ,[part_name]
		  ,[part_name_customs]
		  ,[hs_code]
		  ,[bm]
		  ,[cek_price]
		  ,[part_no2]
		  ,[kode_barang]
			
		");
		$this->db->from("[tbl_dt_mesin_dan_alat_ktr]");
        $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_uploadmesindanalatktr_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tbl_dt_mesin_dan_alat_ktr]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function data_barang_mesindanalatktr_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id_datampk]
		  ,[kode_brg]
		  ,[nama_barang]
		  ,[keterangan]
		  ,[satuan]
		  ,convert(varchar,[create_date],103) as create_date
		  ,[create_by]
		  ,convert(varchar,[update_date],103) as update_date
		  ,[update_by]
			
		");
		$this->db->from("[tbl_dt_mesindanalatkantor_code]");
        $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_barang_mesindanalatktr_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tbl_dt_mesindanalatkantor_code]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function uploadtbl_upload_data_mesinAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
		[id_data_mesin]
		,[date_upload]
		,[filename]
		,[tipe]
		,[filepath]
		,[status_upload]
		,[create_date]
		,[create_by]
		,[update_date]
		,[update_by]
			
		");
		$this->db->from("[tbl_upload_data_mesin_in_out]");
		$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 uploadtbl_upload_data_mesinCountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_upload_data_mesin_in_out]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function data_mpk_inAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
			[id_mpk_in]
			,convert(varchar, [date_in], 101) as date_in
			,[no_in]
			,[part_name]
			,[part_name_customs]
			,[part_no]
			,[qty_in]
			,[qty_out]
			,[unit_in]
			,[unit_konversi]
			,[pengali]
			,[box]
			,[pack]
			,[harga]
			,[kdval]
			
		");
		$this->db->from("[tbl_dt_mpk_in]");
		$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_dt_mpk_inCountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_dt_mpk_in]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function data_dt_mpk_outAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
			[id_mpk_out]
			,convert(varchar, [date_out], 101) as date_out
			,[no_out]
			,[part_name]
			,[part_name_customs]
			,[part_no]
			,[qty_out]
			,[qty_in]
			,[unit_out]
			,[unit_konversi]
			,[pengali]
			,[box]
			,[pack]
			,[harga]
			,[kdval]
			
		");
		$this->db->from("[tbl_dt_mpk_out]");
		$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_dt_mpk_outCountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_dt_mpk_out]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function data_mpk_stockawalAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
			[id_mpk_stockawal]
			,[date_stockawal]
			,[part_name]
			,[part_no]
			,[qty]
			,[unit]
			,[unit_konversi]
			,[pengali]
			,[box]
			,[pack]
			,[harga]
			,[kdval]
			,[create_date]
			,[create_by]
			,[update_date]
			,[update_by]
			
		");
		$this->db->from("[tbl_dt_mpk_stockawal]");
		$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_mpk_stockawalCountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_dt_mpk_stockawal]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function data_bahanpenolong_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id_bahan_penolong]
      ,[part_no]
      ,[part_name]
      ,[part_name_customs]
      ,[hs_code]
      ,[bm]
      ,[cek_price]
      ,[currency]
      ,[part_no2]
      ,[kode_barang]
      ,[item_code]
      ,[uom]
      ,[seri_mesin]
      ,[item_type1]
      ,[item_type2]
      ,[net_weight_unit]
      ,[dangerous_good]
      ,[saldo_awal]
      ,[consumable]
      ,[kode_supplier]
      ,[create_date]
      ,[create_by]
      ,[update_date]
      ,[update_by]
		,[aktif]	
		");
		$this->db->from("[tbl_data_bahan_penolong]");
        $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_bahanpenolong_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("tbl_data_bahan_penolong");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function v_user_all_logs_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			convert(varchar,datetime_log,126) as [datetime_log]
      ,[username_log]
      ,[menu_log]
      ,[action_log]
      ,[info_log]
			
		");
		$this->db->from("[v_user_all_logs]");
        $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_user_all_logs_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("v_user_all_logs");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	}
	
	function data_tbl_data_part_hs_article_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id_konv_part]
      ,[part_no]
      ,[part_no2]
      ,[article_code]
			
		");
		$this->db->from("[tbl_data_part_hs_article]");
        $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_tbl_data_part_hs_article_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tbl_data_part_hs_article]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function v_data_bp_in_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			dbo.v_data_bp_in.kode_barang,
dbo.v_data_bp_in.part_name_customs,
dbo.v_data_bp_in.part_no,
dbo.v_data_bp_in.qty_in,
dbo.v_data_bp_in.doc_in_no,
dbo.v_data_bp_in.doc_in_date,
dbo.v_data_bp_in.CAR,
dbo.v_data_bp_in.BC23No,
dbo.v_data_bp_in.BC23Tg,
dbo.v_data_bp_in.typedok,
dbo.v_data_bp_in.PasokNama,
dbo.v_data_bp_in.PasokAlmt,
dbo.v_data_bp_in.id_data_in_dtl,
dbo.v_data_bp_in.id_data_in_hdr,
dbo.v_data_bp_in.id_bc_in_hdr
			
		");
		$this->db->from("dbo.v_data_bp_in");
        $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_data_bp_in_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("dbo.v_data_bp_in");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function upload_bahanpenolong_outAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
			[id_uploadbp_out_upload]
			,convert(DATE, [date_upload], 126) as date_upload
			,[filename]
			,[tipe]
			,[filepath]
			,[status_upload]
			,convert(DATE, [create_date], 126) as create_date
			,[create_by]
			,[update_date]
			,[update_by]
			
		");
		$this->db->from("[tbl_uploadbahanpenolong_out]");
		$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_bahanpenolong_outcountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_uploadbahanpenolong_out]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function data_bahanpenolong_outAll($limit,$start,$sidx,$sord, $where){
		$this->db->query("
		
			SET ANSI_NULLS ON;  
			SET ANSI_WARNINGS ON;
		
		");
		
		$this->db->select("
		   
			v_data_bp_ct01_all.id_bp_out_dtl,
			v_data_bp_ct01_all.container_number,
			v_data_bp_ct01_all.no_invoice,
			v_data_bp_ct01_all.tgl_invoice,
			v_data_bp_ct01_all.part_no,
			v_data_bp_ct01_all.part_name,
			v_data_bp_ct01_all.qty,
			v_data_bp_ct01_all.qty_out,
			v_data_bp_ct01_all.uom,
			v_data_bp_ct01_all.doc_no,
			convert(varchar(10), v_data_bp_ct01_all.doc_date, 126) as doc_date,
			v_data_bp_ct01_all.doc_out_to,
			v_data_bp_ct01_all.filename,
			v_data_bp_ct01_all.car,
			convert(varchar(10), v_data_bp_ct01_all.create_date, 126) as create_date,
			v_data_bp_ct01_all.create_by,
			v_data_bp_ct01_all.update_date,
			v_data_bp_ct01_all.update_by,
			v_data_bp_ct01_all.approved_date,
			v_data_bp_ct01_all.price,
			v_data_bp_ct01_all.status_data,
			v_data_bp_ct01_all.kode_buyer,
			v_data_bp_ct01_all.nama_buyer,
			v_data_bp_ct01_all.id_memo_bp,
			v_data_bp_ct01_all.bruto,
			v_data_bp_ct01_all.hs_kode,
			v_data_bp_ct01_all.jmkemas,
			v_data_bp_ct01_all.jnkemas,
			v_data_bp_ct01_all.netto
		");
		$this->db->from("[v_data_bp_ct01_all]");
		$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_bahanpenolong_outcountAll($where){
		$this->db->select("*");
        $this->db->from("[v_data_bp_ct01_all]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function data_report_per_part_all($limit,$page,$sidx,$sord, $where, $tglawal, $tglakhir){
		$this->db->query("
		
			SET ANSI_NULLS ON;  
			SET ANSI_WARNINGS ON;
		
		");
		
		$query = $this->db->query(
		"	
			select * from (
				select
					row_number() OVER (ORDER BY part_no) AS row 
					,part_no
					,part_name
					,stock_awal
					,qty_in
					,qty_out
					,sisa_by_date
					,unit
					,stock_opname
					,0 as selisih
					,adj
				from dbo.f_mutasi_bp('$tglawal','$tglakhir','BP')
			where   $where  ) as x
				where x.row between  ($page - 1) * $limit + 1 AND $page * $limit
				order by $sidx $sord 	
		
		
		");
		$result = $query->result_array();
		//var_dump($result);
		//die();
		return $result;
	
	}
	 
	function data_report_per_part_CountAll($where, $tgl_awal, $tgl_akhir){
		 $query = $this->db->query("
			
			select COUNT(*) as cnt from (
			select row_number() OVER (ORDER BY part_no) AS row, 
			part_no
			from dbo.f_mutasi_bp('$tgl_awal','$tgl_akhir','BP')
			
			) x
		 ");

        $result = $query->result_array();
		//var_dump($result);
		//die();
		$xx=0;
		foreach ($result as $r){
			$xx=$r['cnt'];
		}
		return $xx; 
		
	
	
	}
	
	
	//alat kantro
	
	function upload_alatkantorAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
			[id_uploadalatkantor_upload]
			,convert(DATE, [date_upload], 126) as date_upload
			,[filename]
			,[tipe]
			,[filepath]
			,[status_upload]
			,convert(DATE, [create_date], 126) as create_date
			,[create_by]
			,[update_date]
			,[update_by]
			
		");
		$this->db->from("[tbl_uploadalatkantor]");
		$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_alatkantorcountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_uploadalatkantor]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function data_alatkantor_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			[id_alat_kantor]
      ,[part_no]
      ,[part_name]
      ,[part_name_customs]
      ,[hs_code]
      ,[bm]
      ,[cek_price]
      ,[currency]
      ,[part_no2]
      ,[kode_barang]
      ,[item_code]
      ,[uom]
      ,[seri_mesin]
      ,[item_type1]
      ,[item_type2]
      ,[net_weight_unit]
      ,[dangerous_good]
      ,[saldo_awal]
      ,[consumable]
      ,[kode_supplier]
      ,[create_date]
      ,[create_by]
      ,[update_date]
      ,[update_by]
		,[aktif]	
		");
		$this->db->from("[tbl_data_alat_kantor]");
        $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_alatkantor_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("tbl_data_alat_kantor");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function upload_alatkantor_outAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
			[id_uploadak_out_upload]
			,convert(DATE, [date_upload], 126) as date_upload
			,[filename]
			,[tipe]
			,[filepath]
			,[status_upload]
			,convert(DATE, [create_date], 126) as create_date
			,[create_by]
			,[update_date]
			,[update_by]
			
		");
		$this->db->from("[tbl_uploadalatkantor_out]");
		$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_alatkantor_outcountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_uploadalatkantor_out]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function data_alatkantor_outAll($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		   
			dbo.tbl_alatkantor_out.id_ak_out_dtl,
			dbo.tbl_alatkantor_out.container_number,
			dbo.tbl_alatkantor_out.no_invoice,
			dbo.tbl_alatkantor_out.tgl_invoice,
			dbo.tbl_alatkantor_out.part_no,
			dbo.tbl_alatkantor_out.part_name,
			dbo.tbl_alatkantor_out.qty,
			dbo.tbl_alatkantor_out.qty_out,
			dbo.tbl_alatkantor_out.uom,
			dbo.tbl_alatkantor_out.doc_no,
			dbo.tbl_alatkantor_out.doc_date,
			dbo.tbl_alatkantor_out.doc_out_to,
			dbo.tbl_alatkantor_out.filename,
			dbo.tbl_alatkantor_out.car,
			convert(varchar(10), dbo.tbl_alatkantor_out.create_date, 126) as create_date,
			dbo.tbl_alatkantor_out.create_by,
			dbo.tbl_alatkantor_out.update_date,
			dbo.tbl_alatkantor_out.update_by,
			dbo.tbl_alatkantor_out.approved_date,
			dbo.tbl_alatkantor_out.price,
			dbo.tbl_alatkantor_out.status_data,
			dbo.tbl_alatkantor_out.kode_buyer,
			dbo.tbl_alatkantor_out.nama_buyer,
			dbo.tbl_alatkantor_out.id_memo_ak,
			dbo.tbl_alatkantor_out.bruto,
			dbo.tbl_alatkantor_out.hs_kode,
			dbo.tbl_alatkantor_out.jmkemas,
			dbo.tbl_alatkantor_out.jnkemas,
			dbo.tbl_alatkantor_out.netto	
			
		");
		$this->db->from("[tbl_alatkantor_out]");
		$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_alatkantor_outcountAll($where){
		$this->db->select("*");
        $this->db->from("[tbl_alatkantor_out]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        //die($this->db->last_query());
        return $result;
	}
	
	function v_data_ak_in_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
			dbo.v_data_ak_in.kode_barang,
dbo.v_data_ak_in.part_name_customs,
dbo.v_data_ak_in.part_no,
dbo.v_data_ak_in.qty_in,
dbo.v_data_ak_in.doc_in_no,
dbo.v_data_ak_in.doc_in_date,
dbo.v_data_ak_in.CAR,
dbo.v_data_ak_in.BC23No,
dbo.v_data_ak_in.BC23Tg,
dbo.v_data_ak_in.typedok,
dbo.v_data_ak_in.PasokNama,
dbo.v_data_ak_in.PasokAlmt,
dbo.v_data_ak_in.id_data_in_dtl,
dbo.v_data_ak_in.id_data_in_hdr,
dbo.v_data_ak_in.id_bc_in_hdr
			
		");
		$this->db->from("dbo.v_data_ak_in");
        $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_data_ak_in_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("dbo.v_data_ak_in");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function data_report_per_part_ak_all($limit,$page,$sidx,$sord, $where, $tglawal, $tglakhir){
		$query = $this->db->query(
		"	
			select * from (
				select
					row_number() OVER (ORDER BY part_no) AS row 
					,part_no
					,part_name
					,stock_awal
					,qty_in
					,qty_out
					,sisa_by_date
					,unit
					,stock_opname
					,0 as selisih
					,adj
				from dbo.f_mutasi_ak('$tglawal','$tglakhir','BP')
			where   $where  ) as x
				where x.row between  ($page - 1) * $limit + 1 AND $page * $limit
				order by $sidx $sord 	
		
		
		");
		$result = $query->result_array();
		//var_dump($result);
		//die();
		return $result;
	
	}
	 
	function data_report_per_part_akCountAll($where, $tgl_awal, $tgl_akhir){
		 $query = $this->db->query("
			
			select COUNT(*) as cnt from (
			select row_number() OVER (ORDER BY part_no) AS row, 
			part_no
			from dbo.f_mutasi_ak('$tgl_awal','$tgl_akhir','BP')
			
			) x
		 ");

        $result = $query->result_array();
		//var_dump($result);
		//die();
		$xx=0;
		foreach ($result as $r){
			$xx=$r['cnt'];
		}
		return $xx; 
		
	
	
	}
	
	// memo bahan penolong
	
	function data_bahanpenolong_memo_All($limit,$start,$sidx,$sord, $where){
		
		$this->db->select("
			dbo.tbl_bahanpenolong_memo.id_memo,
			dbo.tbl_bahanpenolong_memo.nomor_memo,
			dbo.tbl_bahanpenolong_memo.tgl_memo,
			dbo.tbl_bahanpenolong_memo.npwp_pembeli,
			dbo.tbl_bahanpenolong_memo.kode_pembeli,
			dbo.tbl_bahanpenolong_memo.harga_penyerahan,
			dbo.tbl_bahanpenolong_memo.id_ceisa_hdr,
			convert(varchar, dbo.tbl_bahanpenolong_memo.create_date, 126) as create_date,
			dbo.tbl_bahanpenolong_memo.create_by,
			convert(varchar, dbo.tbl_bahanpenolong_memo.update_date, 126) as update_date,
			dbo.tbl_bahanpenolong_memo.update_by,
			dbo.tbl_bahanpenolong_memo.bc_no,
			dbo.tbl_bahanpenolong_memo.tgl_bc,
			dbo.tbl_bahanpenolong_memo.doc_out_no,
			dbo.tbl_bahanpenolong_memo.doc_out_date,
			dbo.tbl_bahanpenolong_memo.car,
			dbo.tbl_bahanpenolong_memo.tipe_out,
			dbo.tbl_bahanpenolong_memo.status_data,
			dbo.tbl_bahanpenolong_memo.nama_pembeli,
			dbo.tbl_bahanpenolong_memo.typedok,
			dbo.tbl_bahanpenolong_memo.kdval,
			dbo.tbl_bahanpenolong_memo.ndpbm,
			dbo.tbl_bahanpenolong_memo.bruto	
		");
		$this->db->from("dbo.tbl_bahanpenolong_memo");
		//$this->db->join("dbo.tbl_data_supplier" , "tbl_data_supplier.subcode_as400 = dbo.tbl_bahanpenolong_memo.kode_pembeli", "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 data_bahanpenolong_memo_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("dbo.tbl_bahanpenolong_memo");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	
	function data_bahanpenolong_memo_scrap_All($limit,$start,$sidx,$sord, $where){
		
		$this->db->select("
			dbo.tbl_bahanpenolong_out.id_bp_out_dtl,
			dbo.tbl_bahanpenolong_out.part_no,
			dbo.tbl_bahanpenolong_out.part_name,
			dbo.tbl_bahanpenolong_out.qty,
			dbo.tbl_bahanpenolong_out.uom,
			dbo.tbl_bahanpenolong_out.price,
			dbo.tbl_bahanpenolong_out.id_memo_bp,
			dbo.tbl_bahanpenolong_memo_scrap.jmkemas_scrap,
			dbo.tbl_bahanpenolong_memo_scrap.jnkemas_scrap,
			dbo.tbl_bahanpenolong_memo_scrap.kode_scrap,
			dbo.tbl_bahanpenolong_memo_scrap.nama_scrap,
			dbo.tbl_bahanpenolong_memo_scrap.qty_scrap,
			dbo.tbl_bahanpenolong_memo_scrap.bruto_scrap,
			dbo.tbl_bahanpenolong_memo_scrap.netto_scrap,
			dbo.tbl_bahanpenolong_memo_scrap.harga_scrap
		");
		$this->db->from("dbo.tbl_bahanpenolong_out");
		$this->db->join("dbo.tbl_bahanpenolong_memo_scrap" , "dbo.tbl_bahanpenolong_out.id_bp_out_dtl = dbo.tbl_bahanpenolong_memo_scrap.id_bp_out_dtl", "LEFT OUTER");
        $this->db->join("dbo.tbl_bahanpenolong_memo" , "dbo.tbl_bahanpenolong_memo.id_memo = dbo.tbl_bahanpenolong_out.id_memo_bp", "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_bahanpenolong_memo_scrap_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("dbo.tbl_bahanpenolong_out");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	//memo _alatkantor
	function data_alatkantor_memo_All($limit,$start,$sidx,$sord, $where){
		
		$this->db->select("
			dbo.tbl_alatkantor_memo.id_memo,
			dbo.tbl_alatkantor_memo.nomor_memo,
			dbo.tbl_alatkantor_memo.tgl_memo,
			dbo.tbl_alatkantor_memo.npwp_pembeli,
			dbo.tbl_alatkantor_memo.kode_pembeli,
			dbo.tbl_alatkantor_memo.harga_penyerahan,
			dbo.tbl_alatkantor_memo.id_ceisa_hdr,
			convert(varchar, dbo.tbl_alatkantor_memo.create_date, 126) as create_date,
			dbo.tbl_alatkantor_memo.create_by,
			convert(varchar, dbo.tbl_alatkantor_memo.update_date, 126) as update_date,
			dbo.tbl_alatkantor_memo.update_by,
			dbo.tbl_alatkantor_memo.bc_no,
			dbo.tbl_alatkantor_memo.tgl_bc,
			dbo.tbl_alatkantor_memo.doc_out_no,
			dbo.tbl_alatkantor_memo.doc_out_date,
			dbo.tbl_alatkantor_memo.car,
			dbo.tbl_alatkantor_memo.tipe_out,
			dbo.tbl_alatkantor_memo.status_data,
			dbo.tbl_alatkantor_memo.nama_pembeli,
			dbo.tbl_alatkantor_memo.typedok,
			dbo.tbl_alatkantor_memo.kdval,
			dbo.tbl_alatkantor_memo.ndpbm,
			dbo.tbl_alatkantor_memo.bruto	
		");
		$this->db->from("dbo.tbl_alatkantor_memo");
		//$this->db->join("dbo.tbl_data_supplier" , "tbl_data_supplier.subcode_as400 = dbo.tbl_alatkantor_memo.kode_pembeli", "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 data_alatkantor_memo_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("dbo.tbl_alatkantor_memo");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	
	function data_alatkantor_memo_scrap_All($limit,$start,$sidx,$sord, $where){
		
		$this->db->select("
			dbo.tbl_alatkantor_out.id_ak_out_dtl,
			dbo.tbl_alatkantor_out.part_no,
			dbo.tbl_alatkantor_out.part_name,
			dbo.tbl_alatkantor_out.qty,
			dbo.tbl_alatkantor_out.uom,
			dbo.tbl_alatkantor_out.price,
			dbo.tbl_alatkantor_out.id_memo_ak,
			dbo.tbl_alatkantor_memo_scrap.jmkemas_scrap,
			dbo.tbl_alatkantor_memo_scrap.jnkemas_scrap,
			dbo.tbl_alatkantor_memo_scrap.kode_scrap,
			dbo.tbl_alatkantor_memo_scrap.nama_scrap,
			dbo.tbl_alatkantor_memo_scrap.qty_scrap,
			dbo.tbl_alatkantor_memo_scrap.bruto_scrap,
			dbo.tbl_alatkantor_memo_scrap.netto_scrap,
			dbo.tbl_alatkantor_memo_scrap.harga_scrap
		");
		$this->db->from("dbo.tbl_alatkantor_out");
		$this->db->join("dbo.tbl_alatkantor_memo_scrap" , "dbo.tbl_alatkantor_out.id_ak_out_dtl = dbo.tbl_alatkantor_memo_scrap.id_ak_out_dtl", "LEFT OUTER");
        $this->db->join("dbo.tbl_alatkantor_memo" , "dbo.tbl_alatkantor_memo.id_memo = dbo.tbl_alatkantor_out.id_memo_ak", "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_alatkantor_memo_scrap_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("dbo.tbl_alatkantor_out");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function datapart_hs_added_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		[id]
      ,[part_no]
      ,[part_name]
      ,[part_name_customs]
      ,[hs_code]
      ,[bm]
      ,[cek_price]
      ,[part_no2]
      ,[kode_barang]
      ,[part_no_sap]
      ,[order_number]
      ,[new_part]
      ,[shipment_term]
      ,[supplier]
      ,[currency]
      ,[part_name_added]
		,[uom]
      ,[supplier_kode]	
		");
		$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 datapart_hs_added_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tbl_data_part_hs]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function tbl_data_part_hs_koefisien_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		[id]
      ,[partno2]
      ,[inland_koefisien]
      ,[landed_cost]
      ,[currency]
      ,[tgl_berlaku]
		,[supplier]	
		,[kode_supplier]	
		");
		$this->db->from("[tbl_data_part_hs_koefisien]");
        $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_data_part_hs_koefisien_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tbl_data_part_hs_koefisien]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	
	function tbl_upload_bb_added_koef_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		 [id_upload_koef]
      	   ,convert(varchar(10),[date_upload],126) as date_upload
      ,[filename]
      ,[tipe]
      ,[filepath]
      ,[status_upload]
       ,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("[tbl_upload_bb_added_koef]");
        $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_upload_bb_added_koef_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tbl_upload_bb_added_koef]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function tbl_upload_bb_added_master_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		 [id_upload_master]
      	   ,convert(varchar(10),[date_upload],126) as date_upload
      ,[filename]
      ,[tipe]
      ,[filepath]
      ,[status_upload]
       ,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("[tbl_upload_bb_added_master]");
        $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_upload_bb_added_master_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tbl_upload_bb_added_master]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function tbl_upload_bb_added_price_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		 [id_upload_price]
      	   ,convert(varchar(10),[date_upload],126) as date_upload
      ,[filename]
      ,[tipe]
      ,[filepath]
      ,[status_upload]
       ,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("[tbl_upload_bb_added_price]");
        $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_upload_bb_added_price_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tbl_upload_bb_added_price]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	
	function tbl_data_part_hs_price_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		 [id]
      ,[partno2]
      ,[purchase_price]
      ,[valuta]
      ,convert(varchar(10),[tgl_berlaku],126) as tgl_berlaku
      ,[supplier]
	  ,[kode_supplier]
		");
		$this->db->from("[tbl_data_part_hs_price]");
        $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_data_part_hs_price_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tbl_data_part_hs_price]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	
	function tbl_upload_bb_added_daily_adjustment_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		 [id_upload_adjustment_daily]
      	   ,convert(varchar(10),[date_upload],126) as date_upload
      ,[filename]
      ,[tipe]
      ,[filepath]
      ,[status_upload]
       ,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("[tbl_upload_bb_added_adjustment_daily]");
        $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_upload_bb_added_daily_adjustment_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tbl_upload_bb_added_adjustment_daily]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	function tbl_data_part_hs_adjustment_All($limit,$start,$sidx,$sord, $where){
		$this->db->select("
		
		[id]
      ,[partno2]
      ,[qty_in]
      ,[qty_out]
      ,[amount_in]
      ,[amount_out]
      ,convert(varchar(10),[tgl_adjustment],126) as tgl_adjustment 
	  ,[jenis]
		");
		$this->db->from("[tbl_data_part_hs_adjustment]");
        $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_data_part_hs_adjustment_CountAll($where){
	
		$this->db->select("*");
        $this->db->from("[tbl_data_part_hs_adjustment]");
        $this->db->where($where);
        $result = $this->db->count_all_results(); 
        return $result;
	
	
	}
	
	
	function datamutasibb_All($limit,$start,$sidx,$sord, $where,$wheredate, $date1, $date2, $page){
		$query = $this->db->query("
			select 
				row
				,part_no
				,part_no2
				,part_no_sap
				,part_name
				,part_name2
				,new_part
				,shipment_term
				,supplier
				,supplier_kode
				,inland_koefisien
				,purchase_price_usd_amount
				,purchase_price_usd
				,purchase_price_eur
				,purchase_price_idr
				,costing_price_usd
				,currency_part_number
				,uom
				,begin_balance_qty
				,begin_balance_usd
				,price_adjustment
				,in_qty
				,in_usd
				,out_qty
				,out_usd
				,end_system_qty
				,end_system_usd
				,end_sto_qty
				,end_sto_usd
				,qty_in_daily_adjustment
				,amount_in_daily_adjustment
				,qty_out_daily_adjustment
				,amount_out_daily_adjustment
				,qty_adjustment_sto
				,amount_adjustment_sto
				,compare_more_qty
				,compare_more_usd
				,compare_less_qty
				,compare_less_usd
				,mutasi_after_sto_in_qty
				,mutasi_after_sto_in_usd
				,mutasi_after_sto_out_qty
				,mutasi_after_sto_out_usd
				,requirement_15_month
				,over_stock_qty
				,dead_stock_qty
				,over_stock_amount
				,dead_stock_amount
				,supply_to_jai_qty
				,supply_to_jai_amount
				,supply_to_sai_qty
				,supply_to_sai_amount
				,supply_to_sami_qty
				,supply_to_sami_amount
				,supply_to_suai_qty
				,supply_to_suai_amount
				,supply_to_pasi_qty
				,supply_to_pasi_amount
				,receive_to_jai_qty
				,receive_to_jai_amount
				,receive_to_samitugu_qty
				,receive_to_samitugu_amount
				,receive_to_sai_qty
				,receive_to_sai_amount
				,receive_to_suai_qty
				,receive_to_suai_amount
				,receive_to_samijepara_qty
				,receive_to_samijepara_amount
				,return_from_production_qty
				,return_from_production_amount
				,sales_material_qty
				,sales_material_amount
				,return_wire_tube_qty
				,return_wire_tube_amount
				,out_to_production_qty
				,out_to_production_amount
				,in_purchase_qty
				,in_purchase_amount
				,in_purchase_quotes
				,price_idr
				,status_data
				,qty
				,maker
				,supplier_oes

	
			from (
				select row_number() OVER (ORDER BY part_no) AS row
									,part_no
				,part_no2
				,part_no_sap
				,part_name
				,part_name2
				,new_part
				,shipment_term
				,supplier
				,supplier_kode
				,inland_koefisien
				,purchase_price_usd_amount
				,purchase_price_usd
				,purchase_price_eur
				,purchase_price_idr
				,costing_price_usd
				,currency_part_number
				,uom
				,begin_balance_qty
				,begin_balance_usd
				,price_adjustment
				,in_qty
				,in_usd
				,out_qty
				,out_usd
				,end_system_qty
				,end_system_usd
				,end_sto_qty
				,end_sto_usd
				,qty_in_daily_adjustment
				,amount_in_daily_adjustment
				,qty_out_daily_adjustment
				,amount_out_daily_adjustment
				,qty_adjustment_sto
				,amount_adjustment_sto
				,compare_more_qty
				,compare_more_usd
				,compare_less_qty
				,compare_less_usd
				,mutasi_after_sto_in_qty
				,mutasi_after_sto_in_usd
				,mutasi_after_sto_out_qty
				,mutasi_after_sto_out_usd
				,requirement_15_month
				,over_stock_qty
				,dead_stock_qty
				,over_stock_amount
				,dead_stock_amount
				,supply_to_jai_qty
				,supply_to_jai_amount
				,supply_to_sai_qty
				,supply_to_sai_amount
				,supply_to_sami_qty
				,supply_to_sami_amount
				,supply_to_suai_qty
				,supply_to_suai_amount
				,supply_to_pasi_qty
				,supply_to_pasi_amount
				,receive_to_jai_qty
				,receive_to_jai_amount
				,receive_to_samitugu_qty
				,receive_to_samitugu_amount
				,receive_to_sai_qty
				,receive_to_sai_amount
				,receive_to_suai_qty
				,receive_to_suai_amount
				,receive_to_samijepara_qty
				,receive_to_samijepara_amount
				,return_from_production_qty
				,return_from_production_amount
				,sales_material_qty
				,sales_material_amount
				,return_wire_tube_qty
				,return_wire_tube_amount
				,out_to_production_qty
				,out_to_production_amount
				,in_purchase_qty
				,in_purchase_amount
				,in_purchase_quotes
				,price_idr
				,status_data
				,qty
				,maker
				,supplier_oes
	
				from dbo.[f_mutasi_bb_added_mutasi]('$date1','$date2')
				where $where
			--where qty_saldoawal <> 0 or qty_in <> 0 or qty_out <>0

			) x where x.row between  ($page - 1) * $limit + 1 AND $page * $limit
			order by x.part_no asc
		
		");
		
		 //  $result = $this->db->get()->result(); 
        //die($this->db->last_query());
        
		$result = $query->result_array();
		//var_dump($result);
		//die();	
		return $result;
	
	}
	
	function datamutasibb_CountAll($where, $wheredate, $date1, $date2){
		 $query = $this->db->query("
			
			select COUNT(*) as cnt from (
			select row_number() OVER (ORDER BY part_no) AS row
			
			,part_no 
			
			
			from dbo.f_mutasi_bb_added_mutasi('$date1','$date2')
			where $where
			--where (qty_saldoawal <> 0 or qty_in <> 0 or qty_out <>0)  

			) x
		 ");

        //die($this->db->last_query());
        
		$result = $query->result_array();
		//var_dump($result);
		//die();
		$xx=0;
		foreach ($result as $r){
			$xx=$r['cnt'];
		}
		return $xx; 
	
	
	}
	
	
	
}
	
