/*
Add your SAP Business ByDesign scripting language implementation for:
Business Object: SalesOrder
Node: Item
Event: AfterModify
Note:
- To access the elements of the business object node,
use path expressions, for example, this.<element name>.
- To use code completion, press CTRL+J.
- This script file is mass-enabled, i.e. the keyword "this"
refers to a collection of node instances.
- The solution uses this script if:
- the value of any field in the node in which this script is contained is modified.
- the node itself is modified by another business object within the same solution.
*/
import ABSL;
import AP.FinancialAccounting.Global;
import AP.FO.ProductDataMaintenance.Global;
import AP.FO.MOM.Global;
foreach(var item in this){
if(item.IsSet()){
var matID = item.ItemProduct.ProductInternalID;
if(item.ShipFromItemLocation.IsSet()){
var itemBR = item.ShipFromItemLocation.LocationID.content;
var itemOrg = item.ToRoot.SalesAndServiceBusinessArea.SalesOrganisation;
var itemCO = itemOrg.CurrentSuperordinateCompany.UUID;
var qryValLevel = MaterialValuationData.ValuationLevel.QueryByElements;
var paramValLevel = qryValLevel.CreateSelectionParams();
paramValLevel.Add(qryValLevel.MaterialValuationDataMaterialKey.ProductID.content,"I","EQ",matID.content);
paramValLevel.Add(qryValLevel.MaterialValuationDataPermanentEstablishmentID,"I","EQ",itemBR);
var resValLevel = qryValLevel.Execute(paramValLevel);
if(resValLevel.Count()>0){
var matValPrice = resValLevel.ValuationPrice;
if(matValPrice.Count()>0){
foreach(var value in matValPrice){
var valEndDate = Date.ConvertToGlobalDateTime(value.ValidityDatePeriod.EndDate);
var valStartDate = Date.ConvertToGlobalDateTime(value.ValidityDatePeriod.StartDate);
var itemReqDate = item.FirstRequestedItemScheduleLine.DateTimePeriod.EndDateTime.ConvertToGlobalDateTime();
if(valStartDate<= itemReqDate){
if(valEndDate >= itemReqDate){
var sobID = value.SetOfBooksID;
var qrySOB = SetOfBooks.QueryByIDAndDescription;
var sobParam = qrySOB.CreateSelectionParams();
sobParam.Add(qrySOB.ID.content,"I","EQ",sobID.content);
var resSOB =qrySOB.Execute(sobParam);
if(resSOB.Count()>0){
foreach(var books in resSOB){
foreach(var company in books.CompanyAssignment){
if(company.CompanyUUID.content == itemCO.content){
if(company.SetOfBooksDefaultIndicator){
var BRValue = value.LocalCurrencyValuationPrice.Amount;
item.brValue = BRValue;
var netVal = item.PriceAndTaxCalculationItem.ItemMainTotal.CalculatedAmount;
var netCost = (item.FirstRequestedItemScheduleLine.Quantity.content)*BRValue.content;
var margin = netVal.content - netCost;
item.brMargin.content = margin;
item.brMargin.currencyCode =BRValue.currencyCode;
}
}
}
}
}
}
}
}
}
}
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
8 | |
5 | |
4 | |
4 | |
3 | |
3 | |
2 | |
2 | |
2 |