feat: enhance Employee data structure by adding resign_date and improving salary display in employee columns

This commit is contained in:
Yoga Pangestu 2026-08-15 16:12:06 +07:00
parent de18ac5ce8
commit 17273c9479
2 changed files with 63 additions and 1 deletions

View File

@ -22,7 +22,7 @@ public function paginated(int $perPage = 25, string $search = '', string $sort =
->where(fn ($q) => $q->whereHas('employee')->orWhereHas('roles', fn ($rq) => $rq->where('name', 'Owner')))
->with([
'userProfile' => fn ($q) => $q->select(['id', 'user_id', 'full_name', 'phone_number', 'gender']),
'employee' => fn ($q) => $q->select(['id', 'user_id', 'join_date', 'employment_status', 'base_salary']),
'employee' => fn ($q) => $q->select(['id', 'user_id', 'join_date', 'resign_date', 'employment_status', 'base_salary']),
'roles' => fn ($q) => $q->select(['id', 'name']),
'media',
])

View File

@ -18,6 +18,7 @@ export type Employee = {
} | null;
employee: {
join_date: string;
resign_date: string | null;
employment_status: string;
base_salary: number;
} | null;
@ -124,6 +125,67 @@ export function createEmployeeColumns(
);
},
},
{
accessorKey: 'employee.base_salary',
id: 'base_salary',
header: () => <span>Gaji</span>,
cell: ({ row }) => {
const employee = row.original;
const salary = employee.employee?.base_salary;
if (!salary) {
return <span>-</span>;
}
return (
<span className="font-medium">
{formatCurrency(salary)}
</span>
);
},
},
{
id: 'period',
header: () => <span>Masa Kerja</span>,
cell: ({ row }) => {
const employee = row.original;
const joinDate = employee.employee?.join_date;
const resignDate = employee.employee?.resign_date;
if (!joinDate) {
return <span>-</span>;
}
const formattedJoin = new Date(joinDate).toLocaleDateString('id-ID', {
day: 'numeric',
month: 'short',
year: 'numeric',
});
if (resignDate) {
const formattedResign = new Date(resignDate).toLocaleDateString('id-ID', {
day: 'numeric',
month: 'short',
year: 'numeric',
});
return (
<div className="flex flex-col">
<span className="text-xs text-muted-foreground">Masuk</span>
<span>{formattedJoin}</span>
<span className="text-xs text-muted-foreground">Keluar</span>
<span>{formattedResign}</span>
</div>
);
}
return (
<div className="flex flex-col">
<span className="text-xs text-muted-foreground">Masuk</span>
<span>{formattedJoin}</span>
</div>
);
},
},
...(canViewAll
? [
{