<?php include ("header1.php");
 $querylogin = "select * from  mst_users where user_name = '". $_SESSION["LOGIN_NAME"]."' AND password = '".$_SESSION["EMPLOYEE_PASSWORD"]."'";
$resultlogin = mysqli_query($conn,$querylogin);
while($row=mysqli_fetch_array($resultlogin))
{
$user_name = $row['user_name'];
$user_id = $row['user_id'];
$first_name = $row['first_name'];
 $login_type_admin=$row['login_type'];
}
 

?><?php
	require_once("perpage.php");	
	require_once("dbcontroller.php");
	$db_handle = new DBController();
	
	
	$datepicker = "";
	$datepicker1 = "";
	$item_code = "";
	$billing_GST_no = "";
	$state = "";
	$city = "";
	$product_name="";
	
	$queryCondition = "";
	if(!empty($_POST["search"])) {
		foreach($_POST["search"] as $k=>$v){
			if(!empty($v)) {

$queryCases = array("product_name");
				if(in_array($k,$queryCases)) {
					if(!empty($queryCondition)) {
						$queryCondition .= " AND ";
						
					} else {
						$queryCondition .= " WHERE ";
					}
				}
				switch($k) {
					
						case "product_name":
						$product_name = $v;
						$queryCondition .= "product_name LIKE '%" . $v . "%'";
						break;
						
						
						
						
						
				}
			}
		}
	}
	if(!empty($queryCondition)) {
	
	$orderby = " ORDER BY vendor_id "; 
	$sql = "SELECT * FROM  vendor_products   " . $queryCondition ." " ;
	}else{
	 $sql= "SELECT * FROM  vendor_products";
	}
	 $sql ;
	$href = 'view_vendor_stock.php';					
	
	$perPage = 5000; 
	$page = 1;
	if(isset($_POST['page'])){
		$page = $_POST['page'];
	}
	$start = ($page-1)*$perPage;
	if($start < 0) $start = 0;
		
	$query =  $sql . $orderby .  " limit " . $start . "," . $perPage; 
	$result = $db_handle->runQuery($query);
	
	if(empty($result)) {
		
	$result["perpage"] = showperpage($sql, $perPage, $href);
	}
	else{ 
	$result["perpage"] = showperpage($sql, $perPage, $href); }
	
?>

<div class="content-page">
<div class="content">
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="page-header-title">
<button type="button" class="btn btn-dark waves-effect waves-light" onclick="location.href='index.php'">BACK </button>

<div class="clearfix"></div>
</div>
</div>
</div>
<form name="chkForm" id="chkForm" action="view_vendor_stock.php"  method="post" >
<div class="row">
<div class="col-sm-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Search View All VENDOR </h3>
</div>
<div class="panel-body">
<div class="row">

<div class="col-sm-3 col-xs-12">
<div class="form-group">
<label>Product Name</label>
<input type="text" class="form-control"  name="search[product_name]" value="<?php echo $product_name?>"/>
</div>
</div>


<div class="col-sm-12 col-xs-12">
<div class="m-t-20">
<div class="form-group">
<div>
<button type="submit" class="btn btn-primary waves-effect waves-light"> Submit </button>
<input type="reset" class="btn btn-primary " value="Reset" onClick="window.location='view_vendor_stock.php'">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<div class="row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">View All Stock</h3>
</div>
<div class="panel-body">
<table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>Sr.No.</th>
<th>Product Name</th>
<th>Details</th>
<th>Unit</th>
<th>Price</th>
<th>Stock</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
					$i=1;
					 foreach($result as $k=>$v) {
						if(is_numeric($k)) {
						
$product_name  = $result[$k]["product_name"];
$product_id = $result[$k]["product_id"];
$stock = $result[$k]["stock"];
$qry10 = "select * from vendor_product_master where product_id = '$product_id'";
$re10 = mysqli_query($conn,$qry10);
while($row=mysqli_fetch_array($re10))
{  
$unit = $row["unit"];
$price = $row["price"];
}	
						
					?>
<tr>
<td><?php echo $k+1?></td>
<td><?php echo $product_name?> </td>
<td><?php echo $product_details?></td>
<td><?php echo $unit?> </td>
<td><?php echo $price?></td>
<td><?php echo $stock?></td>
<td><a href="view_vendor_product.php?product_id=<?php echo $result[$k]["product_id"]?>" class="btn btn-primary btn-xs waves-effect waves-light">VIEW</a></td>
</tr>
<?php } }?>
</tbody>
</table>

</div>
</div>
</div>
</div>
</div>
</div>
<?php include 'footer1.php';?>
