<?php require_once('header.php'); ?>
<?php if($allPermissions['pickupentry']['read']=="1"){ ?>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
	$(document).ready(function() {
			  getData();
			  function getData()
			  {
			    var from= $('#from').val();     
                var to= $('#to').val();   
                var role= $('#role').val();   
                var role_id= $('#client_id').val();  
                $('#fromm').val(from);   
                $('#too').val(to);
                $('#role_id').val(role_id);
                var entry_type= $('#entry_type').val();
                var awb_type= $('#awb_type').val();
                
			    var del=<?=$allPermissions['pickupentry']['delete'] ?>;
                var edit=<?=$allPermissions['pickupentry']['update'] ?>;
			    var client_id   = $('#client_id').val();
			    var client_type = $('#client_type').val();
			    var status_code = $('#status_code').val();
			    
				var dataTable = $('#employee-grid').DataTable( {
					"processing": true,
					"serverSide": true,
					"bDestroy": true,
					"aaSorting":[[0,'desc']],
					"ajax":{
						url :"data-tables/pending-pickup-entry-data-table.php", 
						data: {client_id:client_id,client_type:client_type,status:status_code,del:del,edit:edit,from:from,to:to,entry_type:entry_type,awb_type:awb_type},
						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");
						}
					}
				});
			  }
	$('#update_status').on('click', function(){
         var entry_date = $('#entry_date').val();
        //  alert(entry_date);
         var checkValues = $('input[name=checkboxlist]:checked').map(function()
            {
                return $(this).val();
            }).get();
             if(checkValues!=""){
          $.ajax({
        url: 'update_status_picked.php',
        type: 'post',
        data: {pickup_id:checkValues,type:'modicare',entry_date:entry_date},
        // dataType: 'json',
        success: function(response)
        {
            
            $("#res_status_table").show();
            $("#res_status_table_data").html(response);
             getData();
        }
    });
        }else{
                alert('No Value Selected');
            }
});
			  
    $('#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);
        }
    });


    $('#print_awb').on('click',function(){
        var checkValues = $('input[name=checkboxlist]:checked').map(function()
            {
                return $(this).val();
            }).get();
               if(checkValues==""){
                      alert("pls Select Atleast One Record");
               }
               else
               {
  var ids=[];
    ids = checkValues;

    window.location.href="awb_number_print.php?list_id="+ids;
}
});
 function redirectTolable(){
        
         var checkValues = $('input[name=checkboxlist]:checked').map(function()
            {
                return $(this).val();
            }).get();
     //   alert(checkValues);
                
  var ids=[];
    ids = checkValues; // some thing like this you can set value for 1st Param.
    window.location.href="lable_print.php?list_id="+ids;
}
$('#get_report').on('click', function(){
			      var from_date=  $('#from').val();
			      if(from_date){
			        getData();
			      } else
                    {
                        alert('Select a Date !!');
                    }
			  } );
});
</script>
<?php 
if($_REQUEST['status']==1)
{
    $status_name="Pending";
}
else if($_REQUEST['status']==2)
{
    $status_name="Picked";
}
else if($_REQUEST['status']==3)
{
    $status_name="Manifest";
}
else if($_REQUEST['status']==4)
{
    $status_name="Intransit";
}
else if($_REQUEST['status']==5)
{
    $status_name="Received At Destination";
}
else if($_REQUEST['status']==6)
{
    $status_name="Out For Delivery";
}
else if($_REQUEST['status']==7)
{
    $status_name="Delivery";
}
else if($_REQUEST['status']==8)
{
    $status_name="Un-Delivey";
}
else
{
    $status_name="Unknown";
} ?>
<section class="content-header">
	<div class="content-header-left">
		<h1><?=$status_name?> Pickup Entry</h1>
	</div>
	<div class="row">
	    <div class="col-md-12">
	 <div class="col-md-2" style="margin-left: 6%;">  
	<div class="content-header-right" >
		<a href="excel/excel-all-status.php?status=<?=$_REQUEST['status']?>" class="btn btn-danger btn-sm">Export as Excel</a>
	</div>
	</div>
	<div class="col-md-2">  
	<div class="content-header-right" >
		<a href="modicare-pickup-entry-add.php" class="btn btn-danger btn-sm">Booking Entry</a>
	</div>
	</div>
		<div class="col-md-2">  
	<div class="content-header-right" >
		<button class="btn btn-danger btn-sm" id="print_awb" >Print AWB Number</button>
	</div>
	</div>
	<?php if($_REQUEST['status']==1 && $allPermissions['pickupentry']['update']=="1"){ ?>
	<div class="col-md-2">  
	<div class="content-header-right" >
		<input type="date" autocomplete="off" class="form-control" name="entry_date"  id="entry_date" value="<?php echo date("Y-m-d"); ?>">
	</div>
	</div>
	<div class="col-md-2">  
	<div class="content-header-right" >
		 <button class="btn btn-success btn-sm" id="update_status" >Update Status Picked</button>
	</div>
	</div>
	<?php } ?>
	</div>
	</div>
		<br>
</section>
<section>
    <div class='row'>
        <div class="col-md-12">
            <div class='col-md-2'>
                 <label for="from">From:</label>
                 <input type="date" id="from" class="form-control" value="<?=$startMonthDate?>" name="from">
            </div>
            <div class='col-md-2'>
                 <label for="to">To:</label>
                 <input type="date" id="to" class="form-control" value="<?php echo date("Y-m-d") ?>" name="to">
            </div>
            <div class='col-md-2'>
                <label for="to">Select Client Name:</label>
                    <select class="form-control select2" name="client_id" id="client_id">
			        
			        <?php
					 if($clientType=="Admin"){ ?>
					     <option value="all" >Select Client Name </option><?php
					$statement = $pdo->prepare("SELECT * FROM tbl_user WHERE role='client' or role='Modicare' ORDER BY full_name ASC");
					 } else {
                    $statement = $pdo->prepare("SELECT * FROM tbl_user WHERE id=$clientId order by full_name asc");    }
					$statement->execute();
					$result = $statement->fetchAll(PDO::FETCH_ASSOC);	
					foreach ($result as $row) {
						?>
						<option value="<?php echo $row['id']; ?>"><?php echo $row['full_name']; ?></option>
						<?php
					}
					?>
			    </select>
			</div>
	        <div class='col-md-2'>
             <label for="to">AWB Type:</label>
                <select class="form-control select2" name="awb_type" id="awb_type">
    	            <option value=''>All</option>
    	            <option value='0'>Forwart AWB</option>
    	            <option value='1'>Reversed AWB </option>
    	        </select>
            </div>
            <div class='col-md-2'>
		      <label for="to">Booking Type:</label>
                <select class="form-control select2" name="entry_type" id="entry_type">
					<option value="">All</option>
					<option value="1">Normarl Booking</option>
					<option value="2">Api Booking</option>
		        </select>
			</div>
    <div class='col-md-2'>
         <label for="to">Action :</label><br>
         <button id="get_report" name="date_select" type="submit" class="btn btn-sm btn-info">Submit</button>
    </div>
	</div>
        
    </div>
</section>
<input type='hidden' name="client_id" id="client_id" value="<?php echo $clientId; ?>">
<input type="hidden" id="client_type" name="client_type" value="<?php echo $clientType; ?>">
<input type="hidden" id="status_code" name="status_code" value="<?php echo $_REQUEST['status']; ?>">
    <div id="res_status_table" class="alert alert-info alert-dismissible"  style='display:none;margin-left: 2%;margin-right: 2%;' >
	    <a href="#" class="close" data-dismiss="alert" onclick='location.reload();' aria-label="close">&times;</a>
    	<table id="res_status_table_data" class="table"></table>
	</div>
<section class="content">
	<div class="row">
		<div class="col-md-12">
			<div class="box box-info">
				<div class="box-body table-responsive">
				<table id="employee-grid"  class="table table-bordered table-striped">
						<thead>
							<tr>
								<th width="30">SL</th>
								<th data-sortable= false>Action</th>
								<th data-sortable= false><i class="fa fa-check"></i><input type="checkbox" id="select_all" /></th>
								<?php  if($clientType=="Admin")	 { ?>
								<th>Client</th><?php } ?>
								<th>Booking AWB</th>
								<?php  if($clientType=="Admin")	 { ?>
								<th>3PL AWB</th>
								<th>3PL Name</th>
								<?php } ?>
								<th>Ref No</th>
								<th>Order Type</th>
								<th>Shipper Name</th>
								<th>Shipper Address</th>
								<th>Shipper City</th>
								<th>Shipper State</th>
								<th>Shipper Phone</th>
								<th>Shipper Pincode</th>
								<th>Consignee Name</th>
								<th>Consignee Address</th>
								<th>Consignee City</th>
								<th>Consignee State</th>
								<th>Consignee Phone</th>
								<th>Consignee Pincode</th>
								<th>Volumetric Weight</th>
								<th>Volumetric Length</th>
								<th>Volumetric Breadth</th>
								<th>Volumetric Height</th>
								<th>Collectable Amount</th>
								<th>Product Description</th>
								<th>Quantity</th>
								<th>Boxes</th>
								<th>Invoice Value</th>
								<th>Taxable Value</th>
								<th>Hsn Code</th>
								<th>Discount</th>
								<th>Gst Amount</th>
								<th>MRP</th>
								<th>Ewaybill</th>
								<th>Actual Weight</th>
								<th>Charged Weight</th>
								<th>Gst Type</th>
								<th>Buyer Gst</th>
								<th>Seller Gst</th>
								<th>RTO Name</th>
								<th>RTO Address</th>
								<th>RTO City</th>
								<th>RTO State</th>
								<th>RTO Phone</th>
								<th>RTO Pincode</th>
								<th>Date Added</th>
							</tr>
						</thead>
						
					</table>
				</div>
			</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-success btn-ok">Delete</a>
            </div>
        </div>
    </div>
</div>

<?php }else{ ?>
<center><h4 style="color:red;">You don't have permission to view this page </h4></center>
<?php } ?>
<?php require_once('footer.php'); ?>