<?php

  include("dbConfig.php");
header('Content-Type: text/html; charset=utf-8');


//115438  799562

    $employ_id=0;
    $dept_id=0;
    $job_id=0;
   $sql_e="SELECT * FROM hr_employ_tbl where employ_id='115438' ";
   $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>';
    

   echo '<hr>';

    $employ_target = $row_e['employ_target']; echo 'employ_target / '.$employ_target;
  echo '<hr>';
    $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;
     
    echo '<hr>';
    echo '<br>';
     //====================================================================
    
    
    $date_from=$today_date;
    $date_to=$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>';
    

    
   //-----------------------chfz------------------------------------------------------------------
    include("dbConfig_old.php");

   $sql_p2="SELECT *,SUM(price),COUNT(did_id),SUM(driver_debit_amount),SUM(driver_credit_amount),SUM(bonus) FROM driver_saned_export_excel_tblll where driver_username ='$id_num' AND (dispatch_time_tow between '$date_from' AND '$date_to')AND (subscriber='The Chefz')  GROUP BY driver_username ";
   $result_p2 = $conn2->query($sql_p2);
   if ($result_p2->num_rows > 0) {
   while($row_p2 = $result_p2->fetch_assoc()) {
   $chfz_count_order=$row_p2["COUNT(did_id)"];    echo 'Chefz Count Orders /'.$chfz_count_order.'<br>';
   
   $chefz_debit=$row_p2["SUM(driver_debit_amount)"]; 
   $chefz_credit=$row_p2["SUM(driver_credit_amount)"]; 
   $chefz_bonus=$row_p2["SUM(bonus)"]; 
   
       
   $chfz_price=$row_p2["SUM(price)"];
   $chfz_pricee=$chfz_price/(1.15);
   $chfz_priceee3=round($chfz_pricee,2);   echo 'chfz_after_vat / '.$chfz_priceee3.'<br>';
   
   //echo $row_p2["did_id"];  
    
    echo '<hr>';
   
   }}
   
  //-----------------------------/chfz---------------------------------------------------------
    
   
   //-----------------------Jahez------------------------------------------------------------------
    include("dbConfig_old.php");

   $sql_p1="SELECT *,SUM(price),COUNT(did_id),SUM(driver_debit_amount),SUM(driver_credit_amount),SUM(bonus) 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')  GROUP BY driver_username ";

   $result_p1 = $conn2->query($sql_p1);
   if ($result_p1->num_rows > 0) {
   while($row_p1 = $result_p1->fetch_assoc()) {
   $jahez_count_order=$row_p1["COUNT(did_id)"];    echo 'Jahez Count Orders /'.$jahez_count_order.'<br>';
   
   
       
   $jahez_price=round($row_p1["SUM(price)"],2);  echo 'Jahez Price / '.$jahez_price;
   
    $jahez_debit=$row_p1["SUM(driver_debit_amount)"]; 
   $jahez_credit=$row_p1["SUM(driver_credit_amount)"]; 
   $jahez_bonus=$row_p1["SUM(bonus)"]; 
   
   

   
 //  echo $row_p1["did_id"];  
    
    echo '<hr>';
   
   }}
   
  //-----------------------------/Jahez---------------------------------------------------------
    
 $sum_all_debit=round($chefz_debit+$jahez_debit,2);  echo 'sum_all_debit / '.$sum_all_debit.'<br>'; 
 
  $sum_all_credit=round($chefz_credit+$jahez_credit,2);  echo 'sum_all_credit / '.$sum_all_credit.'<br>';    
  
  $sum_all_bouns=round($chefz_bonus+$jahez_bonus,2);  echo 'sum_all_bouns / '.$sum_all_bouns.'<br>';    
    

echo '<hr>';    
  //-----------------------------hunger---------------------------------------------------------

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'];  
           
           

$sum_raseed_all=0;
$summ_pp=0;
 $sqlhung="SELECT *,SUM(number_orders_delivered) FROM driver_hunger_orders_tbl where rider_id ='".$row244['rider_id']."' AND(report_date between '$date_from' AND '$date_to') AND report_date!='0000-00-00' GROUP BY rider_id";
  $resulthung = $conn2->query($sqlhung);
  if ($resulthung->num_rows > 0) {
    while($rowhung = $resulthung->fetch_assoc()) {

      $num_orders=$rowhung["SUM(number_orders_delivered)"];
      if($num_orders>=1 && $num_orders<=150){$p1=12; $summ_pp=$num_orders*$p1;
     //----------------------------------------------
      }elseif($num_orders>150 && $num_orders<=300){$p2=13;
      $num_orders2=$num_orders; 
      $summ_pp=($num_orders2*$p2); 
    
      
      //-------------------------------------------
      }elseif($num_orders>300 && $num_orders<=400){$p3=15;
      $num_orders3=$num_orders; 
     // $summ_pp12=(($num_orders-$num_orders3)*13.5);
      $summ_pp=($num_orders3*$p3); 
    
      
       //-------------------------------------------
      }elseif($num_orders>400 && $num_orders<=550){$p4=16;
      $num_orders4=$num_orders; 
     // $summ_pp13=(($num_orders-$num_orders4)*15.5);
      $summ_pp=($num_orders4*$p4); 
    
      
         //-------------------------------------------
      }elseif($num_orders>550){$p5=16;
      $num_orders5=$num_orders; 
      //$summ_pp14=(($num_orders-$num_orders5)*16.5);
      $summ_pp=($num_orders5*$p5); 
     
      
      
     // }elseif($num_orders>300 && $num_orders<400){$p1=15.5;   
     // }elseif($num_orders>400 && $num_orders<550){$p1=16.5;   
     // }elseif($num_orders>550){$p1=18;   
      }else{ } 
 
    }}

  }}
  //-----------------------------/hunger---------------------------------------------------------

  echo' Hunger num order / '. $num_orders.'<br>';  
  
  echo' Hunger  price / '. $summ_pp.'<br>';  
   
    
    
    
}}


    echo '<hr>';


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

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


  echo '<hr>';


$count_all_orders=round($chfz_count_order+$jahez_count_order+$num_orders,2);   echo  'count_all_orders /'.$count_all_orders.'<br>';



 $sum_all_target=round($chfz_priceee3+$jahez_price+$summ_pp+$sum_target_package,2);  echo'sum_all_target / '.$sum_all_target.'<br>';
echo'target_matloop / '.$target_matloop.'<br>';

     
     
     
    $nesba_mohkak=round($sum_all_target/$target_matloop*100,2);
    
    echo 'nesba_mohkak / '.$nesba_mohkak;

  echo '<hr>';  echo '<br>';
  
  
  echo '<hr>';
  
  if($nesba_mohkak>100){$takeem_delivery='good';}else{$takeem_delivery='bad';}
  

 echo 'takeem_delivery  /  '.$takeem_delivery;


?>











<?php 
 echo '<hr>';  echo '<br>';
  echo '<br>';  echo '<br>';
echo '==================Month=========================================';


// $month_date=date("m");  echo $month_date;
// $year_date=date("Y");  echo $month_date;
 
  $month_date='03';  echo $month_date;
  
  $year_date='2024';
  
 
 echo '<hr>';

 echo $id_num;
 
 
 echo '<br>';

   //-----------------------chfz_month------------------------------------------------------------------
    include("dbConfig_old.php");

   $sql_p2_mo="SELECT *,SUM(price),COUNT(did_id),SUM(driver_debit_amount),SUM(driver_credit_amount),SUM(bonus) FROM driver_saned_export_excel_tblll where driver_username ='$id_num' AND MONTH(dispatch_time_tow)='$month_date' AND YEAR(dispatch_time_tow)='$year_date'AND (subscriber='The Chefz')  GROUP BY driver_username ";
   $result_p2_mo = $conn2->query($sql_p2_mo);
   if ($result_p2_mo->num_rows > 0) {
   while($row_p2_mo = $result_p2_mo->fetch_assoc()) {
   $chfz_count_order=$row_p2_mo["COUNT(did_id)"];   // echo 'Chefz Count Orders /'.$chfz_count_order.'<br>';
   
   $chefz_debit=$row_p2_mo["SUM(driver_debit_amount)"]; 
   $chefz_credit=$row_p2_mo["SUM(driver_credit_amount)"]; 
   $chefz_bonus=$row_p2_mo["SUM(bonus)"]; 
   
       
   $chfz_price_mo=$row_p2_mo["SUM(price)"];   // echo '$chfz_price_mo  / '.$chfz_price_mo;   echo '<br>';
   $chfz_pricee_mo=$chfz_price_mo/(1.15);
 
   $chfz_priceee3_mo=round($chfz_pricee_mo,2);   echo 'chfz_after_vat / '.$chfz_priceee3_mo.'<br>';
   
    
    echo '<hr>';
   
   }}
   
  //-----------------------------/chfz_month---------------------------------------------------------


   //-----------------------Jahez_mo------------------------------------------------------------------

   $sql_p1_mo="SELECT *,SUM(price),COUNT(did_id),SUM(driver_debit_amount),SUM(driver_credit_amount),SUM(bonus) FROM driver_saned_export_excel_tblll where driver_username ='$id_num' AND  MONTH(dispatch_time_tow)='$month_date' AND YEAR(dispatch_time_tow)='$year_date' AND (subscriber='Jahez APP'OR subscriber='PiK' or subscriber='blu')  GROUP BY driver_username ";

   $result_p1_mo = $conn2->query($sql_p1_mo);
   if ($result_p1_mo->num_rows > 0) {
   while($row_p1_mo = $result_p1_mo->fetch_assoc()) {
   $jahez_count_order=$row_p1_mo["COUNT(did_id)"];   // echo 'Jahez Count Orders /'.$jahez_count_order.'<br>';
   
   
       
   $jahez_price_mo=round($row_p1_mo["SUM(price)"],2);  echo 'Jahez Price / '.$jahez_price_mo;
   
    $jahez_debit=$row_p1_mo["SUM(driver_debit_amount)"]; 
   $jahez_credit=$row_p1_mo["SUM(driver_credit_amount)"]; 
   $jahez_bonus=$row_p1_mo["SUM(bonus)"]; 

  
    
    echo '<hr>';
   
   }}
   
  //-----------------------------/Jahez_mo---------------------------------------------------------


  //-----------------------------/Hunger_mo---------------------------------------------------------

  echo 'rider_id / '.$rider_id;

$sum_raseed_all=0;
$summ_pp_month=0;
 $sqlhung="SELECT *,SUM(number_orders_delivered) FROM driver_hunger_orders_tbl where rider_id ='$rider_id' AND MONTH(report_date)='$month_date'AND YEAR(report_date)='$year_date' AND report_date!='0000-00-00' GROUP BY rider_id";
  $resulthung = $conn2->query($sqlhung);
  if ($resulthung->num_rows > 0) {
    while($rowhung = $resulthung->fetch_assoc()) {

      $num_orders_month=$rowhung["SUM(number_orders_delivered)"];
      if($num_orders_month>=1 && $num_orders_month<=150){$p1=12; $summ_pp_month=$num_orders_month*$p1;
     //----------------------------------------------
      }elseif($num_orders_month>150 && $num_orders_month<=300){$p2=13;
      $num_orders2=$num_orders_month; 
      $summ_pp_month=($num_orders2*$p2); 
    
      
      //-------------------------------------------
      }elseif($num_orders_month>300 && $num_orders_month<=400){$p3=15;
      $num_orders3=$num_orders_month; 
     // $summ_pp12=(($num_orders-$num_orders3)*13.5);
      $summ_pp_month=($num_orders3*$p3); 
    
      
       //-------------------------------------------
      }elseif($num_orders_month>400 && $num_orders_month<=550){$p4=16;
      $num_orders4=$num_orders_month; 
     // $summ_pp13=(($num_orders-$num_orders4)*15.5);
      $summ_pp_month=($num_orders4*$p4); 
    
      
         //-------------------------------------------
      }elseif($num_orders_month>550){$p5=16;
      $num_orders5=$num_orders_month; 
      //$summ_pp14=(($num_orders-$num_orders5)*16.5);
      $summ_pp_month=($num_orders5*$p5); 
     
      
      
     // }elseif($num_orders>300 && $num_orders<400){$p1=15.5;   
     // }elseif($num_orders>400 && $num_orders<550){$p1=16.5;   
     // }elseif($num_orders>550){$p1=18;   
      }else{ } 
 
    }}

   //echo' Hunger num order MONTH / '. $num_orders_month.'<br>';  
  
  echo' Hunger  price MONTH / '. $summ_pp_month.'<br>';  
  //-----------------------------/Hunger_mo---------------------------------------------------------

  echo '<hr>';  echo '<br>';

  //-----------------------------pakagetarget_month---------------------------------------------------------
  
  
  // 2501359091
  
  // 465516
  
  
        $sum_target_package_month=0;
        $sum_count_package_month=0;
	  $sql_ch2="SELECT * FROM package_target_tbl where id_num='$id_num' AND month='$month_date'AND year='$year_date' AND deleted='0'";
      $result_ch2 = $conn2->query($sql_ch2);
      if ($result_ch2->num_rows > 0) {
      while($row_ch2 = $result_ch2->fetch_assoc()) {
     
     //echo $sum_count_package_month='sum_count_package/ '.$sum_count_package;
     
     
    $sum_target_package_month=round($row_ch2['sum_target_package'],2).'<br>';  
    
  
    
                                   
   }}
   
    echo 'sum_target_package Month / '.$sum_target_package_month;

  //-----------------------------/pakagetarget_month---------------------------------------------------------


  echo '<hr>';





  echo '<br>';  echo '<br>';
  
  
  $summ_all_price_all_project_month=round($chfz_priceee3_mo+$jahez_price_mo+$summ_pp_month+$sum_target_package_month,2); 
  

  
  
 // $target_matloop_month=
   
   
  ?>
  
  
  <?php 
 
// تحديد التاريخ
$year = date('Y');
$month = date('n'); // الشهر الحالي


$year =$year_date;
$month = $month_date; 

// العدادات
$friday_count = 0;
$other_day_count = 0;

// حلقة لحساب أيام الجمعة وأيام الأخرى في الشهر
for ($day = 1; $day <= cal_days_in_month(CAL_GREGORIAN, $month, $year); $day++) {
    // إنشاء تاريخ ليتم فحصه
    $date = strtotime("$year-$month-$day");
    
    // التحقق مما إذا كان اليوم يوم جمعة أم لا
    if (date('l', $date) === 'Friday') {
        $friday_count++;
    } else {
        $other_day_count++;
    }
}

// طباعة النتائج
echo "عدد أيام الجمعة في شهر $month هو: $friday_count<br>";
echo "عدد الأيام بدون يوم الجمعة في شهر $month هو: $other_day_count<br>";
?>

   
  
 <?php 
   
  $target_matloop_month=$other_day_count*$employ_target;
  
   $nesba_mohkak_month=round($summ_all_price_all_project_month/$target_matloop_month*100,2);
 
 ?>
 
  <hr>
  <br>
   <b style="color:blue;"><?php  echo 'nesba_mohkak_month  / '.$nesba_mohkak_month; ?></b>
  <hr><br>
  
  
  <b style="color:red;"><?php  echo 'summ_all_price_all_project_month  / '.$summ_all_price_all_project_month; ?></b>
  
  <?php
  
   echo '<br>';  echo '<br>'; echo '<br>'; echo '<br>';
  
  
  
    
?>















