refactor: update enum handling in migrations and seeder, replace array_column with values() method for better performance and consistency
This commit is contained in:
parent
a5158c3992
commit
b43835335a
@ -156,10 +156,10 @@ ### Definisi Kolom & Tipe Data
|
||||
$table->softDeletes();
|
||||
```
|
||||
- **Kolom Enum:**
|
||||
- Hubungkan dengan PHP Backed Enum menggunakan `array_column(EnumName::cases(), 'value')`.
|
||||
- Hubungkan dengan PHP Backed Enum menggunakan `EnumName::values()`.
|
||||
- **Contoh:**
|
||||
```php
|
||||
$table->enum('status', array_column(StatusEnum::cases(), 'value'))->default(StatusEnum::PENDING->value);
|
||||
$table->enum('status', StatusEnum::values())->default(StatusEnum::PENDING->value);
|
||||
```
|
||||
|
||||
### Relasi & Foreign Key
|
||||
|
||||
@ -2,8 +2,12 @@
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\ProvidesEnumOptions;
|
||||
|
||||
enum StokOpnameStatus: string
|
||||
{
|
||||
use ProvidesEnumOptions;
|
||||
|
||||
case DRAFT = 'draft';
|
||||
case PENDING = 'pending';
|
||||
case VERIFIED = 'verified';
|
||||
|
||||
@ -19,7 +19,7 @@ public function up(): void
|
||||
|
||||
$table->string('full_name', 200);
|
||||
$table->string('phone_number', 20)->nullable();
|
||||
$table->enum('gender', array_column(Gender::cases(), 'value'))->nullable();
|
||||
$table->enum('gender', Gender::values())->nullable();
|
||||
$table->date('birth_date')->nullable();
|
||||
$table->text('address')->nullable();
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ public function up(): void
|
||||
|
||||
$table->date('join_date');
|
||||
$table->date('resign_date')->nullable();
|
||||
$table->enum('employment_status', array_column(EmploymentStatus::cases(), 'value'))->default(EmploymentStatus::FULL_TIME->value);
|
||||
$table->enum('employment_status', EmploymentStatus::values())->default(EmploymentStatus::FULL_TIME->value);
|
||||
$table->unsignedInteger('base_salary');
|
||||
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
|
||||
@ -16,6 +16,7 @@ public function up(): void
|
||||
$table->string('name', 200);
|
||||
$table->unsignedInteger('stock')->default(0);
|
||||
$table->unsignedInteger('reject_stock')->default(0);
|
||||
$table->unsignedInteger('stock_ecer')->default(0);
|
||||
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
|
||||
|
||||
@ -13,7 +13,7 @@ public function up(): void
|
||||
$table->id();
|
||||
|
||||
$table->string('name', 200);
|
||||
$table->enum('unit', array_column(RawMaterialUnit::cases(), 'value'));
|
||||
$table->enum('unit', RawMaterialUnit::values());
|
||||
$table->boolean('is_active')->default(true);
|
||||
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
|
||||
@ -18,7 +18,7 @@ public function up(): void
|
||||
|
||||
$table->unsignedBigInteger('amount');
|
||||
$table->unsignedBigInteger('balance_after');
|
||||
$table->enum('type', array_column(CashTransactionType::cases(), 'value'))->default(CashTransactionType::DEPOSIT->value);
|
||||
$table->enum('type', CashTransactionType::values())->default(CashTransactionType::DEPOSIT->value);
|
||||
$table->string('description', 100);
|
||||
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
|
||||
@ -19,9 +19,10 @@ public function up(): void
|
||||
$table->foreignId('cash_transaction_id')->nullable()->unique()->constrained()->restrictOnDelete();
|
||||
|
||||
$table->unsignedBigInteger('amount');
|
||||
$table->unsignedBigInteger('paid_amount')->default(0);
|
||||
$table->string('description', 100);
|
||||
$table->date('due_date');
|
||||
$table->enum('status', array_column(EmployeeAdvanceStatus::cases(), 'value'))
|
||||
$table->enum('status', EmployeeAdvanceStatus::values())
|
||||
->default(EmployeeAdvanceStatus::PENDING->value);
|
||||
$table->timestamp('verified_at')->nullable();
|
||||
$table->timestamp('paid_at')->nullable();
|
||||
|
||||
@ -16,7 +16,7 @@ public function up(): void
|
||||
|
||||
$table->unsignedSmallInteger('year');
|
||||
$table->unsignedTinyInteger('month');
|
||||
$table->enum('status', array_column(PayrollPeriodStatus::cases(), 'value'))->default(PayrollPeriodStatus::OPEN->value);
|
||||
$table->enum('status', PayrollPeriodStatus::values())->default(PayrollPeriodStatus::OPEN->value);
|
||||
$table->timestamp('closed_at')->nullable();
|
||||
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
|
||||
@ -21,7 +21,7 @@ public function up(): void
|
||||
$table->unsignedBigInteger('bonus_amount')->default(0);
|
||||
$table->unsignedBigInteger('deduction_amount')->default(0);
|
||||
$table->unsignedBigInteger('total_amount');
|
||||
$table->enum('status', array_column(PayrollStatus::cases(), 'value'))->default(PayrollStatus::UNPAID->value);
|
||||
$table->enum('status', PayrollStatus::values())->default(PayrollStatus::UNPAID->value);
|
||||
$table->timestamp('paid_at')->nullable();
|
||||
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
|
||||
@ -16,7 +16,7 @@ public function up(): void
|
||||
$table->foreignId('attendance_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->foreignId('created_by_id')->constrained('users')->restrictOnDelete();
|
||||
|
||||
$table->enum('type', array_column(PayrollAdjustmentType::cases(), 'value'));
|
||||
$table->enum('type', PayrollAdjustmentType::values());
|
||||
$table->unsignedBigInteger('amount');
|
||||
$table->string('description', 100);
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ public function up(): void
|
||||
$table->date('start_date');
|
||||
$table->date('end_date');
|
||||
$table->unsignedInteger('total_days');
|
||||
$table->enum('status', array_column(LeaveRequestStatus::cases(), 'value'))->default(LeaveRequestStatus::PENDING->value);
|
||||
$table->enum('status', LeaveRequestStatus::values())->default(LeaveRequestStatus::PENDING->value);
|
||||
$table->timestamp('verified_at')->nullable();
|
||||
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
|
||||
@ -21,16 +21,16 @@ public function up(): void
|
||||
$table->foreignId('created_by_id')->constrained('users')->restrictOnDelete();
|
||||
|
||||
$table->string('order_number', 30)->unique();
|
||||
$table->enum('channel', array_column(OrderChannel::cases(), 'value'));
|
||||
$table->enum('price_type', array_column(PriceType::cases(), 'value'));
|
||||
$table->enum('status', array_column(OrderStatus::cases(), 'value'))->default(OrderStatus::PENDING->value);
|
||||
$table->enum('payment_type', array_column(PaymentType::cases(), 'value'))->default(PaymentType::CASH->value);
|
||||
$table->enum('channel', OrderChannel::values());
|
||||
$table->enum('price_type', PriceType::values());
|
||||
$table->enum('status', OrderStatus::values())->default(OrderStatus::PENDING->value);
|
||||
$table->enum('payment_type', PaymentType::values())->default(PaymentType::CASH->value);
|
||||
$table->boolean('is_affiliate')->default(false);
|
||||
$table->string('tiktok_order_id', 100)->nullable();
|
||||
$table->string('shopee_order_id', 100)->nullable();
|
||||
$table->unsignedBigInteger('subtotal');
|
||||
$table->unsignedBigInteger('discount')->default(0);
|
||||
$table->unsignedBigInteger('shipping_cost')->default(0);
|
||||
$table->unsignedBigInteger('nego_price')->nullable();
|
||||
$table->json('marketplace_settings_snapshot')->nullable();
|
||||
$table->unsignedBigInteger('total_amount');
|
||||
$table->text('notes')->nullable();
|
||||
|
||||
@ -16,7 +16,7 @@ public function up(): void
|
||||
$table->foreignId('user_id')->nullable()->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('product_variant_id')->constrained()->restrictOnDelete();
|
||||
|
||||
$table->enum('stock_quality', array_column(ProductStockQuality::cases(), 'value'))->default(ProductStockQuality::GOOD->value);
|
||||
$table->enum('stock_quality', ProductStockQuality::values())->default(ProductStockQuality::GOOD->value);
|
||||
$table->unsignedInteger('quantity');
|
||||
$table->unsignedBigInteger('unit_price');
|
||||
$table->unsignedBigInteger('subtotal');
|
||||
|
||||
@ -16,7 +16,7 @@ public function up(): void
|
||||
$table->foreignId('created_by_id')->constrained('users')->restrictOnDelete();
|
||||
$table->foreignId('submitted_by_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
|
||||
$table->enum('status', array_column(CuttingStatus::cases(), 'value'))->default(CuttingStatus::IN_PROGRESS->value);
|
||||
$table->enum('status', CuttingStatus::values())->default(CuttingStatus::IN_PROGRESS->value);
|
||||
$table->string('description', 100)->nullable();
|
||||
|
||||
$table->unsignedBigInteger('total_material_cost')->nullable();
|
||||
@ -36,7 +36,7 @@ public function up(): void
|
||||
$table->foreignId('cutting_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('product_variant_id')->constrained()->restrictOnDelete();
|
||||
|
||||
$table->enum('price_type', array_column(PriceType::cases(), 'value'));
|
||||
$table->enum('price_type', PriceType::values());
|
||||
$table->unsignedBigInteger('price');
|
||||
$table->unsignedBigInteger('cost_per_unit');
|
||||
|
||||
|
||||
@ -16,7 +16,6 @@ public function up(): void
|
||||
$table->foreignId('raw_material_price_id')->constrained()->restrictOnDelete();
|
||||
|
||||
$table->decimal('material_usage', 18, 2);
|
||||
$table->decimal('remaining_material', 18, 2);
|
||||
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
|
||||
|
||||
@ -16,12 +16,12 @@ public function up(): void
|
||||
$table->foreignId('product_variant_id')->constrained()->restrictOnDelete();
|
||||
|
||||
$table->unsignedInteger('cutting_result');
|
||||
$table->unsignedInteger('warehouse_stock');
|
||||
$table->unsignedInteger('cutting_reject')->default(0);
|
||||
$table->unsignedInteger('sampel');
|
||||
$table->unsignedInteger('hasil_cutting_diluar_sampel')->default(0);
|
||||
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
|
||||
$table->softDeletes();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ public function up(): void
|
||||
|
||||
$table->foreignId('variant_id')->constrained('product_variants')->cascadeOnDelete();
|
||||
|
||||
$table->enum('type', array_column(PriceType::cases(), 'value'));
|
||||
$table->enum('type', PriceType::values());
|
||||
$table->unsignedInteger('price');
|
||||
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('cutting_materials', function (Blueprint $table): void {
|
||||
$table->decimal('material_usage', 18, 2)->change();
|
||||
$table->decimal('remaining_material', 18, 2)->change();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('cutting_materials', function (Blueprint $table): void {
|
||||
$table->decimal('material_usage', 18, 2)->change();
|
||||
$table->decimal('remaining_material', 18, 2)->change();
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('employee_advances', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('paid_amount')->default(0)->after('amount');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('employee_advances', function (Blueprint $table) {
|
||||
$table->dropColumn('paid_amount');
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('orders', function (Blueprint $table) {
|
||||
$table->dropColumn('shipping_cost');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('orders', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('shipping_cost')->default(0)->after('discount');
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
// 1. Drop remaining_material from cutting_materials
|
||||
Schema::table('cutting_materials', function (Blueprint $table): void {
|
||||
$table->dropColumn('remaining_material');
|
||||
});
|
||||
|
||||
// 2. Rename warehouse_stock -> sampel, cutting_reject -> hasil_cutting_diluar_sampel in cutting_results
|
||||
Schema::table('cutting_results', function (Blueprint $table): void {
|
||||
$table->renameColumn('warehouse_stock', 'sampel');
|
||||
$table->renameColumn('cutting_reject', 'hasil_cutting_diluar_sampel');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// 1. Add back remaining_material to cutting_materials
|
||||
Schema::table('cutting_materials', function (Blueprint $table): void {
|
||||
$table->decimal('remaining_material', 18, 2)->after('material_usage');
|
||||
});
|
||||
|
||||
// 2. Rename back to original names
|
||||
Schema::table('cutting_results', function (Blueprint $table): void {
|
||||
$table->renameColumn('sampel', 'warehouse_stock');
|
||||
$table->renameColumn('hasil_cutting_diluar_sampel', 'cutting_reject');
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
DB::statement("ALTER TABLE employee_advances MODIFY COLUMN status ENUM('pending','approved','rejected','partially_paid','paid') DEFAULT 'pending'");
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
DB::statement("ALTER TABLE employee_advances MODIFY COLUMN status ENUM('pending','approved','rejected','paid') DEFAULT 'pending'");
|
||||
}
|
||||
};
|
||||
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('product_variants', function (Blueprint $table) {
|
||||
$table->unsignedInteger('stock_ecer')->default(0)->after('reject_stock');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('product_variants', function (Blueprint $table) {
|
||||
$table->dropColumn('stock_ecer');
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -10,14 +10,17 @@ public function up(): void
|
||||
{
|
||||
Schema::create('stock_ecer_histories', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->foreignId('product_variant_id')->constrained('product_variants')->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
|
||||
|
||||
$table->unsignedInteger('quantity');
|
||||
$table->unsignedInteger('stock_before');
|
||||
$table->unsignedInteger('stock_ecer_before');
|
||||
$table->unsignedInteger('stock_after');
|
||||
$table->unsignedInteger('stock_ecer_after');
|
||||
$table->string('notes')->nullable();
|
||||
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('orders', function (Blueprint $table): void {
|
||||
$table->unsignedBigInteger('nego_price')->nullable()->after('discount');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('orders', function (Blueprint $table): void {
|
||||
$table->dropColumn('nego_price');
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\StokOpnameStatus;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
@ -10,25 +11,33 @@ public function up(): void
|
||||
{
|
||||
Schema::create('stok_opnames', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->date('opname_date');
|
||||
$table->enum('status', ['draft', 'pending', 'verified', 'rejected'])->default('draft');
|
||||
$table->text('notes')->nullable();
|
||||
$table->text('verification_notes')->nullable();
|
||||
|
||||
$table->foreignId('created_by_id')->constrained('users')->cascadeOnDelete();
|
||||
$table->foreignId('verified_by_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->date('opname_date');
|
||||
$table->enum('status', StokOpnameStatus::values())->default(StokOpnameStatus::DRAFT->value);
|
||||
$table->text('notes')->nullable();
|
||||
$table->text('verification_notes')->nullable();
|
||||
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
|
||||
$table->softDeletes();
|
||||
});
|
||||
|
||||
Schema::create('stok_opname_items', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
|
||||
$table->foreignId('stok_opname_id')->constrained('stok_opnames')->cascadeOnDelete();
|
||||
$table->foreignId('product_variant_id')->constrained('product_variants')->cascadeOnDelete();
|
||||
|
||||
$table->unsignedInteger('system_stock')->default(0);
|
||||
$table->unsignedInteger('physical_stock')->default(0);
|
||||
$table->integer('difference')->default(0);
|
||||
$table->text('notes')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
|
||||
|
||||
$table->unique(['stok_opname_id', 'product_variant_id']);
|
||||
});
|
||||
|
||||
@ -70,7 +70,7 @@ public function run(): void
|
||||
[
|
||||
'full_name' => $data['full_name'],
|
||||
'phone_number' => '08'.fake()->numerify('##########'),
|
||||
'gender' => fake()->randomElement(array_column(Gender::cases(), 'value')),
|
||||
'gender' => fake()->randomElement(Gender::values()),
|
||||
'birth_date' => '1995-01-01',
|
||||
'address' => 'Jl. Jenderal Sudirman No. 123',
|
||||
]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user