<?php
include("dbConfig.php");

$peroid_dates = array();
$system_id=$_POST["system_id"];
$company_id_sel=$_POST["company_id_sel"];
$company_id=$_POST["company_id"];
$id=$_POST["id"];
$shift_id = $_POST["shift_id"];
$date_from = $_POST["date_from"];
$date_to = $_POST["date_to"];

$add_hours_hodoor = $_POST["add_hours_hodoor"];
$add_hours_shift = $_POST["add_hours_shift"];
$add_hours_khasm = $_POST["add_hours_khasm"];

$sum_salary = $_POST["sum_salary"];


$add_user_id = $_POST["add_user_id"];

$employee_number_fingerprint = $_POST["employee_number_fingerprint"];

//--------------------------------------------
date_default_timezone_set("Asia/Riyadh");
$createdDate_Time = date("Y-m-d h:i:sa");
$createdDate = date("Y-m-d");
$createdTime = date("h:i:sa"); 
//--------------------------------------------
function GetSeriaother() {	
    $strings = '123456789';	
    $stringLength = strlen($strings);
    $newStrings = '';
    for ($i = 0; $i < 6; $i++) {
        $newStrings .= $strings[rand(0, $stringLength - 1)];
    }
    return $newStrings; 
}


$takeed_id=GetSeriaother();  
//عرض الفتره المختاره من تاريخ الى تاريخ
$beginn = new DateTime($date_from);
$endd = new DateTime($date_to);
$endd->modify('+1 day');
$daterangee = new DatePeriod($beginn, new DateInterval('P1D'), $endd);
foreach($daterangee as $datee){
    //echo $date->format("Y-m-d") . "<br>";
    array_push($peroid_dates,$datee->format("Y-m-d"));
    
}
//print_r($peroid_dates);
//

for($i=0;$i<count($id);$i++){
    $sum_all_attend_min = 0;
    $sum_all_attend_min_h = 0;
    $all_shift_hours = 0;
     $all_shift_hours_h = 0;
     $cal_diff_min_h = 0;
     $salary_minut = 0;
     $khasem_from_salary = 0;
     $cal_diff_min =  0;
     
    $taked_dates = $taked_dates.$_POST["id"][$i];
    $taked_dates = array();
    $sql_taked="SELECT * FROM hr_takeed_hodor_ensraf_tbl where employ_id='".$_POST["id"][$i]."'";
     $result_taked = $conn->query($sql_taked);
           if ($result_taked->num_rows > 0) {
                  while($row_taked = $result_taked->fetch_assoc()) {
                      $begin = new DateTime($row_taked["date_from"]);
                      $end = new DateTime($row_taked["date_to"]);
                      $end->modify('+1 day');
                      $daterange = new DatePeriod($begin, new DateInterval('P1D'), $end);
                      foreach($daterange as $date){
                          //echo $date->format("Y-m-d") . "<br>";
                          array_push($taked_dates,$date->format("Y-m-d"));
                          
                      }
                     
                  }}
                  ?>
   <?php 
   
    $newArr = $newArr.$_POST["id"][$i];
      $newArr = array_diff($peroid_dates, $taked_dates);
    
      usort($newArr, function($a, $b) {
        $dateTimestamp1 = strtotime($a);
        $dateTimestamp2 = strtotime($b);
    
        return $dateTimestamp1 < $dateTimestamp2 ? -1: 1;
    });
    $mindate = $newArr[0];
    $maxdate =$newArr[count($newArr) - 1];
   ?>
     <?php
     $num_dayss = count($newArr);
      // حساب 
                                      if(count($newArr)>0){ 
									   $sql_sh="SELECT * FROM hr_shift_tbl where shift_id='".$_POST["shift_id"][$i]."' AND stop='0' AND deleted='0'  ";
                                        $result_sh = $conn->query($sql_sh);
                                        if ($result_sh->num_rows > 0) {
                                       while($row_sh = $result_sh->fetch_assoc()) {
                                        if($lang=='ar'){
                                         
                                            $shift_name=$row_sh['shift_name_ar'];
                                        }else{
                                           
                                            $shift_name=$row_sh['shift_name_en'];
                                        }
                                     
                                         $min_start_time=$row_sh['min_start_time'];
                                         $start_time=$row_sh['start_time'];
                                         $max_start_time=$row_sh['max_start_time'];
                                         
                                          $min_end_time=$row_sh['min_end_time'];
                                          $end_time=$row_sh['end_time'];
                                          $max_end_time=$row_sh['max_end_time'];

                                          $number_hours = $row_sh['number_hours'];

                                          $sat = $row_sh['sat'];
                                          $sun = $row_sh['sun'];
                                          $mon = $row_sh['mon'];
                                          $tue = $row_sh['tue'];
                                          $we = $row_sh['we'];
                                          $thu = $row_sh['thu'];
                                          $fr = $row_sh['fr'];

                                          $flexible_working = $row_sh['flexible_working'];
                                          $hodoor_ghyab = $row_sh['hodoor_ghyab'];
                                         
                                       }}   
                                           
									  ?>
									
                                    <?php foreach ($newArr as $dates_value) {
                                                $day_num = date('N', strtotime($dates_value));
                                                $day_name = date('l', strtotime($dates_value));
                                                if($flexible_working==1){  ?>
                                                    
                                                    <?php //echo "وقت الحضور".":".$row_add["hodor_time"]."</br>";?>
                                                        <?php //echo "وقت الانصراف".":".$row_add["ensraf_time"]."</br>";?>
                                                        <?php 
                                                    
                                                    $Number_of_attendance_minuts = $number_hours * 60;
                                                    $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                    ?>
                                                    
                                               <?php }elseif($hodoor_ghyab==1){ ?>
                                               
                                                       <?php //echo "وقت الحضور".":".$row_add["hodor_time"]."</br>";?>
                                                        <?php //echo "وقت الانصراف".":".$row_add["ensraf_time"]."</br>";?>
                                                        <?php 
                                                    
                                                    $Number_of_attendance_minuts = $number_hours * 60;
                                                    $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                    ?>
                                                   <?php //echo "----";?>
                                                  
                                               <?php }else{
                                               if($day_name=="Saturday" & $sat==0){ ?>
                                              
                                               <?php  
                                               $Number_of_attendance_minuts = $number_hours * 60;
                                                             $takher = 0;
                                                             $inseraf_befor = 0;
                                                             //echo "off"; 
                                                             $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                              ?>
                                       
                                              <?php }elseif($day_name=="Sunday" & $sun==0){ ?>
                                               <?php  
                                               $Number_of_attendance_minuts = $number_hours * 60;
                                                             $takher = 0;
                                                             $inseraf_befor = 0;
                                                             //echo "off"; 
                                                             $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                              ?>
                                              <?php }elseif($day_name=="Monday" & $mon==0){ ?>
                                              <?php  
                                               $Number_of_attendance_minuts = $number_hours * 60;
                                                             $takher = 0;
                                                             $inseraf_befor = 0;
                                                             //echo "off"; 
                                                             $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                              ?>
                                             <?php  }elseif($day_name=="Tuesday" & $tue==0){ ?>
                                              <?php  
                                               $Number_of_attendance_minuts = $number_hours * 60;
                                                             $takher = 0;
                                                             $inseraf_befor = 0;
                                                            // echo "off"; 
                                                             $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                              ?>
                                             <?php  }elseif($day_name=="Wednesday" & $we==0){ ?>
                                             <?php  
                                               $Number_of_attendance_minuts = $number_hours * 60;
                                                             $takher = 0;
                                                             $inseraf_befor = 0;
                                                             //echo "off"; 
                                                             $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                              ?>
                                             <?php  }elseif($day_name=="Thursday" & $thu==0){ ?>
                                                <?php  
                                               $Number_of_attendance_minuts = $number_hours * 60;
                                                             $takher = 0;
                                                             $inseraf_befor = 0;
                                                            // echo "off"; 
                                                             $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                              ?>
                                             <?php }elseif($day_name=="Friday" & $fr==0){ ?>
                                            <?php  
                                               $Number_of_attendance_minuts = $number_hours * 60;
                                                             $takher = 0;
                                                             $inseraf_befor = 0;
                                                            // echo "off"; 
                                                             $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                              ?>
                                             <?php }else{
                                                ?>
                                                <?php 
                                                $sql_add="SELECT * FROM hr_add_hodor_ensraf_tbl where hodor_ensraf_date='$dates_value' and employee_number_fingerprint='".$_POST["employee_number_fingerprint"][$i]."'";
                                                $result_add = $conn->query($sql_add);
                                                if ($result_add->num_rows > 0) {
                                                while($row_add = $result_add->fetch_assoc()) { ?>
                                                     
                                                        <?php //echo $row_add["hodor_ensraf_stat"];?>
                                                      <?php //echo $row_add["hodor_ensraf_id"]."</br>";?>
                                                    
                                                        <?php 

                          
                                                        $start = strtotime($row_add["hodor_time"]);
                                                        $end = strtotime($row_add["ensraf_time"]);
                                                         
                                                        $Number_of_attendance_minuts = floor(($end - $start) / 60);
                                                        $Number_of_attendance_hours = floor((($end - $start) / 60)/60);
                                                        //echo $Number_of_attendance_minuts."</br>";
                                                        //echo $Number_of_attendance_hours."</br>";

                                                        $datetimee = new DateTime($row_add["hodor_time"]);
                                                        $datetime2e = new DateTime($row_add["ensraf_time"]);
                                                        $intervale = $datetimee->diff($datetime2e); ?>
                                                        
                                                        <?php 
                                                        // الغياب
                                                        if($row_add["hodor_ensraf_stat"]=="ghyab"){
                                                            $Number_of_attendance_minuts = 0;
                                                            $takher = 0;
                                                            $inseraf_befor = 0;
                                                            //echo $Number_of_attendance_minuts; 
                                                            // نهاية الغياب
                                                            //echo "غياب";
                                                            $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                            ?>
                                                       
                                                        <?php }elseif($row_add["hodor_ensraf_stat"]=="exception_ghyab"){
                                                             $Number_of_attendance_minuts = $number_hours * 60;
                                                             $takher = 0;
                                                             $inseraf_befor = 0;
                                                             //echo "إستثناء غياب"; 
                                                             $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                        }elseif($row_add["hodor_ensraf_stat"]=="waiting_employee_response"){
                                                        // مسائلة الغياب
                                                        $Number_of_attendance_minuts = 0;
                                                        $takher = 0;
                                                        $inseraf_befor = 0;
                                                       // echo $Number_of_attendance_minuts; 
                                                       //echo "انتظار موافقة الموظف";
                                                        $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                    }elseif($row_add["hodor_ensraf_stat"]=="Answered_by_the_employee"){
                                                        $Number_of_attendance_minuts = 0;
                                                        $takher = 0;
                                                        $inseraf_befor = 0;
                                                        //echo $Number_of_attendance_minuts; 
                                                        //echo "تم الرد من قبل الموظف";
                                                        $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                    }elseif($row_add["hodor_ensraf_stat"]=="Absence_was_approved"){
                                                        $Number_of_attendance_minuts = $number_hours * 60;
                                                        $takher = 0;
                                                        $inseraf_befor = 0;
                                                        $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                        //echo "تاكيد استثناء الغياب";
                                                    }elseif($row_add["hodor_ensraf_stat"]=="Absence_was_rejected"){
                                                        $Number_of_attendance_minuts = 0;
                                                        $takher = 0;
                                                        $inseraf_befor = 0;
                                                        //echo $Number_of_attendance_minuts; 
                                                        //echo "رفض الاستثناء من الغياب";
                                                        $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                    }elseif($row_add["hodor_ensraf_stat"]=="warning"){
                                                        // تمذار اول مره حضور بدون انصراف او العكس
                                                        $Number_of_attendance_minuts = $number_hours * 60;
                                                        $takher = 0;
                                                        $inseraf_befor = 0;
                                                        //echo "انذار اول مره ";
                                                        $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                       }elseif($row_add["hodor_ensraf_stat"]=="cut_second_time"){
                                                        $Number_of_attendance_minuts = ($number_hours * 60)/2;
                                                        $takher = 0;
                                                        $inseraf_befor = 0;
                                                        $khasemIH = ($number_hours * 60)/2;
                                                        //echo "ثاني مره خصم نص يوم ".$Number_of_attendance_minuts;
                                                        $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                       }elseif($row_add["hodor_ensraf_stat"]=="cut_third_time"){
                                                        $Number_of_attendance_minuts = ($number_hours * 60)/2;
                                                        $takher = 0;
                                                        $inseraf_befor = 0;
                                                        $khasemIH = ($number_hours * 60)/2;
                                                        //echo "ثالث مره خصم نص يوم ".$Number_of_attendance_minuts;
                                                        $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                       }elseif($row_add["hodor_ensraf_stat"]=="referral"){
                                                        $Number_of_attendance_minuts = ($number_hours * 60)/2;
                                                        $takher = 0;
                                                        $inseraf_befor = 0;
                                                        $khasemIH = ($number_hours * 60)/2;
                                                       
                                                        //echo "رابع مره احالة للتحقيق و خصم نص يوم ".$Number_of_attendance_minuts;
                                                        $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                       }elseif($row_add["hodor_ensraf_stat"]=="exception_cut_presence_without_l_or_o"){
                                                            $Number_of_attendance_minuts = $number_hours * 60;
                                                            $takher = 0;
                                                            $inseraf_befor = 0;
                                                            //echo "إستثناء";
                                                            $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                        }elseif($row_add["hodor_ensraf_stat"]=="cut_presence_without_l_or_o"){
                                                            $Number_of_attendance_minuts = ($number_hours * 60)/2;
                                                        $takher = 0;
                                                        $inseraf_befor = 0;
                                                        $khasemIH = ($number_hours * 60)/2;
                                                       
                                                        $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                    }elseif($row_add["hodor_ensraf_stat"]=="approval_req_per"){
                                                           $sql_hr_rq="SELECT * FROM hr_request_permission_tbl where employ_id='".$_POST["id"][$i]."' and request_per_date='$dates_value' and request_per_stat='approval_req_per' ";
                                                              $result_hr_rq = $conn->query($sql_hr_rq);
                                                              if ($result_hr_rq->num_rows > 0) {
                                                                 while($row_hr_rq = $result_hr_rq->fetch_assoc()) {
                                                                    if($row_hr_rq["request_type"]=="Late"){
                                                                        $start1 = strtotime($start_time);
                                                                        $end1 = strtotime($row_add["ensraf_time"]);
                                                                        $Number_of_attendance_minuts = floor(($end1 - $start1) / 60);
                                                                        if($Number_of_attendance_minuts>($number_hours * 60)){
                                                                            $Number_of_attendance_minuts = ($number_hours * 60);
                                                                        }else{
                                                                            $Number_of_attendance_minuts = floor(($end - $start) / 60); 
                                                                        }
                                                                        $inseraf_befor = (strtotime($min_end_time) - strtotime($row_add["ensraf_time"])) / 60;
                                                                        $takher = 0;
                                                                        //echo "موافقة اذن طلب تاخير";
                                                                        $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                                    }elseif($row_hr_rq["request_type"]=="leave_before"){
                                                                        $start = strtotime($row_add["hodor_time"]);
                                                                        $end = strtotime($end_time);
                                                                        $Number_of_attendance_minuts = floor(($end - $start) / 60);
                                                                        if($Number_of_attendance_minuts>($number_hours * 60)){
                                                                            $Number_of_attendance_minuts = ($number_hours * 60);
                                                                        }else{
                                                                            $Number_of_attendance_minuts = floor(($end - $start) / 60); 
                                                                        }
                                                                        $takher = (strtotime($row_add["hodor_time"]) - strtotime($max_start_time)) / 60;
                                                                        $inseraf_befor = 0; ?>
                                                                    <?php  //echo "موافقة اذن طلب انصراف";
                                                                        $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                                    }else{

                                                                    }
                                                                 }
                                                              }
                                                    }elseif($row_add["hodor_ensraf_stat"]=="1"){
                                                        if($row_add["hodor_time"]>$max_start_time && $row_add["ensraf_time"]<$min_end_time){
                                                            //تأخير وانصراف قبل انتهاء الدوام
                                                            $start_s = strtotime($row_add["hodor_time"]);
                                                            $end_s = strtotime($row_add["ensraf_time"]);
                                                            $Number_of_attendance_minuts = floor(($end_s - $start_s) / 60);
                                                            if($Number_of_attendance_minuts>($number_hours * 60)){
                                                                $Number_of_attendance_minuts = ($number_hours * 60);
                                                            }else{
                                                                $Number_of_attendance_minuts = floor(($end - $start) / 60); 
                                                            }
                                                            $takher = (strtotime($row_add["hodor_time"]) - strtotime($max_start_time)) / 60;
                                                            $inseraf_befor = (strtotime($end_time) - strtotime($row_add["ensraf_time"])) / 60;
                                                            //echo "تأخير وانصراف قبل انتهاء الدوام";
                                                            //echo "/  $Number_of_attendance_minuts"."</br>";
                                                            //echo "/  $takher"."</br>";
                                                            //echo "/  $inseraf_befor"."</br>";
                                                            $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                            ?>
                                                           
                                                          <?php 
                                                        }elseif($row_add["hodor_time"]>$max_start_time ){
                                                            //تاخير
                                                            $start_s = strtotime($row_add["hodor_time"]);
                                                            $end_s = strtotime($row_add["ensraf_time"]);
                                                            $Number_of_attendance_minuts = floor(($end_s - $start_s) / 60);
                                                            if($Number_of_attendance_minuts>($number_hours * 60)){
                                                                $Number_of_attendance_minuts = ($number_hours * 60);
                                                            }else{
                                                                $Number_of_attendance_minuts = floor(($end - $start) / 60); 
                                                            }
                                                            $takher = (strtotime($row_add["hodor_time"]) - strtotime($max_start_time)) / 60;
                                                            $inseraf_befor = 0;
                                                            //echo "تاخير";
                                                            //echo "/  $Number_of_attendance_minuts"."</br>";
                                                            //echo "/  $takher"."</br>";
                                                            //echo "/  $inseraf_befor"."</br>";
                                                            $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                            ?>
                                                            
                                                            <?php 
                                                        }elseif($row_add["ensraf_time"]<$min_end_time ){
                                                            //انصراف قبل انتهاء الدوام
                                                            $start_s = strtotime($row_add["hodor_time"]);
                                                            $end_s = strtotime($row_add["ensraf_time"]);
                                                            $Number_of_attendance_minuts = floor(($end_s - $start_s) / 60);
                                                            if($Number_of_attendance_minuts>($number_hours * 60)){
                                                                $Number_of_attendance_minuts = ($number_hours * 60);
                                                            }else{
                                                                $Number_of_attendance_minuts = floor(($end - $start) / 60); 
                                                            }
                                                            $takher = 0;
                                                            $inseraf_befor = (strtotime($end_time) - strtotime($row_add["ensraf_time"])) / 60;
                                                            //echo "انصراف قبل انتهاء الدوام";
                                                            //echo "/  $Number_of_attendance_minuts"."</br>";
                                                            //echo "/  $takher"."</br>";
                                                            //echo "/  $inseraf_befor"."</br>";
                                                            $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                            ?>
                                                         
                                                            <?php
                                                        }else{
                                                            //echo "1 لا يوجد اجراء";
                                                            $start_s = strtotime($row_add["hodor_time"]);
                                                            $end_s = strtotime($row_add["ensraf_time"]);
                                                            $Number_of_attendance_minuts = floor(($end_s - $start_s) / 60);
                                                            if($Number_of_attendance_minuts>($number_hours * 60)){
                                                                $Number_of_attendance_minuts = ($number_hours * 60);
                                                            }else{
                                                                $Number_of_attendance_minuts = floor(($end - $start) / 60); 
                                                            }
                                                            $takher = 0;
                                                            $inseraf_befor = 0;
                                                            //echo "/  $Number_of_attendance_minuts"."</br>";
                                                            //echo "/  $takher"."</br>";
                                                            //echo "/  $inseraf_befor"."</br>";
                                                            $sum_all_attend_min =  $sum_all_attend_min +  $Number_of_attendance_minuts;
                                                            ?>
                                                            
                                                       <?php }

                                                       }else{
                                                        //echo "الحاله".$row_add["hodor_ensraf_stat"]."لا يوجد اجراء";
                                                       } ?>
                                                     
                                                  
                                               <?php }}else{ ?>
                                                <?php ?>
                                              
                                                <?php 
                                                $Number_of_attendance_minuts = 0;
                                                //echo $Number_of_attendance_minuts;
                                                ?>
                                                </td>
                                              <?php  } ?>
                                              <?php  } ?>
                                           <?php  }?>
                                           <?php  }?>
    <?php
    //$sum_all_attend_min_h = $sum_all_attend_min_h.$i; 
     $sum_all_attend_min_h=$sum_all_attend_min/60;
     $sum_all_attend_min_h = $sum_all_attend_min_h;
     

     $all_shift_hours = ($num_dayss * $number_hours)*60;
     $all_shift_hours_h=$all_shift_hours/60;

    
     $cal_diff_min_h = $all_shift_hours_h - $sum_all_attend_min_h;


     
     $cal_diff_min = $all_shift_hours - $sum_all_attend_min;

     $khasem_from_salary = 0;
     if($number_hours==0){
        $khasem_from_salary = 0;
      
    }else{
    $salary_minut = (($_POST["sum_salary"][$i]/30)/$number_hours)/60;
    //echo $salary_minut;
    $khasem_from_salary = $cal_diff_min * $salary_minut;
    
    }

    $rest_sallary = $rest_sallary.$i;
    $rest_sallary = $_POST["sum_salary"][$i] -$khasem_from_salary;
    ?>
     <?php 
     
   
 $sql_w = "UPDATE hr_add_hodor_ensraf_tbl SET takeed_stat='1' WHERE employee_number_fingerprint='".$_POST["employee_number_fingerprint"][$i]."'";
 $run_w = $conn->query($sql_w) or die("Error in saving ".$conn->error);
  
  
// $sql_w2 = "INSERT INTO hr_takeed_hodor_ensraf_tbl (system_id,company_id,employ_id,shift_id,date_from,date_to,add_hours_hodoor,add_hours_shift,add_hours_ensraf,createdDate_Time,add_user_id) VALUES ('$system_id','".$_POST["company_id"][$i]."','".$_POST["id"][$i]."','".$_POST["shift_id"][$i]."','".$_POST["add_hours_hodoor"][$i]."','".$_POST["add_hours_shift"][$i]."','".$_POST["add_hours_ensraf"][$i]."','$date_from','$date_from','$createdDate_Time','$add_user_id') ";
 
$sql_w2 = "INSERT INTO hr_takeed_hodor_ensraf_tbl (system_id,company_id,employ_id,shift_id,date_from,date_to,add_hours_hodoor,add_hours_shift,add_hours_khasm,sum_salary,khasem_from_salary,rest_sallary,createdDate_Time,add_user_id) VALUES ('$system_id','".$_POST["company_id"][$i]."','".$_POST["id"][$i]."','".$_POST["shift_id"][$i]."','$mindate','$maxdate','$sum_all_attend_min_h','$all_shift_hours_h','$cal_diff_min_h','".$_POST["sum_salary"][$i]."','$khasem_from_salary','$rest_sallary','$createdDate_Time','$add_user_id') ";
 $run_w2 = $conn->query($sql_w2) or die("Error in saving ".$conn->error);
 

$browserAgent = $_SERVER['HTTP_USER_AGENT'];
 $user_id =$add_user_id;
 $system_type='hr_marsa_system';
  $proccess_type='takeed_hodoor_ensraf';
  $proccess_details_en='Confirmation of attendance and departure from date'.$_POST["date_from"].' to date'.$_POST["date_to"];
$proccess_details_en='تاكيد كشف الحضور والإنصراف من تاريخ'.$_POST["date_from"].'الى تاريخ'.$_POST["date_to"];
 $table_name='hr_takeed_hodor_ensraf_tbl';   
  date_default_timezone_set("Asia/Riyadh");
  $createdDate = date("Y-m-d h:i:sa");
   $sql2 = "INSERT INTO process_systems_tbl(system_type,user_id,user_ip,proccess_type,proccess_details,proccess_details_en,table_name,proccess_id,proccess_date,process_time,process_datetime,browser)values('$system_type','$add_user_id','$user_ip','$proccess_type','$proccess_details','$proccess_details_en','$table_name','".$_POST["employee_number_fingerprint"][$i]."',NOW(),NOW(),'$createdDate','$browserAgent')";
// $run2 = $conn->query($sql2) or die("Error in saving image".$conn->error);    
 //==================العملايات==================================
 

if ($conn->query($sql2) === TRUE) {
} else {
  echo "Error: " . $sql2 . "<br>" . $conn->error;
}
                                      }
}
echo "1";

?>



