In this blog post we are going to propose the use of the message-driven strategy to enable a system agnostic integration that generates electronic invoices based on one of the two event-driven prototypes you probably saw in the posts we published before: the one pushing data out of SAP Business ByDesign, and the other pulling data from that same core ERP.
Proposed architecture and its main elements:
import AP.Common.GDT;
import AP.CustomerInvoicing.Global;
[Extension] businessobject AP.CustomerInvoicing.Global:CustomerInvoice raises Message_Cant_Release{
message Message_Cant_Release text "Missing Electronic Invoice";
// You must activate this business object before you can access the extension fields
// or messages in script files, forms, and screens.
node CustomerInvoice {
[Tooltip ("Issued by Tax Authority")]
[Label ("Electronic Invoice Signature")]
element eInvSignature : ID;
}
}
function callBydGetInv(custInvID, tenant, callback) {
console.log(
"Enterprise Messaging webhook input data: " + JSON.stringify(custInvID)
);
var custInvObjID = custInvID.ObjectUUID || custInvID.ObjectID;
var custTenant = tenant || custInvID.SourceTenantHost || process.env.ERP_URL;
var uri =
custTenant +
"/sap/byd/odata/cust/v1/khcustomerinvoice/CustomerInvoiceCollection('" +
custInvObjID +
"')?$format=json";
console.log("ByD OData URI: " + uri);
//Set HTTP Request Options
var options = {
uri: uri,
headers: {
Authorization: "Basic " + process.env.BYD_B64AUTH,
},
};
function callAFIPGetLast(data, callback) {
var params_createInv = require("../params/compUltimo.js");
soap.createClient(urlTransac, function (err, client) {
client.FECompUltimoAutorizado(params_createInv, function (err, result) {
callback(null, result);
});
});
}
function callAFIPCreateInv(data, callback) {
var params_createInv = initCrear.initValuesSolicitar(data.newInvNum, data.newInvAmount);
soap.createClient(urlTransac, function (err, client) {
client.FECAESolicitar(params_createInv, function (err, result) {
callback(null, result);
});
});
}
function callBydUpdateInv(signature, data, tenant, callback) {
var custInvObjID = data.ObjectUUID || data.ObjectID;
var custTenant = tenant || data.SourceTenantHost || process.env.ERP_URL;
var uri =
custTenant +
"/sap/byd/odata/cust/v1/khcustomerinvoice/CustomerInvoiceCollection('" +
custInvObjID +
"')";
//Set HTTP Request Options
var options = {
uri: uri,
headers: {
Authorization: "Basic " + process.env.BYD_B64AUTH,
"x-csrf-token": "fetch",
},
};
//Make Request
console.log("Getting ByD token for " + uri);
req.get(options, function (error, response) {
if (!error && response.statusCode == 200) {
var xcsrftoken = response.headers["x-csrf-token"];
var xcsrfcookie = response.headers["set-cookie"];
console.log("Token and cookie retrieved successfully");
body = {
eInvSignature_SDK: signature[0].CAE + signature[0].CAEFchVto,
};
//Set HTTP Request Options
var options = {
uri: uri,
body: JSON.stringify(body),
headers: {
"Authorization": "Basic " + process.env.BYD_B64AUTH,
"x-csrf-token": xcsrftoken,
"Cookie": xcsrfcookie,
"x-http-method": "MERGE",
"Content-Type": "application/json",
},
};
//Make Request
console.log("Updating ByD Customer Invoice with AFIPs signature data " + uri);
req.post(options, function (error, response, body) {
if (!error && (response.statusCode == 200 || response.statusCode == 204)) {
callback(null, response.statusCode);
} else {
callback(response.statusMessage, response);
}
});
}
});
}
import ABSL;
// controls the invoice status and electronic invoice signature
if ((this.eInvSignature.Trim() == "") && (this.Status.ApprovalStatusCode == "3")){
raise Message_Cant_Release.Create("E");
return false;
};
return true;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 |