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:
@@ -58,6 +58,8 @@ export class OrdersService {
|
|||||||
num_ped_sar: string;
|
num_ped_sar: string;
|
||||||
numero: number;
|
numero: number;
|
||||||
id_cliente: number;
|
id_cliente: number;
|
||||||
|
nome_cliente: string | null;
|
||||||
|
razao_cliente: string | null;
|
||||||
cod_vendedor: number;
|
cod_vendedor: number;
|
||||||
situa: number;
|
situa: number;
|
||||||
status_descr: string;
|
status_descr: string;
|
||||||
@@ -70,8 +72,10 @@ export class OrdersService {
|
|||||||
const [rows, countRows] = await Promise.all([
|
const [rows, countRows] = await Promise.all([
|
||||||
prisma.$queryRawUnsafe<ErpRow[]>(`
|
prisma.$queryRawUnsafe<ErpRow[]>(`
|
||||||
SELECT e.id_pedido, e.num_ped_sar, e.numero, e.id_cliente, e.cod_vendedor,
|
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
|
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}
|
${filters}
|
||||||
ORDER BY e.dt_pedido DESC
|
ORDER BY e.dt_pedido DESC
|
||||||
LIMIT ${limit} OFFSET ${offset}
|
LIMIT ${limit} OFFSET ${offset}
|
||||||
@@ -88,6 +92,8 @@ export class OrdersService {
|
|||||||
numPedSar: (o.num_ped_sar ?? '').trim(),
|
numPedSar: (o.num_ped_sar ?? '').trim(),
|
||||||
numero: Number(o.numero),
|
numero: Number(o.numero),
|
||||||
idCliente: Number(o.id_cliente),
|
idCliente: Number(o.id_cliente),
|
||||||
|
nomeCliente: o.nome_cliente ?? null,
|
||||||
|
razaoCliente: o.razao_cliente ?? null,
|
||||||
codVendedor: Number(o.cod_vendedor),
|
codVendedor: Number(o.cod_vendedor),
|
||||||
situa: Number(o.situa),
|
situa: Number(o.situa),
|
||||||
statusDescr: o.status_descr,
|
statusDescr: o.status_descr,
|
||||||
|
|||||||
@@ -297,8 +297,15 @@ function OrderDetailDrawer({ id, onClose }: { id: string | null; onClose: () =>
|
|||||||
<Text>{fmtDate(data.dtPedido)}</Text>
|
<Text>{fmtDate(data.dtPedido)}</Text>
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={12}>
|
<Col span={12}>
|
||||||
<span style={label}>Cód. Cliente</span>
|
<span style={label}>Cliente</span>
|
||||||
<Text>{data.idCliente}</Text>
|
<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>
|
||||||
<Col span={12}>
|
<Col span={12}>
|
||||||
<span style={label}>Total</span>
|
<span style={label}>Total</span>
|
||||||
@@ -406,7 +413,8 @@ function MobileOrderCard({
|
|||||||
<OrderStatusBadge situa={order.situa} descr={order.statusDescr} />
|
<OrderStatusBadge situa={order.situa} descr={order.statusDescr} />
|
||||||
</div>
|
</div>
|
||||||
<Text type="secondary" style={{ fontSize: 12, display: 'block', marginBottom: 4 }}>
|
<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>
|
||||||
<Text strong style={{ fontSize: 16, color: '#003B8E' }}>
|
<Text strong style={{ fontSize: 16, color: '#003B8E' }}>
|
||||||
{fmt(order.total)}
|
{fmt(order.total)}
|
||||||
@@ -517,16 +525,24 @@ export function OrdersPage() {
|
|||||||
{
|
{
|
||||||
title: 'Cliente',
|
title: 'Cliente',
|
||||||
key: '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}>
|
<Space direction="vertical" size={0}>
|
||||||
<Text style={{ fontWeight: 500 }}>Cód. {row.idCliente}</Text>
|
{nome ? (
|
||||||
{row.obs && (
|
<Text style={{ fontWeight: 500 }}>{nome}</Text>
|
||||||
<Text type="secondary" style={{ fontSize: 11 }} ellipsis={{ tooltip: row.obs }}>
|
) : (
|
||||||
{row.obs.slice(0, 40)}
|
<Text type="secondary">Cód. {row.idCliente}</Text>
|
||||||
|
)}
|
||||||
|
{row.nomeCliente && row.razaoCliente && (
|
||||||
|
<Text type="secondary" style={{ fontSize: 11 }}>
|
||||||
|
{row.nomeCliente}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
</Space>
|
</Space>
|
||||||
),
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Status',
|
title: 'Status',
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ export const PedidoSummarySchema = z.object({
|
|||||||
numPedSar: z.string(),
|
numPedSar: z.string(),
|
||||||
numero: z.number().int().optional(), // número do pedido no ERP
|
numero: z.number().int().optional(), // número do pedido no ERP
|
||||||
idCliente: z.number().int(),
|
idCliente: z.number().int(),
|
||||||
|
nomeCliente: z.string().nullable().optional(),
|
||||||
|
razaoCliente: z.string().nullable().optional(),
|
||||||
codVendedor: z.number().int(),
|
codVendedor: z.number().int(),
|
||||||
situa: z.number().int(),
|
situa: z.number().int(),
|
||||||
statusDescr: z.string().optional(), // descrição legível do status
|
statusDescr: z.string().optional(), // descrição legível do status
|
||||||
|
|||||||
Reference in New Issue
Block a user