Skip to content
Snippets Groups Projects
Commit 4227ae7f authored by Maximilian Schröger's avatar Maximilian Schröger
Browse files

Preisliste: Bei Insert/Update prüfen auf identische Preislisten

parent 9862a7e5
No related branches found
No related tags found
No related merge requests found
Showing
with 135 additions and 19 deletions
......@@ -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>
......
......@@ -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);
......
......@@ -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>
......
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
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
......@@ -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>
......
......@@ -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>
......@@ -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>
......@@ -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>
......
......@@ -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
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