<?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="row">
		<div class="col-md-4" style="text-align: left;">
			<h4><i class="fa fa-list"></i> Booking Report Details</h4>
		</div>
		<div class="col-md-8" style="text-align: right;"> 
		</div>
	</div>     
        
 <form action="excel/mis-report.php" method="post">       
    <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">Select Consigner:</label>
                    <select class="form-control select2" name="client_id" id="client_id">
                    </select>
        </div>
        <div class='col-md-3 col-sm-6'>
                <label for="to">Select Courier Company:</label>
                    <select class="form-control select2" name="courier_id" id="courier_id">
                    </select>
        </div>
        
    </div>
    <div class="row" style="margin-top:5px;">
        <div class='col-md-2 col-sm-6'>
                <label for="to">Select Consignee:</label>
                    <select class="form-control select2" name="customer_id" id="customer_id">
                    </select>
        </div>
        <div class='col-md-2 col-sm-6'>
                <label for="to">Select Shipment Status:</label>
                    <select class="form-control select2" name="status" id="status">
                        <option value="all">All</option>
				        <?php
				        $statement = $pdo->prepare("SELECT * FROM `tbl_status` WHERE status=1 ");    
                        $statement->execute();
                    	$result = $statement->fetchAll(PDO::FETCH_ASSOC);
                    	foreach($result as $data){
                    	?>
                        	<option value="<?=$data['id']?>"><?=$data['name']?></option>
                    	<?php } ?>
                    </select>
        </div>
        <div class='col-md-2 col-sm-6'>
                 <label for="from">From Date:</label>
                 <input type="date" id="from_date" class="form-control" value="<?=$startMonthDate?>" name="from_date">
        </div>
        <div class='col-md-2 col-sm-6'>
             <label for="to">To Date:</label>
             <input type="date" id="to_date" class="form-control" value="<?php echo date("Y-m-d") ?>" name="to_date">
        </div>
        <div class='col-md-3 col-sm-6'>
             <label for="to">Action :</label><br>
             <span id="filter_table" name="sd" class="btn btn-sm btn-warning"><i class="fa fa-filter"></i> Filter</span>
            <button type="submit" class="btn btn-sm btn-primary"><i class="fa fa-download"></i> Export As Excel</button>
        </div>
    </div>   
    </form>
    </div>
</section>


<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 data-sortable= false>S.no</th>
							    <!--<th style="min-width:50px;" data-sortable= false>Date Added</th>-->
							    <th style="min-width:50px;" data-sortable= false>Invoice Date</th>
							    <th style="min-width:70px;" data-sortable= false>AWB NO</th>
							    <th style="min-width:250px;" data-sortable= false>Client Name</th>
							    <th style="min-width:250px;" data-sortable= false>Shipper Name</th>
							    <th style="min-width:100px;" data-sortable= false>Invoice Number</th>
							    <th style="min-width:100px;" data-sortable= false>Invoice Value</th>
							    <th style="min-width:250px;" data-sortable= false>Customer Name</th>
							    <th data-sortable= false style="min-width:150px;">Shipper City</th>
							    <th style="min-width:150px;" data-sortable= false>Customer City</th>
							    <th style="min-width:100px;" data-sortable= false>Total Box</th>
							    <!--<th style="min-width:100px;" data-sortable= false>QUANTITY</th>-->
							    <th style="min-width:100px;" data-sortable= false>Total Weight</th>
							    <th style="min-width:120px;" data-sortable= false>Shipping Mode</th>
								<th style="min-width:150px;" data-sortable= false>Branch Name</th>
								<th style="min-width:170px;" data-sortable= false>Status</th>
								<th style="min-width:100px;" data-sortable= false>SHIPMENT LAST UPDATE DATE</th>
								<!--<th style="min-width:270px;" data-sortable= false>Remark</th>-->
								<th style="min-width:170px;" data-sortable= false>POD Status</th>
								<th style="min-width:170px;" data-sortable= false>ValidUpto</th>
								<th style="min-width:170px;" data-sortable= false>CreatedAt</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/mis-report.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'); ?>