<?php include("../secure.php"); ?>
<?php //session_start(); ?>
<!DOCTYPE html>
<?php

include('dbConfig.php');

//include('dbConfig.php');

//include('dbconnnn.php');
?>


     <!-- Required meta tags -->
  <meta charset="utf-8">


<html lang="en">
	<head>
	<!--link rel="stylesheet" type="text/css" href="css/fatawa_font.css"/--> 
	<!-- Font CSS -->
        <link rel="stylesheet" type="text/css" href="../../css/fatawa_font.css"/> 
        <!-- Font CSS -->
        
        		<!-- Bootstrap CSS -->
		<!--link rel="stylesheet" href="../../assets/css/bootstrap.rtl.min.css"-->
		

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
		<style>	
		.table {
			width: 100%;
			margin-bottom: 20px;
		}	
		
		.table-striped tbody > tr:nth-child(odd) > td,
		.table-striped tbody > tr:nth-child(odd) > th {
			background-color: #f9f9f9;
		}
		
		@media print{
			#print {
				display:none;
			}
		}
		@media print {
			#PrintButton {
				display: none; 
			}
		}
		
		@page {
			size: auto;   /* auto is the initial value */
			margin: 0;  /* this affects the margin in the printer settings */
		}
	</style>
	
	
  <style>	  
  table {
  border-collapse: collapse;
  width: 100%;
}

th, td {
  text-align: left;
  padding: 8px;
}

tr:nth-child(even) {background-color: #f2f2f2;}
</style>  

       <?php  $lang=$_GET['lang'];  
	
	$link_lang='lang='.$lang;
	
	?>
	

<?php
	if($lang=='ar'){
	?>


         <link rel="stylesheet" href="../../assets/css/bootstrap.rtl.min.css">
   
		<!-- Fontawesome CSS -->
        <link rel="stylesheet" href="../../assets/plugins/fontawesome/css/fontawesome.min.css">
    	<link rel="stylesheet" href="../../assets/plugins/fontawesome/css/all.min.css">

		<!-- Lineawesome CSS -->
        <link rel="stylesheet" href="../../assets/css/line-awesome.min.css">
		<link rel="stylesheet" href="../../assets/css/material.css">
		
		<!-- Fontawesome CSS -->
        <link rel="stylesheet" href="../../assets/css/font-awesome.min.css">
        
        <!-- Select2 CSS -->
		<link rel="stylesheet" href="../../assets/css/select2.min.css">
			<!-- Datetimepicker CSS -->
		<link rel="stylesheet" href="../../assets/css/bootstrap-datetimepicker.min.css">
		
		<!-- Datatable CSS -->
		<link rel="stylesheet" href="../../assets/css/dataTables.bootstrap4.min.css">
		
		<!-- Main CSS -->
        <link rel="stylesheet" href="../../assets/css/style.css">
             
             
             
             
        <?php }else{ ?>
            <link rel="stylesheet" href="../../assets_en/css/bootstrap.min.css">
   
		<!-- Fontawesome CSS -->
        <link rel="stylesheet" href="../../assets_en/plugins/fontawesome/css/fontawesome.min.css">
    	<link rel="stylesheet" href="../../assets_en/plugins/fontawesome/css/all.min.css">

		<!-- Lineawesome CSS -->
        <link rel="stylesheet" href="../../assets_en/css/line-awesome.min.css">
		<link rel="stylesheet" href="../../assets_en/css/material.css">
		
		<!-- Fontawesome CSS -->
        <link rel="stylesheet" href="../../assets_en/css/font-awesome.min.css">
		
		<!-- Datatable CSS -->
		<link rel="stylesheet" href="../../assets_en/css/dataTables.bootstrap4.min.css">
		
		<!-- Main CSS -->
        <link rel="stylesheet" href="../../assets_en/css/style.css">
        

            <?php } ?>
		
		 
     
</head>


	
	   <?php include("../languege_filee_hr.php"); ?> 

    
     
     
<body>
    	<?php 
	$company_id=$_GET['company_id'];
    $step_id=$_GET['step_id'];
    
    $date_from=$_GET['date_from'];
    $date_to=$_GET['date_to']; 

    $check_isset=$_GET['check_isset']; 
     $employ_id_sel = $_GET["employ_id_sel"];
     
      $employ_stat = $_GET["employ_stat"];
    $hr_print_employees = $_GET["hr_print_employees"];
     
     $todaydate = date("Y-m-d");
	?>
	
	
	 <?php include("../hr_permission.php");?>
	
 <?php 
    //================================================== 
     if($lang=='ar'){$main_company_name2='كـــــل الشركات'; 
    }else{ $main_company_name2='All Company';}
     
     if($company_id=='all_company'){
     $main_company_name=$main_company_name2;
         
     }else{
            $sql_m="SELECT * FROM main_company_tbl where company_id='$company_id' ";
          $result_m = $conn->query($sql_m);
           if ($result_m->num_rows > 0) {
          while($row_m = $result_m->fetch_assoc()) {
       if($lang=='ar'){$main_company_name=$row_m['company_name_ar'];}else{$main_company_name=$row_m['company_name_en'];} 
         // $company_name_ar=$row_m['company_name_ar']; 
         // $company_name_en=$row_m['company_name_en']; 
          $company_logo=$row_m['company_logo']; 
            }} 
            
     }
  ?>
  
  
  <?php 

	 
	if(ISSET($_POST['sav_btn'])){
	    
     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; 
     
	}     
     
	?>	
	
	
	 <?php 
                   
                    function getBetweenDates($startDate, $endDate) {
                        $rangArray = [];
                     
                        $startDate = strtotime($startDate);
                        $endDate = strtotime($endDate);
                     
                        for ($currentDate = $startDate; $currentDate <= $endDate; $currentDate += (86400)) {
                            $date = date('Y-m-d', $currentDate);
                            $rangArray[] = $date;
                        }
                     
                        return $rangArray;
                    }
                    $dates = getBetweenDates($date_from, $date_to);
                   //print_r($dates);
                   $ids_dates = join("','",$dates); 
                    ?>




	<!--h2>Marsa Logistics </h2-->
	<br /> <br />
	
	<b style="color:blue;"</b>
	<?php
 date_default_timezone_set("Asia/Riyadh");
 $date=date('Y-m-d H:i:s');
 //echo $date;
 $main_system_id='2222';
 
  $wind=$_GET['wind']; //echo $wind;
	?>
	

<!--center>	<b style="color:blue;float:left;" dir="rtl">Date  :
	 <?php  echo $date; ?>
	 <b>
	 </center-->

	
	
	
	 <?php
	$a=array();
    $sql_comv="SELECT * FROM waseet_company_user_tbl where system_id='$main_system_id' AND deleted='0'AND user_id='".$_SESSION['user_id']."' GROUP BY company_id ";
     $result_comv = $conn->query($sql_comv);
     if ($result_comv->num_rows > 0) {
      while($row_comv = $result_comv->fetch_assoc()) {
      $company_id_all=$row_comv['company_id']; //echo $company_id_all.'<br>';
     array_push($a,$company_id_all);
      // echo $_SESSION['user_id'].'<br>';
        }} 
      // print_r($a);
      ?>
	<?php //echo  $company_id.'<br>';
	//echo $main_system_id;
	 //echo $urow['user_type'];
	  $ids = join("','",$a); 
	  
	//  print_r($a);
	 
		?>  
	
	
	   <?php include("../hr_permission.php");?>
	
	
	<br /><br />
 <br>
  
     <?php if($lang=='ar'){ ?>
	<table dir="rtl"  class="table  table-striped mb-0" clas="table table-striped">
	  <?php }else{ ?>  
	  	<table dir="ltr"  class="table  table-striped mb-0" clas="table table-striped">
	   <?php } ?>
  <thead>

<tr>
<th style=" text-align:center; border:2px solid #6C3;" colspan="23"> <?php echo $Attendance_Report ; ?><small dir="ltr"><?php echo $date_from; ?>/<?php echo $date_to; ?></small></th>
</tr> 

   		<th><?php echo $employee_name; ?></th>
											<th><?php echo $Employee_data; ?></th>
											<th><?php echo $Shift_Details; ?></th>
                                            <th>اجمالي عدد ساعات </th>
                                            <th>الراتب</th>
                                            <th>الفتره</th>
                             <tbody>
			  <?php if(count($dates)==1 & $dates[0]=="1970-01-01"){

                                   }else{ ?>
									  <?php 
				 if(($urow['user_type']=='Top_Manager' or $urow['user_type']=='System_Manager')or($view_hr_attendance_report==1)){
					if($company_id=='all_company'){
                   $sql_cw="SELECT * FROM waseet_company_user_tbl where system_id='2222' and company_id IN ('$ids') AND company_id!='' AND deleted='0'   group by user_id ORDER BY `waseet_company_user_tbl`.`crateddate_time` DESC";
                    }else{
                   $sql_cw="SELECT * FROM waseet_company_user_tbl where system_id='2222' and company_id='$company_id'AND company_id!='' AND deleted='0'   group by user_id ORDER BY `waseet_company_user_tbl`.`crateddate_time` DESC";
                    }
                    
                   }else{
                      $sql_cw="SELECT * FROM waseet_company_user_tbl where system_id='2222' and user_id='".$urow['user_id']."'AND company_id!='' AND deleted='0'  group by user_id ORDER BY `waseet_company_user_tbl`.`crateddate_time` DESC";  
                   }
                    
                   $result_cw = $conn->query($sql_cw);
                   if ($result_cw->num_rows > 0) {
                    while($row_cw = $result_cw->fetch_assoc()) {
                       

                        $sql_taked="SELECT * FROM hr_takeed_hodor_ensraf_tbl where (date_from in ('$ids_dates') or date_to in ('$ids_dates') ) and employ_id='".$row_cw['user_id']."' group by employ_id ";
                        $result_taked = $conn->query($sql_taked);
                         if ($result_taked->num_rows > 0) {
                          while($row_taked = $result_taked->fetch_assoc()) { 
                            $employ_id_taked = $row_taked["employ_id"];
                           //echo $employ_id_taked;
                         
                  
                    $sql_emp="SELECT * FROM hr_employ_tbl where  employ_id='$employ_id_taked' and  employ_stat='active_employ' AND stop='0' AND deleted='0' group by employ_id ORDER BY `hr_employ_tbl`.`employ_name_ar` DESC ";
                          $result_emp = $conn->query($sql_emp);
                           if ($result_emp->num_rows > 0) {
                            while($row_emp = $result_emp->fetch_assoc()) {       
                          if($lang=='ar'){$employ_name=$row_emp['employ_name_ar'];}else{$employ_name=$row_emp['employ_name_en'];}
                          $employee_number_fingerprint = $row_emp["employee_number_fingerprint"]; 
                          $em_id = $row_emp['employ_id'];
                          $em_company = $row_emp['company_id'];
                          $em_dept = $row_emp['dept_id'];
                          $em_job = $row_emp['job_id'];
                          $em_id_num = $row_emp['id_num'];
                          $salary = $row_emp["basic_salary"]+$row_emp["housing_allowance"]+$row_emp["transportation_allowance"]+$row_emp["other_allowances"]+$row_emp["other_allowances_tow"];
                          ?>
                          <?php  }}?>
									  
										<tr>
											<td>
							<h2 class="table-avatar">
							
							<a class="avatar" clas="avatar avatar-xs" href="profile.html">
							<?php
                          $sql_ico="SELECT * FROM hr_employ_attachments_tbl where employ_id='".$em_id."' AND att_name='employ_photo' AND  stop='0' AND deleted='0' ";
                          $result_ico = $conn->query($sql_ico);
                           if ($result_ico->num_rows > 0) {
                            while($row_ico = $result_ico->fetch_assoc()) {
                              $attach_link=$row_ico['attach_link'];  
                            }}
                             ?>  
                               <?php if($attach_link==''){ ?>  
								<img alt="" src="../../assets/img/profiles/avatar-09.jpg">
								<?php }elseif($attach_link!=''){ ?>
								<img alt="" src="../../../Shipping_Clearance_System/jquery/pages/system_maintenance/user_img/<?php echo $attach_link; ?>">
							<?php }else{ ?>
							<img alt="" src="../../assets/img/profiles/avatar-09.jpg">
							<?php } ?>
								
								</a>
							<a href="profile.html"><?php echo $employ_name; ?></a>
						  
							  </h2>
											</td>
											
								<td>
								 <small class="text-muted" style="font-size:12px;">
									 <?php
                                             $sql_cy="SELECT * FROM main_company_tbl where company_id='".$em_company."' ";
                                             $result_cy = $conn->query($sql_cy);
                                             if ($result_cy->num_rows > 0) {
                                             while($row_cy = $result_cy->fetch_assoc()) {
                                                if($lang=='ar'){$company_name=$row_cy['company_name_ar'];}else{$company_name=$row_cy['company_name_en'];} 
                                            echo $company_name;     
                                             }}
                                            // echo $row_emp['company_id'];
                                               ?> 
								<br>	
								   <?php 
					             $sql_c="SELECT * FROM dept_tb where dept_id='".$em_dept."' AND dept_id!='0' ";
                                  $result_c = $conn->query($sql_c);
                                  if ($result_c->num_rows > 0) {
                                   while($row_c = $result_c->fetch_assoc()) {
                                  if($lang=='ar'){$dept_name=$row_c['dept_name'];}else{$city_name2=$row_c['dept_name_en'];} 
                                        echo $dept_name;     
                                    }}
					            ?>-
					         	<?php if($row_cw['user_type']=='Top_Manager' or $row_cw['user_type']=='System_Manager'){ echo $row_cw['user_type'];
					         	}else{ ?>
									      <?php 
									     $sql_jo="SELECT * FROM job_tb where job_id='".$em_job."' AND job_id!='0' ";
                                         $result_jo = $conn->query($sql_jo);
                                         if ($result_jo->num_rows > 0) {
                                         while($row_jo = $result_jo->fetch_assoc()) {
                                          if($lang=='ar'){$job_name=$row_jo['job_name'];}else{$job_name=$row_jo['jop_name_en'];} 
                                          echo $job_name;
                                         //echo $row_jo['job_id'];
                                         
                                         }}else{ echo $no_jop;}
									     ?><?php } ?>
									</small><br>
									<small class="m3"><?php echo $em_id_num; ?></small>
								</td>
								
								
									<td><?php 
                                    $sql_takedd="SELECT * FROM hr_takeed_hodor_ensraf_tbl where (date_from in ('$ids_dates') or date_to in ('$ids_dates') ) and employ_id='".$row_cw['user_id']."' group by shift_id ";
                                    $result_takedd = $conn->query($sql_takedd);
                                     if ($result_takedd->num_rows > 0) {
                                      while($row_takedd = $result_takedd->fetch_assoc()) {

                                        $sql_shift="SELECT * FROM hr_shift_tbl where shift_id='".$row_takedd["shift_id"]."' ";
                                        $result_shift = $conn->query($sql_shift);
                                         if ($result_shift->num_rows > 0) {
                                          while($row_shift = $result_shift->fetch_assoc()) {
                                             
                                        $min_start_time=$row_shift['min_start_time'];
                                        $start_time=$row_shift['start_time'];
                                         $max_start_time=$row_shift['max_start_time'];
                                         
                                          $min_end_time=$row_shift['min_end_time'];
                                          $end_time=$row_shift['end_time'];
                                          $max_end_time=$row_shift['max_end_time'];

                                          $number_hours = $row_shift['number_hours']; 
                                            if($lang=='ar'){$shift_name=$row_shift["shift_name_ar"];}else{$shift_name=$row_shift["shift_name_en"];}
                                            ?>
                                        <small style="font-size:12px;"><?php echo $shift_name;  ?></small><br>
                                        <small style="font-size:12px;"><?php echo $min_start_time; ?>-<?php echo $start_time; ?>-<?php echo $max_start_time; ?></small><br>
									   <small style="font-size:12px;"><?php echo $min_end_time; ?>-<?php echo $end_time; ?>-<?php echo $max_end_time; ?></small><br>
                                       <small style="font-size:12px;"><?php echo $number_hours;  ?></small><br>
                                            <?php
                                          }}
                                      }}
                                    ?></td> 
                                 
                                    <!--td>
                                    <?php 
                                    $sum_add_hours_hodoor = 0;
                                    $sum_add_hours_shift = 0;
                                    $sum_add_hours_khasm = 0;
                                    $sum_khasem_from_salary = 0;
                                    $sql_clac="SELECT * FROM hr_takeed_hodor_ensraf_tbl where (date_from in ('$ids_dates') or date_to in ('$ids_dates') ) and employ_id='".$row_cw['user_id']."'";
                                    $result_calc = $conn->query($sql_clac);
                                     if ($result_calc->num_rows > 0) {
                                      while($row_clac = $result_calc->fetch_assoc()) {
                                        
                                        $sum_add_hours_hodoor+= $row_clac["add_hours_hodoor"];
                                        $sum_add_hours_shift+= $row_clac["add_hours_shift"];
                                        $sum_add_hours_khasm+= $row_clac["add_hours_khasm"];
                                        $sum_khasem_from_salary+= $row_clac["khasem_from_salary"];
                                      }}
                                    ?>  
                                    <?php echo "عدد ساعات الحضور : ".round($sum_add_hours_hodoor,2)."</br>";?>
                                    <?php echo "عدد ساعات الشفت : ".round($sum_add_hours_shift,2)."</br>";?>
                                    <?php echo "ساعات الخصم".round($sum_add_hours_khasm,2)."</br>";?>
                                    <?php echo "الخصم من الراتب : ".round($sum_khasem_from_salary,2)."</br>";?>
                                    </td-->
                                    
                                    <td><small style="font-size:12px;"><?php echo $Total_attendance_hours; ?>/<?php 
                                           echo round($sum_add_hours_hodoor,2);
                                           ?></small><br>
                                           
                                           <small style="font-size:12px;"><?php echo $Total_shift_hours; ?>/<?php
                                           echo $sum_add_hours_shift."</br>";
                                           //echo $num_dayss."/".$number_hours;
                                           ?></small>
                                          
                                           <small style="font-size:12px;" class="text-danger"><?php echo $Total_discount_hours; ?>/<?php
                                           ?>
                                           <?php 
                                           echo round($sum_add_hours_khasm,2);
                                           ?>
                                           </small>

                                           </td>
                                    
                                    
                                     <td>
                                     <small style="font-size:12px;"><?php echo $Total_salary; ?>/
                                    <?php echo round($row_taked["sum_salary"],2); ?>
                                    </small> <br> 
                                    
                                     <small style="font-size:12px;" class="text-danger"><?php echo $Cut_from_salary; ?>
                                     <?php echo round($sum_khasem_from_salary,2); ?>
                                     </small>
                                     
                                     
                                      <br>
                                       <small style="font-size:12px;"><?php echo $remainder_of_the_salary; ?>/
                                           <?php //echo round($row_taked["rest_sallary"],2); ?>
                                           <?php
                                            $rest_sallary = $salary - $sum_khasem_from_salary;
                                            echo round($rest_sallary,2);
                                            ?>
                                            </small>
                                            
                                          </td>
                                    
                                   <td>
                                    <?php
                                   $sql_date="SELECT * FROM hr_takeed_hodor_ensraf_tbl where (date_from in ('$ids_dates') or date_to in ('$ids_dates') ) and employ_id='".$row_cw['user_id']."'";
                                    $result_date = $conn->query($sql_date);
                                     if ($result_date->num_rows > 0) {
                                      while($row_date = $result_date->fetch_assoc()) {
                                       ?>
                          <small style="font-size:12px;" clas="text-danger" dir="ltr">  <?php echo $row_date["date_from"]." - ".$row_date["date_to"]."</br>"; ?>   </small>
                                        
                                    <?php  }}
                                     // print_r($taked_dates);
                                      ?>
                                   </td>
                                        </tr>
                                       
                                        <?php }} ?>
								<?php }} ?>
								
                                <?php }?>
									</tbody>

</table>
       


<br /><br />
<br /><br /><br /><br />
    
</div>


	<center><button id="PrintButton" onclick="PrintPage()">Print</button></center>
</body>
<script type="text/javascript">
	function PrintPage() {
		window.print();
	}
	document.loaded = function(){
		
	}
	window.addEventListener('DOMContentLoaded', (event) => {
   		PrintPage()
		setTimeout(function(){ window.close() },750)
	});
</script>



<!-- Footer -->
		<?php include("../footer.php"); ?>
		<!-- /Footer -->

	 <!-- jQuery -->
        <script src="../../assets/js/jquery-3.6.0.min.js"></script>

        <!-- Feather Icon JS -->
        <script src="../../assets/js/feather.min.js"></script>

        <!-- Slimscroll JS -->
        <script src="../../assets/js/jquery.slimscroll.min.js"></script>

        <!-- Datatable JS -->
        <script src="../../assets/js/jquery.dataTables.min.js"></script>
        <script src="../../assets/js/dataTables.bootstrap4.min.js"></script>
        
        <!-- Bootstrap Core JS -->
        <script src="../../assets/js/bootstrap.bundle.min.js"></script>

        <!-- Custom JS -->
        <script src="../../assets/js/script.js"></script>
      

		 <!-- Theme Settings JS -->
		<script src="../../assets/js/layout.js"></script>
		<script src="../../assets/js/theme-settings.js"></script>
		
		<!-- Select2 JS -->
		<script src="../../assets/js/select2.min.js"></script>
		
		<!-- Datetimepicker JS -->
		<script src="../../assets/js/moment.min.js"></script>
		<script src="../../assets/js/bootstrap-datetimepicker.min.js"></script>
		
		
			 <!-- Theme Settings JS -->
	

		<script src="../../assets/js/greedynav.js"></script>
		<!-- Custom JS -->
		<!--script src="../../assets/js/app.js"></script-->

		<!-- Custom JS -->
		<!--script src="../../assets/js/app.js"></script-->
		
		<script src="../script_lang.js"></script> 
		
		  <!-- Alertify JS -->
		<script src="../../assets/plugins/alertify/alertify.min.js"></script>
		<!--script src="../../assets/plugins/alertify/custom-alertify.min.js"></script-->
        <!-- /Alertify JS -->
		
		
		







</html>


