Skip to content

Commit c8523bc

Browse files
Merge pull request #111 from khalidmaquilang/dev
v2.5.0-
2 parents 0742593 + 3f5e6cc commit c8523bc

File tree

51 files changed

+1489
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1489
-172
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ REDIS_HOST=127.0.0.1
4646
REDIS_PASSWORD=null
4747
REDIS_PORT=6379
4848

49+
QUEUE_CONNECTIONS=default,short-running-queue,long-running-queue
50+
4951
MAIL_MAILER=log
5052
MAIL_HOST=127.0.0.1
5153
MAIL_PORT=2525

.github/workflows/laravel.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ jobs:
2626
run: php artisan key:generate
2727
- name: Directory Permissions
2828
run: chmod -R 777 storage bootstrap/cache
29+
- name: Install NPM
30+
run: npm install
31+
- name: Compile Assets
32+
run: npm run build
2933
- name: Check Code Quality
3034
run: vendor/bin/pint --test
3135
- name: Execute tests (Unit and Feature tests) via PHPUnit

app/Console/Commands/CheckExpiredSubscriptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CheckExpiredSubscriptions extends Command
2121
*
2222
* @var string
2323
*/
24-
protected $description = "This command checks for active subscriptions that have expired based on their `end_date`. Expired subscriptions are then marked as 'expired', and you can add additional logic here to handle notifications, access restrictions, or other relevant actions.";
24+
protected $description = "This command checks for active subscriptions that have expired based on their `end_date`. Expired subscriptions are then marked as 'expired'.";
2525

2626
/**
2727
* Execute the console command.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace App\Console\Commands\Retrofits;
4+
5+
use App\Models\Payment;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Support\Facades\Log;
8+
9+
class RetrofitPaymentsCompanyId extends Command
10+
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'retrofit:fill-payments-company-id';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'This command will fill all payments that does not have any company id.';
24+
25+
/**
26+
* Execute the console command.
27+
*/
28+
public function handle()
29+
{
30+
$this->line('Searching for payments that does not have company_id');
31+
$payments = Payment::with('subscription')->where('company_id', null)->get();
32+
33+
$this->line($payments->count().' payment/s found.');
34+
35+
$this->line('Retrofitting...');
36+
$bar = $this->output->createProgressBar($payments->count());
37+
38+
$errorCount = 0;
39+
$bar->start();
40+
41+
foreach ($payments as $payment) {
42+
try {
43+
$this->addCompanyId($payment);
44+
45+
} catch (\Exception $exception) {
46+
Log::error('There was something wrong while retrofitting payments.', [
47+
'payment_id' => $payment->id,
48+
'exception' => $exception,
49+
]);
50+
$errorCount++;
51+
}
52+
53+
$bar->advance();
54+
}
55+
56+
$bar->finish();
57+
$this->newLine();
58+
59+
if ($errorCount) {
60+
$this->error($errorCount.' errors found. Please check logs.');
61+
}
62+
63+
$this->line('Retrofit Finished!');
64+
}
65+
66+
/**
67+
* @param Payment $payment
68+
* @return void
69+
*/
70+
protected function addCompanyId(Payment $payment)
71+
{
72+
$subscription = $payment->subscription;
73+
74+
$payment->company_id = $subscription->company_id;
75+
$payment->save();
76+
}
77+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace App\Console\Commands\Retrofits;
4+
5+
use App\Models\Role;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Support\Facades\Log;
8+
9+
class RetrofitSuperAdminPermission extends Command
10+
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'retrofit:add-super-admin-permission {permissions* : permission names}';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'This command will add permissions on the super_admin roles.';
24+
25+
/**
26+
* Execute the console command.
27+
*/
28+
public function handle()
29+
{
30+
$permissions = $this->argument('permissions');
31+
32+
$this->line('Getting all Super Admin roles from different companies.');
33+
$roles = Role::where('name', config('filament-shield.super_admin.name'))
34+
->where('company_id', '<>', null)
35+
->get();
36+
37+
$this->line($roles->count().' role/s found.');
38+
39+
$this->line('Retrofitting...');
40+
$bar = $this->output->createProgressBar($roles->count());
41+
42+
$errorCount = 0;
43+
$bar->start();
44+
45+
foreach ($roles as $role) {
46+
try {
47+
$role->givePermissionTo($permissions);
48+
} catch (\Exception $exception) {
49+
Log::error('There was something wrong while retrofitting roles.', [
50+
'payment_id' => $role->id,
51+
'permissions' => $permissions,
52+
'exception' => $exception,
53+
]);
54+
$errorCount++;
55+
}
56+
57+
$bar->advance();
58+
}
59+
60+
$bar->finish();
61+
$this->newLine();
62+
63+
if ($errorCount) {
64+
$this->error($errorCount.' errors found. Please check logs.');
65+
}
66+
67+
$this->line('Retrofit Finished!');
68+
}
69+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Enums\PaymentStatusEnum;
6+
use App\Jobs\SendInvoiceJob;
7+
use App\Models\Subscription;
8+
use Illuminate\Console\Command;
9+
10+
class SendInvoiceNearExpiredSubscriptions extends Command
11+
{
12+
/**
13+
* The name and signature of the console command.
14+
*
15+
* @var string
16+
*/
17+
protected $signature = 'app:send-invoice-near-expired-subscriptions';
18+
19+
/**
20+
* The console command description.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'This command checks for active subscriptions expiring within a week and generates invoices for them.';
25+
26+
/**
27+
* Execute the console command.
28+
*/
29+
public function handle()
30+
{
31+
$expiringSubscriptions = Subscription::where('status', 'active')
32+
->where('total_amount', '>', 0)
33+
->whereDate('end_date', '=', now()->addWeek()->toDateString())
34+
->get();
35+
36+
foreach ($expiringSubscriptions as $subscription) {
37+
$payment = $subscription->createPayment(PaymentStatusEnum::PENDING);
38+
39+
SendInvoiceJob::dispatch($payment)
40+
->onQueue('short-running-queue');
41+
}
42+
}
43+
}

app/Filament/Admin/Resources/CompanyResource/RelationManagers/SubscriptionsRelationManager.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ public function table(Table $table): Table
5353
Tables\Columns\TextColumn::make('total_amount')
5454
->money('PHP'),
5555
])
56-
->filters([
57-
//
58-
])
5956
->headerActions([
6057
Tables\Actions\CreateAction::make()
6158
->mutateFormDataUsing(function (array $data) {
@@ -141,12 +138,7 @@ protected function beforeCreate(array $data): array
141138
*/
142139
protected function afterCreate($record): void
143140
{
144-
$record->payments()->create([
145-
'payment_date' => now(),
146-
'amount' => $record->total_amount,
147-
'payment_method' => 'system',
148-
'status' => PaymentStatusEnum::SUCCESS,
149-
]);
141+
$record->createPayment(PaymentStatusEnum::SUCCESS, now());
150142
}
151143

152144
/**

app/Filament/Admin/Resources/SubscriptionResource/RelationManagers/PaymentsRelationManager.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace App\Filament\Admin\Resources\SubscriptionResource\RelationManagers;
44

5+
use App\Enums\PaymentStatusEnum;
6+
use Filament\Forms\Components\Group;
7+
use Filament\Forms\Components\TextInput;
58
use Filament\Resources\RelationManagers\RelationManager;
69
use Filament\Tables;
710
use Filament\Tables\Table;
@@ -16,6 +19,8 @@ public function table(Table $table): Table
1619
->columns([
1720
Tables\Columns\TextColumn::make('invoice_number')
1821
->searchable(),
22+
Tables\Columns\TextColumn::make('reference_number')
23+
->searchable(),
1924
Tables\Columns\TextColumn::make('payment_date')
2025
->date(),
2126
Tables\Columns\TextColumn::make('amount')
@@ -25,7 +30,27 @@ public function table(Table $table): Table
2530
->badge(),
2631
])
2732
->actions([
33+
Tables\Actions\Action::make('Pay Due')
34+
->label('')
35+
->tooltip('Pay Due')
36+
->icon('heroicon-o-banknotes')
37+
->color('info')
38+
->form([
39+
Group::make([
40+
TextInput::make('reference_number'),
41+
]),
42+
])
43+
->action(function ($record, array $data) {
44+
$record->reference_number = $data['reference_number'];
45+
$record->status = PaymentStatusEnum::SUCCESS;
46+
$record->save();
47+
48+
$record->subscription->updateEndDate();
49+
})
50+
->visible(fn ($record) => $record->status === PaymentStatusEnum::PENDING),
2851
Tables\Actions\Action::make('Download Invoice')
52+
->label('')
53+
->tooltip('Download Invoice')
2954
->icon('heroicon-o-document-arrow-down')
3055
->color('success')
3156
->url(fn ($record) => route('admin.sales.generate-invoice', [$record]))
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace App\Filament\Admin\Resources;
4+
5+
use App\Filament\Admin\Resources\UserResource\Pages;
6+
use App\Models\User;
7+
use Filament\Forms\Form;
8+
use Filament\Resources\Resource;
9+
use Filament\Tables;
10+
use Filament\Tables\Table;
11+
12+
class UserResource extends Resource
13+
{
14+
protected static ?string $model = User::class;
15+
16+
protected static ?string $navigationIcon = 'heroicon-o-user-group';
17+
18+
protected static bool $shouldSkipAuthorization = true;
19+
20+
public static function form(Form $form): Form
21+
{
22+
return $form
23+
->schema(User::getForm());
24+
}
25+
26+
public static function table(Table $table): Table
27+
{
28+
return $table
29+
->columns([
30+
Tables\Columns\TextColumn::make('name')
31+
->searchable(),
32+
Tables\Columns\TextColumn::make('email')
33+
->searchable(),
34+
Tables\Columns\TextColumn::make('email_verified_at')
35+
->dateTime()
36+
->sortable(),
37+
Tables\Columns\TextColumn::make('created_at')
38+
->dateTime()
39+
->sortable()
40+
->toggleable(isToggledHiddenByDefault: true),
41+
Tables\Columns\TextColumn::make('updated_at')
42+
->dateTime()
43+
->sortable()
44+
->toggleable(isToggledHiddenByDefault: true),
45+
])
46+
->filters([
47+
//
48+
])
49+
->actions([
50+
Tables\Actions\EditAction::make(),
51+
])
52+
->bulkActions([
53+
Tables\Actions\BulkActionGroup::make([
54+
Tables\Actions\DeleteBulkAction::make(),
55+
]),
56+
]);
57+
}
58+
59+
public static function getRelations(): array
60+
{
61+
return [
62+
//
63+
];
64+
}
65+
66+
public static function getPages(): array
67+
{
68+
return [
69+
'index' => Pages\ListUsers::route('/'),
70+
'create' => Pages\CreateUser::route('/create'),
71+
'edit' => Pages\EditUser::route('/{record}/edit'),
72+
];
73+
}
74+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace App\Filament\Admin\Resources\UserResource\Pages;
4+
5+
use App\Filament\Admin\Resources\UserResource;
6+
use Filament\Resources\Pages\CreateRecord;
7+
8+
class CreateUser extends CreateRecord
9+
{
10+
protected static string $resource = UserResource::class;
11+
}

0 commit comments

Comments
 (0)