47 lines
1.6 KiB
PHP
Executable File
47 lines
1.6 KiB
PHP
Executable File
<?php
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
return new class extends Migration
|
|
{
|
|
/**
|
|
* Run the migrations.
|
|
*/
|
|
public function up(): void
|
|
{
|
|
Schema::create('mutations', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->string('mutation_number')->unique();
|
|
$table->foreignId('from_dealer_id')->constrained('dealers');
|
|
$table->foreignId('to_dealer_id')->constrained('dealers');
|
|
$table->enum('status', ['pending', 'sent', 'received', 'approved', 'rejected', 'completed', 'cancelled'])
|
|
->default('sent');
|
|
$table->foreignId('requested_by')->constrained('users');
|
|
$table->foreignId('approved_by')->nullable()->constrained('users');
|
|
$table->timestamp('approved_at')->nullable();
|
|
$table->foreignId('received_by')->nullable()->constrained('users');
|
|
$table->timestamp('received_at')->nullable();
|
|
$table->text('notes')->nullable();
|
|
$table->text('rejection_reason')->nullable();
|
|
$table->timestamps();
|
|
$table->softDeletes();
|
|
|
|
// Indexes untuk performa
|
|
$table->index(['from_dealer_id', 'status']);
|
|
$table->index(['to_dealer_id', 'status']);
|
|
$table->index(['status', 'created_at']);
|
|
$table->index('mutation_number');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*/
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('mutations');
|
|
}
|
|
};
|