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.
"; hasErros = true; } if (form.getValue("invoiceIdNfeConsulta") == "") { message += "Consulte a chave da NFe antes de enviar esta etapa.
"; 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 base aprovada e a NFe.
"; 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 ( "" ) } } } function isMobile(form) { return form.getMobile() != null && form.getMobile(); } function getMessage(texto, tipo, form) { if (tipo == 1) { return 'Campo "' + texto + '" nao pode estar vazio.
'; } else if (tipo == 2) { return 'Selecione uma das opcoes do Campo "' + texto + '".
'; } else if (tipo == 3) { return 'Campo "' + texto + '" nao pode estar sem anexo.
'; } else { return 'A quantidade existente de campos "' + texto + '" deve ser maior do que 0.' } }