<?php include "header.php"; ?>

<?php if($session_id==1 || $allPermissions['pod_entry']['read']=="1"){ ?>


<section class="content-header">
	<div class="content-header-left">
		<h1>View POD</h1>
	</div>
	 
	<div class="row " >  
	    <div class="col-md-12 ">
	        
	 <div class='col-md-4' style="margin-top: 2%;">
	     <?php if($session_id==1 || $allPermissions['pod_entry']['create']=="1"){ ?>
		    <a href="pod_upload.php" class="btn btn-info btn-sm"><i class="fa fa-plus"></i> Add POD</a>
		    <?php }?>
	</div>

	 <div class='col-md-2'>
         <label for="from">From:</label>
         <input type="date" id="from" name="from" class="form-control" value="<?=$startMonthDate?>">
    </div>
    
    <div class='col-md-2'>
         <label for="to">To:</label>
         <input type="date" id="to" name="to" class="form-control" value="<?=$endMonthDate?>">
    </div>
     <div class='col-md-2'>
         <label for="to">Status:</label>
         <select class="form-control" name="pod_type" id="pod_type">
	        <option value="">Select Type</option>
	        <option value="1" <?php if(isset($pod_type)){if($pod_type==1){ echo 'selected'; }} ?>>Pickup POD</option>
	        <option value="2"<?php if(isset($pod_type)){if($pod_type==2){ echo 'selected'; }} ?>>Delivery POD</option>
	    </select>
    </div>
    
    
	</div>
	</div>
</section>

<section class="content">
	<div class="row">
		<div class="col-md-12">
			<div class="box box-info">
				<div class="box-body table-responsive">
					<table id="example1" class="table table-bordered table-striped">
						<thead>
							<tr>
								<th width="30">S.No</th>
								<th data-orderable="false"><i class="fa fa-check"></i><input type="checkbox" id="select_all" /></th>
								<th>AWB No</th>
								<th>POD Type</th>
								<th>Date</th>
								<th>File-1</th>
								<th>File-2</th>
								<th>File-3</th>
								<th>File-4</th>
								<th>File-5</th>
							 <?php if($session_id==1){ ?>	
							    <th>Actions</th>	
							 <?php }?>
							</tr>
						</thead>
				
					</table>
				</div>
			</div>
			<?php if($session_id==1){  ?>
			    <center><button id='btnadd' class=" btn btn-danger btn-md">Delete Selected POD's</button></center>
			<?php }?>
		</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 }?>
<?php require_once('footer.php'); ?>



<script>
	$(document).ready(function() {
	    getData();
			  
	    $('#from, #to, #pod_type').change(function() {
            getData();
        });
    });
    
    
    
    
    
    function getData(){
			    var from   = $('#from').val();
			    var to = $('#to').val();
			    var pod_type = $('#pod_type').val();
			    
			    
				var dataTable = $('#example1').DataTable( {
					"processing": true,
					"serverSide": true,
					"bDestroy": true,
					"aaSorting":[[0,'desc']],
					"ajax":{
						url :"data-tables/pod-data-table.php",
						data: {from:from,to:to,pod_type:pod_type},
						type: "post", 
						error: function(){ 
							$(".employee-grid-error").html("");
							$("#example1").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
							$("#employee-grid_processing").css("display","none");
						}
					}
				});
	}
</script>







<script type="text/javascript">
$(document).ready(function(){
    $('#select_all').on('click',function(){
        if(this.checked){
            $('.checkbox').each(function(){
                this.checked = true;
            });
        }else{
             $('.checkbox').each(function(){
                this.checked = false;
            });
        }
    });
    
    $('.checkbox').on('click',function(){
        if($('.checkbox:checked').length == $('.checkbox').length){
            $('#select_all').prop('checked',true);
        }else{
            $('#select_all').prop('checked',false);
        }
    });
});
</script>


<script>
    $(document).ready(function(){
        $('#btnadd').click(function(){
            var checkValues = $('input[name=checkboxlist]:checked').map(function(){
                return $(this).val();
            }).get();
             if(checkValues!=""){
                  $.ajax({
                url: 'pod_multi_delete.php',
                type: 'post',
                data: {pod_ids:checkValues},
                dataType: 'json',
                 success:function(response){
                    alert(response[0]['status']);
                    if(response[0]['status']==1)
                    {
                   alert('Selected PODs Has Been Deleted !!'); 
                   location.reload();
                    }
                    else{
                       alert('Failed To Delete !!');
                      location.reload();
                    }
                }
        
            });
                }
                    else{
                        alert('No Value Selected');
                    }
                });
            });
</script>
