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
@@ -10,6 +10,12 @@ function validateForm(form) {
log.info("Abertura de solcitação: " + atividade);
if (completTask.equals("true")) {
if (atividade == 4 && String(nextAtividade) == "39") {
if (String(form.getValue("justificativaDecisaoGestor") || "").trim() == "") {
message += getMessage("Justificativa da decisão", 1, form);
hasErros = true;
}
}
switch (atividade) {
case EMISSAO:
@@ -27,6 +33,10 @@ function validateForm(form) {
message += "Consulte a chave da NFe antes de enviar esta etapa.<br>";
hasErros = true;
}
if (form.getValue("fnAnexo_Nfe") == "") {
message += getMessage("Anexo da Nota Fiscal", 3, form);
hasErros = true;
}
var qtdDivergenciasNfe = parseInt(String(form.getValue("qtdDivergenciasNfe") || "0"), 10);
if (!isNaN(qtdDivergenciasNfe) && qtdDivergenciasNfe > 0) {
message += "Existem " + qtdDivergenciasNfe + " divergencia(s) entre a solicitacao e a NFe.<br>";
@@ -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 () {
}
});
@@ -252,6 +252,7 @@
'fields':[
{'field':'PDV','label':'Loja'},
{'field':'RESPONSAVEL_LOJA','label':'Gestor'},
{'field':'UF','label':'UF'},
{'field':'LOGIN_LOJA','label':'Login','visible':'false'},
{'field':'COLLEAGUE_ID','label':'Colleague','visible':'false'}
]
@@ -267,12 +268,23 @@
'fields':[
{'field':'PDV','label':'Loja'},
{'field':'RESPONSAVEL_LOJA','label':'Gestor'},
{'field':'UF','label':'UF'},
{'field':'LOGIN_LOJA','label':'Login','visible':'false'},
{'field':'COLLEAGUE_ID','label':'Colleague','visible':'false'}
]
}" />
</div>
</div>
<div class="row" style="margin-top:10px;">
<div class="col-md-2 col-sm-4">
<label class="transfer-label" for="ufOrigem">UF origem</label>
<input type="text" class="form-control transfer-input" name="ufOrigem" id="ufOrigem" readonly />
</div>
<div class="col-md-2 col-sm-4">
<label class="transfer-label" for="ufDestino">UF destino</label>
<input type="text" class="form-control transfer-input" name="ufDestino" id="ufDestino" readonly />
</div>
</div>
</section>
<section class="transfer-card activity activity-0 activity-1 activity-4 activity-6 activity-18 activity-24 activity-31 activity-57">
@@ -292,7 +304,7 @@
<input type="file" id="excelUpload" name="excelUpload" accept=".xlsx,.xls" style="display:none;" />
</div>
<table tablename="tabelaItens" class="table table-striped table-modern" id="tabelaItens" noaddbutton="true" nodeletebutton="true">
<thead>
<thead>
<tr>
<th style="width:70px;">#</th>
<th style="width:34%;">Código do item</th>
@@ -343,6 +355,26 @@
<textarea class="form-control transfer-input" rows="4" name="justificativa" id="justificativa" placeholder="Descreva o motivo da transferencia"></textarea>
</section>
<section class="transfer-card activity activity-4 activity-6 activity-18 activity-24 activity-31 activity-57 justificativa-activity-4">
<h2 class="card-title">Aprovação Filial Emitente</h2>
<div class="row">
<div class="col-md-6 col-sm-12">
<label class="transfer-label" for="userValidacaoGestor">Nome aprovação filial emitente</label>
<input type="text" class="form-control transfer-input" name="userValidacaoGestor" id="userValidacaoGestor" readonly />
</div>
<div class="col-md-6 col-sm-12">
<label class="transfer-label" for="dataValidacaoGestor">Data da aprovação</label>
<input type="text" class="form-control transfer-input" name="dataValidacaoGestor" id="dataValidacaoGestor" readonly />
</div>
</div>
<div class="row" style="margin-top:10px;">
<div class="col-md-12">
<label class="transfer-label" for="justificativaDecisaoGestor">Justificativa da decisão</label>
<textarea class="form-control transfer-input" rows="3" name="justificativaDecisaoGestor" id="justificativaDecisaoGestor" placeholder="Preencha a justificativa ao reprovar"></textarea>
</div>
</div>
</section>
<section class="transfer-card activity activity-6 activity-18 activity-31 activity-57">
<h2 class="card-title">Emissão da NFe</h2>
<div class="row">
@@ -379,11 +411,11 @@
</div>
<div class="row" style="margin-top:10px;">
<div class="col-md-3 col-sm-6">
<label class="transfer-label" for="numeroNfeConsulta">Numero da NFe</label>
<label class="transfer-label" for="numeroNfeConsulta">Número da NFe</label>
<input type="text" class="form-control transfer-input" name="numeroNfeConsulta" id="numeroNfeConsulta" readonly />
</div>
<div class="col-md-3 col-sm-6">
<label class="transfer-label" for="serieNfeConsulta">Serie</label>
<label class="transfer-label" for="serieNfeConsulta">Série</label>
<input type="text" class="form-control transfer-input" name="serieNfeConsulta" id="serieNfeConsulta" readonly />
</div>
<div class="col-md-3 col-sm-6">
@@ -391,7 +423,7 @@
<input type="text" class="form-control transfer-input" name="dataEmissaoApiNfe" id="dataEmissaoApiNfe" readonly />
</div>
<div class="col-md-3 col-sm-6">
<label class="transfer-label" for="situacaoNfeConsulta">Situacao</label>
<label class="transfer-label" for="situacaoNfeConsulta">Situação</label>
<input type="text" class="form-control transfer-input" name="situacaoNfeConsulta" id="situacaoNfeConsulta" readonly />
</div>
</div>
@@ -415,7 +447,7 @@
</div>
<div class="row" style="margin-top:10px;">
<div class="col-md-9 col-sm-12">
<label class="transfer-label" for="operacaoNfeConsulta">Operacao fiscal</label>
<label class="transfer-label" for="operacaoNfeConsulta">Operação fiscal</label>
<input type="text" class="form-control transfer-input" name="operacaoNfeConsulta" id="operacaoNfeConsulta" readonly />
</div>
<div class="col-md-3 col-sm-12">
@@ -497,17 +529,18 @@
</div>
<div class="table-responsive">
<table class="table table-striped table-modern">
<thead>
<thead>
<tr>
<th>Chave de comparação</th>
<th>Item solicitado</th>
<th>Qtd. solicitada</th>
<th>Qtd. NFe</th>
<th>Item emitido na NFe</th>
<th>Qtd. emitida na NFe</th>
<th>Status</th>
</tr>
</thead>
<tbody id="tabelaConferenciaNfeBody">
<tr>
<td colspan="4">Sem conferência.</td>
<td colspan="5">Sem conferência.</td>
</tr>
</tbody>
</table>
@@ -573,3 +606,18 @@
</body>
</html>