diff --git a/entity/Productprice_entity/onValidation.js b/entity/Productprice_entity/onValidation.js index de8f835701b17f6247e266a035faf4d426b10fcc..bc32d44d44f0f4508f4a090173f1f855c2fd3bd5 100644 --- a/entity/Productprice_entity/onValidation.js +++ b/entity/Productprice_entity/onValidation.js @@ -1,3 +1,4 @@ +import("Util_lib"); import("system.datetime"); import("system.eMath"); import("system.translate"); @@ -28,11 +29,26 @@ if(vars.getString("$param.IgnoreOnValidation_param") != "true") // (A) |-------| -> |-----| // (B) |---------| -> |---------| // - //There is another case we cannot handle as easy: - // if priceB's validFrom is after the validFrom of priceA and it's validTo is also before the validTo of priceA - // -> catch this case in the onValidation, since the only solution would be to delete priceB + // + //There are four other cases we cannot handle as easy: + //-If priceB's validFrom is after the validFrom of priceA and it's validTo is also before the validTo of priceA // (A) |----| -> handle in onValidation // (B) |-------------| -> handle in onValidation + // + //-If priceB's validFrom is the same as the validFrom of priceA (no matter what their validTo values are) + // (A) |----| -> handle in onValidation + // (B) |-------------| -> handle in onValidation + // + //-If priceB's validTo is the same as the validTo of priceA (no matter what their validFrom values are) + // (A) |----| -> handle in onValidation + // (B) |-------------| -> handle in onValidation + // + //-If priceB's validFrom is the same as the validFrom of priceA and priceB's validTo is the same as the validTo of priceA + // (A) |-------| -> handle in onValidation + // (B) |-------| -> handle in onValidation + // + //-> catch those case in the onValidation, since the only solution would be to delete priceA + // else if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW) { var priceList = vars.get("$field.PRICELIST"); @@ -56,36 +72,20 @@ if(vars.getString("$param.IgnoreOnValidation_param") != "true") var priceListsToReplace1 = []; var priceListsToReplace2 = []; - var showMessage = false; for (var valPriceList in priceListsToPotentiallyReplace) { var currPriceList = priceListsToPotentiallyReplace[valPriceList]; if(currPriceList["priceList"] == priceList && currPriceList["buySell"] == buySell && Number.parseInt(currPriceList["fromQuantity"]) == Number.parseInt(quantity) && - currPriceList["relationId"] == vars.get("$param.ContactId_param") && - currPriceList["currency"] == currency) + (currPriceList["relationId"] == vars.get("$param.ContactId_param") + || Utils.isNullOrEmptyString(currPriceList["relationId"]) && Utils.isNullOrEmptyString(vars.get("$param.ContactId_param"))) + && currPriceList["currency"] == currency) { - if(currPriceList["validFrom"] > validFrom && ((validTo == undefined || validTo == "") || - (currPriceList["validTo"] != undefined && currPriceList["validTo"] != "" && currPriceList["validTo"] < validTo))) - { - showMessage = true; - break; - } - else if(eMath.addInt(currPriceList["validFrom"], datetime.ONE_DAY) == currPriceList["validTo"]) + if(currPriceList["validFrom"] <= validFrom && (validTo >= currPriceList["validTo"] || Utils.isNotNullOrEmptyString(currPriceList["validTo"]))) { - showMessage = true; - break; - } - else if(currPriceList["validFrom"] == validFrom && validTo == currPriceList["validTo"]) - { - showMessage = true; - break; + result.string(translate.withArguments("There already exists a %0 price with the same type of pricelist, quantity and currency in the defined range.", [vars.get("$field.BUYSELL")])); } } } - if(showMessage) - { - result.string(translate.withArguments("There already exists a %0 price with the same type of pricelist, quantity and currency in the defined range.", [vars.get("$field.BUYSELL")])); - } } } \ No newline at end of file