feat: enhance invoice validation and logistics handling for improved data integrity

This commit is contained in:
2026-01-11 18:58:43 -06:00
parent 8bf0ac8969
commit 6e4e14285d
4 changed files with 83 additions and 27 deletions

View File

@@ -228,7 +228,7 @@ export interface Invoice {
enajenation_goods?: boolean | null;
compliance_mx?: InvoiceComplianceMx | null;
financials?: InvoiceFinancials | null;
logistics?: InvoiceLogistics[];
logistics?: InvoiceLogistics;
details?: InvoiceSalesDetails[];
collections?: InvoiceCollections[];
}

View File

@@ -18,6 +18,43 @@ function formatDate(date?: string | null): string {
export function createColumns(onSuccess?: () => void): ColumnDef<Invoice>[] {
return [
{
accessorKey: "operation_type",
header: "Operación",
cell: ({ row }) => {
const operationType = row.original.operation_type;
const operationSnippet = createRawSnippet<[{ type?: string | null }]>((getType) => {
const { type } = getType();
const isImport = type === 'imp';
const colorClass = isImport ? 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200' : 'bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200';
const label = isImport ? 'Importación' : type === 'exp' ? 'Exportación' : '-';
return {
render: () =>
`<span class="inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium ${colorClass}">
${label}
</span>`
};
});
return renderSnippet(operationSnippet, { type: operationType });
}
},
{
accessorKey: "invoice_type",
header: "Tipo Factura",
cell: ({ row }) => {
const invoiceType = row.original.invoice_type;
const typeSnippet = createRawSnippet<[{ type?: string | null }]>((getType) => {
const { type } = getType();
return {
render: () =>
`<div class="text-sm font-medium">${type || '-'}</div>`
};
});
return renderSnippet(typeSnippet, { type: invoiceType });
}
},
{
accessorKey: "invoice_number",
header: "Núm. Factura",
@@ -113,7 +150,7 @@ export function createColumns(onSuccess?: () => void): ColumnDef<Invoice>[] {
},
{
accessorKey: "total_items",
header: "Total Items",
header: "Total Partidas",
cell: ({ row }) => {
// El total de items viene del conteo de details
const totalItems = row.original.details?.length || 0;
@@ -165,7 +202,7 @@ export function createColumns(onSuccess?: () => void): ColumnDef<Invoice>[] {
header: "Tipo Peso",
cell: ({ row }) => {
// weight_type está en logistics que es un array, tomamos el primer elemento
const weightType = row.original.logistics?.[0]?.weight_type;
const weightType = row.original.logistics?.weight_type;
const weightSnippet = createRawSnippet<[{ type?: string | null }]>((getType) => {
const { type } = getType();

View File

@@ -71,11 +71,11 @@
exchange_rate: invoice.financials?.exchange_rate || null, // Added exchange_rate
weight_type: 'kgs',
iva_factor: invoice.financials?.iva_factor || null,
carrier_id: invoice.logistics?.[0]?.carrier_id || null,
transport_id: invoice.logistics?.[0]?.transport_id || '',
driver_name: invoice.logistics?.[0]?.driver_name || '',
transport_type: invoice.logistics?.[0]?.transport_type || '',
transport_num: invoice.logistics?.[0]?.vehicle_num || '',
carrier_id: invoice.logistics?.carrier_id || null,
transport_id: invoice.logistics?.transport_id || '',
driver_name: invoice.logistics?.driver_name || '',
transport_type: invoice.logistics?.transport_type || '',
transport_num: invoice.logistics?.vehicle_num || '',
aduana: invoice.compliance_mx?.aduana || '',
document_type: invoice.document_type || '',
};