<?php
header('Content-Type: application/json');
  include("dbConfig.php");
    $employ_id=$_GET["employ_id"];
    $dept_id=0;
    $job_id=0;
     $date_from=$_GET["date_from"];
    $date_to=$_GET["date_to"];
    $month = date("m", strtotime($date_from));
$year = date("Y", strtotime($date_from));
   $sql_e="SELECT * FROM hr_employ_tbl where employ_id='".$employ_id."' ";
   $result_e = $conn->query($sql_e);
   if ($result_e->num_rows > 0) {
   while($row_e = $result_e->fetch_assoc()) {
      
  $employ_id=$row_e['employ_id'];
  $dept_id=$row_e['dept_id'];
  $job_id=$row_e['job_id'];
  
  
      if($lang=='ar'){$employ_name=$row_e['employ_name_ar'];}else{$employ_name=$row_e['employ_name_en'];} 

    $employ_name_ar = $row_e['employ_name_ar']; //echo 'employ_name / '.$employ_name_ar.'<br>';
    $employ_name_en = $row_e['employ_name_en'];
    $employ_email = $row_e['employ_email'];
    $mobile_number = $row_e['mobile_number'];
    
    $id_num = $row_e['id_num'];  //echo 'id_num / '.$id_num.'<br>';
    
    $employ_target = $row_e['employ_target']; //echo 'employ_target / '.$employ_target;

    $last_date_commencement = $row_e['last_date_commencement']; //echo 'last_date_commencement / '. $last_date_commencement;


    //-----------------------------------------------------
    $basic_salary = $row_e['basic_salary']; 
    
    //echo 'basic_salary / '.$basic_salary.'<br>';
    
    $housing_allowance = $row_e['housing_allowance'];
    $transportation_allowance = $row_e['transportation_allowance'];
    $other_allowances = $row_e['other_allowances'];
    $other_allowances_tow = $row_e['other_allowances_tow'];

    $sum_sal_employ=$basic_salary+$housing_allowance+$transportation_allowance+$other_allowances+$other_allowances_tow;
    
    $allowances=$housing_allowance+$transportation_allowance+$other_allowances+$other_allowances_tow;  
    
    
    //echo 'allowances / '. $allowances.'<br>';
    
    //echo 'sum_sal_employ / '.$sum_sal_employ.'<br>';
 
     //$today_date=date("Y-m-d"); //echo $today_date;
     
     $today_date='2024-03-25'; //echo $today_date;
 
     //====================================================================
    
    
   
    
    $holiday_dates = array();

	    
     date_default_timezone_set("Asia/Riyadh");
     $dd1=strtotime($date_from);
     $dd2=strtotime($date_to);
   $datediff = $dd2 - $dd1;
   $add_ayam=round($datediff / (60 * 60 * 24)+1);
   //echo $add_ayam ;
   
   
  
   
   
$from_date = new DateTime($date_from);
$to_date = new DateTime($date_to);
$i = 0;
for ($date = $from_date; $date <= $to_date; $date->modify('+1 day')) {
    $d = $date->format('l');
  if($d=="Friday"){
      $i++;
  }
}
 // صافي عدد الأيام
 
   $safy_ayam=$add_ayam-$i; 
	
    
    //echo 'add_ayammmmmmmmmmmmmm / '.$add_ayam.'<br>';
    
    //echo 'safy_ayammmmmmmmmmmm / '.$safy_ayam.'<br>';
    
    
    $target_matloop=$safy_ayam*$employ_target;
    
    
    //====================================================================
    //echo '<hr>';
    

    
}}

  //-----------------------------pakagetarget---------------------------------------------------------
  
  
  // 2501359091
  
  // 465516
   include("dbConfig_old.php");
  
        $sum_target_package=0;
        $sum_count_package=0;
	  $sql_ch2="SELECT * FROM package_target_tbl where id_num='$id_num' AND month='$month'AND year='$year' AND deleted='0'";
      $result_ch2 = $conn2->query($sql_ch2);
      if ($result_ch2->num_rows > 0) {
      while($row_ch2 = $result_ch2->fetch_assoc()) {
        $sum_target_package=round($row_ch2['sum_target_package'],2);  
     
     $target_noon=round($row_ch2['target_noon'],2);  //echo 'target_noon / '.$target_noon;

    $target_alod=round($row_ch2['target_alod'],2);  //echo $target_alod='target_alod/ '.$target_alod;
    
   
     $target_we=round($row_ch2['target_we'],2);  //echo $target_we='target_we/ '.$target_we;
    
    $target_shipping=round($row_ch2['target_shipping'],2);   //echo $target_shipping='target_shipping/ '.$target_shipping;
     
     
      $a[] = array(
                            'success' => true,
                            'target_noon' => strval($target_noon),
                            'target_alod' => strval($target_alod),
                            'target_we' => strval($target_we),
                            'target_shipping' => strval($target_shipping),
                            'sum_target_package' => strval($sum_target_package),
                            
                            
                        );
                         $response = [
                            'success' => true,
                            'data' => $a,
                        ];
    
                                   
   }}else{
         $response = [
                            'success' => false,
                            'data' => [],
                        ];
   }
   
    //echo 'sum_target_package / '.$sum_target_package;

  //-----------------------------/pakagetarget---------------------------------------------------------

echo json_encode($response);
?>






















