diff --git a/app/Http/Controllers/SetupWizardController.php b/app/Http/Controllers/SetupWizardController.php new file mode 100644 index 0000000..6a28a0a --- /dev/null +++ b/app/Http/Controllers/SetupWizardController.php @@ -0,0 +1,119 @@ +get('step', 1); + + return view('setup.wizard', [ + 'step' => $step, + 'hasUser' => User::exists(), + 'hasSettings' => Setting::exists(), + 'hasMaster' => AssetStatus::exists() && AssetClass::exists() && AssetCategory::exists(), + 'hasAsset' => Asset::exists(), + ]); + } + + public function store(Request $request): RedirectResponse + { + $step = (int) $request->input('step', 1); + + if ($step === 1) { + $data = $request->validate([ + 'name' => ['required', 'string', 'max:255'], + 'email' => ['required', 'email', 'max:255', 'unique:users,email'], + 'password' => ['required', 'confirmed', 'min:8'], + ]); + $user = User::create([ + 'name' => $data['name'], + 'email' => $data['email'], + 'password' => Hash::make($data['password']), + ]); + $role = Role::firstOrCreate(['name' => 'super-admin', 'guard_name' => 'web']); + $user->assignRole($role); + auth()->login($user); + return redirect()->route('setup.index', ['step' => 2])->with('success', 'User admin dibuat.'); + } + + if ($step === 2) { + $data = $request->validate([ + 'company_name' => ['required', 'string', 'max:255'], + 'timezone' => ['required', 'string', 'max:100'], + ]); + Setting::updateOrCreate(['key' => 'system.company_name'], [ + 'value' => $data['company_name'], + 'type' => 'string', + 'group' => 'system', + ]); + Setting::updateOrCreate(['key' => 'system.timezone'], [ + 'value' => $data['timezone'], + 'type' => 'string', + 'group' => 'system', + ]); + return redirect()->route('setup.index', ['step' => 3])->with('success', 'Setting dasar disimpan.'); + } + + if ($step === 3) { + $status = AssetStatus::firstOrCreate(['code' => 'ACTIVE'], ['name' => 'Active']); + AssetStatus::firstOrCreate(['code' => 'DISPOSED'], ['name' => 'Disposed']); + $class = AssetClass::firstOrCreate(['code' => 'IT'], ['name' => 'Perangkat IT']); + $category = AssetCategory::firstOrCreate(['code' => 'LAPTOP'], ['name' => 'Laptop']); + $unit = Unit::firstOrCreate(['symbol' => 'pcs'], ['name' => 'Unit']); + $dept = Department::firstOrCreate(['code' => 'GEN'], ['name' => 'General']); + $pic = PersonInCharge::firstOrCreate(['email' => 'pic@example.com'], ['name' => 'Default PIC']); + $loc = AssetLocation::firstOrCreate(['code' => 'WH'], ['name' => 'Warehouse']); + $warranty = Warranty::firstOrCreate(['name' => '1 Tahun'], ['duration_months' => 12]); + + session()->flash('master_refs', compact('status','class','category','unit','dept','pic','loc','warranty')); + + return redirect()->route('setup.index', ['step' => 4])->with('success', 'Master data dasar dibuat.'); + } + + if ($step === 4) { + $service = app(AssetService::class); + $refs = session('master_refs', []); + $asset = $service->create([ + 'name' => $request->input('asset_name', 'Sample Asset'), + 'asset_status_id' => $refs['status']->id ?? AssetStatus::first()->id ?? null, + 'asset_class_id' => $refs['class']->id ?? AssetClass::first()->id ?? null, + 'asset_category_id' => $refs['category']->id ?? AssetCategory::first()->id ?? null, + 'unit_id' => $refs['unit']->id ?? Unit::first()->id ?? null, + 'department_id' => $refs['dept']->id ?? Department::first()->id ?? null, + 'person_in_charge_id' => $refs['pic']->id ?? PersonInCharge::first()->id ?? null, + 'asset_user_id' => null, + 'asset_location_id' => $refs['loc']->id ?? AssetLocation::first()->id ?? null, + 'warranty_id' => $refs['warranty']->id ?? null, + 'purchase_date' => now()->subMonth(), + 'cost' => 15000000, + 'depreciation_method' => 'straight_line', + 'useful_life_months' => 36, + 'residual_value' => 2000000, + ]); + + return redirect()->route('index')->with('success', "Setup selesai. Aset sample {$asset->code} dibuat."); + } + + return back()->with('error', 'Langkah tidak dikenal.'); + } +} diff --git a/resources/views/setup/wizard.blade.php b/resources/views/setup/wizard.blade.php new file mode 100644 index 0000000..288c7c4 --- /dev/null +++ b/resources/views/setup/wizard.blade.php @@ -0,0 +1,108 @@ +@extends('layouts.custom-master') + +@php +$bodyClass = 'bg-white'; +@endphp + +@section('content') +
Siapkan akun, setting, master data, lalu aset pertama.
+