<?php
class MDL_production extends CI_Model
{
	function __construct()
    {
        $CI =& get_instance(); 
	    $CI->db_pasi = $CI->load->database('pasi', TRUE);
	}
	
	function datasupplier_All($limit,$start,$sidx,$sord, $where){
		$this->db_pasi->select("
			[id]
		  ,[supplier_code]
		  ,[supplier_name]
		  ,[supplier_address]
		  ,[supplier_country]
		  ,[base_price]
		  ,[copper_base_reff]
		  ,[subgct]
		  ,[subcode_as400]
			
		");
		$this->db_pasi->from("[tbl_data_supplier]");
        $this->db_pasi->where($where);
        $this->db_pasi->limit($limit,$start);
        $this->db_pasi->order_by($sidx,$sord);
        $result = $this->db_pasi->get()->result(); 
        //die($this->db_pasi->last_query());
        return $result;
	
	}
	
	function datasupplier_CountAll($where){
	
		$this->db_pasi->select("*");
        $this->db_pasi->from("tbl_data_supplier");
        $this->db_pasi->where($where);
        $result = $this->db_pasi->count_all_results(); 
        return $result;
	
	
	}
	
	function datapart_hs_All($limit,$start,$sidx,$sord, $where){
		$this->db_pasi->select("
			id_raw_material, itemno, partno, unit, status
		");
		$this->db_pasi->from("[tbl_raw_material]");
        $this->db_pasi->where($where);
        $this->db_pasi->limit($limit,$start);
        $this->db_pasi->order_by($sidx,$sord);
        $result = $this->db_pasi->get()->result(); 
        //die($this->db_pasi->last_query());
        return $result;
	
	}
	
	function datapart_hs_CountAll($where){
	
		$this->db_pasi->select("*");
        $this->db_pasi->from("tbl_raw_material");
        $this->db_pasi->where($where);
        $result = $this->db_pasi->count_all_results(); 
        return $result;
	
	
	}
	
	function dataitemlist_All($limit,$start,$sidx,$sord, $where){
		$this->db_pasi->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_pasi->from("[tbl_item_list]");
        $this->db_pasi->where($where);
        $this->db_pasi->limit($limit,$start);
        $this->db_pasi->order_by($sidx,$sord);
        $result = $this->db_pasi->get()->result(); 
        //die($this->db_pasi->last_query());
        return $result;
	
	}
	
	function dataitemlist_CountAll($where){
	
		$this->db_pasi->select("*");
        $this->db_pasi->from("[tbl_item_list]");
        $this->db_pasi->where($where);
        $result = $this->db_pasi->count_all_results(); 
        return $result;
	
	
	}
		
	function dataitemfinishgood_All($limit,$start,$sidx,$sord, $where){
		$this->db_pasi->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]
				
		");
		$this->db_pasi->from("[tbl_assy_list]");
        $this->db_pasi->where($where);
        $this->db_pasi->limit($limit,$start);
        $this->db_pasi->order_by($sidx,$sord);
        $result = $this->db_pasi->get()->result(); 
        //die($this->db_pasi->last_query());
        return $result;
	
	}
	
	function dataitemfinishgood_CountAll($where){
	
		$this->db_pasi->select("*");
        $this->db_pasi->from("[tbl_assy_list]");
        $this->db_pasi->where($where);
        $result = $this->db_pasi->count_all_results(); 
        return $result;
	
	
	}
	
	
	function datakurs_All($limit,$start,$sidx,$sord, $where){
		$this->db_pasi->select("
			[id_kurs]
		  ,[KdKurs]
		  ,convert(varchar, [TgAwal], 101)  as TgAwal
		  ,convert(varchar,[TgAkhir],  101) as TgAkhir
		  ,[Nilai]
		  ,[Ket]
				
		");
		$this->db_pasi->from("[tblKurs]");
        $this->db_pasi->where($where);
        $this->db_pasi->limit($limit,$start);
        $this->db_pasi->order_by($sidx,$sord);
        $result = $this->db_pasi->get()->result(); 
        //die($this->db_pasi->last_query());
        return $result;
	
	}
	
	function datakurs_CountAll($where){
	
		$this->db_pasi->select("*");
        $this->db_pasi->from("[tblKurs]");
        $this->db_pasi->where($where);
        $result = $this->db_pasi->count_all_results(); 
        return $result;
	
	
	}

	function databpb_All($limit,$start,$sidx,$sord, $where){
		$this->db_pasi->select("
			id_bukti_penerimaan_brg,period,section_no,section_name,bpb_date,bpb_no,ri_no,ri_date,supp_do_no,supp_do_date,po_no,po_date,item_no,
			item_name,type,description,bpb_qty,unit,po_currency,po_amount,po_amount_usd
		");
		$this->db_pasi->from("tbl_buktipenerimaanbrg");
        $this->db_pasi->where($where);
        $this->db_pasi->limit($limit,$start);
        $this->db_pasi->order_by($sidx,$sord);
        $result = $this->db_pasi->get()->result(); 
        //die($this->db_pasi->last_query());
        return $result;
	}

	function databpb_CountAll($where){
	
		$this->db_pasi->select("*");
        $this->db_pasi->from("tbl_buktipenerimaanbrg");
        $this->db_pasi->where($where);
        $result = $this->db_pasi->count_all_results(); 
        return $result;
	}
	
	function databpbjadi_All($limit,$start,$sidx,$sord, $where){
		$this->db_pasi->select("
			id_bukti_penerimaan_brg_jadi,no_bpbj,tglprod,part_no,lot_no,article_code,kind,size,qty_coil,qty_meter
		");
		$this->db_pasi->from("tbl_buktipenerimaanbrgjadi");
        $this->db_pasi->where($where);
        $this->db_pasi->limit($limit,$start);
        $this->db_pasi->order_by($sidx,$sord);
        $result = $this->db_pasi->get()->result(); 
        //die($this->db_pasi->last_query());
        return $result;
	}

	function databpbjadi_CountAll($where){
	
		$this->db_pasi->select("*");
        $this->db_pasi->from("tbl_buktipenerimaanbrgjadi");
        $this->db_pasi->where($where);
        $result = $this->db_pasi->count_all_results(); 
        return $result;
	}

	function finishgoods_All($limit,$start,$sidx,$sord, $where){
		$this->db_pasi->select("
			[id_finish_goods]
			,[no_bpbj]
			,[tglprod]
			,[part_no]
			,[kdbrg]
			,[item_name]
			,[ttlQtyCoil]
			,[ttlQtyMeter]
			,[pvc_kgkm]
			,[copper_kgkm]
			,[ttl_pvc]
			,[ttl_copper]
			,[create_date]
			,[create_by]
			,[update_date]
			,[update_by]
			,[status]
		");
		$this->db_pasi->from("tbl_finish_goods");
        $this->db_pasi->where($where);
        $this->db_pasi->limit($limit,$start);
        $this->db_pasi->order_by($sidx,$sord);
        $result = $this->db_pasi->get()->result(); 
        //die($this->db_pasi->last_query());
        return $result;
	}

	function finishgoods_CountAll($where){
	
		$this->db_pasi->select("*");
        $this->db_pasi->from("tbl_finish_goods");
        $this->db_pasi->where($where);
        $result = $this->db_pasi->count_all_results(); 
        return $result;
	}
	
	function datareportbarangwip_All($limit,$start,$sidx,$sord, $date1, $date2){
		$query = $this->db_pasi->query("

		select row, namabarang,qty_in,qty_out,saldo_akhir from (
			select row_number() OVER (ORDER BY namabarang) AS row,namabarang,qty_in,qty_out,saldo_akhir
			from [dbo].[fn_mutasi_wip_baru](convert(date,'$date1',103),convert(date,'$date2',103))
		
		) x where x.row between $start and (1+$start)*$limit
		order by x.namabarang asc
		
		");
		
		$result = $query->result_array();	
		return $result;		
	}
	
	function datareportbarangwip_CountAll($date1, $date2){
		 $query = $this->db_pasi->query("
			
		select COUNT(*) as cnt from (
			select row_number() OVER (ORDER BY namabarang) AS row,namabarang,qty_in,qty_out,saldo_akhir
			from [dbo].[fn_mutasi_wip_baru](convert(date,'$date1',103),convert(date,'$date2',103))
			) x
		 ");
		$result = $query->result_array();

		$xx=0;
		foreach ($result as $r){
			$xx=$r['cnt'];
		}
		return $xx; 
	}
	
	function jenisscrap_all($limit,$start,$sidx,$sord, $where){
		$this->db_pasi->select("id_jenis_scrap as r1,JenisScrap as r2");
		$this->db_pasi->from("tbl_jenis_scrap");
        $this->db_pasi->where($where);
        $this->db_pasi->limit($limit,$start);
        $this->db_pasi->order_by($sidx,$sord);
        $result = $this->db_pasi->get()->result(); 
        //die($this->db_pasi->last_query());
        return $result;
	}
	
	function datascrap_All($limit,$start,$sidx,$sord, $where){
		$this->db_pasi->select("
			[id_real_scrap_hdr]
			,[date_start]
			,[date_end]
			,[total_pvc]
			,[total_copper]
			,[total_wire]
			,[total_scrapkemasan]
			,[create_date]
			,[create_by]
			,[update_date]
			,[update_by]
			,[status]
		");
		$this->db_pasi->from("tbl_real_scrap_hdr");
        $this->db_pasi->where($where);
        $this->db_pasi->limit($limit,$start);
        $this->db_pasi->order_by($sidx,$sord);
        $result = $this->db_pasi->get()->result(); 
        //die($this->db_pasi->last_query());
        return $result;
	}
	function datascrap_CountAll($where){
		$this->db_pasi->select("*");
        $this->db_pasi->from("tbl_real_scrap_hdr");
        $this->db_pasi->where($where);
        $result = $this->db_pasi->count_all_results(); 
        return $result;
	}
	
}
	
