From 95c6d5746b87754b8b4e75f8912b03cf40b0dd62 Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Fri, 8 Nov 2024 16:58:23 +0500 Subject: [PATCH] add usercompany --- app/Filament/Resources/BankResource.php | 15 ++- .../Resources/Company/UserCompanyResource.php | 91 ++++++++++++++++++ .../Pages/CreateUserCompany.php | 18 ++++ .../Pages/EditUserCompany.php | 19 ++++ .../Pages/ListUserCompanies.php | 19 ++++ app/Modules/AppHelpers/.DS_Store | Bin 0 -> 6148 bytes app/Modules/AppHelpers/AppHelpersModule.php | 48 +++++++++ .../AppHelpers/Enums/HasEnumHelpers.php | 16 +++ ..._04_184437_create_user_companies_table.php | 1 + .../UserCompany/Models/UserCompany.php | 26 ++++- app/Modules/UserCompany/Types/CompanyType.php | 63 ++++++++++++ 11 files changed, 312 insertions(+), 4 deletions(-) create mode 100644 app/Filament/Resources/Company/UserCompanyResource.php create mode 100644 app/Filament/Resources/Company/UserCompanyResource/Pages/CreateUserCompany.php create mode 100644 app/Filament/Resources/Company/UserCompanyResource/Pages/EditUserCompany.php create mode 100644 app/Filament/Resources/Company/UserCompanyResource/Pages/ListUserCompanies.php create mode 100644 app/Modules/AppHelpers/.DS_Store create mode 100644 app/Modules/AppHelpers/AppHelpersModule.php create mode 100644 app/Modules/AppHelpers/Enums/HasEnumHelpers.php create mode 100644 app/Modules/UserCompany/Types/CompanyType.php diff --git a/app/Filament/Resources/BankResource.php b/app/Filament/Resources/BankResource.php index 4a21a16..9978738 100644 --- a/app/Filament/Resources/BankResource.php +++ b/app/Filament/Resources/BankResource.php @@ -24,9 +24,17 @@ class BankResource extends Resource { return $form ->schema([ - TextInput::make('name'), - TextInput::make('bab'), - TextInput::make('hb'), + TextInput::make('name') + ->required() + ->unique(), + + TextInput::make('bab') + ->required() + ->unique(), + + TextInput::make('hb') + ->required() + ->unique(), ]); } @@ -61,6 +69,7 @@ class BankResource extends Resource ]) ->actions([ Tables\Actions\EditAction::make(), + Tables\Actions\DeleteAction::make(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ diff --git a/app/Filament/Resources/Company/UserCompanyResource.php b/app/Filament/Resources/Company/UserCompanyResource.php new file mode 100644 index 0000000..272b0f7 --- /dev/null +++ b/app/Filament/Resources/Company/UserCompanyResource.php @@ -0,0 +1,91 @@ +schema([ + Select::make('company_type') + ->label('Kompaniýa görnüşi') + ->native(false) + ->options(CompanyType::options()) + ->default(CompanyType::default()) + ->required(), + + TextInput::make('ssb') + ->label('Şahsy salgyt belgisi') + ->unique(ignoreRecord: true) + ->required(), + + TextInput::make('hb') + ->label('HB') + ->unique(ignoreRecord: true) + ->required(), + + Select::make('bank_id') + ->relationship(name: 'bank', titleAttribute: 'name') + ->searchable() + ->preload() + ->required(), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + TextColumn::make('company_type') + ->badge() + ->formatStateUsing(fn (string $state): string => CompanyType::options()[$state]) + ->color(fn (string $state): string => CompanyType::statusClass($state)), + // 'ssb' + // 'hb' + // 'bank_id' + ]) + ->filters([ + // + ]) + ->actions([ + Tables\Actions\EditAction::make(), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + ]), + ]); + } + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListUserCompanies::route('/'), + 'create' => Pages\CreateUserCompany::route('/create'), + 'edit' => Pages\EditUserCompany::route('/{record}/edit'), + ]; + } +} diff --git a/app/Filament/Resources/Company/UserCompanyResource/Pages/CreateUserCompany.php b/app/Filament/Resources/Company/UserCompanyResource/Pages/CreateUserCompany.php new file mode 100644 index 0000000..8fa97bf --- /dev/null +++ b/app/Filament/Resources/Company/UserCompanyResource/Pages/CreateUserCompany.php @@ -0,0 +1,18 @@ +id(); + + return $data; + } +} diff --git a/app/Filament/Resources/Company/UserCompanyResource/Pages/EditUserCompany.php b/app/Filament/Resources/Company/UserCompanyResource/Pages/EditUserCompany.php new file mode 100644 index 0000000..5d4800b --- /dev/null +++ b/app/Filament/Resources/Company/UserCompanyResource/Pages/EditUserCompany.php @@ -0,0 +1,19 @@ +H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0enabled; + } + + /** + * 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 true; + } +} diff --git a/app/Modules/AppHelpers/Enums/HasEnumHelpers.php b/app/Modules/AppHelpers/Enums/HasEnumHelpers.php new file mode 100644 index 0000000..dd16813 --- /dev/null +++ b/app/Modules/AppHelpers/Enums/HasEnumHelpers.php @@ -0,0 +1,16 @@ + + */ + public static function values(): array + { + return array_map(fn ($case) => $case->value, static::cases()); + } +} diff --git a/app/Modules/UserCompany/Database/Migrations/2024_11_04_184437_create_user_companies_table.php b/app/Modules/UserCompany/Database/Migrations/2024_11_04_184437_create_user_companies_table.php index 1f2cfff..66e6f40 100644 --- a/app/Modules/UserCompany/Database/Migrations/2024_11_04_184437_create_user_companies_table.php +++ b/app/Modules/UserCompany/Database/Migrations/2024_11_04_184437_create_user_companies_table.php @@ -28,6 +28,7 @@ return new class extends Migration ->nullable(); $table->foreignId('bank_id')->nullable()->constrained('banks')->nullOnDelete(); + $table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete(); $table->timestamps(); }); diff --git a/app/Modules/UserCompany/Models/UserCompany.php b/app/Modules/UserCompany/Models/UserCompany.php index da3b95a..0977ad4 100644 --- a/app/Modules/UserCompany/Models/UserCompany.php +++ b/app/Modules/UserCompany/Models/UserCompany.php @@ -2,6 +2,30 @@ namespace App\Modules\UserCompany\Models; +use App\Models\User; +use App\Modules\Bank\Models\Bank; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; -class UserCompany extends Model {} +class UserCompany extends Model +{ + /** + * User + * + * @return BelongsTo + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + + /** + * Bank + * + * @return BelongsTo + */ + public function bank(): BelongsTo + { + return $this->belongsTo(Bank::class); + } +} diff --git a/app/Modules/UserCompany/Types/CompanyType.php b/app/Modules/UserCompany/Types/CompanyType.php new file mode 100644 index 0000000..7c5f7ac --- /dev/null +++ b/app/Modules/UserCompany/Types/CompanyType.php @@ -0,0 +1,63 @@ + + */ + public static function options(): array + { + return [ + self::TELEKECI->value => __('Telekeçi'), + self::HK->value => __('Hususy kärhana'), + self::HJ->value => __('Hojalyk jemgyýeti'), + ]; + } + + /** + * Default option + */ + public static function default(): string + { + return self::TELEKECI->value; + } + + /** + * Status classes + * + * @return array + */ + public static function statusClasses(): array + { + return [ + self::TELEKECI->value => 'success', + self::HK->value => 'danger', + self::HJ->value => 'warning', + ]; + } + + /** + * Get status + */ + public static function statusClass(?string $key): string + { + return self::statusClasses()[$key] ?? 'danger'; + } +}