<?php
require_once (PATH_TABLES . "activity/JobQuotationResourcesTable.php") ;
require_once (PATH_MODELS . "base/MasterBase.php") ;

class JobQuotationResourcesClass extends MasterBase {
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= JobQuotationResourcesTable::C_TABLE ;
		$this->fldid 	= JobQuotationResourcesTable::C_ID ;
	}

	function __destruct() {
	}
	function deleteRecordByQuotationId($id){
        $sql = "delete from " . JobQuotationResourcesTable::C_TABLE 
        . " where " . $this->db->fieldParam(JobQuotationResourcesTable::C_QUOTATION_ID) ;

        $params = array() ;
        $params[] = $this->db->valueParam(JobQuotationResourcesTable::C_QUOTATION_ID,$id) ;
        
        return $this->db->deleteRows($sql,$params) ;
	}

	function getAccManagerList($id){
    	$clsUser       = new UserClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobQuotationResourcesTable::C_TABLE . " WHERE " . JobQuotationResourcesTable::C_QUOTATION_ID . " = " . $id;
        $sql .= " AND " . JobQuotationResourcesTable::C_TYPE . " = " . JobCentreResources::AccountManager;
        $sql .= " ORDER BY " . JobQuotationResourcesTable::C_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        $accManager = "";
        if(!is_null($rows) && count($rows) > 0){
            $idx = 0;
            foreach ($rows as $row) {
            	$idx++;
            	if($idx!=count($rows)) {
            		$accManager .= $clsUser->getRecord($row[JobQuotationResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME] . "<br>";
            	} else {
            		$accManager .= $clsUser->getRecord($row[JobQuotationResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME];
            	}
            }

            $data['accManager'] = $accManager;
            return $data;
        }
        
        return null;
    }

    function getProjManagerList($id){
    	$clsUser       = new UserClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobQuotationResourcesTable::C_TABLE . " WHERE " . JobQuotationResourcesTable::C_QUOTATION_ID . " = " . $id;
        $sql .= " AND " . JobQuotationResourcesTable::C_TYPE . " = " . JobCentreResources::ProjectManager;
        $sql .= " ORDER BY " . JobQuotationResourcesTable::C_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        $ProjManager = "";
        if(!is_null($rows) && count($rows) > 0){
            $idx = 0;
            foreach ($rows as $row) {
            	$idx++;
            	if($idx!=count($rows)) {
            		$ProjManager .= $clsUser->getRecord($row[JobQuotationResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME] . "<br>";
            	} else {
            		$ProjManager .= $clsUser->getRecord($row[JobQuotationResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME];
            	}
            }

            $data['ProjManager'] = $ProjManager;
            return $data;
        }
        
        return null;
    }

    function getTechConsultantList($id){
    	$clsUser       = new UserClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobQuotationResourcesTable::C_TABLE . " WHERE " . JobQuotationResourcesTable::C_QUOTATION_ID . " = " . $id;
        $sql .= " AND " . JobQuotationResourcesTable::C_TYPE . " = " . JobCentreResources::TechnicalConsultant;
        $sql .= " ORDER BY " . JobQuotationResourcesTable::C_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        $TechConsultant = "";
        if(!is_null($rows) && count($rows) > 0){
            $idx = 0;
            foreach ($rows as $row) {
            	$idx++;
            	if($idx!=count($rows)) {
            		$TechConsultant .= $clsUser->getRecord($row[JobQuotationResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME] . "<br>";
            	} else {
            		$TechConsultant .= $clsUser->getRecord($row[JobQuotationResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME];
            	}
            }

            $data['TechConsultant'] = $TechConsultant;
            return $data;
        }

        return null;
    }

    function getAppConsultantList($id){
    	$clsUser       = new UserClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobQuotationResourcesTable::C_TABLE . " WHERE " . JobQuotationResourcesTable::C_QUOTATION_ID . " = " . $id;
        $sql .= " AND " . JobQuotationResourcesTable::C_TYPE . " = " . JobCentreResources::ApplicationConsultant;
        $sql .= " ORDER BY " . JobQuotationResourcesTable::C_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        $AppConsultant = "";
        if(!is_null($rows) && count($rows) > 0){
            $idx = 0;
            foreach ($rows as $row) {
            	$idx++;
            	if($idx!=count($rows)) {
            		$AppConsultant .= $clsUser->getRecord($row[JobQuotationResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME] . "<br>";
            	} else {
            		$AppConsultant .= $clsUser->getRecord($row[JobQuotationResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME];
            	}
            }

            $data['AppConsultant'] = $AppConsultant;
            return $data;
        }
        
        return null;
    }

    function getDeveloperList($id){
    	$clsUser       = new UserClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobQuotationResourcesTable::C_TABLE . " WHERE " . JobQuotationResourcesTable::C_QUOTATION_ID . " = " . $id;
        $sql .= " AND " . JobQuotationResourcesTable::C_TYPE . " = " . JobCentreResources::Developer;
        $sql .= " ORDER BY " . JobQuotationResourcesTable::C_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        $dev = "";
        if(!is_null($rows) && count($rows) > 0){
            $idx = 0;
            foreach ($rows as $row) {
            	$idx++;
            	if($idx!=count($rows)) {
            		$dev .= $clsUser->getRecord($row[JobQuotationResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME] . "<br>";
            	} else {
            		$dev .= $clsUser->getRecord($row[JobQuotationResourcesTable::C_USER_ID])[UserTable::C_FULL_NAME];
            	}
            }

            $data['Developer'] = $dev;
            return $data;
        }
        
        return null;
    }

    function getCustProjSponsorList($id){
    	$cls           = new CustomerContactClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobQuotationResourcesTable::C_TABLE . " WHERE " . JobQuotationResourcesTable::C_QUOTATION_ID . " = " . $id;
        $sql .= " AND " . JobQuotationResourcesTable::C_TYPE . " = " . JobCentreResources::CustProjectSponsor;
        $sql .= " ORDER BY " . JobQuotationResourcesTable::C_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        $CustProjSponsor = "";
        if(!is_null($rows) && count($rows) > 0){
            $idx = 0;
            foreach ($rows as $row) {
            	$idx++;
            	if($idx!=count($rows)) {
            		$CustProjSponsor .= $cls->getRecord($row[JobQuotationResourcesTable::C_USER_ID])[CustomerContactTable::C_NAME] . "<br>";
            	} else {
            		$CustProjSponsor .= $cls->getRecord($row[JobQuotationResourcesTable::C_USER_ID])[CustomerContactTable::C_NAME];
            	}
            }

            $data['CustProjSponsor'] = $CustProjSponsor;
            return $data;
        }
        
        return null;
    }

    function getCustProjAdvisorList($id){
    	$cls           = new CustomerContactClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobQuotationResourcesTable::C_TABLE . " WHERE " . JobQuotationResourcesTable::C_QUOTATION_ID . " = " . $id;
        $sql .= " AND " . JobQuotationResourcesTable::C_TYPE . " = " . JobCentreResources::CustProjectAdvisor;
        $sql .= " ORDER BY " . JobQuotationResourcesTable::C_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        $CustProjAdvisor = "";
        if(!is_null($rows) && count($rows) > 0){
            $idx = 0;
            foreach ($rows as $row) {
            	$idx++;
            	if($idx!=count($rows)) {
            		$CustProjAdvisor .= $cls->getRecord($row[JobQuotationResourcesTable::C_USER_ID])[CustomerContactTable::C_NAME] . "<br>";
            	} else {
            		$CustProjAdvisor .= $cls->getRecord($row[JobQuotationResourcesTable::C_USER_ID])[CustomerContactTable::C_NAME];
            	}
            }

            $data['CustProjAdvisor'] = $CustProjAdvisor;
            return $data;
        }
        
        return null;
    }

    function getCustProjManagerList($id){
    	$cls           = new CustomerContactClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobQuotationResourcesTable::C_TABLE . " WHERE " . JobQuotationResourcesTable::C_QUOTATION_ID . " = " . $id;
        $sql .= " AND " . JobQuotationResourcesTable::C_TYPE . " = " . JobCentreResources::CustProjectManager;
        $sql .= " ORDER BY " . JobQuotationResourcesTable::C_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        $CustProjManager = "";
        if(!is_null($rows) && count($rows) > 0){
            $idx = 0;
            foreach ($rows as $row) {
            	$idx++;
            	if($idx!=count($rows)) {
            		$CustProjManager .= $cls->getRecord($row[JobQuotationResourcesTable::C_USER_ID])[CustomerContactTable::C_NAME] . "<br>";
            	} else {
            		$CustProjManager .= $cls->getRecord($row[JobQuotationResourcesTable::C_USER_ID])[CustomerContactTable::C_NAME];
            	}
            }

            $data['CustProjManager'] = $CustProjManager;
            return $data;
        }
        
        return null;
    }

    function getCustProjMemberList($id){
    	$cls           = new CustomerContactClass($this->db);

        $sql = "SELECT * FROM " ;
        $sql .= JobQuotationResourcesTable::C_TABLE . " WHERE " . JobQuotationResourcesTable::C_QUOTATION_ID . " = " . $id;
        $sql .= " AND " . JobQuotationResourcesTable::C_TYPE . " = " . JobCentreResources::CustProjectMember;
        $sql .= " ORDER BY " . JobQuotationResourcesTable::C_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

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