feat: enhance Employee data structure by adding resign_date and improving salary display in employee columns
This commit is contained in:
parent
de18ac5ce8
commit
17273c9479
@ -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')))
|
->where(fn ($q) => $q->whereHas('employee')->orWhereHas('roles', fn ($rq) => $rq->where('name', 'Owner')))
|
||||||
->with([
|
->with([
|
||||||
'userProfile' => fn ($q) => $q->select(['id', 'user_id', 'full_name', 'phone_number', 'gender']),
|
'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']),
|
'roles' => fn ($q) => $q->select(['id', 'name']),
|
||||||
'media',
|
'media',
|
||||||
])
|
])
|
||||||
|
|||||||
@ -18,6 +18,7 @@ export type Employee = {
|
|||||||
} | null;
|
} | null;
|
||||||
employee: {
|
employee: {
|
||||||
join_date: string;
|
join_date: string;
|
||||||
|
resign_date: string | null;
|
||||||
employment_status: string;
|
employment_status: string;
|
||||||
base_salary: number;
|
base_salary: number;
|
||||||
} | null;
|
} | 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
|
...(canViewAll
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user