<?php include("../toper.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>chart </title>
        
  
  
   <!-- animation CSS -->
        <link rel="stylesheet" href="../../assets/css/animate.css">
        
    </head>
    <body>
        <div id="global-loader" >
            <div class="whirly-loader"> </div>
        </div>
        <!-- Main Wrapper -->
        <div class="main-wrapper">

          <!-- Header -->
    <?php include("../header.php");?>
	 <!-- Header -->

            <div class="page-wrapper cardhead">
                <div class="content container-fluid">
				
					<!-- Page Header -->
					<div class="page-header">
						<div class="row">
							<div class="col-sm-12">
              
								<h3 class="page-title">تقرير المصورفات مقابل الإيرادات<?php //echo $h_shipping_add ?></h3>
								<ul class="breadcrumb">
									<li class="breadcrumb-item"><a href="shipping_listt.php?<?php echo $link_lang; ?>&company_id=<?php echo $company_id; ?>"><?php //echo $view.$space.$h_shipping_listt; ?></a></li>
								</ul>
               
							</div>
							
				</div>
					</div>
					
         
					    <ul class="nav nav-tabs" id="myTab" role="tablist">
					        
					        <li class="nav-item" role="presentation">
										   <a href="#">
										      <button class="nav-link active" id="payment-tab" data-bs-toggle="tab" data-bs-target="#payment" type="button" role="tab" aria-controls="payment" aria-selected="false">
										          المصروفات <?php //echo $add.$space.$Shipping_request; ?>    
										      </button>
										  </a>
										</li>
										
  
									  </ul>
					
					
						  <form clas="cmxform" id="signupForm" method="post" action="#" enctype="multipart/form-data" > 
						 
                          <input type="hidden" name="company_idd" id="company_idd" value="<?php echo $company_id?>" >
							<!-- /add -->
					<div class="card">
						<div class="card-body">
							<div class="row">
							    
         	<div class="alert1" id="messages" style="font-family:'Tajawal',sans-serif;">
         	   <?php if(isset($_SESSION['message'])): ?>
            <div class="alert3 alert3-success">
            <?php echo $_SESSION['message']; ?>
           </div>
            <?php endif; ?>
           <?php unset($_SESSION['message']); ?></div>
						 
					
								<input type="hidden"readonly name="add_user_id" value="<?php echo $urow['user_id']; ?>">
								<input type="hidden" name="user_id_top_manager" id="user_id_top_manager" readonly value="<?php echo $user_id_top_manager; ?>">
							  
							    <input type="hidden" name="lang" id="lang" readonly value="<?php echo $lang; ?>"> 
           	  	                 <input type="hidden" name="messag_add" id="messag_add" readonly value="<?php echo $messag_add; ?>"> 
           	  	                  <input type="hidden" name="link_lang" id="link_lang" readonly value="<?php echo $link_lang; ?>"> 
			
							
									  <?php 
									  $req_num=0;
									    $sql_num="SELECT request_id FROM request_tbl where deleted='0' ";
                                             $result_num = $conn->query($sql_num);
                                             if ($result_num->num_rows > 0) {
                                             while($row_num = $result_num->fetch_assoc()) {
                                        $req_num++;
                                             }
                                            // echo $step_num;
                                             } ?>
									<input type="hidden" class="form-control is-invalid" required="" readonly value="<?php echo $req_num+1; ?>" name="request_num" placeholder="ادخل رقم الطلب">
                          
					<div>
                    </div>
          
                    <div class="col-lg-4 col-sm-6 col-12" clas="col-md-6">				
				<div class="form-group">
				<lable><?php echo $select.$space.$the_companyr; ?></option> </lable>	    
				  
                       	<select clas="select" name="company_id_s" id="company_id_s"class="form-select" required="">
                     <option value=""><?php echo $select.$space.$the_companyr; ?></option>
                       <?php
                       if($company_id=='all_company'){
                        $sql_com1="SELECT * FROM main_company_tbl where deleted='0'AND  company_id IN ('$ids')  ";
                       }else{
                         $sql_com1="SELECT * FROM main_company_tbl where deleted='0'AND company_id='$company_id' ";   
                       }
                        $result_com1 = $conn->query($sql_com1);
                        if ($result_com1->num_rows > 0) {
                        while($row_com1 = $result_com1->fetch_assoc()) {
                          //  echo $row_com1['company_name_ar'];
                          if($lang=='ar'){$company_namee=$row_com1['company_name_ar'];}else{$company_namee=$row_com1['company_name_en'];}    
                          ?>
                    
                   <option value="<?php echo $row_com1['company_id']; ?>" <?php if($_POST["company_id_s"]==$row_com1['company_id']){echo "selected";}?>><?php echo $company_namee; ?> </option>
					<?php }} ?>
				
					</select>
					</div>
					</div>
					
					
					 <div class="col-lg-4 col-sm-6 col-12" clas="col-md-6">				
				<div class="form-group">
				<lable><?php echo "حدد السنه"; ?></option> </lable>	    
				  
                       	<select clas="select" name="yearr" id="yearr"class="form-select" required="">
                     <option value=""><?php echo $select.$space; ?>السنة</option>
                   <option value="2015" <?php if($_POST["yearr"]=="2015"){echo "selected";}?>>2015 </option>
                    <option value="2016" <?php if($_POST["yearr"]=="2016"){echo "selected";}?>>2016 </option>
                     <option value="2017" <?php if($_POST["yearr"]=="2017"){echo "selected";}?>>2017 </option>
                     <option value="2018" <?php if($_POST["yearr"]=="2018"){echo "selected";}?>>2018 </option>
                     <option value="2019" <?php if($_POST["yearr"]=="2019"){echo "selected";}?>>2019 </option>
                     <option value="2020" <?php if($_POST["yearr"]=="2020"){echo "selected";}?>>2020 </option>
                     <option value="2021" <?php if($_POST["yearr"]=="2021"){echo "selected";}?>>2021 </option>
                     <option value="2022" <?php if($_POST["yearr"]=="2022"){echo "selected";}?>>2022 </option>
                     <option value="2023" <?php if($_POST["yearr"]=="2023"){echo "selected";}?>>2023 </option>
                     <option value="2024" <?php if($_POST["yearr"]=="2024"){echo "selected";}?>>2024 </option>
                      <option value="2025" <?php if($_POST["yearr"]=="2025"){echo "selected";}?>>2025 </option>
                       <option value="2026" <?php if($_POST["yearr"]=="2026"){echo "selected";}?>>2026 </option>
                        <option value="2027" <?php if($_POST["yearr"]=="2027"){echo "selected";}?>>2027 </option>
                         <option value="2028" <?php if($_POST["yearr"]=="2028"){echo "selected";}?>>2028 </option>
                          <option value="2029" <?php if($_POST["yearr"]=="2029"){echo "selected";}?>>2029 </option>
                           <option value="2030" <?php if($_POST["yearr"]=="2030"){echo "selected";}?>>2030 </option>
				
				
					</select>
					</div>
					</div>
					
					
					<div class="col-lg-4 col-sm-6 col-12" clas="col-md-6">				
				<div class="form-group">
				<lable><?php echo "حدد النوع"; ?></option> </lable>	    
				  
                       	<select clas="select" name="acc_type" id="acc_type"class="form-select" required="">
                     <option value=""><?php echo $select.$space; ?>النوع</option>
                     <option value="03" <?php if($_POST["acc_type"]=="03"){echo "selected";}?>>مصروفات</option>
                     <option value="04" <?php if($_POST["acc_type"]=="04"){echo "selected";}?>>ايرادات</option>
					</select>
					</div>
					</div>
					
		<div class="col-lg-4 col-sm-6 col-12" clas="col-md-6">				
				<div class="form-group">
               <button type="submit" name="btn_ard"class="btn btn-filters ms-auto">
				<img src="../../assets/img/icons/search-whites.svg" alt="img" style="display: block;"> 
			  </button>
					</div>
					</div>
          
     
    
</head>
<body>
<div class="row">
<?php
$acc_type = $_POST["acc_type"];
$sql_account = "SELECT * FROM accounts_tbl WHERE company_id='" . $_POST["company_id_s"] . "' AND account_number LIKE '$acc_type%'";
$result_account = $conn->query($sql_account);

if ($result_account->num_rows > 0) {
    while ($row_account = $result_account->fetch_assoc()) {
        $monthlyData = array();
?>
        <div class="col-lg-6">
            <div class="card">
                <div class="card-header">
                    <h4 class="card-title">اسم الحساب: <?php echo $row_account["account_name"]; ?> / رقم الحساب: <?php echo $row_account["account_number"]; ?>/</h4>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table mb-0">
                            <thead>
                                <tr>
                                    <th>1</th>
                                    <th>2</th>
                                    <th>3</th>
                                    <th>4</th>
                                    <th>5</th>
                                    <th>6</th>
                                    <th>7</th>
                                    <th>8</th>
                                    <th>9</th>
                                    <th>10</th>
                                    <th>11</th>
                                    <th>12</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <?php
                                    for ($i = 1; $i <= 12; $i++) {
                                        $maden[$i] = 0;
                                        $daen[$i] = 0;
                                        $rased[$i] = 0;

                                        $sql_ddpt5 = "SELECT * FROM daily_restriction_tbl WHERE company_id='" . $_POST["company_id_s"] . "' AND YEAR(document_date)='" . $_POST["yearr"] . "' AND MONTH(document_date)='$i' AND account_number='" . $row_account["account_number"] . "'";
                                        $result_ddpt5 = $conn->query($sql_ddpt5);

                                        if ($result_ddpt5->num_rows > 0) {
                                            while ($row_ddpt5 = $result_ddpt5->fetch_assoc()) {
                                                $maden[$i] += $row_ddpt5["maden"];
                                                $daen[$i] += $row_ddpt5["daen"];
                                            }
                                            $rased[$i] = $maden[$i] - $daen[$i];
                                        }
                                        ?>
                                        <td><?php echo $rased[$i]; ?></td>
                                    <?php } ?>
                                </tr>
                            </tbody>
                        </table>
                        <?php
                        $chartData = array();
                        for ($i = 1; $i <= 12; $i++) {
                            $chartData[] = array("label" => "$i", "y" => $rased[$i]);
                        }
                        ?>
                        <div id="chartContainer<?php echo $row_account["account_number"]; ?>" style="height: 570px; width: 100%;"></div>
                        <script src="https://cdn.canvasjs.com/canvasjs.min.js"></script>
                        <script type="text/javascript">
                            window.onload = function() {
                                var chartData = <?php echo json_encode($chartData); ?>;
                                var chartContainer = 'chartContainer<?php echo $row_account["account_number"]; ?>';
                                var chart = new CanvasJS.Chart(chartContainer, {
                                    theme: "light1",
                                    animationEnabled: false,
                                    title: {
                                        text: ""
                                    },
                                    data: [{
                                        type: "column",
                                        dataPoints: chartData
                                    }]
                                });

                                chart.render();
                            }
                        </script>
                    </div>
                </div>
            </div>
        </div>
        
<?php }} ?>
</div>
</body>
</html>






