From 9e5a466a5bb602cb2511b906df387d8c36bb8463 Mon Sep 17 00:00:00 2001 From: armiejean Date: Fri, 16 May 2025 17:37:36 +0800 Subject: [PATCH] station function --- app/Http/Controllers/StationController.php | 200 ++++++++ .../components/station-component.blade.php | 467 ++++++++++++++++++ resources/views/pages/add-station.blade.php | 122 ++--- resources/views/pages/edit-station.blde.php | 49 ++ .../pages/station locator/stations.blade.php | 173 +------ resources/views/pages/view-station.blade.php | 41 ++ routes/web.php | 16 +- 7 files changed, 821 insertions(+), 247 deletions(-) create mode 100644 app/Http/Controllers/StationController.php create mode 100644 resources/views/components/station-component.blade.php create mode 100644 resources/views/pages/edit-station.blde.php create mode 100644 resources/views/pages/view-station.blade.php diff --git a/app/Http/Controllers/StationController.php b/app/Http/Controllers/StationController.php new file mode 100644 index 0000000..f8d6dad --- /dev/null +++ b/app/Http/Controllers/StationController.php @@ -0,0 +1,200 @@ + $request->input('page', 1), + 'page_size' => 5, + '_search' => $request->input('_search'), + 'sort' => $request->input('sort', 'code|asc'), + ]; + + $response = Http::get($this->apiBaseUrl . 'cms/getStations', $params); + $data = $response->json(); + + $stations = []; + $currentPage = $params['page']; + $lastPage = 1; + $total = 0; + + if ($response->successful() && isset($data['data'])) { + $stations = array_map(function ($item) { + return [ + 'id' => $item['station_uuid'], + 'station_code' => $item['code'], + 'station_name' => $item['description'], + 'branch_name' => 'N/A', // Mocked; replace with actual API field if available + 'date_created' => 'N/A', // Mocked + 'created_by' => 'N/A', // Mocked + 'modified_by' => 'N/A', // Mocked + 'date_modified' => 'N/A', // Mocked + ]; + }, $data['data']); + + // Mock pagination since API may not support it + $total = count($data['data']); + $lastPage = ceil($total / $params['page_size']); + $currentPage = min($currentPage, $lastPage); + + // Handle search client-side if API doesn't support _search + if ($params['_search']) { + $searchTerm = strtolower($params['_search']); + $stations = array_filter($stations, function ($station) use ($searchTerm) { + return str_contains(strtolower($station['station_code']), $searchTerm) || + str_contains(strtolower($station['station_name']), $searchTerm) || + str_contains(strtolower($station['branch_name']), $searchTerm); + }); + $stations = array_values($stations); + $total = count($stations); + $lastPage = ceil($total / $params['page_size']); + } + + // Handle sorting client-side if API doesn't support sort + if ($params['sort']) { + [$sortField, $sortDir] = explode('|', $params['sort']); + usort($stations, function ($a, $b) use ($sortField, $sortDir) { + $aValue = $a[$sortField] ?? ''; + $bValue = $b[$sortField] ?? ''; + return $sortDir === 'asc' ? strcmp($aValue, $bValue) : strcmp($bValue, $aValue); + }); + } + + // Paginate manually + $start = ($currentPage - 1) * $params['page_size']; + $stations = array_slice($stations, $start, $params['page_size']); + } + + return view('pages.station locator.stations', compact('stations', 'currentPage', 'lastPage', 'total')); + } + + // public function create() + // { + // return view('pages.add-station'); + // } + + // public function store(Request $request) + // { + // $request->validate([ + // 'station_code' => 'required|string|max:50|unique:stations,station_code', + // 'station_name' => 'required|string|max:255', + // 'branch_name' => 'required|string|max:255', + // ]); + + // // Mock API call to store station + // $response = Http::post($this->apiBaseUrl . 'cms/stations/store', [ + // 'code' => $request->station_code, + // 'description' => $request->station_name, + // 'branch_name' => $request->branch_name, + // 'is_viewable' => 1, + // 'is_active' => 1, + // ]); + + // if ($response->successful()) { + // return redirect()->route('station-management')->with('success', 'Station added successfully'); + // } + + // return back()->withErrors(['error' => 'Failed to add station']); + // } + + // public function show($id) + // { + // $response = Http::get($this->apiBaseUrl . 'cms/getStations'); + // $data = $response->json(); + + // $station = null; + // if ($response->successful() && isset($data['data'])) { + // $station = collect($data['data'])->firstWhere('station_uuid', $id); + // if ($station) { + // $station = [ + // 'id' => $station['station_uuid'], + // 'station_code' => $station['code'], + // 'station_name' => $station['description'], + // 'branch_name' => 'N/A', + // 'date_created' => 'N/A', + // 'created_by' => 'N/A', + // 'modified_by' => 'N/A', + // 'date_modified' => 'N/A', + // ]; + // } + // } + + // if (!$station) { + // abort(404, 'Station not found'); + // } + + // return view('pages.view-station', compact('station')); + // } + + // public function edit($id) + // { + // $response = Http::get($this->apiBaseUrl . 'cms/getStations'); + // $data = $response->json(); + + // $station = null; + // if ($response->successful() && isset($data['data'])) { + // $station = collect($data['data'])->firstWhere('station_uuid', $id); + // if ($station) { + // $station = [ + // 'id' => $station['station_uuid'], + // 'station_code' => $station['code'], + // 'station_name' => $station['description'], + // 'branch_name' => 'N/A', + // 'date_created' => 'N/A', + // 'created_by' => 'N/A', + // 'modified_by' => 'N/A', + // 'date_modified' => 'N/A', + // ]; + // } + // } + + // if (!$station) { + // abort(404, 'Station not found'); + // } + + // return view('pages.edit-station', compact('station')); + // } + + // public function update(Request $request, $id) + // { + // $request->validate([ + // 'station_code' => 'required|string|max:50|unique:stations,station_code,' . $id . ',id', + // 'station_name' => 'required|string|max:255', + // 'branch_name' => 'required|string|max:255', + // ]); + + // // Mock API call to update station + // $response = Http::put($this->apiBaseUrl . 'cms/stations/update/' . $id, [ + // 'code' => $request->station_code, + // 'description' => $request->station_name, + // 'branch_name' => $request->branch_name, + // ]); + + // if ($response->successful()) { + // return redirect()->route('station-management')->with('success', 'Station updated successfully'); + // } + + // return back()->withErrors(['error' => 'Failed to update station']); + // } + + // public function destroy($id) + // { + // // Mock API call to delete station + // $response = Http::delete($this->apiBaseUrl . 'cms/stations/delete/' . $id); + + // if ($response->successful()) { + // return redirect()->route('station-management')->with('success', 'Station deleted successfully'); + // } + + // return back()->withErrors(['error' => 'Failed to delete station']); + // } +} \ No newline at end of file diff --git a/resources/views/components/station-component.blade.php b/resources/views/components/station-component.blade.php new file mode 100644 index 0000000..38fd179 --- /dev/null +++ b/resources/views/components/station-component.blade.php @@ -0,0 +1,467 @@ +@props([ + 'pageTitle' => '', + 'data' => [], + 'columns' => [], + 'actions' => [], + 'showAddButton' => false, + 'addButtonUrl' => '#', + 'showCheckboxes' => false, + 'showBatchDelete' => false, + 'showEditModal' => false, + 'showViewModal' => false, + 'currentPage' => 1, + 'lastPage' => 1, + 'total' => 0, +]) + +
+
+
{{ $pageTitle }}
+ @if ($showAddButton) + + Add {{ $pageTitle }} + + @endif +
+
+
+ +
+
+
+ + + + +
+
+
+ +
+
+ + +
+ + + + @if ($showCheckboxes) + + @endif + @foreach ($columns as $index => $column) + + @endforeach + @if (!empty($actions)) + + @endif + + + +
+ + + {{ $column['name'] }} + @if ($column['sortable']) + + @endif + Action
+
+ + +
+ @if ($showBatchDelete) +
+ +
+ @endif + +
+
+ + +@if ($showEditModal) + +@endif + + +@if ($showViewModal) + +@endif + + + + + + \ No newline at end of file diff --git a/resources/views/pages/add-station.blade.php b/resources/views/pages/add-station.blade.php index 9305ce0..d7011aa 100644 --- a/resources/views/pages/add-station.blade.php +++ b/resources/views/pages/add-station.blade.php @@ -3,84 +3,46 @@ @section('page_title', 'Add Station') @section('content') - -
-
Add New Station
+
+
+
+
+
{{ __('Add Station') }}
+
+ @if (session('success')) +
{{ session('success') }}
+ @endif + @if ($errors->any()) +
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+ @endif +
+ @csrf +
+ + +
+
+ + +
+
+ + +
+
+ {{ __('Cancel') }} + +
+
+
+
+
+
-
-
- @csrf -
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- Cancel - -
-
-
- - -@endsection +@endsection \ No newline at end of file diff --git a/resources/views/pages/edit-station.blde.php b/resources/views/pages/edit-station.blde.php new file mode 100644 index 0000000..dd91333 --- /dev/null +++ b/resources/views/pages/edit-station.blde.php @@ -0,0 +1,49 @@ +@extends('layouts.app') + +@section('page_title', 'Edit Station') + +@section('content') +
+
+
+
+
{{ __('Edit Station') }}
+
+ @if (session('success')) +
{{ session('success') }}
+ @endif + @if ($errors->any()) +
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+ @endif +
+ @csrf + @method('PUT') +
+ + +
+
+ + +
+
+ + +
+
+ {{ __('Cancel') }} + +
+
+
+
+
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/pages/station locator/stations.blade.php b/resources/views/pages/station locator/stations.blade.php index 2427553..b476bea 100644 --- a/resources/views/pages/station locator/stations.blade.php +++ b/resources/views/pages/station locator/stations.blade.php @@ -3,164 +3,9 @@ @section('page_title', 'Station Management') @section('content') - @php - $stations = [ - [ - 'id' => 1, - 'station_code' => 'ST001', - 'station_name' => 'North Station', - 'branch_name' => 'Quezon City Branch', - 'date_created' => '2023-05-01', - 'created_by' => 'Maryse Howe', - 'modified_by' => 'Joseph Sazon', - 'date_modified' => '2023-06-15' - ], - [ - 'id' => 2, - 'station_code' => 'ST002', - 'station_name' => 'East Hub', - 'branch_name' => 'Pasig Branch', - 'date_created' => '2023-05-10', - 'created_by' => 'Graxia Montino', - 'modified_by' => 'Cine Rosimo', - 'date_modified' => '2023-07-01' - ], - [ - 'id' => 3, - 'station_code' => 'ST003', - 'station_name' => 'West Terminal', - 'branch_name' => 'Makati Branch', - 'date_created' => '2023-06-20', - 'created_by' => 'Cine Rosimo', - 'modified_by' => 'Graxia Montino', - 'date_modified' => '2023-08-05' - ], - [ - 'id' => 4, - 'station_code' => 'ST004', - 'station_name' => 'Central Depot', - 'branch_name' => 'Manila Branch', - 'date_created' => '2023-07-05', - 'created_by' => 'Maryse Howe', - 'modified_by' => 'Maryse Howe', - 'date_modified' => '2023-09-10' - ], - [ - 'id' => 5, - 'station_code' => 'ST005', - 'station_name' => 'South Station', - 'branch_name' => 'Parañaque Branch', - 'date_created' => '2023-08-15', - 'created_by' => 'Joseph Sazon', - 'modified_by' => 'Graxia Montino', - 'date_modified' => '2023-10-01' -], -[ - 'id' => 1, - 'station_code' => 'ST001', - 'station_name' => 'North Station', - 'branch_name' => 'Quezon City Branch', - 'date_created' => '2023-05-01', - 'created_by' => 'Maryse Howe', - 'modified_by' => 'Joseph Sazon', - 'date_modified' => '2023-06-15' - ], - [ - 'id' => 2, - 'station_code' => 'ST002', - 'station_name' => 'East Hub', - 'branch_name' => 'Pasig Branch', - 'date_created' => '2023-05-10', - 'created_by' => 'Graxia Montino', - 'modified_by' => 'Cine Rosimo', - 'date_modified' => '2023-07-01' - ], - [ - 'id' => 3, - 'station_code' => 'ST003', - 'station_name' => 'West Terminal', - 'branch_name' => 'Makati Branch', - 'date_created' => '2023-06-20', - 'created_by' => 'Cine Rosimo', - 'modified_by' => 'Graxia Montino', - 'date_modified' => '2023-08-05' - ], - [ - 'id' => 4, - 'station_code' => 'ST004', - 'station_name' => 'Central Depot', - 'branch_name' => 'Manila Branch', - 'date_created' => '2023-07-05', - 'created_by' => 'Maryse Howe', - 'modified_by' => 'Maryse Howe', - 'date_modified' => '2023-09-10' - ], - [ - 'id' => 5, - 'station_code' => 'ST005', - 'station_name' => 'South Station', - 'branch_name' => 'Parañaque Branch', - 'date_created' => '2023-08-15', - 'created_by' => 'Joseph Sazon', - 'modified_by' => 'Graxia Montino', - 'date_modified' => '2023-10-01' -], - [ - 'id' => 1, - 'station_code' => 'ST001', - 'station_name' => 'North Station', - 'branch_name' => 'Quezon City Branch', - 'date_created' => '2023-05-01', - 'created_by' => 'Maryse Howe', - 'modified_by' => 'Joseph Sazon', - 'date_modified' => '2023-06-15' - ], - [ - 'id' => 2, - 'station_code' => 'ST002', - 'station_name' => 'East Hub', - 'branch_name' => 'Pasig Branch', - 'date_created' => '2023-05-10', - 'created_by' => 'Graxia Montino', - 'modified_by' => 'Cine Rosimo', - 'date_modified' => '2023-07-01' - ], - [ - 'id' => 3, - 'station_code' => 'ST003', - 'station_name' => 'West Terminal', - 'branch_name' => 'Makati Branch', - 'date_created' => '2023-06-20', - 'created_by' => 'Cine Rosimo', - 'modified_by' => 'Graxia Montino', - 'date_modified' => '2023-08-05' - ], - [ - 'id' => 4, - 'station_code' => 'ST004', - 'station_name' => 'Central Depot', - 'branch_name' => 'Manila Branch', - 'date_created' => '2023-07-05', - 'created_by' => 'Maryse Howe', - 'modified_by' => 'Maryse Howe', - 'date_modified' => '2023-09-10' - ], - [ - 'id' => 5, - 'station_code' => 'ST005', - 'station_name' => 'South Station', - 'branch_name' => 'Parañaque Branch', - 'date_created' => '2023-08-15', - 'created_by' => 'Joseph Sazon', - 'modified_by' => 'Graxia Montino', - 'date_modified' => '2023-10-01' -], - ]; - @endphp - - @include('components.table-component', [ + @include('components.station-component', [ 'pageTitle' => 'Station Management', - 'data' => $stations, + 'data' => $stations ?? [], 'columns' => [ ['name' => 'Station Code', 'key' => 'station_code', 'sortable' => true], ['name' => 'Station Name', 'key' => 'station_name', 'sortable' => true], @@ -170,12 +15,18 @@ ['name' => 'Modified By', 'key' => 'modified_by', 'sortable' => true], ['name' => 'Date Modified', 'key' => 'date_modified', 'sortable' => true] ], - 'actions' => ['edit', 'view', 'delete'], + 'actions' => ['view', 'edit', 'delete'], 'showAddButton' => true, - 'addButtonUrl' => '/add-station', + 'addButtonUrl' => route('stations.create'), 'showCheckboxes' => false, 'showBatchDelete' => false, 'showEditModal' => true, - 'showViewModal' => true + 'showViewModal' => true, + 'currentPage' => $currentPage ?? 1, + 'lastPage' => $lastPage ?? 1, + 'total' => $total ?? 0, ]) -@endsection +
+

No stations found.

+
+@endsection \ No newline at end of file diff --git a/resources/views/pages/view-station.blade.php b/resources/views/pages/view-station.blade.php new file mode 100644 index 0000000..4d45e85 --- /dev/null +++ b/resources/views/pages/view-station.blade.php @@ -0,0 +1,41 @@ +@extends('layouts.app') + +@section('page_title', 'View Station') + +@section('content') +
+
+
+
+
{{ __('Station Details') }}
+
+
+ {{ __('Station Code') }}: {{ $station['station_code'] }} +
+
+ {{ __('Station Name') }}: {{ $station['station_name'] }} +
+
+ {{ __('Branch Name') }}: {{ $station['branch_name'] }} +
+
+ {{ __('Date Created') }}: {{ $station['date_created'] }} +
+
+ {{ __('Created By') }}: {{ $station['created_by'] }} +
+
+ {{ __('Modified By') }}: {{ $station['modified_by'] }} +
+
+ {{ __('Date Modified') }}: {{ $station['date_modified'] }} +
+ +
+
+
+
+
+@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 646c716..d19ece1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -12,7 +12,7 @@ use App\Http\Controllers\PromotionController; use App\Http\Controllers\TermsAndPrivacyController; use App\Http\Controllers\CardTypeController; use App\Http\Controllers\ReportsController; - +use App\Http\Controllers\StationController; Route::get('/', function () { return redirect()->route('login'); @@ -55,9 +55,7 @@ Route::get('/branches', function () { return view('pages.station locator.branches'); })->name('branches'); -Route::get('/stations', function () { - return view('pages.station locator.stations'); -})->name('stations'); + Route::get('/fuels', function () { return view('pages.station locator.fuels'); @@ -205,6 +203,12 @@ Route::get('/registration-report', [ReportsController::class, 'registration'])-> Route::get('/station-rating-report', [ReportsController::class, 'stationRating'])->name('station-rating-report'); Route::get('/top-up-usage-report', [ReportsController::class, 'topUp'])->name('top-up-usage-report'); - - +//Station +Route::get('/station-management', [StationController::class, 'index'])->name('stations'); +Route::get('/stations/create', [StationController::class, 'create'])->name('stations.create'); +// Route::post('/stations', [StationController::class, 'store'])->name('stations.store'); +// Route::get('/stations/{id}', [StationController::class, 'show'])->name('stations.show'); +// Route::get('/stations/{id}/edit', [StationController::class, 'edit'])->name('stations.edit'); +// Route::put('/stations/{id}', [StationController::class, 'update'])->name('stations.update'); +// Route::delete('/stations/{id}', [StationController::class, 'destroy'])->name('stations.destroy');