202 lines
5.6 KiB
JavaScript
202 lines
5.6 KiB
JavaScript
// Changelog
|
|
// 2022-11-23: EMPEPI1-141: Ablehnung von Rechnungen im Entwurfsmodus ab 25.11.2022
|
|
// EMPEPI1-148: eMobility PEPI Anpassung des Mappings API-Einmalabrechnung
|
|
// 2023-01-18: EMPEPI1-193: Korrektur aperiodische Buchungen
|
|
// 2023-02-22: EMPEPI1-157: Zeilenerweiterung per SST auf Rechnung
|
|
// 2023-03-07: EMPEPI1-230: Anpassungen der Schnittstellen-Fehlermeldungen
|
|
// 2023-08-07: EMPEPI1-273: Anpassungen Invoice Adresse
|
|
// 2023-11-29: EMPEPI1-329: Struktur Haupt-/Zusatzartikel
|
|
// 2023-12-07: EMPEPI1-341: Korrektur Adressmapping
|
|
// 2024-09-13: BUS-6987: Feld Firmenname auf 50 Zeichen begrenzt, führt zu inkonsitenten Rechnungsadressen
|
|
// 2025-04-15: BUS-11743: Feld Comments begrenzen auf 254 Zeichen
|
|
// 2025-05-19: BUS-12136: Erweiterung CRM Invoice Schnittstelle für rechnungsbegleitende Unterlagen
|
|
var slib = $.import("uniorg.ServiceLayer", "B1SLLogic");
|
|
var datetimelib = $.import("uniorg.libs", "datetime");
|
|
var logginglib = $.import("uniorg.libs", "uologging");
|
|
var slDest = $.import("uniorg.destinations", "uodestlib");
|
|
var slfwlib = $.import("uniorg.ServiceLayer", "B1SLFramework");
|
|
|
|
var serviceName = "nice.v1.setinvoice.xsjs";
|
|
var serviceVersion = '3.2';
|
|
|
|
var output = {};
|
|
var outMessages = [];
|
|
var outMsg = {};
|
|
var outStatus = "success";
|
|
var myDebug = {};
|
|
|
|
var companyid = 0;
|
|
var UserName = '';
|
|
var UserPass = '';
|
|
var UserComp = '';
|
|
|
|
var SESSIONID = "";
|
|
var NODEID = "";
|
|
var slLoggedIn = false;
|
|
var logTableId = 0;
|
|
var logDocEntry = -1;
|
|
|
|
var objecttype = "13";
|
|
|
|
var debugLevel = 0;
|
|
switch ($.request.parameters.get("debug")) {
|
|
case "true":
|
|
case "yes":
|
|
case "1":
|
|
debugLevel = 1;
|
|
break;
|
|
case "full":
|
|
case "2":
|
|
debugLevel = 2;
|
|
break;
|
|
}
|
|
|
|
if (debugLevel > 0) {
|
|
output.requestParams = $.request.parameters;
|
|
}
|
|
|
|
var draftMode = true;
|
|
|
|
function updateLogEntry(id, docEntry, b1Obj) {
|
|
var conn = $.hdb.getConnection();
|
|
try {
|
|
conn.executeUpdate(
|
|
"UPDATE \"INTEGRATION_DATA\".\"UO_DOCUMENTS_RAWCALL\" SET \"B1_PK\" = ?, \"B1_OBJ\" = ?, \"UPDATE_TS\" = CURRENT_TIMESTAMP WHERE \"ID\" = ?",
|
|
docEntry, b1Obj, id);
|
|
conn.commit();
|
|
} catch (e) {
|
|
exceptionHandler(e);
|
|
return;
|
|
}
|
|
}
|
|
|
|
function setOutputMessage() {
|
|
output.status = outStatus;
|
|
if (debugLevel > 0) {
|
|
output.debugInfos = myDebug;
|
|
}
|
|
output.messages = outMessages;
|
|
$.response.contentType = "application/json";
|
|
$.response.setBody(JSON.stringify(output));
|
|
$.response.status = $.net.http.OK;
|
|
}
|
|
|
|
function exceptionHandler(ex) {
|
|
if (outMsg.method) {
|
|
outMessages.push(outMsg);
|
|
}
|
|
outMsg = {};
|
|
outMsg.method = "exceptionHandler";
|
|
outMsg.status = "error";
|
|
outMsg.message = ex.toString();
|
|
if (debugLevel > 0) {
|
|
outMsg.exceptionInfo = {};
|
|
outMsg.exceptionInfo.name = ex.name;
|
|
outMsg.exceptionInfo.message = ex.message;
|
|
outMsg.exceptionInfo.fileName = ex.fileName;
|
|
outMsg.exceptionInfo.lineNumber = ex.lineNumber;
|
|
outMsg.exceptionInfo.columnNumber = ex.columnNumber;
|
|
outMsg.exceptionInfo.stack = ex.stack;
|
|
//outMsg.exceptionInfo.source = ex.toSource();
|
|
}
|
|
outMessages.push(outMsg);
|
|
outStatus = "error";
|
|
output.status = outStatus;
|
|
if (debugLevel > 0) {
|
|
output.debugInfos = myDebug;
|
|
}
|
|
output.messages = outMessages;
|
|
|
|
var errbody = JSON.stringify(output);
|
|
$.response.contentType = 'application/json';
|
|
$.response.setBody(errbody);
|
|
//$.response.status = $.net.http.INTERNAL_SERVER_ERROR;
|
|
// Workaround, weil CRM scheinbar Probleme mit anderen Statuscodes hat
|
|
$.response.status = $.net.http.OK;
|
|
|
|
try {
|
|
if (slLoggedIn) {
|
|
slib.SLLogout(SESSIONID, NODEID);
|
|
}
|
|
} catch (e) {
|
|
|
|
}
|
|
}
|
|
|
|
function setConnectionParams(sfcall) {
|
|
var jsonSFCall = JSON.parse(sfcall);
|
|
|
|
var idValue = "A19753_EON_P01";
|
|
var idFieldname = 'SYS_NAME';
|
|
var CompanyConfig = slDest.getCompanyCfg(idValue, idFieldname);
|
|
UserComp = CompanyConfig.COMPANYNAME;
|
|
UserName = CompanyConfig.USERNAME;
|
|
UserPass = slDest.readSecureStore(CompanyConfig.ID);
|
|
if (debugLevel > 1) {
|
|
myDebug.connectionParams = CompanyConfig;
|
|
}
|
|
myDebug.idValue = idValue;
|
|
myDebug.idFieldname = idFieldname;
|
|
if (CompanyConfig.COMPANYNAME === undefined) {
|
|
outMsg = {};
|
|
outMsg.method = "getCompany";
|
|
outStatus = "error";
|
|
outMsg.status = "error";
|
|
outMsg.message = "ERPInstanceName is invalid for this endpoint";
|
|
outMessages.push(outMsg);
|
|
}
|
|
|
|
myDebug.CompanyName = UserComp;
|
|
}
|
|
|
|
function slLogin() {
|
|
var loginResult = false;
|
|
var loginInfo = {};
|
|
loginInfo.UserName = UserName;
|
|
loginInfo.Password = UserPass;
|
|
loginInfo.CompanyDB = UserComp;
|
|
|
|
// SL LOGIN
|
|
var response = slib.SLLogin(JSON.stringify(loginInfo), null, null);
|
|
|
|
// B1SESSION and ROUTEID cookies returned by Login
|
|
for (var j in response.cookies) {
|
|
if (response.cookies[j].name == "B1SESSION") {
|
|
SESSIONID = response.cookies[j].value;
|
|
//output.SessionID = SESSIONID;
|
|
} else if (response.cookies[j].name == "ROUTEID") {
|
|
NODEID = response.cookies[j].value;
|
|
//output.NodeID = NODEID;
|
|
}
|
|
}
|
|
|
|
var loginResponse;
|
|
try {
|
|
loginResponse = JSON.parse(response.body.asString());
|
|
} catch (e) {
|
|
loginResponse = response.body.asString();
|
|
}
|
|
|
|
if (debugLevel > 1) {
|
|
myDebug.loginInfo = loginInfo;
|
|
}
|
|
myDebug.loginResponse = loginResponse;
|
|
if (response.status === 200) {
|
|
loginResult = true;
|
|
} else {
|
|
outMsg = {};
|
|
outMsg.method = "login";
|
|
outMsg.status = "error";
|
|
var slError = myDebug.loginResponse.error;
|
|
if (slError && slError.hasOwnProperty("code") && slError.message && slError.message.value) {
|
|
outMsg.message = slError.message.value + " (Code: " + slError.code.toString() + ")";
|
|
} else {
|
|
outMsg.message = JSON.stringify(myDebug.loginResponse);
|
|
}
|
|
outMsg.response = myDebug.loginResponse;
|
|
//outMsg.message = loginResponse;
|
|
outMessages.push(outMsg);
|
|
outStatus = "error";
|
|
}
|
|
return loginResult;
|
|
} |