first commit
This commit is contained in:
28
app/Enums/ExpenseCategory.php
Normal file
28
app/Enums/ExpenseCategory.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum ExpenseCategory: string
|
||||
{
|
||||
case Alcohol = 'alcohol';
|
||||
case Narcotic = 'narcotic';
|
||||
case Solutions = 'solutions';
|
||||
case Medicines = 'medicines';
|
||||
case Dressing = 'dressing';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Alcohol => 'Спирт',
|
||||
self::Narcotic => 'Наркотики',
|
||||
self::Solutions => 'Растворы',
|
||||
self::Medicines => 'Медикаменты',
|
||||
self::Dressing => 'Перевязка / ИМН',
|
||||
};
|
||||
}
|
||||
|
||||
public function countsTowardsWithoutDressing(): bool
|
||||
{
|
||||
return $this !== self::Dressing;
|
||||
}
|
||||
}
|
||||
23
app/Enums/FundingSource.php
Normal file
23
app/Enums/FundingSource.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum FundingSource: string
|
||||
{
|
||||
case Oms = 'oms';
|
||||
case Budget = 'budget';
|
||||
case Paid = 'paid';
|
||||
case VmpOms = 'vmp_oms';
|
||||
case VmpBudget = 'vmp_budget';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Oms => 'ОМС',
|
||||
self::Budget => 'Бюджет',
|
||||
self::Paid => 'ОПУ',
|
||||
self::VmpOms => 'ВМП ОМС',
|
||||
self::VmpBudget => 'ВМП Бюджет',
|
||||
};
|
||||
}
|
||||
}
|
||||
17
app/Enums/ReportPeriodStatus.php
Normal file
17
app/Enums/ReportPeriodStatus.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum ReportPeriodStatus: string
|
||||
{
|
||||
case Draft = 'draft';
|
||||
case Approved = 'approved';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Draft => 'Черновик',
|
||||
self::Approved => 'Утвержден',
|
||||
};
|
||||
}
|
||||
}
|
||||
16
app/Enums/TeamPermission.php
Normal file
16
app/Enums/TeamPermission.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum TeamPermission: string
|
||||
{
|
||||
case UpdateTeam = 'team:update';
|
||||
case DeleteTeam = 'team:delete';
|
||||
|
||||
case AddMember = 'member:add';
|
||||
case UpdateMember = 'member:update';
|
||||
case RemoveMember = 'member:remove';
|
||||
|
||||
case CreateInvitation = 'invitation:create';
|
||||
case CancelInvitation = 'invitation:cancel';
|
||||
}
|
||||
79
app/Enums/TeamRole.php
Normal file
79
app/Enums/TeamRole.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum TeamRole: string
|
||||
{
|
||||
case Owner = 'owner';
|
||||
case Admin = 'admin';
|
||||
case Member = 'member';
|
||||
|
||||
/**
|
||||
* Get the display label for the role.
|
||||
*/
|
||||
public function label(): string
|
||||
{
|
||||
return ucfirst($this->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the permissions for this role.
|
||||
*
|
||||
* @return array<TeamPermission>
|
||||
*/
|
||||
public function permissions(): array
|
||||
{
|
||||
return match ($this) {
|
||||
self::Owner => TeamPermission::cases(),
|
||||
self::Admin => [
|
||||
TeamPermission::UpdateTeam,
|
||||
TeamPermission::CreateInvitation,
|
||||
TeamPermission::CancelInvitation,
|
||||
],
|
||||
self::Member => [],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the role has the given permission.
|
||||
*/
|
||||
public function hasPermission(TeamPermission $permission): bool
|
||||
{
|
||||
return in_array($permission, $this->permissions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hierarchy level for this role.
|
||||
* Higher numbers indicate higher privileges.
|
||||
*/
|
||||
public function level(): int
|
||||
{
|
||||
return match ($this) {
|
||||
self::Owner => 3,
|
||||
self::Admin => 2,
|
||||
self::Member => 1,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this role is at least as privileged as another role.
|
||||
*/
|
||||
public function isAtLeast(TeamRole $role): bool
|
||||
{
|
||||
return $this->level() >= $role->level();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the roles that can be assigned to team members (excludes Owner).
|
||||
*
|
||||
* @return array<array{value: string, label: string}>
|
||||
*/
|
||||
public static function assignable(): array
|
||||
{
|
||||
return collect(self::cases())
|
||||
->filter(fn (self $role) => $role !== self::Owner)
|
||||
->map(fn (self $role) => ['value' => $role->value, 'label' => $role->label()])
|
||||
->values()
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user