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

class CompanyProfileClass extends MasterBase {
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= CompanyProfileTable::C_TABLE;
		$this->fldid 	= CompanyProfileTable::C_ID ;
		$this->flddesc 	= CompanyProfileTable::C_NAME ;
		$this->fldcode 	= CompanyProfileTable::C_CODE ;
	}
	function __destruct() {
	}

	public function getExistingRecords($comp_code, $comp_id=0) {
        $sql  = "SELECT * FROM " . $this->tbl .
            " WHERE " . $this->fldcode . " = '" . $comp_code . "' ";

        if($comp_id != 0) {
            $sql  .= " AND " . $this->fldid . " <> " . $comp_id . " ";
        }

        $rows = $this->db->getTable($sql);

        if (is_null($rows) || count($rows) == 0) {
            return null;
        } else {
            return $rows;
        }
    }

	function getCompanyProfileList($orderby = ''){
        $sql = "SELECT * FROM " . $this->tbl . " ";

        if($orderby != "")
            $sql .= " ORDER BY " . $orderby;

        $rows = $this->db->getTable($sql);

        return $rows;
    }

    function getActiveCompanyProfileList($orderby = ''){
        $sql = "SELECT * FROM " . $this->tbl .
               " WHERE " . CompanyProfileTable::C_STATUS . " = 1 ";

        if($orderby != "")
            $sql .= " ORDER BY " . $orderby;

        $rows = $this->db->getTable($sql);

        return $rows;
    }
}
