Skip to content
Snippets Groups Projects
Commit 1819640f authored by Benjamin Ulrich's avatar Benjamin Ulrich :speech_balloon:
Browse files

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

parent 345699a2
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,6 @@ import("system.vars");
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");
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
productsWithSumUpPrices[newid] = P2pObject["quantity"];
}
}
var stop = false;
var checkedElements;
var amuntOfKeys;
var itemAdded;
if(pSumUpPrices)//also build treeStructure if pSumUpPrices is set to true
{
......
......@@ -649,126 +649,32 @@ function ProductPriceUtils() {}
* 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} pVat opt vat
* @param {String} pPriceList opt priceList(-"type")
* @param {String} pBuySell opt possible values: PP, SP
*
* @example productUtils.getCurrentProductPrice(vars.get("$field.PRODUCTID"), "PP")
* @param {String} [pVat] vat
* @param {String} [pPriceList] priceList(-"type")
* @param {String} [pBuySell] possible values: PP, SP
* @param {String} [pCurrency] currency
* @param {String} [pFromQuantity] fromQuantity
* @param {String} [pPrice] product price
*
* @return {void} uses neon.setFieldValues({"$field.PRICE": priceObj[oItem]["price"],"$field.VAT": priceObj[oItem]["vat"]})
*/
ProductUtils.presetPriceAndVat = function(pProductId, pVat, pPriceList, pBuySell) {
var vat = pVat;
var productId = pProductId;
var priceList = pPriceList;
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 = {};
ProductUtils.presetPriceAndVat = function(pProductId, pVat, pPriceList, pBuySell, pCurrency, pFromQuantity, pPrice)
{
var currency = pCurrency ? pCurrency : "EUR";
var fromQuantity = pFromQuantity ? pFromQuantity : 1;
var price = pPrice ? pPrice : 0;
var vat = pVat ? pVat : 0;
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)
{
if(sumUpPrices.hasOwnProperty(products[i]["SOURCE_ID"]))
{
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;
}
//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().
var oiUtils = new OfferItemUtils("dummy");
var partsListObject = oiUtils.insertPartsList(pProductId, "dummy", currency, null, null, fromQuantity, true, "dummy", true);
var price = 0;
for (var item in treestructure[productId])
if(partsListObject && partsListObject["topProductInfo"])
{
price += parseInt(priceObj[item]["price"]);
if(vat == null && priceObj[item]["vat"])
{
vat = parseInt(priceObj[item]["vat"]);
}
price = partsListObject["topProductInfo"]["price"];
vat = partsListObject["topProductInfo"]["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