151 lines
6.5 KiB
PHP
151 lines
6.5 KiB
PHP
@extends('layouts.app')
|
|
|
|
@section('page_title', 'Fuel Price On Demand')
|
|
|
|
@section('content')
|
|
<div class="container-fluid">
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3 class="card-title">Fuel Price On Demand</h3>
|
|
<div class="card-tools">
|
|
<div class="btn-group">
|
|
<button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#importModal">
|
|
<i class="fas fa-file-import"></i> Import
|
|
</button>
|
|
<a href="{{ route('fuel-price.on-demand.export') }}" class="btn btn-primary">
|
|
<i class="fas fa-file-export"></i> Export
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
@if(session('success'))
|
|
<div class="alert alert-success">{{ session('success') }}</div>
|
|
@endif
|
|
@if(session('error'))
|
|
<div class="alert alert-danger">{{ session('error') }}</div>
|
|
@endif
|
|
|
|
<form action="{{ route('fuel-price.on-demand.update') }}" method="POST" class="mb-4">
|
|
@csrf
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered">
|
|
<thead>
|
|
<tr>
|
|
<th>Station</th>
|
|
@foreach($fuelTypes ?? [] as $fuelType)
|
|
<th>{{ $fuelType['name'] }}</th>
|
|
@endforeach
|
|
<th>Last Updated</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@forelse($prices ?? [] as $station)
|
|
<tr>
|
|
<td>{{ $station['name'] }}</td>
|
|
@foreach($fuelTypes ?? [] as $fuelType)
|
|
<td>
|
|
<input type="number"
|
|
class="form-control"
|
|
name="prices[{{ $station['id'] }}][{{ $fuelType['id'] }}]"
|
|
value="{{ $station['prices'][$fuelType['id']] ?? '' }}"
|
|
step="0.01"
|
|
min="0">
|
|
</td>
|
|
@endforeach
|
|
<td>{{ $station['last_updated'] ? \Carbon\Carbon::parse($station['last_updated'])->format('Y-m-d H:i:s') : '-' }}</td>
|
|
</tr>
|
|
@empty
|
|
<tr>
|
|
<td colspan="{{ count($fuelTypes ?? []) + 2 }}" class="text-center">No stations found</td>
|
|
</tr>
|
|
@endforelse
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="text-right mt-3">
|
|
<button type="submit" class="btn btn-primary">
|
|
<i class="fas fa-save"></i> Update Prices
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Import Modal -->
|
|
<div class="modal fade" id="importModal" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<form action="{{ route('fuel-price.on-demand.import') }}" method="POST" enctype="multipart/form-data">
|
|
@csrf
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Import Fuel Prices</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div class="mb-3">
|
|
<label for="csv_file" class="form-label">CSV File</label>
|
|
<input type="file"
|
|
class="form-control"
|
|
id="csv_file"
|
|
name="csv_file"
|
|
accept=".csv"
|
|
required>
|
|
<small class="form-text text-muted">
|
|
Please upload a CSV file with the following columns: Station ID, Fuel Type ID, Price
|
|
</small>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
|
<button type="submit" class="btn btn-primary">Import</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@endsection
|
|
|
|
@push('scripts')
|
|
<script>
|
|
$(document).ready(function() {
|
|
// Format number inputs
|
|
$('input[type="number"]').on('change', function() {
|
|
const value = parseFloat($(this).val());
|
|
if (!isNaN(value)) {
|
|
$(this).val(value.toFixed(2));
|
|
}
|
|
});
|
|
|
|
// Handle form submission
|
|
$('form').on('submit', function() {
|
|
const emptyInputs = $(this).find('input[type="number"]').filter(function() {
|
|
return !this.value;
|
|
});
|
|
|
|
if (emptyInputs.length > 0) {
|
|
if (!confirm('Some prices are empty. Do you want to continue?')) {
|
|
return false;
|
|
}
|
|
}
|
|
});
|
|
|
|
// Handle file input
|
|
$('#csv_file').on('change', function() {
|
|
const file = this.files[0];
|
|
const fileType = file.type || 'application/octet-stream';
|
|
|
|
if (fileType !== 'text/csv' && !file.name.endsWith('.csv')) {
|
|
alert('Please upload a CSV file');
|
|
this.value = '';
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
@endpush |