<?php
require_once (PATH_TABLES . "corporate_gift/CorporateGiftDeliveryTable.php") ;
require_once (PATH_MODELS . "base/MasterBase.php") ;

class CorporateGiftDeliveryClass extends MasterBase {
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= CorporateGiftDeliveryTable::C_TABLE;
		$this->fldid 	= CorporateGiftDeliveryTable::C_DELIVERY_ID;
	}
	function __destruct() {
	}
	
	function getCorporateGiftDeliveryByGiftID($id){
		$sql = "SELECT * FROM " . CorporateGiftDeliveryTable::C_TABLE . " WHERE " . CorporateGiftDeliveryTable::C_ID . " = " . $id;
		$rows = $this->db->getTable($sql);

		if(!is_null($rows) && count($rows) > 0){
			return $rows;
		}else{
			return null;
		}
	}

	function deleteCorporateGiftDeliveryByGiftID($id){
		$sql = "DELETE FROM " . CorporateGiftDeliveryTable::C_TABLE . " WHERE " . CorporateGiftDeliveryTable::C_ID . " = " . $id;

		$this->db->executeSql($sql);
	}

	function getDeliveryTimeByGiftID($id, $date = ""){
		$sql = "SELECT * FROM " . CorporateGiftDeliveryTable::C_TABLE . 
				" WHERE " . CorporateGiftDeliveryTable::C_ID . " = " . $id;
		
		$filter = "";
		if($date != ""){
			$filter .= " AND " . CorporateGiftDeliveryTable::C_DATE . " = '" . $date . "'";
		}

		return $this->db->getTable($sql . $filter);
	}
}
