This commit is contained in:
2026-05-06 16:01:10 -03:00
parent f31f809ce7
commit 4a31410351
26 changed files with 22041 additions and 2083 deletions
@@ -38,10 +38,21 @@ function servicetask82(attempt, message) {
log.info("📌 Item adicionado: " + JSON.stringify(item));
}
var filial = String(
hAPI.getCardValue("filialprotheus") ||
hAPI.getCardValue("filialProtheus") ||
hAPI.getCardValue("codigocentroCusto") ||
""
).trim();
if (!filial) {
throw "Campo PROTHEUS da filial não preenchido no formulário (filialprotheus).";
}
log.info("🏬 Filial PROTHEUS enviada no C1_FILENT: " + filial);
var payload = {
"C1_SOLICIT": String(hAPI.getCardValue("usuarioSolicitante")),
"C1_EMISSAO": hojeProtheus(),
"C1_FILENT": String(hAPI.getCardValue("filialProtheus")).trim(),
"C1_FILENT": filial,
"C1_OBS": String(hAPI.getCardValue("observacoes")),
"itens": itens
};
@@ -52,9 +63,9 @@ function servicetask82(attempt, message) {
var data1 = {
companyId: '1',
serviceCode: 'Postprod',
endpoint: '/rest/UF_MATA110',
endpoint: '/UF_MATA110',
method: 'post',
timeoutService: '100',
timeoutService: '60000',
params: payload, // objeto puro
headers: {
'Content-Type': 'application/json'
@@ -66,21 +77,27 @@ function servicetask82(attempt, message) {
var response = clientService.invoke(JSON.stringify(data1)); // SEMPRE stringify aqui
log.info("📬 Resposta da API Protheus:");
log.dir(response);
if (response) {
log.info("HTTP status: " + response.getHttpStatusResult());
log.info("Body: " + response.getResult());
}
if (response && response.getResult()) {
var result = JSON.parse(response.getResult());
if (result.sucesso) {
hAPI.setCardValue("numeroSCProtheus", result.C1_NUM || "");
hAPI.setCardValue("statusSCProtheus", "SC cadastrada com sucesso");
hAPI.setCardValue("statusAtendimento", "Em andamento");
hAPI.setCardValue("solicitanteSCProtheus", result.C1_SOLICIT || "");
hAPI.setCardValue("emissaoSCProtheus", result.C1_EMISSAO || "");
hAPI.setCardValue("qtdItensSCProtheus", String(result.quantidade_itens || ""));
hAPI.setCardValue("dataCadastroSCProtheus", result.data_cadastro || "");
hAPI.setCardValue("horaCadastroSCProtheus", result.hora_cadastro || "");
} else {
hAPI.setCardValue("statusSCProtheus", "Erro: " + result.erro);
throw "Erro Protheus: " + result.message;
var erroMsg = result.erro || result.message || JSON.stringify(result);
hAPI.setCardValue("statusSCProtheus", "Erro: " + erroMsg);
hAPI.setCardValue("statusAtendimento", "Erro no envio");
throw "Erro Protheus: " + erroMsg;
}
} else {
throw "Sem resposta da API Protheus";