<?php
class Requisitions extends CI_Model {


		public function all_requisition()
		{
		
		$query = "select 
					if( omd.material_id is not null,  ( (  order_detail.total_order_detail    ) - omd.order_qty), order_detail.total_order_detail ) 
							as total_order_detail,
							
							
					order_detail.so_po_id,
					order_detail.material_id,
					order_detail.unit as all_unit,
					order_detail.`status`,
					 

					omd.material_id as OMaterial_id,
					omd.product_id,
					omd.weight,
					omd.order_qty,
					omd.unit

					 from 
					(
					select  sum(od.total ) as total_order_detail,
					 
					 od.so_po_id,
					 od.material_id,

					 od.unit,
					 od.`status`
					 
					 

					from puchase_order_details as od

					 where od.material_id > 0 and od.`status`=0 and od.plan_status =0
					 
					group by od.material_id

					) as order_detail

					left join purchase_order_materials_details as omd on omd.material_id= order_detail.material_id  
					";
							

		$sql = $this->db->query($query);
			if($sql->num_rows() >0)
			{return $sql->result_array();
			}else
			{return false;}
		}

   /* public function remaining_requisition()
		{
		
		$this->db->select('SUM(purchase_order_materials_details.order_qty) AS order_qty,purchase_order_materials_details.material_id');
		$this->db->from('purchase_order_materials_details');
		
		$this->db->group_by('purchase_order_materials_details.material_id');
		

		$sql = $this->db->get();
			if($sql->num_rows() >0)
			{return $sql->result_array();
			}else
			{return false;}
		}*/


		public function all_requisition_pro()
		{
		/*$this->db->select('so_po_boms.so_id,so_po_boms.main_product,quantity,so_po_boms.status,so_po_boms.created,sales_order.so_no,sales_order.party_id,sales_order.so_date');
		$this->db->from('so_po_boms');
		$this->db->join('sales_order', 'so_po_boms.so_id = sales_order.id', 'inner');*/
		//$this->db->where('dc_record.qc_status',1 );
		//$this->db->group_by('so_po_boms.created');
		$this->db->select('so_po_boms.status,puchase_order_details.child_product,puchase_order_details.unit,SUM(puchase_order_details.total) AS total,puchase_order_details.status as items_status');
		$this->db->from('so_po_boms');
		$this->db->join('puchase_order_details', 'so_po_boms.id = puchase_order_details.so_po_id', 'inner');
		//$this->db->where('puchase_order_details.status',0);
		$this->db->group_by('puchase_order_details.child_product');

		$sql = $this->db->get();
			if($sql->num_rows() >0)
			{return $sql->result_array();
			}else
			{return false;}
		}


		public function all_requisition_molding_line()
		{
		$this->db->select('sales_order.id,sales_order.so_no,sales_order.party_id,sales_order.so_date,sales_order.production_status,sales_order_products.product_id,sales_order_products.total_qty,sales_order_products.so_id,sales_order_products.created,sales_order_products.quantity,so_po_boms.production_plan');
		$this->db->from('sales_order');
		//$this->db->join('sales_order', 'so_po_boms.so_id = sales_order.id', 'inner');
		$this->db->join('sales_order_products','sales_order.id = sales_order_products.so_id','left');
		$this->db->join('so_po_boms','sales_order.id = so_po_boms.so_id','left');

		//$this->db->join('products','puchase_order_details.child_product = products.id','inner');
		//$this->db->where("products.product_type",1);
		//$this->db->where("sales_order_products.bom_status !=",1);
		$this->db->group_by('sales_order.id');
		$sql = $this->db->get();
			if($sql->num_rows() >0)
			{return $sql->result_array();
			}else
			{return false;}
		}


		

		public function get_plan_data($id)
		{
		$this->db->select('production_plan.id,production_plan.so_id,production_plan.job,production_plan.product_name,production_plan.party_id,production_plan.pro_qty,production_plan.material_id,production_plan.bom_qty,production_plan.bom_unit,production_plan.in_stock_qty,production_plan.p_qty,production_plan.color_id,production_plan.cutting_ratio,production_plan.spec_no,production_plan.mold,production_plan.remarks,production_plan.created,production_plan.cqty,production_plan.bom_unit_color,production_machine_remarks.machine,production_machine_remarks.expected');
		$this->db->from('production_plan');
		$this->db->join('production_mould_remarks','production_plan.so_id = production_mould_remarks.so_id','left');
		$this->db->join('production_machine_remarks','production_plan.so_id = production_machine_remarks.so_id','left');
		/*$this->db->join('production_compund_stock_out','production_plan.id = production_compund_stock_out.production_id','left');*/
		$this->db->join('line_clerence','production_plan.id = line_clerence.so_id','left');
		$this->db->where('production_plan.so_id',$id);
		$this->db->group_by('production_plan.id','DESC');
		
		$sql = $this->db->get();
		//print_r($this->db->last_query());  die;
			if($sql->num_rows() >0)
			{return $sql->result_array();
			}else
			{return false;}
		}


		public function get_plan_all_compund($id)
		{
		$this->db->select('production_plan.id,production_plan.so_id,production_plan.job,production_plan.product_name,production_plan.party_id,production_plan.pro_qty,production_plan.material_id,production_plan.bom_qty,production_plan.bom_unit,production_plan.in_stock_qty,production_plan.p_qty,production_plan.color_id,production_plan.cutting_ratio,production_plan.spec_no,stock_out_production.material_id,stock_out_production.machine_id,stock_out_production.qcr,stock_out_production.color_code,stock_out_production.color_ratio,stock_out_production.qty,stock_out_production.wlot,stock_out_production.weight_wast,stock_out_production.created,stock_out_production.product_id');
		$this->db->from('production_plan');
		$this->db->join('stock_out_production','production_plan.so_id = stock_out_production.so_id','left');
	
		$this->db->where('stock_out_production.so_id',$id);
		$this->db->group_by('stock_out_production.id');

		$sql = $this->db->get();
		//print_r($this->db->last_query());  die;
			if($sql->num_rows() >0)
			{return $sql->result_array();
			}else
			{return false;}
		}



		public function all_requisition_printing_line()
		{
		$this->db->select('so_po_boms.so_id,so_po_boms.main_product,quantity,so_po_boms.status,so_po_boms.created,sales_order.so_no,sales_order.party_id,sales_order.so_date,puchase_order_details.material_id,puchase_order_details.child_product');
		$this->db->from('so_po_boms');
		$this->db->join('sales_order', 'so_po_boms.so_id = sales_order.id', 'inner');
		$this->db->join('puchase_order_details','so_po_boms.id = puchase_order_details.so_po_id','inner');
		$this->db->join('products','puchase_order_details.child_product = products.id','inner');
		$this->db->where("products.product_type",2);
		//$this->db->where("so_po_boms.main_product = products.id");
		$this->db->group_by('puchase_order_details.so_po_id');
		$sql = $this->db->get();
			if($sql->num_rows() >0)
			{return $sql->result_array();
			}else
			{return false;}
		}

		

			public function all_status_production($so_id)
		{
		$this->db->select('puchase_order_details.plan_status');
		$this->db->from('so_po_boms');
		//$this->db->join('sales_order', 'so_po_boms.so_id = sales_order.id', 'inner');
		$this->db->join('puchase_order_details','so_po_boms.id = puchase_order_details.so_po_id','left');
		//$this->db->join('products','puchase_order_details.child_product = products.id','inner');
		$this->db->where("so_po_boms.so_id",$so_id);
		$this->db->where("puchase_order_details.material_id !=",0);
		//$this->db->group_by('puchase_order_details.so_po_id');
		$sql = $this->db->get();
			if($sql->num_rows() >0)
			{return $sql->result_array();
			}else
			{return false;}
		}
		
			public function all_requisition_assembling_line()
			{
			$this->db->select('so_po_boms.so_id,so_po_boms.main_product,quantity,so_po_boms.status,so_po_boms.created,sales_order.so_no,sales_order.party_id,sales_order.so_date,puchase_order_details.material_id,puchase_order_details.child_product');
			$this->db->from('so_po_boms');
			$this->db->join('sales_order', 'so_po_boms.so_id = sales_order.id', 'inner');
			$this->db->join('puchase_order_details','so_po_boms.id = puchase_order_details.so_po_id','inner');
			$this->db->join('products','puchase_order_details.child_product = products.id','inner');
			$this->db->where("products.product_type",3);
			//$this->db->where("so_po_boms.main_product = products.id");
			$this->db->group_by('puchase_order_details.so_po_id');
			$sql = $this->db->get();
				if($sql->num_rows() >0)
				{return $sql->result_array();
				}else
				{return false;}
			}

			public function all_requisition_sealing_line()
			{
			$this->db->select('so_po_boms.so_id,so_po_boms.main_product,quantity,so_po_boms.status,so_po_boms.created,sales_order.so_no,sales_order.party_id,sales_order.so_date,puchase_order_details.material_id,puchase_order_details.child_product');
			$this->db->from('so_po_boms');
			$this->db->join('sales_order', 'so_po_boms.so_id = sales_order.id', 'inner');
			$this->db->join('puchase_order_details','so_po_boms.id = puchase_order_details.so_po_id','inner');
			$this->db->join('products','puchase_order_details.child_product = products.id','inner');
			$this->db->where("products.product_type",4);
			//$this->db->where("so_po_boms.main_product = products.id");
			$this->db->group_by('puchase_order_details.so_po_id');
			$sql = $this->db->get();
				if($sql->num_rows() >0)
				{return $sql->result_array();
				}else
				{return false;}
			}


			public function all_requisition_packing_line()
			{
			$this->db->select('so_po_boms.so_id,so_po_boms.main_product,quantity,so_po_boms.status,so_po_boms.created,sales_order.so_no,sales_order.party_id,sales_order.so_date,puchase_order_details.material_id,puchase_order_details.child_product');
			$this->db->from('so_po_boms');
			$this->db->join('sales_order', 'so_po_boms.so_id = sales_order.id', 'inner');
			$this->db->join('puchase_order_details','so_po_boms.id = puchase_order_details.so_po_id','inner');
			$this->db->join('materials','puchase_order_details.material_id = materials.id','inner');
			$this->db->where("materials.type",2);
			//$this->db->where("so_po_boms.main_product = products.id");
			$this->db->group_by('puchase_order_details.so_po_id');
			$sql = $this->db->get();
				if($sql->num_rows() >0)
				{return $sql->result_array();
				}else
				{return false;}
			}
		

		public function boms_requisition($id)
		{
		$this->db->select('so_po_boms.so_id,so_po_boms.main_product,quantity,puchase_order_details.material_id,puchase_order_details.child_product,puchase_order_details.unit,puchase_order_details.total');
		$this->db->from('so_po_boms');
		$this->db->join('puchase_order_details', 'so_po_boms.id = puchase_order_details.so_po_id', 'inner');
		$this->db->where('so_po_boms.so_id',$id);
		//$this->db->group_by('so_po_boms.created');
		$sql = $this->db->get();
			if($sql->num_rows() >0)
			{return $sql->result_array();
			}else
			{return false;}
		}


		public function get_production_plan_data($id)
		{
	
		 $sql = $this->db->where('so_po_id',$id);
		 $sql = $this->db->where('child_product !=',0);
		 $sql = $this->db->get('puchase_order_details');
		
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	
		}

         public function delete_parameter_plan($id)
	{
		$sql = $this->db->delete('qc_parameter_samples', array('so_id'=>$id));
		
		return true;
	}

	 public function delete_plan($id)
	{
		$sql = $this->db->delete('production_plan', array('so_id'=>$id));
		
		return true;
	}


	 public function delete_machine($id)
	{
		$sql = $this->db->delete('production_machine_remarks', array('so_id'=>$id));
		
		return true;
	}


	 public function delete_moulds_plan($id)
	{
		$sql = $this->db->delete('production_mould_remarks', array('so_id'=>$id));
		
		return true;
	}

	public function delete_bom_laod($so_get_so_id)
	{
		$sql = $this->db->delete('puchase_order_details', array('so_po_id'=>$so_get_so_id));
		
		return true;
	}

	public function delete_so_po_boms($id)
	{
		
		$sql = $this->db->delete('so_po_boms', array('so_id'=>$id));
		//print_r($this->db->last_query());  die;
		return true;
	}

	

	public function compound_deleted($id)
	{
		
		$sql = $this->db->delete('stock_out_production', array('so_id'=>$id));
		//print_r($this->db->last_query());  die;
		return true;
	}
		

		/*public function machine_available($id)
		{
	
	


		$this->db->select('production_machine_remarks.status');  
		  
		$this->db->from('production_machine_remarks');
		//$this->db->where("production_machine_remarks.status",0);
		$this->db->where("production_machine_remarks.machine",$id);
		$sql = $this->db->get();
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	
		}
*/

		 public function machine_available($machine){

    	    $this->db->where("production_machine_remarks.status",0);
    	    //$this->db->where("production_machine_remarks.so_id",$so_id);
    	    //$this->db->where("production_machine_remarks.product_id",$product_id);
    		$this->db->where("production_machine_remarks.machine",$machine);
    	
			 $sql = $this->db->get('production_machine_remarks');

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }

		
		 public function update_so_po_for_bom($get_so_po,$material_id,$pro_id) {
			$result = $this->db->where('so_po_id',$get_so_po);
			$result = $this->db->where('material_id',$material_id);
			$result = $this->db->where('child_product',$pro_id);
			$result = $this->db->update('puchase_order_details',array('plan_status' =>1));
			if($result){return true;}else{return false;}
		}

		
		/*public function update_so_plan_status($so_id) {
			$result = $this->db->where('id',$so_id);
		
			$result = $this->db->update('sales_order',array('production_status' =>1));
			if($result){return true;}else{return false;}
		}*/


		public function update_so_plan_status($so_id) {
			$result = $this->db->where('so_id',$so_id);
		
			$result = $this->db->update('so_po_boms',array('production_plan' =>1));
			if($result){return true;}else{return false;}
		}
		
		public function get_production_plan_data_material_for_addproduction($so_id,$product)
		{
	
		$this->db->select('so_po_boms.so_id,so_po_boms.quantity,so_po_boms.main_product,puchase_order_details.material_id,puchase_order_details.child_product,puchase_order_details.unit,puchase_order_details.total');  
		  
		$this->db->from('so_po_boms');
		$this->db->join('puchase_order_details', 'so_po_boms.id = puchase_order_details.so_po_id', 'left');
		$this->db->where("so_po_boms.id",$so_id);
		$this->db->where("puchase_order_details.child_product",$product);

		$this->db->where("puchase_order_details.plan_status",0);


		/*$this->db->select('so_po_boms.so_id,so_po_boms.quantity,so_po_boms.main_product,boms_materials.material_id');  
		  
		$this->db->from('so_po_boms');
		$this->db->join('boms_materials', 'so_po_boms.main_product = boms_materials.main_product', 'left');
		$this->db->where("so_po_boms.so_id",$so_id);
		$this->db->where("boms_materials.product_id",$product);
		$this->db->where("boms_materials.product_id !=",0);*/
		
		//$this->db->group_by("boms_materials.product_id");

		//$this->db->group_by("boms.product_id");
		//
		$sql = $this->db->get();
		//print_r($this->db->last_query());  die;
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	
		}

	public function get_production_plan_data_material($so_id,$product)
		{
	
		$this->db->select('so_po_boms.so_id,so_po_boms.quantity,so_po_boms.main_product,puchase_order_details.material_id,puchase_order_details.child_product,puchase_order_details.unit,puchase_order_details.total');  
		  
		$this->db->from('so_po_boms');
		$this->db->join('puchase_order_details', 'so_po_boms.id = puchase_order_details.so_po_id', 'left');
		$this->db->where("so_po_boms.so_id",$so_id);
		$this->db->where("puchase_order_details.child_product",$product);

		$this->db->where("puchase_order_details.plan_status",0);


		/*$this->db->select('so_po_boms.so_id,so_po_boms.quantity,so_po_boms.main_product,boms_materials.material_id');  
		  
		$this->db->from('so_po_boms');
		$this->db->join('boms_materials', 'so_po_boms.main_product = boms_materials.main_product', 'left');
		$this->db->where("so_po_boms.so_id",$so_id);
		$this->db->where("boms_materials.product_id",$product);
		$this->db->where("boms_materials.product_id !=",0);*/
		
		//$this->db->group_by("boms_materials.product_id");

		//$this->db->group_by("boms.product_id");
		//
		$sql = $this->db->get();
		//print_r($this->db->last_query());  die;
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	
		}

		

		public function get_production_plan_data_semi($so_id)
		{
	
		$this->db->select('so_po_boms.so_id,so_po_boms.quantity,so_po_boms.main_product,boms_materials.product_id');  
		  
		$this->db->from('so_po_boms');
		$this->db->join('boms_materials', 'so_po_boms.main_product = boms_materials.main_product', 'left');
		//$this->db->join('production_plan', 'production_plan.so_id = so_po_boms.so_id', 'left');
		$this->db->where("so_po_boms.id",$so_id);
		$this->db->where("boms_materials.product_id !=",0);
		
		$this->db->group_by("boms_materials.product_id");
		//
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	
		}


		public function get_plan_id($id){

    	$this->db->select('*');
		$this->db->from('production_plan');
		//$this->db->join('qc_parameter_samples', 'qc_parameter.id = qc_parameter_samples.para_id', 'inner');
		$sql = $this->db->where('production_plan.id',$id);
		
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }


		
		public function get_production($so_id,$pro_name)
		{
	
		$this->db->select('production_plan.id,production_plan.so_id,production_plan.job,production_plan.pro_qty,production_plan.material_id,production_plan.p_qty,production_plan.color_id,production_plan.cutting_ratio,production_plan.spec_no,production_plan.mold,production_plan.product_name');  
		  
		$this->db->from('production_plan');
		$this->db->where("production_plan.so_id",$so_id);
		$this->db->where("production_plan.product_name",$pro_name);
		//$this->db->group_by("boms.product_id");
		//
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	
		}
		
		public function get_production_plan_qty($id,$pro_seg,$so_id){


			$this->db->select('so_po_boms.so_id,so_po_boms.quantity,so_po_boms.main_product,puchase_order_details.material_id,puchase_order_details.child_product,puchase_order_details.unit,puchase_order_details.total');  
		  
		$this->db->from('so_po_boms');
		$this->db->join('puchase_order_details', 'so_po_boms.id = puchase_order_details.so_po_id', 'left');
		$this->db->where("puchase_order_details.material_id",$id);
		$this->db->where("puchase_order_details.child_product",$pro_seg);
	   $this->db->where("puchase_order_details.material_id !=",0);
	   $this->db->where("puchase_order_details.so_po_id",$so_id);
		//$this->db->group_by("boms.product_id");
		//
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
		}


		

		public function get_so_data($so_id_get_from_sopoboms)
		{
			/*print_r($so_id);
			die;*/
	
		 $this->db->select('sales_order.id as sales_order_id,sales_order.party_id,sales_order.so_no,sales_order.so_date,sales_order.instruction,sales_order.pay_term,sales_order.status,sales_order.production_status,sales_order_products.so_id,sales_order_products.product_id,sales_order_products.total_qty,sales_order_products.quantity');  
		  
		$this->db->from('sales_order');
		
		$this->db->join('sales_order_products', 'sales_order.id = sales_order_products.so_id', 'left');
		//$this->db->where('sales_order.status',1);
		$this->db->where('sales_order_products.so_id',$so_id_get_from_sopoboms);
		$sql = $this->db->get();
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	
		}
		

		public function get_production_plan_material($id)
		{
	
		 
			$this->db->select('puchase_order_details.total,materials.color,puchase_order_details.id as pur_id');    
			$this->db->from('puchase_order_details');
			$this->db->join('materials', 'puchase_order_details.material_id = materials.id', 'inner');
			$this->db->where("puchase_order_details.id",$id); 
			$sql = $this->db->get();

			if($sql->num_rows() >0)
			{return $sql->result_array();
			}else
			{return false;}
	
		}

		public function get_molds_data()
		{
	
		
		 $sql = $this->db->get('molds');
		
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	
		}
		
			public function get_molds_data_products($product_id)
		{
	
		$this->db->select('*');  
		  
		$this->db->from('molds');
		$this->db->where("molds.product_id",$product_id);
		//$this->db->where("production_plan.product_name",$pro_name);
		//$this->db->group_by("boms.product_id");
		//
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	
		}




		public function get_machine_data()
		{
	
		
		 $sql = $this->db->get('machines');
		$this->db->select('machines.id,machines.machine_name');    
			$this->db->from('machines');
			/*$this->db->join('production_machine_remarks', 'machines.id = production_machine_remarks.machine', 'inner');
			$this->db->where("production_machine_remarks.status !=",0); */
			$sql = $this->db->get();
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	
		}



		public function add_plan_data($arrayName) {
          $result = $this->db->insert('production_plan',$arrayName);
          if($result){return true;}else{return false;} 
		  
    }

	public function add_config($arrayName) {
		$result = $this->db->insert('machine_config',$arrayName);
		if($result){return true;}else{return false;} 
		
  }
	
  
  public function add_config_ibm($arrayName) {
	$result = $this->db->insert('machine_config_ibm',$arrayName);
	if($result){return true;}else{return false;} 
	
}
    

		public function add_assembled_log($arrayName) {
          $result = $this->db->insert('assembled_line_log',$arrayName);
          if($result){return true;}else{return false;} 
		  
    }


    public function add_sealed_log($arrayName) {
          $result = $this->db->insert('sealed_line_log',$arrayName);
          if($result){return true;}else{return false;} 
		  
    }

    public function add_printing_log($arrayName) {
          $result = $this->db->insert('printing_line_log',$arrayName);
          if($result){return true;}else{return false;} 
		  
    }
    
    public function add_packing_log($arrayName) {
          $result = $this->db->insert('fg_line_log',$arrayName);
          if($result){return true;}else{return false;} 
		  
    }


    public function production_machine_remarks($arrayName) {
		$result = $this->db->insert('production_machine_remarks',$arrayName);
		if($result){return true;}else{return false;}
	}

    
    public function update_plan_status($assembled_id) {
		$result = $this->db->where('id',$assembled_id);
		$result = $this->db->update('puchase_order_details',array('plan_status' =>1));
		if($result){return true;}else{return false;}
	}


	
	public function update_config_machine($so_id,$product,$machine) {
		$result = $this->db->where('so_id',$so_id);
		$result = $this->db->where('product_id',$product);
		$result = $this->db->where('machine',$machine);
		$result = $this->db->where('config',0);
		$result = $this->db->update('production_machine_remarks',array('config' =>1));
		if($result){return true;}else{return false;}
	}

	
	public function update_assembled_status($assembled_line) {
		$result = $this->db->where('id',$assembled_line);
		$result = $this->db->update('assembled_line',array('status' =>1));
		if($result){return true;}else{return false;}
	}

		public function update_product_plan_active($id,$dataarray) {
		$result = $this->db->where('id',$id);
		$result = $this->db->update('production_plan',$dataarray);
		if($result){return true;}else{return false;}
		}
	
		public function update_product_plan($id) {
		$result = $this->db->where('id',$id);
		$result = $this->db->update('production_plan',array('complete_status' =>2));
		if($result){return true;}else{return false;}
		}


	
	public function update_product_plan_machine($id,$so_id) {
		$result = $this->db->where('product_id',$id);
		$result = $this->db->where('so_id',$so_id);
		$result = $this->db->where('status',0);
		$result = $this->db->update('production_machine_remarks',array('status' =>1));
		if($result){return true;}else{return false;}
		}


		public function update_product_plan_machine_active($id,$so_id) {
		$result = $this->db->where('product_id',$id);
		$result = $this->db->where('so_id',$so_id);
		$result = $this->db->where('status',1);
		$result = $this->db->update('production_machine_remarks',array('status' =>0));
		if($result){return true;}else{return false;}
		}




	public function update_sealed_status($sealed_id) {
		$result = $this->db->where('id',$sealed_id);
		$result = $this->db->update('sealed_line',array('status' =>1));
		if($result){return true;}else{return false;}
	}


	public function update_printing_status($printing_id) {
		$result = $this->db->where('id',$printing_id);
		$result = $this->db->update('printed_line',array('status' =>1));
		if($result){return true;}else{return false;}
	}

	
	public function update_packing_status($packing_id) {
		$result = $this->db->where('id',$packing_id);
		$result = $this->db->update('fg_line',array('status' =>1));
		if($result){return true;}else{return false;}
	}

	public function	update_plan_status_material($id){

		$result = $this->db->where('id',$id);
		$result = $this->db->update('puchase_order_details',array('plan_status' =>1));
		if($result){return true;}else{return false;}

	}


		public function update_so_id_status($so_id) {
		$result = $this->db->where('id',$so_id);
		$result = $this->db->update('sales_order',array('production_status' =>1));
		if($result){return true;}else{return false;}
	}



	public function get_view($id){

		 $sql = $this->db->where('child_id',$id);
		 //$sql = $this->db->group_by('material_id');
		 $sql = $this->db->get('production_plan');
		
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

	}

	
	public function check_datain_production($so_id){

		 $sql = $this->db->where('so_id',$so_id);
		 //$sql = $this->db->group_by('material_id');
		 $sql = $this->db->get('production_plan');
		
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

	}

	public function get_material($id){

		 $sql = $this->db->where('id',$id);
		 //$sql = $this->db->group_by('material_id');
		 $sql = $this->db->get('materials');
		
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

	}

	public function get_all_data($id){


		$this->db->select('so_po_boms.id as so_po_bomid,so_po_boms.so_id,so_po_boms.main_product,sales_order_products.quantity,so_po_boms.status,so_po_boms.created,sales_order.so_no,sales_order.party_id,sales_order.so_date,production_plan.color_id,production_plan.qty,production_plan.child_id,production_plan.material_id,production_plan.mold,sales_order_products.product_id,sales_order_products.ref_code,puchase_order_details.total,puchase_order_details.child_product');
		$this->db->from('so_po_boms');
		$this->db->join('sales_order', 'so_po_boms.so_id = sales_order.id', 'inner');
		$this->db->join('sales_order_products', 'sales_order.id = sales_order_products.so_id', 'inner');
		$this->db->join('production_plan','so_po_boms.id = production_plan.so_id','inner');
		$this->db->join('puchase_order_details','so_po_boms.id = puchase_order_details.so_po_id','inner');

		$this->db->where('production_plan.so_id',$id);
		$sql = $this->db->where('child_product !=',0);
		$this->db->group_by('production_plan.material_id');
		$sql = $this->db->get();
			if($sql->num_rows() >0)
			{return $sql->result_array();
			}else
			{return false;}

	}


	public function get_all_data_pro(){


		$this->db->select('so_po_boms.id as so_po_bomid,so_po_boms.so_id,so_po_boms.main_product,sales_order_products.quantity,so_po_boms.status,so_po_boms.created,sales_order.so_no,sales_order.party_id,sales_order.so_date,production_plan.color_id,production_plan.qty,production_plan.child_id,production_plan.material_id,production_plan.mold,production_plan.job,sales_order_products.product_id,sales_order_products.ref_code,puchase_order_details.total,puchase_order_details.child_product');
		$this->db->from('so_po_boms');
		$this->db->join('sales_order', 'so_po_boms.so_id = sales_order.id', 'inner');
		$this->db->join('sales_order_products', 'sales_order.id = sales_order_products.so_id', 'inner');
		$this->db->join('production_plan','so_po_boms.id = production_plan.so_id','inner');
		$this->db->join('puchase_order_details','so_po_boms.id = puchase_order_details.so_po_id','inner');

		//$this->db->where('production_plan.so_id',$id);
		$sql = $this->db->where('child_product !=',0);
		$this->db->group_by('production_plan.material_id');
		$sql = $this->db->get();
			if($sql->num_rows() >0)
			{return $sql->result_array();
			}else
			{return false;}

	}


	

	public function add_line_clerence_data($post) {
          $result = $this->db->insert('line_clerence',$post);
          if($result){return true;}else{return false;} 
		  
    }

    public function get_parameters_data($mold){
    	
		$this->db->select('so_po_boms.so_id,so_po_boms.main_product,so_po_boms.quantity,production_plan.job,production_plan.p_qty,production_plan.mold,production_plan.id,production_plan.material_id,production_plan.product_name');
		$this->db->from('production_plan');
		$this->db->join('so_po_boms', 'so_po_boms.so_id = production_plan.so_id', 'left');
		$sql = $this->db->where('so_po_boms.production_plan',5);
		$sql = $this->db->where('production_plan.status',4);
		 $sql = $this->db->where('mold',$mold);
		 
		 /*  $sql = $this->db->where('product_name',$p_name);
		    $sql = $this->db->where('so_id',$so_id);*/
		//$sql = $this->db->group_by('production_plan.product_name','DESC');
		$sql = $this->db->get();
		/*print_r($this->db->last_query());  die;*/
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
   
    }


    
     public function inspec_details($mold,$so_id1){

    	 
		 $this->db->select('production_plan.job,production_plan.p_qty,production_plan.mold,production_plan.id,production_plan.material_id,production_plan.product_name,qc_parameter.id,qc_parameter.sno_num,qc_parameter.descrip,qc_parameter.parameters,production_plan.so_id');
		$this->db->from('production_plan');
		
		$this->db->join('qc_parameter', 'production_plan.mold = qc_parameter.mold_id', 'left');
		/*$sql = $this->db->where('so_po_boms.production_plan',5);
		$sql = $this->db->where('production_plan.status',4);*/
	    $sql = $this->db->where('production_plan.so_id',$so_id1);
	    $sql = $this->db->where('qc_parameter.mold_id',$mold);
	     $sql = $this->db->group_by('qc_parameter.id','DESC');
	    $sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }



     public function all_inspec_details($mold,$so_id){

    	$this->db->select('qc_parameter.min_range,qc_parameter.max_range,qc_parameter.created,qc_parameter.id,qc_parameter.mold_id,qc_parameter.sno_num,qc_parameter.descrip,qc_parameter.parameters,qc_parameter_samples.sample_size,qc_parameter_samples.para_id,qc_parameter_samples.sample_1,qc_parameter_samples.sample_2,qc_parameter_samples.sample_3,qc_parameter_samples.sample_4,qc_parameter_samples.sample_5,qc_parameter_samples.sample_6,qc_parameter_samples.sample_7,qc_parameter_samples.sample_8,qc_parameter_samples.sample_9,qc_parameter_samples.sample_10,qc_parameter_samples.sample_11,qc_parameter_samples.sample_12,qc_parameter_samples.sample_13,qc_parameter_samples.sample_14,qc_parameter_samples.sample_15,qc_parameter_samples.sample_16,qc_parameter_samples.sample_17,qc_parameter_samples.sample_18,qc_parameter_samples.sample_19,qc_parameter_samples.sample_20,qc_parameter_samples.sample_21,qc_parameter_samples.sample_22,qc_parameter_samples.sample_23,qc_parameter_samples.sample_24,qc_parameter_samples.id as parameter_id');
		$this->db->from('qc_parameter');
		$this->db->join('qc_parameter_samples', 'qc_parameter.id = qc_parameter_samples.para_id', 'inner');
		$sql = $this->db->where('qc_parameter.mold_id',$mold);
		$sql = $this->db->where('qc_parameter_samples.so_id',$so_id);
		$this->db->order_by('qc_parameter_samples.id','ASC');
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }


    public function all_columns_count($id,$so_id){

    	$this->db->select('qc_parameter_samples.sample_1,qc_parameter_samples.sample_2,qc_parameter_samples.sample_3,qc_parameter_samples.sample_4,qc_parameter_samples.sample_5,qc_parameter_samples.sample_6,qc_parameter_samples.sample_7,qc_parameter_samples.sample_8,qc_parameter_samples.sample_9,qc_parameter_samples.sample_10,qc_parameter_samples.sample_11,qc_parameter_samples.sample_12,qc_parameter_samples.sample_13,qc_parameter_samples.sample_14,qc_parameter_samples.sample_15,qc_parameter_samples.sample_16,qc_parameter_samples.sample_17,qc_parameter_samples.sample_18,qc_parameter_samples.sample_19,qc_parameter_samples.sample_20,qc_parameter_samples.sample_21,qc_parameter_samples.sample_22,qc_parameter_samples.sample_23,qc_parameter_samples.sample_24');
		$this->db->from('qc_parameter');
		$this->db->join('qc_parameter_samples', 'qc_parameter.id = qc_parameter_samples.para_id', 'inner');
		$sql = $this->db->where('qc_parameter.mold_id',$id);
		$sql = $this->db->where('qc_parameter_samples.so_id',$so_id);
		$this->db->order_by('qc_parameter_samples.id','ASC');
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }

    

    	 public function delete_parameter($id)
	{
		$sql = $this->db->delete('qc_parameter_samples', array('id'=>$id));
		
		return true;
	}
    

      public function all_inspec($mold){

    	$this->db->select('qc_parameter.id,qc_parameter.mold_id,qc_parameter.sno_num,qc_parameter.descrip,qc_parameter.parameters,qc_parameter_samples.sample_size,qc_parameter_samples.para_id');
		$this->db->from('qc_parameter');
		$this->db->join('qc_parameter_samples', 'qc_parameter.id = qc_parameter_samples.para_id', 'inner');
		//$sql = $this->db->where('qc_parameter.mold_id',$mold);
		//$this->db->group_by('qc_parameter_samples.para_id');
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }

     public function get_view_inspec($id){

    	$sql = $this->db->where('id',$id);
		 //$sql = $this->db->group_by('material_id');
		 $sql = $this->db->get('qc_parameter');

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }

    

    public function get_inspection_condition($so_id,$para_id){

    	 $sql = $this->db->where('so_id',$so_id);
    	 $sql = $this->db->where('para_id',$para_id);
		 //$sql = $this->db->group_by('material_id');
		 $sql = $this->db->get('qc_parameter_samples');

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }
    
      public function add_add_inspecdata($product_id,$so_id,$para_id,$sample_1,$sample_2,$sample_3,$sample_4,$sample_5,$sample_6,$sample_7,$sample_8,$sample_9,$sample_10,$sample_11,$sample_12,$sample_13,$sample_14,$sample_15,$sample_16,$sample_17,$sample_18,$sample_19,$sample_20,$sample_21,$sample_22,$sample_23,$sample_24,$remarks,$user_id,$created,$modified) {


		$data = array(
					'product_id' => $product_id,
					'so_id' => $so_id,
			        'para_id' => $para_id,
			        //'sample_size' => $sample_size,
			        'sample_1' => $sample_1,
			        'sample_2' => $sample_2,
			        'sample_3' => $sample_3,
			        'sample_4' => $sample_4,
			        'sample_5' => $sample_5,
			        'sample_6' => $sample_6,
			        'sample_7' => $sample_7,
			        'sample_8' => $sample_8,
			        'sample_9' => $sample_9,
			        'sample_10' => $sample_10,
			        'sample_11' => $sample_11,
			        'sample_12' => $sample_12,
			        'sample_13' => $sample_13,
			        'sample_14' => $sample_14,
			        'sample_15' => $sample_15,
			        'sample_16' => $sample_16,
			        'sample_17' => $sample_17,
			        'sample_18' => $sample_18,
			        'sample_19' => $sample_19,
			        'sample_20' => $sample_20,
			        'sample_21' => $sample_21,
			        'sample_22' => $sample_22,
			        'sample_23' => $sample_23,
			        'sample_24' => $sample_24,
			        'remarks' => $remarks,
			        'user_id'=> $user_id,
      	            'created' => $created,
			        'modified' => $modified
			        
			        );  
		 
          $result = $this->db->insert('qc_parameter_samples',$data);
          if($result){return true;}else{return false;} 
		  
    }


    

    public function view_ins_samples_details($id){

    	$sql = $this->db->where('para_id',$id);
		 //$sql = $this->db->group_by('material_id');
		 $sql = $this->db->get('qc_parameter_samples');

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }


    
    public function	update_status($para_id){

		$result = $this->db->where('id',$para_id);
		$result = $this->db->update('production_plan',array('status' =>1));
		if($result){return true;}else{return false;}

	}


	

	public function get_counter_number(){

		$this->db->select('production_plan.job');  
		  
		$this->db->from('production_plan');
	
		$this->db->order_by('id','DESC');
		
		$this->db->limit(1);
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}


	public function get_counter_number_qcr(){

		$this->db->select('production_compund_stock_out.qcr');  
		  
		$this->db->from('production_compund_stock_out');
	
		$this->db->order_by('qcr','DESC');
		
		$this->db->limit(1);
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}


	

	public function get_color_ids($material_id){

		$this->db->select('material_mix_color.color_id');  
		  
		$this->db->from('material_mix_color');
		
		$this->db->where('material_id',$material_id);
		
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	

	public function get_match_color_bom($value){

		$this->db->select('puchase_order_details.material_id');  
		  
		$this->db->from('puchase_order_details');
		
		$this->db->where_in('puchase_order_details.material_id',$value);
		
		$sql = $this->db->get();


		foreach ($sql->result() as $row)
		{
		       if($sql->num_rows() >0)
				{return  $row->material_id;
				}else
				{return false;}
		}

		
	}
	

	public function mould_depart_production(){

		$this->db->select('so_po_boms.production_plan,so_po_boms.so_id,so_po_boms.main_product,so_po_boms.quantity,production_plan.job,production_plan.p_qty,production_plan.mold,production_plan.id,production_plan.status,production_plan.product_name');
		$this->db->from('production_plan');
		$this->db->join('so_po_boms', 'so_po_boms.so_id = production_plan.so_id', 'left');
		//$sql = $this->db->where('so_po_boms.production_plan',1);
		$sql = $this->db->where('production_plan.complete_status',0);
		//$this->db->group_by('production_plan.product_name','DESC');
		$sql = $this->db->get();
		/*print_r($this->db->last_query());  die;*/
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }


     public function machine_depart_production(){

			$this->db->select('so_po_boms.production_plan,so_po_boms.so_id,so_po_boms.main_product,so_po_boms.quantity,production_plan.job,production_plan.p_qty,production_plan.mold,production_plan.id,production_plan.product_name,production_plan.status');
			$this->db->from('production_plan');
			$this->db->join('so_po_boms', 'so_po_boms.so_id = production_plan.so_id', 'left');
			//$sql = $this->db->where('so_po_boms.production_plan',2);
			$sql = $this->db->where('production_plan.complete_status',0);
			//$this->db->group_by('production_plan.product_name','DESC');
			$sql = $this->db->get();
			/*print_r($this->db->last_query());  die;*/
			if($sql->num_rows() >0)
			{return $sql->result_array();
			}else
			{return false;}
			    }


				public function machine_depart_production_config(){

					$this->db->select('*');
					$this->db->from('production_machine_remarks');
					
					$sql = $this->db->where('production_machine_remarks.status',0);
					$sql = $this->db->where('production_machine_remarks.config',0);
					//$this->db->group_by('production_plan.product_name','DESC');
					$sql = $this->db->get();
					/*print_r($this->db->last_query());  die;*/
					if($sql->num_rows() >0)
					{return $sql->result_array();
					}else
					{return false;}
						}


    
    public function lineclerence_depart_production(){

		$this->db->select('so_po_boms.so_id,so_po_boms.main_product,so_po_boms.quantity,production_plan.job,production_plan.p_qty,production_plan.mold,production_plan.id,production_plan.product_name');
		$this->db->from('production_plan');
		$this->db->join('so_po_boms', 'so_po_boms.so_id = production_plan.so_id', 'left');
		//$sql = $this->db->where('so_po_boms.production_plan',3);
		$sql = $this->db->where('production_plan.status',2);
		$this->db->group_by('production_plan.product_name','DESC');
		$sql = $this->db->get();
		/*print_r($this->db->last_query());  die;*/
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }

    
    public function compound_production_department(){

		$this->db->select('so_po_boms.so_id,so_po_boms.main_product,so_po_boms.quantity,production_plan.job,production_plan.p_qty,production_plan.mold,production_plan.id');
		$this->db->from('production_plan');
		$this->db->join('so_po_boms', 'so_po_boms.so_id = production_plan.so_id', 'left');
		//$sql = $this->db->where('so_po_boms.production_plan',3);
		//$sql = $this->db->where('production_plan.status',2);
		
		$sql = $this->db->get();
		/*print_r($this->db->last_query());  die;*/
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }


    

    public function get_condition($material_id,$machine_id,$insert_date,$production_id){

		$this->db->select('production_compund_stock_out.insert_date');
		$this->db->from('production_compund_stock_out');
		//$this->db->join('so_po_boms', 'so_po_boms.so_id = production_plan.so_id', 'left');
		$sql = $this->db->where('production_compund_stock_out.material_id',$material_id);
		$sql = $this->db->where('production_compund_stock_out.machine_id',$machine_id);
		$sql = $this->db->where('production_compund_stock_out.insert_date',$insert_date);
		$sql = $this->db->where('production_compund_stock_out.production_id',$production_id);
		$sql = $this->db->get();
		/*print_r($this->db->last_query());  die;*/
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }


      public function product_inspection_department(){

		$this->db->select('so_po_boms.so_id,so_po_boms.main_product,so_po_boms.quantity,production_plan.job,production_plan.p_qty,production_plan.mold,production_plan.id,production_plan.material_id,production_plan.product_name,production_plan.id');
		$this->db->from('production_plan');
		$this->db->join('so_po_boms', 'so_po_boms.so_id = production_plan.so_id', 'left');
		$sql = $this->db->where('so_po_boms.production_plan',5);
		$sql = $this->db->where('production_plan.status',4);
		$sql = $this->db->group_by('production_plan.product_name','DESC');
		$sql = $this->db->get();
		/*print_r($this->db->last_query());  die;*/
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }




     

    public function get_details_mould($items,$so_id){

		$this->db->select('production_plan.job,production_plan.p_qty,production_plan.mold,production_plan.so_id,production_plan.id,production_plan.material_id,production_plan.product_name,production_plan.so_id');
		$this->db->from('production_plan');
		
		$sql = $this->db->where('production_plan.product_name',$items);
		$sql = $this->db->where('production_plan.so_id',$so_id);
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }


    

    public function add_remarks_mould($arrayName) {

          $result = $this->db->insert('production_mould_remarks',$arrayName);
          if($result){return true;}else{return false;} 
		  
    }


    public function add_remarks_machine($arrayName) {

          $result = $this->db->insert('line_clerence',$arrayName);
          if($result){return true;}else{return false;} 
		  
    }

     public function update_production_mould($so_id,$p_name)
			{
			
				$result = $this->db->where('so_id',$so_id);
				$result = $this->db->where('product_name',$p_name);
				$result = $this->db->update('production_plan',array('status' => 1));
				if($result){return true;}else{return false;}
			}


			
			public function update_production_machine($so_id,$product_id)
			{
			
				$result = $this->db->where('so_id',$so_id);
				$result = $this->db->where('product_name',$product_id);
				$result = $this->db->update('production_plan',array('status' => 2));
				if($result){return true;}else{return false;}
			}

			public function update_production_line_clerence($id,$p_name)
			{
			
				$result = $this->db->where('so_id',$id);
				$result = $this->db->where('product_name',$p_name);
				$result = $this->db->update('production_plan',array('status' => 4));
				if($result){return true;}else{return false;}
			}

			
			public function update_compound_production($id)
			{
			
				$result = $this->db->where('id',$id);
				$result = $this->db->update('production_plan',array('status' => 3));
				if($result){return true;}else{return false;}
			}



 		public function update_so_po_mould($id)
			{
			
				$result = $this->db->where('so_id',$id);
				$result = $this->db->update('so_po_boms',array('production_plan' => 2));
				if($result){return true;}else{return false;}
			}


			public function complete_inspection_so_po_status($id)
			{
			
				$result = $this->db->where('so_id',$id);
				$result = $this->db->update('so_po_boms',array('production_plan' => 6));
				if($result){return true;}else{return false;}
			}


			public function complete_inspection_production($mold,$so_id,$p_name)
			{
			
				$result = $this->db->where('mold',$mold);
				$result = $this->db->where('so_id',$so_id);
				$result = $this->db->where('product_name',$p_name);
				$result = $this->db->update('production_plan',array('status' => 5));
				if($result){return true;}else{return false;}
			}


			


			public function update_machine_so_po_mould($id)
			{
			
				$result = $this->db->where('so_id',$id);
				$result = $this->db->update('so_po_boms',array('production_plan' => 3));
				if($result){return true;}else{return false;}
			}


			public function update_so_po_finish($id)
			{
			
				$result = $this->db->where('so_id',$id);
				$result = $this->db->update('so_po_boms',array('production_plan' => 8));
				if($result){return true;}else{return false;}
			}


			public function update_so_po_line_clerence($id)
			{
			
				$result = $this->db->where('so_id',$id);
				$result = $this->db->update('so_po_boms',array('production_plan' => 5));
				if($result){return true;}else{return false;}
			}


				public function update_so_po_production_compound($id)
			{
			
				$result = $this->db->where('so_id',$id);
				$result = $this->db->update('so_po_boms',array('production_plan' => 4));
				if($result){return true;}else{return false;}
			}


			public function get_condition_sopo_update($so_id){

					$this->db->select('production_plan.so_id,production_plan.status');
					$this->db->from('production_plan');
					
					$sql = $this->db->where('production_plan.so_id',$so_id);
					//$sql = $this->db->where('production_plan.product_name',$p_name);
					//$sql = $this->db->where('production_plan.complete_status',0);
					$sql = $this->db->get();

					if($sql->num_rows() >0)
					{return $sql->result_array();
					}else
					{return false;}
			    }


    public function get_total_machine_wast($material_id){
		$this->db->select('waste_in_stock.qty as total_qty,waste_in_stock.wast_lot');  
		  
		$this->db->from('waste_in_stock');
		
		$this->db->where('material_id',$material_id);
		//$this->db->where('status',0);
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
		}


		 public function get_material_for_condition($material_id){

    	$this->db->select('fg_stock.material_id,fg_stock.qty,fg_stock.created');  
		  
		$this->db->from('fg_stock');
		
		$this->db->where('material_id',$material_id);
		//$this->db->group_by('product_id');
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }


    

     public function get_production_mold($p_name,$so_id){

    	$this->db->select('production_plan.mold');  
		  
		$this->db->from('production_plan');
		
		$this->db->where('so_id',$so_id);

		$this->db->where('product_name',$p_name);
		//$this->db->group_by('product_id');
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
    }


    public function add_out_stock_production($dataarray) {
          $result = $this->db->insert('production_compund_stock_out',$dataarray);
          if($result){return true;}else{return false;} 
		  
    }


    	public function edit_mould_production($so_id,$p_name,$mould)
			{
			
				$result = $this->db->where('so_id',$so_id);
				$result = $this->db->where('product_name',$p_name);
				
				$result = $this->db->update('production_plan',array('mold' => $mould));
				if($result){return true;}else{return false;}
			}


			 public function edit_machine_production($product_id,$so_id,$machine)
				{

				$result = $this->db->where('product_id',$product_id);
				$result = $this->db->where('so_id',$so_id);
				$result = $this->db->update('production_machine_remarks',array('machine' => $machine));
				if($result){return true;}else{return false;}
				}



			public function get_production_machine($product_id,$so_id){

    			$this->db->select('production_machine_remarks.machine');  
				 
				$this->db->from('production_machine_remarks');

				$this->db->where('product_id',$product_id);
				$this->db->where('so_id',$so_id);
				//$this->db->group_by('product_id');
				$sql = $this->db->get();

				if($sql->num_rows() >0)
				{return $sql->result_array();
				}else
				{return false;}
				    }


				    	
		public function get_details_assembled($id){

    			$this->db->select('assembled_line.id,assembled_line.qty');  
				 
				$this->db->from('assembled_line');

				$this->db->where('id',$id);
				//$this->db->group_by('product_id');
				$sql = $this->db->get();

				if($sql->num_rows() >0)
				{return $sql->result_array();
				}else
				{return false;}
		  }


		  	public function get_details_saealed($id){

    			$this->db->select('sealed_line.id,sealed_line.qty');  
				 
				$this->db->from('sealed_line');

				$this->db->where('id',$id);
				//$this->db->group_by('product_id');
				$sql = $this->db->get();

				if($sql->num_rows() >0)
				{return $sql->result_array();
				}else
				{return false;}
		  }

		  
		  public function get_details_packing($id){

    			$this->db->select('in_stock_log.id,in_stock_log.qty');  
				 
				$this->db->from('in_stock_log');

				$this->db->where('id',$id);
				//$this->db->group_by('product_id');
				$sql = $this->db->get();

				if($sql->num_rows() >0)
				{return $sql->result_array();
				}else
				{return false;}
		  }


		   public function get_details_printing($id){

    			$this->db->select('printed_line.id,printed_line.qty');  
				 
				$this->db->from('printed_line');

				$this->db->where('id',$id);
				//$this->db->group_by('product_id');
				$sql = $this->db->get();

				if($sql->num_rows() >0)
				{return $sql->result_array();
				}else
				{return false;}
		  }



}