Skip to content
Snippets Groups Projects
Commit 865aaa90 authored by Sebastian Pongratz's avatar Sebastian Pongratz :ping_pong:
Browse files

Merge branch 'sales_1085120_FixPresetpriceFromPartsList' into '2021.2.0'

[Projekt: xRM-Sales][TicketNr.: 1085120][Preisvorschlag bei Stückliste fehlerhaft]

See merge request xrm/basic!1273
parents 48f82eda 1819640f
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,6 @@ import("system.vars"); ...@@ -4,6 +4,6 @@ import("system.vars");
if(vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW || vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_EDIT) if(vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW || vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_EDIT)
{ {
var productId = vars.get("$field.PRODUCT_ID"); ProductUtils.presetPriceAndVat(vars.get("$field.PRODUCT_ID"), vars.get("$field.VAT"), vars.get("$field.PRICELIST"), vars.get("$this.value")
ProductUtils.presetPriceAndVat(vars.get("$field.PRODUCT_ID"), vars.get("$field.VAT"),vars.get("$field.PRICELIST") , vars.get("$this.value")); , vars.get("$field.CURRENCY"), vars.get("$field.FROMQUANTITY"), vars.get("$field.PRICE"));
} }
\ No newline at end of file
...@@ -4,6 +4,6 @@ import("system.vars"); ...@@ -4,6 +4,6 @@ import("system.vars");
if(vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW || vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_EDIT) if(vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW || vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_EDIT)
{ {
var productId = vars.get("$field.PRODUCT_ID"); ProductUtils.presetPriceAndVat(vars.get("$field.PRODUCT_ID"), vars.get("$field.VAT"), vars.get("$this.value"), vars.get("$field.BUYSELL")
ProductUtils.presetPriceAndVat(vars.get("$field.PRODUCT_ID"), vars.get("$field.VAT"), vars.get("$this.value"), vars.get("$field.BUYSELL")); , vars.get("$field.CURRENCY"), vars.get("$field.FROMQUANTITY"), vars.get("$field.PRICE"));
} }
\ No newline at end of file
...@@ -333,10 +333,6 @@ ItemUtils.prototype.insertPartsList = function(columns, productId, assignedTo, c ...@@ -333,10 +333,6 @@ ItemUtils.prototype.insertPartsList = function(columns, productId, assignedTo, c
productsWithSumUpPrices[newid] = P2pObject["quantity"]; productsWithSumUpPrices[newid] = P2pObject["quantity"];
} }
} }
var stop = false;
var checkedElements;
var amuntOfKeys;
var itemAdded;
if(pSumUpPrices)//also build treeStructure if pSumUpPrices is set to true if(pSumUpPrices)//also build treeStructure if pSumUpPrices is set to true
{ {
......
...@@ -649,126 +649,32 @@ function ProductPriceUtils() {} ...@@ -649,126 +649,32 @@ function ProductPriceUtils() {}
* This means we have to start from bottum up to calculate the prices. * This means we have to start from bottum up to calculate the prices.
* *
* @param {String} pProductId ProductID of the product we want to set the fields for * @param {String} pProductId ProductID of the product we want to set the fields for
* @param {String} pVat opt vat * @param {String} [pVat] vat
* @param {String} pPriceList opt priceList(-"type") * @param {String} [pPriceList] priceList(-"type")
* @param {String} pBuySell opt possible values: PP, SP * @param {String} [pBuySell] possible values: PP, SP
* * @param {String} [pCurrency] currency
* @example productUtils.getCurrentProductPrice(vars.get("$field.PRODUCTID"), "PP") * @param {String} [pFromQuantity] fromQuantity
* @param {String} [pPrice] product price
* *
* @return {void} uses neon.setFieldValues({"$field.PRICE": priceObj[oItem]["price"],"$field.VAT": priceObj[oItem]["vat"]}) * @return {void} uses neon.setFieldValues({"$field.PRICE": priceObj[oItem]["price"],"$field.VAT": priceObj[oItem]["vat"]})
*/ */
ProductUtils.presetPriceAndVat = function(pProductId, pVat, pPriceList, pBuySell) { ProductUtils.presetPriceAndVat = function(pProductId, pVat, pPriceList, pBuySell, pCurrency, pFromQuantity, pPrice)
{
var currency = pCurrency ? pCurrency : "EUR";
var vat = pVat; var fromQuantity = pFromQuantity ? pFromQuantity : 1;
var productId = pProductId; var price = pPrice ? pPrice : 0;
var priceList = pPriceList; var vat = pVat ? pVat : 0;
var buySell = pBuySell;
var config = entities.createConfigForLoadingRows()
.entity("Prod2prod_entity")
.addParameter("ProductId_param", productId)
.fields(["PROD2PRODID",
"DEST_ID",
"SOURCE_ID",
"QUANTITY",
"OPTIONAL",
"unit",
"TAKEPRICE",
"currentPurchasePrice",
"currentSalesPrice"]);
var products = entities.getRows(config);//source_id = product_id
var treestructure = {};
var curr = vars.get("$field.CURRENCY");
var priceObj = {};
var sumUpPrices = {};
_handleProducts(products, treestructure, curr, buySell, priceObj, 1, priceList, productId); //build treeStructure and priceObj
var summandObject = {};
for (var i = products.length-1; i > -1; i--)//we do this backwards because otherwiese we would run into problems when trying to build the sum (we could have items without an price yet) //we use the already exisitng code we have in orderOffer_lib. So we have to get an instance. The uid doesn't matter since we don't insert/update anything,
{ //we just have to make sure to use the same dummy string when using insertPartsList().
if(sumUpPrices.hasOwnProperty(products[i]["SOURCE_ID"])) var oiUtils = new OfferItemUtils("dummy");
{ var partsListObject = oiUtils.insertPartsList(pProductId, "dummy", currency, null, null, fromQuantity, true, "dummy", true);
summandObject[products[i]["PROD2PRODID"]] = ItemUtils.getNode(treestructure[productId], products[i]["PROD2PRODID"], Object.keys(treestructure)[0]);
}
}
for(var oItem in summandObject)
{
var calcPrice = 0;
var vat = null;
for (var child in summandObject[oItem])
{
var childPrice;
if(priceObj[child] != undefined)
{
childPrice = priceObj[child]["price"]
}
else if(summandObject[child][child] != undefined)
{
childPrice = priceObj[Object.keys(summandObject[child][child])[0]]["price"]
vat = priceObj[Object.keys(summandObject[child][child])[0]]["vat"]
}
else
{
childPrice = 0;
vat = 0;
}
let quantity = 1;
for (i = 0; i < products.length; i++)
{
if(products[i]["PROD2PRODID"] == oItem)
{
quantity = products[i]["QUANTITY"];
break;
}
}
calcPrice = eMath.addDec(childPrice, calcPrice)*quantity;
if(!vat)
{
vat = priceObj[child]["vat"];
}
}
priceObj[oItem] = {};
priceObj[oItem]["price"] = calcPrice;
priceObj[oItem]["vat"] = vat;
}
var price = 0; if(partsListObject && partsListObject["topProductInfo"])
for (var item in treestructure[productId])
{ {
price += parseInt(priceObj[item]["price"]); price = partsListObject["topProductInfo"]["price"];
if(vat == null && priceObj[item]["vat"]) vat = partsListObject["topProductInfo"]["vat"];
{
vat = parseInt(priceObj[item]["vat"]);
}
} }
neon.setFieldValues({"$field.PRICE": price, "$field.VAT": vat}) neon.setFieldValues({"$field.PRICE": price, "$field.VAT": vat})
//private function for better code-readability
function _handleProducts(products, treestructure, curr, buySell, priceObj, pQuantity, pPriceList, pProductId){
for(var product in products)
{
var productDetails = ProductUtils.getProductDetails(
products[product]["SOURCE_ID"],
{ currency: curr, quantity: pQuantity, relationId: "", priceList: pPriceList});
if(!Utils.isEmpty(productDetails["PriceListToUse"]))
{
priceObj[products[product]["PROD2PRODID"]] = {};
priceObj[products[product]["PROD2PRODID"]]["price"] = productDetails["PriceListToUse"]["price"]*products[product]["QUANTITY"];
priceObj[products[product]["PROD2PRODID"]]["vat"] = productDetails["PriceListToUse"]["vat"];
}
else
{
sumUpPrices[products[product]["SOURCE_ID"]] = {};
}
var assignedTo = products[product]["DEST_ID"] != "" ? products[product]["DEST_ID"] : pProductId;
treestructure = ItemUtils.buildTreeStructure(treestructure, assignedTo, products[product]["PROD2PRODID"]);
}
}
} }
\ 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