This commit is contained in:
2025-11-04 21:07:23 +05:00
parent 84c4a584a0
commit 310590010c
13 changed files with 119 additions and 24 deletions

View File

@@ -36,13 +36,26 @@ class CardOrderForm
Section::make(__('New card order'))
->columnSpan(4)
->columns(4)
->disabled(function (string $context) {
if (user()->isSystemUser()) {
return false;
}
return true;
})
->hidden(function (string $context): bool {
if (user()->isSystemUser()) {
return false;
}
return $context === 'create';
})
->components([
Select::make('status')
->label(__('Status'))
->options(OrderStatusRepository::statusValues())
->default(OrderStatusRepository::defaultStatus())
->native(false)
->required()
->columnSpan(2),
Toggle::make('paid')

View File

@@ -29,6 +29,20 @@ class CardPinOrderForm
Section::make(__('New card pin order'))
->columnSpanFull()
->disabled(function (string $context) {
if (user()->isSystemUser()) {
return false;
}
return true;
})
->hidden(function (string $context): bool {
if (user()->isSystemUser()) {
return false;
}
return $context === 'create';
})
->components([
Select::make('status')
->label(__('Status'))

View File

@@ -22,6 +22,7 @@ class LoanForm
->default(user()->getOption('passport_id')),
TextInput::make('account_number')
->label(__('Account number'))
->required()
->string()
->maxLength(23),

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Filament\Clusters\Users;
use BackedEnum;
use Filament\Clusters\Cluster;
use Filament\Pages\Enums\SubNavigationPosition;
use Filament\Support\Icons\Heroicon;
class UsersCluster extends Cluster
{
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedUsers;
protected static string|BackedEnum|null $activeNavigationIcon = Heroicon::Users;
protected static ?SubNavigationPosition $subNavigationPosition = SubNavigationPosition::Top;
public static function getNavigationLabel(): string
{
return __('Users');
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Filament\Resources\Users\Schemas;
use App\Modules\PhoneNumberVerification\Rules\PhoneNumberVerificationRule;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Schema;
@@ -13,50 +14,58 @@ class UserForm
public static function configure(Schema $schema): Schema
{
return $schema
->columns(2)
->columns(6)
->components([
TextInput::make('first_name')
->label(__('First name'))
->required(),
TextInput::make('last_name')
->label(__('Last name'))
->required(),
TextInput::make('name')
->label(__('Full Name'))
->required()
->columnSpan(3),
TextInput::make('username')
->label(__('Username'))
->required()
->unique(ignoreRecord: true),
->unique(ignoreRecord: true)
->columnSpan(3),
TextInput::make('phone')
->label(__('Phone number'))
->unique(ignoreRecord: true),
->label(__('Phone'))
->unique(ignoreRecord: true)
->mask('99 99 99 99')
->prefix('+993')
->rules([
new PhoneNumberVerificationRule,
])
->columnSpan(2),
TextInput::make('email')
->label(__('Email'))
->email()
->unique(ignoreRecord: true),
->unique(ignoreRecord: true)
->columnSpan(2),
TextInput::make('password')
->label(__('Password'))
->password()
->dehydrateStateUsing(fn ($state) => Hash::make($state))
->dehydrated(fn ($state) => filled($state))
->required(fn (string $context): bool => $context === 'create'),
->required(fn (string $context): bool => $context === 'create')
->columnSpan(2),
Select::make('roles')
->label(__('Roles'))
->relationship('roles', 'name')
->multiple()
->preload()
->native(false),
->native(false)
->columnSpan(3),
Select::make('branches')
->label(__('Branches'))
->relationship('branches', 'name', fn (Builder $query) => $query->distinct('id')->orderBy('id'))
->multiple()
->preload()
->native(false),
->native(false)
->columnSpan(3),
]);
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Filament\Resources\Users;
use App\Filament\Clusters\Users\UsersCluster;
use App\Filament\Resources\Users\Pages\CreateUser;
use App\Filament\Resources\Users\Pages\EditUser;
use App\Filament\Resources\Users\Pages\ListUsers;
@@ -16,15 +17,15 @@ use Filament\Tables\Table;
class UserResource extends Resource
{
protected static ?int $navigationSort = 2;
protected static ?string $model = User::class;
protected static ?string $cluster = UsersCluster::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedUsers;
protected static string|BackedEnum|null $activeNavigationIcon = Heroicon::Users;
protected static ?string $recordTitleAttribute = 'first_name';
protected static ?string $recordTitleAttribute = 'phone';
public static function getNavigationLabel(): string
{

View File

@@ -16,8 +16,13 @@ class RedirectIfUserPhoneIsVerfied
*/
public function handle(Request $request, Closure $next): Response
{
if (Auth::check() && ! is_null($request->user()?->phone_verified_at)) {
return redirect(config()->string('module.base-auth.redirect_path'));
if (Auth::check()) {
/** @var \App\Models\User */
$user = $request->user();
if (! is_null($user->phone_verified_at) || $user->isSystemUser()) {
return redirect(config()->string('module.base-auth.redirect_path'));
}
}
return $next($request);

View File

@@ -12,11 +12,21 @@ class UserBranch extends Pivot
protected $table = 'branch_user';
/**
* Branch
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<Branch, $this>
*/
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class);
}
/**
* User
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<User, $this>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);

View File

@@ -3,8 +3,11 @@
namespace App\Modules\CardPinOrder\Models;
use App\Models\User;
use App\Modules\Branch\Interfaces\BelongsToBranch;
use App\Modules\Branch\Models\Branch;
use App\Modules\CardOrder\Models\CardType;
use App\Modules\LoanOrder\Repositories\LoanOrderRepository;
use App\Modules\OrderStatus\Interfaces\HasStatus;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -33,7 +36,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
*/
class CardPinOrder extends Model
class CardPinOrder extends Model implements BelongsToBranch, HasStatus
{
/**
* The attributes that should be cast.
@@ -73,4 +76,15 @@ class CardPinOrder extends Model
{
return $this->belongsTo(Branch::class);
}
/**
* "boot" method for model
*/
protected static function boot(): void
{
parent::boot();
static::creating(LoanOrderRepository::creating());
static::created(LoanOrderRepository::created());
}
}

View File

@@ -106,6 +106,7 @@ class OrderStatusRepository
self::PROCESSING => 'primary',
self::COMPLETED => 'success',
self::CANCELLED => 'danger',
default => 'primary',
};
}

View File

@@ -41,7 +41,7 @@ trait RoleCheckers
*/
public function isOperator(): bool
{
return $this->hasRole('operator');
return $this->hasRole(['operator', 'operator_card', 'operator_loan']);
}
/**
@@ -57,6 +57,6 @@ trait RoleCheckers
*/
public function isSystemUser(): bool
{
return $this->hasAnyRole();
return $this->isAdmin() || $this->isOperator();
}
}

View File

@@ -76,6 +76,8 @@ trait UserAdjustments
/**
* User branches
*
* @return HasMany<UserBranch, $this>
*/
public function userBranches(): HasMany
{