<?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");?>
<?php


$query_product = "SELECT * FROM product_setup";
$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> 
  
  <?php
if(isset($_POST['new_single_sale_submit']))
    {
	
	
$product_name_input = $_POST['product_name'];
$quantity_input = $_POST['quantity'];
$buying_price = $_POST['buying_price'];
$selling_price = $_POST['selling_price'];


$product_name_ex = explode("-",$product_name_input);
	$product_id_ex = $product_name_ex[0];
	$product_name_last = $product_name_ex[1];


if (empty($product_name_input)) {
 $message= "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' 
      aria-hidden='true'>
      &times;
   </button>
  please write product name
</div>";
 
 }

 
 
 else {
 

mysqli_query($connection,"INSERT INTO store_product(product_id, quantity, buying_price, selling_price, status, branch_id) 
VALUES ('$product_id_ex','$quantity_input','$buying_price','$selling_price','1','$branch_id_for_header_user')")
or die(mysqli_error());




}

}
?>
<style type="text/css">
#sub3 {
display: none;
}
#sub4 {
display: none;
margin-top: 5px;
}
</style>
<script language="JavaScript">
function setVisibility(id) {
if(document.getElementById('bt1').value=='Hide'){
document.getElementById('bt1').value = 'Show';
document.getElementById(id).style.display = 'none';
}else{
document.getElementById('bt1').value = 'Hide';
document.getElementById(id).style.display = 'inline';
}
} 
</script>

<script language="JavaScript">
function setPakSale(id) {
if(document.getElementById('bt2').value=='Hide'){
document.getElementById('bt2').value = 'Show';
document.getElementById(id).style.display = 'none';
}else{
document.getElementById('bt2').value = 'Hide';
document.getElementById(id).style.display = 'inline';
}
} 
</script>
 <script type="text/javascript"><!--
function updatesum() {
document.form.sum.value = ((document.form.sum1.value -0) * (document.form.ctw.value -0) );
}
//--></script>
  
            <!-- 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">
                 	 <div class="row">
                        <div class="col-md-8">
                 <!---Main Content--->
                 		
                 			
                            <div class="box box-success">
                                <div class="box-header">
                                    <i class="fa fa-shopping-cart"></i>
                                    <h3 class="box-title">Purchase Product</h3>
                                
                                </div><!-- /.box-header -->
                                <div class="box-body">
                                 <?php
							if (!empty($message))
							{echo "$message";}
						
                        ?> <form role="form" name="form" action="<?php echo "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" method="post">
                             
                                    <div class="row">
                                    	<div class="col-md-4">
                                        <input type="input" class="form-control" name="product_name" id="tags" placeholder="write product name" autofocus required>
                                        </div>
                                        <div class="col-md-2">
                                        	<input class="form-control" type="number" name="quantity" placeholder="quantity" required/>
                                        </div>
                                        <div class="col-md-3">
                                        	<input class="form-control" type="input" name="buying_price" placeholder="Write Buying Price" required/>
                                        </div>
                                        <div class="col-md-3">
                                        	<input class="form-control" type="input" name="selling_price" placeholder="Write Selling Price" required/>
                                        </div>
                                    </div>
                                 
                                    <div class="row">
                                        <div class="col-md-3 pull-right" style="margin-top:5px;">
                                        	<button type="submit" name="new_single_sale_submit" class="btn btn-success">OK</button>
                                        </div>
                                        </div>
                                    </form>
                                    <br />
                                    
                                    <div class="row">
                                    <table class="table table-hover">
 										<tr>
                                        <th>Serial</th>
                                        <th>Name</th>
                                        <th>Buying Price</th>
                                        <th>Total Quantity</th>
                                        <th>Total Price</th>
                                        </tr>
                                        
                                       <?php
                                        
                                        $query = "SELECT * FROM store_product where status = '1' AND branch_id  = '$branch_id_for_header_user'";
                                        $result = mysqli_query($connection,$query);
                                        
										$i=0;
										$grand_total = 0 ;
                                        while($row=mysqli_fetch_array($result))
                                        {
                                        
										 $i++;
                                        $store_product_id = $row['store_product_id'];
                                        $product_id_to = $row['product_id'];
										
										

$result_for_product = mysqli_query($connection,"SELECT * FROM product_setup WHERE product_id  = $product_id_to");
		$test_for_product = mysqli_fetch_array($result_for_product);
				
				$product_name_to=$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'];
										$buying_price = $row['buying_price'];  
										$selling_price = $row['selling_price'];
                                        $total = $quantity * $buying_price ;
										
										$grand_total = $grand_total + $total ;
										
                                        $total_show = ($total);
																		
                                        echo "<tr>
                                                <td>$i</td>
                                                <td>$product_name_to</td>
                                                <td>$buying_price</td>
                                                <td>$quantity</td>";
                                             
                                            echo    "<td>$total_show</td>
                                                                                            
                                                <td>
                                                
                                             <button type='button' class='btn btn-danger' data-toggle='modal' data-target='#myModal$i'><i class='fa fa-minus-square'></i>&nbsp; Remove</button> 
                                                </td>
                                            </tr>";
											echo "<div class='modal fade' id='myModal$i' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>
  <div class='modal-dialog'>
    <div class='modal-content'>
      <div class='modal-header'>
        <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
        <h4 class='modal-title' id='myModalLabel'>be sure</h4>
      </div>
      <div class='modal-body'>
       are you sure want to delete <strong> $product_name_to </strong>?
      </div>
      <div class='modal-footer'>
        <button type='button' class='btn btn-default' data-dismiss='modal'>No</button>
        <a href='delete.php?tbl=store_product&idcol=store_product_id&id=$store_product_id&redirect=purchase_product'><button type='button' class='btn btn-danger'>Yes</button></a>
      </div>
    </div>
  </div>
</div>";
											}	
                                        ?>
                                        <tr>
                                        <th></th>
                                        <th></th>
                                        <th></th>
                                        <th>Total Price</th>
                                        <th><?php echo ($grand_total); ?></th>
                                        </tr>
									</table>
                                    </div>
                                </div><!-- /.box-body -->
                            </div><!-- /.box -->
                     
                 
                 		</div>
                        <div class="col-md-4">
                        	<form role="form" action="purchase_submit.php" method="post">
                            	<div class="box box-info">
                                <div class="box-header">
                                    <i class="fa fa-file-text"></i>
                                    <h3 class="box-title">Purchase Details</h3>
                                </div><!-- /.box-header -->
                                <div class="box-body">
                                
                                	<table style="margin:auto">
<input type="hidden" name="decrese" value="yes" />
<tr><td valign="top">
<label for="text">Hand On</label>	
</td><td>
	<span class="input-wrap">	<input type="input" class="form-control" name="have_to_pay" value="<?php echo ($grand_total); ?>"  required/></span> 
</td></tr>

	<span class="input-wrap">	<input type="hidden" class="form-control" name="transport_name" value="" /></span> 

<tr><td valign="top">
<label for="text">Cash Payment</label>	
</td><td>
	<span class="input-wrap">	<input type="input" class="form-control" name="cash" value="<?php echo ($grand_total); ?>"  id="total" /></span> 
</td></tr>
<tr><td valign="top">
<label for="text">Bank Payment</label>	
</td><td>
	<span class="input-wrap">	<input type="input" class="form-control" name="bank" value="" /></span> 
</td></tr>
	

<tr><td valign="top">
<label for="text">Bank Name</label>	
</td><td>
	<select name="bank_id" class="form-control">
                                            <option value="">Select</option>
												<?php  
                                                $query_bank = "select * from bank_name";
                                                $result_bank = mysqli_query($connection,$query_bank);
                                                
                                               
                                                while($row_bank=mysqli_fetch_array($result_bank))
                                                {
                                                
                                                echo "<option value='" . $row_bank['bank_id'] . "'>" . $row_bank['bank_name'] . "</option>";}?> 
                                            
                                            </select>
</td></tr>

<tr><td valign="top">
<label for="text">Cheque Number</label>	
</td><td>
	<input type="text" class="form-control" name="check_number" id="" placeholder="Enter">
</td></tr>




<tr><td valign="top">
<label for="text">Cheque Date</label>	
</td><td>
	<input type="text" class="form-control datepicker" autocomplete="off" name="check_date" placeholder="Enter">
</td></tr>


<tr><td valign="top">
<label for="text">Date</label>	
</td><td>
	<input type="text" class="form-control datepicker" autocomplete="off" name="date" value="<?php echo date("d-m-Y");?>" placeholder="Enter">
</td></tr>

<tr><td valign="top">
<label for="text">Chalan Number</label>	
</td><td>
	<input type="text" class="form-control" name="chalan_no" required placeholder="Enter">
</td></tr>

<tr><td valign="top">
<label for="text">Supplier</label>	
</td><td>
	<select name="supplier_id" class="form-control">
                                            
												<?php  
                                                $query = "select * from supplier_setup WHERE branch_id  = '$branch_id_for_header_user'";
                                                $result_techname = mysqli_query($connection,$query);
                                                
                                               
                                                while($row_techname=mysqli_fetch_array($result_techname))
                                                {
                                                
                                                echo "<option value='" . $row_techname['supplier_id'] . "'>" . $row_techname['supplier_name'] . "</option>";}?> 
                                            
                                            </select>
</td></tr>


<tr>
<td>
<label for="text"></label>	
</td>
<td>
<input style="width:90px"  type="submit" name="submit" value="Submit" />
</td>
</tr>
	
</table>

                                
                                </div>
                            	
                            
                            </form>
                        
                        
                        </div>
                    </div>
                 
                 
                 </section>
                </aside>
                <!-- /.right-side -->
        </div><!-- ./wrapper -->

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

        <!-- jQuery 2.0.2 -->
          <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>
        
        <script>
$(function() {
$( ".datepicker" ).datepicker({ dateFormat: 'dd-mm-yy', changeYear: true });
});

</script>

    </body>
</html>