att
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
<processDefinitionVersionPK>
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compra - Ginseng</processId>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
</processDefinitionVersionPK>
|
||||
<versionDescription></versionDescription>
|
||||
<formId>9305</formId>
|
||||
@@ -1009,7 +1009,7 @@
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<expressionOrder>1</expressionOrder>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<sequence>46</sequence>
|
||||
</conditionProcessStatePK>
|
||||
<condition>hAPI.getCardValue("validacaoItens") == "entregue"</condition>
|
||||
@@ -1021,7 +1021,7 @@
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<expressionOrder>2</expressionOrder>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<sequence>46</sequence>
|
||||
</conditionProcessStatePK>
|
||||
<condition>true</condition>
|
||||
@@ -1033,7 +1033,7 @@
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<expressionOrder>1</expressionOrder>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<sequence>128</sequence>
|
||||
</conditionProcessStatePK>
|
||||
<condition>parseFloat(hAPI.getCardValue("valorTotalCotacao")) <= 100000.00</condition>
|
||||
@@ -1047,7 +1047,7 @@
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<expressionOrder>1</expressionOrder>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<sequence>150</sequence>
|
||||
</conditionProcessStatePK>
|
||||
<condition>parseFloat(hAPI.getCardValue("valorTotalCotacao")) >= 5001.00 && 
|
||||
@@ -1063,7 +1063,7 @@ parseFloat(hAPI.getCardValue("valorTotalCotacao")) <= 50000.00
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<expressionOrder>2</expressionOrder>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<sequence>150</sequence>
|
||||
</conditionProcessStatePK>
|
||||
<condition>true</condition>
|
||||
@@ -1077,7 +1077,7 @@ parseFloat(hAPI.getCardValue("valorTotalCotacao")) <= 50000.00
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<expressionOrder>1</expressionOrder>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<sequence>154</sequence>
|
||||
</conditionProcessStatePK>
|
||||
<condition>parseFloat(hAPI.getCardValue("valorTotalCotacao")) > 50000.00</condition>
|
||||
@@ -1091,7 +1091,7 @@ parseFloat(hAPI.getCardValue("valorTotalCotacao")) <= 50000.00
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<expressionOrder>2</expressionOrder>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<sequence>154</sequence>
|
||||
</conditionProcessStatePK>
|
||||
<condition>parseFloat(hAPI.getCardValue("valorTotalCotacao")) < 50000.00</condition>
|
||||
@@ -1536,102 +1536,110 @@ parseFloat(hAPI.getCardValue("valorTotalCotacao")) <= 50000.00
|
||||
<processId>Solicitação de compras </processId>
|
||||
<version>1</version>
|
||||
</workflowProcessEventPK>
|
||||
<eventDescription>function toProtheusDate(d) {
|
||||
if (!d) return "";
|
||||
if (d.indexOf("/") > -1) {
|
||||
var parts = d.split("/");
|
||||
return parts[2] + parts[1] + parts[0]; // dd/MM/yyyy -> yyyyMMdd
|
||||
}
|
||||
if (d.indexOf("-") > -1) {
|
||||
return d.replace(/-/g, ""); // yyyy-MM-dd -> yyyyMMdd
|
||||
}
|
||||
return d; // já está no formato certo
|
||||
}
|
||||
|
||||
function hojeProtheus() {
|
||||
var d = new Date();
|
||||
var yyyy = d.getFullYear();
|
||||
var mm = d.getMonth() + 1;
|
||||
var dd = d.getDate();
|
||||
if (mm < 10) mm = "0" + mm;
|
||||
if (dd < 10) dd = "0" + dd;
|
||||
return "" + yyyy + mm + dd; // yyyyMMdd
|
||||
}
|
||||
|
||||
function servicetask82(attempt, message) {
|
||||
log.info("🚀 Iniciando servicetask82");
|
||||
|
||||
var qtdItens = hAPI.getChildrenIndexes("tbItens");
|
||||
log.info("📦 Total de itens na tabela: " + qtdItens.length);
|
||||
|
||||
var itens = [];
|
||||
for (var i = 0; i < qtdItens.length; i++) {
|
||||
var index = qtdItens[i];
|
||||
var item = {
|
||||
"C1_PRODUTO": String(hAPI.getCardValue("Codproduto___" + index)),
|
||||
"C1_QUANT": Number(hAPI.getCardValue("qtd___" + index)),
|
||||
"C1_DATPRF": toProtheusDate(String(hAPI.getCardValue("dataNec___" + index)))
|
||||
};
|
||||
itens.push(item);
|
||||
log.info("📌 Item adicionado: " + JSON.stringify(item));
|
||||
}
|
||||
|
||||
var payload = {
|
||||
"C1_SOLICIT": String(hAPI.getCardValue("usuarioSolicitante")),
|
||||
"C1_EMISSAO": hojeProtheus(),
|
||||
"C1_FILENT": String(hAPI.getCardValue("filialProtheus")).trim(),
|
||||
"C1_OBS": String(hAPI.getCardValue("observacoes")),
|
||||
"itens": itens
|
||||
};
|
||||
|
||||
log.info("📦 Payload montado:");
|
||||
log.info(JSON.stringify(payload));
|
||||
|
||||
var data1 = {
|
||||
companyId: '1',
|
||||
serviceCode: 'Postprod',
|
||||
endpoint: '/rest/UF_MATA110',
|
||||
method: 'post',
|
||||
timeoutService: '100',
|
||||
params: payload, // objeto puro
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
var clientService = fluigAPI.getAuthorizeClientService();
|
||||
var response = clientService.invoke(JSON.stringify(data1)); // SEMPRE stringify aqui
|
||||
|
||||
log.info("📬 Resposta da API Protheus:");
|
||||
log.dir(response);
|
||||
|
||||
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("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;
|
||||
}
|
||||
} else {
|
||||
throw "Sem resposta da API Protheus";
|
||||
}
|
||||
} catch (e) {
|
||||
log.error("❌ Erro ao enviar SC para o Protheus: " + e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
|
||||
log.info("🏁 Finalização da servicetask82");
|
||||
}
|
||||
<eventDescription>function toProtheusDate(d) {
|
||||
if (!d) return "";
|
||||
if (d.indexOf("/") > -1) {
|
||||
var parts = d.split("/");
|
||||
return parts[2] + parts[1] + parts[0]; // dd/MM/yyyy -> yyyyMMdd
|
||||
}
|
||||
if (d.indexOf("-") > -1) {
|
||||
return d.replace(/-/g, ""); // yyyy-MM-dd -> yyyyMMdd
|
||||
}
|
||||
return d; // já está no formato certo
|
||||
}
|
||||

|
||||
function hojeProtheus() {
|
||||
var d = new Date();
|
||||
var yyyy = d.getFullYear();
|
||||
var mm = d.getMonth() + 1;
|
||||
var dd = d.getDate();
|
||||
if (mm < 10) mm = "0" + mm;
|
||||
if (dd < 10) dd = "0" + dd;
|
||||
return "" + yyyy + mm + dd; // yyyyMMdd
|
||||
}
|
||||

|
||||
function servicetask82(attempt, message) {
|
||||
log.info("🚀 Iniciando servicetask82");
|
||||

|
||||
var qtdItens = hAPI.getChildrenIndexes("tbItens");
|
||||
log.info("📦 Total de itens na tabela: " + qtdItens.length);
|
||||

|
||||
var itens = [];
|
||||
for (var i = 0; i < qtdItens.length; i++) {
|
||||
var index = qtdItens[i];
|
||||
var item = {
|
||||
"C1_PRODUTO": String(hAPI.getCardValue("Codproduto___" + index)),
|
||||
"C1_QUANT": Number(hAPI.getCardValue("qtd___" + index)),
|
||||
"C1_DATPRF": toProtheusDate(String(hAPI.getCardValue("dataNec___" + index)))
|
||||
};
|
||||
itens.push(item);
|
||||
log.info("📌 Item adicionado: " + JSON.stringify(item));
|
||||
}
|
||||

|
||||
var filial = String(hAPI.getCardValue("filialprotheus") || hAPI.getCardValue("filialProtheus") || "").trim();
|
||||
if (!filial) {
|
||||
throw "Campo de filial não preenchido no formulário (filialprotheus).";
|
||||
}
|
||||

|
||||
var payload = {
|
||||
"C1_SOLICIT": String(hAPI.getCardValue("usuarioSolicitante")),
|
||||
"C1_EMISSAO": hojeProtheus(),
|
||||
"C1_FILENT": filial,
|
||||
"C1_OBS": String(hAPI.getCardValue("observacoes")),
|
||||
"itens": itens
|
||||
};
|
||||

|
||||
log.info("📦 Payload montado:");
|
||||
log.info(JSON.stringify(payload));
|
||||

|
||||
var data1 = {
|
||||
companyId: '1',
|
||||
serviceCode: 'Postprod',
|
||||
endpoint: '/UF_MATA110',
|
||||
method: 'post',
|
||||
timeoutService: '60000',
|
||||
params: payload, // objeto puro
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||

|
||||
try {
|
||||
var clientService = fluigAPI.getAuthorizeClientService();
|
||||
var response = clientService.invoke(JSON.stringify(data1)); // SEMPRE stringify aqui
|
||||

|
||||
log.info("📬 Resposta da API Protheus:");
|
||||
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("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;
|
||||
}
|
||||
} else {
|
||||
throw "Sem resposta da API Protheus";
|
||||
}
|
||||
} catch (e) {
|
||||
log.error("❌ Erro ao enviar SC para o Protheus: " + e);
|
||||
throw e;
|
||||
}
|
||||

|
||||

|
||||

|
||||
log.info("🏁 Finalização da servicetask82");
|
||||
}
|
||||
</eventDescription>
|
||||
</WorkflowProcessEvent>
|
||||
<WorkflowProcessEvent>
|
||||
@@ -1641,25 +1649,25 @@ function servicetask82(attempt, message) {
|
||||
<processId>Solicitação de compras </processId>
|
||||
<version>1</version>
|
||||
</workflowProcessEventPK>
|
||||
<eventDescription>function servicetask114(attempt, message) {
|
||||
log.info("🚀 ST92 — Verifica se já existe código de cotação no formulário");
|
||||
|
||||
var numSC = hAPI.getCardValue("numeroSCProtheus");
|
||||
var numCot = hAPI.getCardValue("cotacaoSCProtheus");
|
||||
|
||||
log.info("📌 SC: " + numSC + " | Cotação: " + numCot);
|
||||
|
||||
if (!numSC) {
|
||||
throw "❌ Número da SC não informado no formulário.";
|
||||
}
|
||||
|
||||
// se não tiver cotação ainda, força o loop da atividade
|
||||
if (!numCot || numCot === "000000" || numCot === "000001") {
|
||||
throw "⏳ Cotação ainda não disponível para a SC " + numSC;
|
||||
}
|
||||
|
||||
// se já tiver código, só registra log e deixa o processo seguir
|
||||
log.info("✅ Cotação " + numCot + " encontrada no formulário. Processo segue.");
|
||||
<eventDescription>function servicetask114(attempt, message) {
|
||||
log.info("🚀 ST92 — Verifica se já existe código de cotação no formulário");
|
||||

|
||||
var numSC = hAPI.getCardValue("numeroSCProtheus");
|
||||
var numCot = hAPI.getCardValue("cotacaoSCProtheus");
|
||||

|
||||
log.info("📌 SC: " + numSC + " | Cotação: " + numCot);
|
||||

|
||||
if (!numSC) {
|
||||
throw "❌ Número da SC não informado no formulário.";
|
||||
}
|
||||

|
||||
// se não tiver cotação ainda, força o loop da atividade
|
||||
if (!numCot || numCot === "000000" || numCot === "000001") {
|
||||
throw "⏳ Cotação ainda não disponível para a SC " + numSC;
|
||||
}
|
||||

|
||||
// se já tiver código, só registra log e deixa o processo seguir
|
||||
log.info("✅ Cotação " + numCot + " encontrada no formulário. Processo segue.");
|
||||
}</eventDescription>
|
||||
</WorkflowProcessEvent>
|
||||
</list>
|
||||
@@ -1801,7 +1809,7 @@ function servicetask82(attempt, message) {
|
||||
<processLinkBendPK>
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<linkSequence>26</linkSequence>
|
||||
<bendSequence>1</bendSequence>
|
||||
</processLinkBendPK>
|
||||
@@ -1812,7 +1820,7 @@ function servicetask82(attempt, message) {
|
||||
<processLinkBendPK>
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<linkSequence>125</linkSequence>
|
||||
<bendSequence>1</bendSequence>
|
||||
</processLinkBendPK>
|
||||
@@ -1823,7 +1831,7 @@ function servicetask82(attempt, message) {
|
||||
<processLinkBendPK>
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<linkSequence>126</linkSequence>
|
||||
<bendSequence>1</bendSequence>
|
||||
</processLinkBendPK>
|
||||
@@ -1834,7 +1842,7 @@ function servicetask82(attempt, message) {
|
||||
<processLinkBendPK>
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<linkSequence>127</linkSequence>
|
||||
<bendSequence>1</bendSequence>
|
||||
</processLinkBendPK>
|
||||
@@ -1845,7 +1853,7 @@ function servicetask82(attempt, message) {
|
||||
<processLinkBendPK>
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<linkSequence>129</linkSequence>
|
||||
<bendSequence>1</bendSequence>
|
||||
</processLinkBendPK>
|
||||
@@ -1856,7 +1864,7 @@ function servicetask82(attempt, message) {
|
||||
<processLinkBendPK>
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<linkSequence>142</linkSequence>
|
||||
<bendSequence>1</bendSequence>
|
||||
</processLinkBendPK>
|
||||
@@ -1867,7 +1875,7 @@ function servicetask82(attempt, message) {
|
||||
<processLinkBendPK>
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<linkSequence>144</linkSequence>
|
||||
<bendSequence>1</bendSequence>
|
||||
</processLinkBendPK>
|
||||
@@ -1878,7 +1886,7 @@ function servicetask82(attempt, message) {
|
||||
<processLinkBendPK>
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<linkSequence>152</linkSequence>
|
||||
<bendSequence>1</bendSequence>
|
||||
</processLinkBendPK>
|
||||
@@ -1889,7 +1897,7 @@ function servicetask82(attempt, message) {
|
||||
<processLinkBendPK>
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<linkSequence>152</linkSequence>
|
||||
<bendSequence>2</bendSequence>
|
||||
</processLinkBendPK>
|
||||
@@ -1900,7 +1908,7 @@ function servicetask82(attempt, message) {
|
||||
<processLinkBendPK>
|
||||
<companyId>1</companyId>
|
||||
<processId>Solicitação de compras </processId>
|
||||
<version>8</version>
|
||||
<version>86</version>
|
||||
<linkSequence>161</linkSequence>
|
||||
<bendSequence>1</bendSequence>
|
||||
</processLinkBendPK>
|
||||
|
||||
Reference in New Issue
Block a user