From cc3a9cd8543cc30afb778e508475162ca46ee1fd Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Tue, 4 Nov 2025 23:10:50 +0500 Subject: [PATCH] wip --- README.md | 4 +- .../CardOrders/Schemas/CardOrderForm.php | 2 +- .../LoanOrders/Schemas/LoanOrderForm.php | 7 +- .../Loans/Loans/Tables/LoansTable.php | 6 +- .../LoanOrderMobileResource.php | 4 +- .../Schemas/LoanOrderMobileForm.php | 2 +- .../LoanOrderMobile/LoanOrderMobileModule.php | 64 ++++++ .../Models/LoanOrderMobile.php | 182 ++++++++++++++++++ .../Policies/LoanOrderMobilePolicy.php | 69 +++++++ .../LoanOrderMobileRepository.php | 5 + app/Modules/module-helpers.php | 15 +- 11 files changed, 348 insertions(+), 12 deletions(-) create mode 100644 app/Modules/LoanOrderMobile/LoanOrderMobileModule.php create mode 100644 app/Modules/LoanOrderMobile/Models/LoanOrderMobile.php create mode 100644 app/Modules/LoanOrderMobile/Policies/LoanOrderMobilePolicy.php create mode 100644 app/Modules/LoanOrderMobile/Repositories/LoanOrderMobileRepository.php diff --git a/README.md b/README.md index 1b9cdf8..14bd54e 100644 --- a/README.md +++ b/README.md @@ -7,5 +7,5 @@ create database nurmuhammetsdb; ALTER USER ahat WITH PASSWORD 'K}#zL9@}QkR>MAHMYTJ'; -SELECT setval('card_orders_id_seq', (SELECT MAX(id) from card_orders)); -SELECT nextval('card_orders_id_seq'); +SELECT setval('users_id_seq', (SELECT MAX(id) from users)); +SELECT nextval('users_id_seq'); diff --git a/app/Filament/Clusters/Cards/CardOrders/Schemas/CardOrderForm.php b/app/Filament/Clusters/Cards/CardOrders/Schemas/CardOrderForm.php index 8ae1a0f..34db291 100644 --- a/app/Filament/Clusters/Cards/CardOrders/Schemas/CardOrderForm.php +++ b/app/Filament/Clusters/Cards/CardOrders/Schemas/CardOrderForm.php @@ -256,7 +256,7 @@ class CardOrderForm ->required() ->columnSpan(2), ])->columnSpan(4), - ])->columnSpanFull(), + ])->columnSpanFull()->skippable(fn (string $context) => $context === 'edit'), ]); } } diff --git a/app/Filament/Clusters/Loans/LoanOrders/Schemas/LoanOrderForm.php b/app/Filament/Clusters/Loans/LoanOrders/Schemas/LoanOrderForm.php index 66def38..a74c274 100644 --- a/app/Filament/Clusters/Loans/LoanOrders/Schemas/LoanOrderForm.php +++ b/app/Filament/Clusters/Loans/LoanOrders/Schemas/LoanOrderForm.php @@ -2,6 +2,7 @@ namespace App\Filament\Clusters\Loans\LoanOrders\Schemas; +use App\Modules\FilamentPermission\Repositories\FilamentPermissionRepository; use App\Modules\LoanOrder\Models\LoanOrderRequiredDocs; use App\Modules\LoanOrder\Repositories\LoanOrderRepository; use App\Modules\OrderStatus\Repositories\OrderStatusRepository; @@ -39,7 +40,8 @@ class LoanOrderForm Section::make(__('New loan order')) ->columnSpan(4) ->columns(4) - + ->disabled(fn (string $context): bool => FilamentPermissionRepository::forClients()) + ->hidden(fn (string $context) => FilamentPermissionRepository::defaultSystemInput($context)) ->components([ Select::make('status') ->label(__('Status')) @@ -343,9 +345,10 @@ class LoanOrderForm ->displayFormat('d.m.Y') ->beforeOrEqual('today') ->required() + ->native(false) ->columnSpan(1), ]), - ])->columnSpan(4), + ])->columnSpan(4)->skippable(fn (string $context) => $context === 'edit'), ]); } } diff --git a/app/Filament/Clusters/Loans/Loans/Tables/LoansTable.php b/app/Filament/Clusters/Loans/Loans/Tables/LoansTable.php index 694efd8..ccbfd9f 100644 --- a/app/Filament/Clusters/Loans/Loans/Tables/LoansTable.php +++ b/app/Filament/Clusters/Loans/Loans/Tables/LoansTable.php @@ -18,7 +18,11 @@ class LoansTable { return $table ->modifyQueryUsing(function (Builder $query) { - DefaultQueryForResourceIndexRepository::make($query); + if (user()->isAdmin()) { + return; + } + + $query->where('user_id', user()->id); }) ->columns([ TextColumn::make('account_number') diff --git a/app/Filament/Clusters/Loans/Resources/LoanOrderMobiles/LoanOrderMobileResource.php b/app/Filament/Clusters/Loans/Resources/LoanOrderMobiles/LoanOrderMobileResource.php index fdba5c1..0a8f935 100644 --- a/app/Filament/Clusters/Loans/Resources/LoanOrderMobiles/LoanOrderMobileResource.php +++ b/app/Filament/Clusters/Loans/Resources/LoanOrderMobiles/LoanOrderMobileResource.php @@ -8,7 +8,7 @@ use App\Filament\Clusters\Loans\Resources\LoanOrderMobiles\Pages\EditLoanOrderMo use App\Filament\Clusters\Loans\Resources\LoanOrderMobiles\Pages\ListLoanOrderMobiles; use App\Filament\Clusters\Loans\Resources\LoanOrderMobiles\Schemas\LoanOrderMobileForm; use App\Filament\Clusters\Loans\Resources\LoanOrderMobiles\Tables\LoanOrderMobilesTable; -use App\Modules\LoanOrder\Models\LoanOrder; +use App\Modules\LoanOrderMobile\Models\LoanOrderMobile; use BackedEnum; use Filament\Resources\Resource; use Filament\Schemas\Schema; @@ -19,7 +19,7 @@ use Illuminate\Database\Eloquent\SoftDeletingScope; class LoanOrderMobileResource extends Resource { - protected static ?string $model = LoanOrder::class; + protected static ?string $model = LoanOrderMobile::class; protected static ?int $navigationSort = 3; diff --git a/app/Filament/Clusters/Loans/Resources/LoanOrderMobiles/Schemas/LoanOrderMobileForm.php b/app/Filament/Clusters/Loans/Resources/LoanOrderMobiles/Schemas/LoanOrderMobileForm.php index f1d232a..8d1bc2c 100644 --- a/app/Filament/Clusters/Loans/Resources/LoanOrderMobiles/Schemas/LoanOrderMobileForm.php +++ b/app/Filament/Clusters/Loans/Resources/LoanOrderMobiles/Schemas/LoanOrderMobileForm.php @@ -453,7 +453,7 @@ class LoanOrderMobileForm Tab::make(__('Guarantor').' 2') ->columns(6) ->hidden(function (Get $get): bool { - $loan_amount = string($get('loan_amount')); + $loan_amount = $get('loan_amount') ? string($get('loan_amount')) : 1; return ! ($loan_amount && intval($loan_amount) > 20000); }) diff --git a/app/Modules/LoanOrderMobile/LoanOrderMobileModule.php b/app/Modules/LoanOrderMobile/LoanOrderMobileModule.php new file mode 100644 index 0000000..c1cca1d --- /dev/null +++ b/app/Modules/LoanOrderMobile/LoanOrderMobileModule.php @@ -0,0 +1,64 @@ +enabled; + } + + /** + * Disable module + */ + public function disable(): void + { + $this->enabled = false; + } + + /** + * Enable module + */ + public function enable(): void + { + $this->enabled = true; + } + + /** + * Check if module has a filament resource + */ + public function hasFilamentResource(): bool + { + return false; + } + + /** + * Get module composer requirements + */ + public function getComposerRequirements(): array + { + return []; + } + + /** + * Get module composer suggestions + */ + public function getComposerSuggestions(): array + { + return []; + } +} diff --git a/app/Modules/LoanOrderMobile/Models/LoanOrderMobile.php b/app/Modules/LoanOrderMobile/Models/LoanOrderMobile.php new file mode 100644 index 0000000..fcf5975 --- /dev/null +++ b/app/Modules/LoanOrderMobile/Models/LoanOrderMobile.php @@ -0,0 +1,182 @@ + + */ + protected $casts = [ + 'passport_given_at' => 'date', + 'born_at' => 'date', + 'work_started_at' => 'date', + ]; + + /** + * Loan type + * + * @return BelongsTo + */ + public function loanType(): BelongsTo + { + return $this->belongsTo(LoanType::class, 'loan_type'); + } + + /** + * Branch + * + * @return BelongsTo + */ + public function branch(): BelongsTo + { + return $this->belongsTo(Branch::class); + } + + /** + * Work province + * + * @return BelongsTo + */ + public function workProvince(): BelongsTo + { + return $this->belongsTo(Province::class, 'work_province_id'); + } + + /** + * User (who created order) + * + * @return BelongsTo + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class, 'user_id'); + } + + /** + * Required docs + * + * @return BelongsTo + */ + public function requiredDocs(): BelongsTo + { + return $this->belongsTo(LoanOrderRequiredDocs::class, 'loan_order_required_doc_id'); + } + + /** + * "boot" method for model + */ + protected static function boot() + { + parent::boot(); + + static::creating(LoanOrderRepository::creating()); + static::created(LoanOrderRepository::created()); + // static::updated(function (LoanOrder $model) { + // if ($model->notes && $model->wasChanged('notes')) { + // Alert::create([ + // 'user_id' => $model->user_id, + // 'name' => 'Duýdyryş', + // 'value' => $model->notes, + // ]); + // } + // }); + } +} diff --git a/app/Modules/LoanOrderMobile/Policies/LoanOrderMobilePolicy.php b/app/Modules/LoanOrderMobile/Policies/LoanOrderMobilePolicy.php new file mode 100644 index 0000000..c4b5276 --- /dev/null +++ b/app/Modules/LoanOrderMobile/Policies/LoanOrderMobilePolicy.php @@ -0,0 +1,69 @@ +can('ViewAny:LoanOrderMobile'); + } + + public function view(AuthUser $authUser, LoanOrderMobile $loanOrderMobile): bool + { + return $authUser->can('View:LoanOrderMobile'); + } + + public function create(AuthUser $authUser): bool + { + return $authUser->can('Create:LoanOrderMobile'); + } + + public function update(AuthUser $authUser, LoanOrderMobile $loanOrderMobile): bool + { + return $authUser->can('Update:LoanOrderMobile'); + } + + public function delete(AuthUser $authUser, LoanOrderMobile $loanOrderMobile): bool + { + return $authUser->can('Delete:LoanOrderMobile'); + } + + public function restore(AuthUser $authUser, LoanOrderMobile $loanOrderMobile): bool + { + return $authUser->can('Restore:LoanOrderMobile'); + } + + public function forceDelete(AuthUser $authUser, LoanOrderMobile $loanOrderMobile): bool + { + return $authUser->can('ForceDelete:LoanOrderMobile'); + } + + public function forceDeleteAny(AuthUser $authUser): bool + { + return $authUser->can('ForceDeleteAny:LoanOrderMobile'); + } + + public function restoreAny(AuthUser $authUser): bool + { + return $authUser->can('RestoreAny:LoanOrderMobile'); + } + + public function replicate(AuthUser $authUser, LoanOrderMobile $loanOrderMobile): bool + { + return $authUser->can('Replicate:LoanOrderMobile'); + } + + public function reorder(AuthUser $authUser): bool + { + return $authUser->can('Reorder:LoanOrderMobile'); + } +} diff --git a/app/Modules/LoanOrderMobile/Repositories/LoanOrderMobileRepository.php b/app/Modules/LoanOrderMobile/Repositories/LoanOrderMobileRepository.php new file mode 100644 index 0000000..6881f4f --- /dev/null +++ b/app/Modules/LoanOrderMobile/Repositories/LoanOrderMobileRepository.php @@ -0,0 +1,5 @@ +