mirror of
https://codeberg.org/MarkusThielker/finances.git
synced 2025-07-04 03:59:18 +00:00
N-FIN-7: add payment form
This commit is contained in:
parent
8fce6de31d
commit
8941760827
2 changed files with 426 additions and 0 deletions
65
src/app/payments/columns.tsx
Normal file
65
src/app/payments/columns.tsx
Normal file
|
@ -0,0 +1,65 @@
|
|||
'use client';
|
||||
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { Category, Entity, Payment } from '@prisma/client';
|
||||
import { CellContext, ColumnDefTemplate } from '@tanstack/table-core';
|
||||
import { format } from 'date-fns';
|
||||
|
||||
export const columns = (
|
||||
actionCell: ColumnDefTemplate<CellContext<Payment, unknown>>,
|
||||
entities: Entity[],
|
||||
categories: Category[],
|
||||
) => {
|
||||
|
||||
return [
|
||||
{
|
||||
accessorKey: 'date',
|
||||
header: 'Date',
|
||||
cell: ({row}) => {
|
||||
return format(row.original.date, 'PPP');
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'amount',
|
||||
header: 'Amount',
|
||||
cell: ({row}) => {
|
||||
return new Intl.NumberFormat('en-US', {
|
||||
style: 'currency',
|
||||
currency: 'EUR',
|
||||
}).format(row.getValue('amount') as number / 100);
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'payorId',
|
||||
header: 'Payor',
|
||||
cell: ({row}) => {
|
||||
const entity = entities.find((entity) => entity.id === row.original.payorId);
|
||||
return entity?.name ?? '-';
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'payeeId',
|
||||
header: 'Payee',
|
||||
cell: ({row}) => {
|
||||
const entity = entities.find((entity) => entity.id === row.original.payeeId);
|
||||
return entity?.name ?? '-';
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'categoryId',
|
||||
header: 'Category',
|
||||
cell: ({row}) => {
|
||||
const category = categories.find((category) => category.id === row.original.categoryId);
|
||||
return category?.name ?? '-';
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'note',
|
||||
header: 'Note',
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
cell: actionCell,
|
||||
},
|
||||
] as ColumnDef<Payment>[];
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue