120 lines
3.3 KiB
PHP
120 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\Api\FuelPriceService;
|
|
use Illuminate\Http\Request;
|
|
|
|
class FuelPriceController extends Controller
|
|
{
|
|
protected $fuelPriceService;
|
|
|
|
public function __construct(FuelPriceService $fuelPriceService)
|
|
{
|
|
$this->fuelPriceService = $fuelPriceService;
|
|
}
|
|
|
|
public function onDemand()
|
|
{
|
|
$response = $this->fuelPriceService->getCurrentPrices();
|
|
|
|
if (!$response['success']) {
|
|
return back()->with('error', $response['message']);
|
|
}
|
|
|
|
return view('pages.fuel-price-on-demand', [
|
|
'prices' => $response['data']
|
|
]);
|
|
}
|
|
|
|
public function updateOnDemand(Request $request)
|
|
{
|
|
$response = $this->fuelPriceService->updatePrices($request->all());
|
|
|
|
if (!$response['success']) {
|
|
return back()->withInput()->with('error', $response['message']);
|
|
}
|
|
|
|
return redirect()->route('fuel-price.on-demand')
|
|
->with('success', 'Fuel prices updated successfully');
|
|
}
|
|
|
|
public function schedule()
|
|
{
|
|
$response = $this->fuelPriceService->getScheduledUpdates();
|
|
|
|
if (!$response['success']) {
|
|
return back()->with('error', $response['message']);
|
|
}
|
|
|
|
return view('pages.fuel-price-schedule', [
|
|
'schedules' => $response['data']
|
|
]);
|
|
}
|
|
|
|
public function storeSchedule(Request $request)
|
|
{
|
|
$response = $this->fuelPriceService->createSchedule($request->all());
|
|
|
|
if (!$response['success']) {
|
|
return back()->withInput()->with('error', $response['message']);
|
|
}
|
|
|
|
return redirect()->route('fuel-price.schedule')
|
|
->with('success', 'Price update scheduled successfully');
|
|
}
|
|
|
|
public function updateSchedule(Request $request, $id)
|
|
{
|
|
$response = $this->fuelPriceService->updateSchedule($id, $request->all());
|
|
|
|
if (!$response['success']) {
|
|
return back()->withInput()->with('error', $response['message']);
|
|
}
|
|
|
|
return redirect()->route('fuel-price.schedule')
|
|
->with('success', 'Schedule updated successfully');
|
|
}
|
|
|
|
public function deleteSchedule($id)
|
|
{
|
|
$response = $this->fuelPriceService->deleteSchedule($id);
|
|
|
|
if (!$response['success']) {
|
|
return back()->with('error', $response['message']);
|
|
}
|
|
|
|
return redirect()->route('fuel-price.schedule')
|
|
->with('success', 'Schedule deleted successfully');
|
|
}
|
|
|
|
public function logs()
|
|
{
|
|
$response = $this->fuelPriceService->getUpdateLogs();
|
|
|
|
if (!$response['success']) {
|
|
return back()->with('error', $response['message']);
|
|
}
|
|
|
|
return view('pages.fuel-price-update-logs', [
|
|
'logs' => $response['data']
|
|
]);
|
|
}
|
|
|
|
public function importPrices(Request $request)
|
|
{
|
|
$response = $this->fuelPriceService->importPrices($request->file('csv_file'));
|
|
|
|
if (!$response['success']) {
|
|
return back()->withInput()->with('error', $response['message']);
|
|
}
|
|
|
|
return redirect()->route('fuel-price.on-demand')
|
|
->with('success', 'Fuel prices imported successfully');
|
|
}
|
|
|
|
public function exportPrices()
|
|
{
|
|
return $this->fuelPriceService->exportPrices();
|
|
}
|
|
}
|