<?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">
                            	<input type="text" class="form-control" name="product_name" placeholder="write Barcode">
                            </div>
                           
                            <div class="col-md-2">
                            <input type="text" class="form-control datepicker" autocomplete="off" name="date1" placeholder="Starting Date">
                            </div>
                            <div class="col-md-2">
                            <input type="text" class="form-control datepicker" autocomplete="off" name="date2" placeholder="Ending Date">
                            </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">Sold Products List</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>Quantity</th>
                                                <th>Buy Price</th>
                                                <th>Sellig Price</th>
                                                <th>Total Sellig Price</th>
                                                <th>Whole/Retail Customer</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'])) {
														$barcode = $_POST['product_name'];
														
														$for_product = "barcode = '$barcode' AND";
														}
														else {
														
														$for_product = "";
														}
														
														
														if (!empty($_POST['customer_id'])) {
														$customer_id = $_POST['customer_id'];
														
														
														
														$for_supplier = "customer_id = $customer_id 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>";
															 
															 }
														
														
														 $query = "SELECT * FROM sale left join product_setup on sale.product_id = product_setup.product_id WHERE $for_product sale.`date` >= '$date1' AND sale.`date` <= '$date2' AND sale.branch_id = '$branch_id_for_header_user'";
														
                                                $result = mysqli_query($connection,$query);
                                                 
												 $total_sale_price = 0 ;
                                                $i=0;
                                                while($row=mysqli_fetch_array($result))
                                                {
                                                $i++;
                                                $sale_id = $row['sale_id'];
												$product_id = $row['product_id'];
												
												$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'];
												
                                                
                                                $quantity = $row['quantity'];
												
												$buy_price = $row['buy_price'];
												$buy_price_bn_view = ($buy_price);
												
                                                $selling_price = $row['selling_price'];
												
												$single_total_sale_price = $quantity * $selling_price ;
												
												$total_sale_price = $total_sale_price + $single_total_sale_price ;
												
												$single_total_sale_price = ($single_total_sale_price);
												
												
												$quantity_bn_view = ($quantity);
												$selling_price_bn_view = ($selling_price);
												
                                                $invoice_no = $row['invoice_no'];
												
												$result_for_supplier = mysqli_query($connection,"SELECT * FROM sale_taka WHERE invoice_no  = '$invoice_no'");
		$test_for_supplier = mysqli_fetch_array($result_for_supplier);
				
				$customer_id=$test_for_supplier['customer_id'];
				
				$result_customer_name = mysqli_query($connection,"SELECT * FROM customer_setup WHERE customer_id  = '$customer_id'");
		$test_customer_name = mysqli_fetch_array($result_customer_name);
				
				$customer_name=$test_customer_name['customer_name'];
												
												$date = $row['date'];
												$date = date("d-m-Y", strtotime($date));
												$date_bn_view = ($date);
												
                                                
                                                echo "<tr>";
                                                echo "<td>$product_name</td>";
                                                echo "<td>$quantity_bn_view $unit_type_name </td>";
                                                echo "<td>$buy_price_bn_view</td>";
                                                echo "<td>$selling_price_bn_view</td>";
                                                echo "<td>$single_total_sale_price</td>";
                                                echo "<td>$customer_name</td>";
												echo "<td><a href='invoice.php?inv=$invoice_no' target='_blank'> $invoice_no </a></td>";
                                                echo "<td>$date_bn_view</td>";
                                                echo "</tr>";	
														
														}
														
												echo "</tbody>
                                        <tfoot>";
												echo "<tr>";
                                                echo "<td></td>";
                                                echo "<td></td>";
                                                echo "<td></td>";
                                                echo "<th>Total </th>";
                                                 echo "<th>"; echo ($total_sale_price) ;
												 echo " Tala </th>";
                                                echo "<td></td>";
												echo "<td></td>";
                                                echo "<td></td>";
                                                echo "</tr>";
												echo "</tfoot>
                                    </table>";
														
														}
												
												
												
												
												
                                                else {
												$total_sale_price = 0 ;
                                                $query = "SELECT * FROM sale WHERE branch_id = '$branch_id_for_header_user'";
                                                $result = mysqli_query($connection,$query);
                                                 
                                                $i=0;
                                                while($row=mysqli_fetch_array($result))
                                                {
                                                $i++;
                                                $sale_id = $row['sale_id'];
												$product_id = $row['product_id'];
												
												$result_for_product = mysqli_query($connection,"SELECT product_name, unit_type_id FROM product_setup WHERE product_id  = '$product_id' AND branch_id  = '$branch_id_for_header_user'");
		$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'];
												
                                                
                                                $quantity = $row['quantity'];
												$buy_price = $row['buy_price'];
												$buy_price_bn_view = ($buy_price);
												
                                                $selling_price = $row['selling_price'];
												
												$single_total_sale_price = $quantity * $selling_price ;
												
												$total_sale_price = $total_sale_price + $single_total_sale_price ;
												
												$single_total_sale_price = ($single_total_sale_price);
												
												
												
												
												
												$quantity_bn_view = ($quantity);
												$selling_price_bn_view = ($selling_price);
												
                                                $invoice_no = $row['invoice_no'];
												
												$result_for_supplier = mysqli_query($connection,"SELECT * FROM sale_taka WHERE invoice_no  = '$invoice_no' AND branch_id  = '$branch_id_for_header_user'");
		$test_for_supplier = mysqli_fetch_array($result_for_supplier);
				
				$customer_id=$test_for_supplier['customer_id'];
				
				$result_customer_name = mysqli_query($connection,"SELECT * FROM customer_setup WHERE customer_id  = '$customer_id'");
		$test_customer_name = mysqli_fetch_array($result_customer_name);
				
				$customer_name=$test_customer_name['customer_name'];
												
												$date = $row['date'];
												$date = date("d-m-Y", strtotime($date));
												$date_bn_view = ($date);
												
                                                
                                                echo "<tr>";
                                                echo "<td>$product_name</td>";
                                                echo "<td>$quantity_bn_view $unit_type_name </td>";
                                                echo "<td>$buy_price_bn_view</td>";
                                                echo "<td>$selling_price_bn_view</td>";
                                                echo "<td>$single_total_sale_price</td>";
                                                echo "<td>$customer_name</td>";
												echo "<td><a href='invoice.php?inv=$invoice_no' target='_blank'> $invoice_no </a></td>";
                                                echo "<td>$date_bn_view</td>";
                                                echo "</tr>";
                                                }
												echo "</tbody>
                                        <tfoot>";
												echo "<tr>";
                                                echo "<td></td>";
                                                echo "<td></td>";
                                                echo "<td></td>";
                                                echo "<th>Total </th>";
                                                 echo "<th>"; echo ($total_sale_price) ;
												 echo " Taka </th>";
                                                echo "<td></td>";
												echo "<td></td>";
                                                echo "<td></td>";
                                                echo "</tr>";
												echo "</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>

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

    </body>
</html>