2026-04-15 15:09:37 -03:00

147 lines
6.0 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function validateForm(form) {
var atividade = parseInt(getValue("WKNumState"));
var nextAtividade = getValue("WKNextState");
var completTask = getValue("WKCompletTask");
var hasErros = false;
var message = "";
log.info("Atividade Inicial Para Transferência de Mercadoria");
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:
log.info("Validando rastreabilidade da emissao da NFe");
var chaveNfe = String(form.getValue("chaveNfe") || "").replace(/\D/g, "");
if (chaveNfe == "") {
message += getMessage("Chave de acesso da NFe", 1, form);
hasErros = true;
}
if (chaveNfe != "" && chaveNfe.length != 44) {
message += "Campo \"Chave de acesso da NFe\" deve conter 44 digitos.<br>";
hasErros = true;
}
if (form.getValue("invoiceIdNfeConsulta") == "") {
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;
}
if (form.getValue("usuarioEmissorNfe") == "") {
message += getMessage("Usuário emissor da NFe", 1, form);
hasErros = true;
}
if (form.getValue("dataEmissaoNfe") == "") {
message += getMessage("Data da emissão", 1, form);
hasErros = true;
}
break;
case COLETA:
log.info("Validando dados da coleta");
if (form.getValue("motoristaColetaNome") == "") {
message += getMessage("Motorista responsável pela coleta", 1, form);
hasErros = true;
}
if (form.getValue("dataColeta") == "") {
message += getMessage("Data da coleta", 1, form);
hasErros = true;
}
if (form.getValue("fdAnexo_Coleta") == "") {
message += getMessage("Anexo da Coleta", 3, form);
hasErros = true;
}
var tipoMotoristaEntregaColeta = String(form.getValue("tipoMotoristaEntrega") || "");
if (tipoMotoristaEntregaColeta == "") {
message += getMessage("Quem vai fazer a entrega", 2, form);
hasErros = true;
}
if (tipoMotoristaEntregaColeta == "outro" && form.getValue("motoristaEntregaLogin") == "") {
message += getMessage("Selecionar outro motorista", 1, form);
hasErros = true;
}
if (tipoMotoristaEntregaColeta == "mesmo" && form.getValue("motoristaColetaLogin") == "") {
message += getMessage("Login do motorista da coleta", 1, form);
hasErros = true;
}
break;
case ENTREGA:
log.info("Validando dados da entrega");
if (form.getValue("motoristaEntregaLogin") == "") {
message += getMessage("Motorista da entrega definido na coleta", 1, form);
hasErros = true;
}
if (form.getValue("motoristaEntregaNome") == "") {
message += getMessage("Motorista responsável pela entrega", 1, form);
hasErros = true;
}
if (form.getValue("dataEntrega") == "") {
message += getMessage("Data da entrega", 1, form);
hasErros = true;
}
if (String(form.getValue("nomerecebedor") || "").trim() == "") {
message += getMessage("Nome de quem recebeu a mercadoria", 1, form);
hasErros = true;
}
break;
case RECEBIMENTO:
log.info("Validando recebimento e conferencia dos itens");
var validacaoItens = String(form.getValue("validacaoItens") || "");
if (validacaoItens == "") {
message += getMessage("Validação do recebimento", 2, form);
hasErros = true;
}
if (
(validacaoItens == "divergencia" || validacaoItens == "naoEntregue" || validacaoItens == "incorreto") &&
form.getValue("justificativaDecisaoItens") == ""
) {
message += getMessage("Descreva a divergência encontrada", 1, form);
hasErros = true;
}
break;
default:
break;
}
if (hasErros) {
if (isMobile(form)) throw message;
throw (
"<ul style='list-style-type: disc; padding-left: 90px;' class='alert alert-danger'>" +
message +
"</ul>"
)
}
}
}
function isMobile(form) {
return form.getMobile() != null && form.getMobile();
}
function getMessage(texto, tipo, form) {
if (tipo == 1) {
return 'Campo "' + texto + '" nao pode estar vazio.<br>';
} else if (tipo == 2) {
return 'Selecione uma das opcoes do Campo "' + texto + '".<br>';
} else if (tipo == 3) {
return 'Campo "' + texto + '" nao pode estar sem anexo.<br>';
} else {
return 'A quantidade existente de campos "' + texto + '" deve ser maior do que 0.'
}
}