280 lines
12 KiB
PHP
280 lines
12 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Department;
|
|
use App\Models\Employee;
|
|
use App\Models\Position;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
/**
|
|
* EmployeeSeeder
|
|
*
|
|
* Membuat akun User (role: employee) beserta profil Employee yang
|
|
* terhubung ke Department dan Position yang sudah dibuat oleh MasterDataSeeder.
|
|
*
|
|
* Variasi kasus yang di-cover:
|
|
* - Karyawan tetap (PKWTT) di berbagai departemen
|
|
* - Karyawan kontrak (PKWT)
|
|
* - Karyawan magang
|
|
* - Berbagai jabatan dengan gaji pokok berbeda
|
|
*/
|
|
class EmployeeSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
// ── Resolve Master Data by Name (aman terhadap perubahan ID) ──
|
|
$depts = Department::pluck('id', 'name');
|
|
$positions = Position::pluck('id', 'name');
|
|
|
|
// ──────────────────────────────────────────────────────────────
|
|
// DATA KARYAWAN
|
|
// Format: [user_data, employee_data]
|
|
// ──────────────────────────────────────────────────────────────
|
|
$employees = [
|
|
|
|
// ── IT DEPARTMENT ────────────────────────────────────────
|
|
|
|
[
|
|
'user' => [
|
|
'name' => 'Jono Joni',
|
|
'email' => 'jono12@gmail.com',
|
|
'password' => Hash::make('password'),
|
|
'role' => 'employee',
|
|
],
|
|
'employee' => [
|
|
'nip' => '2023001',
|
|
'name' => 'Jono Joni',
|
|
'gender' => 'L',
|
|
'place_of_birth' => 'Jakarta',
|
|
'birth_date' => '1992-05-14',
|
|
'address' => 'Jl. Merdeka No.12, Jakarta Pusat',
|
|
'phone_number' => '081234567890',
|
|
'department_id' => $depts['Information Technology'],
|
|
'position_id' => $positions['Senior Developer'],
|
|
'status' => 'PKWTT',
|
|
'join_date' => '2023-01-15',
|
|
],
|
|
],
|
|
|
|
[
|
|
'user' => [
|
|
'name' => 'Budi Santoso',
|
|
'email' => 'budi.santoso12@hris.com',
|
|
'password' => Hash::make('password'),
|
|
'role' => 'employee',
|
|
],
|
|
'employee' => [
|
|
'nip' => '2023002',
|
|
'name' => 'Budi Santoso',
|
|
'gender' => 'L',
|
|
'place_of_birth' => 'Bandung',
|
|
'birth_date' => '1995-08-22',
|
|
'address' => 'Jl. Sukajadi No.45, Bandung',
|
|
'phone_number' => '082345678901',
|
|
'department_id' => $depts['Information Technology'],
|
|
'position_id' => $positions['Junior Developer'],
|
|
'status' => 'PKWT',
|
|
'join_date' => '2023-03-01',
|
|
],
|
|
],
|
|
|
|
[
|
|
'user' => [
|
|
'name' => 'Rizky Firmansyah',
|
|
'email' => 'rizky.firmansyah12@hris.com',
|
|
'password' => Hash::make('password'),
|
|
'role' => 'employee',
|
|
],
|
|
'employee' => [
|
|
'nip' => '2024001',
|
|
'name' => 'Rizky Firmansyah',
|
|
'gender' => 'L',
|
|
'place_of_birth' => 'Surabaya',
|
|
'birth_date' => '1998-11-30',
|
|
'address' => 'Jl. Pemuda No.7, Surabaya',
|
|
'phone_number' => '083456789012',
|
|
'department_id' => $depts['Information Technology'],
|
|
'position_id' => $positions['Junior Developer'],
|
|
'status' => 'Magang',
|
|
'join_date' => '2024-02-01',
|
|
],
|
|
],
|
|
|
|
// ── HR DEPARTMENT ────────────────────────────────────────
|
|
|
|
[
|
|
'user' => [
|
|
'name' => 'Dewi Rahayu',
|
|
'email' => 'dewi.rahayu12@hris.com',
|
|
'password' => Hash::make('password'),
|
|
'role' => 'employee',
|
|
],
|
|
'employee' => [
|
|
'nip' => '2022001',
|
|
'name' => 'Dewi Rahayu',
|
|
'gender' => 'P',
|
|
'place_of_birth' => 'Yogyakarta',
|
|
'birth_date' => '1990-03-10',
|
|
'address' => 'Jl. Malioboro No.88, Yogyakarta',
|
|
'phone_number' => '084567890123',
|
|
'department_id' => $depts['Human Resources'],
|
|
'position_id' => $positions['Manager'],
|
|
'status' => 'PKWTT',
|
|
'join_date' => '2022-06-01',
|
|
],
|
|
],
|
|
|
|
[
|
|
'user' => [
|
|
'name' => 'Anisa Putri',
|
|
'email' => 'anisa.putri12@hris.com',
|
|
'password' => Hash::make('password'),
|
|
'role' => 'employee',
|
|
],
|
|
'employee' => [
|
|
'nip' => '2023003',
|
|
'name' => 'Anisa Putri',
|
|
'gender' => 'P',
|
|
'place_of_birth' => 'Semarang',
|
|
'birth_date' => '1997-07-19',
|
|
'address' => 'Jl. Pahlawan No.3, Semarang',
|
|
'phone_number' => '085678901234',
|
|
'department_id' => $depts['Human Resources'],
|
|
'position_id' => $positions['HR Specialist'],
|
|
'status' => 'PKWTT',
|
|
'join_date' => '2023-07-01',
|
|
],
|
|
],
|
|
|
|
// ── FINANCE DEPARTMENT ───────────────────────────────────
|
|
|
|
[
|
|
'user' => [
|
|
'name' => 'Hendra Kurniawan',
|
|
'email' => 'hendra.kurniawan12@hris.com',
|
|
'password' => Hash::make('password'),
|
|
'role' => 'employee',
|
|
],
|
|
'employee' => [
|
|
'nip' => '2021001',
|
|
'name' => 'Hendra Kurniawan',
|
|
'gender' => 'L',
|
|
'place_of_birth' => 'Medan',
|
|
'birth_date' => '1988-12-05',
|
|
'address' => 'Jl. Sudirman No.22, Medan',
|
|
'phone_number' => '086789012345',
|
|
'department_id' => $depts['Finance'],
|
|
'position_id' => $positions['Finance Analyst'],
|
|
'status' => 'PKWTT',
|
|
'join_date' => '2021-04-01',
|
|
],
|
|
],
|
|
|
|
[
|
|
'user' => [
|
|
'name' => 'Sari Wulandari',
|
|
'email' => 'sari.wulandari12@hris.com',
|
|
'password' => Hash::make('password'),
|
|
'role' => 'employee',
|
|
],
|
|
'employee' => [
|
|
'nip' => '2023004',
|
|
'name' => 'Sari Wulandari',
|
|
'gender' => 'P',
|
|
'place_of_birth' => 'Solo',
|
|
'birth_date' => '1996-02-28',
|
|
'address' => 'Jl. Brigjen Katamso No.5, Solo',
|
|
'phone_number' => '087890123456',
|
|
'department_id' => $depts['Finance'],
|
|
'position_id' => $positions['Staff Admin'],
|
|
'status' => 'PKWT',
|
|
'join_date' => '2023-09-01',
|
|
],
|
|
],
|
|
|
|
// ── MARKETING DEPARTMENT ─────────────────────────────────
|
|
|
|
[
|
|
'user' => [
|
|
'name' => 'Fajar Nugroho',
|
|
'email' => 'fajar.nugroho12@hris.com',
|
|
'password' => Hash::make('password'),
|
|
'role' => 'employee',
|
|
],
|
|
'employee' => [
|
|
'nip' => '2022002',
|
|
'name' => 'Fajar Nugroho',
|
|
'gender' => 'L',
|
|
'place_of_birth' => 'Makassar',
|
|
'birth_date' => '1993-09-15',
|
|
'address' => 'Jl. Sultan Hasanuddin No.10, Makassar',
|
|
'phone_number' => '088901234567',
|
|
'department_id' => $depts['Marketing'],
|
|
'position_id' => $positions['Marketing Staff'],
|
|
'status' => 'PKWTT',
|
|
'join_date' => '2022-11-01',
|
|
],
|
|
],
|
|
|
|
// ── OPERATIONS DEPARTMENT ────────────────────────────────
|
|
|
|
[
|
|
'user' => [
|
|
'name' => 'Linda Permatasari',
|
|
'email' => 'linda.permata12@hris.com',
|
|
'password' => Hash::make('password'),
|
|
'role' => 'employee',
|
|
],
|
|
'employee' => [
|
|
'nip' => '2024002',
|
|
'name' => 'Linda Permatasari',
|
|
'gender' => 'P',
|
|
'place_of_birth' => 'Palembang',
|
|
'birth_date' => '1999-04-20',
|
|
'address' => 'Jl. Demang Lebar Daun No.8, Palembang',
|
|
'phone_number' => '089012345678',
|
|
'department_id' => $depts['Operations'],
|
|
'position_id' => $positions['Operations Staff'],
|
|
'status' => 'PKWT',
|
|
'join_date' => '2024-01-10',
|
|
],
|
|
],
|
|
|
|
[
|
|
'user' => [
|
|
'name' => 'Agus Prasetyo',
|
|
'email' => 'agus.prasetyo12@hris.com',
|
|
'password' => Hash::make('password'),
|
|
'role' => 'employee',
|
|
],
|
|
'employee' => [
|
|
'nip' => '2020001',
|
|
'name' => 'Agus Prasetyo',
|
|
'gender' => 'L',
|
|
'place_of_birth' => 'Malang',
|
|
'birth_date' => '1985-06-10',
|
|
'address' => 'Jl. Ijen No.33, Malang',
|
|
'phone_number' => '081112233445',
|
|
'department_id' => $depts['Operations'],
|
|
'position_id' => $positions['Manager'],
|
|
'status' => 'PKWTT',
|
|
'join_date' => '2020-08-01',
|
|
],
|
|
],
|
|
];
|
|
|
|
// ──────────────────────────────────────────────────────────────
|
|
// Buat User → lalu buat Employee yang terhubung ke user tersebut
|
|
// ──────────────────────────────────────────────────────────────
|
|
foreach ($employees as $data) {
|
|
$user = User::create($data['user']);
|
|
Employee::create(array_merge($data['employee'], ['user_id' => $user->id]));
|
|
}
|
|
|
|
$this->command->info('EmployeeSeeder: ' . count($employees) . ' karyawan berhasil dibuat.');
|
|
}
|
|
}
|