From 886969cce02495b245b834202a7b82a8f9d8e240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Thu, 27 Aug 2026 10:56:11 -0300 Subject: [PATCH] Record cut layers and marker references --- backend/db.js | 4 +++- backend/services/productionOrderService.js | 28 ++++++++++++++++++---- src/pages/ProductionOrders.tsx | 4 ++++ src/types.ts | 4 ++++ 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/backend/db.js b/backend/db.js index 35db2dc..d891657 100644 --- a/backend/db.js +++ b/backend/db.js @@ -647,7 +647,9 @@ const initDB = async () => { ADD COLUMN IF NOT EXISTS actual_cut_quantity NUMERIC(14, 4), ADD COLUMN IF NOT EXISTS rejected_quantity NUMERIC(14, 4) NOT NULL DEFAULT 0, ADD COLUMN IF NOT EXISTS finished_quantity NUMERIC(14, 4), - ADD COLUMN IF NOT EXISTS quality_notes TEXT; + ADD COLUMN IF NOT EXISTS quality_notes TEXT, + ADD COLUMN IF NOT EXISTS cut_layers INTEGER, + ADD COLUMN IF NOT EXISTS marker_reference VARCHAR(160); `).catch(() => {}); await pool.query(` diff --git a/backend/services/productionOrderService.js b/backend/services/productionOrderService.js index 0a13455..e70ef73 100644 --- a/backend/services/productionOrderService.js +++ b/backend/services/productionOrderService.js @@ -322,6 +322,8 @@ const mapProductionOrderRow = (row) => { rejectedQuantity: Number(row.rejected_quantity || 0), finishedQuantity: row.finished_quantity === null ? null : Number(row.finished_quantity), qualityNotes: row.quality_notes || '', + cutLayers: row.cut_layers === null || row.cut_layers === undefined ? null : Number(row.cut_layers), + markerReference: row.marker_reference || '', defects: Array.isArray(row.defects) ? row.defects.map(mapDefect) : [], lotReservations: Array.isArray(row.lot_reservations) ? row.lot_reservations.map(mapLotReservation) : [], markers: Array.isArray(row.markers) ? row.markers.filter(Boolean) : [], @@ -526,6 +528,8 @@ const getOrderById = async (id, client = pool) => { po.rejected_quantity, po.finished_quantity, po.quality_notes, + po.cut_layers, + po.marker_reference, po.created_at, po.updated_at, COALESCE( @@ -664,6 +668,8 @@ const baseProductionOrderSelect = ` po.rejected_quantity, po.finished_quantity, po.quality_notes, + po.cut_layers, + po.marker_reference, po.created_at, po.updated_at, COALESCE( @@ -1842,15 +1848,19 @@ const updateProductionOrderExecution = async (id, payload = {}) => { const rejectedQuantity = normalizeNonNegativeQuantity(payload.rejectedQuantity); const finishedQuantity = normalizeNonNegativeQuantity(payload.finishedQuantity); const qualityNotes = normalizeText(payload.qualityNotes); + const cutLayers = payload.cutLayers === '' || payload.cutLayers === null || payload.cutLayers === undefined + ? null + : normalizeInteger(payload.cutLayers); + const markerReference = normalizeText(payload.markerReference); - if (actualCutQuantity === null && rejectedQuantity === null && finishedQuantity === null && !qualityNotes) { + if (actualCutQuantity === null && rejectedQuantity === null && finishedQuantity === null && !qualityNotes && cutLayers === null && !markerReference) { const error = new Error('Informe uma quantidade de execução ou uma observação de qualidade.'); error.statusCode = 400; throw error; } const currentResult = await pool.query(` - SELECT actual_cut_quantity, rejected_quantity, finished_quantity + SELECT actual_cut_quantity, rejected_quantity, finished_quantity, cut_layers, marker_reference FROM production_orders WHERE id = $1; `, [id]); @@ -1864,6 +1874,14 @@ const updateProductionOrderExecution = async (id, payload = {}) => { const effectiveActual = actualCutQuantity === null ? (current.actual_cut_quantity === null ? null : Number(current.actual_cut_quantity)) : actualCutQuantity; const effectiveRejected = rejectedQuantity === null ? Number(current.rejected_quantity || 0) : rejectedQuantity; const effectiveFinished = finishedQuantity === null ? (current.finished_quantity === null ? null : Number(current.finished_quantity)) : finishedQuantity; + const effectiveLayers = cutLayers === null ? (current.cut_layers === null ? null : Number(current.cut_layers)) : cutLayers; + const effectiveMarkerReference = markerReference || current.marker_reference || ''; + + if (effectiveLayers !== null && effectiveLayers <= 0) { + const error = new Error('O número de camadas deve ser maior que zero.'); + error.statusCode = 400; + throw error; + } if (effectiveActual !== null && effectiveRejected > effectiveActual) { const error = new Error('As perdas não podem ser maiores que a quantidade cortada.'); @@ -1882,9 +1900,11 @@ const updateProductionOrderExecution = async (id, payload = {}) => { rejected_quantity = $2, finished_quantity = $3, quality_notes = NULLIF($4, ''), + cut_layers = $5, + marker_reference = NULLIF($6, ''), updated_at = CURRENT_TIMESTAMP - WHERE id = $5; - `, [effectiveActual, effectiveRejected, effectiveFinished, qualityNotes, id]); + WHERE id = $7; + `, [effectiveActual, effectiveRejected, effectiveFinished, qualityNotes, effectiveLayers, effectiveMarkerReference, id]); return getOrderById(id); }; diff --git a/src/pages/ProductionOrders.tsx b/src/pages/ProductionOrders.tsx index c47750e..0cb908c 100644 --- a/src/pages/ProductionOrders.tsx +++ b/src/pages/ProductionOrders.tsx @@ -307,6 +307,8 @@ const ProductionOrders = () => { rejectedQuantity: parseOptionalQuantity('rejectedQuantity'), finishedQuantity: parseOptionalQuantity('finishedQuantity'), qualityNotes: String(form.get('qualityNotes') || '').trim(), + cutLayers: parseOptionalQuantity('cutLayers'), + markerReference: String(form.get('markerReference') || '').trim(), }); const nextSummary = await fetchProductionOrders(dateRange, { search: searchTerm }, { force: true }); setSummary(nextSummary); @@ -419,6 +421,8 @@ const ProductionOrders = () => { + +