Skip to content
Snippets Groups Projects
Commit dac9c522 authored by Sebastian Pongratz's avatar Sebastian Pongratz :ping_pong:
Browse files

Merge branch 'sales_2000947_angebot_beleg_performance' into '2021.2.2'

[Projekt: xRM-Sales][TicketNr.: 2000947][Performance Angebot / Beleg MultiEditView]

See merge request xrm/basic!1537
parents c0f571aa 66e10336
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@
<grantCreateProcess>%aditoprj%/entity/Offeritem_entity/grantCreateProcess.js</grantCreateProcess>
<grantUpdateProcess>%aditoprj%/entity/Offeritem_entity/grantUpdateProcess.js</grantUpdateProcess>
<grantDeleteProcess>%aditoprj%/entity/Offeritem_entity/grantDeleteProcess.js</grantDeleteProcess>
<afterSave>%aditoprj%/entity/Offeritem_entity/afterSave.js</afterSave>
<titlePlural>Offeritems</titlePlural>
<recordContainer>db</recordContainer>
<entityFields>
......@@ -24,8 +25,8 @@
<contentType>NUMBER</contentType>
<outputFormat>0.00'%'</outputFormat>
<inputFormat>0.00</inputFormat>
<titleProcess>%aditoprj%/entity/Offeritem_entity/entityfields/discount/titleProcess.js</titleProcess>
<mandatory v="true" />
<titleProcess>%aditoprj%/entity/Offeritem_entity/entityfields/discount/titleProcess.js</titleProcess>
<onValidation>%aditoprj%/entity/Offeritem_entity/entityfields/discount/onValidation.js</onValidation>
</entityField>
<entityField>
......
import("system.neon");
import("system.entities");
import("system.vars");
import("Sql_lib");
if(vars.get("$local.recordstate") == neon.OPERATINGSTATE_EDIT)
{
var offerId = vars.get("$field.OFFER_ID");
var offerItemUtils = new OfferItemUtils(offerId);
offerItemUtils.initItemTree();
var childIds = new Set();
function _traverseChilds(pId)
{
if(!childIds.has(pId))
{
childIds.add(pId);
if(pId in offerItemUtils.ItemTree)
{
// catch errors if the item tree got calculated while inserting / deleting items
offerItemUtils.ItemTree[pId].ids.forEach(_traverseChilds);
}
}
}
_traverseChilds(vars.get("$sys.uid"));
newWhere("OFFERITEM.OFFERITEMID", Array.from(childIds), SqlBuilder.IN())
.updateFields({"SHOWPRICE": vars.get("$field.SHOWPRICE")});
if(!vars.get("$field.ITEMPOSITION").includes("."))//only the topItems affect the Offer price
{
var discount = vars.exists("$param.Discount_param") ? vars.get("$param.Discount_param"): "";
var cols = ["NET", "VAT"];
var vals = offerItemUtils.getNetAndVat();
var fieldValues = {
NET: vals[0].toString(),
VAT: vals[1].toString()
};
var config = entities.createConfigForUpdatingRows();
config.entity("Offer_entity");
config.uid(offerId);
config.fieldValues(fieldValues);
entities.updateRow(config);
}
}
......@@ -6,78 +6,39 @@ import("system.neon");
import("Offer_lib");
import("Sql_lib");
var offerId = vars.get("$field.OFFER_ID");
if(offerId != "")
// this processs get's executed for every child of this offerItem since we use writeEntiy, so we use the param to make sure we don't execute it for the children
var newQuanitity = parseFloat(vars.get("$field.QUANTITY"));
var oldQuantity = parseFloat(vars.get("$local.initialRowdata")["OFFERITEM.QUANTITY"]);
var offerItemId = vars.get("$field.OFFERITEMID");
if(newQuanitity != oldQuantity) //quantity changed -> change quantities of the childitems accordingly
{
var offerItemUtils = new OfferItemUtils(offerId);
offerItemUtils.initItemTree();
var childIds = new Set();
function _traverseChilds(pId)
{
if(!childIds.has(pId))
{
childIds.add(pId);
offerItemUtils.ItemTree[pId].ids.forEach(_traverseChilds);
}
}
_traverseChilds(vars.get("$sys.uid"));
newWhere("OFFERITEM.OFFERITEMID", Array.from(childIds), SqlBuilder.IN())
.updateFields({"SHOWPRICE": vars.get("$field.SHOWPRICE")});
if(!vars.get("$field.ITEMPOSITION").includes("."))//only the topItems affect the Offer price
{
var discount = vars.exists("$param.Discount_param") ? vars.get("$param.Discount_param"): "";
var cols = ["NET", "VAT"];
var vals = offerItemUtils.getNetAndVat();
var fieldValues = {
NET: vals[0].toString(),
VAT: vals[1].toString()
};
var config = entities.createConfigForUpdatingRows();
config.entity("Offer_entity");
config.uid(offerId);
config.fieldValues(fieldValues);
entities.updateRow(config);
}
//this process get's executed for every child of this offerItem since we use writeEntiy, so we use the param to make sure we don't execute it for the children
if(vars.getString("$param.IgnoreOnUpdateProcess_param") != "true")
{
var newQuanitity = parseFloat(vars.get("$field.QUANTITY"));
var oldQuantity = parseFloat(vars.get("$local.initialRowdata")["OFFERITEM.QUANTITY"]);
var offerItemId = vars.get("$field.OFFERITEMID");
if(newQuanitity != oldQuantity) //quantity changed -> change quantities of the childitems accordingly
{
var multiplier = newQuanitity/oldQuantity;
var multiplier = newQuanitity/oldQuantity;
var loadConfig = entities.createConfigForLoadingRows().entity("Offeritem_entity").addParameter("OfferId_param", offerId).fields(["OFFERITEMID", "ASSIGNEDTO", "PRODUCT_ID", "QUANTITY"])
var loadConfig = entities.createConfigForLoadingRows().entity("Offeritem_entity").addParameter("OfferId_param", vars.get("$field.OFFER_ID")).fields(["OFFERITEMID", "ASSIGNEDTO", "PRODUCT_ID", "QUANTITY"])
var rows = entities.getRows(loadConfig);
var potentialAsignees = {};
var offerItemsToUpdate = {};
var statements = [];
var stop = false;
while(stop == false)//we have too loop for all the rows for each row that needs updating, since those are also pontially asignees
var rows = entities.getRows(loadConfig);
var potentialAsignees = {};
var offerItemsToUpdate = {};
var statements = [];
var stop = false;
while(stop == false)//we have too loop for all the rows for each row that needs updating, since those are also pontially asignees
{
stop = true;
for(var offeritem in rows)//loop trough all the rows and build offerItemsToUpdate
{
if(!(rows[offeritem]["OFFERITEMID"] in offerItemsToUpdate) &&(rows[offeritem]["ASSIGNEDTO"] == offerItemId || rows[offeritem]["ASSIGNEDTO"] in potentialAsignees))
{
stop = true;
for(var offeritem in rows)//loop trough all the rows and build offerItemsToUpdate
{
if(!(rows[offeritem]["OFFERITEMID"] in offerItemsToUpdate) &&(rows[offeritem]["ASSIGNEDTO"] == offerItemId || rows[offeritem]["ASSIGNEDTO"] in potentialAsignees))
{
statements.push(
newWhere("OFFERITEM.OFFERITEMID", rows[offeritem]["OFFERITEMID"]).buildUpdateStatement({
"QUANTITY": parseInt(rows[offeritem]["QUANTITY"])*multiplier
})
);
offerItemsToUpdate[rows[offeritem]["OFFERITEMID"]] = parseInt(rows[offeritem]["QUANTITY"])*multiplier;
potentialAsignees[rows[offeritem]["OFFERITEMID"]] = "";
statements.push(
newWhere("OFFERITEM.OFFERITEMID", rows[offeritem]["OFFERITEMID"]).buildUpdateStatement({
"QUANTITY": parseInt(rows[offeritem]["QUANTITY"])*multiplier
})
);
offerItemsToUpdate[rows[offeritem]["OFFERITEMID"]] = parseInt(rows[offeritem]["QUANTITY"])*multiplier;
potentialAsignees[rows[offeritem]["OFFERITEMID"]] = "";
stop = false;
}
}
stop = false;
}
db.execute(statements);// no write entity -> performance reason
}
}
db.execute(statements);// no write entity -> performance reason
}
......@@ -10,6 +10,7 @@
<grantCreateProcess>%aditoprj%/entity/Orderitem_entity/grantCreateProcess.js</grantCreateProcess>
<grantUpdateProcess>%aditoprj%/entity/Orderitem_entity/grantUpdateProcess.js</grantUpdateProcess>
<grantDeleteProcess>%aditoprj%/entity/Orderitem_entity/grantDeleteProcess.js</grantDeleteProcess>
<afterSave>%aditoprj%/entity/Orderitem_entity/afterSave.js</afterSave>
<titlePlural>Orderitems</titlePlural>
<recordContainer>db</recordContainer>
<entityFields>
......@@ -24,9 +25,9 @@
<contentType>NUMBER</contentType>
<outputFormat>0.00'%'</outputFormat>
<inputFormat>0.00</inputFormat>
<mandatory v="true" />
<titleProcess>%aditoprj%/entity/Orderitem_entity/entityfields/discount/titleProcess.js</titleProcess>
<onValidation>%aditoprj%/entity/Orderitem_entity/entityfields/discount/onValidation.js</onValidation>
<mandatory v="true" />
</entityField>
<entityField>
<name>GROUPCODEID</name>
......
import("system.neon");
import("system.vars");
import("system.entities");
import("Order_lib");
if(vars.get("$local.recordstate") == neon.OPERATINGSTATE_EDIT)
{
var oid = vars.get("$field.SALESORDER_ID");
var discount = vars.exists("$param.Discount_param") ? vars.get("$param.Discount_param"): "";
var cols = ["NET", "VAT"];
var oiUtils = new OrderItemUtils(oid);
var vals = oiUtils.getNetAndVat();
var fieldValues = {
NET: vals[0].toString(),
VAT: vals[1].toString()
};
var config = entities.createConfigForUpdatingRows();
config.entity("Order_entity");
config.uid(oid);
config.fieldValues(fieldValues);
entities.updateRow(config);
}
......@@ -5,66 +5,43 @@ import("system.db");
import("system.neon");
import("Order_lib");
import("Sql_lib");
var oid = vars.get("$field.SALESORDER_ID");
if(oid != "")
{
if(!vars.get("$field.ITEMPOSITION").includes("."))//only the topItems affect the Order price
{
var discount = vars.exists("$param.Discount_param") ? vars.get("$param.Discount_param"): "";
var cols = ["NET", "VAT"];
var oiUtils = new OrderItemUtils(oid);
var vals = oiUtils.getNetAndVat();
var fieldValues = {
NET: vals[0].toString(),
VAT: vals[1].toString()
};
var config = entities.createConfigForUpdatingRows();
config.entity("Order_entity");
config.uid(oid);
config.fieldValues(fieldValues);
entities.updateRow(config);
}
//this process get's executed for every child of this orderItem since we use writeEntiy, so we use the param to make sure we don't execute it for the children
if(vars.getString("$param.IgnoreOnUpdateProcess_param") != "true")
//this process get's executed for every child of this orderItem since we use writeEntiy, so we use the param to make sure we don't execute it for the children
if(vars.getString("$param.IgnoreOnUpdateProcess_param") != "true")
{
var newQuanitity = parseFloat(vars.get("$field.QUANTITY"));
var oldQuantity = parseFloat(vars.get("$local.initialRowdata")["SALESORDERITEM.QUANTITY"]);
var orderItemId = vars.get("$field.SALESORDERITEMID");
if(newQuanitity != oldQuantity) //quantity changed -> change quantities of the childitems accordingly
{
var newQuanitity = parseFloat(vars.get("$field.QUANTITY"));
var oldQuantity = parseFloat(vars.get("$local.initialRowdata")["SALESORDERITEM.QUANTITY"]);
var orderItemId = vars.get("$field.SALESORDERITEMID");
if(newQuanitity != oldQuantity) //quantity changed -> change quantities of the childitems accordingly
{
var multiplier = newQuanitity/oldQuantity;
var multiplier = newQuanitity/oldQuantity;
var loadConfig = entities.createConfigForLoadingRows().entity("Orderitem_entity").addParameter("OrderId_param", oid).fields(["SALESORDERITEMID", "ASSIGNEDTO", "PRODUCT_ID", "QUANTITY"])
var loadConfig = entities.createConfigForLoadingRows().entity("Orderitem_entity").addParameter("OrderId_param", vars.get("$field.SALESORDER_ID")).fields(["SALESORDERITEMID", "ASSIGNEDTO", "PRODUCT_ID", "QUANTITY"])
var rows = entities.getRows(loadConfig);
var potentialAsignees = {};
var orderItemsToUpdate = {};
var statements = [];
var stop = false;
while(stop == false)//we have too loop for all the rows for each row that needs updating, since those are also pontially asignees
var rows = entities.getRows(loadConfig);
var potentialAsignees = {};
var orderItemsToUpdate = {};
var statements = [];
var stop = false;
while(stop == false)//we have too loop for all the rows for each row that needs updating, since those are also pontially asignees
{
stop = true;
for(var orderitem in rows)//loop trough all the rows and build orderItemsToUpdate
{
stop = true;
for(var orderitem in rows)//loop trough all the rows and build orderItemsToUpdate
if(!(rows[orderitem]["SALESORDERITEMID"] in orderItemsToUpdate) &&(rows[orderitem]["ASSIGNEDTO"] == orderItemId || rows[orderitem]["ASSIGNEDTO"] in potentialAsignees))
{
if(!(rows[orderitem]["SALESORDERITEMID"] in orderItemsToUpdate) &&(rows[orderitem]["ASSIGNEDTO"] == orderItemId || rows[orderitem]["ASSIGNEDTO"] in potentialAsignees))
{
statements.push(
newWhere("SALESORDERITEM.SALESORDERITEMID", rows[orderitem]["SALESORDERITEMID"]).buildUpdateStatement({
"QUANTITY": parseInt(rows[orderitem]["QUANTITY"])*multiplier
})
);
orderItemsToUpdate[rows[orderitem]["SALESORDERITEMID"]] = parseInt(rows[orderitem]["QUANTITY"])*multiplier;
potentialAsignees[rows[orderitem]["SALESORDERITEMID"]] = "";
statements.push(
newWhere("SALESORDERITEM.SALESORDERITEMID", rows[orderitem]["SALESORDERITEMID"]).buildUpdateStatement({
"QUANTITY": parseInt(rows[orderitem]["QUANTITY"])*multiplier
})
);
orderItemsToUpdate[rows[orderitem]["SALESORDERITEMID"]] = parseInt(rows[orderitem]["QUANTITY"])*multiplier;
potentialAsignees[rows[orderitem]["SALESORDERITEMID"]] = "";
stop = false;
}
stop = false;
}
}
db.execute(statements);// no write entity -> performance reason
}
db.execute(statements);// no write entity -> performance reason
}
}
......@@ -354,7 +354,8 @@ ItemUtils.prototype.insertPartsList = function(columns, productId, assignedTo, c
//recursive function for building item insert statements
function __itemInsertStatement(partsListObj, assignedTo, currency, contactId) {
for (var i = 0; i < partsListObj.ids.length; i++) {
for (var i = 0; i < partsListObj.ids.length; i++)
{
var newid = util.getNewUUID();
self._appendNode(newid, assignedTo);
var pos = self.ItemTree[newid].pos;
......@@ -383,7 +384,6 @@ ItemUtils.prototype.insertPartsList = function(columns, productId, assignedTo, c
priceObject[newid]["vat"] = vat;
priceObject[newid]["quantity"] = P2pObject["quantity"];
}
}
else if(pSumUpPrices)//also build priceObject if pSumUpPrices is set to true
{
......@@ -396,16 +396,19 @@ ItemUtils.prototype.insertPartsList = function(columns, productId, assignedTo, c
treeStructure = ItemUtils.buildTreeStructure(treeStructure, assignedTo, newid);
}
var vals = [newid
, self.offerOrderId
, prodid
, ProductDetails.groupCode
, assignedTo
, ProductDetails.productName
, ProductDetails.unit
, price
, vat == null || vat == undefined || vat == "" ? 0 : vat
, P2pObject.quantity];
var vals = [
newid,
self.offerOrderId,
prodid,
ProductDetails.groupCode,
assignedTo,
ProductDetails.productName,
ProductDetails.unit,
price,
vat == null || vat == undefined || vat == "" ? 0 : vat,
P2pObject.quantity,
"0"
];
if(_optionalIsIncluded(columns) == true)//add optional if needed
......@@ -913,4 +916,4 @@ ItemUtils.getNode = function (pObject, pName, pCurrName){
return res;
}
return null;
}
\ No newline at end of file
}
......@@ -592,19 +592,22 @@ OfferItemUtils.prototype.roundPrice = function(pPrice) {
OfferItemUtils.prototype.insertPartsList = function(pProductId, pAssignedTo, pCurrency, pContactId, pLanguage, pQuantity, pSumUpPrices, pOfferId, pSumUpTopPrice) {
this.initItemTree();
var cols = ["OFFERITEMID"
, "OFFER_ID"
, "PRODUCT_ID"
, "GROUPCODEID"
, "ASSIGNEDTO"
, "ITEMNAME"
, "UNIT"
, "PRICE"
, "VAT"
, "QUANTITY"
, "OPTIONAL"
, "ITEMPOSITION"
, "ITEMSORT"];
var cols = [
"OFFERITEMID",
"OFFER_ID",
"PRODUCT_ID",
"GROUPCODEID",
"ASSIGNEDTO",
"ITEMNAME",
"UNIT",
"PRICE",
"VAT",
"QUANTITY",
"DISCOUNT",
"OPTIONAL",
"ITEMPOSITION",
"ITEMSORT"
];
return ItemUtils.prototype.insertPartsList.apply(this, [cols, pProductId, pAssignedTo, pCurrency, pContactId, [[["info", "INFO"], ["info",
"( " + newSelect("DESCRIPTION")
......
......@@ -704,18 +704,21 @@ OrderItemUtils.prototype.roundPrice = function(pPrice) {
OrderItemUtils.prototype.insertPartsList = function(pProductId, pAssignedTo, pCurrency, pContactId, pQuantity, pSumUpPrices, pOrderId, pSumUpTopPrice) {
this.initItemTree();
var cols = ["SALESORDERITEMID"
, "SALESORDER_ID"
, "PRODUCT_ID"
, "GROUPCODEID"
, "ASSIGNEDTO"
, "ITEMNAME"
, "UNIT"
, "PRICE"
, "VAT"
, "QUANTITY"
, "ITEMPOSITION"
, "ITEMSORT"];
var cols = [
"SALESORDERITEMID",
"SALESORDER_ID",
"PRODUCT_ID",
"GROUPCODEID",
"ASSIGNEDTO",
"ITEMNAME",
"UNIT",
"PRICE",
"VAT",
"QUANTITY",
"DISCOUNT",
"ITEMPOSITION",
"ITEMSORT"
];
return ItemUtils.prototype.insertPartsList.apply(this, [cols, pProductId, pAssignedTo, pCurrency, pContactId, undefined, pQuantity, pSumUpPrices, "Order", pOrderId, pAssignedTo, pSumUpTopPrice, true]);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment