-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from khalidmaquilang/dev
v2.2.0 - Hotfix | disable admin slug + Hotfix | cant create purchase order + Feature | remove unused permission + Feature | added menu item + Hotfix | fix create user through invitation + Hotfix | kick function missing + Feature | test cases + Feature | subscription + Hotfix | fix design + Hotfix | able to join existing users
- Loading branch information
Showing
82 changed files
with
2,958 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
use Filament\Support\Contracts\HasLabel; | ||
|
||
enum BillingCycleEnum: string implements HasLabel | ||
{ | ||
case MONTHLY = 'monthly'; | ||
case YEARLY = 'yearly'; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getLabel(): string | ||
{ | ||
return match ($this) { | ||
self::MONTHLY => 'Monthly', | ||
self::YEARLY => 'Yearly', | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
use Filament\Support\Contracts\HasColor; | ||
use Filament\Support\Contracts\HasLabel; | ||
|
||
enum PaymentStatusEnum: string implements HasColor, HasLabel | ||
{ | ||
case SUCCESS = 'success'; | ||
case FAILED = 'failed'; | ||
case PENDING = 'pending'; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getLabel(): string | ||
{ | ||
return match ($this) { | ||
self::SUCCESS => 'Success', | ||
self::FAILED => 'Failed', | ||
self::PENDING => 'Pending', | ||
}; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getColor(): string | ||
{ | ||
return match ($this) { | ||
self::SUCCESS => 'success', | ||
self::FAILED => 'danger', | ||
self::PENDING => 'warning', | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
use Filament\Support\Contracts\HasLabel; | ||
|
||
enum PlanTypeEnum: string implements HasLabel | ||
{ | ||
case STANDARD = 'standard'; | ||
case CUSTOM = 'custom'; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getLabel(): string | ||
{ | ||
return match ($this) { | ||
self::STANDARD => 'Standard', | ||
self::CUSTOM => 'Custom', | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
use Filament\Support\Contracts\HasColor; | ||
use Filament\Support\Contracts\HasLabel; | ||
|
||
enum SubscriptionStatusEnum: string implements HasColor, HasLabel | ||
{ | ||
case ACTIVE = 'active'; | ||
case TRIAL = 'trialing'; | ||
case CANCELED = 'canceled'; | ||
case PAST_DUE = 'past_due'; | ||
case UNPAID = 'unpaid'; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getLabel(): string | ||
{ | ||
return match ($this) { | ||
self::ACTIVE => 'Active', | ||
self::TRIAL => 'Trialing', | ||
self::CANCELED => 'Canceled', | ||
self::PAST_DUE => 'Past Due', | ||
self::UNPAID => 'Unpaid', | ||
}; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getColor(): string | ||
{ | ||
return match ($this) { | ||
self::ACTIVE => 'success', | ||
self::TRIAL => 'info', | ||
self::CANCELED => 'danger', | ||
self::PAST_DUE => 'warning', | ||
self::UNPAID => 'danger', | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
app/Filament/Admin/Resources/CompanyResource/Pages/ViewCompany.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Filament\Admin\Resources\CompanyResource\Pages; | ||
|
||
use App\Filament\Admin\Resources\CompanyResource; | ||
use Filament\Actions; | ||
use Filament\Infolists\Components\Section; | ||
use Filament\Infolists\Components\TextEntry; | ||
use Filament\Infolists\Infolist; | ||
use Filament\Resources\Pages\ViewRecord; | ||
|
||
class ViewCompany extends ViewRecord | ||
{ | ||
protected static string $resource = CompanyResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\EditAction::make(), | ||
]; | ||
} | ||
|
||
public function infolist(Infolist $infolist): Infolist | ||
{ | ||
return $infolist | ||
->schema([ | ||
Section::make() | ||
->columns(2) | ||
->schema([ | ||
TextEntry::make('name'), | ||
TextEntry::make('slug'), | ||
TextEntry::make('owner.name'), | ||
TextEntry::make('phone'), | ||
TextEntry::make('email'), | ||
TextEntry::make('currency'), | ||
]), | ||
]); | ||
} | ||
|
||
/** | ||
* @return \class-string[] | ||
*/ | ||
public function getRelationManagers(): array | ||
{ | ||
return [ | ||
CompanyResource\RelationManagers\SubscriptionsRelationManager::class, | ||
]; | ||
} | ||
} |
158 changes: 158 additions & 0 deletions
158
...ilament/Admin/Resources/CompanyResource/RelationManagers/SubscriptionsRelationManager.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?php | ||
|
||
namespace App\Filament\Admin\Resources\CompanyResource\RelationManagers; | ||
|
||
use App\Enums\BillingCycleEnum; | ||
use App\Enums\PaymentStatusEnum; | ||
use App\Enums\SubscriptionStatusEnum; | ||
use App\Models\Plan; | ||
use Carbon\Carbon; | ||
use Filament\Forms; | ||
use Filament\Forms\Components\Select; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Forms\Form; | ||
use Filament\Resources\RelationManagers\RelationManager; | ||
use Filament\Tables; | ||
use Filament\Tables\Table; | ||
|
||
class SubscriptionsRelationManager extends RelationManager | ||
{ | ||
protected static string $relationship = 'subscriptions'; | ||
|
||
public function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Forms\Components\Hidden::make('total_amount') | ||
->default(1), | ||
Forms\Components\Select::make('plan_id') | ||
->relationship('plan', 'name') | ||
->required(), | ||
Forms\Components\DatePicker::make('start_date') | ||
->required(), | ||
Forms\Components\TextInput::make('extra_users') | ||
->default(0), | ||
]); | ||
} | ||
|
||
public function table(Table $table): Table | ||
{ | ||
return $table | ||
->recordTitleAttribute('id') | ||
->columns([ | ||
Tables\Columns\TextColumn::make('plan.name'), | ||
Tables\Columns\TextColumn::make('start_date') | ||
->date(), | ||
Tables\Columns\TextColumn::make('end_date') | ||
->date(), | ||
Tables\Columns\TextColumn::make('status') | ||
->badge(), | ||
Tables\Columns\TextColumn::make('extra_users') | ||
->badge(), | ||
Tables\Columns\TextColumn::make('total_amount') | ||
->money('PHP'), | ||
]) | ||
->filters([ | ||
// | ||
]) | ||
->headerActions([ | ||
Tables\Actions\CreateAction::make() | ||
->mutateFormDataUsing(function (array $data) { | ||
return $this->beforeCreate($data); | ||
}) | ||
->after(fn ($record) => $this->afterCreate($record)) | ||
->createAnother(false), | ||
]) | ||
->actions([ | ||
Tables\Actions\Action::make('view') | ||
->icon('heroicon-m-eye') | ||
->color('gray') | ||
->label('View') | ||
->action(fn ($record) => redirect(route('filament.admin.resources.subscriptions.view', [$record]))), | ||
Tables\Actions\EditAction::make(), | ||
Tables\Actions\Action::make('renew') | ||
->icon('heroicon-m-banknotes') | ||
->color('success') | ||
->fillForm(fn ($record): array => [ | ||
'amount' => $record->total_amount, | ||
]) | ||
->form($this->renewForm()) | ||
->action(function (array $data, $record): void { | ||
$record->updateEndDate(); | ||
$record->payments()->create($data); | ||
}) | ||
->successNotificationTitle('Payment Updated') | ||
->visible(fn ($record) => $record->isActive()), | ||
]) | ||
->bulkActions([ | ||
|
||
]) | ||
->defaultSort('created_at', 'desc'); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
protected function renewForm(): array | ||
{ | ||
return [ | ||
Forms\Components\DatePicker::make('payment_date') | ||
->required(), | ||
TextInput::make('amount') | ||
->numeric() | ||
->required(), | ||
TextInput::make('payment_method') | ||
->required(), | ||
Select::make('status') | ||
->options(PaymentStatusEnum::class) | ||
->required(), | ||
]; | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* @return array | ||
*/ | ||
protected function beforeCreate(array $data): array | ||
{ | ||
$plan = Plan::find($data['plan_id']); | ||
if (empty($plan)) { | ||
return []; | ||
} | ||
|
||
$data['status'] = SubscriptionStatusEnum::ACTIVE; | ||
$data['end_date'] = $plan->billing_cycle === BillingCycleEnum::MONTHLY ? (new Carbon( | ||
$data['start_date'] | ||
))->addMonth() : (new Carbon($data['start_date']))->addYear(); | ||
$data['total_amount'] = $plan->price + ($data['extra_users'] * 100); //100php per user | ||
|
||
$subscription = $this->ownerRecord->getActiveSubscription(); | ||
if (! empty($subscription)) { | ||
$subscription->cancel(); // cancel latest subscription | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* @param $record | ||
* @return void | ||
*/ | ||
protected function afterCreate($record): void | ||
{ | ||
$record->payments()->create([ | ||
'payment_date' => now(), | ||
'amount' => $record->total_amount, | ||
'payment_method' => 'system', | ||
'status' => PaymentStatusEnum::SUCCESS, | ||
]); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isReadOnly(): bool | ||
{ | ||
return false; | ||
} | ||
} |
Oops, something went wrong.