dstpabuaran.com/resources/js/pages/admin/finance/cash-account/transaction-columns.tsx
Yoga Pangestu 4ac83c8e78 feat: add permission checks for various actions across admin pages
- Integrated permission checks using `can` function in payroll period management to control visibility of adjustment, pay, and cancel actions.
- Updated employee management to conditionally render edit, reset password, and delete actions based on permissions.
- Enhanced leave request management with permission checks for approve, reject, edit, and delete actions.
- Implemented permission checks in cutting management for edit and delete actions.
- Added permission checks for purchase management actions including create, edit, and delete.
- Integrated permission checks in restock management for create, edit, and delete actions.
- Updated transaction management to conditionally render create, edit, and delete actions based on permissions.
- Enhanced category management with permission checks for edit and delete actions.
- Integrated permission checks in customer management for edit and delete actions.
- Updated product management to conditionally render create, edit, and delete actions based on permissions.
- Enhanced raw material management with permission checks for edit and delete actions.
- Integrated permission checks in supplier management for edit and delete actions.
- Updated role management to conditionally render edit and delete actions based on permissions.
2026-08-05 22:52:35 +07:00

196 lines
6.2 KiB
TypeScript

import type { ColumnDef } from '@tanstack/react-table';
import { Pencil, Trash2 } from 'lucide-react';
import { ImagePreviewButton } from '@/components/image-preview-button';
import { RowActions } from '@/components/row-actions';
export type CashTransaction = {
id: number;
amount: number;
formatted_amount: string;
balance_after: number;
formatted_balance_after: string;
type: 'deposit' | 'withdrawal' | 'expense' | 'transfer';
description: string;
receipt_key: string | null;
receipt_url: string | null;
created_at: string;
formatted_created_at: string;
created_by: {
user_profile: {
full_name: string;
};
};
reference: {
type: string;
} | null;
};
function getTypeLabel(type: string): string {
const labels: Record<string, string> = {
deposit: 'Deposit',
withdrawal: 'Withdrawal',
expense: 'Pengeluaran',
transfer: 'Transfer',
};
return labels[type] ?? type;
}
function getReferenceLabel(type: string): string {
const labels: Record<string, string> = {
'App\\Models\\Expense': 'Pengeluaran',
'App\\Models\\Order': 'Penjualan Tunai',
'App\\Models\\Purchase': 'Belanja',
'App\\Models\\CashAccount': 'Transfer Kas',
};
return labels[type] ?? '-';
}
type CreateColumnsParams = {
handleEdit: (transaction: CashTransaction) => void;
handleDeleteClick: (transaction: CashTransaction) => void;
can: (permission: string) => boolean;
};
export function createTransactionColumns(
params: CreateColumnsParams,
): ColumnDef<CashTransaction>[] {
const { handleEdit, handleDeleteClick, can } = params;
return [
{
accessorKey: 'formatted_created_at',
header: () => <span>Tanggal</span>,
cell: ({ row }) => (
<span>{row.getValue('formatted_created_at') as string}</span>
),
},
{
id: 'source',
header: () => <span>Sumber</span>,
cell: ({ row }) => {
const transaction = row.original;
return (
<div className="flex flex-col">
<span className="font-medium">
{getTypeLabel(transaction.type)}
</span>
<span className="text-xs text-muted-foreground">
{getReferenceLabel(
transaction.reference?.type ?? '',
)}
</span>
</div>
);
},
},
{
accessorKey: 'formatted_amount',
header: () => <span>Jumlah</span>,
cell: ({ row }) => {
const transaction = row.original;
const isDeposit = transaction.type === 'deposit';
return (
<span
className={
isDeposit
? 'font-medium text-green-600'
: 'font-medium text-red-600'
}
>
{isDeposit ? '+' : '-'}{' '}
{row.getValue('formatted_amount') as string}
</span>
);
},
},
{
accessorKey: 'formatted_balance_after',
header: () => <span>Saldo Setelah</span>,
cell: ({ row }) => (
<span className="font-medium">
{row.getValue('formatted_balance_after') as string}
</span>
),
},
{
accessorKey: 'description',
header: () => <span>Keterangan</span>,
cell: ({ row }) => (
<span className="block max-w-[200px] truncate">
{row.getValue('description') as string}
</span>
),
},
{
id: 'receipt',
header: () => <span>Bukti</span>,
cell: ({ row }) => {
const receiptUrl = row.original.receipt_url;
if (!receiptUrl) {
return <span className="text-muted-foreground">-</span>;
}
return (
<ImagePreviewButton
srcs={[receiptUrl]}
title={row.original.description}
/>
);
},
},
{
id: 'created_by',
header: () => <span>Oleh</span>,
cell: ({ row }) => {
const createdBy = row.original.created_by;
return <span>{createdBy?.user_profile?.full_name ?? '-'}</span>;
},
},
{
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
className: 'w-[100px] text-center',
headerClassName: 'w-[100px] text-center',
},
cell: ({ row }) => {
const transaction = row.original;
const canEdit =
transaction.type === 'deposit' ||
transaction.type === 'withdrawal';
if (!canEdit) {
return <span className="block text-center">-</span>;
}
return (
<RowActions
actions={[
{
label: 'Edit',
icon: <Pencil className="h-4 w-4" />,
show: can('cash.update'),
onClick: () => handleEdit(transaction),
},
{
label: 'Hapus',
icon: (
<Trash2 className="h-4 w-4 text-destructive" />
),
show: can('cash.delete'),
onClick: () => handleDeleteClick(transaction),
},
]}
/>
);
},
},
];
}