diff --git a/entity/Offeritem_entity/Offeritem_entity.aod b/entity/Offeritem_entity/Offeritem_entity.aod index 236c205986cbdc9106c1762473cc0b5b4e177a92..ec65a90423205f31166d1a795db73f3dc4631bec 100644 --- a/entity/Offeritem_entity/Offeritem_entity.aod +++ b/entity/Offeritem_entity/Offeritem_entity.aod @@ -18,6 +18,7 @@ <title>Discount %</title> <contentType>NUMBER</contentType> <outputFormat>#,##0</outputFormat> + <onValidation>%aditoprj%/entity/Offeritem_entity/entityfields/discount/onValidation.js</onValidation> </entityField> <entityField> <name>GROUPCODEID</name> @@ -68,6 +69,7 @@ <title>Article</title> <consumer>Products</consumer> <linkedContext>Product</linkedContext> + <mandatory v="true" /> <displayValueProcess>%aditoprj%/entity/Offeritem_entity/entityfields/product_id/displayValueProcess.js</displayValueProcess> <onValueChange>%aditoprj%/entity/Offeritem_entity/entityfields/product_id/onValueChange.js</onValueChange> <onValueChangeTypes> @@ -80,6 +82,7 @@ <title>Quantity</title> <contentType>NUMBER</contentType> <outputFormat>#</outputFormat> + <mandatory v="true" /> <valueProcess>%aditoprj%/entity/Offeritem_entity/entityfields/quantity/valueProcess.js</valueProcess> <onValidation>%aditoprj%/entity/Offeritem_entity/entityfields/quantity/onValidation.js</onValidation> <onValueChange>%aditoprj%/entity/Offeritem_entity/entityfields/quantity/onValueChange.js</onValueChange> diff --git a/entity/Offeritem_entity/entityfields/discount/onValidation.js b/entity/Offeritem_entity/entityfields/discount/onValidation.js new file mode 100644 index 0000000000000000000000000000000000000000..18bd49fe0d794b001de74fb1caa24930f6adc7e2 --- /dev/null +++ b/entity/Offeritem_entity/entityfields/discount/onValidation.js @@ -0,0 +1,13 @@ +import("system.result"); +import("system.vars"); +import("Util_lib"); +import("Entity_lib"); + +var value = ProcessHandlingUtils.getOnValidationValue(vars.get("$field.DISCOUNT")); + +var validationResult = NumberUtils.validateIsInside("Discount", value, 0, 100); + +if (validationResult) +{ + result.string(validationResult); +} \ No newline at end of file diff --git a/entity/Offeritem_entity/entityfields/quantity/onValidation.js b/entity/Offeritem_entity/entityfields/quantity/onValidation.js index aa24a80d84388aa03c991aec88bafe3333d5b990..a7fe04aaf506c2edfba1e2d74b644c3da785a6d1 100644 --- a/entity/Offeritem_entity/entityfields/quantity/onValidation.js +++ b/entity/Offeritem_entity/entityfields/quantity/onValidation.js @@ -1,16 +1,12 @@ -import("system.logging"); -import("system.translate"); -import("system.result"); -import("system.vars"); -import("Entity_lib"); - -logging.log("valid test 1: " + vars.get("$field.QUANTITY")); - -var quatity = vars.exists("$field.QUANTITY") ? vars.get("$field.QUANTITY") : ""; -quatity = ProcessHandlingUtils.getOnValidationValue(quatity); - -if (parseInt(quatity) <= 0) -{ - logging("valid test 2: " + vars.get("$field.QUANTITY")); - result.string(translate.text("${QUANTITY_LOWER_THAN_1}")); -} +import("system.translate"); +import("system.result"); +import("system.vars"); +import("Entity_lib"); + +var quatity = vars.exists("$field.QUANTITY") ? vars.get("$field.QUANTITY") : ""; +quatity = ProcessHandlingUtils.getOnValidationValue(quatity); + +if (parseInt(quatity) <= 0) +{ + result.string(translate.text("${QUANTITY_LOWER_THAN_1}")); +} diff --git a/entity/Offeritem_entity/entityfields/quantity/onValueChange.js b/entity/Offeritem_entity/entityfields/quantity/onValueChange.js index dea8c2c6691264867d11dadaec837f3fc8473c28..5076a258429919fff7eefdabaacaeb6536416898 100644 --- a/entity/Offeritem_entity/entityfields/quantity/onValueChange.js +++ b/entity/Offeritem_entity/entityfields/quantity/onValueChange.js @@ -1,37 +1,36 @@ -import("system.logging"); -import("system.vars"); -import("system.neon"); -import("Product_lib"); -import("Util_lib"); -import("Entity_lib"); -import("Attribute_lib"); - -var pid = vars.get("$field.PRODUCT_ID"); -var newQuantity = ProcessHandlingUtils.getOnValidationValue(vars.get("$field.QUANTITY")); -if(pid != "" && newQuantity != "") -{ - var curr = vars.exists("$param.Currency_param") ? vars.get("$param.Currency_param") : ""; - var contactid = vars.exists("$param.ContactId_param") ? vars.get("$param.ContactId_param") : ""; - var pricelist = AttributeRelationUtils.getAttribute("97b449a5-d9b4-42ff-b9b0-4f8b27b8a9ec", contactid) || ""; - - var PriceListFilter = { currency: curr, quantity: newQuantity, relationId: contactid, priceList: pricelist }; - - var ProductDetails = ProductUtils.getProductDetails(pid, PriceListFilter); - - if(ProductDetails.productId != undefined && ProductDetails.PriceListToUse != null) - { - vars.set("$field.PRICE", ProductDetails.PriceListToUse.price); - vars.set("$field.VAT", ProductDetails.PriceListToUse.vat); - } -} - - -//checks if the value is <= 0, if so fallback to 1 -var quatity = vars.exists("$field.QUANTITY") ? vars.get("$field.QUANTITY") : ""; -quatity = ProcessHandlingUtils.getOnValidationValue(quatity); - -if (parseInt(quatity) <= 0) -{ - neon.setFieldValue("$field.QUANTITY", "1"); -} +import("system.vars"); +import("system.neon"); +import("Product_lib"); +import("Util_lib"); +import("Entity_lib"); +import("Attribute_lib"); + +var pid = vars.get("$field.PRODUCT_ID"); +var newQuantity = ProcessHandlingUtils.getOnValidationValue(vars.get("$field.QUANTITY")); +if(pid != "" && newQuantity != "") +{ + var curr = vars.exists("$param.Currency_param") ? vars.get("$param.Currency_param") : ""; + var contactid = vars.exists("$param.ContactId_param") ? vars.get("$param.ContactId_param") : ""; + var pricelist = AttributeRelationUtils.getAttribute("97b449a5-d9b4-42ff-b9b0-4f8b27b8a9ec", contactid) || ""; + + var PriceListFilter = { currency: curr, quantity: newQuantity, relationId: contactid, priceList: pricelist }; + + var ProductDetails = ProductUtils.getProductDetails(pid, PriceListFilter); + + if(ProductDetails.productId != undefined && ProductDetails.PriceListToUse != null) + { + vars.set("$field.PRICE", ProductDetails.PriceListToUse.price); + vars.set("$field.VAT", ProductDetails.PriceListToUse.vat); + } +} + + +//checks if the value is <= 0, if so fallback to 1 +var quatity = vars.exists("$field.QUANTITY") ? vars.get("$field.QUANTITY") : ""; +quatity = ProcessHandlingUtils.getOnValidationValue(quatity); + +if (parseInt(quatity) <= 0) +{ + neon.setFieldValue("$field.QUANTITY", "1"); +} \ No newline at end of file diff --git a/entity/Productprice_entity/entityfields/vat/onValidation.js b/entity/Productprice_entity/entityfields/vat/onValidation.js new file mode 100644 index 0000000000000000000000000000000000000000..974d4c311f5691f0540d7090425ad9af89e503ac --- /dev/null +++ b/entity/Productprice_entity/entityfields/vat/onValidation.js @@ -0,0 +1,13 @@ +import("system.result"); +import("system.vars"); +import("Util_lib"); +import("Entity_lib"); + +var value = ProcessHandlingUtils.getOnValidationValue(vars.get("$field.VAT")); + +var validationResult = NumberUtils.validateIsInside("VAT", value, 0, 100); + +if (validationResult) +{ + result.string(validationResult); +} \ No newline at end of file diff --git a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod index b9304b3e3d99a643ce7eb2bc23f2fb41bc7431b6..2e47678c93f3dddeefda74234d54858ec0eda251 100644 --- a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod +++ b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod @@ -2655,6 +2655,12 @@ <entry> <key>true</key> </entry> + <entry> + <key>Protected</key> + </entry> + <entry> + <key>${MIN_MAX_ERROR} field: %0, value: %1, min: %2, max: %3</key> + </entry> </keyValueMap> <font name="Dialog" style="0" size="11" /> <sqlModels> diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod index ea1f024278672d595eccfacd151cfc4f01e3a12d..355302ddf957a55e89b08120a87a40858b0fa337 100644 --- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod +++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod @@ -3416,6 +3416,13 @@ <entry> <key>true</key> </entry> + <entry> + <key>${MIN_MAX_ERROR} field: %0, value: %1, min: %2, max: %3</key> + <value>%0 muss zwischen %2 und %3 sein.</value> + </entry> + <entry> + <key>protected</key> + </entry> </keyValueMap> <font name="Dialog" style="0" size="11" /> </language> diff --git a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod index eb9613d23d4ee40cf7df3339fe11a1dcdcac88b7..f9ebdddbda0ecf0d22bc5b4ae5bcb3beb8f39416 100644 --- a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod +++ b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod @@ -1390,6 +1390,7 @@ </entry> <entry> <key>${ORGTYPE_OTHER}</key> + <value>Other</value> </entry> <entry> <key>Haiti</key> @@ -2185,6 +2186,7 @@ </entry> <entry> <key>${NUMBER}</key> + <value>Number</value> </entry> <entry> <key>Name \"%0\" already used for container \"%1\"</key> @@ -2680,6 +2682,13 @@ <entry> <key>true</key> </entry> + <entry> + <key>Protected</key> + </entry> + <entry> + <key>${MIN_MAX_ERROR} field: %0, value: %1, min: %2, max: %3</key> + <value>%0 has to be between %2 and %3.</value> + </entry> </keyValueMap> <font name="Dialog" style="0" size="11" /> </language> diff --git a/neonView/OfferitemEdit_view/OfferitemEdit_view.aod b/neonView/OfferitemEdit_view/OfferitemEdit_view.aod index 0286bfb270fc7be6b59ac1da8c48fd2fb5b66b9c..ff753701e689f5cb33c49e3d6a9ab5a8253cba60 100644 --- a/neonView/OfferitemEdit_view/OfferitemEdit_view.aod +++ b/neonView/OfferitemEdit_view/OfferitemEdit_view.aod @@ -33,6 +33,10 @@ <name>2b635ddb-d52c-4063-af11-aea8eeee151b</name> <entityField>PRICE</entityField> </entityFieldLink> + <entityFieldLink> + <name>4f339738-6358-463e-b941-3b2693ab115a</name> + <entityField>DISCOUNT</entityField> + </entityFieldLink> <entityFieldLink> <name>c0a22aa4-b09d-4d8b-8d24-1750eb7ba5ca</name> <entityField>VAT</entityField> @@ -47,5 +51,16 @@ </entityFieldLink> </fields> </genericViewTemplate> + <genericViewTemplate> + <name>Price</name> + <editMode v="true" /> + <entityField>#ENTITY</entityField> + <fields> + <entityFieldLink> + <name>9200df17-11e2-4a1a-babb-ea48c6f88a93</name> + <entityField>TotalPrice</entityField> + </entityFieldLink> + </fields> + </genericViewTemplate> </children> </neonView> diff --git a/neonView/OfferitemFilter_view/OfferitemFilter_view.aod b/neonView/OfferitemFilter_view/OfferitemFilter_view.aod index 9a10ee740ce8ba19b7d256a931642202ab381908..5ec130f3ba099046d1085a79662cd44687ff92ba 100644 --- a/neonView/OfferitemFilter_view/OfferitemFilter_view.aod +++ b/neonView/OfferitemFilter_view/OfferitemFilter_view.aod @@ -11,6 +11,7 @@ <children> <tableViewTemplate> <name>Offeritems</name> + <autoNewRow v="true" /> <entityField>#ENTITY</entityField> <columns> <neonTableColumn> @@ -49,6 +50,10 @@ <name>a31fd16c-4237-4cd9-a9de-2267f186d342</name> <entityField>INFO</entityField> </neonTableColumn> + <neonTableColumn> + <name>60a36c38-103f-4fdb-9e8a-b8fd6d441f14</name> + <entityField>TotalPrice</entityField> + </neonTableColumn> </columns> </tableViewTemplate> </children> diff --git a/process/Util_lib/process.js b/process/Util_lib/process.js index bc9a4fe69ff6cc652049381df2983ab42309967c..82af36de2bc840efdc3e4b56e245e38b24af0abe 100644 --- a/process/Util_lib/process.js +++ b/process/Util_lib/process.js @@ -38,6 +38,65 @@ StringUtils.concat = function(pSeparator, pElements) return res; }; +/** + * Class containing static utility functions for numbers + * Do not create an instance of this + * + * @class + */ +function NumberUtils(){} + +/** + * Check iv the value is inside of the min / max values. + * INCLUDING min / max + * + * @param {Number} pValue value to check + * @param {Number} pMin min value INCLUSIVE + * @param {Number} pMax max value INCLUSIVE + * @param {Boolean} [pIgnoreNull=true] return True if pValue is null + * + * @return {Boolean} + */ +NumberUtils.isInside = function(pValue, pMin, pMax, pIgnoreNull) +{ + if (pIgnoreNull == undefined) + pIgnoreNull = true; + + return pValue >= pMin && pValue <= pMax || pIgnoreNull && (pValue == null || isNaN(pValue)); +}; + +/** + * For use in validationProcess. Calls result.string(...) with error message, if number is not inside of the given values + * INCLUDING min / max. + * + * @param {Number} pTitle title to display in error message. Should be the name of the field and it will be translated. + * @param {Number} pValue value to check + * @param {Number} pMin min value INCLUSIVE + * @param {Number} pMax max value INCLUSIVE + * @param {Boolean} [pIgnoreNull=true] return True if pValue is null + * + * @return {String|False} returns the error message or false + * + * @example + * var value = ProcessHandlingUtils.getOnValidationValue(vars.get("$field.DISCOUNT")); <br> + * <br> + * var validationResult = NumberUtils.validateIsInside("Discount", value, 0, 100); <br> + * <br> + * if (validationResult) <br> + * { <br> + * result.string(validationResult); <br> + * } <br> + */ +NumberUtils.validateIsInside = function(pTitle, pValue, pMin, pMax, pIgnoreNull) +{ + var discount = parseInt(pValue); + if (!NumberUtils.isInside(discount, 0, 100, pIgnoreNull)) + { + return (translate.withArguments("${MIN_MAX_ERROR} field: %0, value: %1, min: %2, max: %3", [translate.text(pTitle), discount, pMin, pMax])); + } + return false; +} + /** * Class containing static utility functions for use with arrays * Do not create an instance of this!