88 lines
3.0 KiB
TypeScript
88 lines
3.0 KiB
TypeScript
import type { ColumnDef } from '@tanstack/vue-table';
|
|
import { h } from 'vue';
|
|
import DataTableActions from '@/components/admin/finance/employee-advances/data-table-actions.vue';
|
|
import MediaThumbnailCell from '@/components/media/MediaThumbnailCell.vue';
|
|
import { DataTableColumnHeader } from '@/components/data-table';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import type { EmployeeAdvanceListItem } from '@/types/employee-advance';
|
|
|
|
function statusVariant(status: string): 'default' | 'secondary' | 'destructive' | 'outline' {
|
|
switch (status) {
|
|
case 'approved':
|
|
return 'default';
|
|
case 'paid':
|
|
return 'secondary';
|
|
case 'rejected':
|
|
return 'destructive';
|
|
default:
|
|
return 'outline';
|
|
}
|
|
}
|
|
|
|
export function createColumns(
|
|
authEmployeeId: number | null,
|
|
onEdit: (employeeAdvance: EmployeeAdvanceListItem) => void,
|
|
onReject: (employeeAdvance: EmployeeAdvanceListItem) => void,
|
|
): ColumnDef<EmployeeAdvanceListItem>[] {
|
|
return [
|
|
{
|
|
accessorKey: 'created_at_formatted',
|
|
enableSorting: true,
|
|
header: () => h(DataTableColumnHeader, { title: 'Tanggal', column: 'created_at' }),
|
|
},
|
|
{
|
|
accessorKey: 'employee_name',
|
|
enableSorting: false,
|
|
header: () => 'Pegawai',
|
|
},
|
|
{
|
|
accessorKey: 'amount_formatted',
|
|
enableSorting: true,
|
|
header: () => h(DataTableColumnHeader, { title: 'Jumlah', column: 'amount' }),
|
|
},
|
|
{
|
|
accessorKey: 'description',
|
|
enableSorting: true,
|
|
header: () => h(DataTableColumnHeader, { title: 'Keterangan', column: 'description' }),
|
|
},
|
|
{
|
|
id: 'photos',
|
|
enableSorting: false,
|
|
header: () => 'Foto',
|
|
cell: ({ row }) => h(MediaThumbnailCell, { items: row.original.photos ?? [] }),
|
|
},
|
|
{
|
|
accessorKey: 'due_date_formatted',
|
|
enableSorting: true,
|
|
header: () => h(DataTableColumnHeader, { title: 'Jatuh Tempo', column: 'due_date' }),
|
|
},
|
|
{
|
|
accessorKey: 'status_label',
|
|
enableSorting: true,
|
|
header: () => h(DataTableColumnHeader, { title: 'Status', column: 'status' }),
|
|
cell: ({ row }) => h(
|
|
Badge,
|
|
{ variant: statusVariant(row.original.status) },
|
|
() => row.original.status_label,
|
|
),
|
|
},
|
|
{
|
|
accessorKey: 'rejection_reason',
|
|
enableSorting: false,
|
|
header: () => 'Alasan Penolakan',
|
|
cell: ({ row }) => row.original.rejection_reason ?? '-',
|
|
},
|
|
{
|
|
id: 'actions',
|
|
enableSorting: false,
|
|
enableHiding: false,
|
|
cell: ({ row }) => h(DataTableActions, {
|
|
employeeAdvance: row.original,
|
|
authEmployeeId,
|
|
onEdit: () => onEdit(row.original),
|
|
onReject: () => onReject(row.original),
|
|
}),
|
|
},
|
|
];
|
|
}
|