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

$queryCases = array("datepicker","datepicker1","location","billing_GST_no","company_name");
				if(in_array($k,$queryCases)) {
					if(!empty($queryCondition)) {
						$queryCondition .= " AND ";
						
					} else {
						$queryCondition .= " WHERE ";
					}
				}
				switch($k) {
						case "datepicker":
						$datepicker = $v;
						$queryCondition .= "dpinv_date BETWEEN";
						case "datepicker1":
						$datepicker1 = $v;
						$queryCondition .= "'" . $v . "'";
						break;
						
						case "location":
						$location = $v;
						$queryCondition .= "location LIKE '%" . $v . "%'";
						break;
						case "company_name":
						$company_name = $v;
						$queryCondition .= "company_name LIKE '%" . $v . "%'";
						break;
						
						case "billing_GST_no":
						$billing_GST_no = $v;
						$queryCondition .= "billing_GST_no LIKE '%" . $v . "%'";
						break;
						
						
						
						
				}
			}
		}
	}
	if(!empty($queryCondition)) {
	
	$orderby = " ORDER BY formatid "; 
	$sql = "SELECT * FROM  formate_master" . $queryCondition ." " ;
	}else{
	 $sql= "SELECT * FROM  formate_master";
	}
	//echo $sql ;
	$href = 'view_all_formate.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-primary  waves-effect waves-light" onclick="location.href='formate_master.php'">ADD FORMATE</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">FORMATE</h3>
</div>
<div class="panel-body">
<table  id="datatable-buttons" class="table table-striped table-bordered">
<thead>
<tr>
<th>Sr No.</th>
<th>FORMATE</th>
<th>Status</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]["formate_name"]?></td>
<td><?php if($result[$k]["status"]=='1'){?>
<button type="button" class="btn btn-success btn-xs waves-effect waves-light" onclick="location.href='status06.php?status=0&&formatid =<?php echo $result[$k]["formatid "]?>'" style="float:right; margin-right:10px;">Active</button>				
				
				<?php } else { ?>
				<button type="button" class="btn btn-danger btn-xs waves-effect waves-light" onclick="location.href='status06.php?status=1&&formatid =<?php echo $result[$k]["formatid "]?>'" style="float:right; margin-right:10px;">Inactive</button>	
				<?php } ?></td>
</tr>
<?php }}?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include 'footer1a.php';?>
