<?php
session_start();
$where 					= " WHERE 1=1 ";
$next_page_condition 	= "";
$paging ="";
$source = $gsi->getEnqQuoteJobStatusById($_REQUEST['id']);
################################################## SEND INVOICE ######################################################
if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'send_invoice'){
	$id= $_REQUEST['id'];
	$from= $_REQUEST['from'];
	$job_id= $_REQUEST['job_id'];
	$admin_id = utility::getTableFieldById("job_admin_mapping","admin_id","job_id",$job_id);
	$mail_format_subject = utility::getTableFieldById("mail_format","mail_format_subject","mail_format_name","send_invoice");
	$mail_format_body = strip_tags(utility::getTableFieldById("mail_format","mail_format_body","mail_format_name","send_invoice"));
	
	$first_name = utility::getTableFieldById("job","first_name","id",$job_id);
	$last_name = utility::getTableFieldById("job","last_name","id",$job_id);
	//$first_name2 = utility::getTableFieldById("job","first_name2","id",$job_id);
	//$last_name2 = utility::getTableFieldById("job","last_name2","id",$job_id);
	if(isset($first_name) &&  $first_name !=""){
		$name = ucfirst($first_name)." ".ucfirst($last_name);
	}
	/* if(isset($first_name) &&  $first_name !=""){
		$name = ucfirst($first_name)." ".ucfirst($last_name);
	}else{
		$name = ucfirst($first_name2)." ".ucfirst($last_name2);
	} */
	
	$email_id = utility::getTableFieldById("job","invoice_email","id",$job_id);
	$email_id_decript = utility::app_crypt($email_id,'d');
	if(!(isset($email_id_decript) && $email_id_decript !="")){
		$email_id = utility::getTableFieldById("job","email","id",$job_id);
		$email_id_decript = utility::app_crypt($email_id,'d');
	}
	$email_id_test = "shoebahmad999@gmail.com";
	
	//$email_id = utility::getTableFieldById("job","email","id",$job_id);
	//$email_id_test = "shoebahmad999@gmail.com";
	
	$find_array = array("[user_name]");
	$replace_array = array($name);
	$mail_format_body = str_replace($find_array,$replace_array,$mail_format_body);
	$email_date = date("Y-m-d");
	
	$file_path 		= array();
	///////////////////// Curl to genrate invoice ////////////////////////////
	$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$config->frontEndURL."/invoice/invoice.php");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,"signature_block=$signature_block&pdf_genrate=1&id=".base64_encode(base64_encode(base64_encode(base64_encode(base64_encode(base64_encode($id)))))));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 
    $server_output = curl_exec ($ch);
    curl_close ($ch);
	
	$my_path = $_SERVER['DOCUMENT_ROOT']."/beb/payment_invoice/";
	$doc_name = "invoice_".$id.".pdf";
	array_push($file_path,$my_path.$doc_name);
	//print_r($file_path);
	//die;
	////////////////////////////// End Curl to genrate invoice /////////////////////////
	//////////////////////// send mail ////////////////////
	//$file_path 		= array();
	$site_email = $config->siteEmail;
	if(utility::mailSMTP($email_id, $mail_format_subject, $functions->HTMLemailWithoutSignatureBlock($mail_format_body,$admin_id), $file_path,$site_email,$site_email,"","","",$admin_id)){
		utility::mailSMTP($email_id_test, $mail_format_subject, $functions->HTMLemailWithoutSignatureBlock($mail_format_body,$admin_id), $file_path,$site_email,$site_email,"","","",$admin_id);
		$sql = "INSERT INTO email_track(job_id,invoice_id,email_subject,email_body,email_id,email_date) VALUES('$job_id','$id','$mail_format_subject','$mail_format_body','$email_id','$email_date')";
		mysqli_query($conn,$sql);
		mysqli_query($conn,"UPDATE invoice SET is_send = 1 WHERE id = $id");
		$_SESSION['info_message'] = ucfirst("invoice send sucessfully");
	}else{
		$_SESSION['info_message']	= ucfirst("There is some error");
		///////////////// To run on local //////////////////////////////////////
		//$sql = "INSERT INTO email_track(job_id,invoice_id,email_subject,email_body,email_id,email_date) VALUES('$job_id','$id','$mail_format_subject','$mail_format_body','$email_id','$email_date')";
		//mysqli_query($conn,$sql);
		//mysqli_query($conn,"UPDATE invoice SET is_send = 1 WHERE id = $id");
	}
	
	
	$redirect = "index?page=view_enquiry_progress&from=$from&id=$job_id";
	header("Location: $redirect");
	exit();
	///////////////// End send mail  //////////////////////
}
################################################## END SEND INVOICE ##################################################
if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'move_to_quote'){
	$id						= $_REQUEST['id'];
	$is_celebrant			= 1;
	$celebrant_date			= date("Y-m-d");
	$company_name			= utility::getTableFieldById("job","company_name","id",$id);
	//$quotation_no			= $gsi->getInitialOfCompanyName($company_name).date("dmy");
	$celebrant_by			= $_SESSION['user_id'];
	$updated_by				= $_SESSION['user_id'];
	
	$query_string = (isset($_REQUEST['query_string']) && !empty($_REQUEST['query_string'])) ? $_REQUEST['query_string'] : $_SERVER['QUERY_STRING'];
	$query_string = str_ireplace("action=move_to_quote&", "", $query_string);
	
	$is_celebrant_exist = utility::getTableFieldById("job","is_celebrant","id",$id);
	if($is_celebrant_exist == 0){
		$sql = "UPDATE job SET is_celebrant = '$is_celebrant', celebrant_date = '$celebrant_date', celebrant_by = '$celebrant_by', updated_by = '$updated_by' WHERE id = $id";
		mysqli_query($conn,$sql);
		$_SESSION['info_message'] = "Enquiry move to quotation sucessfully.";
	}else{
		$_SESSION['info_message'] = "Enquiry already moved to quotation.";
	}
	
	header("location: index?$query_string");
	exit();
}else if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'move_to_job'){
	$id						= $_REQUEST['id'];
	$is_funeral					= 1;
	$funeral_date				= date("Y-m-d");
	$company_name			= utility::getTableFieldById("job","company_name","id",$id);
	//$job_no					= $gsi->getInitialOfCompanyName($company_name).date("dmy");
	$funeral_by					= $_SESSION['user_id'];
	$updated_by				= $_SESSION['user_id'];
	
	$query_string = (isset($_REQUEST['query_string']) && !empty($_REQUEST['query_string'])) ? $_REQUEST['query_string'] : $_SERVER['QUERY_STRING'];
	$query_string = str_ireplace("action=move_to_job&", "", $query_string);
	
	$is_funeral_exist = utility::getTableFieldById("job","is_funeral","id",$id);
	if($is_funeral_exist == 1){
		$_SESSION['info_message'] = "Quotation already moved to client.";
	}else{
		$sql = "UPDATE job SET is_funeral = '$is_funeral',funeral_date = '$funeral_date', funeral_by = '$funeral_by', updated_by = '$updated_by' WHERE id = $id";
		mysqli_query($conn,$sql);
		$_SESSION['info_message'] = "Quotation move to Job sucessfully.";
	}
	
	header("location: index?$query_string");
	exit();
}
if($_REQUEST['start']){
	$paging .="&start=".$_REQUEST['start'];
}
if(isset($_REQUEST["from"]) && $_REQUEST["from"] !=""){
	$_SESSION["from"] = $_REQUEST["from"];
}
if(isset($_REQUEST['id']) && $_REQUEST['id'] !=""){
	$job_id = $_REQUEST['id'];
	$where .= " AND id = ".$_REQUEST['id']." ";
}

$j_id = utility::app_crypt($_REQUEST['j_id'],'d');
if($_REQUEST['id'] != $j_id){
	die("Invaild URL");
}
###########################################  PAGING WITH PER PAGE  #####################################
$file_name		= "index"; // this is file name which is used during paging  , included at the bottom of the page
$table_name		= "job";
$paging_table_name	= $table_name;
$paging_query		= $where;
$join_query_for_paging = "SELECT * FROM $table_name  $where ";
include("paging/paging_query.inc.php");
############################################ END PAGING WITH PER PAGE  #######################################
$query = "SELECT * FROM $table_name $where ";
$rs = mysqli_query($conn,$query);
?>
<style>
.form-group .control-label{
	padding-top:0px;
}
.content{
	min-height: 0px;
}
.content-header h1{
	float:left;
	padding-bottom: 10px;
}
</style>
<section class="content-header">
  <div class="container-fluid">
  <div class="row">
  <?
		$query_string 	=  (isset($_POST['query_string'])) ? $_POST['query_string'] : $_SERVER['QUERY_STRING'];
		if(isset($_REQUEST["from"]) && $_REQUEST["from"] == "view_enquiry"){ 
			$query_string = str_ireplace("page=view_enquiry_progress", "page=view", $query_string);
			$page_header = "Enquiry Details";
		}else if(isset($_REQUEST["from"]) && $_REQUEST["from"] == "view_celebrant"){ 
			$query_string = str_ireplace("page=view_enquiry_progress", "page=view_celebrant", $query_string);
			$page_header = "Quotation Details";
		}else if(isset($_REQUEST["from"]) && $_REQUEST["from"] == "view_funeral"){ 
			$query_string = str_ireplace("page=view_enquiry_progress", "page=view_funeral", $query_string);
			$page_header = "Client Details";
		}else if(isset($_REQUEST["from"]) && $_REQUEST["from"] == "view_jobs_by_search"){ 
			$query_string = str_ireplace("page=view_enquiry_progress", "page=view_jobs_by_search", $query_string);
			$page_header = "Enquiry / Quotation / Client Details";
		}
  ?>
	<div class="col-sm-4">
	  <h1 style="float:left;clear:right;margin-top:0px;padding-bottom: 0;">
		<?=$page_header;?>
	  </h1>
	</div>
  <div class="col-sm-4">
	<center><? //include("timer.inc.php"); ?></center>
  </div>
  <div class="col-sm-4">
  <? if(isset($_REQUEST["from"]) && $_REQUEST["from"] == "payment"){  ?>
	<button type="button" id="back" name="back" value="back"  style="float:right;" class="btn btn-primary" onclick="window.location.href = '<?=$config->siteURL;?>/payment_management/index?<?=$query_string;?>'">Back</button>
  <? }else{ ?>
	<button type="button" id="back" name="back" value="back"  style="float:right;" class="btn btn-primary" onclick="window.location.href = 'index?<?=$query_string;?>'">Back</button>
  <? } ?>
  
  
  <? if(isset($_REQUEST["from"]) && $_REQUEST["from"] == "view_funeral"){ ?>
  <a href="index?page=add_funeral&from=view_enquiry_progress&action=edit&j_id=<?=urlencode(utility::app_crypt($_REQUEST['id'],'e'));?>&id=<?=$_REQUEST['id'];?>" style="float:right;margin-right:5px;" class="btn btn-danger">Edit</a>
  <? }else if(isset($_REQUEST["from"]) && $_REQUEST["from"] == "view_celebrant"){ ?>
  <a href="index?page=add_celebrant&from=view_enquiry_progress&action=edit&j_id=<?=urlencode(utility::app_crypt($_REQUEST['id'],'e'));?>&id=<?=$_REQUEST['id'];?>" style="float:right;margin-right:5px;" class="btn btn-danger">Edit</a>
  <? }else if(isset($_REQUEST["from"]) && $_REQUEST["from"] == "view_enquiry"){ ?>
   <a href="index?page=add&from=view_enquiry_progress&action=edit&j_id=<?=urlencode(utility::app_crypt($_REQUEST['id'],'e'));?>&id=<?=$_REQUEST['id'];?>" style="float:right;margin-right:5px;" class="btn btn-danger">Edit</a>
  <? 
	}else if(isset($_REQUEST["from"]) && $_REQUEST["from"] == "view_jobs_by_search"){ 
		$is_enquiry = utility::getTableFieldById("job","is_enquiry","id",$_REQUEST['id']);
		$is_celebrant = utility::getTableFieldById("job","is_celebrant","id",$_REQUEST['id']);
		$is_funeral = utility::getTableFieldById("job","is_funeral","id",$_REQUEST['id']);
		if($is_funeral == 1){
  ?>
	<a href="index?page=add_funeral&action=edit&id=<?=$_REQUEST['id'];?>" style="float:right;margin-right:5px;" class="btn btn-danger">Edit</a>
  <? }else if($is_celebrant == 1 && $is_funeral == 0){  ?>
	<a href="index?page=add_celebrant&action=edit&id=<?=$_REQUEST['id'];?>" style="float:right;margin-right:5px;" class="btn btn-danger">Edit</a>
  <? }else if($is_enquiry == 1 && $is_celebrant == 0 && $is_funeral == 0){ ?>
	<a href="index?page=add&action=edit&id=<?=$_REQUEST['id'];?>" style="float:right;margin-right:5px;" class="btn btn-danger">Edit</a>
  <? } ?>
  <? } ?>
  
  <?
	if(isset($_REQUEST["from"]) && $_REQUEST["from"] == "view_enquiry"){ 
		$query_string = str_ireplace("page=view", "page=view_enquiry_progress", $query_string);
		$is_celebrant_exist = utility::getTableFieldById("job","is_celebrant","id",$_REQUEST['id']);
		if($is_celebrant_exist == 0){
  ?>
	<button type="button" id="add_placement" name="add_placement" style="float:right;margin-right:5px;margin-bottom:5px;" class="btn btn-warning" onclick="window.location.href = 'index?action=move_to_quote&<?=$query_string;?>'">Move to Quote</button>
  <? 
	}
	}else if(isset($_REQUEST["from"]) && $_REQUEST["from"] == "view_celebrant"){ 
		$query_string = str_ireplace("page=view_celebrant", "page=view_enquiry_progress", $query_string);
  ?>
	<button type="button" id="add_placement" name="add_placement" style="float:right;margin-right:5px;margin-bottom:5px;" class="btn btn-warning" onclick="window.location.href = 'index?action=move_to_job&<?=$query_string;?>'">Move to Client</button>
  <? 
	}else if(isset($_REQUEST["from"]) && $_REQUEST["from"] == "view_jobs_by_search"){ 
		$query_string = str_ireplace("page=view_jobs_by_search", "page=view_enquiry_progress", $query_string);
		$is_celebrant_exist = utility::getTableFieldById("job","is_celebrant","id",$_REQUEST['id']);
		$is_funeral_exist = utility::getTableFieldById("job","is_funeral","id",$_REQUEST['id']);
		if($is_celebrant_exist == 0){
  ?>
		<button type="button" id="add_placement" name="add_placement" style="float:right;margin-right:5px;margin-bottom:5px;" class="btn btn-warning" onclick="window.location.href = 'index?action=move_to_quote&<?=$query_string;?>'">Move to Quote</button>
  <? 
		}else if($is_funeral_exist == 0){
  ?>
		<button type="button" id="add_placement" name="add_placement" style="float:right;margin-right:5px;margin-bottom:5px;" class="btn btn-warning" onclick="window.location.href = 'index?action=move_to_job&<?=$query_string;?>'">Move to Client</button>
  <? } } ?>
  </div>
  </div>
  </div>
</section>
<?
	$enq_row = mysqli_fetch_assoc($rs);
	$enq_row = utility::validate_crypt_data($enq_row);
?>
<section class="content">
	<div class="container-fluid">
	<div class="row">
		<div class="col-lg-12 no-padding">
		<div class="row">
			<!----------------------- Message ------------------------------->
			<? if(isset($_SESSION['info_message'])){ ?>
			  <div class="col-sm-12 alert alert-info alert-dismissable">
				<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
				<? echo $_SESSION['info_message']; unset($_SESSION['info_message']);?>
			  </div>
			  <? } ?>
			<!----------------------- End Message ------------------------------->
			<!-- general form elements -->
			<? 
				$col_width = 12;
			?>
			<div class="col-lg-6 col-md-6 col-sm-12" style="/* min-height:700px; */">
              <div class="scrollbar scrollbar-default box box-warning card" style="height: 350px;overflow: hidden;overflow-y: scroll;">
                <form class="form-horizontal" method="post" name="form1" id="form1" action="index?page=add_placement&action=<? echo $form_action; ?>" onsubmit="return validateForm(this)" enctype="multipart/form-data">
                  <div class="box-body">
					<? if($enq_row["is_funeral"] != 1){ ?>
					<div class="form-group">
                      <label for="Company Name" class="col-sm-4 control-label">Company Name</label>
                      <div class="col-sm-8">
						<? echo $enq_row["company_name"]; ?>
                      </div>
                    </div>
					<div class="form-group">
                      <label for="Sector" class="col-sm-4 control-label">Sector</label>
                      <div class="col-sm-8">
						<?php echo ucfirst(Keycode::getkeycodeById($enq_row["sector"]));?>
                      </div>
                    </div>
					<? } ?>
					<div class="form-group">
					  <label for="Name" class="col-sm-4 control-label">
						<? echo ($enq_row["is_funeral"] == 1) ? "" : ""; ?> Name
					  </label>
					  <div class="col-sm-8">
						<?php echo ucfirst(Keycode::getkeycodeById($enq_row["title"]))." ".ucfirst($enq_row["first_name"])." ".ucfirst($enq_row["last_name"]); ?>
					  </div>
					</div>
					<div class="form-group">
                      <label for="Profession" class="col-sm-4 control-label">Profession</label>
                      <div class="col-sm-8">
						<? echo $enq_row["profession"]; ?>
                      </div>
                    </div>
					<div class="form-group">
					  <label for="Phone No.1" class="col-sm-4 control-label">Phone No.1</label>
					  <div class="col-sm-8">
						<?php 
							if(isset($enq_row["phone_no"]) && $enq_row["phone_no"] !=""){
								echo $enq_row["phone_no"]; 
							}
						?>
					  </div>
					</div>
					<div class="form-group">
					  <label for="Phone No.2" class="col-sm-4 control-label">Phone No.2</label>
					  <div class="col-sm-8">
						<?php 
							if(isset($enq_row["landline_phone_no"]) && $enq_row["landline_phone_no"] !=""){
								echo $enq_row["landline_phone_no"]; 
							}
						?>
					  </div>
					</div>
					<div class="form-group">
					  <label for="Email" class="col-sm-4 control-label">Email / Username</label>
					  <div class="col-sm-8">
						<?php echo $enq_row["email"]; ?>
					  </div>
					</div>
					<div class="form-group">
					  <label for="Address" class="col-sm-4 control-label">Address</label>
					  <div class="col-sm-8">
						<?php 
							if(isset($enq_row["address1"]) && $enq_row["address1"] !=""){
								echo $enq_row["address1"]; 
							}
							if(isset($enq_row["address2"]) && $enq_row["address2"] !=""){
								echo " ".$enq_row["address2"]; 
							}
							if(isset($enq_row["address3"]) && $enq_row["address3"] !=""){
								echo " ".$enq_row["address3"]; 
							}
							if(isset($enq_row["city"]) && $enq_row["city"] !=""){
								echo " ".$enq_row["city"]; 
							}
							if(isset($enq_row["county"]) && $enq_row["county"] !=""){
								echo " ".$gsi->getCountyById($enq_row['county']);  
							}
							if(isset($enq_row["postcode"]) && $enq_row["postcode"] !=""){
								echo " ".$enq_row["postcode"]; 
							}
						?>
					  </div>
					</div>
					
					<div class="form-group">
					  <label for="Contact1" class="col-sm-4 control-label">Contact 1</label>
					  <div class="col-sm-8">
						<?php 
							if(isset($enq_row["contact1name"]) && $enq_row["contact1name"] !=""){
								echo '<b>Name:</b>&nbsp;&nbsp;'.$enq_row["contact1name"].',&nbsp;&nbsp;'; 
							}
							if(isset($enq_row["contact1position"]) && $enq_row["contact1position"] !=""){
								echo '<b>Position:</b>&nbsp;&nbsp;'.$enq_row["contact1position"]; 
							}							
						?>
					  </div>
					</div>
					
					<div class="form-group">
					  <label for="Contact2" class="col-sm-4 control-label">Contact 2</label>
					  <div class="col-sm-8">
						<?php 
							if(isset($enq_row["contact2name"]) && $enq_row["contact2name"] !=""){
								echo '<b>Name:</b>&nbsp;&nbsp;'.$enq_row["contact2name"].',&nbsp;&nbsp;'; 
							}
							if(isset($enq_row["contact2position"]) && $enq_row["contact2position"] !=""){
								echo '<b>Position:</b>&nbsp;&nbsp;'.$enq_row["contact2position"]; 
							}							
						?>
					  </div>
					</div>
					
					<div class="form-group">
                      <label for="Enquiry Date" class="col-sm-4 control-label">Enquiry Date</label>
                      <div class="col-sm-8">
						<? echo utility::getFormatedDateReturn($enq_row["enquiry_date"]); ?>
                      </div>
                    </div>
					
                  </div><!-- /.box-body -->
                </form>
              </div><!-- /.box -->
            </div><!-- /.box -->
			
			<div class="col-lg-6 col-md-6 col-sm-12" style="/* min-height:700px; */">
              <div class="scrollbar scrollbar-default box box-success card" style="height: 350px;overflow: hidden;overflow-y: scroll;">
                <form class="form-horizontal" method="post" name="form1" id="form1" action="index?page=add_placement&action=<? echo $form_action; ?>" onsubmit="return validateForm(this)" enctype="multipart/form-data">
                  <div class="box-body">
					<div class="form-group">
                      <label for="Renewal Dates" class="col-sm-4 control-label">Renewal Dates</label>
                      <div class="col-sm-8">
						<? echo utility::getFormatedDateReturn($enq_row["renewal_dates"]); ?>
                      </div>
                    </div>
					
					<div class="form-group">
                      <label for="Consultant" class="col-sm-4 control-label">Consultant</label>
                      <div class="col-sm-8" id="introducer_div">
						<? 
							$consultant_string = "";
							$sql_for_enquiry_admin = "SELECT * FROM job_admin_mapping WHERE job_id = ".$_REQUEST['id']." ";
							$result_for_enquiry_admin = mysqli_query($conn,$sql_for_enquiry_admin);
							while($row_for_enquiry_admin = mysqli_fetch_array($result_for_enquiry_admin)){
								$consultant_string .= ucfirst(utility::getTableFieldById("admin","name","id",$row_for_enquiry_admin["admin_id"])).",";
							}
							$consultant_string = substr($consultant_string,0,-1);
							echo $consultant_string;
						?>
                      </div>
                    </div>
					
					<div class="form-group">
					  <label for="Turnover" class="col-sm-4 control-label">Turnover</label>
					  <div class="col-sm-8">
						<?php 
							if(isset($enq_row["turnover"]) && $enq_row["turnover"] != 0){
								echo "&pound".number_format($enq_row["turnover"],2); 
							}
						?>
					  </div>
					</div>
					
					<div class="form-group">
					  <label for="Number of employees" class="col-sm-4 control-label">Number of employees</label>
					  <div class="col-sm-8">
						<?php 
							if(isset($enq_row["number_of_employees"]) && $enq_row["number_of_employees"] != 0){
								echo $enq_row["number_of_employees"]; 
							}
						?>
					  </div>
					</div>
					
					<div class="form-group">
					  <label for="Package/Insurance Type" class="col-sm-4 control-label">Package/Insurance Type</label>
					  <div class="col-sm-8">
						<?php echo ucfirst(Keycode::getkeycodeById($enq_row["insurance_type"]));?>
					  </div>
					</div>
					
					<div class="form-group">
					  <label for="Business Type" class="col-sm-4 control-label">Business Type</label>
					  <div class="col-sm-8">
						<?php echo ucfirst(Keycode::getkeycodeById($enq_row["business_type"]));?>
					  </div>
					</div>
					
					<!--<div class="form-group">
					  <label for="Policy Type" class="col-sm-4 control-label">Policy Type</label>
					  <div class="col-sm-8">
						<?php //echo ucfirst(Keycode::getkeycodeById($enq_row["policy_type"]));?>
					  </div>
					</div>-->
					
					<div class="form-group">
					  <label for="Prospect traffic lights" class="col-sm-4 control-label">Prospect traffic lights</label>
					  <div class="col-sm-8">
						<?php echo ucfirst(Keycode::getkeycodeById($enq_row["prospect_traffic_lights"]));?>
					  </div>
					</div>
					
					<div class="form-group">
					  <label for="Contact Method" class="col-sm-4 control-label">Contact Method</label>
					  <div class="col-sm-8">
						<?php echo ucfirst(Keycode::getkeycodeById($enq_row["contact_method"]));?>
					  </div>
					</div>
					
					
					<? if($enq_row["is_enquiry"] == 1){ ?>
					<div class="form-group">
                      <label for="Contact Source" class="col-sm-4 control-label">Enquiry Source</label>
                      <div class="col-sm-8">
                        <?php echo ucfirst(Keycode::getkeycodeById($enq_row["enquiry_source"]));?>
                      </div>
                    </div>
					<!--<div class="form-group">
                      <label for="Business Type" class="col-sm-4 control-label">Business Type</label>
                      <div class="col-sm-8">
                        <?php echo ucfirst(Keycode::getkeycodeById($enq_row["business_type"]));?>
                      </div>
                    </div>
					<div class="form-group">
                      <label for="Contact Workshops" class="col-sm-4 control-label">Contact Workshops</label>
                      <div class="col-sm-8">
                        <?php echo ucfirst(Keycode::getkeycodeById($enq_row["contact_workshops"]));?>
                      </div>
                    </div>-->
					<? }else if($enq_row["is_celebrant"] == 1){ ?>
					<!--<div class="form-group">
                      <label for="Type of Celebrant" class="col-sm-4 control-label">Type of Celebrant</label>
                      <div class="col-sm-8">
                        <?php echo ucfirst(Keycode::getkeycodeById($enq_row["type_of_celebrant"]));?>
                      </div>
                    </div>
					<div class="form-group">
                      <label for="Status" class="col-sm-4 control-label">Status</label>
                      <div class="col-sm-8">
                        <?php echo ucfirst(Keycode::getkeycodeById($enq_row["celebrant_status"]));?>
                      </div>
                    </div>
					<div class="form-group">
                      <label for="Mentor" class="col-sm-4 control-label">Mentor</label>
                      <div class="col-sm-8">
                        <?php echo ucfirst(Keycode::getkeycodeById($enq_row["celebrant_mentor"]));?>
                      </div>
                    </div>
					<div class="form-group">
                      <label for="Accreditation Observer" class="col-sm-4 control-label">Accreditation Observer</label>
                      <div class="col-sm-8">
                        <?php echo ucfirst(Keycode::getkeycodeById($enq_row["accreditation_observer"]));?>
                      </div>
                    </div>
					<div class="form-group">
                      <label for="Peer Observation Date" class="col-sm-4 control-label">Peer Observation Date</label>
                      <div class="col-sm-8">
						<? echo utility::getFormatedDateReturn($enq_row["peer_observation_date"]); ?>
                      </div>
                    </div>
					<div class="form-group">
                      <label for="CPD Complete Date" class="col-sm-4 control-label">CPD Complete Date</label>
                      <div class="col-sm-8">
						<? echo utility::getFormatedDateReturn($enq_row["cpd_complete_date"]); ?>
                      </div>
                    </div>
					<div class="form-group">
                      <label for="Last Spoke Date" class="col-sm-4 control-label">Last Spoke Date</label>
                      <div class="col-sm-8">
						<? echo utility::getFormatedDateReturn($enq_row["last_spoke_date"]); ?>
                      </div>
                    </div>-->
					<? }else if($enq_row["is_funeral"] == 1){ ?>
					<!--<div class="form-group">
                      <label for="Funeral Date" class="col-sm-4 control-label">Funeral Date</label>
                      <div class="col-sm-8">
						<? echo utility::getFormatedDateReturn($enq_row["funeral_date"]); ?>
                      </div>
                    </div>
					<div class="form-group">
                      <label for="Funeral Director" class="col-sm-4 control-label">Funeral Director</label>
                      <div class="col-sm-8">
                        <?php echo ucfirst(Keycode::getkeycodeById($enq_row["funeral_director"]));?>
                      </div>
                    </div>
					<div class="form-group">
                      <label for="Crematorium" class="col-sm-4 control-label">Crematorium</label>
                      <div class="col-sm-8">
                        <?php echo ucfirst(Keycode::getkeycodeById($enq_row["crematorium"]));?>
                      </div>
                    </div>
					<div class="form-group">
                      <label for="Date of Birth" class="col-sm-4 control-label">Date of Birth</label>
                      <div class="col-sm-8">
						<? echo utility::getFormatedDateReturn($enq_row["date_of_birth"]); ?>
                      </div>
                    </div>
					<div class="form-group">
                      <label for="Date of Death" class="col-sm-4 control-label">Date of Death</label>
                      <div class="col-sm-8">
						<? echo utility::getFormatedDateReturn($enq_row["date_of_death"]); ?>
                      </div>
                    </div>
					<div class="form-group">
                      <label for="Next of Kin" class="col-sm-4 control-label">Next of Kin</label>
                      <div class="col-sm-8">
						<? echo $enq_row["next_of_kin"]; ?>
                      </div>
                    </div>
					<div class="form-group">
                      <label for="Date of Family Meeting" class="col-sm-4 control-label">Date of Family Meeting</label>
                      <div class="col-sm-8">
						<? echo utility::getFormatedDateReturn($enq_row["date_of_family_meeting"]); ?>
                      </div>
                    </div>
					<div class="form-group">
                      <label for="Is Music Required" class="col-sm-4 control-label">Is Music Required</label>
                      <div class="col-sm-8">
						<? echo ($enq_row["is_music_required"]) ? "Yes" : "No"; ?>
                      </div>
                    </div>-->
					<? } ?>
                  </div><!-- /.box-body -->
                </form>
              </div><!-- /.box -->
            </div><!-- /.box -->
		</div>
		</div>
	</div>
	</div>
</section>

<? include("modules/enquiry_management/add_post_out.inc.php");?>

<section class="content" style="/* width:100%;float:left; */">
<div class="container-fluid">
<div class="row">
		<div class="col-xs-12 no-padding">
<? if($enq_row["is_celebrant"]==1){ ?>
	<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 <?//=$hidden_for_installer?>">
	  <div class="box box-primary">
		<div class="box-header with-border">
			<h3 class="box-title">Download</h3>
		</div>
		<div class="form-horizontal">
			<div class="box-body">
				<div class="form-group">
				  <label for="Quotation Template" class="col-sm-6 control-label">Quotation</label>
				  <div class="col-sm-6">
					<!--<a href="../../invoice/quotation_template.php?id=<?=base64_encode(base64_encode(base64_encode(base64_encode(base64_encode(base64_encode($_REQUEST['id']))))));?>" target="_blank">-->
					<a href="../../invoice/quotation_template.php?di=<?=urlencode(utility::app_crypt($_REQUEST["id"],'e'));?>&id=<?=$_REQUEST['id']?>" target="_blank">
						<span>
							<i class="fa fa-fw fa-download"></i>
						</span>
					</a>
				  </div>
				</div>
			</div>
		</div>
	  </div>
	</div>
<? } ?>
</div>
</div>
</div>
</section>

<? if(Admin::hasPermission('template_document')){
	include("modules/template_document/view_template_for_client.inc.php");
}?>

<? if($enq_row["is_enquiry"]!=1 && $enq_row["is_celebrant"]!=1){ ?>

<form id="export_invoice" name="export_invoice" method="post" action="index?page=export_invoice">
<section class="content-header">
	<h1 style="float:left;">
		Invoices
	</h1>
	<a href="" data-toggle="modal" data-target="#myModal" alt="<?=$_REQUEST['id'];?>" class="btn btn-primary invoice1" style="float:right;margin-right:5px;margin-bottom:5px;">
	Add Invoice</a>
	
	<button type="submit" name="export_to_xero" id="export_to_xero" class="btn btn-primary" style="float:right;margin-right:5px;margin-bottom:5px;">Export To Xero</button>
	<input type="hidden" name="job_id" value="<?=$_REQUEST['id'];?>">
</section>
<?
$query = "SELECT * FROM invoice WHERE job_id = ".$_REQUEST['id']." ORDER BY invoice_date DESC ";
$sql=mysqli_query($conn,$query);
$result=mysqli_num_rows($sql);
?>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<? if($result>0){ ?>
			<div class="box box-primary" id="overflow_div">
			<!-- Start  records header -->
			<table id="example1" class="table table-bordered table-striped">
				<thead>
					<tr>
						<th>Job Id</th>
						<th>Description</th>
						<th>Consultant</th>
						<th>Status</th>
						<th>Amount (&pound;)</th>
						<th>Date</th>
						<th>Due Date</th>
						<th>Inv. Pay. Status</th>
						<th>Paid Amount (&pound;)</th>
						<th>Send Invoice</th>
						<th>View Invoice</th>
						<th>Xero<br><input type="checkbox" name="check_all" id="check_all" /></th>
					</tr>
				</thead>
				<tbody>
				<!-- End records header -->
				<?
				while($row = mysqli_fetch_array($sql)){
				?>
				<!-- Start data -->
				<tr>
					<td><?php echo $row['job_id']; ?></td>
					<td width="20%"><?php echo $row['invoice_text']; ?></td>
					<td><?php echo Admin::getAdminsById($row['admin_id']); ?></td>
					<td><?php echo $gsi->getInvoiceStatusById($row['invoice_status']); ?></td>
					<td><?php echo number_format($row['amount'],2); ?></td>
					<td><?php echo utility::getFormatedDateReturn($row['invoice_date']); ?></td>
					<td><?php echo utility::getFormatedDateReturn($row['due_date']); ?></td>
					<td><?php echo $gsi->getInvoicePaymentStatusById($row['id']); ?></td>
					<td><?php echo $gsi->getInvoicePaymentAmountById($row['id']); ?></td>
					<? $is_send_color = (utility::getTableFieldById("invoice","is_send","id",$row['id']) == 1) ? "red" : "";?>
					<?
						$from = $_REQUEST["from"];
					?>
					<td><a style="color:<?=$is_send_color;?>" href="index?page=view_enquiry_progress&from=<?=$from;?>&action=send_invoice&id=<?=$row['id'];?>&job_id=<?=$row['job_id'];?>">Send Invoice</a></td>
					<td><a href="<?=$config->frontEndURL;?>/invoice/invoice.php?id=<?=base64_encode(base64_encode(base64_encode(base64_encode(base64_encode(base64_encode($row['id']))))))?>" target="_blank">View Invoice</a></td>
					<td><input type="checkbox" class="checkbox" name="invoice_ids[]" value="<?=$row['id'];?>" <?=$checked;?> /></td>
				</tr>
				<!-- End data -->
				<? 
				}?>
				</tbody>
			</table>
			</div>
			<?}else{?>
				<div class="box box-primary">No invoice found...</div>
			<? } ?>
		</div>
	</div>
</section>
</form>

<section class="content-header">
	<h1 style="float:left;">
		Payments
	</h1>
	<a href="" data-toggle="modal" data-target="#myModal" alt="<?=$_REQUEST['id'];?>" class="btn btn-primary payment" style="float:right;margin-right:5px;margin-bottom:5px;">
	Add Payments</a>
</section>
<?
$query = "SELECT * FROM payment WHERE job_id = ".$_REQUEST['id']." ORDER BY payment_date DESC ";
$sql=mysqli_query($conn,$query);
$result=mysqli_num_rows($sql);
?>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<? if($result>0){ ?>
			<div class="box box-primary" id="overflow_div">
			<!-- Start  records header -->
			<table id="example1" class="table table-bordered table-striped">
				<thead>
					<tr>
						<th>Job Id</th>
						<th>Description</th>
						<th>Consultant</th>
						<th>Status</th>
						<th>Amount (&pound;)</th>
						<th>Date</th>
						<th>For Invoice</th>
					</tr>
				</thead>
				<tbody>
				<!-- End records header -->
				<?
				while($row = mysqli_fetch_array($sql)){
				?>
				<!-- Start data -->
				<tr>
					<td><?php echo $row['job_id']; ?></td>
					<td><?php echo $row['payment_text']; ?></td>
					<td><?php echo Admin::getAdminsById($row['admin_id']); ?></td>
					<td><?php echo $gsi->getPaymentStatusById($row['payment_status']); ?></td>
					<td><?php echo number_format($row['amount'],2); ?></td>
					<td><?php echo utility::getFormatedDateReturn($row['payment_date']); ?></td>
					<td><?php echo $gsi->getInvoiceById($row['invoice_id']); ?></td>
				</tr>
				<!-- End data -->
				<? } ?>
				</tbody>
			</table>
			</div>
			<?}else{?>
				<div class="box box-primary p-15">No payment found...</div>
			<? } ?>
		</div>
	</div>
</section>

<?}?>
<? if(Admin::hasPermission('quotation_items')){
	include("modules/quotation_items/add_quotation_with_modal.inc.php");
}?>
<?/*?> 
<section class="content-header <?=$hidden_for_installer?>">
	<h1 style="float:left;">
		Quotation Items
	</h1>
	<a href="" data-toggle="modal" data-target="#myModal" alt="<?=$_REQUEST['id'];?>" class="btn btn-primary quotationitems" style="float:right;margin-right:5px;margin-bottom:5px;">
	Add Quotation Items</a>
</section>
<?
$query = "SELECT * FROM quotation_items_mapping WHERE job_id = ".$_REQUEST['id']." ORDER BY id ";
$sql=mysqli_query($conn,$query);
$result=mysqli_num_rows($sql);
?>
<section class="content <?=$hidden_for_installer?>">
	<div class="row">
		<div class="col-xs-12">
			<? if($result>0){ ?>
			<div class="box box-primary" id="overflow_div">
			<!-- Start  records header -->
			<table id="example1" class="table table-bordered table-striped">
				<thead>
					<tr>
						<th>Name</th>
						<th>Price</th>
						<th>Qty</th>
						<th>Total</th>
					</tr>
				</thead>
				<tbody>
				<!-- End records header -->
				<?
				while($row = mysqli_fetch_array($sql)){
					$total = $row["qty_list"] * $row["quotation_items_price"];
				?>
				<!-- Start data -->
				<tr>
					<td><?php echo $row['quotation_items_name_list']; ?></td>
					<td><?php echo number_format($row['quotation_items_price'],2); ?></td>
					<td><?php echo $row['qty_list']; ?></td>
					<td><?php echo number_format($total,2); ?></td>
				</tr>
				<!-- End data -->
				<? } ?>
				</tbody>
			</table>
			</div>
			<?}else{?>
				<div class="box box-primary p-15">No quotation item found...</div>
			<? } ?>
		</div>
	</div>
</section>
<? */?>
<? if(Admin::hasPermission('job_contract')){
	include("modules/job_contract/add_contract_with_modal.inc.php");
}?>

<?/* ?>
<section class="content-header hide">
	<h1 style="float:left;">
		Job Contract
	</h1>
	<a href="" data-toggle="modal" data-target="#myModal" alt="<?=$_REQUEST['id'];?>" class="btn btn-danger job_contract" style="float:right;margin-right:5px;margin-bottom:5px;">
	Add Job Contract</a>
</section>
<?
$query = "SELECT * FROM job_contract WHERE job_id = ".$_REQUEST['id']." ORDER BY renewal_date DESC ";
$sql=mysqli_query($conn,$query);
$result=mysqli_num_rows($sql);
?>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<? if($result>0){ ?>
			<div class="box box-danger" id="overflow_div">
			<!-- Start  records header -->
			<table id="example1" class="table table-bordered table-striped">
				<thead>
					<tr>
						<th>Policy type</th>
						<th>Contract status</th>
						<th>Contract value</th>
						<th>Renewal date</th>
						<th>Edit</th>
						<th>Delete</th>
					</tr>
				</thead>
				<tbody>
				<!-- End records header -->
				<?
				while($row = mysqli_fetch_array($sql)){
				?>
				<!-- Start data -->
				<tr>
					<td><?php echo ucfirst(Keycode::getkeycodeById($row["policy_type"]));?></td>
					<td><?php echo ucfirst(Keycode::getkeycodeById($row["contract_status"]));?></td>
					<td><?php echo $row['contract_value']; ?></td>
					<td><?php echo utility::getFormatedDateReturn($row['renewal_date']); ?></td>
					<td>
						<a href="" class="edit_job_contract" data-toggle="modal" data-target="#myModal" alt="<?=$row['id'];?>"> 
							<i class="fa fa-fw fa-edit"></i> 
						</a>
					</td>
					<td>
						<a href="" class="delete_job_contract" data-toggle="modal" data-target="#myModal" alt="<?=$row['id'];?>">
							<i class="fa fa-fw fa-trash-o"></i> 
						</a>
					</td>
				</tr>
				<!-- End data -->
				<? } ?>
				</tbody>
			</table>
			</div>
			<?}else{?>
				<div class="box box-danger p-15">No Job Contract found...</div>
			<? } ?>
		</div>
	</div>
</section>
<? */?>

<? //include("modules/timesheet_management/view_timesheet_for_clients.inc.php");?>

<? if(Admin::hasPermission('timesheet_management')){
	include("modules/timesheet_management/add_timesheet_with_ajax.inc.php");
}?>

<?/* <section class="content-header hide">
	<h1 style="float:left;">
		Timesheets
	</h1>
	<a href="" data-toggle="modal" data-target="#myModal" alt="<?=$_REQUEST['id'];?>" class="btn btn-primary timesheet" style="float:right;margin-right:5px;margin-bottom:5px;">
	Add Timesheet</a>
	<div style="float:right;margin-right:5px;border:0px solid;width:150px;height:24px;margin-top:8px;">
		<b>Total Time</b>
		<b><? echo $gsi->getTotalTimeByJobId($_REQUEST['id'])?></b>
	</div>
</section>
<?
/* $query = "SELECT * FROM timesheet WHERE job_id = ".$_REQUEST['id']." ORDER BY timesheet_date DESC ";
$sql=mysqli_query($conn,$query);
$result=mysqli_num_rows($sql); 
?>
<section class="content hide">
	<div class="row">
		<div class="col-xs-12">
			<? if($result>0){ ?>
			<div class="box box-primary" id="overflow_div">
			<!-- Start  records header -->
			<table id="example1" class="table table-bordered table-striped">
				<thead>
					<tr>
						<th>Description</th>
						<!--<th>Job</th>-->
						<th>Created By</th>
						<th>Date</th>
						<th>From Time</th>
						<th>To Time</th>
						<th>Time</th>
					</tr>
				</thead>
				<tbody>
				<!-- End records header -->
				<?
				while($row = mysqli_fetch_array($sql)){
				?>
				<!-- Start data -->
				<tr>
					<td><?php echo $row['timesheet_text']; ?></td>
					<!--<td><?php //echo $gsi->getEnqQuoteJobById($row['job_id']); ?></td>-->
					<td><?php echo Admin::getAdminsById($row['admin_id']); ?></td>
					<td><?php echo utility::getFormatedDateReturn($row['timesheet_date']); ?></td>
					<td><?php echo $row['from_time']; ?></td>
					<td><?php echo $row['to_time']; ?></td>
					<td><?php echo $row['timesheet_time']; ?></td>
				</tr>
				<!-- End data -->
				<? 
				}?>
				<tr>
					<td colspan="5" style="text-align:right;"><b>Total Time</b></td>
					<td><b><? echo $gsi->getTotalTimeByJobId($_REQUEST['id'])?></b></td>
				</tr>
				</tbody>
			</table>
			</div>
			<?}else{?>
				<div class="box box-primary p-15">No timesheet found...</div>
			<? } ?>
		</div>
	</div>
</section>
 */?>
 
<section class="content">
	<div class="container-fluid">
		<div class="row">
			<div class="col-12"> 
				<div id="" class="card">

				<div class="card-header">
				<h3 class="card-title">Appointments</h3>

					<div class="card-tools">
						<div class="input-group input-group-sm" style="">
							<a href="" data-toggle="modal" data-target="#myModal" alt="<?=$_REQUEST['id'];?>" class="btn btn-warning appointment" style="float:right;margin-right:5px;margin-bottom:5px;">Add Appointment</a>
						</div>
					</div>
				</div>
				<?
				$query = "SELECT * FROM appointment WHERE job_id = ".$_REQUEST['id']." ORDER BY appointment_date DESC ";
				$sql=mysqli_query($conn,$query);
				$result=mysqli_num_rows($sql); 
				?>

					<div class="card-body table-responsive" style="height: auto;">
						<? if($result>0){ ?>
						<div class="box box-warning" id="overflow_div">
						<!-- Start  records header -->
						<table id="example1" class="table table-bordered table-striped">
							<thead>
								<tr>
									<th>Description</th>
									<!--<th>Job</th>-->
									<th>Consultant</th>
									<th>Date</th>
									<th>Time From</th>
									<th>Time To</th>
									<th>Edit</th>
									<th>Delete</th>
								</tr>
							</thead>
							<tbody>
							<!-- End records header -->
							<?
							while($row = mysqli_fetch_array($sql)){
							?>
							<!-- Start data -->
							<tr>
								<td><?php echo '<span title="'.ucfirst($row['appointment_text']).'">'.utility::ellipsis(ucfirst($row['appointment_text']),50).'</span>'; ?></td>
								<!--<td><?php //echo $gsi->getEnqQuoteJobById($row['job_id']); ?></td>-->
								<td><?php echo Admin::getAdminsById($row['admin_id']); ?></td>
								<td><?php echo utility::getFormatedDateReturn($row['appointment_date']); ?></td>
								<td><?php echo $row['appointment_time']; ?></td>
								<td><?php echo $row['appointment_time_to']; ?></td>								
								<td>
									<a href="" class="edit_appointment" data-toggle="modal" data-target="#myModal" alt="<?=$row['id'];?>"> 
										<i class="fa fa-fw fa-edit"></i> 
									</a>
								</td>
								<td>
									<a href="" class="delete_appointment" data-toggle="modal" data-target="#myModal" alt="<?=$row['id'];?>">
										<i class="fa fa-fw fa-trash-o"></i> 
									</a>
								</td>
							</tr>
							<!-- End data -->
							<? } ?>
							</tbody>
						</table>
						</div>
						<?}else{?>
							<div class="box box-warning p-15">No appointment found...</div>
						<? } ?>
					</div>					
				</div>
			</div>
		</div>
	</div>
</section>

<? //include("modules/notes/view_notes_for_clients.inc.php");?>


<? if(Admin::hasPermission('notes_management')){
	include("modules/notes/add_notes_with_ajax.inc.php");
}?>

<? if(Admin::hasPermission('reminders_management')){
	include("modules/notes/add_reminder_with_ajax.inc.php");
}?>

<? if(Admin::hasPermission('message')){
	include("modules/message/send_message_with_modal.inc.php");
}?>
<?/* ?>
<section class="content-header">
	<h1 style="float:left;">
		Message
	</h1>
	<a href="" data-toggle="modal" data-target="#myModal" alt="<?=$_REQUEST['id'];?>" class="btn btn-warning message" style="float:right;margin-right:5px;margin-bottom:5px;">
	Send Message</a>
</section>
<?
$query = "SELECT * FROM message WHERE job_id = ".$_REQUEST['id']." ORDER BY message_date DESC ";
$sql=mysqli_query($conn,$query);
$result=mysqli_num_rows($sql);
?>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<? if($result>0){ ?>
			<div class="box box-warning" id="overflow_div">
			<!-- Start  records header -->
			<table id="example1" class="table table-bordered table-striped">
				<thead>
					<tr>
						<th>Message Name</th>
						<th style="width:68%;">Message</th>
						<th>Created By</th>
						<th>Date</th>
					</tr>
				</thead>
				<tbody>
				<!-- End records header -->
				<?
				while($row = mysqli_fetch_array($sql)){
				?>
				<!-- Start data -->
				<tr>
					<td><?php echo $gsi->getMessageTemplateById($row['message_id']); ?></td>
					<td><?php echo '<span class="titleonmob" title="'.ucfirst($row['message_text']).'">'.utility::ellipsis(ucfirst($row['message_text']),105).'</span>'; ?></td>
					<td>
						<?php 
							if(isset($row['job_user_id']) && $row['job_user_id'] != 0){
								echo $gsi->getJobUserById($row['admin_id']); 
							}else{
								echo Admin::getAdminsById($row['admin_id']); 
							}
						?>
					</td>
					<td><?php echo utility::getFormatedDateReturn($row['message_date']); ?></td>
				</tr>
				<!-- End data -->
				<? } ?>
				</tbody>
			</table>
			</div>
			<?}else{?>
				<div class="box box-warning p-15">No message found...</div>
			<? } ?>
		</div>
	</div>
</section>
<? */?>
<? 
	$add_docu_btn = "hide";
	$docu_id = utility::getTableFieldById("documents","id","job_id",$_REQUEST['id']); 
	if($docu_id >0){
		$add_docu_btn = "none";
	}
?>
<section class="content">
	<div class="container-fluid">
		<div class="row">
			<div class="col-12"> 
				<div id="" class="card">
					<div class="card-header">
					<h3 class="card-title">Documents</h3>

						<div class="card-tools">
							<div class="input-group input-group-sm" style="">
							<a href="" data-toggle="modal" data-target="#myModal" alt="<?=$_REQUEST['id'];?>" class="btn btn-info document" style="float:right;margin-right:5px;margin-bottom:5px;">Add Document</a>

							<a target="_blank" href="<?=$config->siteURL;?>/modules/fileuploads/server/php/files-zip.php?id=<?=$_REQUEST['id'];?>" data-toggle="modal"class="btn btn-info document <?=$add_docu_btn;?>" style="float:right;margin-right:5px;margin-bottom:5px;display:<?=$hide_button;?>;">Download All as Zip</a> &nbsp;&nbsp;
							</div>
						</div>
					</div>

				<?
				$query = "SELECT * FROM documents WHERE job_id = ".$_REQUEST['id']." ORDER BY document_date DESC ";
				$sql=mysqli_query($conn,$query);
				$result=mysqli_num_rows($sql);
				?>

					<div class="card-body table-responsive" style="height: auto;">
						
						<div class="box box-primary" id="overflow_div" style="height:185px;">
						<!-- Start  records header -->
						<iframe width="100%" height="185px" style="border:0;" src="<? echo $config->siteURL;?>/modules/fileuploads/image-files.php?id=<?=$_REQUEST['id'];?>&hide_add=1"></iframe>
						</div>			
					</div>					
				</div>
			</div>
		</div>
	</div>
</section>

<section class="content">
	<div class="container-fluid">
		<div class="row">
			<div class="col-12"> 
				<div id="" class="card">
				<div class="card-header">
					<h3 class="card-title">Mails</h3>

					<div class="card-tools">
						<div class="input-group input-group-sm" style="">
							<a href="" data-toggle="modal" data-target="#myModalForSendMail" class="btn btn-primary send_mail" alt="<?=$_REQUEST['id'];?>" style="float:right;margin-right:5px;margin-bottom:5px;">Send Mail</a>
						</div>
					</div>
				</div>

				<?
				$query = "SELECT * FROM email_track WHERE job_id = ".$_REQUEST['id']." ORDER BY email_date DESC ";
				$sql=mysqli_query($conn,$query);
				$result=mysqli_num_rows($sql);
				?>

					<div class="card-body table-responsive" style="height: auto;">
						<? if($result>0){ ?>
						<div class="box box-primary" id="overflow_div">
						<!-- Start  records header -->
						<table id="example1" class="table table-bordered table-striped">
							<thead>
								<tr>
									<th>Mail Subject</th>
									<th>Mail Body</th>
									<th style="width:10%;">Date</th>
									<th>Attach</th>
								</tr>
							</thead>
							<tbody>
							<!-- End records header -->
							<?
							while($row = mysqli_fetch_array($sql)){
							?>
							<!-- Start data -->
							<tr>
								<td><?php echo $row['email_subject']; ?></td>
								<td><?php echo $row['email_body']; ?></td>
								<td><?php echo utility::getFormatedDateReturn($row['email_date']); ?></td>
								<td>
									<?php
									$sql_for_attch = "SELECT * FROM mail_document_upload WHERE email_track_id = ".$row['id'];
										$rs_for_attch = mysqli_query($conn,$sql_for_attch);
										if(mysqli_num_rows($rs_for_attch) > 0){
											while($data_for_attch = mysqli_fetch_assoc($rs_for_attch)){
												echo "<a href='".$config->siteURL."/document_upload/".$data_for_attch["document_name"]."' target='_blank'>".$data_for_attch["document_name"]."</a> ,  ";
											}
										}
									?>
								</td>
							</tr>
							<!-- End data -->
							<? } ?>
							</tbody>
						</table>
						</div>
						<? }else{ ?>
						<div class="box box-primary p-15">No email found...</div>
						<? } ?>
					</div>					
				</div>
			</div>
		</div>
	</div>
</section>

<style>
	#overflow_div::-webkit-scrollbar
    {
      width: 5px;  /* for vertical scrollbars */
      height: 5px; /* for horizontal scrollbars */
    }
 
    #overflow_div::-webkit-scrollbar-track
    {
      background:#E7E8E9;
    }
 
    #overflow_div::-webkit-scrollbar-thumb
    {
      background: #3c8dbc;
    }
	#overflow_div{
		height:150px;
		overflow-y: auto;
	}
</style>
<div class="modal fade" id="myModalForSendMail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"></div>
<script type="text/javascript">
$(function () {
	
	$('#export_to_xero').click(function(){
		if ($(".checkbox:checked").length == 0){
			alert("Please check at least one invoice to export.");
			return false;
		}
	});

	$('#check_all').click(function(){
        if($("#check_all:checked").length == 1){
            $('.checkbox').prop( "checked", true );
        }else{
            $('.checkbox').prop( "checked", false );
        }
    });
	$(".download_span").click(function(){
		//alert($(this).parent().attr("id"));
		var form_id = $(this).parent().attr("id");
		$("#"+form_id).submit();
	});
	$(".download_instruction_to_proceed").click(function(){
		//alert($(this).parent().attr("id"));
		var form_id = $(this).parent().attr("id");
		$("#"+form_id).submit();
	});
	$(".download_client_care_letter").click(function(){
		//alert($(this).parent().attr("id"));
		var form_id = $(this).parent().attr("id");
		$("#"+form_id).submit();
	});
	
	$(".invoice1").click(function(){	
		$("#myModalLabel").text("Invoice Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/payment_management/index?page=view_invoice&source=<?=$source;?>&job_id="+job_id+hide_top_left);
	});
	$(".payment").click(function(){	
		$("#myModalLabel").text("Payment Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/payment_management/index?page=view_payment&source=<?=$source;?>&job_id="+job_id+hide_top_left);
	});
	$(".one_to_one").click(function(){	
		$("#myModalLabel").text("One to One Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/one_to_one_management/index?page=view&source=<?=$source;?>&job_id="+job_id+hide_top_left);
	});
	$(".referral").click(function(){	
		$("#myModalLabel").text("Referral Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/referrals_management/index?page=view&source=<?=$source;?>&job_id="+job_id+hide_top_left);
	});
	$(".timesheet").click(function(){	
		$("#myModalLabel").text("Timesheet Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/timesheet_management/index?page=view&source=<?=$source;?>&job_id="+job_id+hide_top_left);
	});
	$(".mileage").click(function(){	
		$("#myModalLabel").text("Mileage Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/mileage/index?page=view&source=<?=$source;?>&job_id="+job_id+hide_top_left);
	});
	$(".quotationitems").click(function(){	
		$("#myModalLabel").text("Quotation Items");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/quotation_items/index?page=addquickquotationitems&source=e&job_id="+job_id+hide_top_left);
	});
	$(".job_contract").click(function(){	
		$("#myModalLabel").text("Job Contract Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/job_contract/index?page=list&source=<?=$source;?>&job_id="+job_id+hide_top_left);
	});
	
	$(".edit_job_contract").click(function(){
		$("#myModalLabel").text("Job Contract Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = "<?=$_REQUEST['id'];?>";	
		var job_contract_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/job_contract/index?page=list&action=edit&from=view_enquiry_progress&source=<?=$source;?>&job_id="+job_id+"&id="+job_contract_id+hide_top_left);
	});
	$(".delete_job_contract").click(function(){	
		if(confirm('Are you sure! You want to delete') == true){
			$("#myModalLabel").text("Job Contract Management");
			var hide_top_left = "&hide_top=1&hide_left=1";
			var job_id = "<?=$_REQUEST['id'];?>";	
			var job_contract_id = $(this).attr("alt");		
			$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/job_contract/index?page=list&action=delete&source=<?=$source;?>&job_id="+job_id+"&id="+job_contract_id+hide_top_left);
		}else{
			return false;
		}
	});
	
	
	$(".notes").click(function(){	
		$("#myModalLabel").text("Notes");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/notes/index?page=view&source=<?=$source;?>&job_id="+job_id+hide_top_left);
	});
	
	$(".edit_notes").click(function(){
		$("#myModalLabel").text("Notes");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = "<?=$_REQUEST['id'];?>";	
		var notes_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/notes/index?page=view&action=edit&from=view_enquiry_progress&source=<?=$source;?>&job_id="+job_id+"&id="+notes_id+hide_top_left);
	});
	$(".delete_notes").click(function(){	
		if(confirm('Are you sure! You want to delete') == true){
			$("#myModalLabel").text("Notes");
			var hide_top_left = "&hide_top=1&hide_left=1";
			var job_id = "<?=$_REQUEST['id'];?>";	
			var notes_id = $(this).attr("alt");		
			$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/notes/index?page=view&action=delete&source=<?=$source;?>&job_id="+job_id+"&id="+notes_id+hide_top_left);
		}else{
			return false;
		}
	});
	
	
	$(".reminders").click(function(){	
		$("#myModalLabel").text("Reminders Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/notes/index?page=view_reminder&source=<?=$source;?>&job_id="+job_id+hide_top_left);
	});
	
	$(".edit_reminders").click(function(){
		$("#myModalLabel").text("Reminders Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = "<?=$_REQUEST['id'];?>";	
		var reminders_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/notes/index?page=view_reminder&action=edit&from=view_enquiry_progress&source=<?=$source;?>&job_id="+job_id+"&id="+reminders_id+hide_top_left);
	});
	$(".delete_reminders").click(function(){	
		if(confirm('Are you sure! You want to delete') == true){
			$("#myModalLabel").text("Reminders Management");
			var hide_top_left = "&hide_top=1&hide_left=1";
			var job_id = "<?=$_REQUEST['id'];?>";	
			var reminders_id = $(this).attr("alt");		
			$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/notes/index?page=view_reminder&action=delete&source=<?=$source;?>&job_id="+job_id+"&id="+reminders_id+hide_top_left);
		}else{
			return false;
		}
	});
	
	
	$(".appointment").click(function(){	
		$("#myModalLabel").text("Appointment Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/appointment/index?page=view&source=<?=$source;?>&job_id="+job_id+hide_top_left);
	});
	
	$(".edit_appointment").click(function(){
		$("#myModalLabel").text("Appointment Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = "<?=$_REQUEST['id'];?>";	
		var appointment_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/appointment/index?page=view&action=edit&from=view_enquiry_progress&source=<?=$source;?>&job_id="+job_id+"&id="+appointment_id+hide_top_left);
	});
	$(".delete_appointment").click(function(){	
		if(confirm('Are you sure! You want to delete') == true){
			$("#myModalLabel").text("Appointment Management");
			var hide_top_left = "&hide_top=1&hide_left=1";
			var job_id = "<?=$_REQUEST['id'];?>";	
			var appointment_id = $(this).attr("alt");		
			$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/appointment/index?page=view&action=delete&from=view_enquiry_progress&source=<?=$source;?>&job_id="+job_id+"&id="+appointment_id+hide_top_left);
		}else{
			return false;
		}
	});
	
	$(".message").click(function(){	
		$("#myModalLabel").text("Message");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/message/index?page=view&source=<?=$source;?>&job_id="+job_id+hide_top_left);
	});
	
	$(".sales").click(function(){	
		$("#myModalLabel").text("Sales Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/sales/index?page=view&source=<?=$source;?>&job_id="+job_id+hide_top_left);
	});
	/* $(".document").click(function(){	
		$("#myModalLabel").text("Documents Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/document_management/index?page=view&source=<?=$source;?>&job_id="+job_id+hide_top_left);
	}); */
	$(".document").click(function(){	
		$("#myModalLabel").text("Documents Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/modules/fileuploads/image-files.php?id="+job_id+"&page=view&source=j"+hide_top_left);
	});
	
	$(".edit_document").click(function(){
		$("#myModalLabel").text("Documents Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = "<?=$_REQUEST['id'];?>";	
		var document_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/document_management/index?page=view&action=edit&from=view_enquiry_progress&source=<?=$source;?>&job_id="+job_id+"&id="+document_id+hide_top_left);
	});
	$(".delete_document").click(function(){	
		if(confirm('Are you sure! You want to delete') == true){
			$("#myModalLabel").text("Documents Management");
			var hide_top_left = "&hide_top=1&hide_left=1";
			var job_id = "<?=$_REQUEST['id'];?>";	
			var document_id = $(this).attr("alt");		
			$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/document_management/index?page=view&action=delete&source=<?=$source;?>&job_id="+job_id+"&id="+document_id+hide_top_left);
		}else{
			return false;
		}
	});
	
	
	
	$(".close_button").click(function(){
		$(".modal_iframe").attr("src","");
		location.reload();
	});
	$(".send_mail").click(function(){
		//if(confirm("Are you want to send mail.")){
			//alert($(this).attr('alt'));
			var job_id = $(this).attr('alt');
			var form_data   = {'job_id':job_id};       
			$.ajax({
				async: false,
				type: "POST",
				url: site_url+"/modules/enquiry_management/index.php?page=ajax_actions&action=send_mail",
				data: form_data,
				success: function(r){    
					//alert(r);
					//location.reload();
					$('#myModalForSendMail').show().html(r);  // put your modal id 
				}
			});
			//return false;
		//}
	});
});
</script>