From 67fe31439c47206e2631d1306a48053a73468d80 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Mon, 8 Dec 2025 13:46:22 +0700 Subject: [PATCH] refactor(enum): menyelarasikan semua enum agar sama --- app/Enums/ArticleStatus.php | 4 ++-- app/Enums/AuditStockStatus.php | 16 +++++++++++++++- app/Enums/Concentration.php | 4 ++-- app/Enums/Day.php | 15 ++++++++++++++- app/Enums/EmploymentStatus.php | 4 ++-- app/Enums/ExpenseType.php | 4 ++-- app/Enums/Gender.php | 4 ++-- app/Enums/IsActive.php | 4 ++-- app/Enums/IsPaid.php | 4 ++-- app/Enums/IsShow.php | 4 ++-- app/Enums/OutletStatus.php | 4 ++-- app/Enums/PointRecordType.php | 4 ++-- app/Enums/PriceRequestStatus.php | 2 +- app/Enums/SalaryAdjustmentType.php | 4 ++-- app/Enums/StockOpnameStatus.php | 4 ++-- app/Enums/UserRole.php | 27 ++++++++++++++++++++++++++- app/Enums/UserStatus.php | 4 ++-- app/Enums/VoucherType.php | 4 ++-- 18 files changed, 84 insertions(+), 32 deletions(-) diff --git a/app/Enums/ArticleStatus.php b/app/Enums/ArticleStatus.php index 94e3c7e..cb43a82 100644 --- a/app/Enums/ArticleStatus.php +++ b/app/Enums/ArticleStatus.php @@ -13,7 +13,7 @@ enum ArticleStatus: int case DRAFT = 2; case ARCHIVED = 3; - public function label() + public function label(): string { return match ($this) { self::PUBLISHED => 'Publish', @@ -22,7 +22,7 @@ public function label() }; } - public function color() + public function color(): string { return match ($this) { self::PUBLISHED => 'emerald', diff --git a/app/Enums/AuditStockStatus.php b/app/Enums/AuditStockStatus.php index 5d065c2..adab7e6 100644 --- a/app/Enums/AuditStockStatus.php +++ b/app/Enums/AuditStockStatus.php @@ -2,13 +2,27 @@ namespace App\Enums; +use App\Traits\WithCommentEnum; +use App\Traits\WithValueEnum; + enum AuditStockStatus: string { + use WithCommentEnum, WithValueEnum; + case INCREASED = 'Menambah'; case DECREASED = 'Mengurangi'; case UPDATED = 'Mengubah'; - public function color() + public function label(): string + { + return match ($this) { + self::INCREASED => 'Menambah', + self::DECREASED => 'Mengurangi', + self::UPDATED => 'Mengubah', + }; + } + + public function color(): string { return match ($this) { self::INCREASED => 'emerald', diff --git a/app/Enums/Concentration.php b/app/Enums/Concentration.php index b817445..7f93ca3 100644 --- a/app/Enums/Concentration.php +++ b/app/Enums/Concentration.php @@ -14,7 +14,7 @@ enum Concentration: int case EAU_DE_COLOGNE = 3; case EAU_DE_TOILETTE = 4; - public function label() + public function label(): string { return match ($this) { self::EXTRAIT_DE_PERFUME => 'Extrait de Parfum', @@ -24,7 +24,7 @@ public function label() }; } - public function color() + public function color(): string { return match ($this) { self::EXTRAIT_DE_PERFUME => 'emerald', diff --git a/app/Enums/Day.php b/app/Enums/Day.php index fe41de7..e5ed260 100644 --- a/app/Enums/Day.php +++ b/app/Enums/Day.php @@ -17,7 +17,7 @@ enum Day: int case FRIDAY = 6; case SATURDAY = 7; - public function label() + public function label(): string { return match ($this) { self::SUNDAY => 'Minggu', @@ -29,4 +29,17 @@ public function label() self::SATURDAY => 'Sabtu', }; } + + public function color(): string + { + return match ($this) { + self::SUNDAY => 'red', + self::MONDAY => 'blue', + self::TUESDAY => 'green', + self::WEDNESDAY => 'yellow', + self::THURSDAY => 'orange', + self::FRIDAY => 'purple', + self::SATURDAY => 'pink', + }; + } } diff --git a/app/Enums/EmploymentStatus.php b/app/Enums/EmploymentStatus.php index 51c9364..5caecbc 100644 --- a/app/Enums/EmploymentStatus.php +++ b/app/Enums/EmploymentStatus.php @@ -13,7 +13,7 @@ enum EmploymentStatus: int case CONTRACT = 2; case INTERN = 3; - public function label() + public function label(): string { return match ($this) { self::PERMANENT => 'Permanen', @@ -22,7 +22,7 @@ public function label() }; } - public function color() + public function color(): string { return match ($this) { self::PERMANENT => 'emerald', diff --git a/app/Enums/ExpenseType.php b/app/Enums/ExpenseType.php index f849a1c..cad0ccf 100644 --- a/app/Enums/ExpenseType.php +++ b/app/Enums/ExpenseType.php @@ -13,7 +13,7 @@ enum ExpenseType: int case PURCHASE = 2; case SALARY = 3; - public function label() + public function label(): string { return match ($this) { self::OPERATIONAL => 'Operasional', @@ -22,7 +22,7 @@ public function label() }; } - public function color() + public function color(): string { return match ($this) { self::OPERATIONAL => 'emerald', diff --git a/app/Enums/Gender.php b/app/Enums/Gender.php index d156597..402d95c 100644 --- a/app/Enums/Gender.php +++ b/app/Enums/Gender.php @@ -11,7 +11,7 @@ enum Gender: int case MALE = 1; case FEMALE = 2; - public function label() + public function label(): string { return match ($this) { self::MALE => 'Laki-laki', @@ -19,7 +19,7 @@ public function label() }; } - public function color() + public function color(): string { return match ($this) { self::MALE => 'blue', diff --git a/app/Enums/IsActive.php b/app/Enums/IsActive.php index 13628d0..9cd8e9f 100644 --- a/app/Enums/IsActive.php +++ b/app/Enums/IsActive.php @@ -12,7 +12,7 @@ enum IsActive: int case ACTIVE = 1; case INACTIVE = 2; - public function label() + public function label(): string { return match ($this) { self::ACTIVE => 'Aktif', @@ -20,7 +20,7 @@ public function label() }; } - public function color() + public function color(): string { return match ($this) { self::ACTIVE => 'emerald', diff --git a/app/Enums/IsPaid.php b/app/Enums/IsPaid.php index 1ea0662..f362227 100644 --- a/app/Enums/IsPaid.php +++ b/app/Enums/IsPaid.php @@ -12,7 +12,7 @@ enum IsPaid: int case PAID = 1; case NOT_PAID = 2; - public function label() + public function label(): string { return match ($this) { self::PAID => 'Dibayar', @@ -20,7 +20,7 @@ public function label() }; } - public function color() + public function color(): string { return match ($this) { self::PAID => 'emerald', diff --git a/app/Enums/IsShow.php b/app/Enums/IsShow.php index eabfe17..7c9398e 100644 --- a/app/Enums/IsShow.php +++ b/app/Enums/IsShow.php @@ -12,7 +12,7 @@ enum IsShow: int case SHOW = 1; case HIDDEN = 2; - public function label() + public function label(): string { return match ($this) { self::SHOW => 'Ditampilkan', @@ -20,7 +20,7 @@ public function label() }; } - public function color() + public function color(): string { return match ($this) { self::SHOW => 'emerald', diff --git a/app/Enums/OutletStatus.php b/app/Enums/OutletStatus.php index b79be75..20c55e6 100644 --- a/app/Enums/OutletStatus.php +++ b/app/Enums/OutletStatus.php @@ -13,7 +13,7 @@ enum OutletStatus: int case UNDER_CONSTRUCTION = 2; case TERMINATED = 3; - public function label() + public function label(): string { return match ($this) { self::OPERATIONAL => 'Operasional', @@ -22,7 +22,7 @@ public function label() }; } - public function color() + public function color(): string { return match ($this) { self::OPERATIONAL => 'emerald', diff --git a/app/Enums/PointRecordType.php b/app/Enums/PointRecordType.php index 5bd2217..fc33e29 100644 --- a/app/Enums/PointRecordType.php +++ b/app/Enums/PointRecordType.php @@ -12,7 +12,7 @@ enum PointRecordType: int case TIER = 1; case REWARD = 2; - public function label() + public function label(): string { return match ($this) { self::TIER => 'Tier', @@ -20,7 +20,7 @@ public function label() }; } - public function color() + public function color(): string { return match ($this) { self::TIER => 'emerald', diff --git a/app/Enums/PriceRequestStatus.php b/app/Enums/PriceRequestStatus.php index 1e8c1a6..18ba11d 100644 --- a/app/Enums/PriceRequestStatus.php +++ b/app/Enums/PriceRequestStatus.php @@ -22,7 +22,7 @@ public function label(): string }; } - public function color() + public function color(): string { return match ($this) { self::PENDING => 'gray', diff --git a/app/Enums/SalaryAdjustmentType.php b/app/Enums/SalaryAdjustmentType.php index b8be00c..acd18c6 100644 --- a/app/Enums/SalaryAdjustmentType.php +++ b/app/Enums/SalaryAdjustmentType.php @@ -12,7 +12,7 @@ enum SalaryAdjustmentType: int case BONUS = 1; case DEDUCTION = 2; - public function label() + public function label(): string { return match ($this) { self::BONUS => 'Bonus', @@ -20,7 +20,7 @@ public function label() }; } - public function color() + public function color(): string { return match ($this) { self::BONUS => 'emerald', diff --git a/app/Enums/StockOpnameStatus.php b/app/Enums/StockOpnameStatus.php index e42681a..ebdb031 100644 --- a/app/Enums/StockOpnameStatus.php +++ b/app/Enums/StockOpnameStatus.php @@ -14,7 +14,7 @@ enum StockOpnameStatus: int case PENDING_APPROVAL = 3; case COMPLETED = 4; - public function label() + public function label(): string { return match ($this) { self::DRAFT => 'Draft', @@ -24,7 +24,7 @@ public function label() }; } - public function color() + public function color(): string { return match ($this) { self::DRAFT => 'yellow', diff --git a/app/Enums/UserRole.php b/app/Enums/UserRole.php index 100ee94..c8d4b1a 100644 --- a/app/Enums/UserRole.php +++ b/app/Enums/UserRole.php @@ -2,11 +2,12 @@ namespace App\Enums; +use App\Traits\WithCommentEnum; use App\Traits\WithValueEnum; enum UserRole: string { - use WithValueEnum; + use WithCommentEnum, WithValueEnum; case Developer = 'Developer'; case Owner = 'Owner'; @@ -14,4 +15,28 @@ enum UserRole: string case Admin = 'Admin'; case Partner = 'Partner'; case Customer = 'Customer'; + + public function label(): string + { + return match ($this) { + self::Developer => 'Developer', + self::Owner => 'Owner', + self::Leader => 'Leader', + self::Admin => 'Admin', + self::Partner => 'Partner', + self::Customer => 'Customer', + }; + } + + public function color(): string + { + return match ($this) { + self::Developer => 'purple', + self::Owner => 'emerald', + self::Leader => 'blue', + self::Admin => 'orange', + self::Partner => 'cyan', + self::Customer => 'gray', + }; + } } diff --git a/app/Enums/UserStatus.php b/app/Enums/UserStatus.php index 89858a5..39ef464 100644 --- a/app/Enums/UserStatus.php +++ b/app/Enums/UserStatus.php @@ -12,7 +12,7 @@ enum UserStatus: int case ACTIVE = 1; case INACTIVE = 2; - public function label() + public function label(): string { return match ($this) { self::ACTIVE => 'Aktif', @@ -20,7 +20,7 @@ public function label() }; } - public function color() + public function color(): string { return match ($this) { self::ACTIVE => 'emerald', diff --git a/app/Enums/VoucherType.php b/app/Enums/VoucherType.php index 554b68d..f4e752e 100644 --- a/app/Enums/VoucherType.php +++ b/app/Enums/VoucherType.php @@ -12,7 +12,7 @@ enum VoucherType: int case FIXED = 1; case PERCENTAGE = 2; - public function label() + public function label(): string { return match ($this) { self::FIXED => 'Nominal', @@ -20,7 +20,7 @@ public function label() }; } - public function color() + public function color(): string { return match ($this) { self::FIXED => 'blue',