Seed depreciation sample data and fix vendor contract FK

This commit is contained in:
Arya Dwi Putra
2025-12-02 16:32:36 +07:00
parent efbaf711e6
commit 3215baa566
2 changed files with 16 additions and 2 deletions

View File

@@ -13,7 +13,7 @@ return new class extends Migration
$table->unsignedInteger('useful_life_months')->nullable()->after('depreciation_method');
$table->decimal('residual_value', 15, 2)->nullable()->after('useful_life_months');
$table->string('capex_opex')->nullable()->after('residual_value'); // capex|opex
$table->foreignUuid('vendor_contract_id')->nullable()->after('capex_opex')->constrained('vendor_contracts')->nullOnDelete();
$table->uuid('vendor_contract_id')->nullable()->after('capex_opex'); // FK opsional, tambahkan manual jika perlu
$table->timestamp('warranty_reminder_sent_at')->nullable()->after('warranty_end');
});
}
@@ -21,7 +21,6 @@ return new class extends Migration
public function down(): void
{
Schema::table('assets', function (Blueprint $table) {
$table->dropForeign(['vendor_contract_id']);
$table->dropColumn([
'depreciation_method',
'useful_life_months',

View File

@@ -10,6 +10,7 @@ use App\Models\AssetUser;
use App\Models\AssetPhoto;
use App\Models\Department;
use App\Models\PersonInCharge;
use App\Models\VendorContract;
use App\Models\Unit;
use App\Models\Warranty;
use App\Services\Asset\AssetService;
@@ -32,6 +33,15 @@ class AssetSeeder extends Seeder
$user = AssetUser::first();
$location = AssetLocation::first();
$warranty = Warranty::first();
$contract = VendorContract::create([
'vendor_name' => 'Vendor Default',
'contract_number' => 'CNT-001',
'start_date' => now()->subMonths(6),
'end_date' => now()->addMonths(6),
'sla_response_hours' => 4,
'sla_resolution_hours' => 24,
'notes' => 'Kontrak default untuk sample aset',
]);
$names = [
'Laptop Dell XPS 13',
@@ -81,6 +91,11 @@ class AssetSeeder extends Seeder
'warranty_id' => $warranty?->id,
'purchase_date' => now()->subDays(30 + $index),
'cost' => 1000000 + ($index * 250000),
'residual_value' => 500000,
'useful_life_months' => 36,
'depreciation_method' => $index % 2 === 0 ? 'straight_line' : 'diminishing',
'capex_opex' => $index % 3 === 0 ? 'capex' : 'opex',
'vendor_contract_id' => $contract->id,
]);
// Download 2 foto berbeda untuk tiap aset dari pool.