dstpabuaran.com/resources/js/pages/admin/finance/payroll-period/index.tsx
Yoga Pangestu 6dbe9da581 feat: add payroll management features including payroll periods, adjustments, and payment processing
- Implemented routes for managing payroll periods, including current, close, and reopen functionalities.
- Added payroll payment and cancellation routes.
- Introduced payroll adjustments with store and delete functionalities.
- Created comprehensive feature tests for payroll management, covering authentication, CRUD operations, and business logic.
- Ensured proper handling of payroll adjustments and their impact on payroll totals.
- Developed tests for generating payrolls and managing payroll periods, ensuring accurate status transitions and data integrity.
2026-07-30 17:06:52 +07:00

113 lines
3.7 KiB
TypeScript

import { Head, router } from '@inertiajs/react';
import { useState } from 'react';
import { ConfirmDialog } from '@/components/confirm-dialog';
import { DataTable } from '@/components/data-table';
import { Button } from '@/components/ui/button';
import {
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog';
import { index as payrollPeriodsIndex } from '@/routes/admin/finance/payroll-periods';
import { show as payrollPeriodShow } from '@/routes/admin/finance/payroll-periods';
import { close, reopen } from '@/routes/admin/finance/payroll-periods';
import { createPayrollPeriodColumns } from './columns';
import type { PayrollPeriod } from './columns';
type Props = {
payrollPeriods: PayrollPeriod[];
};
const MONTH_NAMES = [
'', 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni',
'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember',
];
export default function PayrollPeriodIndex({ payrollPeriods }: Props) {
const [closing, setClosing] = useState<PayrollPeriod | null>(null);
const [reopening, setReopening] = useState<PayrollPeriod | null>(null);
function handleClose() {
if (!closing) return;
router.post(close(closing.id), {}, {
onSuccess: () => setClosing(null),
});
}
function handleReopen() {
if (!reopening) return;
router.post(reopen(reopening.id), {}, {
onSuccess: () => setReopening(null),
});
}
const columns = createPayrollPeriodColumns({
showUrl: (id) => payrollPeriodShow(id).url,
handleClose: (period) => setClosing(period),
handleReopen: (period) => setReopening(period),
});
return (
<>
<Head title="Gaji" />
<div className="flex h-full flex-1 flex-col gap-6 overflow-x-auto p-4 md:p-6">
<div className="flex items-center justify-between">
<div>
<h2 className="text-2xl font-semibold tracking-tight">
Gaji
</h2>
</div>
</div>
<DataTable
columns={columns}
data={payrollPeriods}
searchKey="year"
searchPlaceholder="Cari periode..."
emptyText="Belum ada periode gaji."
/>
<ConfirmDialog
open={closing !== null}
onOpenChange={(open) => {
if (!open) setClosing(null);
}}
title="Tutup Periode Gaji"
description={`Apakah Anda yakin ingin menutup periode gaji ${closing ? `${MONTH_NAMES[closing.month]} ${closing.year}` : ''}? Semua gaji harus sudah dibayar sebelum periode ditutup.`}
confirmLabel="Tutup"
onConfirm={handleClose}
/>
<ConfirmDialog
open={reopening !== null}
onOpenChange={(open) => {
if (!open) setReopening(null);
}}
title="Buka Periode Gaji"
description={`Apakah Anda yakin ingin membuka kembali periode gaji ${reopening ? `${MONTH_NAMES[reopening.month]} ${reopening.year}` : ''}?`}
confirmLabel="Buka"
onConfirm={handleReopen}
/>
</div>
</>
);
}
PayrollPeriodIndex.layout = {
breadcrumbs: [
{
title: 'Keuangan',
href: payrollPeriodsIndex(),
},
{
title: 'Gaji',
href: payrollPeriodsIndex(),
},
],
};