<?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> DRS Report Details</h4>
		</div>
		<div class="col-md-8" style="text-align: right;"> 
		</div>
	</div>     
        
     <form action="excel/drs-report-export.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-2 col-sm-6'>
                    <label for="to">Select Driver:</label>
                        <select class="form-control select2" name="driver_id" id="driver_id">
                            <option value="all">All</option>
    				        <?php
    				        $statement = $pdo->prepare("SELECT * FROM `tbl_drivers` WHERE status=1 ");    
                            $statement->execute();
                        	$result = $statement->fetchAll(PDO::FETCH_ASSOC);
                        	foreach($result as $data){
                        	?>
                            	<option value="<?=$data['id']?>"><?=$data['name']." - ".$data['mobile_no']?></option>
                        	<?php } ?>
                        </select>
            </div>
            
            
             <div class='col-md-2 col-sm-6'>
                <label for="to">Select Deliver Boy:</label>
                <select class="form-control select2" name="delivery_boy_id" id="delivery_boy_id">
                    <option value="all">All</option>
                    <?php
                    $statement = $pdo->prepare("SELECT * FROM `tbl_delivery_boy` WHERE status=1 ");    
                    $statement->execute();
                	$result = $statement->fetchAll(PDO::FETCH_ASSOC);
                	foreach($result as $data){
                	?>
                    	<option value="<?=$data['id']?>"><?=$data['name'] ." - ",$data['mobile_no']?></option>
                	<?php } ?>
                </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>
                <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 style="min-width:50px;"data-sortable= false>S No</th>
							    <th style="min-width:150px;" data-sortable= false>DRS Code</th>
								<th style="min-width:150px;" data-sortable= false>Driver Name</th>
								<th style="min-width:150px;" data-sortable= false>Driver Mobile No</th>
								<th style="min-width:150px;" data-sortable= false>Vehicle Number</th>
								<th style="min-width:150px;" data-sortable= false>Delivery Boy Name</th>
								<th style="min-width:250px;" data-sortable= false>Delivery Boy Mobile No</th>
								<th style="min-width:150px;" data-sortable= false>Actual Weight</th>
								<th style="min-width:150px;" data-sortable= false>Charged Weight</th>
								<th style="min-width:150px;" data-sortable= false>Branch Name</th>
                                <th style="min-width:150px;" data-sortable= false>Total Shipment</th>
                                <th style="min-width:150px;" data-sortable= false>DRS Date</th>
                                <th style="min-width:150px;" data-sortable= false>DRS Status</th>
                                <th style="min-width:150px;" data-sortable= false>Delivery Count</th>
                                <th style="min-width:150px;" data-sortable= false>Pending Count</th>
                                <th style="min-width:150px;" data-sortable= false>POD Not Updated</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 branch_id = $('#branch_id').val();
    var driver_id = $('#driver_id').val();
    var delivery_boy_id = $('#delivery_boy_id').val();
    
    var dataTable = $('#employee-grid').DataTable( {
    	"processing": true,
    	"serverSide": true,
    	"bDestroy": true,
    	"aaSorting":[[0,'desc']],
    	"ajax":{
    		url :"data-tables/drs-report-dt.php", 
    		data: {driver_id:driver_id,branch_id:branch_id,delivery_boy_id:delivery_boy_id},
    		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'); ?>