diff --git a/conversor_relatorio_estruturas.html b/conversor_relatorio_estruturas.html index c6e9ab5..e55d008 100644 --- a/conversor_relatorio_estruturas.html +++ b/conversor_relatorio_estruturas.html @@ -618,11 +618,9 @@ } if (currentAssembly) { - const isSubComp = - itemMark === '-' || - itemMark.includes('-100') || - itemMark.includes('-10') || - (itemMark.match(/-\d+$/) && parseInt(itemMark.match(/-(\d+)$/)[1], 10) >= 1000); + const lastNumberMatch = itemMark.match(/(?:^|-)(\d+)$/); + const itemNum = lastNumberMatch ? parseInt(lastNumberMatch[1], 10) : (parseInt(itemMark, 10) || 0); + const isSubComp = itemMark === '-' || itemNum >= 1000; if (isSubComp) { currentAssembly.isComposed = 'SIM'; diff --git a/public/conversor_relatorio_estruturas.html b/public/conversor_relatorio_estruturas.html index c6e9ab5..e55d008 100644 --- a/public/conversor_relatorio_estruturas.html +++ b/public/conversor_relatorio_estruturas.html @@ -618,11 +618,9 @@ } if (currentAssembly) { - const isSubComp = - itemMark === '-' || - itemMark.includes('-100') || - itemMark.includes('-10') || - (itemMark.match(/-\d+$/) && parseInt(itemMark.match(/-(\d+)$/)[1], 10) >= 1000); + const lastNumberMatch = itemMark.match(/(?:^|-)(\d+)$/); + const itemNum = lastNumberMatch ? parseInt(lastNumberMatch[1], 10) : (parseInt(itemMark, 10) || 0); + const isSubComp = itemMark === '-' || itemNum >= 1000; if (isSubComp) { currentAssembly.isComposed = 'SIM'; diff --git a/src/components/conversores/AdvanceSteelConverter.tsx b/src/components/conversores/AdvanceSteelConverter.tsx index 08e3eba..47ed144 100644 --- a/src/components/conversores/AdvanceSteelConverter.tsx +++ b/src/components/conversores/AdvanceSteelConverter.tsx @@ -518,12 +518,12 @@ const AdvanceSteelConverterContent: React.FC = () => { } if (currentAssembly) { - const isSubComp = - itemMark === '-' || - isComponente(itemMark) || - itemMark.includes('-100') || - itemMark.includes('-10') || - (itemMark.match(/-\d+$/) && parseInt(itemMark.match(/-(\d+)$/)![1], 10) >= (labels.faixaComponenteMin || 1000)); + // Extrai o número final da marca do item (ex: de "B134-13-1" -> 1, de "B134-13-1000" -> 1000, de "B133-13-1015" -> 1015, de "1000" -> 1000) + const lastNumberMatch = itemMark.match(/(?:^|-)(\d+)$/); + const itemNum = lastNumberMatch ? parseInt(lastNumberMatch[1], 10) : (parseInt(itemMark, 10) || 0); + + // Um item é SUBCOMPONENTE apenas se sua numeração de marca for >= faixaComponenteMin (1000) OU se for explicitamente '-' + const isSubComp = itemMark === '-' || itemNum >= (labels.faixaComponenteMin || 1000); if (isSubComp) { currentAssembly.isComposed = 'SIM'; diff --git a/src/components/pecas/table/TableHeaderSortable.tsx b/src/components/pecas/table/TableHeaderSortable.tsx index 78117cb..89bdfd5 100644 --- a/src/components/pecas/table/TableHeaderSortable.tsx +++ b/src/components/pecas/table/TableHeaderSortable.tsx @@ -72,8 +72,8 @@ export function TableHeaderSortable({ Prioridade - - Tipo / {labels.componenteLabel} + + Componentes diff --git a/src/components/pecas/table/TableRow.tsx b/src/components/pecas/table/TableRow.tsx index 51a8861..dd13302 100644 --- a/src/components/pecas/table/TableRow.tsx +++ b/src/components/pecas/table/TableRow.tsx @@ -13,7 +13,8 @@ import { ChevronDown, Layers, Loader2, - ExternalLink + ExternalLink, + Minus } from 'lucide-react'; import { Peca } from '@/hooks/usePecas'; import { useComponentesPeca } from '@/hooks/useComponentesPeca'; @@ -110,11 +111,14 @@ export function TableRow({ - -
+ +
{!peca.tem_componentes ? ( -
- +
+
) : (
0) { - console.log('🔧 Inserindo e sincronizando componentes...'); - - for (const [pecaKey, componentes] of componentesMap.entries()) { - const pecaId = pecaIdResolvedMap.get(pecaKey); - - if (pecaId && componentes.length > 0) { + console.log('🔧 Inserindo e sincronizando componentes...'); + + for (const peca of pecasParaProcessar) { + const pecaKey = `${peca.of_number || ''}-${peca.etapa_fase || ''}-${peca.marca || ''}`; + const pecaId = pecaIdResolvedMap.get(pecaKey); + const componentes = componentesMap.get(pecaKey) || []; + + if (pecaId) { + if (componentes.length > 0) { // Limpar componentes antigos desta peça para atualizar de forma limpa await supabase .from('componentes_peca') @@ -596,6 +598,12 @@ export function usePecas() { } else { totalComponentesInseridos += componentesComPecaId.length; } + } else { + // Peça simples sem componentes: limpar componentes residuais antigos caso existissem + await supabase + .from('componentes_peca') + .delete() + .eq('peca_id', pecaId); } } }