<?php require_once('header.php'); ?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" language="javascript" >
			$(document).ready(function() {
			    var client_id   = $('#client_id').val();
			    var client_type = $('#client_type').val();
				var dataTable = $('#delivery-grid').DataTable( {
					"processing": true,
					"serverSide": true,
					"ajax":{
						url :"data-tables/delivery-update-data-table.php", // json datasource
						data: {client_id:client_id,client_type:client_type},
						type: "post",  // method  , by default get
						error: function(){  // error handling
							$(".delivery-grid-error").html("");
							$("#delivery-grid").append('<tbody class="delivery-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
							$("#delivery-grid_processing").css("display","none");
							
						}
					}
				} );
			} );
		</script>
<script>
$(document).ready(function(){
    $('input[type=datetime-local]').val(new Date().toJSON().slice(0,19));
});

</script>


<script>
    $(document).ready(function(){
       $('#status').on('change',function(){
        //   var status_v= $("#status option:selected").val();
        //   alert(status_v);
           var status= $("#status option:selected").text();
         
         if(status=='Delivered'){
              $("#delivered").show();
              $("#undelivered").hide();
         }
         else if(status=='Undelivery'){
               $("#delivered").hide();
              $("#undelivered").show();
         }
         else
         {
               $("#delivered").hide();
              $("#undelivered").hide();
         }
        });
    });
</script>

<script type="text/javascript">
$(document).ready(function(){
    $('#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);
        }
    });
});

    
 function updatestatusTo(){
      var status_value=$("#status option:selected").val();
      var r_name=$('#r_name').val();
      var r_mobile=$('#r_mobile').val();
      var r_relation=$('#r_relation').val();
      var r_delivery_date=$('#r_delivery_date').val();
       var s_date=$('#s_date').val();
      var reason=$('#reason').val();
      var remark=$('#remark').val();
      var status= $("#status option:selected").text();
      
       var checkValues = $('input[name=checkboxlist]:checked').map(function()
            {
                return $(this).val();
            }).get();
             if(checkValues!=""){
          $.ajax({
        url: 'delivery_status_update.php',
        type: 'post',
        data: {pickup_id:checkValues,status:status,r_name:r_name,r_mobile:r_mobile,r_relation:r_relation,r_delivery_date:r_delivery_date,reason:reason,remark:remark,status_value:status_value,s_date:s_date},
        // dataType: 'json',
        success: function(response)
        {
            console.log(response);
            $("#res_status_table").show();
            $("#res_status_table_data").html(response);
        }

    });
        }
            else{
                alert('No Value Selected');
            }

}
 
</script>
<section class="content-header">
	<div class="content-header-left">
		<h1>View Delivery</h1>
	</div>
<!--Bulk Upload Code Start-->
	<div class="row">
	    <div class="col-md-12">
	        <div class="col-md-2">  
        	    <div class="content-header-left" >
	   	    	<a href="delivery_bulk_upload.php" class="btn btn-danger btn-sm">Bulk Upload</a>
            	</div>
    	    </div>
    	</div>
	</div>
	<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; ?>">
	<!--Bulk Upload Code End-->	
</section><br>
<div class="row">
	    <div class="col-md-12">
	        <div class="col-md-5">
	        	<div class="form-group">
					<label for="" class="col-sm-6 control-label text-right">Select Status <span>*</span></label>
							<div class="col-sm-6">
							    <select name="status" class="form-control" id='status'>
							        <option value="4">In Transit</option> 
							        <option value="5">Received at Destination</option>
							        <option value="6">Out for delivery</option>
							        <option value="7">Delivered</option>
							        <option value="8">Undelivery</option>
							        ?>
							        
							    </select>
							</div>	
						</div>		
				</div>
				<div class="col-md-5">
				        <div class="form-group">
				    	<label for="" class="col-sm-6 control-label text-right">Status Update Date<span>*</span></label>
							<div class="col-sm-6">
								<input type="datetime-local" autocomplete="off" class="form-control" name="s_date" id="s_date" >
							</div>
				</div>
				    </div>
				<div id='delivered' style="display:none;padding-top: 4%;" >
				    <div class="col-md-5">
				        <div class="form-group">
				    	<label for="" class="col-sm-6 control-label text-right">Receiver Name <span>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="r_name" id="r_name"  value="">
							</div>
				</div>
				    </div>
				    <div class="col-md-5">
				        <div class="form-group">
				    	<label for="" class="col-sm-6 control-label text-right">Receiver Mobile <span>*</span></label>
							<div class="col-sm-6">
								<input type="number" autocomplete="off" class="form-control" name="r_mobile" id="r_mobile" value="">
							</div>
				</div>
				    </div>
				    
	     <div style="padding-top: 4%;">
				    <div class="col-md-5">
				        <div class="form-group">
				    	<label for="" class="col-sm-6 control-label text-right">Relation <span>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="r_relation" id="r_relation" value="">
							</div>
				</div>
				    </div>
				    <div class="col-md-5">
				        <div class="form-group">
				    	<label for="" class="col-sm-6 control-label text-right">Delivery Date <span>*</span></label>
							<div class="col-sm-6">
								<input type="date" autocomplete="off" class="form-control" name="r_delivery_date" id="r_delivery_date" value="<?php echo date('Y-m-d');?>">
							</div>
				</div>
				    </div>
				    </div>
				    
				</div>
				<div id='undelivered' style="display:none;padding-top: 4%;">
				    <div class="col-md-5">
				        <div class="form-group">
				    	<label for="" class="col-sm-6 control-label text-right">Reason <span>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="reason" id="reason" value="">
							</div>
				</div>
				    </div>
				    <div class="col-md-5">
				        <div class="form-group">
				    	<label for="" class="col-sm-6 control-label text-right">Remark <span>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="remark" id="remark" value="">
							</div>
				</div>
				    </div>
				</div>
				<div class="col-md-12">
				<center><button class="btn btn-danger btn-sm" onclick="updatestatusTo();">Update Status</button></center>
					</div>
		<br>	<br>
	        
	    </div>
	</div>
	<div id="res_status_table" class="alert alert-success alert-dismissible"  style='display:none;margin-left: 2%;margin-right: 2%;' >
	    <a href="#" class="close" data-dismiss="alert" onclick='location.reload();' aria-label="close">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="delivery-grid"  class="table table-bordered table-striped">
						<thead>
							<tr>
								<th width="30">SL</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>CSCS AWB</th>
								<th>3PL AWB</th>
								<th>Ref No</th>
								<th>Order Type</th>
								<th>Status</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>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-danger btn-ok">Delete</a>
            </div>
        </div>
    </div>
</div>


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