<?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> Manifest Report Details   </h4>
		</div>
		<div class="col-md-8" style="text-align: right;"> 
		</div>
	</div>     
        
        
    <div class="row">
        
         <div class='col-md-3 col-sm-6'>
                 <label for="from">From Date:</label>
                 <input type="date" id="from_date" class="form-control" value="<?php echo date("Y-m-01") ?>" name="from_date" onchange="date_changed()">
        </div>
        <div class='col-md-3 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" onchange="date_changed()">
        </div>
        
    
		<div class="col-md-3">
            <label>Sender Branch</label>
        		<select class="form-control select2" name="from_branch" id="from_branch" onchange="getData()">
        		    <option value="">All</option>
        	        <?php
        	        $condi='';
        	        
        	        if($session['id']!=1 && $session_branch_ids!='0'){
                        $condi.= " and id IN ($session_branch_ids)";
                    }
        	        
        			$statement = $pdo->prepare("SELECT * FROM `tbl_branch` where status='1' $condi");
        			$statement->execute();
        			$result = $statement->fetchAll(PDO::FETCH_ASSOC);	
        			foreach ($result as $row) { ?>
        				<option value="<?php echo $row['id']; ?>"><?php echo $row['name']; ?></option>
        			<?php } ?>
        	    </select>
		</div>
		<div class="col-md-3">
                <label>Receiver Branch</label>
            		<select class="form-control select2" name="to_branch" id="to_branch" onchange="getData()">
            		    <option value="">All</option>
            	        <?php
            	        $condi='';
            	        
            	        if($session['id']!=1 && $session_branch_ids!='0'){
                            $condi.= " and id IN ($session_branch_ids)";
                        }
            	        
            			$statement = $pdo->prepare("SELECT * FROM `tbl_branch` where status='1' $condi");
            			$statement->execute();
            			$result = $statement->fetchAll(PDO::FETCH_ASSOC);	
            			foreach ($result as $row) { ?>
            				<option value="<?php echo $row['id']; ?>"><?php echo $row['name']; ?></option>
            			<?php } ?>
            	    </select>
			</div>
			
        
    </div>
    <div class="row" style="margin-top:5px;">
        <div class="col-md-3 col-sm-6">
            <label>Co-Loader Name</label>
        		<select class="form-control select2" name="coloader" id="coloader" onchange="getData()">
        		    <option value="">All</option>
        	        <?php
        			$statement = $pdo->prepare("SELECT * FROM `tbl_coloader` where status='1'");
        			$statement->execute();
        			$result = $statement->fetchAll(PDO::FETCH_ASSOC);	
        			foreach ($result as $row) { ?>
        				<option value="<?php echo $row['id']; ?>"><?php echo $row['name']; ?></option>
        			<?php } ?>
        	    </select>
		</div>
		
		<div class="col-md-3 col-sm-6">
            <label>Manifest Status</label>
        		<select class="form-control select2" name="manifest_status" id="manifest_status" onchange="getData()">
        		    <option value="" selected>All Status</option>
        		    <option value="0">Not Verified</option>
        		    <option value="1">Fully Verified</option>
        		    <option value="2">Partially Verified</option>
        		  
        	    </select>
		</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>
            <a href="excel/manifest-report-export.php" class="btn btn-sm btn-primary"><i class="fa fa-download"></i> Export As Excel</a>
        </div>
    </div>    
    </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 style="min-width:50px;" data-sortable= false>S&nbsp;No</th>
								<th style="min-width:150px;" data-sortable= false>Driver&nbsp;Name</th>
								<th style="min-width:250px;" data-sortable= false>Driver&nbsp;Mobile No</th>
								<th style="min-width:50px;" data-sortable= false>Vehicle&nbsp;No</th>
								<th style="min-width:120px;" data-sortable= false>From Branch</th>
								<th style="min-width:250px;" data-sortable= false>To&nbsp;Branch</th>
								<th data-sortable= false>Date</th>
								<th data-sortable= false>Total&nbsp;Shipment</th>
								<th data-sortable= false>Total&nbsp;Box</th>
								<th data-sortable= false>Total&nbsp;Wt</th>
								<th style="min-width:250px;" data-sortable= false>Co-Loader&nbsp;Name</th>
								<th style="min-width:250px;" data-sortable= false>Manifest&nbsp;Type</th>
							</tr>
						</thead>
						
					</table>
				</div>
    </div>
</section>


<script>
$(document).ready(function() {
    
    function date_changed(){
        var from_date=$('#from_date').val();
            var to_date=$('#to_date').val();
            if(from_date!='' && to_date!=''){
                getData();
            }
    }
    getData();

    $('#filter_table').on('click', function(){
            getData();
    });
    
});

function getData()
{
     var from_branch=$('#from_branch').val();
    var to_branch=$('#to_branch').val();
    var coloader=$('#coloader').val();
    var from_date=$('#from_date').val();
    var to_date=$('#to_date').val();
    var manifest_status = $('#manifest_status').val();
    
    var dataTable = $('#employee-grid').DataTable( {
    	"processing": true,
    	"serverSide": true,
    	"bDestroy": true,
    	"aaSorting":[[0,'desc']],
    	"ajax":{
    		url :"data-tables/delivery-manifest-report-dt.php", 
    		data: {from_branch:from_branch,to_branch:to_branch,coloader:coloader,from_date:from_date,to_date:to_date, manifest_status:manifest_status},
    		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");
    		}
    	}
    });
}


</script>

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