173 lines
10 KiB
PHP
173 lines
10 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Employee;
|
|
use App\Models\Payroll;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class PayrollSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
// Kalkulasi net_salary konsisten dengan logika di PayrollController
|
|
$net = function (int $basic, array $details): int {
|
|
$total = $basic;
|
|
foreach ($details as $item) {
|
|
$total += $item['type'] === 'bonus' ? $item['amount'] : -$item['amount'];
|
|
}
|
|
return max(0, $total);
|
|
};
|
|
|
|
// Eager pluck: 1 query untuk semua employee
|
|
$emp = Employee::pluck('id', 'name');
|
|
|
|
$bulanLalu = now()->subMonth()->format('Y-m');
|
|
$bulanIni = now()->format('Y-m');
|
|
|
|
$records = [];
|
|
|
|
if (isset($emp['Jono Joni'])) {
|
|
$basic = 9_000_000;
|
|
$detailLalu = [
|
|
['name' => 'Tunjangan Transport', 'type' => 'bonus', 'amount' => 600_000],
|
|
['name' => 'Tunjangan Makan', 'type' => 'bonus', 'amount' => 450_000],
|
|
['name' => 'Potongan BPJS Kesehatan', 'type' => 'deduction', 'amount' => 180_000],
|
|
['name' => 'Potongan BPJS TK', 'type' => 'deduction', 'amount' => 90_000],
|
|
];
|
|
$records[] = ['employee_id' => $emp['Jono Joni'], 'period' => $bulanLalu, 'basic_salary' => $basic, 'details' => $detailLalu, 'net_salary' => $net($basic, $detailLalu), 'status' => 'paid'];
|
|
|
|
$detailIni = [
|
|
['name' => 'Tunjangan Transport', 'type' => 'bonus', 'amount' => 600_000],
|
|
['name' => 'Tunjangan Makan', 'type' => 'bonus', 'amount' => 450_000],
|
|
['name' => 'Bonus Proyek Klien', 'type' => 'bonus', 'amount' => 1_500_000],
|
|
['name' => 'Potongan BPJS Kesehatan', 'type' => 'deduction', 'amount' => 180_000],
|
|
['name' => 'Potongan BPJS TK', 'type' => 'deduction', 'amount' => 90_000],
|
|
];
|
|
$records[] = ['employee_id' => $emp['Jono Joni'], 'period' => $bulanIni, 'basic_salary' => $basic, 'details' => $detailIni, 'net_salary' => $net($basic, $detailIni), 'status' => 'pending'];
|
|
}
|
|
|
|
if (isset($emp['Budi Santoso'])) {
|
|
$basic = 5_500_000;
|
|
$detailLalu = [
|
|
['name' => 'Tunjangan Transport', 'type' => 'bonus', 'amount' => 400_000],
|
|
['name' => 'Tunjangan Makan', 'type' => 'bonus', 'amount' => 350_000],
|
|
['name' => 'Potongan BPJS TK', 'type' => 'deduction', 'amount' => 55_000],
|
|
['name' => 'Potongan Keterlambatan', 'type' => 'deduction', 'amount' => 100_000],
|
|
];
|
|
$records[] = ['employee_id' => $emp['Budi Santoso'], 'period' => $bulanLalu, 'basic_salary' => $basic, 'details' => $detailLalu, 'net_salary' => $net($basic, $detailLalu), 'status' => 'paid'];
|
|
|
|
$detailIni = [
|
|
['name' => 'Tunjangan Transport', 'type' => 'bonus', 'amount' => 400_000],
|
|
['name' => 'Tunjangan Makan', 'type' => 'bonus', 'amount' => 350_000],
|
|
['name' => 'Potongan BPJS TK', 'type' => 'deduction', 'amount' => 55_000],
|
|
];
|
|
$records[] = ['employee_id' => $emp['Budi Santoso'], 'period' => $bulanIni, 'basic_salary' => $basic, 'details' => $detailIni, 'net_salary' => $net($basic, $detailIni), 'status' => 'pending'];
|
|
}
|
|
|
|
if (isset($emp['Rizky Firmansyah'])) {
|
|
$basic = 5_500_000;
|
|
$detailIni = [
|
|
['name' => 'Uang Transport Magang', 'type' => 'bonus', 'amount' => 200_000],
|
|
['name' => 'Potongan Tidak Hadir', 'type' => 'deduction', 'amount' => 250_000],
|
|
];
|
|
$records[] = ['employee_id' => $emp['Rizky Firmansyah'], 'period' => $bulanIni, 'basic_salary' => $basic, 'details' => $detailIni, 'net_salary' => $net($basic, $detailIni), 'status' => 'pending'];
|
|
}
|
|
|
|
if (isset($emp['Dewi Rahayu'])) {
|
|
$basic = 12_000_000;
|
|
$detailLalu = [
|
|
['name' => 'Tunjangan Jabatan', 'type' => 'bonus', 'amount' => 2_000_000],
|
|
['name' => 'Tunjangan Transport', 'type' => 'bonus', 'amount' => 700_000],
|
|
['name' => 'Tunjangan Makan', 'type' => 'bonus', 'amount' => 500_000],
|
|
['name' => 'Potongan BPJS Kesehatan', 'type' => 'deduction', 'amount' => 240_000],
|
|
['name' => 'Potongan BPJS TK', 'type' => 'deduction', 'amount' => 120_000],
|
|
['name' => 'Potongan PPh 21', 'type' => 'deduction', 'amount' => 500_000],
|
|
];
|
|
$records[] = ['employee_id' => $emp['Dewi Rahayu'], 'period' => $bulanLalu, 'basic_salary' => $basic, 'details' => $detailLalu, 'net_salary' => $net($basic, $detailLalu), 'status' => 'paid'];
|
|
|
|
$detailIni = [
|
|
['name' => 'Tunjangan Jabatan', 'type' => 'bonus', 'amount' => 2_000_000],
|
|
['name' => 'Tunjangan Transport', 'type' => 'bonus', 'amount' => 700_000],
|
|
['name' => 'Tunjangan Makan', 'type' => 'bonus', 'amount' => 500_000],
|
|
['name' => 'Bonus Kinerja Triwulan', 'type' => 'bonus', 'amount' => 1_000_000],
|
|
['name' => 'Potongan BPJS Kesehatan', 'type' => 'deduction', 'amount' => 240_000],
|
|
['name' => 'Potongan BPJS TK', 'type' => 'deduction', 'amount' => 120_000],
|
|
['name' => 'Potongan PPh 21', 'type' => 'deduction', 'amount' => 600_000],
|
|
];
|
|
$records[] = ['employee_id' => $emp['Dewi Rahayu'], 'period' => $bulanIni, 'basic_salary' => $basic, 'details' => $detailIni, 'net_salary' => $net($basic, $detailIni), 'status' => 'pending'];
|
|
}
|
|
|
|
if (isset($emp['Anisa Putri'])) {
|
|
$basic = 5_800_000;
|
|
$detailLalu = [
|
|
['name' => 'Tunjangan Transport', 'type' => 'bonus', 'amount' => 400_000],
|
|
['name' => 'Tunjangan Makan', 'type' => 'bonus', 'amount' => 350_000],
|
|
['name' => 'Potongan BPJS Kesehatan', 'type' => 'deduction', 'amount' => 116_000],
|
|
['name' => 'Potongan BPJS TK', 'type' => 'deduction', 'amount' => 58_000],
|
|
];
|
|
$records[] = ['employee_id' => $emp['Anisa Putri'], 'period' => $bulanLalu, 'basic_salary' => $basic, 'details' => $detailLalu, 'net_salary' => $net($basic, $detailLalu), 'status' => 'paid'];
|
|
}
|
|
|
|
if (isset($emp['Hendra Kurniawan'])) {
|
|
$basic = 7_000_000;
|
|
$detailLalu = [
|
|
['name' => 'Tunjangan Transport', 'type' => 'bonus', 'amount' => 500_000],
|
|
['name' => 'Tunjangan Makan', 'type' => 'bonus', 'amount' => 450_000],
|
|
['name' => 'Potongan BPJS Kesehatan', 'type' => 'deduction', 'amount' => 140_000],
|
|
['name' => 'Potongan BPJS TK', 'type' => 'deduction', 'amount' => 70_000],
|
|
['name' => 'Cicilan Pinjaman', 'type' => 'deduction', 'amount' => 500_000],
|
|
];
|
|
$records[] = ['employee_id' => $emp['Hendra Kurniawan'], 'period' => $bulanLalu, 'basic_salary' => $basic, 'details' => $detailLalu, 'net_salary' => $net($basic, $detailLalu), 'status' => 'paid'];
|
|
|
|
$detailIni = $detailLalu;
|
|
$records[] = ['employee_id' => $emp['Hendra Kurniawan'], 'period' => $bulanIni, 'basic_salary' => $basic, 'details' => $detailIni, 'net_salary' => $net($basic, $detailIni), 'status' => 'pending'];
|
|
}
|
|
|
|
if (isset($emp['Sari Wulandari'])) {
|
|
$basic = 4_000_000;
|
|
$detailIni = [
|
|
['name' => 'Tunjangan Transport', 'type' => 'bonus', 'amount' => 300_000],
|
|
['name' => 'Potongan Absen', 'type' => 'deduction', 'amount' => 200_000],
|
|
['name' => 'Potongan BPJS TK', 'type' => 'deduction', 'amount' => 40_000],
|
|
];
|
|
$records[] = ['employee_id' => $emp['Sari Wulandari'], 'period' => $bulanIni, 'basic_salary' => $basic, 'details' => $detailIni, 'net_salary' => $net($basic, $detailIni), 'status' => 'pending'];
|
|
}
|
|
|
|
if (isset($emp['Fajar Nugroho'])) {
|
|
$basic = 4_500_000;
|
|
$detailLalu = [
|
|
['name' => 'Tunjangan Transport', 'type' => 'bonus', 'amount' => 350_000],
|
|
['name' => 'Komisi Penjualan', 'type' => 'bonus', 'amount' => 2_000_000],
|
|
['name' => 'Potongan BPJS TK', 'type' => 'deduction', 'amount' => 45_000],
|
|
];
|
|
$records[] = ['employee_id' => $emp['Fajar Nugroho'], 'period' => $bulanLalu, 'basic_salary' => $basic, 'details' => $detailLalu, 'net_salary' => $net($basic, $detailLalu), 'status' => 'paid'];
|
|
|
|
$detailIni = [
|
|
['name' => 'Tunjangan Transport', 'type' => 'bonus', 'amount' => 350_000],
|
|
['name' => 'Potongan BPJS TK', 'type' => 'deduction', 'amount' => 45_000],
|
|
];
|
|
$records[] = ['employee_id' => $emp['Fajar Nugroho'], 'period' => $bulanIni, 'basic_salary' => $basic, 'details' => $detailIni, 'net_salary' => $net($basic, $detailIni), 'status' => 'pending'];
|
|
}
|
|
|
|
if (isset($emp['Agus Prasetyo'])) {
|
|
$basic = 12_000_000;
|
|
$detailLalu = [
|
|
['name' => 'Tunjangan Jabatan', 'type' => 'bonus', 'amount' => 2_500_000],
|
|
['name' => 'Tunjangan Transport', 'type' => 'bonus', 'amount' => 700_000],
|
|
['name' => 'Tunjangan Makan', 'type' => 'bonus', 'amount' => 500_000],
|
|
['name' => 'Potongan BPJS Kesehatan', 'type' => 'deduction', 'amount' => 240_000],
|
|
['name' => 'Potongan BPJS TK', 'type' => 'deduction', 'amount' => 120_000],
|
|
['name' => 'Potongan PPh 21', 'type' => 'deduction', 'amount' => 650_000],
|
|
];
|
|
$records[] = ['employee_id' => $emp['Agus Prasetyo'], 'period' => $bulanLalu, 'basic_salary' => $basic, 'details' => $detailLalu, 'net_salary' => $net($basic, $detailLalu), 'status' => 'paid'];
|
|
}
|
|
|
|
foreach ($records as $data) {
|
|
Payroll::create($data);
|
|
}
|
|
|
|
$this->command->info('PayrollSeeder: ' . count($records) . ' slip gaji berhasil dibuat.');
|
|
}
|
|
}
|