Skip to content

Commit

Permalink
Implement zones
Browse files Browse the repository at this point in the history
  • Loading branch information
OniiCoder committed Feb 9, 2024
1 parent f87f4d0 commit f688160
Show file tree
Hide file tree
Showing 19 changed files with 367 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePamtechogaZonesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('pamtechoga_zones', function (Blueprint $table) {
$table->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');
}
}
11 changes: 11 additions & 0 deletions resources/views/models/fuel-prices/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
<x-fab::layouts.main-with-aside>
<x-fab::layouts.panel>

<x-fab::forms.select
wire:model="model.zone_id"
label="Zone"
help="This is the zone this filling station belongs to."
>
<option value="0">-- Choose Zone --</option>
@foreach($this->allZones() as $data)
<option value="{{ $data->id }}">{{ $data->name }}</option>
@endforeach
</x-fab::forms.select>

<x-fab::forms.input
wire:model="model.company_name"
label="Company Name"
Expand Down
6 changes: 6 additions & 0 deletions resources/views/models/fuel-prices/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
</x-fab::lists.table.column>
@endisset

@if($this->shouldShowColumn('zone'))
<x-fab::lists.table.column>
<a href="{{ route('lego.pamtechoga.fuel-prices.edit', $data) }}">{{ $data->zone?->name }}</a>
</x-fab::lists.table.column>
@endif

@if($this->shouldShowColumn('petrol'))
<x-fab::lists.table.column>
<a href="{{ route('lego.pamtechoga.fuel-prices.edit', $data) }}">{{ $data->petrol }}</a>
Expand Down
3 changes: 2 additions & 1 deletion resources/views/models/orders/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
@endisset

<x-fab::lists.table.column align="right" slim>
<a href="{{ route('lego.pamtechoga.orders.edit', $data) }}">Edit</a>
<a href="{{ route('lego.pamtechoga.orders.edit', $data) }}">Edit</a> •
<a href="{{ route('lego.pamtechoga.organizations.organizationOrders', $data->organization) }}">Breakdown</a>
</x-fab::lists.table.column>
</x-fab::lists.table.row>
@endforeach
Expand Down
5 changes: 4 additions & 1 deletion resources/views/models/organizationOrders/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
@php
use Carbon\Carbon;
@endphp
<x-fab::layouts.page
title="{{ \Vibraniuum\Pamtechoga\Models\Organization::where('id', $this->organization)->first()->name }}'s Orders and Payments Breakdown"
:breadcrumbs="[
Expand Down Expand Up @@ -114,7 +117,7 @@

@if($this->shouldShowColumn('date'))
<x-fab::lists.table.column align="right">
{{ $data->created_at->toFormattedDateString() }}
{{ Carbon::parse($data->order_date)->toFormattedDateString() }}
</x-fab::lists.table.column>
@endisset

Expand Down
75 changes: 75 additions & 0 deletions resources/views/models/zones/form.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<x-fab::layouts.page
:title="$model?->name ?: 'Untitled'"
:breadcrumbs="[
['title' => 'Home', 'url' => route('lego.dashboard')],
['title' => 'Zones', 'url' => route('lego.pamtechoga.zones.index')],
['title' => $model?->name ?: 'Untitled'],
]"
x-data=""
x-on:keydown.meta.s.window.prevent="$wire.call('save')" {{-- For Mac --}}
x-on:keydown.ctrl.s.window.prevent="$wire.call('save')" {{-- For PC --}}
>
<x-slot name="actions">
@include('lego::models._includes.forms.page-actions')
</x-slot>
<x-lego::feedback.errors class="sh-mb-4" />

<x-fab::layouts.main-with-aside>
<x-fab::layouts.panel>

<x-fab::forms.input
wire:model="model.name"
label="Zone name"
help="This is the name of the zone."
/>

</x-fab::layouts.panel>

<x-fab::layouts.panel
title="Stations"
description="Below are the stations in this zone."
class="sh-mt-4"
>
<x-fab::lists.stacked
>
@foreach($this->model->stations as $data)
<div
x-sortable.products.item="{{ $data->id }}"
>
<x-fab::lists.stacked.grouped-with-actions
:title="$data?->company_name"
description="{{ $data->updated_at->toFormattedDateString() }}"
>
<x-slot name="avatar">
<div class="flex">
<x-fab::elements.icon icon="dots-vertical" x-sortable.products.handle
class="sh-h-5 sh-w-5 sh-text-gray-300 sh--mr-2"/>
<x-fab::elements.icon icon="dots-vertical" x-sortable.products.handle
class="sh-h-5 sh-w-5 sh-text-gray-300 sh--ml-1.5"/>
</div>
</x-slot>
<x-slot name="actions">
<x-fab::elements.button
size="xs"
type="link"
:url="route('lego.pamtechoga.fuel-prices.edit', $data)"
>
View
</x-fab::elements.button>
</x-slot>
</x-fab::lists.stacked.grouped-with-actions>
</div>
@endforeach
</x-fab::lists.stacked>
</x-fab::layouts.panel>

<x-slot name="aside">
@include('pamtechoga::models.components.timestamp')
</x-slot>

</x-fab::layouts.main-with-aside>
</x-fab::layouts.page>

@push('styles')
<link href="{{ asset('vendor/pamtechoga/css/pamtechoga.css') }}" rel="stylesheet">
@endpush
46 changes: 46 additions & 0 deletions resources/views/models/zones/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<x-fab::layouts.page
title="Zones"
:breadcrumbs="[
['title' => 'Home', 'url' => route('lego.dashboard')],
['title' => 'Zones','url' => route('lego.pamtechoga.zones.index')],
]"
x-data="{ showColumnFilters: false }"
>
<x-slot name="actions">
<x-fab::elements.button type="link" :url="route('lego.pamtechoga.zones.create')">Create</x-fab::elements.button>
</x-slot>

@include('lego::models._includes.indexes.filters')

<x-fab::lists.table>
<x-slot name="headers">
@include('lego::models._includes.indexes.headers')
<x-fab::lists.table.header :hidden="true">Edit</x-fab::lists.table.header>
</x-slot>

@include('lego::models._includes.indexes.header-filters')
<x-fab::lists.table.header x-show="showColumnFilters" x-cloak class="bg-gray-100" />

@foreach($models as $data)
<x-fab::lists.table.row :odd="$loop->odd">
@if($this->shouldShowColumn('name'))
<x-fab::lists.table.column primary full>
<a href="{{ route('lego.pamtechoga.zones.edit', $data) }}">{{ $data->name }} ({{ count($data->stations) }} stations)</a>
</x-fab::lists.table.column>
@endif

@if($this->shouldShowColumn('updated_at'))
<x-fab::lists.table.column align="right">
{{ $data->updated_at->toFormattedDateString() }}
</x-fab::lists.table.column>
@endisset

<x-fab::lists.table.column align="right" slim>
<a href="{{ route('lego.pamtechoga.zones.edit', $data) }}">Edit</a>
</x-fab::lists.table.column>
</x-fab::lists.table.row>
@endforeach
</x-fab::lists.table>

@include('lego::models._includes.indexes.pagination')
</x-fab::layouts.page>
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
12 changes: 12 additions & 0 deletions routes/backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down Expand Up @@ -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');
});

});
11 changes: 11 additions & 0 deletions src/Http/Controllers/Api/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
]);
}
}
7 changes: 7 additions & 0 deletions src/Http/Livewire/FuelPricesForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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',
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/Http/Livewire/FuelPricesIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function columns(): array
{
return [
'company_name' => 'Account Name',
'zone' => 'Zone',
'petrol' => 'Petrol (NGN)',
'diesel' => 'Diesel (NGN)',
'premium' => 'Premium (NGN)',
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Livewire/OrganizationOrdersIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand Down Expand Up @@ -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);
Expand Down
33 changes: 33 additions & 0 deletions src/Http/Livewire/ZonesForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Vibraniuum\Pamtechoga\Http\Livewire;

use Helix\Lego\Http\Livewire\Models\Form;
use Vibraniuum\Pamtechoga\Models\Zone;

class ZonesForm extends Form
{
protected bool $canBeViewed = false;

public function rules()
{
return [
'model.name' => 'required',
];
}

public function mount($zone = null)
{
$this->setModel($zone);
}

public function view()
{
return 'pamtechoga::models.zones.form';
}

public function model(): string
{
return Zone::class;
}
}
Loading

0 comments on commit f688160

Please sign in to comment.