<?php 
function countadvancelevel($company_id){
  $servername = "localhost";
  $username = "marsalog_mahran";
  $password = "gX-;hjZN-B*u";
  $dbname = "marsalog_shipping_clearance_db";
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  }
  $sql_num_level="SELECT * FROM hr_advance_level_tbl where company_id='$company_id' and type='salf'";
  $result_num_level = $conn->query($sql_num_level);
  $rowcount=mysqli_num_rows($result_num_level);


  return $rowcount;
}
function employ_dept($id){
  $servername = "localhost";
  $username = "marsalog_mahran";
  $password = "gX-;hjZN-B*u";
  $dbname = "marsalog_shipping_clearance_db";
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  }

  $sql_j = "SELECT * FROM hr_employ_tbl where employ_id='$id'";
 $result_j = $conn->query($sql_j);
  if ($result_j->num_rows > 0) {
  while($row_j = $result_j->fetch_assoc()) {
    $dep_id = $row_j["dept_id"];
   
  }}


  return $dep_id;

}
function dept_level_name($id,$company_id){
  $servername = "localhost";
  $username = "marsalog_mahran";
  $password = "gX-;hjZN-B*u";
  $dbname = "marsalog_shipping_clearance_db";
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  }

  $sql_j = "SELECT * FROM hr_advance_level_tbl where level='$id' and company_id='$company_id' and type='salf'";
 $result_j = $conn->query($sql_j);
  if ($result_j->num_rows > 0) {
  while($row_j = $result_j->fetch_assoc()) {
    $dept_d = $row_j["dept_id"];
   
  }}

  $sql_jj = "SELECT * FROM dept_tb where dept_id='$dept_d'";
  $result_jj = $conn->query($sql_jj);
   if ($result_jj->num_rows > 0) {
   while($row_jj = $result_jj->fetch_assoc()) {
     $dept_name = $row_jj["dept_name"];
    
   }}
  return $dept_name;

}
function dept_manager($id){
  $servername = "localhost";
  $username = "marsalog_mahran";
  $password = "gX-;hjZN-B*u";
  $dbname = "marsalog_shipping_clearance_db";
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  }

  $sql_j = "SELECT * FROM hr_employ_tbl where dept_id='$id' and dept_manager_type='dept_manager'";
 $result_j = $conn->query($sql_j);
  if ($result_j->num_rows > 0) {
  while($row_j = $result_j->fetch_assoc()) {
    $employ_id = $row_j["employ_id"];
   
  }}


  return $employ_id;

}
function promotionEmploy($company_id){
  $servername = "localhost";
  $username = "marsalog_mahran";
  $password = "gX-;hjZN-B*u";
  $dbname = "marsalog_shipping_clearance_db";
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  }
$promoEmploy = array();
  $sql_j = "SELECT * FROM hr_promo_employ where company_id='$company_id' and type='salf'";
 $result_j = $conn->query($sql_j);
  if ($result_j->num_rows > 0) {
  while($row_j = $result_j->fetch_assoc()) {
    array_push($promoEmploy,$row_j["employ_id"]);
   
  }}


  return $promoEmploy;

}
function checkifleveldeptmanager($id,$company_id){
  $servername = "localhost";
  $username = "marsalog_mahran";
  $password = "gX-;hjZN-B*u";
  $dbname = "marsalog_shipping_clearance_db";
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  }

  $sql_j = "SELECT * FROM hr_advance_level_tbl where level='$id' and company_id='$company_id' and type='salf'";
 $result_j = $conn->query($sql_j);
  if ($result_j->num_rows > 0) {
  while($row_j = $result_j->fetch_assoc()) {
    $dept_d = $row_j["dept_id"];
   
  }}


  return $dept_d;

}
function refuselevel($id,$company_id){
  $servername = "localhost";
  $username = "marsalog_mahran";
  $password = "gX-;hjZN-B*u";
  $dbname = "marsalog_shipping_clearance_db";
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  }

  $sql_j = "SELECT * FROM hr_advance_level_tbl where level='$id' and company_id='$company_id' and type='salf'";
 $result_j = $conn->query($sql_j);
  if ($result_j->num_rows > 0) {
  while($row_j = $result_j->fetch_assoc()) {
    $refuse_level = $row_j["level_refuse"];
   
  }}


  return $refuse_level;

}
function refusedetailsAr($id,$company_id){
  $servername = "localhost";
  $username = "marsalog_mahran";
  $password = "gX-;hjZN-B*u";
  $dbname = "marsalog_shipping_clearance_db";
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  }

  $sql_j = "SELECT * FROM hr_advance_level_tbl where level='$id' and company_id='$company_id' and type='salf'";
 $result_j = $conn->query($sql_j);
  if ($result_j->num_rows > 0) {
  while($row_j = $result_j->fetch_assoc()) {
    $level_refuse_stat_details_ar = $row_j["level_refuse_stat_details_ar"];
   
  }}


  return $level_refuse_stat_details_ar;

}
function refusedetailsEn($id,$company_id){
  $servername = "localhost";
  $username = "marsalog_mahran";
  $password = "gX-;hjZN-B*u";
  $dbname = "marsalog_shipping_clearance_db";
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  }

  $sql_j = "SELECT * FROM hr_advance_level_tbl where level='$id' and company_id='$company_id' and type='salf'";
 $result_j = $conn->query($sql_j);
  if ($result_j->num_rows > 0) {
  while($row_j = $result_j->fetch_assoc()) {
    $level_refuse_stat_details_en = $row_j["level_refuse_stat_details_en"];
   
  }}


  return $level_refuse_stat_details_en;

}
function countsalfStat($id){
  $servername = "localhost";
  $username = "marsalog_mahran";
  $password = "gX-;hjZN-B*u";
  $dbname = "marsalog_shipping_clearance_db";
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  }
  $sql_num_level="SELECT * FROM hr_salf_steps_tbl where salf_id='$id' and stat!='3'";
  $result_num_level = $conn->query($sql_num_level);
  $rowcount=mysqli_num_rows($result_num_level);


  return $rowcount;
}
function salf_level($id){
  $servername = "localhost";
  $username = "marsalog_mahran";
  $password = "gX-;hjZN-B*u";
  $dbname = "marsalog_shipping_clearance_db";
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  }
  $sql_j = "SELECT * FROM hr_salf_tbl where id='$id'";
  $result = $conn->query($sql_j);
  if ($result->num_rows > 0) {
   
      $level = $result->fetch_assoc();
      $idd = $level["level"];
  
  } else {
    $idd ="no";
  } 
  
      return $idd;


  return $rowcount;
}
function getnumlevel($id,$company_id){
  $servername = "localhost";
  $username = "marsalog_mahran";
  $password = "gX-;hjZN-B*u";
  $dbname = "marsalog_shipping_clearance_db";
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  }
$ar = array();
$sql_j = "SELECT * FROM hr_advance_level_tbl where company_id='$company_id' and type='salf'";
 $result_j = $conn->query($sql_j);
  if ($result_j->num_rows > 0) {
  while($row_j = $result_j->fetch_assoc()) {
    $d = $row_j["level"];
    $ar[$d] = $row_j["level"];
    
  }}


  return $ar[$id];
}
function getemployacceptid($id,$company_id){
  $servername = "localhost";
  $username = "marsalog_mahran";
  $password = "gX-;hjZN-B*u";
  $dbname = "marsalog_shipping_clearance_db";
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  }
$ar = array();
$sql_j = "SELECT * FROM hr_level_employ_approval where level='$id' and company_id='$company_id' and type='salf'";
 $result_j = $conn->query($sql_j);
  if ($result_j->num_rows > 0) {
  while($row_j = $result_j->fetch_assoc()) {
    array_push($ar,$row_j["employ_id"]);
  }}


  return $ar;
}
function getstatdetailsAR($id,$company_id){
  $servername = "localhost";
  $username = "marsalog_mahran";
  $password = "gX-;hjZN-B*u";
  $dbname = "marsalog_shipping_clearance_db";
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  }
  $ar = array();
  $sql_j = "SELECT * FROM hr_advance_level_tbl where company_id='$company_id' and type='salf'";
   $result_j = $conn->query($sql_j);
    if ($result_j->num_rows > 0) {
    while($row_j = $result_j->fetch_assoc()) {
      $d = $row_j["level"];
      $ar[$d] = $row_j["level_stat_details_ar"];
      
    }}
 

    return $ar[$id];
  }
  function getstatdetailsEN($id,$company_id){
    $servername = "localhost";
$username = "marsalog_mahran";
$password = "gX-;hjZN-B*u";
$dbname = "marsalog_shipping_clearance_db";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
    $ar = array();
    $sql_j = "SELECT * FROM hr_advance_level_tbl where company_id='$company_id' and type='salf'";
     $result_j = $conn->query($sql_j);
      if ($result_j->num_rows > 0) {
      while($row_j = $result_j->fetch_assoc()) {
        $d = $row_j["level"];
        $ar[$d] = $row_j["level_stat_details_en"];
        
      }}
   

    return $ar[$id];
    }
    function getthelastidofsalfstat($id){
      $servername = "localhost";
  $username = "marsalog_mahran";
  $password = "gX-;hjZN-B*u";
  $dbname = "marsalog_shipping_clearance_db";
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  }
 
  $sql_j = "SELECT * FROM hr_salf_steps_tbl where salf_id='$id' ORDER BY id DESC LIMIT 1";

  // Execute the query
  $result = $conn->query($sql_j);
  // Check if a record was found
  if ($result->num_rows > 0) {
      // Fetch the last record as an associative array
      $lastRecord = $result->fetch_assoc();
      $idd = $lastRecord["id"];
  
  } else {
    $idd ="no";
  } 
  
      return $idd;
      }
   
?>