<?php require_once('header.php'); ?>
<?php if($session_id==1 || $allPermissions['generate_zone']['read']=="1"){ ?>
<section class="content" style="background-color: white;">
    <div class="row">
		<div class="col-md-4" style="text-align: left;">
			<h4><i class="fa fa-map-marker"></i> Generated Zone Details</h4>
		</div>
		<div class="col-md-8" style="text-align: right;"> 
		<?php if($session_id==1 || $allPermissions['generate_zone']['create']=="1"){ ?>
		    <a href="generate-zones.php" class="btn btn-success btn-sm"><i class="fa fa-plus"></i> Create New Zone</a>
		    <?php }?>
		    <a href="index.php" class="btn btn-warning btn-sm"><i class="fa fa-arrow-left"></i> Back to Home</a>
		</div>
		<div class="clearfix"></div>
		
		<div class="col-sm-3 col-md-3 col-lg-3" style="margin-top: 2px;">
			<label for="" class="control-label">Select Client <span style='color:red;'>*</span></label>
			<div class="" style="margin-top: 2px;">
				 <select name="client_id" id="client_id" class="form-control select2">
				     <option value="">All</option>
					<?php 
			        $statement = $pdo->prepare("SELECT * FROM `tbl_client_new` WHERE status=1");
					$statement->execute();
					$result = $statement->fetchAll(PDO::FETCH_ASSOC);
					 foreach($result as $rows) { ?>
						<option value="<?=$rows['id'];?>" <?php if($partner_count && $partner_result[0]['client_id']==$rows['id']){ echo "selected";} ?>>
							<?=$rows['name']; ?>
						</option>
				    <?php } ?>
				</select>
			</div>
       </div>
        <div class="col-sm-2 col-md-2 col-lg-2" style="margin-top: 2px;">
          <label for="" class="control-label">Select Zone <span style='color:red;'>*</span></label>
			<div class="" style="margin-top: 2px;">
				 <select name="zone_id" id="zone_id" class="form-control select2">
				     <option value="">All</option>
					<?php 
			        $statement = $pdo->prepare("SELECT * FROM `tbl_zone` WHERE status=1");
					$statement->execute();
					$result = $statement->fetchAll(PDO::FETCH_ASSOC);
					 foreach($result as $rows) { ?>
						<option value="<?=$rows['id'];?>" <?php if($partner_count && $partner_result[0]['zone_id']==$rows['id']){ echo "selected";} ?>>
							<?=$rows['zone_name']; ?>
						</option>
				    <?php } ?>
				</select>
			</div>
       </div>
       <div class="col-sm-3 col-md-3 col-lg-3" style="margin-top: 2px;">
          <label for="" class="control-label">Select From City <span style='color:red;'>*</span></label>
			<div class="" style="margin-top: 2px;">
				 <select name="from_city" id="from_city" class="form-control select2">
				     <option value="">All</option>
					<?php 
			        $statement = $pdo->prepare("SELECT city FROM `pincode` GROUP by city ORDER by city ASC");
					$statement->execute();
					$result = $statement->fetchAll(PDO::FETCH_ASSOC);
					 foreach($result as $rows) { ?>
						<option value="<?=$rows['city'];?>" <?php if($partner_count && $partner_result[0]['from_city']==$rows['city']){ echo "selected";} ?>>
							<?=$rows['city']; ?>
						</option>
				    <?php } ?>
				</select>
			</div>
       </div>
       <div class="col-sm-3 col-md-3 col-lg-3" style="margin-top: 2px;">
          <label for="" class="control-label">Select Destination State <span style='color:red;'>*</span></label>
			<div class="" style="margin-top: 2px;">
				 <select name="destination_state" id="destination_state" class="form-control select2">
				     <option value="">All</option>
					<?php 
			        $statement = $pdo->prepare("SELECT state FROM `pincode` GROUP by state ORDER by state ASC");
					$statement->execute();
					$result = $statement->fetchAll(PDO::FETCH_ASSOC);
					 foreach($result as $rows) { ?>
						<option value="<?=$rows['state'];?>" <?php if($partner_count && $partner_result[0]['destination_state']==$rows['state']){ echo "selected";} ?>>
							<?=$rows['state']; ?>
						</option>
				    <?php } ?>
				</select>
			</div>
       </div>
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
	</div> 
    
	<div class="row">
		<div class="col-md-12">
			<div>
			<div class="box-body table-responsive">
					<table id="employee-grid"  class="table table-bordered table-striped">
						<thead>
							<tr>
								<th width="30">S.No</th>
								<th>Actions</th>
								<th>Client Name </th>
								<th>From City</th>
								<th>Zone</th>
								<th>Destination State</th>
								<th>Destination Cities</th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
		</div>
	</div>
</section>
<?php }?>
<?php require_once('footer.php'); ?>

<script type="text/javascript">
$(document).ready(function(){
    getData();
});
$("#destination_state,#client_id,#zone_id,#from_city").change(function() {
	    getData();
});


function getData(){
    var client_id =$('#client_id').val();
    var zone_id =$('#zone_id').val();
    var from_city =$('#from_city').val();
    var destination_state =$('#destination_state').val();
    
	var dataTable = $('#employee-grid').DataTable( {
		"processing": true,
		"serverSide": true,    
        "destroy":true,
        "ajax":{
			url : "data-tables/generated-zone-data-table.php",
			type: "post", 
			data:{client_id:client_id,zone_id:zone_id,from_city:from_city,destination_state:destination_state},
			error: function(){ 
				$(".employee-grid-error").html("");
				$("#employee-grid").append('<tbody class="employee-grid-error"><tr><th colspan="10" style="text-align;center;">No data found in the server</th></tr></tbody>');
				$("#employee-grid_processing").css("display","none");
			}
		}
	} );
    }
</script>