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

$queryCases = array("customer_name");
				if(in_array($k,$queryCases)) {
					if(!empty($queryCondition)) {
						$queryCondition .= " AND ";
						
					} else {
						$queryCondition .= " WHERE ";
					}
				}
				switch($k) {
					
						case "customer_name":
						$customer_name = $v;
						$queryCondition .= "customer_name LIKE '%" . $v . "%'";
						break;
						
						
						
						
						
				}
			}
		}
	}
	if(!empty($queryCondition)) {
	
	$orderby = " ORDER BY customer_id"; 
	$sql = "SELECT * FROM  mst_customer   " . $queryCondition ." " ;
	}else{
	 $sql= "SELECT * FROM  mst_customer";
	}
	 $sql ;
	$href = 'view_customer.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_customer.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 Customers
					 <button type="button" class="btn btn-dark  waves-effect waves-light" onclick="location.href='new_customer.php'" style="float:right">ADD NEW CUSTOMER </button> 
									</h3></div>
									
									
									
									
                                <div class="panel-body">
                                    <div class="row">
                                      
													
													
                                                   
													
													
													<div class="col-sm-3 col-xs-12"><div class="form-group">
                                                        <label>Customer Name</label>
                                                        <input type="text" class="form-control"  name="search[customer_name]" value="<?php echo $customer_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_customer.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 CUSTOMERS</h3>
              </div>
              <div class="panel-body">
                <table  id="datatable-buttons" class="table table-striped table-bordered">
                  <thead>
                    <tr>
                     
									
									<th>Sr No.</th>
									<th>Customer Name</th>
									<th>Billing Contact Person</th>
									<th>Email ID</th>
									<th>Mobile Number</th>
									<th>Telephone Number</th>
									<th>Billing Address</th>
									<th>Country</th>
									<th>State</th>
									<th>Location</th>
									<th>Pincode</th>
									<th>Website</th>
									<th>GST NO</th>
									<th>PAN NO</th>
									
									<th>Buyer Name</th>
									<th>Buyer State</th>
									<th>Buyer State Code</th>
									<th>Buyer GST No</th>
									<th>Buyer PAN No</th>
									
									
									<th>Buyer Address</th>
									<th>Vendor Code</th>
									
									<th>EDIT</th>
									<th>DELETE</th>
                    </tr>
                  </thead>
                  <tbody>
				  <? 
				 foreach($result as $k=>$v) {
						if(is_numeric($k)) {
													
													?>  <tr>
                    	
                        <td><?php echo $k+1;?></td>
						<td><?php echo $result[$k]["customer_name"]?></td>
					  <td><?php echo $result[$k]["billing_contact_person"]?></td>
						<td><?php echo $result[$k]["email_id"]?></td>
						 <td><?php echo $result[$k]["tel_no"]?></td>
						<td><?php echo $result[$k]["cell_no"]?></td>
					  <td><?php echo $result[$k]["billing_address"]?></td>
						<td><?php echo $result[$k]["country"]?></td>
							<td><?php echo $result[$k]["state"]?></td>
					  <td><?php echo $result[$k]["location"]?></td>
						<td><?php echo $result[$k]["pincode"]?></td>
						
						<td><?php echo $result[$k]["website"]?></td>
						<td><?php echo $result[$k]["billing_GST_no"]?></td>
						<td><?php echo $result[$k]["billing_PAN_no"]?></td>
						
						<td><?php echo $result[$k]["buyer_name"]?></td>
						<td><?php echo $result[$k]["buyer_state"]?></td>
						<td><?php echo $result[$k]["buyer_state_code"]?></td>
						<td><?php echo $result[$k]["buyer_GST_no"]?></td>
						<td><?php echo $result[$k]["buyer_PAN_no"]?></td>
						<td><?php echo $result[$k]["buyer_address"]?></td>
						<td><?php echo $result[$k]["vendor_code"]?></td>
						
						
						
						
                      <td><a href="view_details.php?customer_id=<?php echo $result[$k]["customer_id"]?>" target="_blank" class="btn waves-light" style=" background-color:#044eb3; color: #FFFFFF">EDIT</a></td>
                        	<td><a href="delete_customer.php?customer_id=<?php echo $result[$k]["customer_id"]?>" class="btn waves-light" target="_blank" style=" background-color:RED; color: #FFFFFF">Delete</a></td> 
                    </tr>
                     <?php }}?>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
        
      </div>
    </div>
	<?php include 'footer1.php';?>