att
This commit is contained in:
@@ -72,6 +72,10 @@ $(document).ready(function () {
|
||||
applyMotoristaEntregaMode($(this).val(), false);
|
||||
});
|
||||
|
||||
$(document).on("change", "input[name='tipoEntregaAprovacao']", function () {
|
||||
applyTipoEntregaAprovacao($(this).val(), true);
|
||||
});
|
||||
|
||||
$(document).on("change", "#motoristaEntregaSelecionado", function () {
|
||||
applySelectedMotoristaEntregaOption();
|
||||
});
|
||||
@@ -100,6 +104,26 @@ $(document).ready(function () {
|
||||
atualizarStatusLinhaAprovacaoGestor(linha);
|
||||
});
|
||||
|
||||
$(document).on("input", ".input-codigo-nfe-gestor-view", function () {
|
||||
var linha = String($(this).attr("data-linha") || "");
|
||||
var indice = String($(this).attr("data-indice") || "");
|
||||
if (!linha && !indice) return;
|
||||
|
||||
var normalizedCode = normalizeCodigoComparacao($(this).val());
|
||||
$(this).val(normalizedCode);
|
||||
|
||||
var $row = $("#tabelaAprovacaoGestorItensBody tr[data-linha='" + linha + "']");
|
||||
var $hiddenCode = getCampoItem("codigoProdutoNfeItem", indice, $row);
|
||||
if (!$hiddenCode.length) {
|
||||
$hiddenCode = getCampoItem("codigoProdutoNfeItem", indice);
|
||||
}
|
||||
if ($hiddenCode.length) {
|
||||
$hiddenCode.val(normalizedCode);
|
||||
}
|
||||
|
||||
processarConferenciaNfe();
|
||||
});
|
||||
|
||||
var activity = String($("#activity").val() || "");
|
||||
applyTransferStatus(activity);
|
||||
|
||||
@@ -130,6 +154,7 @@ $(document).ready(function () {
|
||||
$("#dataValidacaoGestor").val(
|
||||
requestDate[0] + " - " + requestDate[1]
|
||||
);
|
||||
initTipoEntregaAprovacao(true);
|
||||
updt_line();
|
||||
} else if (activity == 6) {
|
||||
showAndBlock([0, 4]);
|
||||
@@ -245,6 +270,7 @@ $(document).ready(function () {
|
||||
updateConferenciaNfeVisibility(activity);
|
||||
}
|
||||
|
||||
initTipoEntregaAprovacao(String(activity) === "4");
|
||||
syncQuantidadeAprovadaAllRows();
|
||||
toggleQuantidadeAprovadaGestorByActivity(activity);
|
||||
agendarRefreshTabelaAprovacao(activity);
|
||||
@@ -529,6 +555,8 @@ function toggleQuantidadeAprovadaGestorByActivity(activity) {
|
||||
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 codigoProdutoOriginal = normalizeCodigoComparacao(getCampoItem("codigoProdutoItem", linha, $row).val());
|
||||
var codigoProdutoNfeDigitado = normalizeCodigoComparacao(getCampoItem("codigoProdutoNfeItem", linha, $row).val());
|
||||
var qtdSolicitadaNorm = normalizeQuantidadeCampo($qtdSolicitadaField.val());
|
||||
|
||||
var hasData = qtdSolicitadaNorm !== "" || codigo !== "" || descricao !== "" || categoria !== "";
|
||||
@@ -541,6 +569,13 @@ function toggleQuantidadeAprovadaGestorByActivity(activity) {
|
||||
if (descricao && descricao !== codigo) itemLabel += " - " + descricao;
|
||||
if (categoria) itemLabel += " (" + categoria + ")";
|
||||
|
||||
if (!codigoProdutoOriginal && codigo) {
|
||||
codigoProdutoOriginal = normalizeCodigoComparacao(codigo);
|
||||
}
|
||||
var codigoNfePlaceholder = codigoProdutoOriginal
|
||||
? ("Ex.: " + codigoProdutoOriginal)
|
||||
: "Informe o código da NFe";
|
||||
|
||||
var $hiddenAprovada = getCampoItem("quantidadeAprovadaGestor", linha, $row);
|
||||
var qtdAprovadaAtual = normalizeQuantidadeCampo($hiddenAprovada.val());
|
||||
if (qtdAprovadaAtual === "" && qtdSolicitadaNorm !== "") {
|
||||
@@ -585,13 +620,20 @@ function toggleQuantidadeAprovadaGestorByActivity(activity) {
|
||||
" id='quantidadeAprovadaGestorView___" + escapeHtml(linhaKey) + "' " +
|
||||
" value='" + escapeHtml(qtdAprovadaAtual) + "' placeholder='Se diferente' />" +
|
||||
"</td>" +
|
||||
"<td>" +
|
||||
"<input type='text' " + disabledAttr +
|
||||
" class='form-control transfer-input input-codigo-nfe-gestor-view' " +
|
||||
" data-linha='" + escapeHtml(linhaKey) + "' data-indice='" + escapeHtml(linha) + "' " +
|
||||
" id='codigoProdutoNfeItemView___" + escapeHtml(linhaKey) + "' " +
|
||||
" value='" + escapeHtml(codigoProdutoNfeDigitado) + "' placeholder='" + escapeHtml(codigoNfePlaceholder) + "' />" +
|
||||
"</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>");
|
||||
html.push("<tr><td colspan='6'>Sem itens para validação.</td></tr>");
|
||||
}
|
||||
|
||||
$tbody.html(html.join(""));
|
||||
@@ -692,6 +734,78 @@ function validarQuantidadeAprovadaGestor() {
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeLoginAtribuicao(value) {
|
||||
return String(value == null ? "" : value).trim();
|
||||
}
|
||||
|
||||
function initTipoEntregaAprovacao(useCurrentUserForEu) {
|
||||
var escolha = String($("input[name='tipoEntregaAprovacao']:checked").val() || "").trim();
|
||||
var loginSalvo = String($("#loginEntregaAprovacao").val() || "").trim();
|
||||
|
||||
if (!escolha) {
|
||||
escolha = loginSalvo ? "eu" : "motorista";
|
||||
$("input[name='tipoEntregaAprovacao'][value='" + escolha + "']").prop("checked", true);
|
||||
}
|
||||
|
||||
applyTipoEntregaAprovacao(escolha, useCurrentUserForEu === true);
|
||||
}
|
||||
|
||||
function applyTipoEntregaAprovacao(mode, useCurrentUserForEu) {
|
||||
var escolha = String(mode || "").trim();
|
||||
var usarUsuarioAtual = useCurrentUserForEu === true;
|
||||
|
||||
if (escolha === "eu") {
|
||||
var login = usarUsuarioAtual
|
||||
? String($("#currentUserId").val() || "").trim()
|
||||
: String($("#loginEntregaAprovacao").val() || "").trim();
|
||||
var nome = usarUsuarioAtual
|
||||
? String($("#currentUserName").val() || "").trim()
|
||||
: String($("#nomeAtribuicaoEntregaAprovacao").val() || "").trim();
|
||||
|
||||
if (!login) {
|
||||
login = String($("#loginEntregaAprovacao").val() || "").trim();
|
||||
}
|
||||
if (!nome) {
|
||||
nome = String($("#nomeAtribuicaoEntregaAprovacao").val() || "").trim();
|
||||
}
|
||||
|
||||
login = normalizeLoginAtribuicao(login);
|
||||
$("#loginEntregaAprovacao").val(login);
|
||||
$("#loginEntregaAprovacaoView").val(login);
|
||||
$("#nomeAtribuicaoEntregaAprovacao").val(nome);
|
||||
return;
|
||||
}
|
||||
|
||||
$("#loginEntregaAprovacao").val("");
|
||||
$("#loginEntregaAprovacaoView").val("");
|
||||
$("#nomeAtribuicaoEntregaAprovacao").val("");
|
||||
}
|
||||
|
||||
function validarEscolhaEntregaAprovacao(nextState) {
|
||||
if (String(nextState) === "39") return;
|
||||
|
||||
var escolha = String($("input[name='tipoEntregaAprovacao']:checked").val() || "").trim();
|
||||
if (!escolha) {
|
||||
$("#blocoTipoEntregaAprovacao").addClass("errorValidate");
|
||||
throw "Informe quem vai fazer a entrega na aprovação (Eu ou Motorista).";
|
||||
}
|
||||
|
||||
applyTipoEntregaAprovacao(escolha, true);
|
||||
if (escolha === "eu") {
|
||||
var loginAtribuicao = normalizeLoginAtribuicao($("#loginEntregaAprovacao").val());
|
||||
$("#loginEntregaAprovacao").val(loginAtribuicao);
|
||||
$("#loginEntregaAprovacaoView").val(loginAtribuicao);
|
||||
if (!loginAtribuicao) {
|
||||
$("#blocoLoginEntregaAprovacao").addClass("errorValidate");
|
||||
throw "Nao foi possivel definir o login para atribuicao da entrega.";
|
||||
}
|
||||
if (loginAtribuicao.length > 30) {
|
||||
$("#blocoLoginEntregaAprovacao").addClass("errorValidate");
|
||||
throw "O campo 'loginEntregaAprovacao' permite no maximo 30 caracteres.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initMotoristaEntregaEscolha() {
|
||||
var escolha = String($("input[name='tipoMotoristaEntrega']:checked").val() || "");
|
||||
if (!escolha) {
|
||||
@@ -1200,11 +1314,14 @@ function buildSolicitacaoMap() {
|
||||
if (qty <= 0) return;
|
||||
|
||||
var productId = String(getCampoItem("productIdItem", indice, $row).val() || "").trim();
|
||||
var code = resolveSolicitacaoItemCode(indice, $qtd);
|
||||
var codigoNfeDigitado = resolveCodigoNfeDigitado(indice, $row);
|
||||
var code = codigoNfeDigitado || resolveSolicitacaoItemCode(indice, $qtd);
|
||||
var descricao = String(getCampoItem("codigoItem", indice, $row).val() || "").trim();
|
||||
|
||||
var key = resolveConferenciaKey(productId, code, "ROW:" + rowKey);
|
||||
var label = productId ? ("PID " + productId) : (code || descricao || ("Linha " + rowKey));
|
||||
var key = codigoNfeDigitado
|
||||
? resolveConferenciaKey("", code, "ROW:" + rowKey)
|
||||
: resolveConferenciaKey(productId, code, "ROW:" + rowKey);
|
||||
var label = codigoNfeDigitado || (productId ? ("PID " + productId) : (code || descricao || ("Linha " + rowKey)));
|
||||
|
||||
if (!out[key]) {
|
||||
out[key] = { qty: 0, label: label };
|
||||
@@ -1229,6 +1346,12 @@ function getQuantidadeBaseConferencia($qtdSolicitada, indice, $row) {
|
||||
return qtdSolicitada;
|
||||
}
|
||||
|
||||
function resolveCodigoNfeDigitado(indice, $scopeRow) {
|
||||
var code = String(getCampoItem("codigoProdutoNfeItem", indice, $scopeRow).val() || "").trim();
|
||||
if (!code) return "";
|
||||
return normalizeCodigoComparacao(code);
|
||||
}
|
||||
|
||||
function resolveSolicitacaoItemCode(indice, qtyInput) {
|
||||
var code = String($("#codigoProdutoItem___" + indice).val() || "").trim();
|
||||
if (code) return normalizeCodigoComparacao(code);
|
||||
@@ -1579,6 +1702,7 @@ var beforeSendValidate = function (numState, nextState) {
|
||||
throw "'Justificativa da decisão' é obrigatória para reprovar.";
|
||||
}
|
||||
} else {
|
||||
validarEscolhaEntregaAprovacao(nextState);
|
||||
validarQuantidadeAprovadaGestor();
|
||||
}
|
||||
} else if (numState == 6) {
|
||||
@@ -1746,6 +1870,7 @@ function setSelectedZoomItem(selectedItem) {
|
||||
var itemCategoria = selectedItem["categoria"] || selectedItem["strategicDescription"] || "";
|
||||
$("#codigoItem" + "___" + indice).val(itemDescricao);
|
||||
$("#codigoProdutoItem" + "___" + indice).val(itemCode);
|
||||
$("#codigoProdutoNfeItem" + "___" + indice).val("");
|
||||
$("#productIdItem" + "___" + indice).val(itemProductId);
|
||||
$("#categoriaItem" + "___" + indice).val(itemCategoria);
|
||||
processarConferenciaNfe();
|
||||
@@ -1788,6 +1913,7 @@ function removedZoomItem(removedItem) {
|
||||
if (linha[0] == "descricao") {
|
||||
$("#codigoItem___" + linha[1]).val("");
|
||||
$("#codigoProdutoItem___" + linha[1]).val("");
|
||||
$("#codigoProdutoNfeItem___" + linha[1]).val("");
|
||||
$("#productIdItem___" + linha[1]).val("");
|
||||
$("#categoriaItem___" + linha[1]).val("");
|
||||
$("#quantidadeItem___" + linha[1]).val("");
|
||||
@@ -1800,6 +1926,7 @@ function removedZoomItem(removedItem) {
|
||||
if (name_item == "descricao") {
|
||||
$("#codigoItem" + "___" + indice).val("");
|
||||
$("#codigoProdutoItem" + "___" + indice).val("");
|
||||
$("#codigoProdutoNfeItem" + "___" + indice).val("");
|
||||
$("#productIdItem" + "___" + indice).val("");
|
||||
$("#categoriaItem" + "___" + indice).val("");
|
||||
$("#quantidadeAprovadaGestor" + "___" + indice).val("");
|
||||
|
||||
Reference in New Issue
Block a user