<?php require_once('header.php'); ?>
	<?php if($session_id==1 || $allPermissions['incoming_manifest']['read']=="1"){ ?>
<section class="content" style="background-color: white;">
    
    <div class="row">
        
		<div class="col-md-4" style="text-align: left;">
			<h4><i class="fa fa-map-marker"></i> Incoming Manifest Details</h4>
		</div>
		<div class="col-md-8" style="text-align: right;"> 
			<?php if($session_id==1 || $allPermissions['incoming_manifest']['create']=="1"){ ?>
		   <!-- <a href="incoming-manifest.php" class="btn btn-success btn-sm"><i class="fa fa-plus"></i> Create New Incoming Manifest</a>-->
		    <?php }?>
		    <a href="index.php" class="btn btn-warning btn-sm"><i class="fa fa-arrow-left"></i> Back to Home</a>
		</div>
	</div> 
	
	<div class="row" style="padding-left: 10px;padding-right: 10px;margin-top:10px;">
	    <div class='col-md-2 col-sm-6'>
                 <label for="from">From Date:</label>
                 <input type="date" id="from_date" class="form-control" value="<?php echo date("Y-m-d") ?>" name="from_date" onchange="date_changed()">
        </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" 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 class="col-md-2">
                <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-2">
                <label>Manifest Status</label>
            		<select class="form-control select2" name="manifest_status" id="manifest_status" onchange="getData()">
            		    <option value="0">Not Verified</option>
            		    <option value="1">Fully Verified</option>
            		    <option value="2">Partially Verified</option>
            		    <option value="">All Status</option>
            	    </select>
			</div>
    </div>
    
	<div class="row">
		<div class="col-md-12">
			<div>
			<div class="box-body table-responsive">
					<table id="employee-grid"  class="table table-bordered table-striped">
						<thead>
							<tr>
								<th width="30">S.No</th>
								<th>Actions</th>
								<th>Orgin Branch</th>
								<th>Destination Branch</th>
								<th>Date</th>
								<th>Total Shipment</th>
								<th>Total Box</th>
								<th>Total Wt</th>
								<th>Co-Loader Name</th>
								<th>Driver Name</th>
								<th>Invoice No</th>
								<th>Mobile No</th>
								<th>Vehicle No</th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
		</div>
	</div>
</section>
<?php } ?>
<?php require_once('footer.php'); ?>

<script type="text/javascript">
$(document).ready(function(){
    getData();
});

function date_changed(){
    var from_date=$('#from_date').val();
    var to_date=$('#to_date').val();
    if(from_date!='' && to_date!=''){
        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,    
        "destroy":true,
        "ajax":{
			url : "data-tables/manifest-data-table.php",
			type: "post",
			data:{'type':2,from_branch:from_branch,to_branch:to_branch,coloader:coloader,from_date:from_date,to_date:to_date, manifest_status:manifest_status},
			error: function(){ 
				$(".employee-grid-error").html("");
				$("#employee-grid").append('<tbody class="employee-grid-error"><tr><th colspan="10" style="text-align;center;">No data found in the server</th></tr></tbody>');
				$("#employee-grid_processing").css("display","none");
			}
		}
	} );
    }
</script>