Skip to content
Snippets Groups Projects
Commit 3cd938e9 authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

Offer fixes

parent 7edf40f5
No related branches found
No related tags found
No related merge requests found
Showing
with 177 additions and 52 deletions
......@@ -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>
......
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
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}"));
}
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
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
......@@ -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>
......
......@@ -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>
......@@ -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>
......@@ -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>
......@@ -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>
......
......@@ -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!
......
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