dstpabuaran.com/resources/js/pages/admin/finance/payroll-period/show-columns.tsx
Yoga Pangestu d91ec8869e refactor: replace tooltip buttons with row actions component in supplier and role columns
feat: implement delete confirmation dialog component for better UX

refactor: update supplier and role index pages to utilize new form dialog and delete confirm dialog components

feat: add reusable form dialog component for creating and editing entities

feat: introduce filter popover component for enhanced filtering options in data tables

feat: create image preview button component for displaying images with modal preview

feat: add page header component for consistent page layout

feat: implement row actions component for handling actions on table rows

feat: add status badge component for displaying entity statuses

feat: create toggle status component for easily toggling entity states

feat: implement draft save hook for auto-saving form data

feat: add server table hook for managing server-side pagination and filtering

feat: create utility functions for formatting dates and numbers

feat: add constants for month names and measurement units
2026-08-02 23:40:12 +07:00

243 lines
8.2 KiB
TypeScript

import type { ColumnDef } from '@tanstack/react-table';
import { CircleDollarSign, Pencil, Trash2, XCircle } from 'lucide-react';
import { RowActions } from '@/components/row-actions';
import { Badge } from '@/components/ui/badge';
import { formatCurrency } from '@/lib/utils';
export type Payroll = {
id: number;
base_salary: number;
bonus_amount: number;
deduction_amount: number;
total_amount: number;
status: 'unpaid' | 'paid' | 'cancelled';
paid_at: string | null;
employee: {
user: {
user_profile: {
full_name: string;
};
};
};
payroll_adjustments?: PayrollAdjustment[];
};
export type PayrollAdjustment = {
id: number;
type: 'bonus' | 'deduction';
amount: number;
description: string;
created_at: string;
};
function getStatusBadge(status: string) {
const statusConfig: Record<string, { label: string; className: string }> = {
unpaid: {
label: 'Belum Dibayar',
className: 'bg-yellow-100 text-yellow-800 hover:bg-yellow-100',
},
paid: {
label: 'Dibayar',
className: 'bg-green-100 text-green-800 hover:bg-green-100',
},
cancelled: {
label: 'Dibatalkan',
className: 'bg-red-100 text-red-800 hover:bg-red-100',
},
};
const config = statusConfig[status] ?? statusConfig.unpaid;
return (
<Badge variant="secondary" className={config.className}>
{config.label}
</Badge>
);
}
type CreateColumnsParams = {
handlePay: (payroll: Payroll) => void;
handleCancel: (payroll: Payroll) => void;
handleAddAdjustment: (payroll: Payroll) => void;
handleDeleteAdjustment: (
adjustment: PayrollAdjustment,
payrollId: number,
) => void;
};
export function createPayrollColumns(
params: CreateColumnsParams,
): ColumnDef<Payroll>[] {
const {
handlePay,
handleCancel,
handleAddAdjustment,
handleDeleteAdjustment,
} = params;
return [
{
id: 'employee_name',
header: () => <span>Nama Karyawan</span>,
cell: ({ row }) => {
const employee = row.original.employee;
return (
<span className="font-medium">
{employee?.user?.user_profile?.full_name ?? '-'}
</span>
);
},
},
{
accessorKey: 'base_salary',
header: () => <span>Gaji Pokok</span>,
cell: ({ row }) => (
<span>
{formatCurrency(row.getValue('base_salary') as number)}
</span>
),
},
{
accessorKey: 'bonus_amount',
header: () => <span>Bonus</span>,
cell: ({ row }) => {
const value = row.getValue('bonus_amount') as number;
return (
<span
className={
value > 0 ? 'font-medium text-green-600' : ''
}
>
{value > 0 ? '+ ' : ''}
{formatCurrency(value)}
</span>
);
},
},
{
accessorKey: 'deduction_amount',
header: () => <span>Potongan</span>,
cell: ({ row }) => {
const value = row.getValue('deduction_amount') as number;
return (
<span
className={value > 0 ? 'font-medium text-red-600' : ''}
>
{value > 0 ? '- ' : ''}
{formatCurrency(value)}
</span>
);
},
},
{
accessorKey: 'total_amount',
header: () => <span>Total</span>,
cell: ({ row }) => (
<span className="font-semibold">
{formatCurrency(row.getValue('total_amount') as number)}
</span>
),
},
{
accessorKey: 'status',
header: () => <span>Status</span>,
cell: ({ row }) => (
<span>{getStatusBadge(row.getValue('status') as string)}</span>
),
},
{
id: 'adjustments',
header: () => <span>Penyesuaian</span>,
cell: ({ row }) => {
const payroll = row.original;
const adjustments = payroll.payroll_adjustments ?? [];
if (adjustments.length === 0) {
return <span className="text-muted-foreground">-</span>;
}
return (
<div className="flex flex-col gap-1">
{adjustments.map((adj: PayrollAdjustment) => (
<div
key={adj.id}
className="flex items-center gap-1 text-xs"
>
<span
className={
adj.type === 'bonus'
? 'text-green-600'
: 'text-red-600'
}
>
{adj.type === 'bonus' ? '+' : '-'}{' '}
{formatCurrency(adj.amount)}
</span>
<span className="max-w-[100px] truncate text-muted-foreground">
{adj.description}
</span>
{payroll.status === 'unpaid' && (
<button
onClick={() =>
handleDeleteAdjustment(
adj,
payroll.id,
)
}
className="text-destructive hover:text-destructive/80"
>
<XCircle className="h-3 w-3" />
</button>
)}
</div>
))}
</div>
);
},
},
{
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
className: 'w-[120px] text-center',
headerClassName: 'w-[120px] text-center',
},
cell: ({ row }) => {
const payroll = row.original;
return (
<RowActions
actions={[
{
label: 'Tambah Adjustment',
icon: <Pencil className="h-4 w-4" />,
show: payroll.status === 'unpaid',
onClick: () => handleAddAdjustment(payroll),
},
{
label: 'Tandai Dibayar',
icon: (
<CircleDollarSign className="h-4 w-4 text-green-600" />
),
show: payroll.status === 'unpaid',
onClick: () => handlePay(payroll),
},
{
label: 'Batalkan',
icon: (
<XCircle className="h-4 w-4 text-destructive" />
),
show: payroll.status === 'unpaid',
onClick: () => handleCancel(payroll),
},
]}
/>
);
},
},
];
}