feat: implement services overview page with service status cards and counts
This commit is contained in:
33
app/Admin/Clusters/Services/Pages/ServicesOverview.php
Normal file
33
app/Admin/Clusters/Services/Pages/ServicesOverview.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Clusters\Services\Pages;
|
||||
|
||||
use App\Admin\Clusters\Services;
|
||||
use App\Models\Service;
|
||||
use Filament\Pages\Page;
|
||||
|
||||
class ServicesOverview extends Page
|
||||
{
|
||||
protected static ?string $navigationIcon = 'ri-dashboard-line';
|
||||
|
||||
protected static ?string $activeNavigationIcon = 'ri-dashboard-fill';
|
||||
|
||||
protected static ?string $navigationLabel = 'Overview';
|
||||
|
||||
protected static ?int $navigationSort = -1;
|
||||
|
||||
protected static ?string $cluster = Services::class;
|
||||
|
||||
protected static string $view = 'admin.clusters.services.pages.services-overview';
|
||||
|
||||
public function getViewData(): array
|
||||
{
|
||||
return [
|
||||
'activeCount' => Service::where('status', 'active')->count(),
|
||||
'pendingCount' => Service::where('status', 'pending')->count(),
|
||||
'suspendedCount' => Service::where('status', 'suspended')->count(),
|
||||
'cancelledCount' => Service::where('status', 'cancelled')->count(),
|
||||
'totalCount' => Service::count(),
|
||||
];
|
||||
}
|
||||
}
|
||||
217
app/Admin/Resources/ActiveServiceResource.php
Normal file
217
app/Admin/Resources/ActiveServiceResource.php
Normal file
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Resources;
|
||||
|
||||
use App\Admin\Clusters\Services;
|
||||
use App\Admin\Components\UserComponent;
|
||||
use App\Admin\Resources\Common\RelationManagers\PropertiesRelationManager;
|
||||
use App\Admin\Resources\ServiceResource\RelationManagers;
|
||||
use App\Helpers\ExtensionHelper;
|
||||
use App\Models\Currency;
|
||||
use App\Models\Product;
|
||||
use App\Models\Service;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Actions\Action;
|
||||
use Filament\Forms\Components\Component;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Support\RawJs;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ActiveServiceResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Service::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'ri-checkbox-circle-line';
|
||||
|
||||
protected static ?string $activeNavigationIcon = 'ri-checkbox-circle-fill';
|
||||
|
||||
protected static ?string $navigationLabel = 'Active';
|
||||
|
||||
protected static ?string $modelLabel = 'Active Service';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Active Services';
|
||||
|
||||
protected static ?string $slug = 'active-services';
|
||||
|
||||
protected static ?int $navigationSort = 0;
|
||||
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
return Service::where('status', 'active')->count() ?: null;
|
||||
}
|
||||
|
||||
public static function getNavigationBadgeColor(): ?string
|
||||
{
|
||||
return 'success';
|
||||
}
|
||||
|
||||
protected static ?string $cluster = Services::class;
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()->where('status', 'active');
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Select::make('product_id')
|
||||
->label('Product')
|
||||
->required()
|
||||
->options(Product::all()->pluck('name', 'id')->toArray())
|
||||
->searchable()
|
||||
->live()
|
||||
->preload()
|
||||
->placeholder('Select the product'),
|
||||
Forms\Components\Select::make('plan_id')
|
||||
->label('Plan')
|
||||
->required()
|
||||
->relationship('plan', 'name', fn (Builder $query, Get $get) => $query->where('priceable_id', $get('product_id'))->where('priceable_type', Product::class))
|
||||
->searchable()
|
||||
->preload()
|
||||
->disabled(fn (Get $get) => !$get('product_id'))
|
||||
->placeholder('Select the plan'),
|
||||
UserComponent::make('user_id'),
|
||||
Forms\Components\Select::make('status')
|
||||
->label('Status')
|
||||
->required()
|
||||
->options([
|
||||
'active' => 'Active',
|
||||
'pending' => 'Pending',
|
||||
'suspended' => 'Suspended',
|
||||
'cancelled' => 'Cancelled',
|
||||
])
|
||||
->default('active'),
|
||||
Forms\Components\TextInput::make('quantity')
|
||||
->label('Quantity')
|
||||
->required()
|
||||
->placeholder('Enter the quantity'),
|
||||
Forms\Components\DatePicker::make('expires_at')
|
||||
->label('Expires At')
|
||||
->required()
|
||||
->placeholder('Select the expiration date'),
|
||||
Forms\Components\Select::make('coupon_id')
|
||||
->label('Coupon')
|
||||
->relationship('coupon', 'code')
|
||||
->searchable()
|
||||
->placeholder('Select the coupon'),
|
||||
Forms\Components\Select::make('currency_code')
|
||||
->options(function (Get $get, ?string $state) {
|
||||
$pricing = collect($get('../../pricing'))->pluck('currency_code');
|
||||
if ($state !== null) {
|
||||
$pricing = $pricing->filter(function ($code) use ($state) {
|
||||
return $code !== $state;
|
||||
});
|
||||
}
|
||||
$pricing = $pricing->filter(function ($code) {
|
||||
return $code !== null;
|
||||
});
|
||||
|
||||
return Currency::whereNotIn('code', $pricing)->pluck('code', 'code');
|
||||
})
|
||||
->live()
|
||||
->default(config('settings.default_currency'))
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('price')
|
||||
->required()
|
||||
->label('Price')
|
||||
->prefix(fn (Get $get) => Currency::where('code', $get('currency_code'))->first()?->prefix)
|
||||
->suffix(fn (Get $get) => Currency::where('code', $get('currency_code'))->first()?->suffix)
|
||||
->live(onBlur: true)
|
||||
->mask(RawJs::make(
|
||||
<<<'JS'
|
||||
$money($input, '.', '', 2)
|
||||
JS
|
||||
))
|
||||
->numeric()
|
||||
->minValue(0),
|
||||
Forms\Components\TextInput::make('subscription_id')
|
||||
->label('Subscription ID')
|
||||
->nullable()
|
||||
->placeholder('Enter the subscription ID')
|
||||
->hintAction(
|
||||
Action::make('Cancel Subscription ID')
|
||||
->action(function (Component $component) {
|
||||
if (ExtensionHelper::cancelSubscription($component->getRecord())) {
|
||||
Notification::make('Subscription Cancelled')
|
||||
->title('The subscription has been successfully cancelled')
|
||||
->success()
|
||||
->send();
|
||||
} else {
|
||||
Notification::make('Subscription Not Cancelled')
|
||||
->title('The subscription could not be cancelled')
|
||||
->error()
|
||||
->send();
|
||||
}
|
||||
$component->getRecord()->update(['subscription_id' => null]);
|
||||
})
|
||||
->requiresConfirmation()
|
||||
->label('Cancel Subscription')
|
||||
->hidden(fn (Component $component) => !$component->getRecord()?->subscription_id),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('user.name')
|
||||
->label('User')
|
||||
->searchable(true, fn (Builder $query, string $search) => $query->whereHas('user', fn (Builder $query) => $query->where('first_name', 'like', "%$search%")->orWhere('last_name', 'like', "%$search%"))),
|
||||
Tables\Columns\TextColumn::make('product.name')
|
||||
->label('Product')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->badge()
|
||||
->color('success')
|
||||
->formatStateUsing(fn (string $state) => ucfirst($state))
|
||||
->label('Status'),
|
||||
Tables\Columns\TextColumn::make('expires_at')
|
||||
->label('Expires At')
|
||||
->date()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
])
|
||||
->defaultSort(function (Builder $query): Builder {
|
||||
return $query->orderBy('id', 'desc');
|
||||
})
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
RelationManagers\InvoicesRelationManager::class,
|
||||
PropertiesRelationManager::class,
|
||||
RelationManagers\ConfigOptionsRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => \App\Admin\Resources\ActiveServiceResource\Pages\ListActiveServices::route('/'),
|
||||
'create' => \App\Admin\Resources\ActiveServiceResource\Pages\CreateActiveService::route('/create'),
|
||||
'edit' => \App\Admin\Resources\ActiveServiceResource\Pages\EditActiveService::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Resources\ActiveServiceResource\Pages;
|
||||
|
||||
use App\Admin\Resources\ActiveServiceResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateActiveService extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ActiveServiceResource::class;
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$data['status'] = 'active';
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Resources\ActiveServiceResource\Pages;
|
||||
|
||||
use App\Admin\Resources\ActiveServiceResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditActiveService extends EditRecord
|
||||
{
|
||||
protected static string $resource = ActiveServiceResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Resources\ActiveServiceResource\Pages;
|
||||
|
||||
use App\Admin\Resources\ActiveServiceResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListActiveServices extends ListRecords
|
||||
{
|
||||
protected static string $resource = ActiveServiceResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<x-filament-panels::page>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||
{{-- Active Services Card --}}
|
||||
<a href="{{ route('filament.admin.resources.active-services.index') }}" class="block">
|
||||
<x-filament::section class="hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors cursor-pointer">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="p-3 rounded-full bg-success-500/10">
|
||||
<x-ri-checkbox-circle-fill class="w-8 h-8 text-success-500" />
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm font-medium text-gray-500 dark:text-gray-400">Active Services</p>
|
||||
<p class="text-3xl font-bold text-success-500">{{ number_format($activeCount) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</x-filament::section>
|
||||
</a>
|
||||
|
||||
{{-- Pending Services Card --}}
|
||||
<a href="{{ route('filament.admin.resources.pending-services.index') }}" class="block">
|
||||
<x-filament::section class="hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors cursor-pointer">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="p-3 rounded-full bg-warning-500/10">
|
||||
<x-ri-time-fill class="w-8 h-8 text-warning-500" />
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm font-medium text-gray-500 dark:text-gray-400">Pending Services</p>
|
||||
<p class="text-3xl font-bold text-warning-500">{{ number_format($pendingCount) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</x-filament::section>
|
||||
</a>
|
||||
|
||||
{{-- Suspended Services Card --}}
|
||||
<a href="{{ route('filament.admin.resources.suspended-services.index') }}" class="block">
|
||||
<x-filament::section class="hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors cursor-pointer">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="p-3 rounded-full bg-orange-500/10">
|
||||
<x-ri-pause-circle-fill class="w-8 h-8 text-orange-500" />
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm font-medium text-gray-500 dark:text-gray-400">Suspended Services</p>
|
||||
<p class="text-3xl font-bold text-orange-500">{{ number_format($suspendedCount) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</x-filament::section>
|
||||
</a>
|
||||
|
||||
{{-- Cancelled Services Card --}}
|
||||
<a href="{{ route('filament.admin.resources.cancelled-services.index') }}" class="block">
|
||||
<x-filament::section class="hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors cursor-pointer">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="p-3 rounded-full bg-danger-500/10">
|
||||
<x-ri-close-circle-fill class="w-8 h-8 text-danger-500" />
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm font-medium text-gray-500 dark:text-gray-400">Cancelled Services</p>
|
||||
<p class="text-3xl font-bold text-danger-500">{{ number_format($cancelledCount) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</x-filament::section>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{{-- Total Summary --}}
|
||||
<x-filament::section class="mt-6">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="p-3 rounded-full bg-primary-500/10">
|
||||
<x-ri-archive-stack-fill class="w-8 h-8 text-primary-500" />
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm font-medium text-gray-500 dark:text-gray-400">Total Services</p>
|
||||
<p class="text-3xl font-bold text-primary-500">{{ number_format($totalCount) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-right text-sm text-gray-500 dark:text-gray-400">
|
||||
<p>Select a service type from the navigation or cards above to view and manage services.</p>
|
||||
</div>
|
||||
</div>
|
||||
</x-filament::section>
|
||||
</x-filament-panels::page>
|
||||
Reference in New Issue
Block a user