<?php
class classStaff
{
	######################## STAFF INFORMATION #####################################
	private $staffID = NULL;
	private $jDate = NULL;
	private $title = NULL;
	private $fname = NULL;
	private $lname = NULL;
	private  $dob = NULL;
	private $gener = NULL;
	private $cnic =  NULL;
	private $address = NULL;
	private $city = NULL;
	private $phone = NULL;
	private $email =NULL;
	private $role = NULL;
	private $otherInfo = NULL;
	
	############################# PROFESSIONAL HISTORY ###############################
	private $qualification = NULL;
	private $specialization = NULL;
	private $degree =NULL;
	private $gradyear = NULL;
	private $licenseNo = NULL;
	
	################### CONTRACT DETAILS #####################
	private $jobTitle = NULL;
	private  $timing = NULL;
	private $fee = NULL;
	private $hospitalShare = NULL;
	private $salary =  NULL;
	private $notes = NULL;
	
	##################################### 	ACCOUNTS INFORMATION ############################################
	
	private $accountID = NULL;
	
	private $locationID = NULL;
	######################################  ALLOWANCES INFORMATION #########################################
	
	private $allowanceID = NULL;
	private $law = NULL;
	private $disability = NULL;
	private $endmonth = NULL;
	private $temporary = NULL;
	private $overTime = NULL;
	private $onCall = NULL;
	private $student =NULL;
	private $accomodation =NULL;
	private $meal = NULL;
	private $loundry = NULL;
	private $milage = NULL;
	private $reimbersing = NULL;
	private $traveling = NULL;
	private $gst = NULL;
		
			
	######################################### SET FUNCTION ##################################################
	
	function setstaffID($staffID)
	{
		if($staffID!="")
		{
			if(classFilter::validateInteger($staffID))
			{
				$this->staffID = classFilter::addMySlashes($staffID);
			}
			else
			{
				throw new MyException(122100);
			}
		}
		else
		{
			throw new MyException(122101);
		}
	}
	
	public function setLocationID($locationID)
		{
			if($locationID!="")
			{
				$this->locationID=$locationID;	
			}
			else
			{
				throw new MyException(122102);
				
			}
		}
	function setJDate($jDate)
	{
		if($jDate!="")
		{
		//	if(classFilter::validateDate($jDate))
			//{
				
				$this->jDate = $jDate;
			//}
			//else
			//{
				//throw new MyException(122110);	
			//}
		}
		else
		{
		//	throw new MyException(122111);
		}
	}
		
	function setTitle($title)
		{
			if ($title!="")
			{
				$this->title = $title;
			}
			else
			{
				throw new MyException(122105);
				}
		}
		
		
	function setFirstName($fname) 
	{
		if($fname!="")
		{
			if(classFilter::validateName($fname))
			{
				$this->fname = classFilter::addMySlashes($fname);
			}
			else
			{
				throw new MyException(122106);
			}
		}
		else
		{
			throw new MyException(122107);
		}
	}
	
	function setLastName($lname) 
	{
		if($lname!="")
		{
			if(classFilter::validateName($lname))
			{
				$this->lname = classFilter::addMySlashes($lname);
			}
			else
			{
				throw new MyException(122108);
			}
		}
		else
		{
			throw new MyException(122109);
		}
	}
		function setDOB($dob)
		{
			if($dob!="")
			{
				/*if(classFilter::validateDate($dob))
				{
					
				
				}
				else
				{
					throw new MyException(122103);	
				}*/
					$this->dob = $dob;
			}
			else
			{
				throw new MyException(122104);
			}
		}
	
		
	function setGender($gender)
	{
		if($gender!="")
		{
			$this->gender = $gender;
		}
	}

	function setCNIC($cnic) 
		{
			if($cnic!="")
			{
				if(classFilter::validateNumber($cnic))
				{
					$this->cnic = classFilter::addMySlashes($cnic);
				}
				else
				{
					throw new MyException(122112);
				}
			}
			else
			{
			
			}
		}
		
		function setAddress($address)
		{
			if($address!="")
			{
				$this->address = $address;
			}
		}
		
		function setCity($userCity) 
		{
			if($userCity!="")
			{
				if(classFilter::validateStringWithoutSpecialCharacters($userCity))
				{
					$this->city = classFilter::addMySlashes($userCity);
				}
				else
				{
				}
			}
		}
		
		function setPhoneNumber($phone) 
		{
			if($phone!="")
			{
				if(classFilter::validateNumber($phone))
				{
					$this->phone = classFilter::addMySlashes($phone);
				}
				else
				{
					throw new MyException(122113);
				}
			}
			else
			{
				throw new MyException(122114);
			}
		}
		
		function setEmail($email) 
		{
			if($email!="")
			{
				if(classFilter::validateEmail($email))
				{
					$this->email = classFilter::addMySlashes($email);
				}
				else
				{
					throw new MyException(122115);
				}
			}
			else
			{
				
			}
		}
		
		function setRole($role)
		{
			if($role!="")
			{
				$this->role = $role;
			}
		}
	
	function setotherInfo($otherInfo)
	{
		if($otherInfo!="")
		{
			$this->otherInfo = $otherInfo;
		}
	}
	
	function setQualification($qualification)
	{
		if($qualification!="")
		{
			$this->qualification = $qualification;
		}
	}
		
	function setSpecialization($specialization)
	{
		if($specialization!="")
		{
			$this->specialization = $specialization;
		}
	}
		
	function setDegree($degree)
	{
		if($degree!="")
		{
			$this->degree = $degree;
		}
	}
	
	function setGradYear($gradyear)
	{
		if($gradyear!="")
		{
			$this->gradYear = $gradyear;
		}
	}
	
	function setLicenseNo($licenseNo)
	{
		if($licenseNo!="")
		{
			$this->licenseNo = $licenseNo;
		}
	}
		
	function setJobTitle($jobtitle)
	{
		if($jobtitle!="")
		{
			$this->jobtitle = $jobtitle;
		}
	}
	
	function setTiming($timing)
	{
		if($timing!="")
		{
			$this->timing = $timing;
		}
	}
	
	function setFee($fee)
	{
		if($fee!="")
		{
			$this->fee = $fee;
		}
	}
	
	function setHospitalShare($hospitalShare)
	{
		if($hospitalShare!="")
		{
			$this->hospitalShare = $hospitalShare;
		}
	}
	
	function setSalary($salary)
	{
		if($salary!="")
		{
			$this->salary = $salary;
		}
	}
	
	function setNotes($notes)
	{
		if($notes!="")
		{
			$this->notes = $notes;
		}
	}
	function setAccountID($accountID)
	{
		if($accountID!="")
		{
			$this->accountID = $accountID;
		}
	}
	
	######################################### ALLOWANCES SET FUNCTIONS ##################################################
	
		function setAllowanceID($allowanceID)
		{
			if($allowanceID!="")
			{
				if(classFilter::validateInteger($allowanceID))
				{
					$this->allowanceID = classFilter::addMySlashes($allowanceID);
				}
				else
				{
					throw new MyException(122116);
				}
			}
			else
			{
				throw new MyException(122117);
			}
		}
		
			function setLaw($law)
		{
			if($law!="")
			{
				$this->law = $law;
			}
		}
		
			function setDisability($disability)
		{
			if($disablity!="")
			{
				$this->disability = $disablity;
			}
		}	
			function setEndMonth($endmonth)
		{
			if($endmonth!="")
			{
				$this->endmonth = $endmonth;
			}
		}
		
		function setTemporary($temporary)
		{
			if($temporary!="")
			{
				$this->temporary = $temporary;
			}
		}
		function setOverTime($overTime)
		{
			if($overTime!="")
			{
				$this->overTime = $overTime;
			}
		}
		function setOnCall($onCall)
		{
			if($onCall!="")
			{
				$this->onCall= $onCall;
			}
		}
		function setStudent($student)
		{
			if($student!="")
			{
				$this->student= $student;
			}
		}
			function setAccomodation($accomodation)
		{
			if($accomodation!="")
			{
				$this->accomodation= $accomodation;
			}
		}
		
		function setMeal($meal)
		{
			if($meal!="")
			{
				$this->meal= $meal;
			}
		}
			function setLoundry($loundry)
		{
			if($loundry!="")
			{
				$this->loundry= $loundry;
			}
		}
			function setMilage($milage)
		{
			if($milage!="")
			{
				$this->milage= $milage;
			}
		}
		function setReimbursing($reimbursing)
		{
			if($reimbursing!="")
			{
				$this->reimbersing= $reimbursing;
			}
		}
		function setTraveling($traveling)
		{
			if($traveling!="")
			{
				$this->traveling= $traveling;
			}
		}
		function setGST($gst)
		{
			if($gst!="")
			{
				$this->gst= $gst;
			}
		}

	######################################### GET FUNCTION ###################################################

	function getStaffID()
	{
		if($this->staffID!="")
		{
			return $this->staffID;
		}
		else
		{
			//throw new MyException(122118);
		}
	}
		
	function getLocationID()
	{
		if($this->locationID!="")
		{
			return $this->locationID;
		}
		else
		{
		//	throw new MyException(122118);
		}
	}
		
	function getJDate()
	{
		if($this->jDate!="")
		{
			return $this->jDate;
		}
		else
		{
			//throw new MyException(122119);
		}
	}
	
	function getTitle()
		{
			if($this->title!="")
			{
				return $this->title;
			}
			else
			{
				throw new MyException(122120);
			}
	}
	
	function getFirstName()
	{
		if($this->fname!="")
		{
			return $this->fname;
		}
		else
		{
			throw new MyException(122121);
		}
	}
	
	function getLastName()
	{
		if($this->lname!="")
		{
			return $this->lname;
		}
		else
		{
			throw new MyException(122122);
		}
	}
	
	function getDOB()
	{
		if($this->dob!="")
		{
			return $this->dob;
		}
		else
		{
			throw new MyException(122123);
		}
	}
	
	function getGender()
	{
		if($this->gender!="")
		{
			return $this->gender;
		}
	}
			
	function getCNIC()
	{
		if($this->cnic!="")
		{
			return $this->cnic;
		}
	}
	
	function getAddress()
	{
		if($this->address!="")
		{
			return $this->address;
		}
	}
	
	function getCity()
	{
		if($this->city!="")
		{
			return $this->city;
		}
	}
	
	function getPhoneNumber() 
	{
		if($this->phone!="")
		{
			return $this->phone;
		}
		else
		{
		
		}
	}
		
	function getEmail() 
	{
		if($this->email!="")
		{
			return $this->email;
		}
		else
		{
			//throw new MyException(106139);
		}
	}
		
	function getRole()
	{
		if($this->role!="")
		{
			return $this->role;
		}
	}
	
	function getotherInfo()
	{
		if($this->otherInfo!="")
		{
			return $this->otherInfo;
		}
	}
			
			############################################## GET PROFESSIONAL HISTORY #############################################
			
		function getQualification()
		{
		if($this->qualification!="")
		{
			return $this->qualification;
		}
		}
		
		function getSpecialization()
		{
		if($this->specialization!="")
		{
			return $this->specialization;
		}
		}
	
		function getDegree()
		{
		if($this->degree!="")
		{
			return $this->degree;
		}
		}
		function getGradYear()
		{
		if($this->gradyear!="")
		{
			return $this->gradyear;
		}
		}
		
		function getLicenseNo()
		{
		if($this->licenseNo!="")
		{
			return $this->licenseNo;
		}
		}
		
			
			##################################### FUNCTIONS GET CONTRACT DETAILS #######################################3
			
		function getJobTitle()
		{
		if($this->jobTitle!="")
		{
			return $this->jobTitle;
		}
		}
		
		function getTiming()
		{
		if($this->timing!="")
		{
			return $this->timing;
		}
		}
		
		function getFee()
		{
		if($this->fee!="")
		{
			return $this->fee;
		}
		}
		
		function getHospitalShare()
		{
		if($this->hospitalShare!="")
		{
			return $this->hospitalShare;
		}
		}
		
		function getSalary()
		{
		if($this->salary!="")
		{
			return $this->salary;
		}
		}
		
			function getNotes()
		{
		if($this->notes!="")
		{
			return $this->notes;
		}
		}
		
		function getaccountID()
		{
		if($this->accountID!="")
		{
			return $this->accountID;
		}
		}
		
		######################################## FUNCTIONS GET ALLOWANCES DETAILS ###########################################
		
		function getAllowancesID()
		{
			if($this->allowanceID!="")
			{
				return $this->allowanceID;
			}
			else
			{
			//	throw new MyException(122124);
			}
		}	
	
		function getLaw()
		{
		if($this->law!="")
		{
			return $this->law;
		}
		}
		
		function getDisablity()
		{
		if($this->disability!="")
		{
			return $this->disability;
		}
		}
		
		function getEndMonth()
		{
		if($this->endMonth!="")
		{
			return $this->endMonth;
		}
		}
		
		function getTemporary()
		{
		if($this->temporary!="")
		{
			return $this->temporary;
		}
		}
		
		function getOverTime()
		{
		if($this->overTime!="")
		{
			return $this->overTime;
		}
		}
		
		function getOnCall()
		{
		if($this->onCall!="")
		{
			return $this->onCall;
		}
		}
		
		function getStudent()
		{
		if($this->student!="")
		{
			return $this->student;
		}
		}
		function getAccomodation()
		{
		if($this->accomodation!="")
		{
			return $this->accomodation;
		}
		}
		
		function getMeal()
		{
		if($this->meal!="")
		{
			return $this->meal;
		}
		}
		
		function getLoundry()
		{
		if($this->loundry!="")
		{
			return $this->loundry;
		}
		}
		
		function getMilage()
		{
		if($this->milage!="")
		{
			return $this->milage;
		}
		}
		
		function getReimbursing()
		{
		if($this->reimbrusing!="")
		{
			return $this->reimbursing;
		}
		}
		
		function getTraveling()
		{
		if($this->traveling!="")
		{
			return $this->traveling;
		}
		}
		
		function getGST()
		{
		if($this->gst!="")
		{
			return $this->gst;
		}
		}
	######################################### RETRIEVE USER FUNCTION ###################################################
	
	function retrieveUserAllDataByUserName($user_name)
	{
		$query="SELECT * FROM users WHERE user_name = '$user_name'";
		$queryOb = new classQueryGlobal;
		$row = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
		if(isset($row[0]))
		{
			$this->userID=$row[0]['user_id'];
			$this->userName=$row[0]['user_name']; 
			$this->password=$row[0]['password'];
			$this->userRoleID=$row[0]['userrole_id'];
			$this->firstName=$row[0]['fname'];
			$this->lastName=$row[0]['lname'];
			$this->email=$row[0]['email'];
			$this->phone=$row[0]['phone'];
			$this->organizationID=$row[0]['org_id'];
			$this->locationID=$row[0]['location_id'];
			
		}
	}
	
	function retrieveUserAllDataByUserID($user_id)
	{
		$query="SELECT * FROM users WHERE user_id = '$user_id'";
		$queryOb = new classQueryGlobal;
		$row = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
		
		if(isset($row[0]))
		{
			$this->userID=$row[0]['user_id'];
			$this->userName=$row[0]['user_name']; 
			$this->password=$row[0]['password'];
			$this->userRoleID=$row[0]['userrole_id'];
			$this->firstName=$row[0]['fname'];
			$this->lastName=$row[0]['lname'];
			$this->email=$row[0]['email'];
			$this->phone=$row[0]['phone'];
			$this->organizationID=$row[0]['org_id'];
			$this->locationID=$row[0]['location_id'];
		}
	}
	
	function searchUser($by_id=NULL,$by_name=NULL,$by_phone=NULL)
	{
		if($by_id!="")
		{
			$query = "SELECT * FROM users WHERE  user_id = '$by_id' order by time_stamp DESC";
		}
		elseif($by_name!="")
		{
			$query = "SELECT * FROM users WHERE (fname LIKE '%".$by_name."%') OR (lname LIKE '%".$by_name."%') order by time_stamp DESC"; 
		}
		elseif($by_phone!="")
		{
			$query = "SELECT * FROM users WHERE  phone LIKE '%".$by_phone."%' order by time_stamp DESC"; 
		}
		
		$queryOb = new classQueryGlobal;
		$user_details = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
		
		if(isset($user_details[0]['user_id'])&&$user_details[0]['user_id']!='')
		{
			return $user_details;
		}
	}
	
	######################################## RETREIVE STAFF FUNCTIONS ###########################################
		
		function retrieveAllStaff()
		{
			$query = "SELECT * FROM staff";
			$queryOb = new classQueryGlobal;
			$staff_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			if(isset($staff_array[0]))
			{
				return $staff_array;
			}
		}
		
		
		function retrieveStaffAllDataByStaffID($staffID)
		{
		$query="SELECT * FROM staff WHERE staff_id = '$staffID'";
		$queryOb = new classQueryGlobal;
		$row = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
		if(isset($row[0]))
		{
			$this->staffID=$row[0]['staff_id'];
			$this->jdate=$row[0]['jdate']; 
			$this->title=$row[0]['title'];
			$this->fname=$row[0]['fname'];
			$this->lname=$row[0]['lname'];
			$this->dob=$row[0]['dob'];
			$this->gender=$row[0]['gender'];
			$this->cnic=$row[0]['cnic'];
			$this->address=$row[0]['address'];
			$this->city=$row[0]['city'];
			$this->phone=$row[0]['phone'];
			$this->email=$row[0]['email'];
			$this->role=$row[0]['role'];
			$this->other_info=$row[0]['other_info'];
			$this->qualification=$row[0]['qualification'];
			$this->specialization=$row[0]['specialization'];
			$this->degree=$row[0]['degree'];
			$this->gradYear=$row[0]['grad_year'];
			$this->licenseNo=$row[0]['license_no'];
			$this->jobTitle=$row[0]['job_title'];
			$this->timing=$row[0]['timing'];
			$this->fee=$row[0]['fee'];
			$this->notes=$row[0]['notes'];
			$this->accountID=$row[0]['account_id'];
			$this->locationID=$row[0]['location_id'];
			$this->salary=$row[0]['salary'];
		}
	}
	
		function retrieveStaffAllDataByStaffFirstName($fname)
		{
		$query="SELECT * FROM staff WHERE fname = '$fname'";
		$queryOb = new classQueryGlobal;
		$row = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
		if(isset($row[0]))
		{
			$this->staffID=$row[0]['staff_id'];
			$this->jdate=$row[0]['jdate']; 
			$this->title=$row[0]['title'];
			$this->fname=$row[0]['fname'];
			$this->lname=$row[0]['lname'];
			$this->dob=$row[0]['dob'];
			$this->gender=$row[0]['gender'];
			$this->cnic=$row[0]['cnic'];
			$this->address=$row[0]['address'];
			$this->city=$row[0]['city'];
			$this->phone=$row[0]['phone'];
			$this->email=$row[0]['email'];
			$this->role=$row[0]['role'];
			$this->other_info=$row[0]['other_info'];
			
			$this->qualification=$row[0]['qualification'];
			$this->specialization=$row[0]['specialization'];
			$this->degree=$row[0]['degree'];
			$this->gradYear=$row[0]['gradyear'];
			$this->licenseNo=$row[0]['license_no'];
			$this->jobTitle=$row[0]['job_title'];
			$this->timing=$row[0]['timing'];
			$this->fee=$row[0]['fee'];
			$this->notes=$row[0]['notes'];
			
			$this->accountID=$row[0]['account_id'];
			$this->locationID=$row[0]['location_id'];
			$this->salary=$row[0]['salary'];
		}
	}
	  
	  	function retrieveStaffAllDataByStaffLastName($lname)
		{
		$query="SELECT * FROM staff WHERE lname = '$lname'";
		$queryOb = new classQueryGlobal;
		$row = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
		if(isset($row[0]))
		{
			$this->staffID=$row[0]['staff_id'];
			$this->jdate=$row[0]['jdate']; 
			$this->title=$row[0]['title'];
			$this->fname=$row[0]['fname'];
			$this->lname=$row[0]['lname'];
			$this->dob=$row[0]['dob'];
			$this->gender=$row[0]['gender'];
			$this->cnic=$row[0]['cnic'];
			$this->address=$row[0]['address'];
			$this->city=$row[0]['city'];
			$this->phone=$row[0]['phone'];
			$this->email=$row[0]['email'];
			$this->role=$row[0]['role'];
			$this->other_info=$row[0]['other_info'];
			
			$this->qualification=$row[0]['qualification'];
			$this->specialization=$row[0]['specialization'];
			$this->degree=$row[0]['degree'];
			$this->gradYear=$row[0]['gradyear'];
			$this->licenseNo=$row[0]['license_no'];
			$this->jobTitle=$row[0]['job_title'];
			$this->timing=$row[0]['timing'];
			$this->fee=$row[0]['fee'];
			$this->notes=$row[0]['notes'];
			
			$this->accountID=$row[0]['account_id'];
			$this->locationID=$row[0]['location_id'];
			$this->salary=$row[0]['salary'];
		}
	}
	
	
		function retrieveStaffByStaffID()
		{
			$staffID = $this->getStaffID();
			
			$query="SELECT * FROM staff WHERE staff_id = '$staffID'";
			$queryOb = new classQueryGlobal;
			$staff_details = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($staff_details[0]['staff_id'])&&$staff_details[0]['staff_id']!='')
			{
				return $staff_details;
			}
			
		}
		
		function retrieveLocationsByLocationID()
		{
			$locationID = $this->getLocationID();
			$query="SELECT * FROM locations WHERE location_id = '$locationID'";
			$queryOb = new classQueryGlobal;
			$location_array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			return $location_array;
		}
	
	######################################### FUNCTION SEARCH STAFF #############################################
	
		function searchStaff($by_id=NULL,$by_name=NULL,$by_phone=NULL)
		{
		if($by_id!="")
		{
			$query = "SELECT * FROM staff WHERE  staff_id = '$by_id' order by jdate DESC";
		}
		elseif($by_name!="")
		{
			$query = "SELECT * FROM staff WHERE (fname LIKE '%".$by_name."%') OR (lname LIKE '%".$by_name."%') order by jdate DESC"; 
		}
		elseif($by_phone!="")
		{
			$query = "SELECT * FROM staff WHERE  phone LIKE '%".$by_phone."%' order by jdate DESC"; 
		}
		
		$queryOb = new classQueryGlobal;
		$staff_details = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
		
		if(isset($staff_details[0]['staff_id'])&&$staff_details[0]['staff_id']!='')
		{
			return $staff_details;
		}
	}
	
	############################################### CHECK FUNCTIONS  ##############################################
	  
		
		function checkStaffPhoneRegistered($phone,$locationID) 
		{
			$query = "SELECT staff_id FROM staff WHERE phone = '$phone' AND location_id = '$locationID'";
			$queryOb = new classQueryGlobal;
			$array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			if(isset($array[0]['staff_id']))
			{
				return 0;
			}
			else
			{
				return 1;
			}
			
		}
		
		function checkStaffCNICRegistered($cnic,$locationID) 
		{
			$query = "SELECT cnic FROM staff WHERE cnic = '$cnic' AND location_id = '$locationID'";
			$queryOb = new classQueryGlobal;
			$array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			if(isset($array[0]['staff_id']))
			{
				return 0;
			}
			else
			{
				return 1;
			}
			
		}
		
		function checkStafemailRegistered($email,$locationID) 
		{
			$query = "SELECT email FROM staff WHERE email = '$email' AND location_id = '$locationID'";
			$queryOb = new classQueryGlobal;
			$array = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			if(isset($array[0]['staff_id']))
			{
				return 0;
			}
			else
			{
				return 1;
			}
			
		}
		
	    function age_from_dob($dob) 
	    {
	
			list($y,$m,$d) = explode('-', $dob);
		   
			if (($m = (date('m') - $m)) < 0) 
			{
				$y++;
			} 
			elseif ($m == 0 && date('d') - $d < 0)
			{
				$y++;
			}
	   
			return date('Y') - $y;
		}
	
	######################################### INSERT FUNCTION ###################################################
	
		function executeHireStaff() 
		{
		
			$locationID = $this->getLocationID();
			$cnic = $this->getCNIC();
			$phone = $this->getPhoneNumber	();
			$email = $this->getEmail();

			if($this->checkStaffCNICRegistered($cnic,$locationID) )
			{
				 if($this->checkStaffPhoneRegistered($phone,$locationID))
				{
					if($this->checkStafemailRegistered($email,$locationID))
					{
							$jDate=$this->getjDate();
							$title=$this->getTitle();
							$fname = $this->getFirstName();
							$lname = $this->getLastName();
							$dob = $this->getDOB();
							$gender = $this->getGender();
							
							$address = $this->getAddress();
							$city = $this->getCity();
							$role = $this->getRole();
							$otheInfo = $this->getotherInfo();
							
							$qualification = $this->getQualification();
							$specialization = $this->getSpecialization();	
							$degree = $this->getDegree();
							$gradYear = $this->getGradYear();	
							$licenseNo = $this->getLicenseNo();		
							
							$jobTitle = $this->getJobTitle();
							$timing = $this->getTiming();
							$fee= $this->getFee();
							$hospitalShare = $this->getHospitalShare();
							$salary = $this->getSalary();
							$notes = $this->getNotes();
							
							$accountID = $this->getAccountID();
							
							
							
							
							$query="INSERT INTO staff 
							(
								jdate,
								title,
								fname,
								lname,
								dob,
								gender,
								cnic,
								address,
								city,
								phone,
								email,
								role,
								other_info,
								qualification,
								specialization,
								degree,
								grad_year,
								license_no,
								job_title,
								timing,
								fee,
								salary,
								notes,
								account_id,
								location_id
							) 
							VALUES
							(
								'$jDate',
								'$title',
								'$fname',
								'$lname',
								'$dob',
								'$gender',
								'$cnic',
								'$address',
								'$city',
								'$phone',
								'$email',
								'$role',
								'$otheInfo',					
								'$qualification',
								'$specialization',
								'$degree',
								'$gradYear',
								'$licenseNo',	
								'$jobTitle',
								'$timing',
								'$fee',
								'$salary',
								'$notes',
								'$accountID',
								'$locationID'
							)";
							$queryOb = new classQueryGlobal;
							$this->staffID = $queryOb->check_fetch_query($query,'insert',$server="",$debug_mode="off");
			}
					
				}
			
			}
			
			else
			{
				throw new MyException(122124);
			}
		}


		
		function executeAllawance() 
		{
			$alllawancID = $this->getAllowanceID();
			$staffID = $this->getStaffID();
			$locationID = $this->getlocationID();
			
			if($this->checkStaffIDRegistered($staffID,$locationID))
			{
				
				
				$law=$this->getLaw();
				$dsiablity=$this->getdisability();
				$endMonth = $this->getEndMonth();
				$temporary = $this->getTemporary();
				$overTime = $this->getOverTime();
				$onCall = $this->getOnCall();
				$student = $this->getStudent();
				$accomodation = $this->getAccomodation();
				$meal = $this->getMeal();
				$loundry = $this->getLoundry	();
				$milage = $this->getMilage();
				$reimbursing = $this->getReimbursing();
				$traveling = $this->getTraveling();
				$gst = $this->getGST();

				$query="INSERT INTO allowances 
				(
					allowance_id,
					staff_id,
					law,
					disablity,
					ene_month,
					temoporary,
					over_time,
					on_call,
					student,
					accomodation,
					meal,
					loundry,
					milage,
					reimbursing,
					traveling,
					gst
				) 
				VALUES
				(
					'$StaffID',
					'$law',
					'$disability',
					'$endMonth',
					'$temporary	',
					'$overTime',
					'$onCall',
					'$student',
					'$accomodation',
					'$meal',
					'$loundry',
					'$milage',
					'$reimbursing',
					'$gst'
				)";
				$queryOb = new classQueryGlobal;
				$this->allwaonceID = $queryOb->check_fetch_query($query,'insert',$server="",$debug_mode="off");
			}
			else
			{
				throw new MyException(122125);
			}
		}
		

	######################################### UPDATE FUNCTION ###################################################
	
	
	function updateStaff() 
		{
				$staffID = $this->getStaffID();
				$title = $this->getTitle();
				$fname = $this->getFirstName();
				$lname = $this->getLastName();
				$dob = $this->getDOB();

				$gender = $this->getGender();
				$cnic = $this->getCNIC();
				$address = $this->getAddress();
				$city = $this->getCity();
				$phone = $this->getPhoneNumber	();
				$email = $this->getEmail();
				$role = $this->getRole();
				$otheInfo = $this->getotherInfo();
				
				$qualification = $this->getQualification();
				$specialization = $this->getSpecialization();	
				$degree = $this->getDegree();
				$gradYear = $this->getGradYear();	
				$licenseNo = $this->getLicenseNo();		
				
				$jobTitle = $this->getJobTitle();
				$timing = $this->getTiming();
				$fee= $this->getFee();
				$hospitalShare = $this->getHospitalShare();
				$salary = $this->getSalary();
				$notes = $this->getNotes();
				$locationID = $this->getLocationID();
				$accountID = $this->getAccountID();
				
				$query="UPDATE staff  SET
					title = '$title',
					fname = '$fname',
					lname = '$lname',
					dob = '$dob',
					gender = '$gender',
					cnic = '$cnic',
					address = '$address',
					city ='$city',
					phone ='$phone',
					email ='$email',
					role = '$role',
					other_info = '$otheInfo',
					qualification = '$qualification',
					specialization ='$specialization',
					degree ='$degree',
					grad_year = '$gradYear',
					license_no ='$licenseNo',
					job_title = '$jobTitle',
					timing ='$timing',
					fee = '$fee',
					salary ='$salary',
					notes ='$notes',
					account_id = '$accountID',
					location_id ='$locationID'
					
					WHERE staff_id = '$staffID'
					";
				$queryOb = new classQueryGlobal;
				$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
		}
		
	function updateAllowances() 
		{
				$alllawancID = $this->getAllowanceID();
				$staffID = $this->getStaffID();
				$law=$this->getLaw();
				$dsiablity=$this->getdisability();
				$endMonth = $this->getEndMonth();
				$temporary = $this->getTemporary();
				$overTime = $this->getOverTime();
				$onCall = $this->getOnCall();
				$student = $this->getStudent();
				$accomodation = $this->getAccomodation();
				$meal = $this->getMeal();
				$loundry = $this->getLoundry	();
				$milage = $this->getMilage();
				$reimbursing = $this->getReimbursing();
				$traveling = $this->getTraveling();
				$gst = $this->getGST();
			
			$query="UPDATE allwoances SET
			
				allowance_id= '$allowanceID',
				staff_id= '$staffID',
				law = '$law',
				disablity= '$disability',
				ene_month= '$endMonth',
				temoporary= '$temporary',
				over_time= '$overTime',
				on_call= '$onCall',
				student= '$student',
				accomodation = '$accomodation',
				meal= '$meal',
				loundry= '$loundry',
				milage= '$milage',
				reimbursing= '$reimbursing',
				traveling= '$traveling',
				gst= '$gst'
				
				WHERE allowance = '$allowanceID' AND staff_id='$staffID'" ;
				$queryOb = new classQueryGlobal;
				$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
		}
	######################################### DELETE FUNCTION ###################################################
		
		function deleteStaff() 
		{
			$staffID = $this->getStaffID();	
			$query="DELETE FROM staff WHERE staff_id = '$staffID'";
			$queryOb = new classQueryGlobal;
			$queryOb->check_fetch_query($query,'delete',$server="",$debug_mode="off");
		}
		
		######################################## COUNT FUCTIONS ##################################################333
			
			
		function retrieveStaffByLocationID($limit=NULL)
		{
			$locationID = $this->getLocationID();
			
			if($limit!='')
			{
				$query="SELECT * FROM staff WHERE location_id = '$locationID' order by staff_id DESC limit $limit";	
			}
			else
			{
				$query="SELECT * FROM staff WHERE location_id = '$staff_id' order by staff_id DESC";
			}
			
			$queryOb = new classQueryGlobal;
			$staff_details = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($staff_details[0]['staff_id'])&&$staff_details[0]['staff_id']!='')
			{
				return $staff_details;
			}
			
		}
		
		
		
		function countStaffByLocationID()
		{
			$locationID = $this->getLocationID();
			
			$query="SELECT count(staff_id) FROM staff WHERE location_id = '$locationID'";
			$queryOb = new classQueryGlobal;
			$staff_details = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($staff_details[0]['count(staff_id)'])&&$staff_details[0]['count(staff_id)']!='')
			{
				return $staff_details[0]['count(staff_id)'];
			}
			
		}
		
			function countsStafftByStaffRole()
		{
			$staffRole = $this->getRole();
			
			$query="SELECT count(staff_id) FROM staff WHERE staff_role = '$staffRole' order by reg_date DESC";
			$queryOb = new classQueryGlobal;
			$staff_details = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
			
			if(isset($staff_details[0]['count(staff_id)'])&&$staff_details[0]['count(staff_id)']!='')
			{
				return $staff_details;
			}
			
		}
}
?>