<?php require_once('header.php'); ?>

<script type="text/javascript">
	$(document).ready(function() {
	    
	    $('#get_report').on('click', function(){
	        console.log('test');
                var branch_id=$('#branch_id').val();
                var new_client=$('#new_client').val();
                 window.location.replace("user.php?branch_id="+branch_id+"&new_client_id="+new_client);	
                
            });
	});
</script>


<?php if($session_id==1 || $allPermissions['consignor']['read']=="1"){ ?>
<section class="content-header" style="background-color: white;">
    
    <div class="row">
		<div class="col-md-4" style="text-align: left;">
			<h4><i class="fa fa-map-marker"></i> Consigner Details</h4>
		</div>
		<div class="col-md-8" style="text-align: right;"> 
		   <?php if($session_id==1 || $allPermissions['consignor']['create']=="1"){ ?> <a href="user-add.php" class="btn btn-success btn-sm"><i class="fa fa-plus"></i> Create New Consigner</a><?php } ?>
		    <a href="user.php" class="btn btn-warning btn-sm"><i class="fa fa-arrow-left"></i> Back to Consigner List</a>
		</div>
	</div> 
	
	<div class="row">
        <div class='col-md-3 col-sm-6'>
                <label for="to">Select Branch:</label>
                    <select class="form-control select2" name="branch_id" id="branch_id">
                    </select>
        </div>
        <div class="col-md-3">
            <label>Select Client <span style='color:red;'>*</span></label>
            <select name="new_client" id="new_client" class="form-control select2">
					
			</select>
        </div>
        <div class='col-md-3 col-sm-6'>
             <label for="to">Action :</label><br>
             <span id="get_report" name="sd" class="btn btn-sm btn-warning"><i class="fa fa-filter"></i> Filter</span>
             
        </div>
       
    </div>
	
	<br>
	
<!--</section>

<section class="content">-->
	<div class="row">
		<div class="col-md-12">
			<div class="box box-warning" <?=$border_style?>>
				<div class="box-body table-responsive">
					<table id="example1" class="table table-bordered table-striped">
						<thead>
							<tr>
								<th width="30">SL</th>
								<th>Action</th>
								<th>Name</th>
								<th>ID</th>
								<th>Branch Name</th>
								<th>Email</th>
								<th>Phone</th>
								<th>GST Number</th>
								<th width="120px;">Address</th>
								<th>City</th>
								<th>State</th>
								<th>Pincode</th>
								<th>Status</th>
								<th>Password</th>
								<th>Air&nbsp;Calculation</th>
								<th>Surface&nbsp;Calculation</th>
							</tr>
						</thead>
						<tbody>
							<?php
							$condi='';
							if($session['id']!=1 && $session_branch_ids!='0'){
                                $condi.= " and tbl_user.branch_id IN ($session_branch_ids)";
                            }
							if(isset($_GET['branch_id']) && $_GET['branch_id']!='all' && $_GET['branch_id']!=''){
							    $condi.= " and tbl_user.branch_id IN (".$_GET['branch_id'].")";
							}
							
							if($session['id']!=1 && $session_client_ids!='0'){
                                $condi.= " and tbl_user.client_id IN ($session_client_ids)";
                            }
							if(isset($_GET['new_client']) && $_GET['new_client']!='all' && $_GET['new_client']!=''){
							    $condi.= " and tbl_user.client_id IN (".$_GET['new_client'].")";
							}
							
							
							$i=0;
							$statement = $pdo->prepare("SELECT tbl_user.*,
							tbl_branch.name as branch_name
							FROM tbl_user 
							LEFT JOIN tbl_branch ON tbl_branch.id=tbl_user.branch_id
							LEFT JOIN tbl_client_new ON tbl_client_new.id=tbl_user.client_id
							where tbl_user.id!=1 and tbl_user.role='Modicare' $condi and tbl_user.delete_status!=1");
							$statement->execute();
							$result = $statement->fetchAll(PDO::FETCH_ASSOC);
							foreach ($result as $row) {
								$i++;
								?>
								<tr>
								    <td><?php echo $i; ?></td>
								    <td>										
									<?php if($session_id==1 || $allPermissions['consignor']['update']=="1"){ ?>	<a href="user-edit.php?id=<?php echo $row['id']; ?>" class="btn btn-primary btn-xs">Edit</a><?php } ?>
									<?php if($session_id==1 || $allPermissions['consignor']['delete']=="1"){ ?>	<a href="#" class="btn btn-danger btn-xs" data-href="user-delete.php?id=<?php echo $row['id']; ?>" data-toggle="modal" data-target="#confirm-delete">Delete</a>  <?php } ?>
									</td>
									<td><?php echo $row['full_name']; ?></td>
									<td><?php echo $row['id']; ?></td>
									<td><?php echo $row['branch_name']; ?></td>
									<td><?php echo $row['email']; ?></td>
									<td><?php echo $row['phone']; ?></td>
									<td><?php echo $row['gst_no']; ?></td>
									<td><?php echo $row['address']; ?></td>	
									<td><?php echo $row['city']; ?></td>
									<td><?php echo $row['state']; ?></td>
									<td><?php echo $row['pincode']; ?></td>
									<td><?php if($row['status']=='Active'){ echo '<button class="btn btn-xs btn-success">Active</button>'; } else { echo '<button class="btn btn-xs btn-danger">Inactive</button>'; } ?></td>
									<td><?php echo $row['password']; ?></td>
									<td><?php echo $row['air_amt']; ?></td>
									<td><?php echo $row['surface_amt']; ?></td>
									
								</tr>
								<?php
							}
							?>							
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>


</section>


<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Delete Confirmation</h4>
            </div>
            <div class="modal-body">
                <p>Are you sure want to delete this item?</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                <a class="btn btn-danger btn-ok">Delete</a>
            </div>
        </div>
    </div>
</div>
<?php }else{ ?>
<center><h4 style="color:red;">You don't have permission to view this page </h4></center>
<?php } ?>
<script>
  
$(document).ready(function() {
    
    get_branch();
   
    $('#branch_id').on('change', function(){
        
             get_new_client();
    });
    
    
   /* $('#client_id').on('change', function(){
            get_customer();
    });
    $('#filter_table').on('click', function(){
            getData();
    });*/
    
});

function get_branch(){
    $('#branch_id').empty();
    $.ajax({
        url: 'apis/get-drop-down-list.php',
        type: 'post',
        data: {type:'get_branch_dropdown'},
         success:function(response){
            $('#branch_id').empty();
            $('#branch_id').append(response);
            <?php 
            if(isset($_GET['branch_id']) && $_GET['branch_id']!='all' && $_GET['branch_id']!=''){ ?>
			$('#branch_id').val(<?=$_GET['branch_id']?>);
			$('#branch_id').trigger('change');
		<?php	}
            
            ?>
            get_new_client();
        }
    });
}


function get_new_client(){
    $('#new_client').empty();
     
    var branch_id=$('#branch_id').val();
    console.log('New Client Id Change');
    $.ajax({
        url: 'apis/get-drop-down-list.php',
        type: 'post',
        data: {type:'get_new_client_dropdown',branch_id:branch_id},
         success:function(response){
            $('#new_client').empty();
            $('#new_client').append(response);
            
            <?php 
            if(isset($_GET['new_client']) && $_GET['new_client']!='all' && $_GET['new_client']!=''){ ?>
			$('#new_client').val(<?=$_GET['new_client']?>);
			$('#new_client').trigger('change');
		<?php	}
            
            ?>
            
           
        }
    });
}

</script>

<?php require_once('footer.php'); ?>