Skip to content
Snippets Groups Projects
onValueChange.js 1.91 KiB
Newer Older
import("system.db");
import("Sql_lib");
S.Listl's avatar
S.Listl committed
import("AttributeRegistry_basic");
import("system.vars");
import("system.neon");
import("Product_lib");
S.Listl's avatar
S.Listl committed
import("Attribute_lib");
Johannes Hörmann's avatar
Johannes Hörmann committed
    var currency = vars.exists("$param.Currency_param") ? vars.get("$param.Currency_param") : "";
    var contactid = vars.exists("$param.ContactId_param") ? vars.get("$param.ContactId_param") : "";
S.Listl's avatar
S.Listl committed
    var pricelist = AttributeRelationUtils.getAttribute($AttributeRegistry.pricelist(), contactid) || "";
S.Listl's avatar
S.Listl committed
    var PriceListFilter = { currency: currency, quantity: vars.get("$field.QUANTITY"), relationId: contactid, priceList: pricelist };
    //TODO: loading from db until loading from Consumer is possible.
    var ProductDetails = ProductUtils.getProductDetails(pid, PriceListFilter, 
            [["info", SqlUtils.translateStatementWithQuotes(SqlCondition.begin()
                                  .andPrepareVars("DESCRIPTIONTRANSLATION.OBJECT_ROWID", "local.value")
                                  .and("DESCRIPTIONTRANSLATION.OBJECT_TYPE = 'Product'")
                                  .andPrepareVars("DESCRIPTIONTRANSLATION.LANG", "$param.Language_param")
                                  .buildSql("(select DESCRIPTION from DESCRIPTIONTRANSLATION", "1=2", ")"))]
            ]);
    
    if(ProductDetails.productId != undefined)
        neon.setFieldValue("$field.GROUPCODEID", ProductDetails.groupCode);
        neon.setFieldValue("$field.UNIT", ProductDetails.unit);
        neon.setFieldValue("$field.ITEMNAME", ProductDetails.productName);
        neon.setFieldValue("$field.INFO", ProductDetails.info);
        if(ProductDetails.PriceListToUse != null)
            neon.setFieldValue("$field.PRICE", ProductDetails.PriceListToUse.price);
            neon.setFieldValue("$field.VAT", ProductDetails.PriceListToUse.vat);