<?php 
require_once("config/configDB.php"); 
//session_start();
require "userPermission.php";
require 'financial_year_calculation.php';

$sqlVehicleQuery = mysqli_query($conn,"SELECT DISTINCT id, vehicleno  FROM vehicle_master WHERE isdelete=1 and  brandtype LIKE 'equipment' OR brandtype LIKE 'transport' ");

$sqlVehicleNo = '';
//$prow = mysqli_fetch_array($sqlBrandQuery,MYSQLI_NUM))
while($prow = mysqli_fetch_array($sqlVehicleQuery)){

    $sqlVehicleNo =$sqlVehicleNo."<option value='".$prow['id']."'>".$prow['vehicleno']."</option>";

}



?>
<!DOCTYPE html>
<html>
<head>
    <?php 
        require 'meta.php';  
        require 'header.php'; 
    ?>
</head>
<body>
    <?php require 'menu.php' ?>
    <div class="col-sm-12 "> <h3 class="text-center"><strong>Spare Out Report</strong></h3></div>
<div class="container-fluid text-center col-sm-12 dashboard-add">  
<?php if($reportTrips_Add==1) {  ?>  
<!-- <a href="reportTripsAdd.php" class="btn btn-primary">Add</a> -->
<?php } ?>
<!-- 
    <div class=" col-sm-2">
        <label>Category</label>
        <select class="form-control input-lg select-purchase-category" data-live-search="true" name="purchaseInvoice" id="trip_category" >
            <option value="transportation"  selected >Transportation Vehicle</option>
            <option value="equipment"   >Equipment Vehicle</option>
        </select> 
    </div> 
-->
<div class=" col-sm-2">
    <label>From Date</label>
    <input type="text" class="form-control input-lg" id="fromDate" autocomplete="off">   
</div>
<div class=" col-sm-2">
    <label>To Date</label>
    <input type="text" class="form-control input-lg" id="toDate" autocomplete="off">    
</div>
<div class=" col-sm-2">
    <label>Vehicle/Machinery</label>
    <select class="form-control input-lg selectpicker select-trip-vehicle" id="selecttripvehicle" data-live-search="true" name="vehicleno">
        <option disabled selected>Please Select Vehicle/Machinery</option>
        <?php   echo $sqlVehicleNo;   ?>
    </select> 
</div>
<div class=" col-sm-1" style="padding-top: 24px;">
    <button type="button" class="btn btn-primary btn-lg datewise-submit-sale">Apply</button>
</div>
<div class=" col-sm-1" style="padding-top: 24px;">
    <a type="button" class="btn btn-success btn-lg report-submit-pdf" target="_blank" >Generate PDF</a>
</div>
</div>
<div class="container col-sm-12 ">
    <div class="datatable-header ">
        <div class="col-sm-12 box-title"><strong>Manage your Spare Details</strong></div>

        <table id="reportSpareOutDashboard" class="table table-striped table-bordered dt-responsive wrap" cellspacing="0" style="width:100%" >
            <thead>
                <tr>				
                    <th>Date</th>
                    <th>Vehicle/Machinery</th> 
                    <th>Spare.Kms</th>     
                     <th>Spare.Hrs</th>                    
                    <th>Spare Details</th>                    
                    <th>Given By</th>
                    <th>Received By</th>
                </tr>
            </thead>
           
    </div>
    <input class="input-lg reportTrips-edit"  type="hidden" value="<?php echo $reportTrips_Edit; ?>"  readonly >
    <input class="input-lg reportTrips-delete"  type="hidden" value="<?php echo $reportTrips_Delete; ?>"  readonly >
</div>
    <?php require 'footer.php' ?>
    <script type="text/javascript">var base_url = "<?= $base_url ?>";</script>
    <script type="text/javascript" src="reportSpareOutScript.js"></script>
    <script type="text/javascript" src="js/plugin/jquery-ui.min.js"></script>

    <script>
    
$(document).ready(function() {

    var dataTable =  $('#reportSpareOutDashboard').DataTable( {
                
                responsive: {
             details: {
                 renderer: function ( api, rowIdx ) {
                 var data = api.cells( rowIdx, ':hidden' ).eq(0).map( function ( cell ) {
                     var header = $( api.column( cell.column ).header() );
                     return  '<p style="color:#00A">'+header.text()+' : '+api.cell( cell ).data()+'</p>';
                 } ).toArray().join('');

                 return data ?    $('<table/>').append( data ) :    false;
                 }
             }
             },
            processing: true,
         serverSide: true,				aaSorting: [[0, 'desc']],
         //ajax: "test.js", // json datasource
         ajax: {
             url : "reportSpareOutgriddata.php",
             type: 'POST',
             data:  {
                tripfromDate : $('input#fromDate').val(),
                triptoDate  : $('input#toDate').val(),
                tripvehicle  : $('select#selecttripvehicle').val()
            }
         }
    });
                
    $("#fromDate").datepicker({
       
        dateFormat: 'dd-mm-yy',
        onSelect: function (dateStr) {
            var min = $(this).datepicker('getDate'); // Get selected date
            $("#toDate").datepicker('option', 'minDate', min || '0'); // Set other min, default to today
        }
    });

    $("#toDate").datepicker({
        minDate: '1',
        dateFormat: 'dd-mm-yy',
        onSelect: function (dateStr) {
            var max = $(this).datepicker('getDate'); // Get selected date

            $('#datepicker').datepicker('option', 'maxDate', max || '+1Y+6M'); // Set other max, default to +18 months

            
        }
    });

			} );

</script>
</body>
</html>