190 lines
6.0 KiB
JavaScript
190 lines
6.0 KiB
JavaScript
var slib = $.import("uniorg.ServiceLayer", "B1SLLogic");
|
|
var slfwlib = $.import("uniorg.ServiceLayer", "B1SLFramework");
|
|
var datetimelib = $.import("uniorg.libs", "datetime");
|
|
var logginglib = $.import("uniorg.libs", "uologging");
|
|
var slDest = $.import("uniorg.destinations", "uodestlib");
|
|
var bpmaplib = $.import("uniorg.eon.libs", "bpmapping");
|
|
|
|
//var ParDebug = false;
|
|
//var mCardCode = "";
|
|
var output = {};
|
|
var outMessages = [];
|
|
var outMsg = {};
|
|
var outStatus = "success";
|
|
var myDebug = {};
|
|
var UserName = slDest.uniorg_eon_bp_v1_UserName;
|
|
var UserPass = slDest.uniorg_eon_bp_v1_UserPass;
|
|
var UserComp = slDest.uniorg_eon_bp_v1_UserComp;
|
|
var service_version = '1.4';
|
|
|
|
|
|
|
|
|
|
function copyBP(ParDebug,mCardCode) {
|
|
|
|
var SESSIONID = "";
|
|
var NODEID = "";
|
|
|
|
// SL credentials
|
|
var loginInfo = {};
|
|
loginInfo.UserName = UserName;
|
|
loginInfo.Password = UserPass;
|
|
loginInfo.CompanyDB = UserComp;
|
|
|
|
var searchparamC = {};
|
|
//searchparam.key = "U_EON_ID_CRM_INTERNAL";
|
|
searchparamC.key = "CardCode";
|
|
searchparamC.value = mCardCode;
|
|
|
|
var searchparamV = {};
|
|
//searchparam.key = "U_EON_ID_CRM_INTERNAL";
|
|
searchparamV.key = "CardCode";
|
|
searchparamV.value = mCardCode + "-L";
|
|
|
|
output.searchparamC = searchparamC;
|
|
output.searchparamV = searchparamV;
|
|
|
|
var slError;
|
|
|
|
// 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;
|
|
}
|
|
}
|
|
if (ParDebug > 1) {
|
|
//output.loginInfo = loginInfo;
|
|
}
|
|
// output.loginResponse = JSON.parse(response.body.asString());
|
|
var loginResponse;
|
|
try {
|
|
loginResponse = JSON.parse(response.body.asString());
|
|
} catch (e) {
|
|
loginResponse = response.body.asString();
|
|
}
|
|
output.loginResponse = loginResponse;
|
|
if (response.status !== 200) {
|
|
outMsg = {};
|
|
outMsg.method = "login";
|
|
outMsg.status = "error";
|
|
//outMsg.message = output.loginResponse;
|
|
var slError = 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(loginResponse);
|
|
}
|
|
outMsg.response = loginResponse;
|
|
outMessages.push(outMsg);
|
|
outStatus = "error";
|
|
}
|
|
|
|
output.cardcode = mCardCode;
|
|
output.outStatus = outStatus;
|
|
|
|
if (outStatus !== "error") {
|
|
|
|
outMsg = {};
|
|
outMsg.method = "CustomercheckExists";
|
|
|
|
var customerObject = slfwlib.getfullBPbysearchParam(searchparamC, SESSIONID, NODEID,ParDebug);
|
|
var vendorObject = slfwlib.getfullBPbysearchParam(searchparamV, SESSIONID, NODEID,ParDebug);
|
|
var consBPObject="";
|
|
|
|
// outMessages.push(customerObject.Messages);
|
|
// outMessages.push(vendorObject.Messages);
|
|
myDebug.customerObject = customerObject;
|
|
myDebug.vendorObject = vendorObject;
|
|
|
|
|
|
|
|
//consBPObject = bpmaplib.buildBPObj(customerObject.BP,vendorObject.BP);
|
|
//myDebug.mappedUPDBPObj = consBPObject;
|
|
if (customerObject.Status == "exists" && vendorObject.Status == "exists") {
|
|
consBPObject = bpmaplib.buildBPObj(customerObject.BP,vendorObject.BP);
|
|
myDebug.mappedUPDBPObj = consBPObject;
|
|
output.method = "updateVendor";
|
|
var responseUpdate = slib.updateBusinessPartner(vendorObject.BP.CardCode, JSON.stringify(consBPObject), SESSIONID, NODEID);
|
|
outMsg = {};
|
|
outMsg.method = "update";
|
|
myDebug.statusUpdate = responseUpdate.status;
|
|
outMsg.statuscode = responseUpdate.status;
|
|
if (responseUpdate.status >= 200 && responseUpdate.status < 300) {
|
|
myDebug.Updatemessage = "Update sucessfull";
|
|
outMsg.status = "success";
|
|
} else {
|
|
myDebug.message = "Update error occured";
|
|
outMsg.status = "error";
|
|
if (responseUpdate.body) {
|
|
myDebug.responseUpdate = JSON.parse(responseUpdate.body.asString());
|
|
//outMsg.message = myDebug.responseUpdate;
|
|
slError = myDebug.responseUpdate.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.responseUpdate);
|
|
}
|
|
outMsg.response = myDebug.responseUpdate;
|
|
}
|
|
outStatus = "error";
|
|
}
|
|
outMessages.push(outMsg);
|
|
|
|
}
|
|
|
|
if (customerObject.Status == "exists" && vendorObject.Status == "not exists") {
|
|
consBPObject = bpmaplib.buildBPObj(customerObject.BP);
|
|
myDebug.mappedCreateBPObj = consBPObject;
|
|
output.method = "createVendor";
|
|
outMsg = {};
|
|
outMsg.method = "create";
|
|
var responseCreate = slib.createBusinessPartner(JSON.stringify(consBPObject), SESSIONID, NODEID);
|
|
myDebug.statusCreate = responseCreate.status;
|
|
outMsg.statuscode = responseCreate.status;
|
|
myDebug.responseCreate = JSON.parse(responseCreate.body.asString());
|
|
if (responseCreate.status >= 200 && responseCreate.status < 300) {
|
|
myDebug.Createmessage = "Create sucessfull";
|
|
outMsg.status = "success";
|
|
} else {
|
|
myDebug.Createmessage = "Create error occured";
|
|
output.errorCreatestatus = myDebug.Createmessage;
|
|
outMsg.status = "error";
|
|
//outMsg.message = myDebug.responseCreate;
|
|
outStatus = "error";
|
|
slError = myDebug.responseCreate.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.responseCreate);
|
|
}
|
|
outMsg.response = myDebug.responseCreate;
|
|
}
|
|
outMessages.push(outMsg);
|
|
}
|
|
|
|
|
|
//output.CardCode = CardCode;
|
|
//output.CardName = body.CardName;
|
|
|
|
slib.SLLogout(SESSIONID, NODEID);
|
|
|
|
}
|
|
outMessages.push(outMsg);
|
|
output.Messages = outMessages;
|
|
if (ParDebug)
|
|
{
|
|
output.debug = myDebug;
|
|
}
|
|
|
|
|
|
|
|
|
|
return output;
|
|
} |