From 9503b874ecd32ca44042699cab671a6af565c77b Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Sun, 3 Aug 2025 09:49:50 -0300 Subject: [PATCH] Atualizando arquivos --- js/main.js | 68 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/js/main.js b/js/main.js index 55b1abc..be12ba9 100644 --- a/js/main.js +++ b/js/main.js @@ -1686,10 +1686,10 @@ function questionModal(data, message){ modalPage(true, 0, 0, 'Atenção', message, '', 'question', func); } + //Marca e desmarca todos os checkboxes de uma tabela function alternarCheckboxes() { - - + const checkboxes = document.querySelectorAll('input.group'); const todosMarcados = Array.from(checkboxes).every(cb => cb.checked); const novoEstado = !todosMarcados; @@ -1697,7 +1697,7 @@ function alternarCheckboxes() { // Marca ou desmarca todos checkboxes.forEach(cb => cb.checked = novoEstado); - // Verifica novamente quantos foram marcados após o clique + // Selecionados const selecionados = Array.from(checkboxes).filter(cb => cb.checked); if (selecionados.length === 0) { @@ -1705,29 +1705,57 @@ function alternarCheckboxes() { return; } - if (selecionados.length === checkboxes.length) { - const linhas = document.querySelectorAll('#tblProductsCompanies tbody tr'); + // Inicializa acumuladores + let totalValor = 0; + let vencimento = null; + let reajuste = null; + let descricoes = []; + let referencias = []; - linhas.forEach((linha, index) => { - const checkbox = linha.querySelector('input.group'); + for (const checkbox of selecionados) { + const linha = checkbox.closest('tr'); + if (!linha) continue; - if (checkbox && checkbox.checked) { - const colunas = linha.querySelectorAll('td'); - const dados = { - produto: colunas[1]?.textContent.trim(), - referencias: colunas[2]?.textContent.trim(), - descricao: colunas[3]?.textContent.trim(), - reajuste: colunas[4]?.textContent.trim(), - vencimento: colunas[5]?.textContent.trim(), - valor: colunas[6]?.textContent.trim() - }; - console.log(`Linha ${index + 1}:`, dados); + const colunas = linha.querySelectorAll('td'); + const valorTexto = colunas[6]?.textContent.trim().replace(/\./g, '').replace(',', '.'); + const valor = parseFloat(valorTexto); + if (!isNaN(valor)) { + totalValor += valor; } - }); + + // Vencimento + const venc = colunas[5]?.textContent.trim(); + if (vencimento === null) vencimento = venc; + else if (vencimento !== venc) { + alert("Existem vencimentos diferentes entre os itens selecionados!"); + return; + } + + // Reajuste + const reaj = colunas[4]?.textContent.trim(); + if (reajuste === null) reajuste = reaj; + else if (reajuste !== reaj) { + alert("Existem reajustes diferentes entre os itens selecionados!"); + return; + } + + // Descrição e Referência + const desc = colunas[3]?.textContent.trim(); + const ref = colunas[2]?.textContent.trim(); + if (desc) descricoes.push(desc); + if (ref) referencias.push(ref); } - + + // Exibe resultado agrupado + console.log("🔹 Resultado agrupado:"); + console.log("Referências:", referencias.join(', ')); + console.log("Descrição:", descricoes.join(', ')); + console.log("Reajuste:", reajuste); + console.log("Vencimento:", vencimento); + console.log("Total Valor:", totalValor.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' })); } + /** Carrega os itens de uma linha de uma tabela informada */ function prepareBudget(id, source, productId, budgetsId){