48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import type { ColumnDef } from '@tanstack/table-core';
|
|
import type { ExchangeRate } from '$lib/api/dashboard/a76/general_catalogs/exchange-rate';
|
|
import { renderComponent } from '$lib/components/ui/data-table';
|
|
import DataTableActions from './data-table-actions.svelte';
|
|
|
|
export function createColumns(onSuccess?: () => void): ColumnDef<ExchangeRate>[] {
|
|
return [
|
|
{
|
|
accessorKey: 'date',
|
|
header: 'Fecha',
|
|
cell: ({ row }) => {
|
|
const dateStr = row.original.date;
|
|
if (!dateStr) return 'N/A';
|
|
const date = new Date(dateStr);
|
|
return date.toLocaleDateString('es-MX');
|
|
}
|
|
},
|
|
{
|
|
accessorKey: 'value',
|
|
header: 'Valor',
|
|
cell: ({ row }) => {
|
|
const value = row.original.value;
|
|
if (value === null || value === undefined) return 'N/A';
|
|
return value.toFixed(6);
|
|
}
|
|
},
|
|
{
|
|
accessorKey: 'local_currency',
|
|
header: 'Moneda Local',
|
|
cell: ({ row }) => row.original.local_currency ?? 'N/A'
|
|
},
|
|
{
|
|
accessorKey: 'foreign_currency',
|
|
header: 'Moneda Extranjera',
|
|
cell: ({ row }) => row.original.foreign_currency ?? 'N/A'
|
|
},
|
|
{
|
|
id: 'actions',
|
|
header: 'Acciones',
|
|
cell: ({ row }) => {
|
|
return renderComponent(DataTableActions, {
|
|
item: row.original,
|
|
onSuccess
|
|
});
|
|
}
|
|
}
|
|
];
|
|
} |