<?php
ob_start();
session_start();
include "../inc/config.php";

/*Get Table List*/
if(isset($_POST['type']) && $_POST['type']=='get_exisitng_table'){

        $client_id= $_POST['client_id'];
        $rate_type= $_POST['rate_type'];
        $mode= $_POST['mode'];
        $pod_type= $_POST['pod_type'];
        $from_rate_type= $_POST['from_rate_type'];
        $from_city= $_POST['from_city'];
        $from_zone= $_POST['from_zone'];
        $to_rate_type= $_POST['to_rate_type'];
        $to_city= $_POST['to_city'];
        $to_zone= $_POST['to_zone'];

        $conditions.=" and client_id='".$client_id."'";
        $conditions.=" and rate_type='".$rate_type."'";
        $conditions.=" and mode='".$mode."'";
        $conditions.=" and pod_type='".$pod_type."'";
        $conditions.=" and from_rate_type='".$from_rate_type."'";
        
        if($from_city!=''){
            $conditions.=" and from_city='".$from_city."'";
        }
        if($from_zone!=''){
            $conditions.=" and from_city='".$from_zone."'";
        }
        
        
        $conditions.=" and to_rate_type='".$to_rate_type."'";
        
        if($to_city!=''){
            $conditions.=" and to_city='".$to_city."'";
        }
        if($to_zone!=''){
            $conditions.=" and to_zone='".$to_zone."'";
        }


        $statement = $pdo->prepare("SELECT * FROM `tbl_client_rate_master` where 1=1 $conditions");
        $statement->execute();
        $edit_result = $statement->fetchAll(PDO::FETCH_ASSOC);
       // echo $conditions;
        foreach($edit_result as $edit){
?>
    <tr class="db_delete">
		                               <td>
		                                   <span class="btn btn-danger btn-xs mr-2 remove_db_delete" contenteditable="false" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</span>
		                               </td>
		                               <td>
		                                   <input type="text" name="ids[]" value="<?=$edit['id']?>" style="text-align:center;" class="form-control input-sm idsds" readonly/>
		                               </td>
		                               <td style="width:30%"> 
		                                   <select name="origin_city[]" class="form-control select2">
        										<?php 
            							        $statement = $pdo->prepare("SELECT * FROM `pincode` where 1=1 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($edit['origin_city']==$rows['city']){ echo 'selected';}  ?>> <?=$rows['city']; ?></option>
        									    <?php } ?>
            								</select>
		                               
		                               </td>
		                               <td style="width:30%">
		                                    <select name="destination_city[]" class="form-control select2">
        										<?php 
            							        $statement = $pdo->prepare("SELECT * FROM `pincode` where 1=1 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($edit['destination_city']==$rows['city']){ echo 'selected';}  ?>> <?=$rows['city']; ?></option>
        									    <?php } ?>
            								</select>
		                               
		                               </td>
		                               <td class="slab_rate"><input name="min_weight[]" value="<?=$edit['min_wt']?>" type="text" class="form-control input-sm slab_rate_txt" onkeypress="return isNumberKey(this, event);"/></td>
		                               <td class="slab_rate"><input name="max_weight[]" value="<?=$edit['max_wt']?>" type="text" class="form-control input-sm slab_rate_txt" onkeypress="return isNumberKey(this, event);"/></td>
		                               <td><input type="text" name="per_kg_rate[]" value="<?=$edit['per_kg_rate']?>" class="form-control input-sm" onkeypress="return isNumberKey(this, event);" required/></td>
		                           </tr>
<?php } } ?>
<script>
    $(document).ready(function(){
      $(".select2").select2();
    });
</script>
