<?php
class ExpenseReason{

	private $conn;
	private $table_name = "expense_reason";

	public $id;	
	public $expense_reason;	

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

	function create(){
		$query = "INSERT INTO " . $this->table_name . " SET expense_reason=:expense_reason";
		$stmt = $this->conn->prepare($query);

		$stmt->bindParam(":expense_reason", $this->expense_reason);
		
		if($stmt->execute()){
			return true;
		}	 
		return false;
	}

	function getAllRows(){

		$query = "SELECT * FROM " . $this->table_name . " group by expense_reason ORDER BY expense_reason ";
		$stmt = $this->conn->prepare($query);
		$stmt->execute();
		return $stmt;
	}

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

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