This commit is contained in:
Andrey Cunha
2026-03-20 23:32:59 -03:00
parent 60a17ce6d9
commit 5f7c2f99d1
25 changed files with 2971 additions and 2504 deletions
@@ -503,6 +503,13 @@ function updateConferenciaNfeVisibility(activity) {
var activityValue = String(activity || $("#activity").val() || "");
var exibirConferencia = (activityValue === "6" || activityValue === "18");
$("#blocoConferenciaNfe").toggle(exibirConferencia);
// Na emissao (6), mostra apenas a tabela de conferencia.
// Os campos de validacao de recebimento ficam apenas na atividade 18.
var showOnlyConferencia = (activityValue === "6");
$("input[name='validacaoItens']").closest(".row").toggle(!showOnlyConferencia);
$("#fdAnexo_recebimento").closest(".row").toggle(!showOnlyConferencia);
$(".justificativaDecisaoItens").toggle(!showOnlyConferencia);
}
var ATTACHMENT_PLUGIN_CONFIG = {
@@ -538,18 +545,19 @@ function initAttachmentPlugins() {
var cfg = ATTACHMENT_PLUGIN_CONFIG[inputId];
var input = $("#" + inputId);
if (!input.length) return;
var dynamicFilename = resolveAttachmentFilename(inputId, cfg.filename);
var canUploadHere = (mode !== "VIEW" && allowedInputs.indexOf(inputId) >= 0);
try {
if (!input.data("fluigFormAttachment")) {
input.fluigFormAttachment({
filename: cfg.filename,
filename: dynamicFilename,
accept: cfg.accept,
showActionButton: canUploadHere
});
} else {
input.fluigFormAttachment("filename", cfg.filename);
input.fluigFormAttachment("filename", dynamicFilename);
}
if (canUploadHere) {
@@ -563,6 +571,13 @@ function initAttachmentPlugins() {
});
}
function resolveAttachmentFilename(inputId, fallback) {
if (inputId !== "fnAnexo_Nfe") return fallback;
var solicitacao = String($("#WKNumProces").val() || "").trim();
if (!solicitacao) return "Nota Fiscal";
return "Nota Fiscal - " + solicitacao;
}
function normalizeNfeKey(value) {
return String(value == null ? "" : value).replace(/\D/g, "").substring(0, 44);
}
@@ -856,15 +871,29 @@ function renderTabelaConferencia(rows, totalItens, divergencias, mensagem, tipo)
var html = "";
if (!rows || rows.length === 0) {
html = "<tr><td colspan='4'>Sem conferencia.</td></tr>";
html = "<tr><td colspan='5'>Sem conferencia.</td></tr>";
} else {
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var rowClass = row.status === "OK" ? "" : " class='danger'";
var itemSolicitado = row.key;
var qtdSolicitada = formatConferenciaNumero(row.requestedQty);
var itemNfe = row.key;
var qtdNfe = formatConferenciaNumero(row.nfeQty);
if (row.status === "Somente solicitacao") {
itemNfe = "-";
qtdNfe = "0";
} else if (row.status === "Somente NFe") {
itemSolicitado = "-";
qtdSolicitada = "0";
}
html += "<tr" + rowClass + ">" +
"<td>" + escapeHtml(row.key) + "</td>" +
"<td>" + formatConferenciaNumero(row.requestedQty) + "</td>" +
"<td>" + formatConferenciaNumero(row.nfeQty) + "</td>" +
"<td>" + escapeHtml(itemSolicitado) + "</td>" +
"<td>" + escapeHtml(qtdSolicitada) + "</td>" +
"<td>" + escapeHtml(itemNfe) + "</td>" +
"<td>" + escapeHtml(qtdNfe) + "</td>" +
"<td>" + escapeHtml(row.status) + "</td>" +
"</tr>";
}
@@ -881,6 +910,64 @@ function renderTabelaConferencia(rows, totalItens, divergencias, mensagem, tipo)
resumo.text(mensagem || ("Conferencia: " + totalItens + " item(ns), " + divergencias + " divergencia(s)."));
}
function montarResumoDivergenciasConferencia(limit) {
var max = parseInt(limit, 10);
if (isNaN(max) || max <= 0) max = 5;
var linhas = [];
$("#tabelaConferenciaNfeBody tr.danger").each(function () {
var cols = $(this).find("td");
if (!cols || cols.length < 5) return;
var itemSolicitado = String($(cols[0]).text() || "").trim();
var qtdSolicitada = String($(cols[1]).text() || "").trim();
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);
});
if (!linhas.length) return "";
if (linhas.length > max) {
var restantes = linhas.length - max;
return linhas.slice(0, max).join("; ") + "; ... +" + restantes + " item(ns)";
}
return linhas.join("; ");
}
function listarProdutosDivergentes(limit) {
var max = parseInt(limit, 10);
if (isNaN(max) || max <= 0) max = 10;
var items = [];
var seen = {};
$("#tabelaConferenciaNfeBody tr.danger").each(function () {
var cols = $(this).find("td");
if (!cols || cols.length < 5) return;
var itemSolicitado = String($(cols[0]).text() || "").trim();
var itemNfe = String($(cols[2]).text() || "").trim();
if (itemSolicitado && itemSolicitado !== "-" && !seen[itemSolicitado]) {
seen[itemSolicitado] = true;
items.push(itemSolicitado);
}
if (itemNfe && itemNfe !== "-" && !seen[itemNfe]) {
seen[itemNfe] = true;
items.push(itemNfe);
}
});
if (!items.length) return "";
if (items.length > max) {
return items.slice(0, max).join(", ") + " ... +" + (items.length - max);
}
return items.join(", ");
}
function toFloatSafe(value) {
var text = String(value == null ? "" : value).replace(",", ".").trim();
var n = parseFloat(text);
@@ -990,7 +1077,12 @@ var beforeSendValidate = function (numState, nextState) {
}
}
} else if (numState == 4) {
//
if (String(nextState) == "39") {
if ($("#justificativaDecisaoGestor").val() == "") {
$("#justificativaDecisaoGestor").parent("div").addClass("errorValidate");
throw "'Justificativa da decisão' é obrigatória para reprovar.";
}
}
} else if (numState == 6) {
var chaveNfe = normalizeNfeKey($("#chaveNfe").val());
$("#chaveNfe").val(chaveNfe);
@@ -1012,7 +1104,12 @@ var beforeSendValidate = function (numState, nextState) {
var qtdDivergencias = parseInt($("#qtdDivergenciasNfe").val() || "0", 10);
if (!isNaN(qtdDivergencias) && qtdDivergencias > 0) {
throw "Existem " + qtdDivergencias + " divergencia(s) entre itens solicitados e itens da NFe.";
var produtos = listarProdutosDivergentes(10);
var msg = "A nota tem produtos divergentes da solicitacao.";
if (produtos) {
msg += " Produtos: " + produtos + ".";
}
throw msg;
}
} else if (numState == 31) {
if ($("#motoristaColetaNome").val() == "") {
@@ -1126,12 +1223,14 @@ function setSelectedZoomItem(selectedItem) {
$("#gestorNome").val(selectedItem["RESPONSAVEL_LOJA"] || "");
$("#gestorEmail").val(selectedItem["emailGestor"] || "");
$("#gestor_cc").val(selectedItem["COLLEAGUE_ID"] || "");
$("#ufDestino").val(selectedItem["UF"] || "");
}
if (name_item == "estabelecimento") {
$("#gestorNomeE").val(selectedItem["RESPONSAVEL_LOJA"] || "");
$("#gestorEmailE").val(selectedItem["emailGestor"] || "");
$("#gestor_cce").val(selectedItem["COLLEAGUE_ID"] || "");
$("#ufOrigem").val(selectedItem["UF"] || "");
}
if (name_item == "userSolicitante") {
@@ -1175,10 +1274,12 @@ function removedZoomItem(removedItem) {
$("#gestorNome").val("");
$("#gestorEmail").val("");
$("#gestor_cc").val("");
$("#ufDestino").val("");
} else if (name_item == "estabelecimento") {
$("#gestorNomeE").val("");
$("#gestorEmailE").val("");
$("#gestor_cce").val("");
$("#ufOrigem").val("");
} else if (name_item == "motoristaEntregaSelecionado") {
if ($("input[name='tipoMotoristaEntrega']:checked").val() === "outro") {
$("#motoristaEntregaNome").val("");
@@ -1705,15 +1806,18 @@ function invalidFilesTable(tablename, idInput){
*/
function invalidFile(idInput){
try {
const inputNameFile = $(`#${idInput}`).val()
const inputNameFile = String($(`#${idInput}`).val() || "").trim();
if(inputNameFile){
let fileDescription = "";
if($(`#_${idInput}`).length){
let fileDescription = $(`#_${idInput}`).parent().find(".descAnexo").val()
return !hasFileFluig(fileDescription)
fileDescription = String($(`#_${idInput}`).parent().find(".descAnexo").val() || "").trim();
} else{
let fileDescription = $(`#${idInput}`).parent().find(".descAnexo").val()
return !hasFileFluig(fileDescription)
fileDescription = String($(`#${idInput}`).parent().find(".descAnexo").val() || "").trim();
}
if (!fileDescription) {
fileDescription = inputNameFile;
}
return !hasFileFluig(fileDescription)
}else{
return false
}
@@ -1732,10 +1836,12 @@ function invalidFile(idInput){
*/
function hasFileFluig(fileDescription){
try {
var target = String(fileDescription || "").trim();
if (!target) return false;
const anexos = parent.ECM.attachmentTable.getData();
for(let i = 0; i < anexos.length; i++){
var descricao = anexos[i].description;
if (fileDescription == descricao) {
var descricao = String(anexos[i].description || "").trim();
if (target == descricao || descricao.indexOf(target + " - ") === 0) {
return true
}
}
@@ -1767,3 +1873,7 @@ window.parent.$("#ecm-navigation-inputFile-clone").on('change', function () {
}
});