<?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">Product Setup</li>
                    </ol>
                </section>
                 <section class="content">
                 <!---Main Content--->
                  <form role="form"  action="<?php echo "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" method="post">
                     <div class="row">
                     
                         <div class="col-md-12">
                   			<div class="col-md-3">
                            <select name="product_id" class="form-control">
                            	<option value="">All Product</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-2">
                            <input type="text" class="form-control datepicker" autocomplete="off" name="date1" placeholder="Starting Date" required>
                            </div>
                            <div class="col-md-2">
                            <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>
                         
                         </div>
                         </form>
                         <br />
<br />
<br />
 <button type="button" class="btn btn-info" onClick="printDiv('printableArea')"><i class="fa fa-print"></i>  Print</button>
                  <div class="row" id="printableArea">
                         
                         
                         <div class="box">
                                <div class="box-header">
                                    <h3 class="box-title">Fast And Slow Item Report</h3>
                                </div><!-- /.box-header -->
                                <div class="box-body table-responsive">
                                    <table id="example1" class="table table-bordered table-striped">
                                        <thead>
                                            <tr>
                                                <th>Product Name</th>
                                                <th>Barcode</th>
                                                <th>Total Sale</th>
                                                <th>Total Quantity</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            
												<?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 = "";
														}
													
														
														
														$date1 = $_POST['date1'];
												$date1 = date("Y-m-d", strtotime($date1));
														$date2 = $_POST['date2'];
												$date2 = date("Y-m-d", strtotime($date2));
														
												
														
														
														 $query = "SELECT * FROM product_setup $for_product";
														
                                                $result = mysqli_query($connection,$query);
                                                 
												 $total_sale_price = 0 ;
                                                $i=0;
                                                while($row=mysqli_fetch_array($result))
                                                {
                                                $i++;
                                                $product_id_to = $row['product_id'];
												$barcode = $row['barcode'];
												$product_name = $row['product_name'];
												
				/*$unit_type_id = $row['unit_type_id'];
												
				$result_for_unit_type = mysqli_query($connection,"SELECT * FROM unit_type WHERE unit_type_id  = '$unit_type_id'");
		$test_for_unit_type = mysqli_fetch_array($result_for_unit_type);
				
				$unit_type_name=$test_for_unit_type['unit_type_name'];*/
												
                                                
												
												$result_for_supplier = mysqli_query($connection,"SELECT COUNT(sale_id) AS total_sale , SUM(quantity) as total_qty FROM sale WHERE product_id = '$product_id_to' and date >= '$date1' AND date <= '$date2' AND branch_id  = '$branch_id_for_header_user'");
		$test_for_supplier = mysqli_fetch_array($result_for_supplier);
				
				$total_sale=$test_for_supplier['total_sale'];
				$total_qty=$test_for_supplier['total_qty'];
												
                                                
                                                echo "<tr>";
                                                echo "<td>$product_name</td>";
                                                echo "<td>$barcode</td>";
                                                echo "<td>$total_sale</td>";
                                                echo "<td>$total_qty</td>";
                                                echo "</tr>";	
														
														}
														
												
                                   echo "</table>";
														
														}
											
                                                ?>
                                         
                                       
                                    <?php
						if (!empty($message))
						echo "$message";
                    ?>
                                </div><!-- /.box-body -->
                            </div>
                         
                         </div>
                     
                     </div>
                 
                 
                 
                 
                 </section>
                </aside>
                <!-- /.right-side -->
        </div><!-- ./wrapper -->

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

 <script>
function EditProduct(id) {
    window.open('edit_store.php?id='+id,'logos','width=500,height=500');}
</script>

<?php include("sass/footer_for_datepicker_and_datatable.php");?>

    </body>
</html>