diff --git a/entity/Product_entity/Product_entity.aod b/entity/Product_entity/Product_entity.aod index aa87c91ce0b841ec76f18e4affe47fd9a319f042..1d63cd564ef2acdbaa1d95d4f51eb6c3d4f59df8 100644 --- a/entity/Product_entity/Product_entity.aod +++ b/entity/Product_entity/Product_entity.aod @@ -134,6 +134,10 @@ <entityField> <name>STOCKCOUNT</name> <caption>Stock</caption> + <contentType>NUMBER</contentType> + <outputFormat>#.##0</outputFormat> + <state>READONLY</state> + <valueProcess>%aditoprj%/entity/Product_entity/entityfields/stockcount/valueProcess.js</valueProcess> </entityField> <entityParameter> <name>OrgId_param</name> @@ -145,10 +149,16 @@ <entityField> <name>currentPurchasePrice</name> <caption>Curr. purchase price</caption> + <contentType>NUMBER</contentType> + <outputFormat>#,##0.00 €</outputFormat> + <state>READONLY</state> + <valueProcess>%aditoprj%/entity/Product_entity/entityfields/currentpurchaseprice/valueProcess.js</valueProcess> </entityField> <entityField> <name>currentSalesPrice</name> <caption>Curr. sales price</caption> + <state>READONLY</state> + <valueProcess>%aditoprj%/entity/Product_entity/entityfields/currentsalesprice/valueProcess.js</valueProcess> </entityField> <entityOutgoingField> <name>ProductProductprice_dfo</name> diff --git a/entity/Product_entity/entityfields/currentpurchaseprice/valueProcess.js b/entity/Product_entity/entityfields/currentpurchaseprice/valueProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..b026f1d3dad142c69a6ee4c59a87f7b27e27e789 --- /dev/null +++ b/entity/Product_entity/entityfields/currentpurchaseprice/valueProcess.js @@ -0,0 +1,7 @@ +import("system.result"); +import("system.vars"); +import("Product_lib"); + +var ProductUtils = new ProductUtils(); + +result.string( ProductUtils.getCurrentProductPrice(vars.get("$field.PRODUCTID"), "PP") ); \ No newline at end of file diff --git a/entity/Product_entity/entityfields/currentsalesprice/valueProcess.js b/entity/Product_entity/entityfields/currentsalesprice/valueProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..156641616b233d5fced83be3453d49f5f80f5315 --- /dev/null +++ b/entity/Product_entity/entityfields/currentsalesprice/valueProcess.js @@ -0,0 +1,7 @@ +import("system.result"); +import("system.vars"); +import("Product_lib"); + +var productUtils = new ProductUtils(); + +result.string( productUtils.getCurrentProductPrice(vars.get("$field.PRODUCTID"), "SP") ); \ No newline at end of file diff --git a/entity/Product_entity/entityfields/stockcount/valueProcess.js b/entity/Product_entity/entityfields/stockcount/valueProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..1f4a638ea8ce96cdccbb1dec17c1b33ef38a979e --- /dev/null +++ b/entity/Product_entity/entityfields/stockcount/valueProcess.js @@ -0,0 +1,7 @@ +import("system.result"); +import("system.vars"); +import("Product_lib"); + +var ProductUtils = new ProductUtils(); + +result.string( ProductUtils.getStockCount(vars.get("$field.PRODUCTID")) ); \ No newline at end of file diff --git a/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod b/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod index 9fb33b2728fdfd126836bddb26f10b1287064351..6342decac506717ea22a8355652f8a4fde3f4c99 100644 --- a/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod +++ b/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod @@ -2,7 +2,7 @@ <preferences xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="3.0.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/preferences/3.0.1"> <name>_____PREFERENCES_PROJECT</name> <majorModelMode>DISTRIBUTED</majorModelMode> - <projectName>xRM-Basic 5</projectName> + <projectName>xRM-Basic</projectName> <jditoMaxContentSize v="57671680" /> <calendarCategoriesEvent> <entry> diff --git a/process/Product_lib/Product_lib.aod b/process/Product_lib/Product_lib.aod new file mode 100644 index 0000000000000000000000000000000000000000..0940dbd30195c3cf11aa844ceb906bded0758c60 --- /dev/null +++ b/process/Product_lib/Product_lib.aod @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.7" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.1.7"> + <name>Product_lib</name> + <majorModelMode>DISTRIBUTED</majorModelMode> + <process>%aditoprj%/process/Product_lib/process.js</process> +</process> diff --git a/process/Product_lib/process.js b/process/Product_lib/process.js new file mode 100644 index 0000000000000000000000000000000000000000..f4bc88ee889846eabaa8701a60bf2a6d38b7a93d --- /dev/null +++ b/process/Product_lib/process.js @@ -0,0 +1,67 @@ +import("system.logging"); +import("system.SQLTYPES"); +import("system.datetime"); +import("system.db"); +import("system.vars"); + +function ProductUtils() +{ + /** + * Delivers the currently valid product price + * + * @param pPid {String} ProductID + * @param pBuySell {String} possible values: PP, SP + * + * @example productUtils.getCurrentProductPrice(vars.get("$field.PRODUCTID"), "PP") + * + * @result {String} currently valid product price + */ + this.getCurrentProductPrice = function( pPid, pBuySell ) + { + if(pPid != undefined && pPid != "" && pBuySell != undefined && pBuySell != "") + { + var actualpriceSelect = "select PRICE from PRODUCTPRICE \n\ + where BUYSELL = '" + pBuySell + "' and PRODUCT_ID = '" + pPid + "' and CURRENCY = 1 \n\ + and VALID_FROM <= ? and (VALID_TO >= ? or VALID_TO is null) \n\ + order by VALID_FROM desc"; + + var today = datetime.today(); + var sqltypes = [ [today.toString(), SQLTYPES.TIMESTAMP], [today.toString(), SQLTYPES.TIMESTAMP] ]; + var actualprice = db.cell([actualpriceSelect, sqltypes]); + + if(actualprice != "") + return actualprice; + else + return "0.00"; + } + else + { + throw new Error();//TODO: add message + } + } + + /** + * Delivers the stock + * + * @param pPid {String} ProductID + * + * @example productUtils.getStockCount(vars.get("$field.PRODUCTID")) + * + * @result {String} stock count + */ + this.getStockCount = function( pPid ) + { + if(pPid != undefined && pPid != "")//TODO: could this not be solved with dfo's ? + { + var sum = db.cell("select sum(QUANTITY * IN_OUT) from STOCK where PRODUCT_ID = '" + pPid + "'"); + if(sum == "") + sum = "0"; + + return sum; + } + else + { + throw new Error();//TODO: add message + } + } +} \ No newline at end of file