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

    $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']; 
    $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'];
    $employ_target = $row_e['employ_target'];
    $last_date_commencement = $row_e['last_date_commencement'];
    $basic_salary = $row_e['basic_salary']; 
   
    $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;  
  
     $today_date='2024-03-25';
    //$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);

$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; 

    $target_matloop=$safy_ayam*$employ_target;

include("dbConfig_old.php");

$sql244="SELECT * FROM new_employ_tb where id_num='$id_num'  ";
       $result244 = $conn2->query($sql244);
       if ($result244->num_rows > 0) {
       while($row244 = $result244->fetch_assoc()) { 
        
        $rider_id= $row244['rider_id'];  
           
  }}

}}

?>



 <?php 

  $summ_pp=0;
  $sqlhung1="SELECT * FROM driver_hunger_orders_tbl where rider_id ='$rider_id' AND(report_date between '$date_from' AND '$date_to') AND report_date!='0000-00-00' ORDER BY `driver_hunger_orders_tbl`.`report_date` ASC ";
  $resulthung1 = $conn2->query($sqlhung1);
  if ($resulthung1->num_rows > 0) {
    while($rowhung1 = $resulthung1->fetch_assoc()) {
      $number_orders_delivered=$rowhung1['number_orders_delivered'];
       
        $report_date=$rowhung1['report_date'];
    
                                        $num_orders=$rowhung1["number_orders_delivered"];
                                        if($num_orders>1 && $num_orders<150){$p1=12.5; $summ_pp=$num_orders*$p1; 
                                       //----------------------------------------------
                                        }elseif($num_orders>150 && $num_orders<300){$p2=13.5;
                                        $num_orders2=$num_orders-150; 
                                        $summ_pp11=(($num_orders-$num_orders2)*12.5);
                                        $summ_pp=($num_orders2*$p2)+$summ_pp11; 
                                       
                                        //-------------------------------------------
                                        }elseif($num_orders>300 && $num_orders<400){$p3=15.5;
                                        $num_orders3=$num_orders-300; 
                                        $summ_pp12=(($num_orders-$num_orders3)*13.5);
                                        $summ_pp=($num_orders3*$p3)+$summ_pp12; 
                                       
                                        
                                         //-------------------------------------------
                                        }elseif($num_orders>400 && $num_orders<550){$p4=16.5;
                                        $num_orders4=$num_orders-400; 
                                        $summ_pp13=(($num_orders-$num_orders4)*15.5);
                                        $summ_pp=($num_orders4*$p4)+$summ_pp13; 
                                      
                                        
                                           //-------------------------------------------
                                        }elseif($num_orders>550){$p5=18;
                                        $num_orders5=$num_orders-550; 
                                        $summ_pp14=(($num_orders-$num_orders5)*16.5);
                                        $summ_pp=($num_orders5*$p5)+$summ_pp14; 
                                        
                                        }else{ } 
                          $a[] = array(
                            'success' => true,
                            'number_orders_delivered' => $number_orders_delivered,
                            'summ_pp' => strval($summ_pp),
                            'report_date' => $report_date,
                            
                        );
                        $response = [
                            'success' => true,
                            'data' => $a,
                        ];
}}else{
    $a = array();
    $response = [
        'success' => false,
        'msg' => "not found",
        'data' => $a,
    ];
}
echo json_encode($response);
?>




  

  














