Yes, add cancelled, pending, and suspended service resources to admin panel
This commit is contained in:
@@ -14,6 +14,8 @@ class ServicesOverview extends Page
|
|||||||
|
|
||||||
protected static ?string $navigationLabel = 'Overview';
|
protected static ?string $navigationLabel = 'Overview';
|
||||||
|
|
||||||
|
protected static ?string $slug = '/';
|
||||||
|
|
||||||
protected static ?int $navigationSort = -1;
|
protected static ?int $navigationSort = -1;
|
||||||
|
|
||||||
protected static ?string $cluster = Services::class;
|
protected static ?string $cluster = Services::class;
|
||||||
|
|||||||
217
app/Admin/Resources/CancelledServiceResource.php
Normal file
217
app/Admin/Resources/CancelledServiceResource.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 CancelledServiceResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = Service::class;
|
||||||
|
|
||||||
|
protected static ?string $navigationIcon = 'ri-close-circle-line';
|
||||||
|
|
||||||
|
protected static ?string $activeNavigationIcon = 'ri-close-circle-fill';
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'Cancelled';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'Cancelled Service';
|
||||||
|
|
||||||
|
protected static ?string $pluralModelLabel = 'Cancelled Services';
|
||||||
|
|
||||||
|
protected static ?string $slug = 'cancelled-services';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 3;
|
||||||
|
|
||||||
|
public static function getNavigationBadge(): ?string
|
||||||
|
{
|
||||||
|
return Service::where('status', 'cancelled')->count() ?: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getNavigationBadgeColor(): ?string
|
||||||
|
{
|
||||||
|
return 'danger';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static ?string $cluster = Services::class;
|
||||||
|
|
||||||
|
public static function getEloquentQuery(): Builder
|
||||||
|
{
|
||||||
|
return parent::getEloquentQuery()->where('status', 'cancelled');
|
||||||
|
}
|
||||||
|
|
||||||
|
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('cancelled'),
|
||||||
|
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('danger')
|
||||||
|
->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\CancelledServiceResource\Pages\ListCancelledServices::route('/'),
|
||||||
|
'create' => \App\Admin\Resources\CancelledServiceResource\Pages\CreateCancelledService::route('/create'),
|
||||||
|
'edit' => \App\Admin\Resources\CancelledServiceResource\Pages\EditCancelledService::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Resources\CancelledServiceResource\Pages;
|
||||||
|
|
||||||
|
use App\Admin\Resources\CancelledServiceResource;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateCancelledService extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = CancelledServiceResource::class;
|
||||||
|
|
||||||
|
protected function mutateFormDataBeforeCreate(array $data): array
|
||||||
|
{
|
||||||
|
$data['status'] = 'cancelled';
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Resources\CancelledServiceResource\Pages;
|
||||||
|
|
||||||
|
use App\Admin\Resources\CancelledServiceResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditCancelledService extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = CancelledServiceResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\DeleteAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Resources\CancelledServiceResource\Pages;
|
||||||
|
|
||||||
|
use App\Admin\Resources\CancelledServiceResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListCancelledServices extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = CancelledServiceResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
217
app/Admin/Resources/PendingServiceResource.php
Normal file
217
app/Admin/Resources/PendingServiceResource.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 PendingServiceResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = Service::class;
|
||||||
|
|
||||||
|
protected static ?string $navigationIcon = 'ri-time-line';
|
||||||
|
|
||||||
|
protected static ?string $activeNavigationIcon = 'ri-time-fill';
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'Pending';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'Pending Service';
|
||||||
|
|
||||||
|
protected static ?string $pluralModelLabel = 'Pending Services';
|
||||||
|
|
||||||
|
protected static ?string $slug = 'pending-services';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 1;
|
||||||
|
|
||||||
|
public static function getNavigationBadge(): ?string
|
||||||
|
{
|
||||||
|
return Service::where('status', 'pending')->count() ?: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getNavigationBadgeColor(): ?string
|
||||||
|
{
|
||||||
|
return 'warning';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static ?string $cluster = Services::class;
|
||||||
|
|
||||||
|
public static function getEloquentQuery(): Builder
|
||||||
|
{
|
||||||
|
return parent::getEloquentQuery()->where('status', 'pending');
|
||||||
|
}
|
||||||
|
|
||||||
|
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('pending'),
|
||||||
|
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('gray')
|
||||||
|
->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\PendingServiceResource\Pages\ListPendingServices::route('/'),
|
||||||
|
'create' => \App\Admin\Resources\PendingServiceResource\Pages\CreatePendingService::route('/create'),
|
||||||
|
'edit' => \App\Admin\Resources\PendingServiceResource\Pages\EditPendingService::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Resources\PendingServiceResource\Pages;
|
||||||
|
|
||||||
|
use App\Admin\Resources\PendingServiceResource;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreatePendingService extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = PendingServiceResource::class;
|
||||||
|
|
||||||
|
protected function mutateFormDataBeforeCreate(array $data): array
|
||||||
|
{
|
||||||
|
$data['status'] = 'pending';
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Resources\PendingServiceResource\Pages;
|
||||||
|
|
||||||
|
use App\Admin\Resources\PendingServiceResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditPendingService extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = PendingServiceResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\DeleteAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Resources\PendingServiceResource\Pages;
|
||||||
|
|
||||||
|
use App\Admin\Resources\PendingServiceResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListPendingServices extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = PendingServiceResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,6 +31,10 @@ class ServiceResource extends Resource
|
|||||||
|
|
||||||
protected static ?string $activeNavigationIcon = 'ri-function-fill';
|
protected static ?string $activeNavigationIcon = 'ri-function-fill';
|
||||||
|
|
||||||
|
protected static bool $shouldRegisterNavigation = false;
|
||||||
|
|
||||||
|
protected static ?string $slug = 'all-services';
|
||||||
|
|
||||||
public static function getNavigationBadge(): ?string
|
public static function getNavigationBadge(): ?string
|
||||||
{
|
{
|
||||||
return Service::where('status', 'pending')->count() ?: null;
|
return Service::where('status', 'pending')->count() ?: null;
|
||||||
|
|||||||
@@ -3,11 +3,8 @@
|
|||||||
namespace App\Admin\Resources\ServiceResource\Pages;
|
namespace App\Admin\Resources\ServiceResource\Pages;
|
||||||
|
|
||||||
use App\Admin\Resources\ServiceResource;
|
use App\Admin\Resources\ServiceResource;
|
||||||
use App\Models\Service;
|
|
||||||
use Filament\Actions;
|
use Filament\Actions;
|
||||||
use Filament\Resources\Components\Tab;
|
|
||||||
use Filament\Resources\Pages\ListRecords;
|
use Filament\Resources\Pages\ListRecords;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
|
|
||||||
class ListService extends ListRecords
|
class ListService extends ListRecords
|
||||||
{
|
{
|
||||||
@@ -19,38 +16,4 @@ class ListService extends ListRecords
|
|||||||
Actions\CreateAction::make(),
|
Actions\CreateAction::make(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTabs(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'all' => Tab::make('All Services')
|
|
||||||
->icon('ri-apps-line')
|
|
||||||
->badge(Service::count()),
|
|
||||||
'active' => Tab::make('Active')
|
|
||||||
->icon('ri-checkbox-circle-line')
|
|
||||||
->badgeColor('success')
|
|
||||||
->modifyQueryUsing(fn (Builder $query) => $query->where('status', 'active'))
|
|
||||||
->badge(Service::where('status', 'active')->count()),
|
|
||||||
'pending' => Tab::make('Pending')
|
|
||||||
->icon('ri-time-line')
|
|
||||||
->badgeColor('warning')
|
|
||||||
->modifyQueryUsing(fn (Builder $query) => $query->where('status', 'pending'))
|
|
||||||
->badge(Service::where('status', 'pending')->count()),
|
|
||||||
'suspended' => Tab::make('Suspended')
|
|
||||||
->icon('ri-pause-circle-line')
|
|
||||||
->badgeColor('warning')
|
|
||||||
->modifyQueryUsing(fn (Builder $query) => $query->where('status', 'suspended'))
|
|
||||||
->badge(Service::where('status', 'suspended')->count()),
|
|
||||||
'cancelled' => Tab::make('Cancelled')
|
|
||||||
->icon('ri-close-circle-line')
|
|
||||||
->badgeColor('danger')
|
|
||||||
->modifyQueryUsing(fn (Builder $query) => $query->where('status', 'cancelled'))
|
|
||||||
->badge(Service::where('status', 'cancelled')->count()),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDefaultActiveTab(): string|int|null
|
|
||||||
{
|
|
||||||
return 'active';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
217
app/Admin/Resources/SuspendedServiceResource.php
Normal file
217
app/Admin/Resources/SuspendedServiceResource.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 SuspendedServiceResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = Service::class;
|
||||||
|
|
||||||
|
protected static ?string $navigationIcon = 'ri-pause-circle-line';
|
||||||
|
|
||||||
|
protected static ?string $activeNavigationIcon = 'ri-pause-circle-fill';
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'Suspended';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'Suspended Service';
|
||||||
|
|
||||||
|
protected static ?string $pluralModelLabel = 'Suspended Services';
|
||||||
|
|
||||||
|
protected static ?string $slug = 'suspended-services';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 2;
|
||||||
|
|
||||||
|
public static function getNavigationBadge(): ?string
|
||||||
|
{
|
||||||
|
return Service::where('status', 'suspended')->count() ?: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getNavigationBadgeColor(): ?string
|
||||||
|
{
|
||||||
|
return 'warning';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static ?string $cluster = Services::class;
|
||||||
|
|
||||||
|
public static function getEloquentQuery(): Builder
|
||||||
|
{
|
||||||
|
return parent::getEloquentQuery()->where('status', 'suspended');
|
||||||
|
}
|
||||||
|
|
||||||
|
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('suspended'),
|
||||||
|
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('warning')
|
||||||
|
->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\SuspendedServiceResource\Pages\ListSuspendedServices::route('/'),
|
||||||
|
'create' => \App\Admin\Resources\SuspendedServiceResource\Pages\CreateSuspendedService::route('/create'),
|
||||||
|
'edit' => \App\Admin\Resources\SuspendedServiceResource\Pages\EditSuspendedService::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Resources\SuspendedServiceResource\Pages;
|
||||||
|
|
||||||
|
use App\Admin\Resources\SuspendedServiceResource;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateSuspendedService extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = SuspendedServiceResource::class;
|
||||||
|
|
||||||
|
protected function mutateFormDataBeforeCreate(array $data): array
|
||||||
|
{
|
||||||
|
$data['status'] = 'suspended';
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Resources\SuspendedServiceResource\Pages;
|
||||||
|
|
||||||
|
use App\Admin\Resources\SuspendedServiceResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditSuspendedService extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = SuspendedServiceResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\DeleteAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Resources\SuspendedServiceResource\Pages;
|
||||||
|
|
||||||
|
use App\Admin\Resources\SuspendedServiceResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListSuspendedServices extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = SuspendedServiceResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -47,6 +47,7 @@ class AdminPanelProvider extends PanelProvider
|
|||||||
->favicon(config('settings.logo') ? Storage::url(config('settings.logo')) : null)
|
->favicon(config('settings.logo') ? Storage::url(config('settings.logo')) : null)
|
||||||
->discoverResources(in: app_path('Admin/Resources'), for: 'App\\Admin\\Resources')
|
->discoverResources(in: app_path('Admin/Resources'), for: 'App\\Admin\\Resources')
|
||||||
->discoverPages(in: app_path('Admin/Pages'), for: 'App\\Admin\\Pages')
|
->discoverPages(in: app_path('Admin/Pages'), for: 'App\\Admin\\Pages')
|
||||||
|
->discoverPages(in: app_path('Admin/Clusters/Services/Pages'), for: 'App\\Admin\\Clusters\\Services\\Pages')
|
||||||
->discoverClusters(in: app_path('Admin/Clusters'), for: 'App\\Admin\\Clusters')
|
->discoverClusters(in: app_path('Admin/Clusters'), for: 'App\\Admin\\Clusters')
|
||||||
->userMenuItems([
|
->userMenuItems([
|
||||||
MenuItem::make()
|
MenuItem::make()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<x-filament-panels::page>
|
<x-filament-panels::page>
|
||||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||||
{{-- Active Services Card --}}
|
{{-- Active Services Card --}}
|
||||||
<a href="{{ route('filament.admin.resources.active-services.index') }}" class="block">
|
<a href="{{ \App\Admin\Resources\ActiveServiceResource::getUrl('index') }}" class="block">
|
||||||
<x-filament::section class="hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors cursor-pointer">
|
<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="flex items-center gap-4">
|
||||||
<div class="p-3 rounded-full bg-success-500/10">
|
<div class="p-3 rounded-full bg-success-500/10">
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
</a>
|
</a>
|
||||||
|
|
||||||
{{-- Pending Services Card --}}
|
{{-- Pending Services Card --}}
|
||||||
<a href="{{ route('filament.admin.resources.pending-services.index') }}" class="block">
|
<a href="{{ \App\Admin\Resources\PendingServiceResource::getUrl('index') }}" class="block">
|
||||||
<x-filament::section class="hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors cursor-pointer">
|
<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="flex items-center gap-4">
|
||||||
<div class="p-3 rounded-full bg-warning-500/10">
|
<div class="p-3 rounded-full bg-warning-500/10">
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
</a>
|
</a>
|
||||||
|
|
||||||
{{-- Suspended Services Card --}}
|
{{-- Suspended Services Card --}}
|
||||||
<a href="{{ route('filament.admin.resources.suspended-services.index') }}" class="block">
|
<a href="{{ \App\Admin\Resources\SuspendedServiceResource::getUrl('index') }}" class="block">
|
||||||
<x-filament::section class="hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors cursor-pointer">
|
<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="flex items-center gap-4">
|
||||||
<div class="p-3 rounded-full bg-orange-500/10">
|
<div class="p-3 rounded-full bg-orange-500/10">
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
</a>
|
</a>
|
||||||
|
|
||||||
{{-- Cancelled Services Card --}}
|
{{-- Cancelled Services Card --}}
|
||||||
<a href="{{ route('filament.admin.resources.cancelled-services.index') }}" class="block">
|
<a href="{{ \App\Admin\Resources\CancelledServiceResource::getUrl('index') }}" class="block">
|
||||||
<x-filament::section class="hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors cursor-pointer">
|
<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="flex items-center gap-4">
|
||||||
<div class="p-3 rounded-full bg-danger-500/10">
|
<div class="p-3 rounded-full bg-danger-500/10">
|
||||||
|
|||||||
Reference in New Issue
Block a user