<?php 
class Posparts_model extends CI_Model {
	public function _consruct(){
		parent::_construct();
 	}

 	public function getPospartsData($Posparts_id='',$view=''){

 		
 		$sql = "SELECT *
			    FROM pos_parts  
			  
			    WHERE id='$Posparts_id' Order by id DESC";

	    $PospartsData = $this->db->query($sql);

	    
	    if(isset($PospartsData)){

	    	return ($PospartsData->row());
	    }
	    return 0;
 	}

 	public function addPosparts($Posparts_data = array()){

	
		$qry = $this->db->insert('pos_parts',$Posparts_data);

		if ($this->db->trans_status() === TRUE)
		{
			$this->db->trans_commit();
			return TRUE;
		}else
		{
			$this->db->trans_rollback();
			return false;
		}
	}

 public function updatePosparts($id,$pospartData)
	{


		$this->db->where('id',$id);
		$qry = $this->db->update('pos_parts',$pospartData);
		return true;


	}


 	function changeStatus($Posparts_id = '', $status = '0'){

 		if(empty($Posparts_id)){
 			return 0;
 		}

 		$status = $this->db->update('users',array('status'=>$status),array('profile_id'=>$Posparts_id,'user_type'=>'1'));
 		//echo $this->db->last_query();exit;
 		return $status;
 	}



function email_availability_check($email)
    {
if($email!=''){

        $query = "SELECT * FROM pos_parts AS CUST 
 									   INNER JOIN users AS USR ON (USR.user_id=CUST.Posparts_id)
 									   WHERE CUST.id!='".$Posparts_id."' AND 
								   			 USR.username='".$email."'";
        $query=$this->db->query($query,array($email));
        if($query->num_rows()>0)
        {
            return $query->row_array();
        } else
        {
            return false;
        }

        }
    return false;
    }

public function get_all_Posparts($filter=null) {
    	if($filter){
    		$this->db->order_by($filter['order_by'], $filter['order_type']);
    		if(!empty($filter['where'])){
    			$this->db->where($filter['where']);
    		}
    		if($filter['length']!=-1)
    			$this->db->limit($filter['length'],$filter['start']);
    	}
    	
    	$this->db->order_by('pos_parts.id','desc');
    	$this->db->select('pos_parts.*,pos.name as pos_name,parts.part_name');
    	$this->db->from('pos_parts');
    	$this->db->join('pos','pos.pos_id = pos_parts.id');
        $this->db->join('parts', 'parts.id = pos_parts.id');
    	$res = $this->db->get();
    
    	return $res->result();
    }

public function getPosdata(){
 		$sql = "SELECT pos.pos_id,pos.name FROM pos 
                  LEFT JOIN users ON (users.profile_id = pos.pos_id)
			  WHERE users.status!='2' AND users.user_type='3' Group By pos.pos_code Order by pos.pos_id DESC";

	    $PospartsData = $this->db->query($sql);
	 //echo $this->db->last_query();exit;
	    if(isset($PospartsData)){

	    	return ($PospartsData->result());
	    }
	    return 0;
 	}

 	public function getPartdata(){
 		$sql = "SELECT parts.id,parts.part_name FROM parts
			  WHERE parts.status!='2' Order by parts.id DESC";

	    $PospartsData = $this->db->query($sql);
	 //echo $this->db->last_query();exit;
	    if(isset($PospartsData)){

	    	return ($PospartsData->result());
	    }
	    return 0;
 	}
 	public function getAmenities(){

 		

 		$sql = "SELECT *
			    FROM amenities WHERE status!='3' Order by id DESC";

	    $amenitiesData = $this->db->query($sql);
	 
	    if(isset($amenitiesData)){

	    	return ($amenitiesData->result());
	    }
	    return 0;
 	}

}
?>