<?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 = "";
	$vendor_name="";
	
	$queryCondition = "";
	if(!empty($_POST["search"])) {
		foreach($_POST["search"] as $k=>$v){
			if(!empty($v)) {

$queryCases = array("vendor_name");
				if(in_array($k,$queryCases)) {
					if(!empty($queryCondition)) {
						$queryCondition .= " AND ";
						
					} else {
						$queryCondition .= " WHERE ";
					}
				}
				switch($k) {
					
						case "vendor_name":
						$vendor_name = $v;
						$queryCondition .= "vendor_name LIKE '%" . $v . "%'";
						break;
						
						
						
						
						
				}
			}
		}
	}
	if(!empty($queryCondition)) {
	
	$orderby = " ORDER BY vendor_id "; 
	$sql = "SELECT * FROM  vendor_product_master   " . $queryCondition ." " ;
	}else{
	 $sql= "SELECT * FROM  vendor_product_master where vproduct_id = '".$_REQUEST['product_id']."'";
	}
	 $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='view_vendor_stock.php'">BACK </button>

<div class="clearfix"></div>
</div>
</div>
</div>

<div class="row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">View All Vendor Products </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>Vendor Name </th>
<th>Product Name</th>
<th>Details</th>
<th>Unit</th>
<th>Price</th>
<th>Stock</th>
</tr>
</thead>
<tbody>
<?php
					$i=1;
					 foreach($result as $k=>$v) {
						if(is_numeric($k)) {
						
$product_name  = $result[$k]["product_name"];
$product_details = $result[$k]["product_details"];
$unit = $result[$k]["unit"];
$price = $result[$k]["price"];
$stock = $result[$k]["stock"];
$vendor_id = 	$result[$k]["vendor_id"];
						
					?>
<tr>
<td><?php echo $k+1?></td>
<td><?php  
$queryso = "select * from vendor_master where vendor_id = '$vendor_id'";
$resultso = mysqli_query($conn,$queryso);
while($row=mysqli_fetch_array($resultso))
{
echo $vendor_name = $row['vendor_name'];
}

?></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>
</tr>
<?php } }?>
</tbody>
</table>

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