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




<section class="content-header">
    <div class='box-body' style="margin: 0px 0px;box-shadow: rgba(0, 0, 0, 0.19) 0px 10px 20px, rgba(0, 0, 0, 0.23) 0px 6px 6px;background-color: white;">
				<div class="box-body table-responsive">
				<table id="employee-grid"  class="table table-bordered table-striped">
						<thead style="color:gray;">
							<tr>
								<th style="min-width:50px;" data-sortable= false>SNo</th>
								<th style="min-width:100px;" data-sortable= false>Awb NO</th>
								<th style="min-width:120px;" data-sortable= false>Reason</th>
								<th style="min-width:120px;" data-sortable= false>Date</th>
							</tr>
						</thead>
						
					</table>
				</div>
    </div>
</section>


<script>
$(document).ready(function() {
    
    get_branch();
    get_courier();
    get_customer()
    getData();
    $('#branch_id').on('change', function(){
            get_client();
             get_new_client();
    });
    $('#client_id').on('change', function(){
            get_customer();
    });
    $('#filter_table').on('click', function(){
            getData();
    });
    
});

function getData()
{
    var status = $('#status').val();
    var from_date = $('#from_date').val();
    var to_date = $('#to_date').val();
    var status = $('#status').val();
    var client_id = $('#client_id').val();
    var new_client = $('#new_client').val();
    var branch_id = $('#branch_id').val();
    var courier_id = $('#courier_id').val();
    var customer_id = $('#customer_id').val();
    
    var dataTable = $('#employee-grid').DataTable( {
    	"processing": true,
    	"serverSide": true,
    	"bDestroy": true,
    	"aaSorting":[[0,'desc']],
    	"ajax":{
    		url :"data-tables/ewbn-error-report-dt.php", 
    		data: {status:status,from_date:from_date,to_date:to_date,client_id:client_id,branch_id:branch_id,courier_id:courier_id,customer_id:customer_id,new_client:new_client},
    		type: "post",
    		error: function(){  
    			$(".employee-grid-error").html("");
    			$("#employee-grid").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");
    		}
    	}
    });
}

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);
            get_client();
            get_new_client();
        }
    });
}
function get_client(){
    $('#client_id').empty();
    var branch_id=$('#branch_id').val();
    $.ajax({
        url: 'apis/get-drop-down-list.php',
        type: 'post',
        data: {type:'get_client_dropdown',branch_id:branch_id},
         success:function(response){
            $('#client_id').empty();
            $('#client_id').append(response);
        }
    });
}

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);
           
        }
    });
}
function get_courier(){
    $('#courier_id').empty();
    $.ajax({
        url: 'apis/get-drop-down-list.php',
        type: 'post',
        data: {type:'get_courier_dropdown'},
         success:function(response){
            $('#courier_id').empty();
            $('#courier_id').append(response);
        }
    });
}
function get_customer(){
    $('#customer_id').empty();
    var client_id=$('#client_id').val();
    $.ajax({
        url: 'apis/get-drop-down-list.php',
        type: 'post',
        data: {type:'get_customer_dropdown',client_id:client_id},
         success:function(response){
            $('#customer_id').empty();
            $('#customer_id').append(response);
        }
    });
}
</script>

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