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

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
		<meta name="description" content="POS - Bootstrap Admin Template">
		<meta name="keywords" content="admin, estimates, bootstrap, business, corporate, creative, management, minimal, modern,  html5, responsive">
		<meta name="author" content="Dreamguys - Bootstrap Admin Template">
		<meta name="robots" content="noindex, nofollow">
		<title>Marsa Logistic</title>

                <style>
@font-face {
    font-family: 'DroidSansArabic';
    src: url('../../font/DroidSansArabic.ttf');
}
body * {
    font-family: "DroidSansArabic", sans-serif ;
}
    </style>
		<?php 
	$lang=$_GET['lang'];  
    $link_lang='lang='.$lang;
    $company_id=$_GET['company_id']; 
    $main_system_id='2222';
	?> 
	
	 <?php include("../languege_filee_hr.php");?>
	 
 <?php include("../hr_permission.php");?>
	
		<!-- Favicon -->
        <link rel="shortcut icon" type="image/x-icon" href="../../assets/img/favicon.png">
        
        <link rel="stylesheet" href="../../assets/plugins/alertify/alertify.min.css">
        
		<?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">
		
		<!-- 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 } ?>
		
		 
	<body>
	<!-- Main Wrapper -->
        <div class="main-wrapper">
		
			<!-- Toper -->
            <?php include("../toper.php"); ?>
			<!-- /Toper -->
			
			<!-- header -->
            <?php include("../header.php");?>
			
			<!-- /header -->
			
			<div class="page-wrapper">
				<div class="content">
				    
				<!-- Page Header -->
					<div class="page-header">
						<div class="row">
							<div class="col-sm-12">
								<h3 class="page-title">التقرير الشامل </h3>
								<ul class="breadcrumb">
									<li class="breadcrumb-item"><a href="#">عرض العمليات الحسابية</a></li>
								</ul>
							</div>
						</div>
					</div>   
					<div class="card">
						<div class="card-body">
							
							<ul class="nav nav-tabs nav-tabs-solid nav-justified">
                            <li class="nav-item"><a class="nav-link a " id="" href="hr_Comprehensive_reports1.php?lang=<?php echo $lang;?>&company_id=<?php echo $company_id;?>" ><?php echo "الشهر الحالي";?></a></li>
                            <li class="nav-item"><a class="nav-link a active"  id="" href="hr_Comprehensive_reportsM.php?lang=<?php echo $lang;?>&company_id=<?php echo $company_id;?>" ><?php echo "ملخص";?></a></li>
                            </ul>
						</div>
					</div>
                    <div class="row">
    <form action="hr_Comprehensive_reportsM.php?lang=<?php echo $lang;?>&company_id=<?php echo $company_id;?>" method="post">
        <div class="col-sm-6" style="display: inline-block;width: 30%;">
            <input type="date" name="date_from" class="form-control">
        </div>
        <div class="col-sm-6" style="display: inline-block;width:30%;">
            <input type="date" name="date_to" class="form-control">
        </div>
        <input type="submit" value="البحث">
    </form>
</div>
                   <?php 
                   echo $_POST["date_from"].'  '.$_POST["date_to"];
                   ?>
      </div>      
					<div class="row" style="margin-right:20px;">
    <!-- ============================================================ -->
					     <?php
                    include("dbConfig.php");
                    $today = date('Y-m-d');
                    $month = date('m');
                    $year = date("Y");
                    $dateMonthYearArr = array();
                         // التعريفات الرئيسيه
                         if(isset($_POST["date_from"])& isset($_POST["date_to"])){

                         if($company_id=='all_company'){
                            $sql_def="SELECT * FROM def_tb where type='hr' and company_id IN ('$ids') order by createdDate,creatime";
                        }else{
                            $sql_def="SELECT * FROM def_tb where type='hr' and company_id='$company_id' order by createdDate,creatime";
                        }
                        
                              $result_def = $conn->query($sql_def);
                              if ($result_def->num_rows > 0) {
                                while($row_def = $result_def->fetch_assoc()) {
                                    $dfid = $row_def["id"];
                        ?>
                        <?php 
                        // التعريفات الفرعيه
                        $amount_ar1 = $amount_ar.$row_def["id"];
                        $amount_ar1 = array();
                        $op_ar1 = $op_ar.$row_def["id"];
                        $op_ar1 = array();
                        $ac_name_ar1 = $ac_name_ar.$row_def["id"];
                        $ac_name_ar1 = array();


                        $sql_sub_def="SELECT * FROM sub_def_tb where def_id='".$row_def["id"]."'";
                              $result_sub_def = $conn->query($sql_sub_def);
                              if ($result_sub_def->num_rows > 0) {
                                while($row_sub_def = $result_sub_def->fetch_assoc()) {
                                    $account_num = $row_sub_def["account_number"];
                                
                                    $sql_account="SELECT * FROM accounts_tbl where account_number='".$row_sub_def["account_number"]."' and company_id='".$row_def["company_id"]."'";
                              $result_account = $conn->query($sql_account);
                              if ($result_account->num_rows > 0) {
                                while($row_account = $result_account->fetch_assoc()) {
                                    $account_name = $row_account["account_name"];
                                    array_push($ac_name_ar1,$account_name);
                                }}
                                    // الاستعلام عن الرصيد------------------------------
                                      $madenn = 0;
                                      $daenn = 0;
                                      $raseedd = 0;
                                      
                                                        $sql_daily="SELECT * FROM daily_restriction_tbl where (document_date between '".$_POST["date_from"]."' and '".$_POST["date_to"]."') and company_id='".$row_def["company_id"]."' and  account_number LIKE '$account_num%'";
                                                        $result_daily = $conn->query($sql_daily);
                                                        if ($result_daily->num_rows > 0) {
                                                        while($row_daily = $result_daily->fetch_assoc()) {
                                                            $daenn += $row_daily["daen"];
                                                            $madenn += $row_daily["maden"];
                                                            
                                                         }}
                                                         $raseedd = $daenn - $madenn;
                                    // نهاية الاستعلام عن االرصيد----------------------
                                    if($row_sub_def["request"]=="sum_maden"){
                                        array_push($amount_ar1,$madenn);
                                    }elseif($row_sub_def["request"]=="sum_daen"){
                                        array_push($amount_ar1,$daenn);
                                    }elseif($row_sub_def["request"]=="raseed"){
                                        if($raseedd<0){
                                            $raseedd = $raseedd * -1;
                                            array_push($amount_ar1,$raseedd);
                                        }else{
                                            array_push($amount_ar1,$raseedd);
                                        }
                                        
                                    }else{

                                    }
                                   
                                    array_push($op_ar1,$row_sub_def["operator"]);

                                }}
                               
                        ?>
                        <?php 
                        $d.$row_def["id"] = $amount_ar1[0];
                        for($i=0;$i<count($amount_ar1);$i++){
   
                            if($op_ar1[$i]=="sum"){
                                if($amount_ar1[$i+1]!=""){
                                    $d.$row_def["id"] = ($d.$row_def["id"] + $amount_ar1[$i+1]);
                                }else{
                                    //$d = $amount_ar[$i] + 0;
                                }
                            
                            }elseif($op_ar1[$i]=="sub"){
                                if($amount_ar1[$i+1]!=""){
                                    $d.$row_def["id"] = ($d.$row_def["id"] - $amount_ar1[$i+1]);
                                }else{
                                    //$d = $amount_ar[$i] - 0;
                                }
                            }elseif($op_ar1[$i]=="multi"){
                                if($amount_ar1[$i+1]!=""){
                                    $d.$row_def["id"] = ($d.$row_def["id"] * $amount_ar1[$i+1]);
                                }else{
                                    //$d = $amount_ar[$i] - 0;
                                }
                            }elseif($op_ar1[$i]=="divid"){
                                if($amount_ar1[$i+1]!=""){
                                    $d.$row_def["id"] = ($d.$row_def["id"] / $amount_ar1[$i+1]);
                                }else{
                                    //$d = $amount_ar[$i] - 0;
                                }
                            }else{
                            
                            }
                            //echo $amount_ar1[$i+1];
                            }
                        ?>
                        <div class="col-lg-3 col-sm-6 col-12">
							<div class="card dash-widget">
							    <div class="card-body">
								 <div class="dash-widgetimg">
									<span><img src="../../assets/img/icons/dash1.svg" alt="img"></span>
								 </div>
								 <div class="dash-widgetcontent">
								      <h5>
                                      <?php echo  $dfid."</br>";?>
                                        <?php echo  $row_def["company_id"]."</br>";?>
                                        <?php echo  $account_num."</br>";?>
                                        <?php echo $row_def["def_name"];?>
                                    </h5> 
                                      <h6 style="color: #1d6abe;"> 
                                      <?php 
                                      echo "(";
                        for($i=0;$i<count($amount_ar1);$i++){
                            if($op_ar1[$i]=="sum"){
                                $op = " + ";
                            }elseif($op_ar1[$i]=="sub"){
                                $op = " - ";
                            }elseif($op_ar1[$i]=="multi"){
                                $op = " * ";
                            }elseif($op_ar1[$i]=="divid"){
                                $op = " / ";
                            }else{
                                $op = "";
                            }
                            echo $ac_name_ar1[$i].$op;
                            }
                            echo ")";
                        ?>
                                      </h6> 
                                    <h6>
                                    <?php 
                        for($i=0;$i<count($amount_ar1);$i++){
                            echo $ac_name_ar1[$i]." : ".round($amount_ar1[$i])."</br>";
                            }
                        ?>
                                    </h6> 
                                    <h5><?php echo "الناتج"." : ";?><a href="" class="counters" data-count="<?php echo round($d.$row_def["id"]);?>"><?php echo round($d.$row_def["id"]);?></a></h5>  
                        </br>
                                        
                                </div>
							</div>
						</div>
						</div>
				
                       <?php }} }?>
                     </div>
			</div>
		</div>
		
		
		<!-- ============================================================ -->
		
				</div>
			</div>
		</div>
		
		
	<?php include("../setting.php"); ?>
	    <!-- /sitting -->

	<!-- Footer -->
		<?php include("../footer.php"); ?>
		<!-- /Footer -->
		<!-- jQuery -->
		
			 <!-- 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>

		<!-- 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 -->
		
		
		
	<script>
        $(document).ready(function(){
            $("#type").change(function(){
        var id = $('#type').find(":selected").val();
       
        $.ajax({
          type : "POST",
          url : "Show_accounting_period.php",
          data: {
            id:id,		
          },
          success : function(data){
            $("#show_period").html(data);
          }
      });
            });
        });
    </script>
    
    
    
	</body>
</html>







