diff --git a/apps/api/src/app/orders/orders.service.ts b/apps/api/src/app/orders/orders.service.ts index ef03d82..ae25b6a 100644 --- a/apps/api/src/app/orders/orders.service.ts +++ b/apps/api/src/app/orders/orders.service.ts @@ -58,6 +58,8 @@ export class OrdersService { num_ped_sar: string; numero: number; id_cliente: number; + nome_cliente: string | null; + razao_cliente: string | null; cod_vendedor: number; situa: number; status_descr: string; @@ -70,8 +72,10 @@ export class OrdersService { const [rows, countRows] = await Promise.all([ prisma.$queryRawUnsafe(` SELECT e.id_pedido, e.num_ped_sar, e.numero, e.id_cliente, e.cod_vendedor, - e.situa, e.status_descr, e.dt_pedido, e.total::text, e.desconto_perc::text, e.obs + e.situa, e.status_descr, e.dt_pedido, e.total::text, e.desconto_perc::text, e.obs, + c.nome AS nome_cliente, c.razao AS razao_cliente FROM vw_pedidos_erp e + LEFT JOIN vw_clientes c ON c.id_cliente = e.id_cliente AND c.id_empresa = e.id_empresa ${filters} ORDER BY e.dt_pedido DESC LIMIT ${limit} OFFSET ${offset} @@ -88,6 +92,8 @@ export class OrdersService { numPedSar: (o.num_ped_sar ?? '').trim(), numero: Number(o.numero), idCliente: Number(o.id_cliente), + nomeCliente: o.nome_cliente ?? null, + razaoCliente: o.razao_cliente ?? null, codVendedor: Number(o.cod_vendedor), situa: Number(o.situa), statusDescr: o.status_descr, diff --git a/apps/web/src/cockpits/rep/OrdersPage.tsx b/apps/web/src/cockpits/rep/OrdersPage.tsx index 428a5df..7697e2e 100644 --- a/apps/web/src/cockpits/rep/OrdersPage.tsx +++ b/apps/web/src/cockpits/rep/OrdersPage.tsx @@ -297,8 +297,15 @@ function OrderDetailDrawer({ id, onClose }: { id: string | null; onClose: () => {fmtDate(data.dtPedido)} - Cód. Cliente - {data.idCliente} + Cliente + + {data.razaoCliente ?? data.nomeCliente ?? `Cód. ${data.idCliente}`} + + {data.nomeCliente && data.razaoCliente && ( + + {data.nomeCliente} + + )} Total @@ -406,7 +413,8 @@ function MobileOrderCard({ - Cód. cliente {order.idCliente} · {fmtDate(order.dtPedido)} + {order.razaoCliente ?? order.nomeCliente ?? `Cód. ${order.idCliente}`} ·{' '} + {fmtDate(order.dtPedido)} {fmt(order.total)} @@ -517,16 +525,24 @@ export function OrdersPage() { { title: 'Cliente', key: 'cliente', - render: (_: unknown, row: PedidoSummary) => ( - - Cód. {row.idCliente} - {row.obs && ( - - {row.obs.slice(0, 40)} - - )} - - ), + ellipsis: true, + render: (_: unknown, row: PedidoSummary) => { + const nome = row.razaoCliente ?? row.nomeCliente; + return ( + + {nome ? ( + {nome} + ) : ( + Cód. {row.idCliente} + )} + {row.nomeCliente && row.razaoCliente && ( + + {row.nomeCliente} + + )} + + ); + }, }, { title: 'Status', diff --git a/libs/shared/api-interface/src/lib/order.contract.ts b/libs/shared/api-interface/src/lib/order.contract.ts index 97b0c72..921a5e7 100644 --- a/libs/shared/api-interface/src/lib/order.contract.ts +++ b/libs/shared/api-interface/src/lib/order.contract.ts @@ -51,6 +51,8 @@ export const PedidoSummarySchema = z.object({ numPedSar: z.string(), numero: z.number().int().optional(), // número do pedido no ERP idCliente: z.number().int(), + nomeCliente: z.string().nullable().optional(), + razaoCliente: z.string().nullable().optional(), codVendedor: z.number().int(), situa: z.number().int(), statusDescr: z.string().optional(), // descrição legível do status