<?
class gsi
{
	
	static $jobType = array(1=>"Fixed",
							2=>"Consultancy");											
															  
	static function getJobTypeList($listName = "", $id="", $width = "100%",$multiple){
		print utility::createList(self::$jobType,$listName,$id,$width,"Please Select",$multiple,$className="form-control");
  	}
	static function getJobTypeById($id){
		return self::$jobType[$id];
	}
	
	static $KinPhoneType = array(1=>"Radio Work",
							   2=>"Mobile");

	static function getKinPhoneTypeList($listName = "", $id="", $width = "100%",$multiple,$className="form-control",$required=""){
		print utility::createList(self::$KinPhoneType,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
	}
	static function getKinPhoneTypeById($id){
		return self::$KinPhoneType[$id];
	}
	static $getLeaveType = array(1=>"Holiday",
							   2=>"Leave");

	static function getLeaveType($listName = "", $id="", $width = "100%",$multiple,$className="form-control",$required=""){
		print utility::createList(self::$getLeaveType,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
	}
	static function getLeaveById($id){
		return self::$getLeaveType[$id];
	}
	
	static $PensionType = array(1=>"Yes",
							   2=>"No");

	static function getPensionTypeList($listName = "", $id="", $width = "100%",$multiple,$className="form-control",$required=""){
		print utility::createList(self::$PensionType,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
	}
	
	static function getPensionTypeById($id){
		return self::$PensionType[$id];
    }
	static function getJobUserById($job_user_id){
		global $db,$conn;		
		$result = $db->query("SELECT * FROM job WHERE id = $job_user_id");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return stripslashes($row['company_name'])." / ".ucfirst($row['first_name'])." ".ucfirst($row['last_name']);
		}
	}
	static function getEnqQuoteJobList($listName = "", $id="", $width = "100%", $multiple,$className,$required="",$source=""){
  		global $db,$conn;	
		$where_condition = " WHERE 1=1 ";
		if(isset($source) && $source !=""){
			if($source == "e"){
				$where_condition .= " AND is_enquiry = '1' ";
			}else if($source == "c"){
				$where_condition .= " AND is_celebrant = '1' ";
			}else if($source == "f"){
				$where_condition .= " AND is_funeral = '1' ";
			}
		}
		$result = $db->query("SELECT * FROM job $where_condition AND is_archive = '0' ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['company_name'])." / ".ucfirst($row['first_name'])." ".ucfirst($row['last_name']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
	}
	static function getEnqQuoteJobById($job_id){
		global $db,$conn;		
		$result = $db->query("SELECT * FROM job WHERE id = $job_id");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			//return $row['id']." - ".stripslashes($row['company_name'])." / ".ucfirst($row['first_name'])." ".ucfirst($row['last_name']);
			return $row['id']." - ".ucfirst($row['first_name'])." ".ucfirst($row['last_name']);
		}
	}
	static function getEnqQuoteJobStatusById($job_id){
		global $db,$conn;		
		$result = $db->query("SELECT * FROM job WHERE id = $job_id");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			if($row['is_funeral']==1){
				return "j";
			}else if($row['is_celebrant']==1){
				return "q";
			}else{
				return "e";
			}
		}
	}
	static function getTotalActiveAppointmentByConsultantId($consultant_id){
		global $db,$conn;		
		$today_date = date("Y-m-d");
		$result = $db->query("SELECT * FROM appointment WHERE admin_id LIKE '%".$_SESSION['user_id']."%' AND appointment_date >= '$today_date' ");
		return $db->num_rows($result);
	}
	static function getTotalActiveAppointment(){
		global $db,$conn;		
		$today_date = date("Y-m-d");
		$result = $db->query("SELECT * FROM appointment WHERE appointment_date >= '$today_date' ");
		return $db->num_rows($result);
	}
	static function getTotalActiveReminderByConsultantId($consultant_id){
		global $db,$conn;		
		$today_date = date("Y-m-d");
		$result = $db->query("SELECT * FROM notes WHERE admin_id LIKE '%".$_SESSION['user_id']."%' AND note_date >= '$today_date' AND note_type = 1 ");
		return $db->num_rows($result);
	}
	static function getTotalActiveReminder(){
		global $db,$conn;		
		$today_date = date("Y-m-d");
		$result = $db->query("SELECT * FROM notes WHERE note_date >= '$today_date' AND note_type = 1 ");
		return $db->num_rows($result);
	}
	static function getTotalNotesByConsultantId($consultant_id){
		global $db,$conn;	
		$job_ids = "";
		$sql1 = "select job_id FROM job_admin_mapping where admin_id = '".$consultant_id."' ";
		$rs1 =  mysqli_query($conn,$sql1);
		if(mysqli_num_rows($rs1) > 0){
			while($row1 = mysqli_fetch_assoc($rs1)){
				$job_ids .= $row1["job_id"].",";
			}
			$job_ids = substr($job_ids,0,-1);
		}
		if(isset($job_ids) && $job_ids !=""){
			$result = $db->query("SELECT * FROM notes WHERE job_id IN($job_ids) AND note_type = 0 AND job_user_id != 0 ");
		}else{
			$result = "";
		}
		return $db->num_rows($result);
	}
	static function getTotalNotesOfUser(){
		global $db,$conn;	
		$result = $db->query("SELECT * FROM notes WHERE note_type = 0 AND job_user_id != 0 ");
		return $db->num_rows($result);
	}
	
	static function getTotalTimeByJobId($job_id){
		global $db,$conn;
		$result = $db->query("SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(`timesheet_time`))) AS total_time FROM timesheet WHERE job_id = '$job_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			if(isset($row["total_time"]) && $row["total_time"] !=""){
				return $row["total_time"];
			}else{
				return 0;
			}
		}
	}
	
	static function getFirstNameList($listName = "", $id="", $width = "100%", $multiple,$className="form-control"){
  		global $db,$conn;		
		$result = $db->query("SELECT first_name FROM job ORDER BY first_name");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['first_name']] = $row['first_name'];
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className);
	}
	static function getTitleList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required){
  		global $db,$conn;		
		$result = $db->query("SELECT DISTINCT title FROM job WHERE title !='' ORDER BY title");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['title']] = ucfirst($row['title']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"100%",$required);
	}
	static function getCountyList($listName = "", $id="", $width = "100%", $multiple,$className="form-control"){
  		global $db,$conn;		
		$result = $db->query("SELECT id,county FROM county ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['county']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className);
	}
	static function getCountyById($county_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,county FROM county WHERE id = '$county_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return $row['county'];
		}
	}
	static function getPurchaseOrderList($listName = "", $id="", $width = "100%", $multiple,$className="form-control"){
  		global $db,$conn;		
		$result = $db->query("SELECT id,order_ref FROM purchase_order ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['order_ref']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className);
	}
	static function getPurchaseById($county_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,order_ref FROM purchase_order WHERE id = '$county_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return $row['order_ref'];
		}
	}
	static function getCountryList($listName = "", $id="", $width = "100%", $multiple,$className="form-control"){
  		global $db,$conn;		
		$result = $db->query("SELECT id,country FROM country ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['country']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className);
	}
	static function getCountryById($country_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,country FROM country WHERE id = '$country_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return $row['country'];
		}
	}
	
	static function getCategoryList($listName = "", $id="", $width = "100%", $multiple,$className="form-control"){
  		global $db,$conn;		
		$result = $db->query("SELECT id,part_num_category FROM category ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['part_num_category']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className);
	}
	static function getCategoryById($country_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,part_num_category FROM category WHERE id = '$country_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return $row['part_num_category'];
		}
	}
	
	static function getTimerTimeInSecondByJobId($job_id){
		global $db,$conn;
		$result = $db->query("SELECT TIME_TO_SEC(`timer_time`) AS timer_time FROM timer WHERE job_id = '$job_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return $row["timer_time"];
		}
	}
	static function getTotalTimeInDecimal($time){
		$timeArr = explode(':', $time);
		$decTime = ($timeArr[0]*60) + ($timeArr[1]) + ($timeArr[2]/60);
 
		return round(($decTime/60),2);
	}
	static function getEntryForMonthByJobId($job_id){
		global $db,$conn;		
		$result = $db->query("SELECT job_start_date FROM job WHERE id = $job_id");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			$job_start_date = $row['job_start_date'];
			$seconds  = strtotime(date('Y-m-d H:i:s')) - strtotime($job_start_date);
			$months = floor($seconds / (3600*24*30));
			$day = floor($seconds / (3600*24)) - ($months * 30);
			if($months == 0){
				return 1;
			}else if($months > 0){
				return $months + 1;
			}
		}
	}
	
	static function getDurationMonthsList($listName = "", $id="", $width = "100%", $multiple,$className="form-control"){
		global $db,$conn;		
		$result = $db->query("SELECT MAX(duration_month) as duration FROM hourly_packages ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			$dataArray = array();
			if($row["duration"] > 0){
				for($i = 1;$i <= $row["duration"];$i++){
					$dataArray[$i] = $i;
				}
			}
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className);
	}
	
	static function getPercentOfJobByJobId($job_id){
		$no_of_hours_worked = self::getTotalTimeInDecimal(self::getTotalTimeByJobId($job_id));
		$total_hours = utility::getTableFieldById("job","total_hours","id",$job_id);
		$percent = (($no_of_hours_worked / $total_hours) * 100);
		return number_format($percent,2);
	}
	
	static function ifHalfOfHourlyJobTimePassByJobId($job_id){
		$enquiry_type = utility::getTableFieldById("job","enquiry_type","id",$job_id);
		if($enquiry_type == 2){
			$job_start_date = utility::getTableFieldById("job","job_start_date","id",$job_id);
			$job_end_date = utility::getTableFieldById("job","job_end_date","id",$job_id);
			
			if($job_start_date != "0000-00-00 00:00:00" && $job_end_date != "0000-00-00 00:00:00"){
				$job_start_date_time  = strtotime($job_start_date);
				$job_end_date_time = strtotime($job_end_date);
				$mid_time       = ($job_start_date_time + $job_end_date_time) / 2;
				$mid_time       = round($mid_time);
				$now            = date('Y-m-d');
				$curr_date_in_time = strtotime($now);
				if($curr_date_in_time > $mid_time){
					return true;
				}else{
					return false;
				}
			}else{
				return false;
			}
		}else{
			return false;
		}
	}
	
	static function getTotalPaymentAmountByJobId($job_id){
		global $db,$conn;		
		$amount = 0;
		$result = $db->query("SELECT * FROM payment WHERE job_id = $job_id");
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$amount = $amount + $row["amount"];
			}
			return	number_format($amount,2);
		}else{
			return number_format($amount,2);
		}
	}
	// print year list
	static function getYearList($listName = "", $id="",  $width = "100%",$multiple,$className="form-control",$required=""){		
		$selectList ="<select $required class='$className' name='$listName' id='$listName' style='width: $width;'>";
		$options = "<option value=''>Year</option>";				
	    for($i=date('Y')-1; $i<=date('Y')+1; $i++) {
	      $selected = ($id == $i) ? "selected" : "";
	      $options.= "<option value=$i $selected>".$i."</option>";		  
	    }
		$selectList.=$options;
		$selectList.="</select>";
		print $selectList;
  	}
	static $monthArray = array("01"=>"Jan",
							   "02"=>"Feb",
							   "03"=>"Mar",
							   "04"=>"Apr",
							   "05"=>"May",
							   "06"=>"Jun",
							   "07"=>"Jul",
							   "08"=>"Aug",
							   "09"=>"Sep",
							   "10"=>"Oct",
							   "11"=>"Nov",
							   "12"=>"Dec");
							   
	static function getYearMonth($listName = "", $id="", $width = "100%",$multiple,$className="form-control",$required=""){
		print utility::createList(self::$monthArray,$listName,$id,$width,"Select Month",$multiple,$className,100,$required);
	}
	static function getYearMonthById($month_id){
		return self::$monthArray[$month_id];
	}

	static $weekArray = array(0=>"Sunday",
							  1=>"Monday",
							  2=>"Tuesday",
							  3=>"Wednesday",
							  4=>"Thursday",
							  5=>"Friday",
							  6=>"Saturday");
							   
	static function getWeekList($listName = "", $id="", $width = "100%",$multiple,$className="form-control"){
		print utility::createList(self::$weekArray,$listName,$id,$width,"Select",$multiple,$className);
	}
	static function getWeekById($week_id){
		return self::$weekArray[$week_id];
	}
	static function getInitialOfCompanyName($company_name){
		$initial = "";
		$company_array = explode(" ",$company_name);
		foreach($company_array as $c){
			$initial .= ucfirst(substr($c,0,1));
		}
		return $initial;
	}
	static function getInvoiceNumber($job_id){
		global $db,$conn;		
		$result = $db->query("SELECT MAX(id) as invoice_id FROM invoice");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			$new_invoice_id = $row["invoice_id"] + 1;
		}
		$company_name = utility::getTableFieldById('job','company_name','id',$job_id);
		$initial_company_name = self::getInitialOfCompanyName($company_name);
		$invoice_number = $initial_company_name."/".date("m")."/".date("y")."/".$new_invoice_id;
		return $invoice_number;
	}
	static function getInitial8CharOfCompanyName($company_name){
		if(strlen($company_name) > 8){
			$company_name = substr($company_name,0,8);
			return $company_name;
		}else{
			return $company_name;
		}
	}
	static function getLastNotesDateByJobId($job_id){
		global $db,$conn;		
		$result = $db->query("SELECT id, max(note_date) as last_date FROM notes WHERE job_id = '".$job_id."'");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			$last_date = $row["last_date"];
			if($last_date != ""){
				return $last_date;
			}
		}
	}
	static function getJobIdsFrom($from1,$from2,$from3){
		global $db,$conn;	
		if($from1 == "enquiry"){
			$where  = " WHERE (job.is_enquiry = 1 ";
		}else if($from1 == "celebrant"){
			$where  = " WHERE (job.is_celebrant = 1 ";
		}else if($from1 == "funeral"){
			$where  = " WHERE (job.is_funeral = 1 ";
		}
		
		if($from2 == "enquiry"){
			$where .= " OR job.is_enquiry = 1) ";
		}else if($from2 == "celebrant"){
			$where .= " OR job.is_celebrant = 1) ";
		}else if($from2 == "funeral"){
			$where .= " OR job.is_funeral = 1) ";
		}
		
		if($from3 == "enquiry"){
			$where .= " AND job_contract.contract_status = '62' ";
		}else if($from3 == "celebrant"){
			$where .= " AND job_contract.contract_status = '63' ";
		}else if($from3 == "funeral"){
			$where .= " AND job_contract.contract_status = '65' ";
		}
		$result = $db->query("SELECT * FROM job INNER JOIN job_contract ON job.id=job_contract.job_id  $where ");
		if ($db->num_rows($result) > 0){
			$job_ids = "";
			while($row = mysqli_fetch_assoc($result)){
				$job_ids .= $row["job_id"].",";
			}
			$job_ids = substr($job_ids,0,-1);
		}
		return $job_ids;
	}
	static $prospectTrafficLightColorArray = array(51=>"#dff5ff",
													 52=>"#E1F8C4",
													 53=>"#FFF9BB",
													 54=>"#FADADD",
													 55=>"#FFFFFF");
	static $prospectTrafficStatusArray = array(51=>"Unlikely Client",
											   52=>"Likely Client",
											   53=>"Made contact",
											   54=>"Dont contact again",
											   55=>"Done nothing");
	static $formField = array(1=>"Text",
							  2=>"Drop Down",
							  3=>"Multiselect Drop Down",
							  4=>"Radio",
							  5=>"Checkbox",
							  6=>"Textarea",
							  7=>"Date",
							  8=>"Time",
							  9=>"Amount",
							  10=>"File Upload");
							   
	static function getFormFieldList($listName = "", $id="", $width = "100%",$multiple,$className="form-control"){
		print utility::createList(self::$formField,$listName,$id,$width,"Select",$multiple,$className);
	}
	static function getFormFieldById($form_field_id){
		return self::$formField[$form_field_id];
	}
	
	static $paymentStatus = array(1=>"1st Payment",
								  2=>"2nd Payment",
								  3=>"3rd Payment");											
															  
	static function getPaymentStatusList($listName = "", $id="", $width = "100%",$multiple){
		print utility::createList(self::$paymentStatus,$listName,$id,$width,"Please Select",$multiple,$className="form-control");
  	}
	static function getPaymentStatusById($id){
		return self::$paymentStatus[$id];
	}
	
	static $paymentModeColorArray = array(1=>"#FF96E3",
										  2=>"#FFDC89",
										  3=>"#71E096");
										  
	static $invoiceModeColorArray = array(1=>"#f25757",
										  2=>"#AFDCEC",
										  3=>"#FFC0CB",
										  4=>"#DCDCDC");
	
	static $jobStatusColorArray = array('e'=>"#FFC0CB",
										'q'=>"#FFDC89",										
										'j'=>"#71E096");
	
	static $jobCompleteStatusColorArray = array(1=>"#FFC0CB",
												2=>"#FFDC89",										
												3=>"#71E096");
	static $jobCompleteStatusPercentArray = array(1=>"Less than 35%",
												  2=>"More than 35%",										
												  3=>"More than 50%");
												  
												  
	static function getTimesheetTimeInRound($timesheet_time1){
		$timesheet_time_array = explode(":",$timesheet_time1);
		if($timesheet_time_array[0] > 0){
			$hours_in_min = $timesheet_time_array[0]*60;
		}else{
			$hours_in_min = 0;
		}
		$timer_time_in_minute = $hours_in_min + $timesheet_time_array[1];
		if($timer_time_in_minute <= 6){
			$timesheet_time = "00:06:00";
		}else if($timer_time_in_minute > 6 && $timer_time_in_minute <= 12){
			$timesheet_time = "00:12:00";
		}else if($timer_time_in_minute > 12 && $timer_time_in_minute <= 18){
			$timesheet_time = "00:18:00";
		}else if($timer_time_in_minute > 18 && $timer_time_in_minute <= 24){
			$timesheet_time = "00:24:00";
		}else if($timer_time_in_minute > 24 && $timer_time_in_minute <= 30){
			$timesheet_time = "00:30:00";
		}else if($timer_time_in_minute > 30 && $timer_time_in_minute <= 36){
			$timesheet_time = "00:36:00";
		}else if($timer_time_in_minute > 36 && $timer_time_in_minute <= 42){
			$timesheet_time = "00:42:00";
		}else if($timer_time_in_minute > 42 && $timer_time_in_minute <= 48){
			$timesheet_time = "00:48:00";
		}else if($timer_time_in_minute > 48 && $timer_time_in_minute <= 54){
			$timesheet_time = "00:54:00";
		}else if($timer_time_in_minute > 54 && $timer_time_in_minute <= 60){
			$timesheet_time = "01:00:00";
		}else if($timer_time_in_minute > 60 && $timer_time_in_minute <= 66){
			$timesheet_time = "01:06:00";
		}else if($timer_time_in_minute > 66 && $timer_time_in_minute <= 72){
			$timesheet_time = "01:12:00";
		}else if($timer_time_in_minute > 72 && $timer_time_in_minute <= 78){
			$timesheet_time = "01:18:00";
		}else if($timer_time_in_minute > 78 && $timer_time_in_minute <= 84){
			$timesheet_time = "01:24:00";
		}else if($timer_time_in_minute > 84 && $timer_time_in_minute <= 90){
			$timesheet_time = "01:30:00";
		}else if($timer_time_in_minute > 90 && $timer_time_in_minute <= 96){
			$timesheet_time = "01:36:00";
		}else{
			$timesheet_time = $timesheet_time1;
		}
		return $timesheet_time;
	}
	
	static function getTotalTimeByAdminId($admin_id,$lead="",$where_for_admin=''){
		global $db,$conn;
		if($where_for_admin !=""){
			$where_for_admin = " $where_for_admin ";
		}
		if($lead !=""){
			$job_ids_for_lead_consultant = self::getJobIdsForLeadConsultant($admin_id);
			$where = " WHERE job_id IN($job_ids_for_lead_consultant) ";
		}else{
			$where = " WHERE admin_id LIKE '%$admin_id%' ";
		}
		
		$result = $db->query("SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(`timesheet_time`))) AS total_time FROM timesheet $where $where_for_admin ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			if(isset($row["total_time"]) && $row["total_time"] !=""){
				return $row["total_time"];
			}else{
				return 0;
			}
		}
	}
	
	static function getTotalTimeByJobAndProjectId($job_id,$project_id){
		global $db,$conn;
		$result = $db->query("SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(`timesheet_time`))) AS total_time FROM timesheet WHERE job_id = '$job_id' AND project_id = '$project_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			if(isset($row["total_time"]) && $row["total_time"] !=""){
				return $row["total_time"];
			}else{
				return 0;
			}
		}
	}

	static function getUnitByTime($time){
		$timeArr = explode(':', $time);
		$decTime = ($timeArr[0]*60) + ($timeArr[1]) + ($timeArr[2]/60);
 
		return ceil($decTime/6);
	}

	static function getProjectListByJobId($listName = "", $id="", $width = "100%", $multiple,$className,$required="",$job_id="",$return_type="print"){
  		global $db,$conn;		
		$where = " WHERE 1=1 AND is_archive = '0'";
		if($job_id){
			$where .= " AND job_id = '$job_id'";
		}
		
		$sql = "SELECT * FROM job_project_mapping $where AND is_private != '1' ORDER BY project_title ";
		$result = $db->query($sql);
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				if($row['is_private'] == 1){
					if($row['updated_by'] != $_SESSION['admin_user_id']){
						continue;
					}
				}
				$dataArray[$row['id']] = ucfirst($row['project_title']);
			}			
		}
		if($return_type == "print"){
			print utility::createList($dataArray,$listName,$id,$width,"Select Project",$multiple,$className,100,$required);
		}else{
			return utility::createList($dataArray,$listName,$id,$width,"Select Project",$multiple,$className,100,$required);
		}
	}

	static function getProjectList($listName = "", $id="", $width = "100%", $multiple,$className,$required="",$job_id="",$return_type="print"){
  		global $db,$conn;		
		//echo "SELECT * FROM job_project_mapping WHERE is_archive = '0' AND job_id='$job_id'";
		$add_job_id_condition = "";
		if($job_id !=""){
			$add_job_id_condition = " AND job_id='$job_id' "; 
		}
		$result = $db->query("SELECT * FROM job_project_mapping WHERE is_archive = '0' AND is_private != '1' $add_job_id_condition ");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				if($row['is_private'] == 1){
					if($row['updated_by'] != $_SESSION['admin_user_id']){
						continue;
					}
				}
				if($_SESSION['is_consultant']){
					if(!(in_array($_SESSION['admin_user_id'],self::getConsultantByJobId($row['job_id'])))){
						continue;
					}
				}
				$dataArray[$row['id']] = utility::getTableFieldById('job','first_name1','id',$row['job_id'])." - ".ucfirst($row['project_title']);
			}			
		}
		if($return_type == "print"){
			print utility::createList($dataArray,$listName,$id,$width,"Select Project",$multiple,$className,100,$required);
		}else{
			return utility::createList($dataArray,$listName,$id,$width,"Select Project",$multiple,$className,100,$required);
		}
	}

	static $invoiceStatusColorArray = array(1=>"#FADADD",
											2=>"#E1F8C4");
	static $invoiceStatusArray = array(1=>"Not / Partially Paid",
									   2=>"Full Paid");
									   
	static $invoiceStatus = array(1=>"Not Invoiced",
								  2=>"1st Invoiced",
								  3=>"2nd Invoiced",
								  4=>"3rd Invoiced");											
															  
	static function getInvoiceStatusList($listName = "", $id="", $width = "100%",$multiple,$className="form-control"){
		print utility::createList(self::$invoiceStatus,$listName,$id,$width,"Please Select",$multiple,$className);
  	}
	static function getInvoiceStatusById($id){
		return self::$invoiceStatus[$id];
	}								   
												  
	static function getInvoiceList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$job_id){
  		global $db,$conn;		
		if(isset($job_id) && $job_id !=""){
			$result = $db->query("SELECT * FROM invoice WHERE job_id = $job_id ORDER BY invoice_date DESC");
			$dataArray = array();
			if ($db->num_rows($result) > 0){
				while($row = $db->next_record($result)){
					$dataArray[$row['id']] = self::getInvoiceStatusById($row['invoice_status'])." - ".number_format($row['amount'],2);
				}			
			}
			print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className);
		}else{
			print "";
		}
	}
	static function getInvoiceById($invoice_id){
		global $db,$conn;		
		$result = $db->query("SELECT * FROM invoice WHERE id = $invoice_id");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return self::getInvoiceStatusById($row['invoice_status'])." - ".number_format($row['amount'],2);
		}
	}
	
	static $invoicePaymentStatusArray = array(1=>"Not Paid",
											  2=>"Partially Paid",
											  3=>"Fully Paid");
	static function getInvoicePaymentStatusList($listName = "", $id="", $width = "100%",$multiple){
		print utility::createList(self::$invoicePaymentStatusArray,$listName,$id,$width,"Please Select",$multiple,$className="form-control");
  	}

	static function getInvoicePaymentStatusById($invoice_id){
		global $db,$conn;		
		$amount = 0;
		$result = $db->query("SELECT * FROM payment WHERE invoice_id = $invoice_id");
		if ($db->num_rows($result) > 0){
			$invoice_amount = utility::getTableFieldById("invoice","amount","id",$invoice_id);
			while($row = $db->next_record($result)){
				$amount = $amount + $row["amount"];
			}
			if($amount == 0){
				return self::$invoicePaymentStatusArray[1];
			}else if($amount < $invoice_amount){
				return self::$invoicePaymentStatusArray[2];
			}else if($amount == $invoice_amount){
				return self::$invoicePaymentStatusArray[3];
			}
		}else{
			return self::$invoicePaymentStatusArray[1];
		}
	}
	
	static function getInvoicePaymentAmountById($invoice_id){
		global $db,$conn;		
		$amount = 0;
		$result = $db->query("SELECT * FROM payment WHERE invoice_id = $invoice_id");
		if ($db->num_rows($result) > 0){
			$invoice_amount = utility::getTableFieldById("invoice","amount","id",$invoice_id);
			while($row = $db->next_record($result)){
				$amount = $amount + $row["amount"];
			}
			return	number_format($amount,2);
		}else{
			return number_format($amount,2);
		}
	}
	static function getInvoicePaymentAmountWithoutNumberFormatById($invoice_id){
		global $db,$conn;		
		$amount = 0;
		$result = $db->query("SELECT * FROM payment WHERE invoice_id = $invoice_id");
		if ($db->num_rows($result) > 0){
			$invoice_amount = utility::getTableFieldById("invoice","amount","id",$invoice_id);
			while($row = $db->next_record($result)){
				$amount = $amount + $row["amount"];
			}
			return	$amount;
		}else{
			return $amount;
		}
	}
	
	static function getEnqQuoteJobListForInvoice($listName = "", $id="", $width = "100%", $multiple,$className,$required=""){
  		global $db,$config;	
		$archive_status_id = $config->archive_status_id;
		$result = $db->query("SELECT id,company_name FROM job ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['id']." - ".stripslashes($row['company_name']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
	}
	
	static function getMaxInvoiceStatusByJobId($job_id){
		global $db,$conn;		
		$result = $db->query("SELECT MAX(invoice_status) as invoice_status FROM invoice WHERE job_id = $job_id");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return $row["invoice_status"];
		}
	}
	static function getMaxPaymentStatusByJobId($job_id){
		global $db,$conn;		
		$result = $db->query("SELECT MAX(payment_status) as payment_status FROM payment WHERE job_id = $job_id");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return $row["payment_status"];
		}
	}
	
	static function getFixedPackagesById($package_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,package_name FROM fixed_packages WHERE id = $package_id");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return $row['package_name'];
		}
	}
	
	static function getTotalSectionByDocumentTemplateId($document_template_id){
		global $db,$conn;		
		$today_date = date("Y-m-d");
		$result = $db->query("SELECT * FROM document_template_section WHERE document_template_id = '".$document_template_id."' ");
		return $db->num_rows($result);
	}
	
	static function getDocumentTemplateList($listName = "", $id="", $width = "100%", $multiple,$className="form-control"){
  		global $db,$conn;		
		$result = $db->query("SELECT * FROM document_template ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = ucfirst($row['document_template']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className);
	}
	
	static $clientType = array(1=>"Individual - Director",
							   2=>"Individual - Partner",
							   3=>"Individual - Sole Trader",
							   4=>"Individual - Other",
							   5=>"Individual - Repayment Claim",
							   6=>"Limited company - by shares",
							   7=>"Limited company - by guarantee",
							   8=>"Partnership",
							   9=>"LLP",
							   10=>"PLC",
							   11=>"Charity - incorporated",
							   12=>"Charity - unincorporated",
							   13=>"Club or association - incorporated",
							   14=>"Club or association - unincorporated",
							   15=>"Trust");											
															  
	static function getClientTypeList($listName = "", $id="", $width = "100%",$multiple,$className,$required=""){
		print utility::createList(self::$clientType,$listName,$id,$width,"Please Select",$multiple,$className="form-control",100,$required);
  	}
	static function getClientTypeById($id){
		return self::$clientType[$id];
	}
	
	static $clientDetailArray = array(1=>"title",2=>"first_name",3=>"last_name",4=>"date_of_birth",5=>"profession",6=>"phone_no",7=>"landline_phone_no",8=>"email",9=>"contact1name",10=>"contact1position",11=>"contact2name",12=>"contact2position",13=>"address1",14=>"address2",15=>"address3",16=>"city",17=>"county",18=>"postcode",19=>"renewal_dates",20=>"turnover",21=>"number_of_employees",22=>"insurance_type",23=>"business_type",24=>"prospect_traffic_lights",25=>"contact_method");
	
	static function getFieldValueById($field_value,$client_field,$job_id){
  		global $db,$conn;		
		if($client_field == "client_type"){
			$return_value = self::getClientTypeById($field_value);
		}else{
			$return_value = $field_value;
		}
		
		return $return_value;
	}
	
	static $emailTrack = array(575=>"New Lead",
							   555=>"Nurture");											
															  
	static function getEmailTrackList($listName = "", $id="", $width = "100%",$multiple){
		print utility::createList(self::$emailTrack,$listName,$id,$width,"Please Select",$multiple,$className="form-control");
  	}
	static function getEmailTrackById($id){
		return self::$emailTrack[$id];
	}
	
	private static $sendingTriggerArray =array();
	static function setSendingTriggerArray(){
		for($i=0; $i<=14; $i++) {
			if($i == 0){
				self::$sendingTriggerArray[$i] = "Immediate";
			}else{
				self::$sendingTriggerArray[$i] = "$i days";
			}
		}
		for($i=3; $i<=52; $i++) {
			$week = $i*7;
			self::$sendingTriggerArray[$week] = "$i weeks";
		}
		self::$sendingTriggerArray["728"] = "104 weeks";
  	}
	static function getSendingTriggerList($listName = "", $id="",  $width = "100%",$multiple){
		print utility::createList(self::$sendingTriggerArray,$listName,$id,$width,"Please Select",$multiple,$className="form-control");
  	}
	static function getSendingTriggerById($id){
		return self::$sendingTriggerArray[$id];
	}
	
	static $emailStatus = array(1=>"Paused",
						        2=>"Active",
							    3=>"Hide");											
															  
	static function getEmailStatusList($listName = "", $id="", $width = "100%",$multiple){
		print utility::createList(self::$emailStatus,$listName,$id,$width,"Please Select",$multiple,$className="form-control");
  	}
	static function getEmailStatusById($id){
		return self::$emailStatus[$id];
	}
	
	static $smsTrack = array(1=>"Electronic",
						     2=>"Manual Sending");											
															  
	static function getSMSTrackList($listName = "", $id="", $width = "100%",$multiple){
		print utility::createList(self::$smsTrack,$listName,$id,$width,"Please Select",$multiple,$className="form-control");
  	}
	static function getSMSTrackById($id){
		return self::$smsTrack[$id];
	}
	
	public static $salesStepArray = array();
	static function setSalesStepArray(){
		$array_sales_step = keycode::getKeycodeListValue("sales_step", $sales_step, $width = "100%", "Sales Step", "id", "code", "sales_step",1);
		foreach($array_sales_step as $key => $salesStep){
			self::$salesStepArray[$key] = '#' . substr(md5(mt_rand()), 0, 6);
		}
		//print_r($salesStepArray);
	}
	static function getSalesStepArray(){
		return self::$salesStepArray;
	}
	static function geSalesStepById($id){
		return self::$salesStepArray[$id];
	}
	static function getTotalQuotationItemsByJobId($job_id){
		global $db,$conn;
		$result = $db->query("SELECT * FROM quotation_items_mapping WHERE job_id = $job_id");
		return $db->num_rows($result);
	}
	static function getQuotationItemsList($listName = "", $id="", $width = "100%", $multiple,$className="form-control"){
  		global $db,$conn;		
		$result = $db->query("SELECT * FROM quotation_items ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['quotation_items_name']] = stripslashes($row['quotation_items_name']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className);
	}
	static $vatType = array(1=>"0%",
							2=>"5%",
							3=>"20%");											
															  
	static function getvatTypeList($listName = "", $id="", $width = "100%",$multiple){
		print utility::createList(self::$vatType,$listName,$id,$width,"Please Select",$multiple,$className="form-control");
  	}
	static function getvatTypeById($id){
		return self::$vatType[$id];
	}
	static function getMessageTemplateList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;	
		$where = " WHERE 1=1 ";
		$result = $db->query("SELECT id,sms_name FROM sms_schedule $where ORDER BY sms_name ASC");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = ucfirst($row['sms_name']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
	static function getMessageTemplateById($id){
		return utility::getTableFieldById("sms_schedule","sms_name","id",$id);
	}
	
	static function getOrganisationList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;	
		$where = " WHERE 1=1 AND is_organisation = '1' AND is_archive = '0'";
		$result = $db->query("SELECT id,organisation_name FROM organisation_management $where ORDER BY organisation_name ASC");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = ucfirst($row['organisation_name']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
	static function getOrganisationById($id){
		$org_name_array = array();
		$org_ids = explode(",",$id);
		foreach($org_ids as $o_id){
			array_push($org_name_array,utility::getTableFieldById("organisation_management","organisation_name","id",$o_id));
		}
		return implode(",",$org_name_array);
	}
	static function getOrganisationByOrgId($org_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,organisation_name FROM organisation_management WHERE id = $org_id");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['organisation_name']);
		}
	}
	
	static $appointmentType = array(1=>"One Off",
									3=>"Weekly",									
									4=>"Forthnightly",
									2=>"Monthly");											
															  
	static function getTypeOfAppointmentList($listName = "", $id="", $width = "100%",$multiple,$className="form-control"){
		print utility::createList(self::$appointmentType,$listName,$id,$width,"Please Select",$multiple,$className);
  	}
	static function getTypeOfAppointmentById($id){
		return self::$appointmentType[$id];
	}
	static $weekType = array(1=>"First",
							 2=>"Second",									
							 3=>"Third",
							 4=>"Fourth",
							 5=>"Last");											
															  
	static function getWeekListForAppointment($listName = "", $id="", $width = "100%",$multiple,$className="form-control"){
		print utility::createList(self::$weekType,$listName,$id,$width,"Please Select",$multiple,$className);
  	}
	static $daysOfWeek = array(1=>"Mon",
							 2=>"Tue",									
							 3=>"Wed",									
							 4=>"Thu",
							 5=>"Fri",
							 6=>"Sat",
							 7=>"Sun");											
															  
	static function getDayOfWeekList($listName = "", $id="", $width = "100%",$multiple,$className="form-control"){
		print utility::createList(self::$daysOfWeek,$listName,$id,$width,"Please Select",$multiple,$className);
  	}
	static function getDayOfMonthList($listName = "", $id="", $width = "100%", $multiple,$className="form-control"){
		global $db;		
			$dataArray = array();
			$row["duration"] =31;
			if($row["duration"] > 0){
				for($i = 1;$i <= $row["duration"];$i++){
					$dataArray[$i] = $i;
				}
			}
		//}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className);
	}
	
	static function getAddressByJobId($job_id){
		$job_id = $_REQUEST['job_id'];
		$sql_for_addess = "SELECT address1,address2,address3,city,county,postcode FROM job WHERE id = '$job_id' ";
		$rs_for_addess = mysqli_query($conn,$sql_for_addess);
		$row = mysqli_fetch_assoc($rs_for_addess);
		
		$address = "";
		if(isset($row["address1"]) && $row["address1"] !=""){
			$address .= $row["address1"]." ";
		}
		if(isset($row["address2"]) && $row["address2"] !=""){
			$address .= $row["address2"]." ";
		}
		if(isset($row["address3"]) && $row["address3"] !=""){
			$address .= $row["address3"]." ";
		}
		if(isset($row["city"]) && $row["city"] !=""){
			$address .= $row["city"]." ";
		}
		if(isset($row["county"]) && $row["county"] !=""){
			$address .= self::getCountyById($row['county'])." ";
		}
		if(isset($row["postcode"]) && $row["postcode"] !=""){
			$address .= $row['postcode'];
		}
		return $address;
	}
	static function getDescripByJobId($job_id){
		$job_id = $_REQUEST['job_id'];
		$sql_for_addess = "SELECT notes FROM job WHERE id = '$job_id' ";
		$rs_for_addess = mysqli_query($conn,$sql_for_addess);
		$row = mysqli_fetch_assoc($rs_for_addess);
		
		$notes = "";
		if(isset($row["notes"]) && $row["notes"] !=""){
			$notes .= $row["notes"]." ";
		}
		return $notes;
	}
	
	static function getNumberOfMileageByJobId($job_id){
		global $db,$conn;
		$result = $db->query("SELECT count(id) as total_mileage FROM mileage WHERE job_id = '$job_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return $row['total_mileage'];
		}else{
			return 0;
		}
	}
	static function getNumberOfAppointmentByJobId($job_id){
		global $db,$conn;
		$result = $db->query("SELECT count(id) as total_appointment FROM appointment WHERE job_id = '$job_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return $row['total_appointment'];
		}else{
			return 0;
		}
	}
	static function getNumberOfNotesByJobId($job_id){
		global $db,$conn;
		$result = $db->query("SELECT count(id) as total_notes FROM notes WHERE note_type = 0 AND job_id = '$job_id'");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return $row['total_notes'];
		}else{
			return 0;
		}
	}
	static function getNumberOfReminderByJobId($job_id){
		global $db,$conn;
		$result = $db->query("SELECT count(id) as total_reminder FROM notes WHERE note_type = 1 AND job_id = $job_id");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return $row['total_reminder'];
		}else{
			return 0;
		}
	}
	static function getNumberOfDocumentByJobId($job_id){
		global $db,$conn;
		$result = $db->query("SELECT count(id) as total_document FROM documents WHERE job_id = $job_id");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return $row['total_document'];
		}else{
			return 0;
		}
	}
	static function getESSImgTemplateList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required){
  		global $db,$conn;		
		$result = $db->query("SELECT id,title FROM ess_image_template ORDER BY id ASC");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
			$dataArray[$row['id']] = ucfirst($row['title']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,$required);
	}
	static function getESSImgTemplateById($template_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,title FROM ess_image_template WHERE id = '$template_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['title']);
		}
	}
	static function getESSHeading($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required){
  		global $db,$conn;		
		$result = $db->query("SELECT id,heading FROM ess_heading ORDER BY id ASC");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
			$dataArray[$row['id']] = ucfirst($row['heading']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,$required);
	}
	static function getESSHeadingById($heading_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,heading FROM ess_heading WHERE id = '$heading_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['heading']);
		}
	}
	static function getCompanyList($listName = "", $id="", $width = "100%", $multiple,$className="form-control"){
  		global $db,$conn;		
		$result = $db->query("SELECT id, company_name FROM organisation_management ORDER BY company_name");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['company_name'];
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className);
	}
	static function getCompanyListById($com_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,company_name FROM organisation_management WHERE id = '$com_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['company_name']);
		}
	}
	static function getProductList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
		$result = $db->query("SELECT id, product FROM enquiry_product ORDER BY product");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['product'];
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
	static function getProductById($product_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,product FROM enquiry_product WHERE id = '$product_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['product']);
		}
	}
	static $StatusList = array(1=>"SOLD",
							 2=>"ORDERED",									
							 3=>"BOILING",									
							 4=>"HOT",
							 5=>"WARM",
							 6=>"COLD",
							 7=>"LOST",											
							 8=>"DEAD",											
							 9=>"ON GOING");											
															  
	static function getStatusList($listName = "", $id="", $width = "100%",$multiple,$className="form-control"){
		print utility::createList(self::$StatusList,$listName,$id,$width,"Please Select",$multiple,$className);
  	}
	static function getStatusListById($id){
		return self::$StatusList[$id];
	}
	static $TickboxesList = array(1=>"Return customer",
							 2=>"Site vist request",									
							 3=>"Want 2nd Hand",									
							 4=>"Selling used GE",
							 5=>"Development",
							 6=>"Case Study",
							 7=>"Distributor",											
							 8=>"OEM",											
							 9=>"Highlight",											
							 10=>"Hire Enquiry",											
							 11=>"On Hire",											
							 12=>"Hire next Season");											
															  
	static function getTickboxesList($listName = "", $id="", $width = "100%", $multiple , $className="form-control") {
    print utility::createList(self::$TickboxesList, $listName, $id, $width, "Please Select", $multiple, $className);
	}

	static function getTickboxesListById($id) {
		return self::$TickboxesList[$id];
	}
	static function getJobEnquiryList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
		$result = $db->query("SELECT id,company_name FROM job WHERE company_name!=''");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['company_name'];
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
	}
	static function getJobEnquiryById($id){
		global $db,$conn;		
		$result = $db->query("SELECT id,company_name FROM job WHERE id = '$id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['company_name']);
		}
	}
	
	static function getProductItemList($listName = "", $id="", $width = "100%", $multiple,$className="form-control"){
  		global $db,$conn;	
		
		/* if($pro_id){
			$where .= "";
		}else{
			$where .= "parent_id = '0'";
		}
				 */
		$result = $db->query("SELECT id,product FROM product ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['product']] = stripslashes($row['product']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className);
	}
	static function getProductItemById($product_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,product FROM product WHERE id = '$product_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return $row['product'];
		}
	}
	static function getProductCodeList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
		$result = $db->query("SELECT id,product,internal_product FROM product ORDER BY id limit 0,5");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['product'].'  '.$row['internal_product']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
	}
	static function getProductCodeById($product_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,product,description FROM product WHERE id = '$product_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucwords($row['product'].' '.$row['description']);
		}
	}
	
	static function getProductTempateList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
		$result = $db->query("SELECT id,product_template_name FROM product_template ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['product_template_name']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
	}
	static function getProductTempateById($product_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,product_template_name FROM product_template WHERE id = '$product_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucwords($row['product_template_name']);
		}
	}
	static function getCurrencyList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
		$result = $db->query("SELECT id,currency_name FROM currency ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['currency_name']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
	}
	static function getCurrencyById($product_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,currency_name FROM currency WHERE id = '$product_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucwords($row['currency_name']);
		}
	}
	static function getProductGroupList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
		$result = $db->query("SELECT * FROM product_group ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
					
						$dataArray[$row['id']] = ucwords($row['product_group_name']);
					

			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
	}
	static function getProductGroupById($product_id){
		global $db,$conn;		
		$result = $db->query("SELECT * FROM product_group WHERE id = '$product_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucwords($row['product_group_name']);
		}
	}	
	static function getReceipt_LocationList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
		$result = $db->query("SELECT * FROM default_receipt_location ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
					
						$dataArray[$row['id']] = ucwords($row['receipt_location_code']);
					

			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
	}
	static function getReceipt_LocationById($product_id){
		global $db,$conn;		
		$result = $db->query("SELECT * FROM default_receipt_location WHERE id = '$product_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucwords($row['receipt_location_code']);
		}
	}
	
	static $YesNo = array(1=>"Yes",
							2=>"No");											
															  
	static function getYesNo($listName = "", $id="", $width = "100%",$multiple,$className="form-control"){
		print utility::createList(self::$YesNo,$listName,$id,$width,"Please Select",$multiple,$className);
  	}
	static function getYesNoById($id){
		return self::$YesNo[$id];
	}
	static $PartChecked = array(1=>"Part Checked",
							2=>"Part Requires Attention");											
															  
	static function getPartChecked($listName = "", $id="", $width = "100%",$multiple,$className="form-control"){
		print utility::createList(self::$PartChecked,$listName,$id,$width,"Please Select",$multiple,$className);
  	}
	static function getPartCheckedById($id){
		return self::$PartChecked[$id];
	}
	static function getProductMainList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
		$result = $db->query("SELECT id, name FROM product_main ORDER BY name");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['name'];
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
	static function getProductMainById($product_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,name FROM product_main WHERE id = '$product_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['name']);
		}
	}
   static function getLocationList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
		$result = $db->query("SELECT id, location FROM stock_location ORDER BY location");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['location'];
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
	static function getLocationById($location_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,location FROM stock_location WHERE id = '$location_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['location']);
		}
	}
	static function getSuppliersList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
		$result = $db->query("SELECT id, supplier_name FROM supplier_management ORDER BY id");
		$dataArray = array();
		$dataArray[-1] = "Add New"; 
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['supplier_name'];
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
	static function getSuppliersListNew($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
		$result = $db->query("SELECT id, supplier_name FROM supplier_management ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['supplier_name'];
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
	static function getSuppliersById($location_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,supplier_name FROM supplier_management WHERE id = '$location_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['supplier_name']);
		}
	}
	static function getDepartmentList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
		$result = $db->query("SELECT id, department FROM department ORDER BY department");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['department'];
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
	static function getDepartmentById($department_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,department FROM department WHERE id = '$department_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['department']);
		}
	}
	
	static function getCountryCodeList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
	$result = $db->query("SELECT id, country, country_code FROM country ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['country']) . ' - ' . stripslashes($row['country_code']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
    
	static function getCountryCodeById($county_id) {
		global $db, $conn;        
		$result = $db->query("SELECT id, country, country_code FROM country WHERE id = '$county_id'");
    
		if ($db->num_rows($result) > 0) {
			$row = $db->next_record($result);
			return stripslashes($row['country']) . ' - ' . stripslashes($row['country_code']);
		}
    }
	static function getStationList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
	$result = $db->query("SELECT id, resource_code FROM station_detail_table WHERE hide = 0 ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['resource_code']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
	
	static function getStationList_quotation($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
	$result = $db->query("SELECT id, station FROM quotation_machines ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['station']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
	static function getvacStationList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
	$result = $db->query("SELECT id, resource_code FROM station_detail_table WHERE machine_type = 1 AND hide = 0 ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['resource_code']);
			}			
		}
		return utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
	static function getcncStationList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
	$result = $db->query("SELECT id, resource_code FROM station_detail_table WHERE machine_type = 3 AND hide = 0 ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['resource_code']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
	static function getpuStationList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
	$result = $db->query("SELECT id, resource_code FROM station_detail_table WHERE machine_type = 4 AND hide = 0 ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['resource_code']);
			}			
		}
		return utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
	
	static function getASSYPUStationList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
	$result = $db->query("SELECT id, resource_code FROM station_detail_table WHERE machine_type = 5 AND hide = 0 ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['resource_code']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
    
	static function getStationById($station_id) {
		global $db, $conn;        
		$result = $db->query("SELECT id, resource_code FROM station_detail_table WHERE id = '$station_id'");
    
		if ($db->num_rows($result) > 0) {
			$row = $db->next_record($result);
			return stripslashes($row['resource_code']);
		}
    }
	
	static function getCustomerListNew($listName = "", $id = "", $width = "100%", $multiple, $className = "form-control", $required = "") {
		global $db, $conn;
		$result = $db->query("SELECT id, customer_name FROM client_management ORDER BY id");
		$dataArray = array();
		//$dataArray[-1] = "Other"; 

		if ($db->num_rows($result) > 0) {
			while ($row = $db->next_record($result)) {
				$dataArray[$row['id']] = stripslashes($row['customer_name']);
			}
		}

		return utility::createList($dataArray, $listName, $id, $width, "Please Select", $multiple, $className, "", $required);
	}
	
	static function getCustomercodeListNew($listName = "", $id = "", $width = "100%", $multiple, $className = "form-control", $required = "") {
		global $db, $conn;
		$result = $db->query("SELECT id, customer_code FROM client_management ORDER BY id");
		$dataArray = array();
		//$dataArray[-1] = "Other"; 

		if ($db->num_rows($result) > 0) {
			while ($row = $db->next_record($result)) {
				$dataArray[$row['id']] = stripslashes($row['customer_code']);
			}
		}

		return utility::createList($dataArray, $listName, $id, $width, "Please Select", $multiple, $className, "", $required);
	}
     
	 static function getCustomerList($listName = "", $id = "", $width = "100%", $multiple, $className = "form-control", $required = "") {
		global $db, $conn;
		$result = $db->query("SELECT id, customer_name FROM client_management ORDER BY id");
		$dataArray = array();
		$dataArray[-1] = "Other"; 

		if ($db->num_rows($result) > 0) {
			while ($row = $db->next_record($result)) {
				$dataArray[$row['id']] = stripslashes($row['customer_name']);
			}
		}

		print utility::createList($dataArray, $listName, $id, $width, "Please Select", $multiple, $className, "", $required);
	}

  
	static function getCustomerById($client_id) {
		global $db, $conn;
		if ($client_id == '-1') {
			return "Other"; 
		}
		$result = $db->query("SELECT id, customer_name FROM client_management WHERE id = '$client_id'");

		if ($db->num_rows($result) > 0) {
			$row = $db->next_record($result);
			return stripslashes($row['customer_name']);
		}

	}
	static function getCustomercodeById($client_id) {
		global $db, $conn;
		if ($client_id == '-1') {
			return "Other"; 
		}
		$result = $db->query("SELECT id, customer_code FROM client_management WHERE id = '$client_id'");

		if ($db->num_rows($result) > 0) {
			$row = $db->next_record($result);
			return stripslashes($row['customer_code']);
		}

	}
	static function getEnquiryList($listName = "", $id = "", $width = "100%", $multiple, $className = "form-control", $required = "") {
		global $db, $conn;
		$result = $db->query("SELECT id, part_number,enquiry_no FROM enquiry_management ORDER BY id");
		$dataArray = array();

		if ($db->num_rows($result) > 0) {
			while ($row = $db->next_record($result)) {
	           $customer_name = utility::getTableFieldById("client_management","customer_name","id",$row["customer"]);
				$dataArray[$row['id']] = ($row['enquiry_no']) .' - '. $row['part_number'];
			}
		}

		print utility::createList($dataArray, $listName, $id, $width, "Please Select", $multiple, $className, "", $required);
	}
	
	static $EnquiryTypeList = array(1=>"New Parts",
							 2=>"Existing Parts",									
							 3=>"Prototype");											
															  
	static function getEnquiryTypeList($listName = "", $id="", $width = "100%",$multiple,$className="form-control"){
		print utility::createList(self::$EnquiryTypeList,$listName,$id,$width,"Please Select",$multiple,$className);
  	}
	static function getEnquiryTypeListById($id){
		return self::$EnquiryTypeList[$id];
	}	
	
	static $TaxCodeList = array(1=>"0%",									
							 2=>"20%");											
															  
	static function getTaxCodeList($listName = "", $id="", $width = "100%",$multiple,$className="form-control",$required = ""){
		print utility::createList(self::$TaxCodeList,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
  	}
	static function getTaxCodeListById($id){
		return self::$TaxCodeList[$id];
	}
	
	static function getRawMaterialTypeList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
	$result = $db->query("SELECT id, type FROM raw_materials ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['type']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
	
	static function getRawMaterialTypeById($type_id) {
		global $db, $conn;        
		$result = $db->query("SELECT id, type FROM raw_materials WHERE id = '$type_id'");
    
		if ($db->num_rows($result) > 0) {
			$row = $db->next_record($result);
			return stripslashes($row['type']);
		}
    }
	static function getPartNumberListBOM($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required="",$product_id=""){
  		global $db,$conn;	
             if($product_id){
				 $where = "WHERE id != '$product_id'";
			 }else{
				 $where ='';
			 }		
		$result = $db->query("SELECT id, part_number ,product_description FROM item_management $where ORDER BY id");
			$dataArray = array(); 
			if ($db->num_rows($result) > 0){
				while($row = $db->next_record($result)){
					$dataArray[$row['id']] = ucfirst($row['part_number'].' - '.ucfirst($row['product_description']));
				}			
			}
			print utility::createList($dataArray,$listName,$id,$width,"Select Part",$multiple,$className,"",$required);
		}
	static function getPartNumberList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
	$result = $db->query("SELECT id, part_number FROM item_management ORDER BY id");
		$dataArray = array();
		$dataArray[-1] = "Add New"; 
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['part_number']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Select Part",$multiple,$className,"",$required);
	}
	static function getPartNumberListNew($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required="",$po_id=""){
  		global $db,$conn;	

	 if ($po_id) {
        $result = $db->query("SELECT part_number FROM purchase_order_items_mapping WHERE po_id = '$po_id' ORDER BY id");
        if ($db->num_rows($result) > 0) {
            while ($row = $db->next_record($result)) {
                $partNumberId = $row['part_number'];
                $itemCheck = $db->query("SELECT id, part_number FROM item_management WHERE id = '$partNumberId'");
                if ($db->num_rows($itemCheck) > 0) {
                    $itemRow = $db->next_record($itemCheck);
                    $dataArray[$itemRow['id']] = stripslashes($itemRow['part_number']);
                }
            }
        }
		}else{
			  
			$result = $db->query("SELECT id, part_number FROM item_management ORDER BY id");
				$dataArray = array();
				if ($db->num_rows($result) > 0){
					while($row = $db->next_record($result)){
						$dataArray[$row['id']] = stripslashes($row['part_number']);
					}			
				}
				
			}
			if($return_type == "Return"){
					Return utility::createList($dataArray,$listName,$id,$width,"Select Part",$multiple,$className,"",$required);
				}else{
				  print utility::createList($dataArray,$listName,$id,$width,"Select Part",$multiple,$className,"",$required);
			}
}	
	static function getPartNumberById($type_id) {
		global $db, $conn;        
		$result = $db->query("SELECT id, part_number FROM item_management WHERE id = '$type_id'");
    
		if ($db->num_rows($result) > 0) {
			$row = $db->next_record($result);
			return stripslashes($row['part_number']);
		}
    }
	static function getRouteNumberList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
	$result = $db->query("SELECT id, route_no FROM route_details ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['route_no']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Select Route",$multiple,$className,"",$required);
	}
	static function getSetNumberList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
	$result = $db->query("SELECT id, set_number FROM set_mangmnt ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['set_number']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Select Set",$multiple,$className,"",$required);
	}
	
	static function getRouteNumberById($type_id) {
		global $db, $conn;        
		$result = $db->query("SELECT id, route_no FROM route_details WHERE id = '$type_id'");
    
		if ($db->num_rows($result) > 0) {
			$row = $db->next_record($result);
			return stripslashes($row['route_no']);
		}
    }
	static $feasibilityTypeList = array(1=>"Type A: Standard Product",
							 2=>"Type B: Feasibility Review Required",
							 3=>"Type C: Unknown\ Unfamiliar Process",									
							 4=>"Type D: Not Suitable for Thermotec");											
															  
	static function getFeasibilityTypeList($listName = "", $id="", $width = "100%",$multiple,$className="form-control"){
		print utility::createList(self::$feasibilityTypeList,$listName,$id,$width,"Please Select",$multiple,$className);
  	}
	static function getFeasibilityTypeListById($id){
		return self::$feasibilityTypeList[$id];
	}


	static function getEmployeeList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
	$result = $db->query("SELECT id, uname FROM admin ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['uname']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
	
	static function getEmployeeById($employee_id) {
		global $db, $conn;        
		$result = $db->query("SELECT id, uname FROM admin WHERE id = '$employee_id'");
    
		if ($db->num_rows($result) > 0) {
			$row = $db->next_record($result);
			return stripslashes($row['uname']);
		}
    }	
	static function getCustomerImportList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
	$result = $db->query("SELECT id, customer_reff FROM production_planning ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['customer_reff']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}
	static function getEmployeeClockNoList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  	    global $db,$conn;		
	    $result = $db->query("SELECT id, clock_no FROM admin ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['clock_no']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please select",$multiple,$className,"",$required);
	}
	
	static function getEmployeeClockNoById($clock_no_id) {
		global $db, $conn;        
		$result = $db->query("SELECT id, clock_no FROM admin WHERE id = '$clock_no_id'");
    
		if ($db->num_rows($result) > 0) {
			$row = $db->next_record($result);
			return stripslashes($row['clock_no']);
		}
    }	
	static function getTimeList($listName = "", $id="", $width = "100%", $multiple, $className="form-control", $required=""){
		$dataArray = array();
		$i = 0;
		while ($i < 24 * 60) {
			$hour = str_pad(intval($i / 60), 2, '0', STR_PAD_LEFT);
			$minute = str_pad($i % 60, 2, '0', STR_PAD_LEFT);
			$timeKey = "$hour:$minute:00";
			$timeValue = "$hour:$minute";
			$dataArray[$timeKey] = $timeValue;
			$i += 15;
		}
		$dataArray["23:59:00"] = "23:59";
		print utility::createList($dataArray, $listName, $id, $width, "00:00", $multiple, $className, "", $required);
	}
	static function getShiftList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;
		$result = $db->query("SELECT id,shift_name FROM working_hours ORDER BY id ASC");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = ucfirst($row['shift_name']);
			}
		}
		 if (!is_array($id)) {
				$id = array();
			}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
	}
	static function getShiftNameById($shift_id){
		global $db,$conn;
		$result = $db->query("SELECT id,shift_name FROM working_hours WHERE id = '$shift_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['shift_name']);
		}
	}
	static $PurchaseItemStatusArray =array(1=>"Pending",
											2=>"Problem (Broken)",
											3=>"Problem (Lost)",
											4=>"Completed",
											5=>"Invoiced");													  
	
	static function getPurchaseItemStatusList($listName = "", $id="", $width = "100%",$multiple,$className="form-control",$required=""){
		
		print utility::createList(self::$PurchaseItemStatusArray,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
		
  	}
	static function getPurchaseItemStatusById($id){
		return self::$PurchaseItemStatusArray[$id];
	}
	static function getReturnRefMax(){
		global $db,$conn;
		$return_array = array();
		$result = $db->query("SELECT MAX(return_integer_ref) as return_ref FROM returns");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			$new_return_ref = $row["return_ref"] + 1;
			$new_return_int_ref= $new_return_ref;
		}
		$return_array["new_return_ref"] = "".$new_return_ref;
		$return_array["new_return_int_ref"] = $new_return_int_ref;
		return $return_array;
	}static $returnstatus = array(1=>"On Site",
							2=>"Collection Arranged",								  
							3=>"Collection Complete",								  
							4=>"Awaiting Credit",								  
							5=>"Credit Received");
	static function getReturnStatusList($listName = "", $id="", $width = "100%",$multiple,$className="form-control",$required){
		print utility::createList(self::$returnstatus,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
  	}
	static function getReturnStatusById($id){
		return self::$returnstatus[$id];
	}
    static $PurchaseStatusArray =array(1=>"Pending ",
											2=>"Waiting Delivery",
											3=>"Partial Item Recieved",
											4=>"All Item Recieved",
											5=>"Completed");													  
	
	static function getPurchaseStatusList($listName = "", $id="", $width = "100%",$multiple,$className="form-control",$required=""){
		
		print utility::createList(self::$PurchaseStatusArray,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
		
  	}
	static function getPurchaseStatusById($id){
		return self::$PurchaseStatusArray[$id];
	}
	static $ShipStatusArray = array(
				1 => "Standard Shipping",
				2 => "Express Shipping",
				3 => "Overnight Shipping",
				4 => "Two-Day Shipping",
				5 => "Pickup In-Store",
				6 => "Freight Shipping",
				7 => "International Shipping",
				8 => "Done Delivery"
			);
											  
	
	static function getShipStatusList($listName = "", $id="", $width = "100%",$multiple,$className="form-control",$required=""){
		
		print utility::createList(self::$ShipStatusArray,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
		
  	}
	static function getShipStatusById($id){
		return self::$ShipStatusArray[$id];
	}
	
	static function getItemTypeList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required="",$return_type = ""){
  		global $db,$conn;		
		$result = $db->query("SELECT id, stock_category FROM stock_category ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['stock_category'];
			}			
		}
		if($return_type == "Return"){
			Return utility::createList($dataArray,$listName,$id,$width,"Select Type",$multiple,$className,$required);
		}else{
			
		  print utility::createList($dataArray,$listName,$id,$width,"Select Part",$multiple,$className,"",$required);
		}
	}
	static function getItemTypeById($item_type_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,stock_category FROM stock_category WHERE id = '$item_type_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['stock_category']);
		}
	}
	
	static function getworkItemList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;
		$result = $db->query("SELECT DISTINCT bom.main_product_id, item_management.id, item_management.part_number, item_management.product_description FROM bom INNER JOIN item_management ON bom.main_product_id = item_management.id ORDER BY id ASC");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = ucfirst($row['part_number']) . ' ' . ucfirst($row['product_description']);
			}
		}
		
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,100,$required);
	}
	
	static function getworkItemById($work_item_id){
		global $db,$conn;		
		$result = $db->query("SELECT DISTINCT bom.main_product_id, item_management.id, item_management.part_number, item_management.product_description FROM bom INNER JOIN item_management ON bom.main_product_id = item_management.id WHERE item_management.id = '$work_item_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['part_number']) . ' ' . ucfirst($row['product_description']);
		}
	}static function getAddressDropList($listName = "", $id="", $width = "100%", $multiple,$className="form-control"){
  		global $db,$conn;		
		if($id){
		$result = $db->query("SELECT id,delivery_address_1 FROM client_delivery_address_mapping ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['delivery_address_1']);
			}			
		}
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className);
	}
	static function getworkOrderList($listName = "", $id="", $width = "100%", $multiple,$className="form-control"){
  		global $db,$conn;		
		$result = $db->query("SELECT id,product_id FROM work_order ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['product_id']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className);
	}static 
	function getworkOrderListNew($listName = "", $id="", $width = "100%", $multiple,$className="form-control"){
  		global $db,$conn;		
		$result = $db->query("SELECT id,work_order_no FROM work_order ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['work_order_no']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className);
	}
	
	static function getworkOrderById($item_type_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,product_id FROM work_order WHERE id = '$item_type_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['product_id']);
		}
	}
	static function getworkOrderNewById($item_type_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,work_order_no FROM work_order WHERE id = '$item_type_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['work_order_no']);
		}
	}
	function getworkordergroupList($listName = "", $id="", $width = "100%", $multiple,$className="form-control"){
  		global $db,$conn;		
		$result = $db->query("SELECT id,group_number FROM group_mangmnt ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = stripslashes($row['group_number']);
			}			
		}
		print utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className);
	}
	
	static function getworkordergroupById($item_type_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,group_number FROM group_mangmnt WHERE id = '$item_type_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['product_id']);
		}
	}
	
	static $machine_type = array(1=>"VAC",
							 2=>"ASSM",
							 3=>"CNC",
							 4=>"PU",									
							 5=>"ASSYPU");											
															  
	static function getmachineTypeList($listName = "", $id="", $width = "100%",$multiple,$className="form-control"){
		print utility::createList(self::$machine_type,$listName,$id,$width,"Please Select",$multiple,$className);
  	}
	static function getmachineTypeListById($id){
		return self::$machine_type[$id];
	}
	
	static function getPutableList($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required=""){
  		global $db,$conn;		
	$result = $db->query("SELECT no_of_table, virtual_id FROM pu_mapping_tables WHERE machine_id = '$id' ");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['virtual_id']] = stripslashes($row['no_of_table']);
			}			
		}
		return utility::createList($dataArray,$listName,$id,$width,"Please Select",$multiple,$className,"",$required);
	}

	static function getSalesRefCodeListNew($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required="",$return_type = ""){
  		global $db,$conn;		
		$result = $db->query("SELECT id, RefSalesCode FROM production_planning ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['RefSalesCode'];
			}			
		}
		if($return_type == "Return"){
			Return utility::createList($dataArray,$listName,$id,$width,"Select Type",$multiple,$className,$required);
		}else{
			
		  print utility::createList($dataArray,$listName,$id,$width,"Select Part",$multiple,$className,"",$required);
		}
	}
	static function getSalesRefCodeById($id){
		global $db,$conn;		
		$result = $db->query("SELECT id, RefSalesCode FROM production_planning WHERE id = '$id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['RefSalesCode']);
		}
	}
	static function getDeliveryNoteNoListNew($listName = "", $id="", $width = "100%", $multiple,$className="form-control",$required="",$return_type = ""){
  		global $db,$conn;		
		$result = $db->query("SELECT id, note_number FROM delivery_notes ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['note_number'];
			}			
		}
		if($return_type == "Return"){
			Return utility::createList($dataArray,$listName,$id,$width,"Select Type",$multiple,$className,$required);
		}else{
			
		  print utility::createList($dataArray,$listName,$id,$width,"Select Part",$multiple,$className,"",$required);
		}
	}
	static function getDeliveryNoteCodeById($id){
		global $db,$conn;		
		$result = $db->query("SELECT id, note_number FROM delivery_notes WHERE id = '$id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['note_number']);
		}
	}
	
	
	
	static function getNominalCodeList($listName = "", $id="", $width = "100%", $multiple, $className="form-control", $required="", $return_type = ""){
		global $db,$conn;

		$result = $db->query("SELECT id, nominal_code, nominal_code_description FROM nominal_codes ORDER BY id");
		$dataArray = array();

		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['nominal_code'] . ' - ' . $row['nominal_code_description'];
			}
		}

		if($return_type == "Return"){
			return utility::createList($dataArray, $listName, $id, $width, "Select Type", $multiple, $className, $required);
		}else{
			print utility::createList($dataArray, $listName, $id, $width, "Select Part", $multiple, $className, "", $required);
		}
	}
	static function getNominalCodeById($nominal_code_id){
		global $db,$conn;		
		$result = $db->query("SELECT id,nominal_code,nominal_code_description FROM nominal_codes WHERE id = '$nominal_code_id' ");
		if ($db->num_rows($result) > 0){
			$row = $db->next_record($result);
			return ucfirst($row['nominal_code']);
		}
	}	
	
	
} # Class Ends
?>