Atualizando arquivos
This commit is contained in:
parent
01525cee84
commit
9503b874ec
1 changed files with 48 additions and 20 deletions
68
js/main.js
68
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){
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue