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

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

	function __destruct() {
	}

	function getJobAssignmentList($jobnumber='',$fromdate='',$todate='',$status){
        $sql = "SELECT H.*,C.* FROM " . JobAssignmentTable::C_TABLE . " H ";
		$sql .= "LEFT JOIN " . JobCentreTable::C_TABLE . " C ON (H." . JobAssignmentTable::C_JOB_CENTRE_ID . " = C." . JobCentreTable::C_ID .")";
		$sql .= "WHERE C." . JobCentreTable::C_STATUS . "= ".$status." ";

		if($jobnumber != ''){
            $sql .= "AND C." . JobCentreTable::C_JOB_NUMBER . " LIKE '%" . $jobnumber . "%' ";
            
        } 
		if($fromdate!='' && $todate!=''){
			$sql .= "AND cast(C." . JobCentreTable::C_JOB_START_DATE . " as date) BETWEEN '" . $fromdate . "' AND '" . $todate . "' ";
		}
		
        $rows = $this->db->getTable($sql);
        
        return $rows;
	}
	
	function getIdFromJobId($job_id){
		$sql = "select ".JobAssignmentTable::C_ID." FROM ".JobAssignmentTable::C_TABLE." where ".JobAssignmentTable::C_JOB_CENTRE_ID." = ".$job_id." ";

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

		if(!is_null($rows) && count($rows)>0){
			$id = $rows[0][JobAssignmentTable::C_ID];
		}else{
			$id = 0 ;
		}
		return $id;
	}

	
}
?>