feat(orders): nome do cliente na lista de pedidos via LEFT JOIN vw_clientes

- JOIN de vw_pedidos_erp com vw_clientes pelo id_cliente + id_empresa
- Campos nomeCliente e razaoCliente adicionados ao PedidoSummary (contrato)
- Tabela, cards mobile e drawer exibem razão social (fallback para nome)

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-29 19:00:22 +00:00
parent fb6df551b7
commit 2d4f342697
3 changed files with 38 additions and 14 deletions

View File

@@ -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<ErpRow[]>(`
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,

View File

@@ -297,8 +297,15 @@ function OrderDetailDrawer({ id, onClose }: { id: string | null; onClose: () =>
<Text>{fmtDate(data.dtPedido)}</Text>
</Col>
<Col span={12}>
<span style={label}>Cód. Cliente</span>
<Text>{data.idCliente}</Text>
<span style={label}>Cliente</span>
<Text strong>
{data.razaoCliente ?? data.nomeCliente ?? `Cód. ${data.idCliente}`}
</Text>
{data.nomeCliente && data.razaoCliente && (
<Text type="secondary" style={{ fontSize: 12, display: 'block' }}>
{data.nomeCliente}
</Text>
)}
</Col>
<Col span={12}>
<span style={label}>Total</span>
@@ -406,7 +413,8 @@ function MobileOrderCard({
<OrderStatusBadge situa={order.situa} descr={order.statusDescr} />
</div>
<Text type="secondary" style={{ fontSize: 12, display: 'block', marginBottom: 4 }}>
Cód. cliente {order.idCliente} · {fmtDate(order.dtPedido)}
{order.razaoCliente ?? order.nomeCliente ?? `Cód. ${order.idCliente}`} ·{' '}
{fmtDate(order.dtPedido)}
</Text>
<Text strong style={{ fontSize: 16, color: '#003B8E' }}>
{fmt(order.total)}
@@ -517,16 +525,24 @@ export function OrdersPage() {
{
title: 'Cliente',
key: 'cliente',
render: (_: unknown, row: PedidoSummary) => (
ellipsis: true,
render: (_: unknown, row: PedidoSummary) => {
const nome = row.razaoCliente ?? row.nomeCliente;
return (
<Space direction="vertical" size={0}>
<Text style={{ fontWeight: 500 }}>Cód. {row.idCliente}</Text>
{row.obs && (
<Text type="secondary" style={{ fontSize: 11 }} ellipsis={{ tooltip: row.obs }}>
{row.obs.slice(0, 40)}
{nome ? (
<Text style={{ fontWeight: 500 }}>{nome}</Text>
) : (
<Text type="secondary">Cód. {row.idCliente}</Text>
)}
{row.nomeCliente && row.razaoCliente && (
<Text type="secondary" style={{ fontSize: 11 }}>
{row.nomeCliente}
</Text>
)}
</Space>
),
);
},
},
{
title: 'Status',

View File

@@ -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