<?php
header('Content-Type: application/json');
  include("dbConfig.php");

//115438  799562

    $employ_id=$_GET["employ_id"];
    $date_from=$_GET["date_from"];
    $date_to=$_GET["date_to"];
    $dept_id=0;
    $job_id=0;
   $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;
 // echo '<hr>';

    //-----------------------------------------------------
    $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>';
    
    
    
   // echo '<hr>';
    
    
    //====================================================================
    //echo '<br>';
     //$today_date=date("Y-m-d"); echo $today_date;
     
     $today_date='2024-03-25'; //echo $today_date;
     
  
     //====================================================================
    
    
    //$date_from='2024-03-01';
    //$date_to='2024-03-31';
    
    $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;
 
   //-----------------------Jahez------------------------------------------------------------------
    include("dbConfig_old.php");


}}
   $sql_p1="SELECT * FROM driver_saned_export_excel_tblll where driver_username ='$id_num' AND (dispatch_time_tow between '$date_from' AND '$date_to')AND (subscriber='Jahez APP'OR subscriber='PiK' or subscriber='blu')   ";
   $result_p1 = $conn2->query($sql_p1);
   if ($result_p1->num_rows > 0) {
   while($row_p1 = $result_p1->fetch_assoc()) {
    
    $did_id=$row_p1["did_id"];    //echo  'did_id / '.$did_id; 
  //echo '<br>';
   $jahez_price=round($row_p1["price"],2);  //echo 'Jahez Price / '.$jahez_price;
   
    // echo '<br>';
   $jahez_amount=round($row_p1["amount"],2);  //echo 'Jahez amount / '.$jahez_amount;
   
    $jahez_debit=$row_p1["driver_debit_amount"];   //echo 'jahez_debit / '.$jahez_debit;
    // echo '<br>';
   $jahez_credit=$row_p1["driver_credit_amount"];  // echo 'jahez_credit / '.$jahez_credit;
    //echo '<br>';
   $jahez_bonus=$row_p1["bonus"];  //echo 'jahez_bonus / '.$jahez_bonus;
   $dispatch_time = $row_p1["dispatch_time"];
   
 //echo '<br>';
 $a[] = array(
                            'success' => true,
                            'number_orders_delivered' =>strval($did_id),
                            'jahez_price' => strval($jahez_price),
                            'jahez_amount' => $jahez_amount,
                            'jahez_debit' => $jahez_debit,
                            'jahez_credit' => $jahez_credit,
                            'jahez_bonus' => $jahez_bonus,
                            'report_date' => $dispatch_time,
                            
                        );
                         $response = [
                            'success' => true,
                            'data' => $a,
                        ];
   
   }}else{
    $a = array();
    $response = [
        'success' => true,
        'msg' => "not found",
        'data' => $a,
    ];
}
echo json_encode($response);
   


//echo '<hr>';    









?>















