Skip to content
Snippets Groups Projects
Commit 9d012194 authored by Pascal Neub's avatar Pascal Neub
Browse files

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

parent 60885dbb
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);
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
}
}
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