$(document).ready(function () { if ($("#formMode").val() == "VIEW") { showAndBlock(["all"]); } else { var activity = $("#activity").val(); var requestDate = getCurrentDate(); // Ponto de partida: tudo visível, depois escondemos só o que ainda não chegou $(".activity").css("display", "block"); if (activity == 0 || activity == 1 || !activity) { // Atividade inicial — esconde tudo que ainda não foi liberado $(".activity-121, .activity-18, .activity-24").css("display", "none"); $("#dataAbertura").val(requestDate[0]); add_new_row("tabelaItens"); } else if (activity == 121) { // Gestor analisa — esconde atividades futuras $(".activity-18, .activity-24").css("display", "none"); showAndBlock([1]); if (typeof colapsarAtividadesAnteriores === "function") { colapsarAtividadesAnteriores([1]); } $("#user_validacao_gestor").val($("#currentUserName").val()); $("#data_validacao_gestor").val(requestDate[0] + " - " + requestDate[1]); updt_line(); } else if (activity == 18) { // Validação dos itens — esconde só a atividade futura $(".activity-24").css("display", "none"); showAndBlock([1, 121]); if (typeof colapsarAtividadesAnteriores === "function") { colapsarAtividadesAnteriores([1, 121]); } $("#userValidacaoItens").val($("#currentUserName").val()); $("#dataValidacaoItens").val(requestDate[0] + " - " + requestDate[1]); $("input[name=validacaoItens]").on("change", function () { $(".justificativaDecisaoItens").hide(); if ( $("input[name=validacaoItens]:checked").val() == "incorreto" || $("input[name=validacaoItens]:checked").val() == "naoEntregue" ) { $(".justificativaDecisaoItens").show(); } }); $("input[name=validacaoItens]").trigger("change"); updt_line(); } else if (activity == 24) { // Última atividade — tudo visível, bloqueia anteriores showAndBlock([1, 121, 18]); if (typeof colapsarAtividadesAnteriores === "function") { colapsarAtividadesAnteriores([1, 121, 18]); } updt_line(); } } formatarMoedasTabela("preco___"); //formatarMoedasTabela("precoIndica___"); formatarMoedasTabela("ValorTotal"); gerarTabelaCotacaoIndica("tabelaCotacaoIndica", "tabelaItens"); }); function formatarMoedasTabela(ids) { $(document).on('input', `[id^="${ids}"]`, function() { let valor = $(this).val(); // Remove tudo que não for número valor = valor.replace(/\D/g, ''); // Converte para número decimal let numero = parseFloat(valor) / 100; // Formata para Real Brasileiro if (!isNaN(numero)) { valor = numero.toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); } // Atualiza o campo com a formatação correta $(this).val(valor);     }); } //show the activity and then block the fields function showAndBlock(activity) { for (var i = 0, l = activity.length; i < l; i++) { $(".activity-" + activity[i]).css("display", "block"); $(".hideButton").hide(); $(".activity-" + activity[i] + " :input").each(function () { $(this).attr("readonly", "readonly"); $(this) .css("background-color", "#eee") .children("option:not(:selected)") .prop("disabled", true); $(this).on("mousedown", function (e) { this.blur(); window.focus(); }); if ($(this).is(":checkbox")) { $(this).attr("disabled", true); } else if ($(this).is(":radio")) { $(this).on("click", function () { return false; }); } }); } } function getCurrentDate() { var newDate = new Date(); var h = newDate.getHours(); if (h < 10) { h = "0" + h; } var m = newDate.getMinutes(); if (m < 10) { m = "0" + m; } var hour = h + ":" + m; // + ":" + s; var day = newDate.getDate(); if (day < 10) { day = "0" + day; } var month = newDate.getMonth() + 1; if (month < 10) { month = "0" + month; } newDate = day + "/" + month + "/" + newDate.getFullYear(); var currentDate = [newDate, hour]; return currentDate; } var beforeSendValidate = function (numState, nextState) { $(".errorValidate").removeClass("errorValidate"); if (numState == 0 || numState == 1) { if ($("#estabelecimento ").val() == "") { $("#estabelecimento ").parent("div").addClass("errorValidate"); throw "'Estabelecimento/filial ' é obrigatório."; } else if ($("#enderecoSolicitante").val() == "") { $("#enderecoSolicitante").parent("div").addClass("errorValidate"); throw "'Endereço do solicitante' é obrigatório."; } else if ($("#cnpj").val() == "") { $("#cnpj").parent("div").addClass("errorValidate"); throw "'CNPJ' é obrigatório."; } else if ($("#justificativa").val() == "") { $("#justificativa").parent("div").addClass("errorValidate"); throw "'Qual o motivo da compra?' é obrigatório."; } else { $("input[id^='quantidadeItem___']").each(function (index, value) { var linha = $(value).attr("name").split("___")[1]; if ( $("#descricao___" + linha).val() == "" && $("#quantidadeItem___" + linha).val() == "" ) { remove_row(value); } }); $("input[id^='quantidadeItem___']").each(function (index, value) { var linha = $(value).attr("name").split("___")[1]; 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) + "."; } }); if ($("input[name^='quantidadeItem___']").length == 0) { throw "Ao menos um item é necessário para iniciar a solicitação."; } } } else if (numState == 4) { // } else if (numState == 6) { // } else if (numState == 18) { if ( $("input[name='validacaoItens']:checked").val() == "" || $("input[name='validacaoItens']:checked").val() == undefined ) { throw "'Consegue resolver?' é obrigatório."; } else if ( $("input[name='validacaoItens']:checked").val() == "naoEntregue" || $("input[name='validacaoItens']:checked").val() == "incorreto" ) { if ($("#justificativaDecisaoItens").val() == "") { $("#justificativaDecisaoItens") .parent("div") .addClass("errorValidate"); throw "'Justificativa' é obrigatório."; } } } else if (numState == 24) { $('#justificativaValidaProblema').parent().removeClass('has-error errorValidate'); if ($('#justificativaValidaProblema').val() == "") { $('#justificativaValidaProblema').parent().addClass('has-error errorValidate'); throw "Preencha os campos obrigatórios." } } }; // setSelectedZoomItem e removedZoomItem foram consolidados em compras_digital.js // (carregado via