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


$query_product = "SELECT * FROM product_setup WHERE unit_type_id <> 6 ";
$result_product = mysqli_query($connection,$query_product);

while($row_product=mysqli_fetch_array($result_product))
{
	$product_id = $row_product['product_id'];
	$product_name = $row_product['product_name'];
	
	
	
	$all_product[] = $product_id."-".$product_name;
}

  ?>        
<link rel="stylesheet" href="js1/jquery-ui.css">
  <script src="js1/jquery-2.1.1.min.js"></script>
  <script src="js1/jquery-ui.js"></script>
   <script>
  $(function() {
  
  var availableTags = JSON.parse('<?php echo json_encode($all_product); ?>');
  
    
    $( "#tags" ).autocomplete({
      source: availableTags
    });
  });
  </script>         
        
        <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">
                            	<input type="text" id="tags" class="form-control" name="product_name" placeholder="write product name">
                            </div>
                            
                         	<div class="col-md-3">
                            <select class="form-control" name="supplier">
                            	<option value="">All Supplier</option>
                                <?php  
                                                $query_sup = "select * from supplier_setup WHERE branch_id = '$branch_id_for_header_user'";
                                                $result_techname = mysqli_query($connection,$query_sup);
                                                
                                               
                                                while($row_techname=mysqli_fetch_array($result_techname))
                                                {
                                                
                                                echo "<option value='" . $row_techname['supplier_id'] . "'>" . $row_techname['supplier_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">Product List In Storehouse</h3>
                                </div><!-- /.box-header -->
                                <div class="box-body table-responsive">
                                    <table class="table table-bordered table-striped">
                                        <thead>
                                            <tr>
                                                <th>Product Name</th>
                                                <th>Quantity</th>
                                                <th>Buy Price</th>
                                                <th>Sellig Price</th>
                                                <th>Supplier</th>
                                                <th>Chalan Number</th>
                                                <th>Date</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            
												<?php
												
												
												if(isset($_POST['submit'])) // To check 'submmited or not' by if(isset($_POST['submit'])) 
														{
														
														if (!empty($_POST['product_name'])) {
														$product_name = $_POST['product_name'];
														$product_name = explode("-",$product_name);
														$product_id = $product_name[0];
														
														
														
														$for_product = "product_id = $product_id AND";
														}
														else {
														
														$for_product = "";
														}
														
														
														if (!empty($_POST['supplier'])) {
														$supplier = $_POST['supplier'];
														
														
														
														$for_supplier = "supplier_id = $supplier AND";
														}
														else {
														
														$for_supplier = "";
														}
														
														
														$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>";
															 
															 }
														
														}
														
														else {
															$for_product = "";
															$for_supplier = "";
															$date1 = date("Y-m-d") ;
															$date2 = date("Y-m-d") ;
														}
														
														 $query = "SELECT * FROM store WHERE $for_product $for_supplier date >= '$date1' AND date <= '$date2'  AND branch_id = '$branch_id_for_header_user'";
														
                                                $result = mysqli_query($connection,$query);
                                                 
                                               
												  $i = 0;
                                                while($row=mysqli_fetch_array($result))
                                               {
                                                $i++;
                                                $store_id = $row['store_id'];
                                                $supplier_id = $row['supplier_id'];
												$chalan_no = $row['chalan_no'];
					
					
				
												$result_for_supplier = mysqli_query($connection,"SELECT * FROM supplier_setup WHERE supplier_id  = '$supplier_id'");
		$test_for_supplier = mysqli_fetch_array($result_for_supplier);
				
				$supplier_name=$test_for_supplier['supplier_name'];
												
												$date = $row['date'];
												$date = ($date);
									
	
		$query2 = "SELECT * FROM store_product WHERE chalan_no  = '$chalan_no'";
                                                $result2 = mysqli_query($connection,$query2);
                                                $total_sing_qty = 0 ;
                                                while($test_for_store=mysqli_fetch_array($result2))
                                                {
				
				$product_id=$test_for_store['product_id'];	
												
			
			$quantity = $test_for_store['quantity'];
			//$remain_qty = $test_for_store['remain_qty'];
			//$expire_date = $test_for_store['expire_date'];
			
			$buying_price = $test_for_store['buying_price'];
			
			$selling_price = $test_for_store['selling_price'];
			

$total_sing_qty=$total_sing_qty+ $quantity	;	
				
				
			$result_for_product = mysqli_query($connection,"SELECT product_name, unit_type_id FROM product_setup WHERE product_id  = '$product_id'");
		$test_for_product = mysqli_fetch_array($result_for_product);
				
				$product_name=$test_for_product['product_name'];
				$unit_type_id=$test_for_product['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'];
									
                                                
                                                echo "<tr>";
                                                echo "<td>$product_name" ;
												
													if(!empty($expire_date)){
													echo "<br>Expire: $expire_date Remain: $remain_qty" ;
												}
												echo "</td>";
                                               
                                                echo "<td>$quantity $unit_type_name ";  echo "</td>";
                                                echo "<td>$buying_price</td>";
                                                echo "<td>$selling_price</td>";
                                                echo "<td>$supplier_name</td>";
												 echo "<td>$chalan_no</td>";
                                                echo "<td>$date</td>";
                                              
                                                echo "</tr>";
												}
                                                }
													
														
														
														
														
												
												
												
												
                                                ?>
                                         
                                        </tbody>
                                        <tfoot>
                                            <tr>
                                                <th>Product Name</th>
                                                <th>Quantity</th>
                                                <th>Buy Price</th>
                                                <th>Sellig Price</th>
                                                <th>Supplier</th>
                                                <th>Chalan Number</th>
                                                <th>Date</th>
                                            </tr>
                                        </tfoot>
                                    </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>

  <!-- jQuery 2.0.2 -->
       
        <!-- Bootstrap -->
        <script src="js/bootstrap.min.js" type="text/javascript"></script>
        <!-- DATA TABES SCRIPT -->
        <script src="js/plugins/datatables/jquery.dataTables.js" type="text/javascript"></script>
        <script src="js/plugins/datatables/dataTables.bootstrap.js" type="text/javascript"></script>
        <!-- AdminLTE App -->
        <script src="js/AdminLTE/app.js" type="text/javascript"></script>
        <!-- AdminLTE for demo purposes -->
        <script src="js/AdminLTE/demo.js" type="text/javascript"></script>
        <!-- page script -->
        <script type="text/javascript">
            $(function() {
                $("#example1").dataTable();
                $('#example2').dataTable({
                    "bPaginate": true,
                    "bLengthChange": false,
                    "bFilter": false,
                    "bSort": true,
                    "bInfo": true,
                    "bAutoWidth": false
                });
            });
        </script>
<script>
$(function() {
$( ".datepicker" ).datepicker({ dateFormat: 'dd-mm-yy', changeYear: true });
});

</script>

    </body>
</html>