<?php
class InstallItems{

	private $conn;
	private $table_name = "install_items";

	public $id;	
	public $category;	
	public $brand;	
    public $item_code;	
    public $item_name;	
    public $unit;	
	public $entry_by;	
	public $entry_date_time;	

	public function __construct($db){
		$this->conn = $db;
	}

	function create(){
		$query = "INSERT INTO " . $this->table_name . " SET category=:category, item_code=:item_code, item_name=:item_name, unit=:unit, entry_by=:entry_by, entry_date_time=:entry_date_time";
		$stmt = $this->conn->prepare($query);

		$stmt->bindParam(":category", $this->category);
		$stmt->bindParam(":item_code", $this->item_code);
		$stmt->bindParam(":item_name", $this->item_name);
		$stmt->bindParam(":unit", $this->unit);
		$stmt->bindParam(":entry_by", $this->entry_by);
		$stmt->bindParam(":entry_date_time", $this->entry_date_time);

		if($stmt->execute()){
			return true;
		}	 
		return false;
	}

	function exist(){
		$query = "SELECT id FROM " . $this->table_name . " WHERE item_code = ? LIMIT 0,1";
		$stmt = $this->conn->prepare( $query );	
	 
		$stmt->bindParam(1, $this->item_code);
		
		$stmt->execute();
		if($stmt->rowCount()>0){
			return true;
		}
		return false;
	}

	function getAllRows(){
		$query = "SELECT * FROM " . $this->table_name . " where category=:category ORDER BY item_code ";
		$stmt = $this->conn->prepare($query);
		$stmt->bindParam(":category", $this->category);
		$stmt->execute();
		return $stmt;
	}

    function delete(){
		$query = "DELETE FROM " . $this->table_name . " WHERE id = ?";
		$stmt = $this->conn->prepare($query);
		$stmt->bindParam(1, $this->id);
		if($stmt->execute()){
			return true;
		}
		return false;
    }
    

}
?>
