diff --git a/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js b/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js index a86dd0453eef51446501a4f8119e4896ee27fa68..4e1864a66569e6d69cea44d9153098241b69e2d5 100644 --- a/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js @@ -9,31 +9,38 @@ import("Sql_lib"); var oid = vars.get("$field.OFFER_ID"); if(oid != "") { - var discount = vars.exists("$param.Discount_param") ? vars.get("$param.Discount_param"): ""; - var cols = ["NET", "VAT"]; - var oiUtils = new OfferItemUtils(oid); - var vals = oiUtils.getNetAndVat(); - var discountedVals = OfferItemUtils.getDiscountedNet(null, oid, discount); - - let config = entities.createConfigForUpdatingRows() - config.entity("Offer_entity"); - - if(discountedVals){ - config.fieldValues({ - "NET": vals[0], - "VAT": vals[1], - "DISCOUNTED_NET": discountedVals[0], - "DISCOUNTED_VAT": discountedVals[1] - }); - } - else{ - config.fieldValues({ - "NET": vals[0], - "VAT": vals[1] - }); + 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 oiUtils = new OfferItemUtils(oid); + var vals = oiUtils.getNetAndVat(); + var discountedVals = OfferItemUtils.getDiscountedNet(null, oid, discount); + + let config = entities.createConfigForUpdatingRows() + config.entity("Offer_entity"); + + if(discountedVals) + { + config.fieldValues({ + "NET": vals[0], + "VAT": vals[1], + "DISCOUNTED_NET": discountedVals[0], + "DISCOUNTED_VAT": discountedVals[1] + }); + } + else + { + config.fieldValues({ + "NET": vals[0], + "VAT": vals[1] + }); + } + + config.uid(oid); + entities.updateRow(config); } - config.uid(oid); - 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") { @@ -47,29 +54,30 @@ if(oid != "") var loadConfig = entities.createConfigForLoadingRows().entity("Offeritem_entity").addParameter("OfferId_param", oid).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 forall the rows for each row that needs updating, since those are also pontially asignees + 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)) { + 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; } } } - - var updateConfig = entities.createConfigForUpdatingRows().entity("Offeritem_entity").addParameter("OfferId_param", oid).addParameter("IgnoreOnUpdateProcess_param", true); - for(var object_Id in offerItemsToUpdate) - { - entities.updateRow(updateConfig.fieldValues({"QUANTITY": offerItemsToUpdate[object_Id]}).uid(object_Id)) - } + db.execute(statements);// no write entity -> performance reason } } } \ No newline at end of file diff --git a/entity/Orderitem_entity/recordcontainers/db/onDBUpdate.js b/entity/Orderitem_entity/recordcontainers/db/onDBUpdate.js index 55517585ef0974dec7e7964e713775ebf6a944c6..ad90012920fe399e0a1685a840660d68e656adef 100644 --- a/entity/Orderitem_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/Orderitem_entity/recordcontainers/db/onDBUpdate.js @@ -8,32 +8,35 @@ import("Sql_lib"); var oid = vars.get("$local.rowdata")["SALESORDERITEM.SALESORDER_ID"]; if(oid != "") { - var discount = vars.exists("$param.Discount_param") ? vars.get("$param.Discount_param"): ""; - var oiUtils = new OrderItemUtils(oid); - var vals = oiUtils.getNetAndVat(); - var discountedVals = OrderItemUtils.getDiscountedNet(null, oid, discount); - - let config = entities.createConfigForUpdatingRows() - config.entity("Order_entity"); - - if(discountedVals){ - config.fieldValues({ - "NET": vals[0], - "VAT": vals[1], - "DISCOUNTED_NET": discountedVals[0], - "DISCOUNTED_VAT": discountedVals[1] - }); - } - else + if(!vars.get("$field.ITEMPOSITION").includes("."))//only the topItems affect the Order price { - config.fieldValues({ - "NET": vals[0], - "VAT": vals[1] - }); - } - config.uid(oid); - entities.updateRow(config); + var discount = vars.exists("$param.Discount_param") ? vars.get("$param.Discount_param"): ""; + var oiUtils = new OrderItemUtils(oid); + var vals = oiUtils.getNetAndVat(); + var discountedVals = OrderItemUtils.getDiscountedNet(null, oid, discount); + let config = entities.createConfigForUpdatingRows() + config.entity("Order_entity"); + + if(discountedVals) + { + config.fieldValues({ + "NET": vals[0], + "VAT": vals[1], + "DISCOUNTED_NET": discountedVals[0], + "DISCOUNTED_VAT": discountedVals[1] + }); + } + else + { + config.fieldValues({ + "NET": vals[0], + "VAT": vals[1] + }); + } + config.uid(oid); + 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") @@ -51,6 +54,7 @@ if(oid != "") var potentialAsignees = {}; var offerItemsToUpdate = {}; + var statements = []; var stop = false; while(stop == false)//we have too loop forall the rows for each row that needs updating, since those are also pontially asignees { @@ -59,18 +63,18 @@ if(oid != "") { if(!(rows[offeritem]["SALESORDERITEMID"] 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]["SALESORDERITEMID"]] = parseInt(rows[offeritem]["QUANTITY"])*multiplier; potentialAsignees[rows[offeritem]["SALESORDERITEMID"]] = ""; stop = false; } } } - - var updateConfig = entities.createConfigForUpdatingRows().entity("Orderitem_entity").addParameter("OrderId_param", oid).addParameter("IgnoreOnUpdateProcess_param", true); - for(var object_Id in offerItemsToUpdate) - { - entities.updateRow(updateConfig.fieldValues({"QUANTITY": offerItemsToUpdate[object_Id]}).uid(object_Id)) - } + db.execute(statements);// no write entity -> performance reason } } } \ No newline at end of file