 
<?php $__env->startSection('content'); ?>
	<div class="row">
    	<div class="col-lg-12">
    		<h1 class="page-header">Vehicles</h1>
    	</div>
    </div>
    <div class="row">


                   <div class="col-lg-12">
                    <div class="panel panel-default">
                    	<?php if(session('status')): ?>
							<div class="alert alert-success">
								<?php echo e(session('status')); ?>

							</div>
						<?php endif; ?>
			
						<?php if(count($errors) > 0): ?>
							<div class="alert alert-danger">
								<strong>Whoops!</strong> There were some problems with your input.<br><br>
								<ul>
									<?php foreach($errors->all() as $error): ?>
										<li><?php echo e($error); ?></li>
									<?php endforeach; ?>
								</ul>
							</div>
						<?php endif; ?>
                        <div class="panel-heading" style="height: 50px;">
                            <label class="col-lg-11 col-xs-9 control-label">All Mileage Report</label>
                            <div class="col-lg-1 col-xs-3">
                                <select  class="form-control" name="year" onchange="location = this.value;">
                                    <?php foreach($years as $uYear): ?>
                                    <option value="<?php echo e('/uadmin/mileages/all/'.$uYear); ?>" 
                                    <?php if($year == $uYear): ?> 
                                        <?php echo e('selected'); ?> 
                                    <?php endif; ?>
                                    >
                                        <?php echo e($uYear); ?>

                                    </option>
                                    <?php endforeach; ?>
                                </select>
                            </div>
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example2">
                                    <thead>
                                        <tr>
                                        	<th>Month</th>
                                        	<th>Driver</th>
                                       		<th>Vehicle</th>
                                            <th>Ending Odometer</th>
                                            <th>Commute</th>
                                            <th>Personal</th>
                                            <th>Approval</th>
                                            
                                        </tr>
                                    </thead>
                                    <tbody>
                                    <?php $count = 0; ?>
                                    <?php foreach($mileages as $mileage): ?>
                                    <?php $count++; ?>
                                    <?php if($count % 2 == 1): ?>
                                        <tr class="odd">
                                    <?php else: ?>
                                    	<tr class="even">
                                    <?php endif; ?>
                                    		<?php 
                                    			$vehicle = \App\Vehicle::find($mileage->vehicle); 
                                                if(!$vehicle) $vehicle = new \App\Vehicle();
                                    			$details = \App\Mileage_detail::where('mileage','=',$mileage->id)->orderBy('date','asc')->get();
                                    			$commute = 0;
                                    			$personal = 0;
                                    			$string = 'Personal Miles\\n\\n';
                                    			foreach($details as $detail)
                                    			{
                                    				if($detail->type == 'commute')
                                    				{
                                    					$commute += $detail->miles;
                                    				}
                                    				elseif($detail->type == 'personal')
                                    				{
                                    					$personal += $detail->miles;
                                    					if($detail->miles > 0)
                                    					{
                                    						$string .= date('Y-m-d', strtotime($detail->date)) . ": " . $detail->miles . " Miles\\n";
                                    					}
                                    					
                                    				}
                                    			}
                                    			$string .= "\\nTotal: " . $personal . " Miles";
                                    		?>
                                    		<td>
                                    			<span style="display: none;"><?php echo e(date('Ym', strtotime($mileage->date))); ?></span>
                                    			<?php echo e(date('F Y', strtotime($mileage->date))); ?>

                                    		</td>
                                    		<td><?php echo e(\App\User::find($mileage->driver)->name); ?></td>
                                            <td><?php echo e($vehicle->year . ' ' . $vehicle->make . ' ' . $vehicle->model); ?></td>
                                            <td><?php echo e($mileage->odometer); ?></td>
                                            <td><?php echo e($commute); ?> Miles</td>
                                            <td>
                                            	<?php if($personal > 0): ?>
                                            		<a href="#" onclick='alert("<?php echo e($string); ?>")'><?php echo e($personal); ?> Miles</a>
                                            	<?php else: ?>
                                            		<?php echo e($personal); ?> Miles
                                            	<?php endif; ?>
                                            </td>
                                            <td style="text-align: center;">
                                            	<?php if($mileage->approve_self && $mileage->approve_manager): ?>
                                            		<span style="color: green;" title="Approved by <?php echo e(\App\User::find($mileage->manager)->name); ?>"><?php echo e(date('Y-m-d H:i:s', strtotime($mileage->approve_manager))); ?></span>
                                            		
                                            	<?php else: ?>
                                            		<i class="fa fa-times" style="color: red;">
                                            	<?php endif; ?>
                                            </td>
                                        </tr>
                                  	<?php endforeach; ?>
                                       </tbody>
                                	</table>
                                </div>
                             </div>
                         </div>
                     </div>
                 </div>
                 
    			<div class="row">


                   <div class="col-lg-12">
                    <div class="panel panel-default">
                    	<?php if(session('status')): ?>
							<div class="alert alert-success">
								<?php echo e(session('status')); ?>

							</div>
						<?php endif; ?>
			
						<?php if(count($errors) > 0): ?>
							<div class="alert alert-danger">
								<strong>Whoops!</strong> There were some problems with your input.<br><br>
								<ul>
									<?php foreach($errors->all() as $error): ?>
										<li><?php echo e($error); ?></li>
									<?php endforeach; ?>
								</ul>
							</div>
						<?php endif; ?>
                      <div class="panel-heading">
                           Driver Mileage Report
					  </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example3">
                                    <thead>
                                        <tr>
                                        	<th>Driver</th>
                                            <th>Months</th>
                                            <th>Personal Total</th>
                                            <th>Commute Total</th>
                                            <th>Combined Total</th>
                                            <th>Monthly Average</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    <?php $count = 0; ?>
                                    <?php foreach(\App\Mileage::getData() as $key => $data): ?>
                                    <?php $count++; ?>
                                    <?php if($count % 2 == 1): ?>
                                        <tr class="odd">
                                    <?php else: ?>
                                    	<tr class="even">
                                    <?php endif; ?>
                                    		<td><?php echo e(\App\User::find($key)->name); ?></td>
											<td><?php echo e($data['months']); ?></td>
											<td><?php echo e($data['personal']); ?></td>
											<td><?php echo e($data['commute']); ?></td>
											<td><?php echo e($data['total']); ?></td>
											<td><?php echo e($data['average']); ?></td>

                                        </tr>
                                  	<?php endforeach; ?>
                                       </tbody>
                                	</table>
                                </div>
                             </div>
                         </div>
                     </div>

                 </div>
                 <hr>
                 <div class="row">
                    <div class="col-lg-12">
                        <form method="post" action="<?php echo e(url('admin/mileages/odometer_report')); ?>">
                            <input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
                            <button type="submit" class="btn btn-primary">
                                Generate Odometer Report
                            </button>
                        </form>
                    </div>
                </div>
                <br><br><br>
               
<?php $__env->stopSection(); ?>

<?php $__env->startSection('extras'); ?>
	<!-- DataTables CSS -->
    <!-- <link href="<?php echo e(asset('uad/css/plugins/dataTables.bootstrap.css')); ?>" rel="stylesheet">  -->
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/t/bs/pdfmake-0.1.18,dt-1.10.11,b-1.1.2,b-flash-1.1.2,b-html5-1.1.2,b-print-1.1.2/datatables.min.css"/>
    
    
    <style>
    	a:hover{
    		text-decoration: none;
    	}
    	.odd .subBack {
    		background-color: #f0fcff;
    	}
    	.even .subBack {
    		background-color: #ecf7fa;
    	}
    	.floatLeft
    	{
    		float: left;
    	}

    </style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('bottom'); ?>

    <!-- DataTables JavaScript 
    <script src="<?php echo e(asset('uad/js/plugins/dataTables/jquery.dataTables.js')); ?>"></script>
    <script src="<?php echo e(asset('uad/js/plugins/dataTables/dataTables.bootstrap.js')); ?>"></script> -->
	<script type="text/javascript" src="https://cdn.datatables.net/t/bs/pdfmake-0.1.18,dt-1.10.11,b-1.1.2,b-flash-1.1.2,b-html5-1.1.2,b-print-1.1.2/datatables.min.js"></script>

	
    
    <!-- Page-Level Demo Scripts - Tables - Use for reference -->
    <script>
    $(document).ready(function() {
    var table1 =    $('#dataTables-example2').dataTable( {
					"pageLength": 100,
					"order": [[ 0, 'desc' ],[ 6, 'desc']],
					"stateSave" : false,
					"scrollX" : window.innerWidth < 800 ? true : false

					
        } );  
    var table2 =    $('#dataTables-example3').dataTable( {
		"pageLength": 100,
		"order": [ 0, 'asc' ],
		"stateSave" : false,
		"scrollX" : window.innerWidth < 800 ? true : false

		
} ); 


    });

    

    
    
    if ( typeof $.fn.dataTable == "function" && typeof $.fn.dataTableExt.fnVersionCheck == "function" && $.fn.dataTableExt.fnVersionCheck('1.9.2')/*older versions should work too*/ )
    {
        $.fn.dataTableExt.oApi.clearSearch = function ( oSettings )
        {
     
            var table = this;
             
            //any browser, must include your own file
            //var clearSearch = $('<img src="/images/delete.png" style="vertical-align:text-bottom;cursor:pointer;" alt="Delete" title="Delete"/>');
             
            //no image file needed, css embedding must be supported by browser
            var clearSearch = $('<i class="fa fa-times-circle-o fa-fw" style="vertical-align:text-bottom;cursor:pointer;color: gray;"></i>');
            $(clearSearch).click( function ()
                    {
                          table.fnFilter('');
                    });
            $(oSettings.nTableWrapper).find('div.dataTables_filter').append(clearSearch);
            $(oSettings.nTableWrapper).find('div.dataTables_filter label').css('margin-right', '-16px');//16px the image width
            $(oSettings.nTableWrapper).find('div.dataTables_filter input').css('padding-right', '16px');
        }
     
        //auto-execute, no code needs to be added
        $.fn.dataTable.models.oSettings['aoInitComplete'].push( {
            "fn": $.fn.dataTableExt.oApi.clearSearch,
            "sName": 'whatever'
        } );
    }

    </script> 

<?php $__env->stopSection(); ?>




<?php echo $__env->make('residential.templates.uadmin', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>