diff --git a/database/migrations/2023_05_17_000013_create_pamtechoga_fuel_prices_table.php b/database/migrations/2023_05_17_000013_create_pamtechoga_fuel_prices_table.php index ec8385a..f6331c8 100644 --- a/database/migrations/2023_05_17_000013_create_pamtechoga_fuel_prices_table.php +++ b/database/migrations/2023_05_17_000013_create_pamtechoga_fuel_prices_table.php @@ -16,6 +16,7 @@ public function up() Schema::create('pamtechoga_fuel_prices', function (Blueprint $table) { $table->increments('id'); $table->string('company_name'); + $table->integer('zone_id')->nullable(); $table->float('petrol'); $table->float('diesel')->nullable(); $table->float('premium')->nullable(); diff --git a/database/migrations/2023_05_17_000020_create_pamtechoga_zones_table.php b/database/migrations/2023_05_17_000020_create_pamtechoga_zones_table.php new file mode 100644 index 0000000..a018a50 --- /dev/null +++ b/database/migrations/2023_05_17_000020_create_pamtechoga_zones_table.php @@ -0,0 +1,34 @@ +increments('id'); + $table->string('name'); + $table->boolean('is_deleted')->default(false); + $table->dateTime('created_at')->nullable(); + $table->dateTime('updated_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('pamtechoga_reviews'); + } +} diff --git a/resources/views/models/fuel-prices/form.blade.php b/resources/views/models/fuel-prices/form.blade.php index 0f8b768..572b479 100644 --- a/resources/views/models/fuel-prices/form.blade.php +++ b/resources/views/models/fuel-prices/form.blade.php @@ -17,6 +17,17 @@ + + + @foreach($this->allZones() as $data) + + @endforeach + + @endisset + @if($this->shouldShowColumn('zone')) + + {{ $data->zone?->name }} + + @endif + @if($this->shouldShowColumn('petrol')) {{ $data->petrol }} diff --git a/resources/views/models/orders/index.blade.php b/resources/views/models/orders/index.blade.php index 45fcd0a..498d2a6 100644 --- a/resources/views/models/orders/index.blade.php +++ b/resources/views/models/orders/index.blade.php @@ -104,7 +104,8 @@ @endisset - Edit + Edit • + Breakdown @endforeach diff --git a/resources/views/models/organizationOrders/index.blade.php b/resources/views/models/organizationOrders/index.blade.php index aca29e7..e029645 100644 --- a/resources/views/models/organizationOrders/index.blade.php +++ b/resources/views/models/organizationOrders/index.blade.php @@ -1,3 +1,6 @@ +@php + use Carbon\Carbon; +@endphp - {{ $data->created_at->toFormattedDateString() }} + {{ Carbon::parse($data->order_date)->toFormattedDateString() }} @endisset diff --git a/resources/views/models/zones/form.blade.php b/resources/views/models/zones/form.blade.php new file mode 100644 index 0000000..2d4851b --- /dev/null +++ b/resources/views/models/zones/form.blade.php @@ -0,0 +1,75 @@ + + + @include('lego::models._includes.forms.page-actions') + + + + + + + + + + + + + @foreach($this->model->stations as $data) +
+ + +
+ + +
+
+ + + View + + +
+
+ @endforeach +
+
+ + + @include('pamtechoga::models.components.timestamp') + + +
+
+ +@push('styles') + +@endpush diff --git a/resources/views/models/zones/index.blade.php b/resources/views/models/zones/index.blade.php new file mode 100644 index 0000000..6b432f8 --- /dev/null +++ b/resources/views/models/zones/index.blade.php @@ -0,0 +1,46 @@ + + + Create + + + @include('lego::models._includes.indexes.filters') + + + + @include('lego::models._includes.indexes.headers') + Edit + + + @include('lego::models._includes.indexes.header-filters') + + + @foreach($models as $data) + + @if($this->shouldShowColumn('name')) + + {{ $data->name }} ({{ count($data->stations) }} stations) + + @endif + + @if($this->shouldShowColumn('updated_at')) + + {{ $data->updated_at->toFormattedDateString() }} + + @endisset + + + Edit + + + @endforeach + + + @include('lego::models._includes.indexes.pagination') + diff --git a/routes/api.php b/routes/api.php index 3a3f6e3..051291e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -32,6 +32,7 @@ Route::get('/order-reviews', [ReviewsController::class, 'orderReviews'])->middleware('auth:sanctum'); Route::get('/fuel-prices', [DashboardController::class, 'fuelPrices'])->middleware('auth:sanctum'); +Route::get('/zones-and-stations', [DashboardController::class, 'zonesAndStations'])->middleware('auth:sanctum'); Route::get('/dashboard/stats', [DashboardController::class, 'dashboard'])->middleware('auth:sanctum'); diff --git a/routes/backend.php b/routes/backend.php index e355449..e981d7f 100644 --- a/routes/backend.php +++ b/routes/backend.php @@ -38,6 +38,8 @@ use Vibraniuum\Pamtechoga\Http\Livewire\SalesIndex; use Vibraniuum\Pamtechoga\Http\Livewire\TrucksForm; use Vibraniuum\Pamtechoga\Http\Livewire\TrucksIndex; +use Vibraniuum\Pamtechoga\Http\Livewire\ZonesForm; +use Vibraniuum\Pamtechoga\Http\Livewire\ZonesIndex; Route::group([ 'as' => 'pamtechoga.', @@ -193,4 +195,14 @@ Route::get('/{announcement}/edit', AnnouncementsForm::class)->name('edit'); }); + // Zones + Route::group([ + 'as' => 'zones.', + 'prefix' => 'zones/' + ], function() { + Route::get('/', ZonesIndex::class)->name('index'); + Route::get('/create', ZonesForm::class)->name('create'); + Route::get('/{zone}/edit', ZonesForm::class)->name('edit'); + }); + }); diff --git a/src/Http/Controllers/Api/DashboardController.php b/src/Http/Controllers/Api/DashboardController.php index 5d06d84..446b7cb 100644 --- a/src/Http/Controllers/Api/DashboardController.php +++ b/src/Http/Controllers/Api/DashboardController.php @@ -13,6 +13,7 @@ use Vibraniuum\Pamtechoga\Models\OrganizationUser; use Vibraniuum\Pamtechoga\Models\Payment; use Vibraniuum\Pamtechoga\Models\Product; +use Vibraniuum\Pamtechoga\Models\Zone; /** * @group Order management @@ -112,4 +113,14 @@ public function fuelPrices(): JsonResponse 'data' => $fuelPrices, ]); } + + public function zonesAndStations(): JsonResponse + { + $stations = Zone::with('stations')->get(); + + return response()->json([ + 'status' => true, + 'data' => $stations, + ]); + } } diff --git a/src/Http/Livewire/FuelPricesForm.php b/src/Http/Livewire/FuelPricesForm.php index 64439a5..2dba364 100644 --- a/src/Http/Livewire/FuelPricesForm.php +++ b/src/Http/Livewire/FuelPricesForm.php @@ -5,6 +5,7 @@ use Helix\Lego\Http\Livewire\Models\Form; use Vibraniuum\Pamtechoga\Events\FuelPriceUpdated; use Vibraniuum\Pamtechoga\Models\FuelPrice; +use Vibraniuum\Pamtechoga\Models\Zone; class FuelPricesForm extends Form { @@ -13,6 +14,7 @@ class FuelPricesForm extends Form public function rules() { return [ + 'model.zone_id' => 'required', 'model.company_name' => 'required', 'model.petrol' => 'required', 'model.diesel' => 'nullable', @@ -36,6 +38,11 @@ public function model(): string return FuelPrice::class; } + public function allZones() + { + return Zone::all(); + } + public function saved() { $this->model->logo = $this->model->getFirstMedia('Logo')->getUrl(); diff --git a/src/Http/Livewire/FuelPricesIndex.php b/src/Http/Livewire/FuelPricesIndex.php index 6fb0ec6..7414ba6 100644 --- a/src/Http/Livewire/FuelPricesIndex.php +++ b/src/Http/Livewire/FuelPricesIndex.php @@ -18,6 +18,7 @@ public function columns(): array { return [ 'company_name' => 'Account Name', + 'zone' => 'Zone', 'petrol' => 'Petrol (NGN)', 'diesel' => 'Diesel (NGN)', 'premium' => 'Premium (NGN)', diff --git a/src/Http/Livewire/OrganizationOrdersIndex.php b/src/Http/Livewire/OrganizationOrdersIndex.php index ed1ed4e..a31bee7 100644 --- a/src/Http/Livewire/OrganizationOrdersIndex.php +++ b/src/Http/Livewire/OrganizationOrdersIndex.php @@ -43,7 +43,7 @@ public function columns(): array return [ // 'organization_name' => 'Organization Name', - 'date' => 'Date', + 'date' => 'Order Date', 'product' => 'Product Type', 'volume' => 'Volume (Litres)', 'unit_price' => 'Unit Price (NGN)', @@ -252,7 +252,7 @@ public function exportAsCSV() // Write the orders data rows foreach ($this->orders as $order) { $row = []; - $row[] = $order->created_at->format('Y-m-d'); + $row[] = $order->order_date?->format('Y-m-d'); $row[] = $order->product->type; $row[] = number_format($order->volume); $row[] = number_format($order->unit_price); diff --git a/src/Http/Livewire/ZonesForm.php b/src/Http/Livewire/ZonesForm.php new file mode 100644 index 0000000..a36af07 --- /dev/null +++ b/src/Http/Livewire/ZonesForm.php @@ -0,0 +1,33 @@ + 'required', + ]; + } + + public function mount($zone = null) + { + $this->setModel($zone); + } + + public function view() + { + return 'pamtechoga::models.zones.form'; + } + + public function model(): string + { + return Zone::class; + } +} diff --git a/src/Http/Livewire/ZonesIndex.php b/src/Http/Livewire/ZonesIndex.php new file mode 100644 index 0000000..a18ed24 --- /dev/null +++ b/src/Http/Livewire/ZonesIndex.php @@ -0,0 +1,36 @@ + 'Zone Name', + 'updated_at' => 'Last updated', + ]; + } + + public function mainSearchColumn(): string|false + { + return 'name'; + } + + public function render() + { + return view('pamtechoga::models.zones.index', [ + 'models' => $this->getModels(), + ])->extends('lego::layouts.lego')->section('content'); + } +} diff --git a/src/Models/FuelPrice.php b/src/Models/FuelPrice.php index d8d6137..e6a4045 100644 --- a/src/Models/FuelPrice.php +++ b/src/Models/FuelPrice.php @@ -37,4 +37,9 @@ public static function getDisplayKeyName(): string { return 'company_name'; } + + public function zone() + { + return $this->belongsTo(Zone::class); + } } diff --git a/src/Models/Zone.php b/src/Models/Zone.php new file mode 100644 index 0000000..9e40349 --- /dev/null +++ b/src/Models/Zone.php @@ -0,0 +1,70 @@ +where('name', 'LIKE', '%' . $value . '%'); + } + + public function searchableName(): string + { + return $this->name; + } + + public function searchableDescription(): string + { + return Str::limit($this->name ?? '', 60); + } + + public function searchableRoute(): string + { + return route('lego.pamtechoga.zones.edit', $this); + } + + public function stations() + { + return $this->hasMany(FuelPrice::class); + } +} diff --git a/src/PamtechogaServiceProvider.php b/src/PamtechogaServiceProvider.php index c97e3c0..b0e7a21 100644 --- a/src/PamtechogaServiceProvider.php +++ b/src/PamtechogaServiceProvider.php @@ -58,6 +58,8 @@ use Vibraniuum\Pamtechoga\Http\Livewire\Timestamp; use Vibraniuum\Pamtechoga\Http\Livewire\TrucksForm; use Vibraniuum\Pamtechoga\Http\Livewire\TrucksIndex; +use Vibraniuum\Pamtechoga\Http\Livewire\ZonesForm; +use Vibraniuum\Pamtechoga\Http\Livewire\ZonesIndex; use Vibraniuum\Pamtechoga\Models\Organization; use Vibraniuum\Pamtechoga\Settings\PamtechogaSettings; @@ -146,6 +148,12 @@ public function registerApp(App $app) ->icon(Icon::FOLDER_OPEN) ->after('Models') ); + $menu->addToSection( + Menu::MAIN_SECTIONS['PRIMARY'], + Link::to(route('lego.pamtechoga.zones.index'), 'Zones') + ->icon(Icon::FOLDER_OPEN) + ->after('Fuel Prices') + ); }) ->backendRoutes(__DIR__.'/../routes/backend.php') ->apiRoutes(__DIR__.'/../routes/api.php') @@ -207,6 +215,8 @@ public function bootingPackage() Livewire::component('astrogoat.pamtechoga.http.livewire.pamtechoga-news-form', NewsForm::class); Livewire::component('astrogoat.pamtechoga.http.livewire.pamtechoga-announcements-index', AnnouncementsIndex::class); Livewire::component('astrogoat.pamtechoga.http.livewire.pamtechoga-announcements-form', AnnouncementsForm::class); + Livewire::component('astrogoat.pamtechoga.http.livewire.pamtechoga-zones-index', ZonesIndex::class); + Livewire::component('astrogoat.pamtechoga.http.livewire.pamtechoga-zones-form', ZonesForm::class); Livewire::component('pamtechoga-datefilter-form', DateFilter::class); Livewire::component('pamtechoga-dashboard', Dashboard::class); }