From 4227ae7fe522f9631a1f8ebca6839a740249f522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Schr=C3=B6ger?= <m.schroeger@adito.de> Date: Wed, 7 Nov 2018 11:14:27 +0100 Subject: [PATCH] =?UTF-8?q?Preisliste:=20Bei=20Insert/Update=20pr=C3=BCfen?= =?UTF-8?q?=20auf=20identische=20Preislisten?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entity/Offeritem_entity/Offeritem_entity.aod | 1 - .../entityfields/product_id/onValidation.js | 2 - .../entityfields/product_id/onValueChange.js | 1 - .../Productprice_entity.aod | 7 ++ .../entityfields/fromquantity/valueProcess.js | 10 ++ .../entityfields/pricelist/onValidation.js | 20 ++++ .../_____LANGUAGE_EXTRA.aod | 3 + .../_____LANGUAGE_de/_____LANGUAGE_de.aod | 4 + .../_____LANGUAGE_en/_____LANGUAGE_en.aod | 3 + .../ProductpriceEdit_view.aod | 2 +- process/Product_lib/process.js | 101 +++++++++++++++--- 11 files changed, 135 insertions(+), 19 deletions(-) delete mode 100644 entity/Offeritem_entity/entityfields/product_id/onValidation.js create mode 100644 entity/Productprice_entity/entityfields/fromquantity/valueProcess.js create mode 100644 entity/Productprice_entity/entityfields/pricelist/onValidation.js diff --git a/entity/Offeritem_entity/Offeritem_entity.aod b/entity/Offeritem_entity/Offeritem_entity.aod index c28e322e3bd..5cca45ce71d 100644 --- a/entity/Offeritem_entity/Offeritem_entity.aod +++ b/entity/Offeritem_entity/Offeritem_entity.aod @@ -117,7 +117,6 @@ <columnName>PRODUCT_ID</columnName> <caption>Article</caption> <possibleItemsProcess>%aditoprj%/entity/Offeritem_entity/entityfields/product_id/possibleItemsProcess.js</possibleItemsProcess> - <onValidation>%aditoprj%/entity/Offeritem_entity/entityfields/product_id/onValidation.js</onValidation> <onValueChange>%aditoprj%/entity/Offeritem_entity/entityfields/product_id/onValueChange.js</onValueChange> </entityField> <entityField> diff --git a/entity/Offeritem_entity/entityfields/product_id/onValidation.js b/entity/Offeritem_entity/entityfields/product_id/onValidation.js deleted file mode 100644 index 139597f9cb0..00000000000 --- a/entity/Offeritem_entity/entityfields/product_id/onValidation.js +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/entity/Offeritem_entity/entityfields/product_id/onValueChange.js b/entity/Offeritem_entity/entityfields/product_id/onValueChange.js index bdb931f90f8..f55f272b2f2 100644 --- a/entity/Offeritem_entity/entityfields/product_id/onValueChange.js +++ b/entity/Offeritem_entity/entityfields/product_id/onValueChange.js @@ -13,7 +13,6 @@ if(pid != "") var PriceListFilter = { currency: curr, quantity: vars.get("$field.QUANTITY"), relationId: relid }; var ProductDetails = pUtils.getProductDetails(pid, PriceListFilter); - if(ProductDetails[pid] != undefined) { vars.set("$field.GROUPCODEID", ProductDetails[pid].groupCode); diff --git a/entity/Productprice_entity/Productprice_entity.aod b/entity/Productprice_entity/Productprice_entity.aod index 029ac867926..ac7b7a2ea4f 100644 --- a/entity/Productprice_entity/Productprice_entity.aod +++ b/entity/Productprice_entity/Productprice_entity.aod @@ -6,8 +6,11 @@ <alias>Data_alias</alias> <conditionProcess>%aditoprj%/entity/Productprice_entity/conditionProcess.js</conditionProcess> <orderClauseProcess>%aditoprj%/entity/Productprice_entity/orderClauseProcess.js</orderClauseProcess> + <onDBInsert>%aditoprj%/entity/Productprice_entity/onDBInsert.js</onDBInsert> + <grantCreateProcess>%aditoprj%/entity/Productprice_entity/grantCreateProcess.js</grantCreateProcess> <recordContainerType>DB</recordContainerType> <caption>Price list</caption> + <onValidation>%aditoprj%/entity/Productprice_entity/onValidation.js</onValidation> <entityFields> <entityField> <name>BUYSELL</name> @@ -50,7 +53,9 @@ <caption>From no. of units</caption> <contentType>TEXT</contentType> <outputFormat>#,##0</outputFormat> + <mandatory v="true" /> <state>AUTO</state> + <valueProcess>%aditoprj%/entity/Productprice_entity/entityfields/fromquantity/valueProcess.js</valueProcess> </entityField> <entityField> <name>PRICE</name> @@ -126,6 +131,7 @@ <contentType>TEXT</contentType> <outputFormat>#,##0.00</outputFormat> <mandatory v="true" /> + <onValidation>%aditoprj%/entity/Productprice_entity/entityfields/vat/onValidation.js</onValidation> </entityField> <entityField> <name>PRICELIST</name> @@ -137,6 +143,7 @@ <state>AUTO</state> <stateProcess>%aditoprj%/entity/Productprice_entity/entityfields/pricelist/stateProcess.js</stateProcess> <valueProcess>%aditoprj%/entity/Productprice_entity/entityfields/pricelist/valueProcess.js</valueProcess> + <onValidation>%aditoprj%/entity/Productprice_entity/entityfields/pricelist/onValidation.js</onValidation> </entityField> <entityIncomingField> <name>ProductProductprice_dfi</name> diff --git a/entity/Productprice_entity/entityfields/fromquantity/valueProcess.js b/entity/Productprice_entity/entityfields/fromquantity/valueProcess.js new file mode 100644 index 00000000000..3aebc70e19c --- /dev/null +++ b/entity/Productprice_entity/entityfields/fromquantity/valueProcess.js @@ -0,0 +1,10 @@ +import("system.vars"); +import("system.result"); +import("system.neon"); + +if(vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW && vars.get("$this.value") == "") +{ + result.string("1"); +} +else + result.string(vars.get("$this.value")); \ No newline at end of file diff --git a/entity/Productprice_entity/entityfields/pricelist/onValidation.js b/entity/Productprice_entity/entityfields/pricelist/onValidation.js new file mode 100644 index 00000000000..c2e17e931c1 --- /dev/null +++ b/entity/Productprice_entity/entityfields/pricelist/onValidation.js @@ -0,0 +1,20 @@ +import("system.translate"); +import("system.result"); +import("system.vars"); +import("Product_lib"); + +var pUtils = new ProductUtils(); +var priceList = { + priceList: vars.get("$local.value") + , fromQuantity: vars.get("$field.FROMQUANTITY") + , buySell: vars.get("$field.BUYSELL") + , currency: vars.get("$field.CURRENCY") + , validFrom: vars.get("$field.VALID_FROM") + , validTo: vars.get("$field.VALID_TO") + }; + +var identicalPriceList = pUtils.checkForIndenticalPriceLists(vars.get("$field.PRODUCT_ID"), priceList); +if(identicalPriceList != null) +{ + result.string(translate.text("Identical price list found!")); +} \ No newline at end of file diff --git a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod index a37c3f2fda4..0aa60e864e4 100644 --- a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod +++ b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod @@ -765,6 +765,9 @@ <entry> <key>Total gross</key> </entry> + <entry> + <key>Identical price list found!</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 a3683b63224..f5fd8ff554b 100644 --- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod +++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod @@ -980,6 +980,10 @@ <key>Total gross</key> <value>Betrag brutto</value> </entry> + <entry> + <key>Identical price list found!</key> + <value>Identische Preisliste gefunden!</value> + </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 8f1c4ca4922..ef68d4f6d16 100644 --- a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod +++ b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod @@ -773,6 +773,9 @@ <entry> <key>Total gross</key> </entry> + <entry> + <key>Identical price list found!</key> + </entry> </keyValueMap> <font name="Dialog" style="0" size="11" /> </language> diff --git a/neonView/ProductpriceEdit_view/ProductpriceEdit_view.aod b/neonView/ProductpriceEdit_view/ProductpriceEdit_view.aod index 9f54f721136..034a73b26df 100644 --- a/neonView/ProductpriceEdit_view/ProductpriceEdit_view.aod +++ b/neonView/ProductpriceEdit_view/ProductpriceEdit_view.aod @@ -14,7 +14,7 @@ <entityField>#ENTITY</entityField> <fields> <entityFieldLink> - <name>1df849bc-354d-4c52-a468-638a58966270</name> + <name>e2afee84-173b-430a-8e29-1fd16d33dd69</name> <entityField>PRICELIST</entityField> </entityFieldLink> <entityFieldLink> diff --git a/process/Product_lib/process.js b/process/Product_lib/process.js index 0d4f9f1d184..d9ff3b7d4b1 100644 --- a/process/Product_lib/process.js +++ b/process/Product_lib/process.js @@ -6,6 +6,7 @@ import("system.vars"); function ProductUtils() { + var that = this; /** * Delivers the currently valid product price * @@ -90,22 +91,31 @@ function ProductUtils() //Prod2Prod //TODO: get product structure - //PriceList + //PriceList (all) + var colsPricelistAll = ["allPP.PRODUCTPRICEID", "allPP.RELATION_ID", "allPP.PRICELIST", "allPP.PRICE", "allPP.VAT" + , "allPP.VALID_FROM", "allPP.VALID_TO", "allPP.BUYSELL", "allPP.FROMQUANTITY", "allPP.CURRENCY"]; + + cols = cols.concat(colsPricelistAll); + joins.push(" left join PRODUCTPRICE allPP on allPP.PRODUCT_ID = PRODUCTID "); + + //PriceList (currently valid) + var validPriceLists = false; if(pPriceListFilter != undefined && pPriceListFilter.currency != undefined && pPriceListFilter.currency != "" && pPriceListFilter.quantity != undefined && pPriceListFilter.quantity != "") { - var colsPricelist = ["PRODUCTPRICE.PRODUCTPRICEID", "PRODUCTPRICE.RELATION_ID", "PRODUCTPRICE.PRICELIST", "PRODUCTPRICE.PRICE", "PRODUCTPRICE.VAT"]; - cols = cols.concat(colsPricelist); - joins.push(" left join PRODUCTPRICE on PRODUCTPRICE.PRODUCT_ID = PRODUCTID " - + " and PRODUCTPRICE.CURRENCY = " + pPriceListFilter.currency - + " and PRODUCTPRICE.VALID_FROM <= ? and (PRODUCTPRICE.VALID_TO > ? or PRODUCTPRICE.VALID_TO is null) " - + " and PRODUCTPRICE.FROMQUANTITY <= " + pPriceListFilter.quantity - + " and (PRODUCTPRICE.RELATION_ID = '" + pPriceListFilter.relationId + "' or (PRODUCTPRICE.RELATION_ID is null and PRODUCTPRICE.BUYSELL = 'SP')) "); + validPriceLists = true; + var colsPricelistValid = ["validPP.PRODUCTPRICEID", "validPP.RELATION_ID", "validPP.PRICELIST", "validPP.PRICE", "validPP.VAT"]; + cols = cols.concat(colsPricelistValid); + joins.push(" left join PRODUCTPRICE validPP on validPP.PRODUCT_ID = PRODUCTID " + + " and validPP.CURRENCY = " + pPriceListFilter.currency + + " and validPP.VALID_FROM <= ? and (validPP.VALID_TO > ? or validPP.VALID_TO is null) " + + " and validPP.FROMQUANTITY <= " + pPriceListFilter.quantity + + " and (validPP.RELATION_ID = '" + pPriceListFilter.relationId + "' or (validPP.RELATION_ID is null and validPP.BUYSELL = 'SP')) "); sqltypes.push([datetime.date().toString(), SQLTYPES.TIMESTAMP]); sqltypes.push([datetime.date().toString(), SQLTYPES.TIMESTAMP]); - orderby = orderby.concat(["PRODUCTPRICE.VALID_FROM desc, PRODUCTPRICE.FROMQUANTITY desc"]); + orderby = orderby.concat(["validPP.VALID_FROM desc, validPP.FROMQUANTITY desc"]); } var ProductDataSql = "select " + cols.join(", ") @@ -129,25 +139,47 @@ function ProductUtils() , groupCode: ProductData[i][2] , unit: ProductData[i][3] , Prod2Prod: {} + , PriceLists: {} , CurrentValidPriceLists: {} , PriceListToUse: null }; } - //Pricelist + //Pricelist (all) var colIdx = colsProduct.length; - if(ProductData[i][colIdx] != "") //Pricelist found + if(ProductData[i][colIdx] != "" && ProductDetails[ProductData[i][0]].PriceLists[ProductData[i][colIdx]] == undefined) //Pricelist found { - ProductDetails[ProductData[i][0]].CurrentValidPriceLists[ProductData[i][colIdx]] = { + ProductDetails[ProductData[i][0]].PriceLists[ProductData[i][colIdx]] = { priceListId: ProductData[i][colIdx++] , relationId: ProductData[i][colIdx++] , priceList: ProductData[i][colIdx++] , price: ProductData[i][colIdx++] , vat: ProductData[i][colIdx++] + , validFrom: ProductData[i][colIdx++] + , validTo: ProductData[i][colIdx++] + , buySell: ProductData[i][colIdx++] + , fromQuantity: ProductData[i][colIdx++] + , currency: ProductData[i][colIdx++] + } + } + + //Pricelist (currently valid) + if(validPriceLists) + { + if(ProductData[i][colIdx] != "" && ProductDetails[ProductData[i][0]].CurrentValidPriceLists[ProductData[i][colIdx]] == undefined) //Pricelist found + { + ProductDetails[ProductData[i][0]].CurrentValidPriceLists[ProductData[i][colIdx]] = { + priceListId: ProductData[i][colIdx++] + , relationId: ProductData[i][colIdx++] + , priceList: ProductData[i][colIdx++] + , price: ProductData[i][colIdx++] + , vat: ProductData[i][colIdx++] + } } } } - ProductDetails[pPid].PriceListToUse = _getPriceListToUse(ProductDetails[pPid].CurrentValidPriceLists, pPriceListFilter); + if(validPriceLists) + ProductDetails[pPid].PriceListToUse = _getPriceListToUse(ProductDetails[pPid].CurrentValidPriceLists, pPriceListFilter); return ProductDetails; @@ -178,6 +210,47 @@ function ProductUtils() } } - + //pPriceList Object beschreiben + this.checkForIndenticalPriceLists = function(pPid, pPriceList) + { + var PriceLists = that.getProductDetails(pPid)[pPid].PriceLists; + + for(var pricelist in PriceLists) + { + + if( pPriceList.priceList == PriceLists[pricelist].priceList + && pPriceList.fromQuantity == PriceLists[pricelist].fromQuantity + && pPriceList.buySell == PriceLists[pricelist].buySell + && pPriceList.currency == PriceLists[pricelist].currency ) + + { + + if( pPriceList.validFrom == PriceLists[pricelist].validFrom && pPriceList.validTo == PriceLists[pricelist].validTo + || ! ( pPriceList.validFrom <= PriceLists[pricelist].validFrom && pPriceList.validTo <= PriceLists[pricelist].validTo + || pPriceList.validFrom >= PriceLists[pricelist].validFrom && pPriceList.validTo >= PriceLists[pricelist].validTo + || pPriceList.validFrom < PriceLists[pricelist].validFrom && pPriceList.validTo > PriceLists[pricelist].validTo ) + ) + { + //identical price list found + return PriceLists[pricelist]; + } + } + } + + return null; + + //equal price list + + //identical fromquantity + //identical currency + //identical pp/sp + + //identical validFrom & validTo + // OR NOT [ validFrom_new <= validFrom & validTo_new <= validTo + // OR validFrom_new >= validFrom & validTo_new >= validTo + // OR validFrom_new < validFrom & validTo_new > validTo + // ] + + } } \ No newline at end of file -- GitLab