<?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 "; 
	if($login_type_admin=='Super Admin'){
	$sql = "SELECT * FROM  vendor_master   " . $queryCondition ." and entry_by='$user_id'" ;
	}else{
	$sql = "SELECT * FROM  vendor_master   " . $queryCondition ." " ;
	}
	}else{
		if($login_type_admin=='Super Admin'){
	 $sql= "SELECT * FROM  vendor_master";
	 }else{
	 $sql= "SELECT * FROM  vendor_master where entry_by ='$user_id'";
	 }
	}
	 $sql ;
	$href = 'view_finish_product.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>
<button type="button" class="btn btn-danger waves-effect waves-light" onclick="location.href='vendor_master.php'">ADD VENDOR </button>

<div class="clearfix"></div>
</div>
</div>
</div>
<form name="chkForm" id="chkForm" action="view_vendor_details.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>Vendor Name</label>
<input type="text" class="form-control"  name="search[vendor_name]" value="<?php echo $vendor_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_details.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 Vendor </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>Supply Products</th>
<th>Vendor Source</th>
<th>Address</th>
<th>GST NO  </th>
<th>Action</th><th>Action</th>
</tr>
</thead>
<tbody>
<?php
					$i=1;
					 foreach($result as $k=>$v) {
						if(is_numeric($k)) {
						
$vendor_id  = $result[$k]["vendor_id "];
$vendor_name = $result[$k]["vendor_name"];
$email_id = $result[$k]["email_id"];
$contractor_name = $result[$k]["contractor_name"];
$product_wise_details = $result[$k]["product_wise_details"];
$vendor_source = $result[$k]["vendor_source"];
$gst_no=$result[$k]["gst_no"];
$contact_no=$result[$k]["contact_no"];
$vendor_id = $result[$k]["vendor_id"];
$address = $result[$k]["address"];
	
						
					?>
<tr>
<td><?php echo $k+1?></td>
<td><?php echo $result[$k]["vendor_name"]?> </td>
<td><ol><?php  
$queryso = "select * from vendor_product_master where vendor_id = '$vendor_id'";
$resultso = mysqli_query($conn,$queryso);
while($row=mysqli_fetch_array($resultso))
{
$product_name = $row['product_name'];
?><li><?php echo $product_name?></li><?php }?> </ol></td>
<td><?php echo $result[$k]["vendor_source"]?> </td>
<td><?php echo wordwrap($result[$k]["address"],35,"<br>\n");?></td>
<td><?php echo $result[$k]["gst_no"]?></td>
<td><a href="edit_vendor.php?vendor_id=<?php echo $result[$k]["vendor_id"]?>" target="_blank" class="btn btn-primary btn-xs waves-effect waves-light">EDIT</a></td>
                        	<td><a href="delete_vendor.php?vendor_id=<?php echo $result[$k]["vendor_id"]?>" class="btn btn-danger btn-xs waves-effect waves-light">Delete</a></td> 
</tr>
<?php } }?>
</tbody>
</table>

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