class DGS_CommonDimension
{
static DimensionDefault buildDimension(DimensionDefault olddimensionDefault, str dimensionName, DimensionValue newDimensionValue)
{
DimensionAttributeValueSetStorage dimensionAttributeValueSetStorage;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
DimensionDefault dimensionDefault;
LedgerDimensionAccount ledgerDimensionAccount;
DimensionValue oldDimensionValue;
DimensionValue getDimensonValue(DimensionDefault _dimensionDefault)
{
DefaultDimensionView defaultDimensionView;
select firstonly DisplayValue
from defaultDimensionView
where defaultDimensionView.Name == dimensionName
&& defaultDimensionView.DefaultDimension == _dimensionDefault;
return defaultDimensionView.DisplayValue;
}
oldDimensionValue = getDimensonValue(olddimensionDefault);
// dimensionAttributeValueSetStorage = new DimensionAttributeValueSetStorage();
// Build DimensionAttributeValueSetStorage
dimensionAttributeValueSetStorage = DimensionAttributeValueSetStorage::find(olddimensionDefault);
if(!dimensionAttributeValueSetStorage)
{
dimensionAttributeValueSetStorage = new DimensionAttributeValueSetStorage();
}
// Remove old dimension value
dimensionAttribute = DimensionAttribute::findByName(dimensionName);
dimensionAttributeValueSetStorage.removeDimensionAttributeValue(
DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, oldDimensionValue).RecId);
// Set new dimension value
if(newDimensionValue != "")
{
dimensionAttribute = DimensionAttribute::findByName(dimensionName);
dimensionAttributeValueSetStorage.addItem(
DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, newDimensionValue));
}
dimensionDefault = dimensionAttributeValueSetStorage.save();
info(strFmt("Default dimension recId: %1", dimensionDefault));
return dimensionDefault;
}
static DimensionAttributeValue createValueInDimension(str dimensionName, DimensionValue newDimensionValue)
{
DimensionAttribute dimAttr;
DimensionAttributeDirCategory dimAttrCategory;
DimensionFinancialTag dimFinancialTag;
DimensionAttributeValue dimensionAttributeValue;
if(dimensionName)
{
dimAttr = DimensionAttribute::findByName(dimensionName);
select firstonly dimAttrCategory
where dimAttrCategory.DimensionAttribute == dimAttr.RecId;
if(dimAttrCategory)
{
select dimFinancialTag
where dimFinancialTag.FinancialTagCategory == dimAttrCategory.DirCategory
&& dimFinancialTag.Value == newDimensionValue;
if (!dimFinancialTag)
{
ttsbegin;
dimFinancialTag.Description = newDimensionValue;
dimFinancialTag.Value = newDimensionValue;
dimFinancialTag.FinancialTagCategory = dimAttrCategory.DirCategory;
dimFinancialTag.insert();
ttscommit;
}
if(dimFinancialTag)
{
// check and add DimensionAttributeValue
dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttr,newDimensionValue, false, true);
}
}
}
return dimensionAttributeValue;
}
}
======================================================
加入Country Location
[ExtensionOf(tableStr(DirPartyLocation))]
final class DGS_DirPartyLocation_Extension
{
public void update()
{
DirPartyLocation original = this.orig();
DirPartyLocation partyLocation = this;
next update();
if(original.IsPrimary != partyLocation.IsPrimary && partyLocation.IsPrimary == NoYes::Yes)
DirPartyLocation::createOrUpdateCountryDimension(partyLocation);
}
public void insert()
{
DirPartyLocation original = this.orig();
DirPartyLocation partyLocation = this;
next insert();
// info(strFmt("Original isPrimary: %1 , this isPrimary : %2", original.IsPrimary , partyLocation.IsPrimary));
if(partyLocation.IsPrimary == NoYes::Yes)
DirPartyLocation::createOrUpdateCountryDimension(partyLocation);
}
public static void createOrUpdateCountryDimension(DirPartyLocation partyLocation)
{
CustTable _custTable;
VendTable _vendTable;
DirPartyPostalAddressView _addressView;
DimensionAttributeValue _dimensionAttributeValue;
DimensionValue _value;
DimensionDefault newDimensionDefault;
DimensionAttribute _dimensionAttribute;
;
ttsbegin;
LedgerParameters ledgerParameters = LedgerParameters::find();
str dimensionName = ledgerParameters.THK_FinancialDimCountry;
_custTable = CustTable::findByPartyRecId(partyLocation.Party);
_vendTable = VendTable::findByPartyRecId(partyLocation.Party);
_addressView = DirPartyPostalAddressView::find(partyLocation.Party, partyLocation.Location);
_value = _addressView.ISOcode;
if(dimensionName)
{
// check dimenion exist on financial dimension
_dimensionAttributeValue = DGS_CommonDimension::createValueInDimension(dimensionName, _value);
if(_dimensionAttributeValue)
{
ttsbegin;
if(_custTable)
{
newDimensionDefault = DGS_CommonDimension::buildDimension(_custTable.defaultDimension,dimensionName,_value);
_custTable.selectForUpdate(true);
_custTable.DefaultDimension = newDimensionDefault;
_custTable.update();
}
else if(_vendTable)
{
newDimensionDefault = DGS_CommonDimension::buildDimension(_vendTable.defaultDimension,dimensionName,_value);
_vendTable.selectForUpdate(true);
_vendTable.DefaultDimension = newDimensionDefault;
_vendTable.update();
}
ttscommit;
}
else
{
throw Error(strFmt("@SYS26332", dimensionName));
}
}
else
{
throw Error(strFmt("Please setup Ledger Parameters - Country."));
}
ttscommit;
}
}
====================================================
主要:
_dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(_dimensionAttribute,_value);
// if have this display value inside Financial Dimension, create a new dimensiont value set to purchTable
if(_dimensionAttributeValue)
{
newDimensionDefault = DGS_CommonDimension::buildDimension(purchTable.defaultDimension,dimensionName,_value);
ttsbegin;
purchTable.selectForUpdate(true);
purchTable.DefaultDimension = newDimensionDefault;
purchTable.update();
ttscommit;
}
留言列表