diff --git a/entity/Offeritem_entity/Offeritem_entity.aod b/entity/Offeritem_entity/Offeritem_entity.aod index 539426a9accdeccf35ae7df22f09485107038217..d79f7aa05eea2a03bc5ca7c424efba757e1482d5 100644 --- a/entity/Offeritem_entity/Offeritem_entity.aod +++ b/entity/Offeritem_entity/Offeritem_entity.aod @@ -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> diff --git a/entity/Offeritem_entity/afterSave.js b/entity/Offeritem_entity/afterSave.js new file mode 100644 index 0000000000000000000000000000000000000000..0fc435de6530b8e80d7e205b331ace1191a336ac --- /dev/null +++ b/entity/Offeritem_entity/afterSave.js @@ -0,0 +1,44 @@ +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); + } +} diff --git a/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js b/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js index 0c21ed1243a9982c6067b1ee46134dfcee02cf88..5a02db4f37aed6f50518823f220499af44fe47e5 100644 --- a/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js @@ -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 } diff --git a/entity/Orderitem_entity/Orderitem_entity.aod b/entity/Orderitem_entity/Orderitem_entity.aod index a22087028d3fb3ac617b40b7989e5cb94a5b6d3b..2dc1a55d4ab8f98ee61dcf266876cb12414bb061 100644 --- a/entity/Orderitem_entity/Orderitem_entity.aod +++ b/entity/Orderitem_entity/Orderitem_entity.aod @@ -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> diff --git a/entity/Orderitem_entity/afterSave.js b/entity/Orderitem_entity/afterSave.js new file mode 100644 index 0000000000000000000000000000000000000000..6025f5a1c7b7a29b289a59e64cf962741de7efb9 --- /dev/null +++ b/entity/Orderitem_entity/afterSave.js @@ -0,0 +1,24 @@ +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); +} diff --git a/entity/Orderitem_entity/recordcontainers/db/onDBUpdate.js b/entity/Orderitem_entity/recordcontainers/db/onDBUpdate.js index d96eedd5e3d6e49302083d0d3ba84dee5874bdc1..b895f0d7cd0bd3edbf0cdc28a900204644013cd3 100644 --- a/entity/Orderitem_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/Orderitem_entity/recordcontainers/db/onDBUpdate.js @@ -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 } } diff --git a/process/OfferOrder_lib/process.js b/process/OfferOrder_lib/process.js index 7d890d2866c7f074a10c13b8506608fec261502d..567c87350b049c3f212d5782cdb6aeb3bbe77f68 100644 --- a/process/OfferOrder_lib/process.js +++ b/process/OfferOrder_lib/process.js @@ -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 + } diff --git a/process/Offer_lib/process.js b/process/Offer_lib/process.js index 15c7e2f1a7843a5e40784d64a04249acff3a2cd8..4f4be22c23c572b7d6cdf2ef79027dab7cfa60a0 100644 --- a/process/Offer_lib/process.js +++ b/process/Offer_lib/process.js @@ -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") diff --git a/process/Order_lib/process.js b/process/Order_lib/process.js index 802648b9ffade4f8e137f796eb5722f5b11e4381..3cfcb2dc8c4f8cc328d1897faad8ef8173eaa509 100644 --- a/process/Order_lib/process.js +++ b/process/Order_lib/process.js @@ -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]); }