att
This commit is contained in:
@@ -1,8 +1,34 @@
|
||||
var EXCEL_ATTACHMENT_DESCRIPTION = "Planilha de Itens Excel";
|
||||
var EXCEL_ATTACHMENT_INPUT_ID = "fnAnexo_PlanilhaItens";
|
||||
|
||||
function updateExcelImportUi(filename) {
|
||||
var name = String(filename || "").trim();
|
||||
if (name) {
|
||||
$("#nomeArquivoExcel").text("Arquivo selecionado: " + name);
|
||||
$("#btnAdicionarExcel").hide();
|
||||
$("#btnRemoverExcel").show();
|
||||
return;
|
||||
}
|
||||
$("#nomeArquivoExcel").text("Nenhum arquivo selecionado");
|
||||
$("#btnAdicionarExcel").show();
|
||||
$("#btnRemoverExcel").hide();
|
||||
}
|
||||
|
||||
function getExcelAttachmentField() {
|
||||
var $field = $("#" + EXCEL_ATTACHMENT_INPUT_ID);
|
||||
if ($field.length) return $field;
|
||||
return $("#_" + EXCEL_ATTACHMENT_INPUT_ID);
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
// Quando clicar em "Adicionar arquivo"
|
||||
$('#btnAdicionarExcel').on('click', function () {
|
||||
$('#excelUpload').click(); // aciona o input escondido
|
||||
if (typeof uploadFile === "function" && getExcelAttachmentField().length) {
|
||||
uploadFile(EXCEL_ATTACHMENT_DESCRIPTION, EXCEL_ATTACHMENT_INPUT_ID);
|
||||
return;
|
||||
}
|
||||
$('#excelUpload').click(); // fallback: aciona o input escondido
|
||||
});
|
||||
|
||||
// Quando um arquivo for selecionado
|
||||
@@ -10,10 +36,7 @@ $(document).ready(function () {
|
||||
const file = this.files[0];
|
||||
|
||||
if (file) {
|
||||
$('#nomeArquivoExcel').text('Arquivo selecionado: ' + file.name);
|
||||
$('#btnAdicionarExcel').hide();
|
||||
$('#btnRemoverExcel').show();
|
||||
|
||||
updateExcelImportUi(file.name);
|
||||
carregarItensDoExcel('excelUpload'); // chama sua função
|
||||
}
|
||||
});
|
||||
@@ -21,9 +44,17 @@ $(document).ready(function () {
|
||||
// Quando clicar em "Remover arquivo"
|
||||
$('#btnRemoverExcel').on('click', function () {
|
||||
$('#excelUpload').val('');
|
||||
$('#nomeArquivoExcel').text('Nenhum arquivo selecionado');
|
||||
$('#btnAdicionarExcel').show();
|
||||
$('#btnRemoverExcel').hide();
|
||||
updateExcelImportUi("");
|
||||
getExcelAttachmentField().val("");
|
||||
|
||||
try {
|
||||
removeFile(EXCEL_ATTACHMENT_DESCRIPTION);
|
||||
if (typeof setFilePhisicalName === "function") {
|
||||
setFilePhisicalName(EXCEL_ATTACHMENT_INPUT_ID, "");
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Falha ao remover anexo da planilha:", e);
|
||||
}
|
||||
});
|
||||
|
||||
$('#chaveNfe').on('input', function () {
|
||||
@@ -45,8 +76,28 @@ $(document).ready(function () {
|
||||
applySelectedMotoristaEntregaOption();
|
||||
});
|
||||
|
||||
$(document).on("input", "input[name^='quantidadeItem___']", function () {
|
||||
$(document).on("input", "input[name^='quantidadeItem___'], input[name^='_quantidadeItem___'], input[name='quantidadeItem'], input[name='_quantidadeItem'], input[id^='quantidadeItem___'], input[id^='_quantidadeItem___'], #quantidadeItem, #_quantidadeItem", function () {
|
||||
syncQuantidadeAprovadaFromSolicitada(this);
|
||||
processarConferenciaNfe();
|
||||
toggleQuantidadeAprovadaGestorByActivity($("#activity").val());
|
||||
});
|
||||
|
||||
$(document).on("input", ".input-qtd-aprov-gestor-view", function () {
|
||||
var linha = String($(this).attr("data-linha") || "");
|
||||
var indice = String($(this).attr("data-indice") || "");
|
||||
if (!linha) return;
|
||||
|
||||
var normalized = normalizeQuantidadeCampo($(this).val());
|
||||
$(this).val(normalized);
|
||||
var $row = $("#tabelaAprovacaoGestorItensBody tr[data-linha='" + linha + "']");
|
||||
var $hidden = getCampoItem("quantidadeAprovadaGestor", indice, $row);
|
||||
if (!$hidden.length) {
|
||||
$hidden = getCampoItem("quantidadeAprovadaGestor", indice);
|
||||
}
|
||||
if ($hidden.length) {
|
||||
$hidden.val(normalized);
|
||||
}
|
||||
atualizarStatusLinhaAprovacaoGestor(linha);
|
||||
});
|
||||
|
||||
var activity = String($("#activity").val() || "");
|
||||
@@ -194,11 +245,17 @@ $(document).ready(function () {
|
||||
updateConferenciaNfeVisibility(activity);
|
||||
}
|
||||
|
||||
syncQuantidadeAprovadaAllRows();
|
||||
toggleQuantidadeAprovadaGestorByActivity(activity);
|
||||
agendarRefreshTabelaAprovacao(activity);
|
||||
updateExcelImportUi(getExcelAttachmentField().val());
|
||||
|
||||
formatarMoedasTabela("preco___");
|
||||
//formatarMoedasTabela("precoIndica___");
|
||||
formatarMoedasTabela("ValorTotal");
|
||||
|
||||
displayBtnFiles();
|
||||
invisibleBtnUpload("fnAnexo_PlanilhaItens");
|
||||
invisibleBtnUpload("fnAnexo_Nfe");
|
||||
invisibleBtnUpload("fdAnexo_Coleta");
|
||||
invisibleBtnUpload("fdAnexo_Entrega");
|
||||
@@ -211,6 +268,20 @@ $(document).ready(function () {
|
||||
|
||||
});
|
||||
|
||||
function agendarRefreshTabelaAprovacao(activity) {
|
||||
var state = String(activity || $("#activity").val() || "");
|
||||
var retries = [250, 800, 1800];
|
||||
|
||||
for (var i = 0; i < retries.length; i++) {
|
||||
(function (delay) {
|
||||
setTimeout(function () {
|
||||
syncQuantidadeAprovadaAllRows();
|
||||
toggleQuantidadeAprovadaGestorByActivity(state);
|
||||
}, delay);
|
||||
})(retries[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function applyTransferStatus(activity) {
|
||||
var current = String(activity || "");
|
||||
var pills = $("#transferStatus .status-pill");
|
||||
@@ -331,6 +402,296 @@ function getCurrentDate() {
|
||||
return currentDate;
|
||||
}
|
||||
|
||||
function normalizeQuantidadeCampo(value) {
|
||||
var txt = String(value == null ? "" : value).trim();
|
||||
if (txt === "") return "";
|
||||
|
||||
txt = txt.replace(",", ".");
|
||||
var n = parseFloat(txt);
|
||||
if (isNaN(n) || n < 0) return "";
|
||||
|
||||
if (Math.floor(n) === n) return String(parseInt(n, 10));
|
||||
return String(n);
|
||||
}
|
||||
|
||||
function toNumberQuantidade(value) {
|
||||
var txt = normalizeQuantidadeCampo(value);
|
||||
if (txt === "") return NaN;
|
||||
return parseFloat(txt);
|
||||
}
|
||||
|
||||
function getIndiceCampoPaiFilho($el) {
|
||||
var raw = String($el.attr("name") || $el.attr("id") || "");
|
||||
if (raw.indexOf("___") < 0) return "";
|
||||
return String(raw.split("___")[1] || "");
|
||||
}
|
||||
|
||||
function collectQuantidadeItemFields() {
|
||||
var out = [];
|
||||
var seen = {};
|
||||
var selector = [
|
||||
"input[name^='quantidadeItem___']",
|
||||
"input[name^='_quantidadeItem___']",
|
||||
"input[name='quantidadeItem']",
|
||||
"input[name='_quantidadeItem']",
|
||||
"input[id^='quantidadeItem___']",
|
||||
"input[id^='_quantidadeItem___']",
|
||||
"#quantidadeItem",
|
||||
"#_quantidadeItem"
|
||||
].join(", ");
|
||||
|
||||
$(selector).each(function () {
|
||||
var $field = $(this);
|
||||
var key = String($field.attr("name") || $field.attr("id") || "");
|
||||
if (!key) {
|
||||
key = "anon_" + out.length;
|
||||
}
|
||||
if (seen[key]) return;
|
||||
seen[key] = true;
|
||||
out.push(this);
|
||||
});
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
function getCampoItem(baseName, indice, $scopeRow) {
|
||||
var idx = String(indice == null ? "" : indice).trim();
|
||||
var selectors = [];
|
||||
|
||||
if (idx !== "") {
|
||||
selectors.push("#" + baseName + "___" + idx);
|
||||
selectors.push("#_" + baseName + "___" + idx);
|
||||
selectors.push("[name='" + baseName + "___" + idx + "']");
|
||||
selectors.push("[name='_" + baseName + "___" + idx + "']");
|
||||
}
|
||||
|
||||
selectors.push("#" + baseName);
|
||||
selectors.push("#_" + baseName);
|
||||
selectors.push("[name='" + baseName + "']");
|
||||
selectors.push("[name='_" + baseName + "']");
|
||||
|
||||
for (var i = 0; i < selectors.length; i++) {
|
||||
var selector = selectors[i];
|
||||
var $field = $();
|
||||
|
||||
if ($scopeRow && $scopeRow.length) {
|
||||
$field = $scopeRow.find(selector).first();
|
||||
}
|
||||
|
||||
if (!$field.length) {
|
||||
$field = $(selector).first();
|
||||
}
|
||||
|
||||
if ($field.length) return $field;
|
||||
}
|
||||
|
||||
return $();
|
||||
}
|
||||
|
||||
function syncQuantidadeAprovadaFromSolicitada(inputSolicitada) {
|
||||
var $solicitada = $(inputSolicitada);
|
||||
var idx = getIndiceCampoPaiFilho($solicitada);
|
||||
var $row = $solicitada.closest("tr");
|
||||
|
||||
var $aprovada = getCampoItem("quantidadeAprovadaGestor", idx, $row);
|
||||
if (!$aprovada.length) return;
|
||||
|
||||
var currentAprovada = normalizeQuantidadeCampo($aprovada.val());
|
||||
if (currentAprovada !== "") return;
|
||||
|
||||
var solicitada = normalizeQuantidadeCampo($solicitada.val());
|
||||
if (solicitada !== "") {
|
||||
$aprovada.val(solicitada);
|
||||
}
|
||||
}
|
||||
|
||||
function syncQuantidadeAprovadaAllRows() {
|
||||
$(collectQuantidadeItemFields()).each(function () {
|
||||
syncQuantidadeAprovadaFromSolicitada(this);
|
||||
});
|
||||
}
|
||||
|
||||
function toggleQuantidadeAprovadaGestorByActivity(activity) {
|
||||
var state = String(activity || "");
|
||||
var isGestorApproval = state === "4";
|
||||
var $tbody = $("#tabelaAprovacaoGestorItensBody");
|
||||
if (!$tbody.length) return;
|
||||
|
||||
var html = [];
|
||||
var rowsFound = 0;
|
||||
|
||||
$(collectQuantidadeItemFields()).each(function (idx, el) {
|
||||
var $qtdSolicitadaField = $(el);
|
||||
var $row = $qtdSolicitadaField.closest("tr");
|
||||
var linha = getIndiceCampoPaiFilho($qtdSolicitadaField);
|
||||
var linhaKey = linha !== "" ? linha : ("base_" + idx);
|
||||
|
||||
var codigo = $.trim(String(getCampoItem("descricao", linha, $row).val() || ""));
|
||||
var descricao = $.trim(String(getCampoItem("codigoItem", linha, $row).val() || ""));
|
||||
var categoria = $.trim(String(getCampoItem("categoriaItem", linha, $row).val() || ""));
|
||||
var qtdSolicitadaNorm = normalizeQuantidadeCampo($qtdSolicitadaField.val());
|
||||
|
||||
var hasData = qtdSolicitadaNorm !== "" || codigo !== "" || descricao !== "" || categoria !== "";
|
||||
if (!hasData) return;
|
||||
|
||||
rowsFound++;
|
||||
var qtdSolicitadaLabel = qtdSolicitadaNorm || "-";
|
||||
|
||||
var itemLabel = codigo || descricao || ("Item " + rowsFound);
|
||||
if (descricao && descricao !== codigo) itemLabel += " - " + descricao;
|
||||
if (categoria) itemLabel += " (" + categoria + ")";
|
||||
|
||||
var $hiddenAprovada = getCampoItem("quantidadeAprovadaGestor", linha, $row);
|
||||
var qtdAprovadaAtual = normalizeQuantidadeCampo($hiddenAprovada.val());
|
||||
if (qtdAprovadaAtual === "" && qtdSolicitadaNorm !== "") {
|
||||
qtdAprovadaAtual = qtdSolicitadaNorm;
|
||||
$hiddenAprovada.val(qtdAprovadaAtual);
|
||||
}
|
||||
|
||||
var status = "Sem divergência";
|
||||
var statusClass = "label label-success";
|
||||
if (qtdSolicitadaNorm === "" || qtdAprovadaAtual === "") {
|
||||
status = "Aprovado";
|
||||
statusClass = "label label-default";
|
||||
} else {
|
||||
var nSolicitada = toNumberQuantidade(qtdSolicitadaNorm);
|
||||
var nAprovada = toNumberQuantidade(qtdAprovadaAtual);
|
||||
if (isNaN(nSolicitada) || isNaN(nAprovada)) {
|
||||
status = "Inválido";
|
||||
statusClass = "label label-danger";
|
||||
} else if (nAprovada > nSolicitada) {
|
||||
status = "Maior que solicitada";
|
||||
statusClass = "label label-danger";
|
||||
} else if (nAprovada === 0) {
|
||||
status = "Sem estoque";
|
||||
statusClass = "label label-warning";
|
||||
} else if (nAprovada < nSolicitada) {
|
||||
status = "Divergente";
|
||||
statusClass = "label label-warning";
|
||||
}
|
||||
}
|
||||
|
||||
var disabledAttr = isGestorApproval ? "" : " readonly disabled ";
|
||||
|
||||
html.push(
|
||||
"<tr data-linha='" + escapeHtml(linhaKey) + "' data-indice='" + escapeHtml(linha) + "' data-qtd-solicitada='" + escapeHtml(qtdSolicitadaNorm) + "'>" +
|
||||
"<td>" + rowsFound + "</td>" +
|
||||
"<td>" + escapeHtml(itemLabel) + "</td>" +
|
||||
"<td>" + escapeHtml(qtdSolicitadaLabel) + "</td>" +
|
||||
"<td>" +
|
||||
"<input type='number' min='0' " + disabledAttr +
|
||||
" class='form-control transfer-input input-qtd-aprov-gestor-view' " +
|
||||
" data-linha='" + escapeHtml(linhaKey) + "' data-indice='" + escapeHtml(linha) + "' " +
|
||||
" id='quantidadeAprovadaGestorView___" + escapeHtml(linhaKey) + "' " +
|
||||
" value='" + escapeHtml(qtdAprovadaAtual) + "' placeholder='Se diferente' />" +
|
||||
"</td>" +
|
||||
"<td><span class='" + statusClass + " status-aprov-gestor' data-linha='" + escapeHtml(linhaKey) + "'>" + escapeHtml(status) + "</span></td>" +
|
||||
"</tr>"
|
||||
);
|
||||
});
|
||||
|
||||
if (!rowsFound) {
|
||||
html.push("<tr><td colspan='5'>Sem itens para validação.</td></tr>");
|
||||
}
|
||||
|
||||
$tbody.html(html.join(""));
|
||||
$(".hint-qtd-aprov-gestor").toggle(isGestorApproval);
|
||||
}
|
||||
|
||||
function atualizarStatusLinhaAprovacaoGestor(linha) {
|
||||
var rowSelector = "#tabelaAprovacaoGestorItensBody tr[data-linha='" + linha + "']";
|
||||
var $row = $(rowSelector);
|
||||
if (!$row.length) return;
|
||||
|
||||
var $status = $row.find(".status-aprov-gestor");
|
||||
if (!$status.length) return;
|
||||
|
||||
var qtdSolicitada = toNumberQuantidade($row.attr("data-qtd-solicitada"));
|
||||
var qtdAprovada = toNumberQuantidade($row.find(".input-qtd-aprov-gestor-view").val());
|
||||
|
||||
$status.removeClass("label-success label-warning label-danger label-default");
|
||||
|
||||
if (isNaN(qtdSolicitada) || isNaN(qtdAprovada)) {
|
||||
$status.addClass("label-default").text("Pendente");
|
||||
return;
|
||||
}
|
||||
|
||||
if (qtdAprovada > qtdSolicitada) {
|
||||
$status.addClass("label-danger").text("Maior que solicitada");
|
||||
return;
|
||||
}
|
||||
|
||||
if (qtdAprovada === 0) {
|
||||
$status.addClass("label-warning").text("Sem estoque");
|
||||
return;
|
||||
}
|
||||
|
||||
if (qtdAprovada < qtdSolicitada) {
|
||||
$status.addClass("label-warning").text("Divergente");
|
||||
return;
|
||||
}
|
||||
|
||||
$status.addClass("label-success").text("Sem divergência");
|
||||
}
|
||||
|
||||
function validarQuantidadeAprovadaGestor() {
|
||||
var divergencias = 0;
|
||||
var itemContador = 0;
|
||||
|
||||
$(collectQuantidadeItemFields()).each(function () {
|
||||
var $qtdSolicitada = $(this);
|
||||
var $row = $qtdSolicitada.closest("tr");
|
||||
var linha = getIndiceCampoPaiFilho($qtdSolicitada);
|
||||
|
||||
var codigo = $.trim(String(getCampoItem("descricao", linha, $row).val() || ""));
|
||||
var descricao = $.trim(String(getCampoItem("codigoItem", linha, $row).val() || ""));
|
||||
var qtdSolicitadaRaw = $.trim(String($qtdSolicitada.val() || ""));
|
||||
|
||||
if (qtdSolicitadaRaw === "" && !codigo && !descricao) {
|
||||
return;
|
||||
}
|
||||
|
||||
itemContador++;
|
||||
|
||||
var $qtdAprovada = getCampoItem("quantidadeAprovadaGestor", linha, $row);
|
||||
if (!$qtdAprovada.length) return;
|
||||
|
||||
var qtdSolicitada = toNumberQuantidade(qtdSolicitadaRaw);
|
||||
if (isNaN(qtdSolicitada) || qtdSolicitada <= 0) {
|
||||
$qtdSolicitada.closest("td, div").addClass("errorValidate");
|
||||
throw "Quantidade solicitada inválida no item " + itemContador + ".";
|
||||
}
|
||||
|
||||
var qtdAprovadaRaw = $.trim(String($qtdAprovada.val() || ""));
|
||||
if (qtdAprovadaRaw === "") {
|
||||
$qtdAprovada.val(normalizeQuantidadeCampo($qtdSolicitada.val()));
|
||||
qtdAprovadaRaw = $.trim(String($qtdAprovada.val() || ""));
|
||||
}
|
||||
|
||||
var qtdAprovada = toNumberQuantidade(qtdAprovadaRaw);
|
||||
if (isNaN(qtdAprovada) || qtdAprovada < 0) {
|
||||
$qtdAprovada.closest("td, div").addClass("errorValidate");
|
||||
throw "Preencha a quantidade aprovada do item " + itemContador + " com valor maior ou igual a zero.";
|
||||
}
|
||||
|
||||
if (qtdAprovada > qtdSolicitada) {
|
||||
$qtdAprovada.closest("td, div").addClass("errorValidate");
|
||||
throw "A quantidade aprovada do item " + itemContador + " não pode ser maior que a solicitada.";
|
||||
}
|
||||
|
||||
if (qtdAprovada !== qtdSolicitada) {
|
||||
divergencias++;
|
||||
}
|
||||
});
|
||||
|
||||
$("#qtdDivergenciasGestor").val(String(divergencias));
|
||||
|
||||
if (divergencias > 0 && $.trim($("#justificativaDecisaoGestor").val()) === "") {
|
||||
$("#justificativaDecisaoGestor").parent("div").addClass("errorValidate");
|
||||
throw "Informe a justificativa da decisão quando houver divergência de quantidade.";
|
||||
}
|
||||
}
|
||||
|
||||
function initMotoristaEntregaEscolha() {
|
||||
var escolha = String($("input[name='tipoMotoristaEntrega']:checked").val() || "");
|
||||
if (!escolha) {
|
||||
@@ -607,6 +968,10 @@ function updateConferenciaNfeVisibility(activity) {
|
||||
}
|
||||
|
||||
var ATTACHMENT_PLUGIN_CONFIG = {
|
||||
fnAnexo_PlanilhaItens: {
|
||||
filename: EXCEL_ATTACHMENT_DESCRIPTION,
|
||||
accept: ".xlsx,.xls"
|
||||
},
|
||||
fnAnexo_Nfe: {
|
||||
filename: "Nota Fiscal",
|
||||
accept: ".pdf,.xml,image/*"
|
||||
@@ -666,6 +1031,10 @@ function initAttachmentPlugins() {
|
||||
}
|
||||
|
||||
function resolveAttachmentFilename(inputId, fallback) {
|
||||
if (inputId === EXCEL_ATTACHMENT_INPUT_ID) {
|
||||
var numProcExcel = String($("#WKNumProces").val() || "").trim();
|
||||
return numProcExcel ? (EXCEL_ATTACHMENT_DESCRIPTION + " - " + numProcExcel) : EXCEL_ATTACHMENT_DESCRIPTION;
|
||||
}
|
||||
if (inputId !== "fnAnexo_Nfe") return fallback;
|
||||
var solicitacao = String($("#WKNumProces").val() || "").trim();
|
||||
if (!solicitacao) return "Nota Fiscal";
|
||||
@@ -785,7 +1154,7 @@ function processarConferenciaNfe() {
|
||||
if (req.qty === 0 && nfe.qty > 0) {
|
||||
status = "Somente NFe";
|
||||
} else if (nfe.qty === 0 && req.qty > 0) {
|
||||
status = "Somente solicitacao";
|
||||
status = "Somente base";
|
||||
} else if (Math.abs(req.qty - nfe.qty) > 0.00001) {
|
||||
status = "Quantidade divergente";
|
||||
}
|
||||
@@ -821,20 +1190,21 @@ function parseItensNfeJson() {
|
||||
|
||||
function buildSolicitacaoMap() {
|
||||
var out = {};
|
||||
$("input[name^='quantidadeItem___']").each(function () {
|
||||
var name = $(this).attr("name") || "";
|
||||
var indice = name.split("___")[1];
|
||||
if (!indice) return;
|
||||
$(collectQuantidadeItemFields()).each(function (i) {
|
||||
var $qtd = $(this);
|
||||
var $row = $qtd.closest("tr");
|
||||
var indice = getIndiceCampoPaiFilho($qtd);
|
||||
var rowKey = indice || ("BASE_" + (i + 1));
|
||||
|
||||
var qty = toFloatSafe($(this).val());
|
||||
var qty = getQuantidadeBaseConferencia($qtd, indice, $row);
|
||||
if (qty <= 0) return;
|
||||
|
||||
var productId = String($("#productIdItem___" + indice).val() || "").trim();
|
||||
var code = resolveSolicitacaoItemCode(indice, $(this));
|
||||
var descricao = String($("#codigoItem___" + indice).val() || "").trim();
|
||||
var productId = String(getCampoItem("productIdItem", indice, $row).val() || "").trim();
|
||||
var code = resolveSolicitacaoItemCode(indice, $qtd);
|
||||
var descricao = String(getCampoItem("codigoItem", indice, $row).val() || "").trim();
|
||||
|
||||
var key = resolveConferenciaKey(productId, code, "ROW:" + indice);
|
||||
var label = productId ? ("PID " + productId) : (code || descricao || ("Linha " + indice));
|
||||
var key = resolveConferenciaKey(productId, code, "ROW:" + rowKey);
|
||||
var label = productId ? ("PID " + productId) : (code || descricao || ("Linha " + rowKey));
|
||||
|
||||
if (!out[key]) {
|
||||
out[key] = { qty: 0, label: label };
|
||||
@@ -844,6 +1214,21 @@ function buildSolicitacaoMap() {
|
||||
return out;
|
||||
}
|
||||
|
||||
function getQuantidadeBaseConferencia($qtdSolicitada, indice, $row) {
|
||||
var qtdSolicitada = toFloatSafe($qtdSolicitada.val());
|
||||
var $qtdAprovada = getCampoItem("quantidadeAprovadaGestor", indice, $row);
|
||||
|
||||
if ($qtdAprovada.length) {
|
||||
var qtdAprovadaRaw = String($qtdAprovada.val() == null ? "" : $qtdAprovada.val()).trim();
|
||||
// Regra: se o gestor preencheu, a conferencia da NFe usa a quantidade aprovada (inclusive 0).
|
||||
if (qtdAprovadaRaw !== "") {
|
||||
return toFloatSafe(qtdAprovadaRaw);
|
||||
}
|
||||
}
|
||||
|
||||
return qtdSolicitada;
|
||||
}
|
||||
|
||||
function resolveSolicitacaoItemCode(indice, qtyInput) {
|
||||
var code = String($("#codigoProdutoItem___" + indice).val() || "").trim();
|
||||
if (code) return normalizeCodigoComparacao(code);
|
||||
@@ -975,7 +1360,7 @@ function renderTabelaConferencia(rows, totalItens, divergencias, mensagem, tipo)
|
||||
var itemNfe = row.key;
|
||||
var qtdNfe = formatConferenciaNumero(row.nfeQty);
|
||||
|
||||
if (row.status === "Somente solicitacao") {
|
||||
if (row.status === "Somente base") {
|
||||
itemNfe = "-";
|
||||
qtdNfe = "0";
|
||||
} else if (row.status === "Somente NFe") {
|
||||
@@ -1018,7 +1403,7 @@ function montarResumoDivergenciasConferencia(limit) {
|
||||
var itemNfe = String($(cols[2]).text() || "").trim();
|
||||
var qtdNfe = String($(cols[3]).text() || "").trim();
|
||||
|
||||
linhas.push("Item solicitado: " + itemSolicitado + " / Quantidade: " + qtdSolicitada + " | Item emitido na nota: " + itemNfe + " / Quantidade: " + qtdNfe);
|
||||
linhas.push("Item base: " + itemSolicitado + " / Quantidade: " + qtdSolicitada + " | Item emitido na nota: " + itemNfe + " / Quantidade: " + qtdNfe);
|
||||
});
|
||||
|
||||
if (!linhas.length) return "";
|
||||
@@ -1138,35 +1523,52 @@ var beforeSendValidate = function (numState, nextState) {
|
||||
} else if ($("#justificativa").val() == "") {
|
||||
$("#justificativa").parent("div").addClass("errorValidate");
|
||||
throw "'Qual o motivo da transferência?' é obrigatório.";
|
||||
} else if (String($("#analistasup").val() || "").trim() == "") {
|
||||
$("#analistasup").parent("div").addClass("errorValidate");
|
||||
throw "'Analista solicitante' é obrigatório.";
|
||||
} else {
|
||||
$("input[id^='quantidadeItem___']").each(function (index, value) {
|
||||
var linha = $(value).attr("name").split("___")[1];
|
||||
$(collectQuantidadeItemFields()).each(function () {
|
||||
var $qtd = $(this);
|
||||
var $row = $qtd.closest("tr");
|
||||
var linha = getIndiceCampoPaiFilho($qtd);
|
||||
if (!linha) return;
|
||||
|
||||
if (
|
||||
$("#descricao___" + linha).val() == "" &&
|
||||
$("#quantidadeItem___" + linha).val() == ""
|
||||
) {
|
||||
remove_row(value);
|
||||
var $descricao = getCampoItem("descricao", linha, $row);
|
||||
var descricaoValor = $.trim(String($descricao.val() || ""));
|
||||
var qtdValor = $.trim(String($qtd.val() || ""));
|
||||
if (!descricaoValor && !qtdValor) {
|
||||
var $btnRemove = $row.find("button[onclick*='remove_row']");
|
||||
if ($btnRemove.length) {
|
||||
remove_row($btnRemove.get(0));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$("input[id^='quantidadeItem___']").each(function (index, value) {
|
||||
var linha = $(value).attr("name").split("___")[1];
|
||||
var itensInformados = 0;
|
||||
$(collectQuantidadeItemFields()).each(function () {
|
||||
var $qtd = $(this);
|
||||
var $row = $qtd.closest("tr");
|
||||
var linha = getIndiceCampoPaiFilho($qtd);
|
||||
var $descricao = getCampoItem("descricao", linha, $row);
|
||||
|
||||
if ($("#descricao___" + linha).val() == "") {
|
||||
$("#descricao___" + linha)
|
||||
.parent("div")
|
||||
.addClass("errorValidate");
|
||||
throw "Selecione o item " + (index + 1) + ".";
|
||||
} else if ($("#quantidadeItem___" + linha).val() == "") {
|
||||
$("#quantidadeItem___" + linha)
|
||||
.parent("div")
|
||||
.addClass("errorValidate");
|
||||
throw "Preencha a quantidade do item " + (index + 1) + ".";
|
||||
var descricaoValor = $.trim(String($descricao.val() || ""));
|
||||
var qtdValor = $.trim(String($qtd.val() || ""));
|
||||
if (!descricaoValor && !qtdValor) return;
|
||||
|
||||
itensInformados++;
|
||||
|
||||
if (!descricaoValor) {
|
||||
$descricao.parent("div").addClass("errorValidate");
|
||||
throw "Selecione o item " + itensInformados + ".";
|
||||
}
|
||||
|
||||
if (!qtdValor) {
|
||||
$qtd.parent("div").addClass("errorValidate");
|
||||
throw "Preencha a quantidade do item " + itensInformados + ".";
|
||||
}
|
||||
});
|
||||
|
||||
if ($("input[name^='quantidadeItem___']").length == 0) {
|
||||
if (itensInformados === 0) {
|
||||
throw "Ao menos um item é necessário para iniciar a solicitação.";
|
||||
}
|
||||
}
|
||||
@@ -1176,6 +1578,8 @@ var beforeSendValidate = function (numState, nextState) {
|
||||
$("#justificativaDecisaoGestor").parent("div").addClass("errorValidate");
|
||||
throw "'Justificativa da decisão' é obrigatória para reprovar.";
|
||||
}
|
||||
} else {
|
||||
validarQuantidadeAprovadaGestor();
|
||||
}
|
||||
} else if (numState == 6) {
|
||||
var chaveNfe = normalizeNfeKey($("#chaveNfe").val());
|
||||
@@ -1199,7 +1603,7 @@ var beforeSendValidate = function (numState, nextState) {
|
||||
var qtdDivergencias = parseInt($("#qtdDivergenciasNfe").val() || "0", 10);
|
||||
if (!isNaN(qtdDivergencias) && qtdDivergencias > 0) {
|
||||
var produtos = listarProdutosDivergentes(10);
|
||||
var msg = "A nota tem produtos divergentes da solicitacao.";
|
||||
var msg = "A nota tem produtos divergentes da base aprovada para emissão.";
|
||||
if (produtos) {
|
||||
msg += " Produtos: " + produtos + ".";
|
||||
}
|
||||
@@ -1247,6 +1651,7 @@ var beforeSendValidate = function (numState, nextState) {
|
||||
throw "'Data da entrega' é obrigatória.";
|
||||
}
|
||||
if (String($("#nomerecebedor").val() || "").trim() == "") {
|
||||
$("#nomerecebedor").parent("div").addClass("errorValidate");
|
||||
throw "'Nome de quem recebeu a mercadoria' é obrigatório.";
|
||||
}
|
||||
} else if (numState == 18) {
|
||||
@@ -1354,6 +1759,7 @@ function setSelectedZoomItem(selectedItem) {
|
||||
$("#productIdItem" + "___" + indice).val(itemProductId);
|
||||
$("#categoriaItem" + "___" + indice).val(itemCategoria);
|
||||
processarConferenciaNfe();
|
||||
toggleQuantidadeAprovadaGestorByActivity($("#activity").val());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1395,7 +1801,9 @@ function removedZoomItem(removedItem) {
|
||||
$("#productIdItem___" + linha[1]).val("");
|
||||
$("#categoriaItem___" + linha[1]).val("");
|
||||
$("#quantidadeItem___" + linha[1]).val("");
|
||||
$("#quantidadeAprovadaGestor___" + linha[1]).val("");
|
||||
processarConferenciaNfe();
|
||||
toggleQuantidadeAprovadaGestorByActivity($("#activity").val());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1404,13 +1812,17 @@ function removedZoomItem(removedItem) {
|
||||
$("#codigoProdutoItem" + "___" + indice).val("");
|
||||
$("#productIdItem" + "___" + indice).val("");
|
||||
$("#categoriaItem" + "___" + indice).val("");
|
||||
$("#quantidadeAprovadaGestor" + "___" + indice).val("");
|
||||
processarConferenciaNfe();
|
||||
toggleQuantidadeAprovadaGestorByActivity($("#activity").val());
|
||||
}
|
||||
}
|
||||
|
||||
function add_new_row(table) {
|
||||
var row = wdkAddChild(table);
|
||||
updt_line();
|
||||
toggleQuantidadeAprovadaGestorByActivity($("#activity").val());
|
||||
syncQuantidadeAprovadaAllRows();
|
||||
}
|
||||
|
||||
function updt_line() {
|
||||
@@ -1424,6 +1836,7 @@ function remove_row(element) {
|
||||
fnWdkRemoveChild(element);
|
||||
updt_line();
|
||||
processarConferenciaNfe();
|
||||
toggleQuantidadeAprovadaGestorByActivity($("#activity").val());
|
||||
}
|
||||
|
||||
|
||||
@@ -1820,6 +2233,10 @@ function getAllowedAttachmentInputs() {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (activity === "0" || activity === "1") {
|
||||
return ["fnAnexo_PlanilhaItens"];
|
||||
}
|
||||
|
||||
if (activity === "6") {
|
||||
return ["fnAnexo_Nfe"];
|
||||
}
|
||||
@@ -1958,18 +2375,22 @@ function hasFileFluig(fileDescription){
|
||||
//Quando o Fluig finalizar o upload e o anexo for escolhido
|
||||
window.parent.$("#ecm-navigation-inputFile-clone").on('change', function () {
|
||||
|
||||
const fileDescription = this.getAttribute("data-file-name-camera");
|
||||
const fileDescription = String(this.getAttribute("data-file-name-camera") || "");
|
||||
const file = this.files[0];
|
||||
if (!file) return;
|
||||
|
||||
if (fileDescription === "Planilha de Itens Excel") {
|
||||
if (fileDescription === EXCEL_ATTACHMENT_DESCRIPTION || fileDescription.indexOf(EXCEL_ATTACHMENT_DESCRIPTION + " - ") === 0) {
|
||||
|
||||
// Copia o arquivo para o input técnico
|
||||
const dt = new DataTransfer();
|
||||
dt.items.add(file);
|
||||
document.getElementById("excelUpload").files = dt.files;
|
||||
var excelInput = document.getElementById("excelUpload");
|
||||
if (!excelInput) return;
|
||||
excelInput.files = dt.files;
|
||||
|
||||
// Atualiza nome mostrado
|
||||
$("#nomeArquivoExcel").text("Arquivo selecionado: " + file.name);
|
||||
updateExcelImportUi(file.name);
|
||||
getExcelAttachmentField().val(file.name);
|
||||
|
||||
// Agora sim o arquivo está dentro do input e pode ser lido
|
||||
carregarItensDoExcel("excelUpload");
|
||||
@@ -1978,5 +2399,9 @@ window.parent.$("#ecm-navigation-inputFile-clone").on('change', function () {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function getChaveNfeLimpa() {
|
||||
return (document.getElementById("chaveNfe").value || "")
|
||||
.replace(/\s+/g, "") // tira espaços
|
||||
.replace(/\D/g, "") // garante só dígitos
|
||||
.slice(0, 44); // limite oficial
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user