<?php include("sass/icon_for_datepicker_and_datatable.php");?>
        <div class="wrapper row-offcanvas row-offcanvas-left">
            <!-- Left side column. contains the logo and sidebar -->
            <?php include("sass/sidebar.php");?>

            <!-- Right side column. Contains the navbar and content of the page -->
               <aside class="right-side">
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                       <?php echo $company_name ; ?>
                        <small>Control panel</small>
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li class="active">Dashboard</li>
                    </ol>
                </section>
                 <section class="content">
                 	  <form role="form"  action="<?php echo "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" method="post">
					 <div class="row">
                        <div class="col-md-4">
                 <!---Main Content--->
                  
                 			<select name="product_id" class="form-control">
 <option value="">All</option>
                                            
												<?php  
                                                $query = "select product_id, product_name from product_setup ";
                                                $result_techname = mysqli_query($connection,$query);
                                                
                                               
                                                while($row_techname=mysqli_fetch_array($result_techname))
                                                {
                                                
                                                echo "<option value='" . $row_techname['product_id'] . "'>" . $row_techname['product_name'] . "</option>";}?> 
                                            
                                            </select>
                 
                 		</div>
						<div class="col-md-3">
                            <input type="text" class="form-control datepicker" autocomplete="off" name="date1" placeholder="Starting Date" required>
                            </div>
                            <div class="col-md-3">
                            <input type="text" class="form-control datepicker" autocomplete="off" name="date2" placeholder="Ending Date" required>
                            </div>
						
						
						
						
						  <div class="col-md-2">
						
						<button type="submit" name="submit" class="btn btn-primary">Submit</button>
						
						
						</div>
                    </div>
                 
                     </form>
                 </section>
				 
				 <br><br>
				 
				 
				  <?php



												if(isset($_POST['submit'])) // To check 'submmited or not' by if(isset($_POST['submit'])) 
														{
																if (!empty($_POST['product_id'])) {
														$product_id = $_POST['product_id'];
														
														$for_product = "Where product_id = '$product_id'";
														}
														else {
														
														$for_product = "";
														}
													$from = $_POST['date1'];
													$to = $_POST['date2'];
														
													
														
														$date1 = $_POST['date1'];
												$date1 = date("Y-m-d", strtotime($date1));
														$date2 = $_POST['date2'];
												$date2 = date("Y-m-d", strtotime($date2));
														
														if (empty($date1)) {
															 $message= "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' 
																  aria-hidden='true'>
																  &times;
															   </button>
															  please write starting date
															</div>";
															 
															 }
															 elseif (empty($date2)) {
															 $message= "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' 
																  aria-hidden='true'>
																  &times;
															   </button>
															    please write ending date
															</div>";
															 
															 }

						 ?>
                                <div class="box-header">
                                    <h3 class="box-title">Product Sales Ratio From <?php echo $from ; ?> To <?php echo $to ; ?></h3>
                                </div><!-- /.box-header -->
                                <div class="box-body">
                                    <table id="example1" class="table table-bordered table-striped">
                                        <thead>
                                            <tr>
                                                <th>Product Name</th>
                                                <th>Sales Ratio</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                           
				 <?php
												
									$result_for_cus_name = mysqli_query($connection,"SELECT SUM(`quantity` * `selling_price`) AS total_selling_price FROM `sale` WHERE `date` >= '$date1' AND `date` <= '$date2'");
		$test_for_cus_name = mysqli_fetch_array($result_for_cus_name);
				
				$total_selling_price=$test_for_cus_name['total_selling_price'];	


		
														
														
														
														 $query = "SELECT product_id, product_name FROM `product_setup` $for_product";
														
                                                $result = mysqli_query($connection,$query);
                                                 
												 
                                                $i=0;
												$total_sale_ratio = 0 ;
                                                while($row_invoice=mysqli_fetch_array($result))
                                                {
                                                $i++;
                                              
										$product_id_row = $row_invoice['product_id'];
										$product_name = $row_invoice['product_name'];
										
									  

	$result_for_cus_name = mysqli_query($connection,"SELECT SUM(`quantity` * `selling_price`) AS single_selling_price FROM `sale` WHERE product_id = '$product_id_row' and `date` >= '$date1' AND `date` <= '$date2'");
		$test_for_cus_name = mysqli_fetch_array($result_for_cus_name);
				
				$single_selling_price=$test_for_cus_name['single_selling_price'];	

                                               
if($single_selling_price<>0){
$sale_ratio =($single_selling_price * 100) / $total_selling_price ;
}
else{
	$sale_ratio = "0";
}
$total_sale_ratio = $total_sale_ratio + $sale_ratio ;
                                  
                                                echo "<tr>";
                                                echo "<td>$product_name</td>";
                                               echo "<td>$sale_ratio %</td>";
                                                echo "</tr>";
												
												
												}
												?>
				 
				 
				    </tbody>
				 
				 
				  <tfoot>
                                            <tr>
                                                <th>Total</th>
                                                <th><?php echo "$total_sale_ratio %" ; ?></th>
                                            </tr>
                                        </tfoot>
				 
				 </table>
				 
				 
														<?php } ?>
				 
                </aside>
                <!-- /.right-side -->
        </div><!-- ./wrapper -->

        <!-- add new calendar event modal -->


        <!-- jQuery 2.0.2 -->
          <?php include("sass/footer_for_datepicker_and_datatable.php");?>

    </body>
</html>