Get Last Price x++ :
public static Price TIDgetSTDCostItemPrice(ItemId _itemId,TransDate _activationDate,InventSiteId _inventSiteId)
{
InventDim InventDimLoc;
InventItemPrice inventItemPriceLoc;
InventDimLoc.clear();
InventDimLoc.InventSiteId = _inventSiteId;
InventDimLoc = InventDim::findOrCreate(InventDimLoc);
inventItemPriceLoc = InventItemPrice::findCurrent(_itemId,CostingVersionPriceType::Cost,InventDimLoc.inventDimId,
_activationDate,_inventSiteId,InventItemCostingType::Standard);
return inventItemPriceLoc.Price;
}
oR
public static Price Addit_getSTDCostItemPrice(ItemId _itemId = 'A010001001',TransDate _activationDate = systemDateGet(),InventSiteId _inventSiteId = 'KSR')
{
InventDim InventDimLoc;
InventItemPrice inventItemPriceLoc;
InventDimLoc.clear();
InventDimLoc.InventSiteId = _inventSiteId;
InventDimLoc = InventDim::findOrCreate(InventDimLoc);
inventItemPriceLoc = InventItemPrice::findCurrent(_itemId,CostingVersionPriceType::Cost,InventDimLoc.inventDimId,
_activationDate,_inventSiteId,InventItemCostingType::Last);
info(strFmt("%1", inventItemPriceLoc.Price));
return inventItemPriceLoc.Price;
}
=OR=
void BIT_GetAccount8Dimesions()
{
container conDimValue;
RefRecId ledgerDimension;
DimensionAttributeValueCombination _DimensionAttributeValueCombination;
InventJournalTrans _getJournalID;
int recordsCount;
str _mainAccount, CashFlow, Location , Divison, YOPID, Fields, Vehicle, Station, Category;
container con;
container accountCon;
MainAccount mainAcc;
DimensionStorage dimensionStorage;
DimensionAttributeValueCombination dimCombination;
int hierarchyCount, hierarchyIndex, segmentCount, segmentIndex;
RefRecId recordvalue;
int dimCount;
DimensionStorageSegment segment;
DimensionHierarchyLevel hierarchyLevel;
DimensionAttribute dimAttribute;
DimensionServiceProvider DimensionServiceProvider = new DimensionServiceProvider();
LedgerAccountContract LedgerAccountContract = new LedgerAccountContract();
DimensionAttributeValueContract ValueContract;
List ListValueContract = new List(Types::Class);
dimensionAttributeValueCombination dimensionAttributeValueCombination;
DimensionStorage dimStorage;
// Get Voucher
NumberSeq numberSeq;
NumberSequenceReference numberSequenceReference;
inventItemPrice _inventItemPrice;
InventDim _InventDim;
InventTableModule _inventTableModuleInvent = null;
InventPriceMap inventPriceMap;
;
recordsCount = InventJournalTrans_ds.recordsMarked().lastIndex(); // Total number of marked records.
_getJournalID = InventJournalTrans_ds.getFirst(1);
ttsBegin;
while (_getJournalID)
{
_mainAccount = _getJournalID.BIT_MainAccountNum;
CashFlow = _getJournalID.BIT_CashFlow; // #1
Location = _getJournalID.BIT_Location; // #2
Divison = _getJournalID.BIT_Division; // #3
YOPID = _getJournalID.BIT_YOPid; // #4
Fields = _getJournalID.BIT_Fields; // #5
Vehicle = _getJournalID.BIT_Vehicle; // #6
Station = _getJournalID.BIT_Station; // #7
Category = _getJournalID.BIT_Category; // #8
accountCon = [_mainAccount, _mainAccount];
mainAcc = MainAccount::findByMainAccountId(_mainAccount);
if(!mainAcc)
{
error ("COA does not exist in this company");
}
else
recordvalue = DimensionHierarchy::getAccountStructure(mainAcc.RecId);
//If the ledgerDimension already created then we can find it in below table
select recid from dimCombination where dimCombination.MainAccount == mainAcc.RecId
&& dimCombination.AccountStructure == recordvalue;
if (!dimCombination)
{
accountCon = [_mainAccount, _mainAccount, 0];
if (CashFlow) // #1
{
accountCon += ["CashFlow", CashFlow];
dimCount++;
}
if (Location) // #2
{
accountCon += ["Location", Location];
dimCount++;
}
if (Divison) // #3
{
accountCon += ["Divison", Divison];
dimCount++;
}
if (YOPID) // #4
{
accountCon += ["YOPID", YOPID];
dimCount++;
}
}
if (Vehicle) // #5
{
accountCon += ["Vehicle", Vehicle];
dimCount++;
}
if (Fields) // #6
{
accountCon += ["Fields", Fields];
dimCount++;
if (Station) // #7
{
accountCon += ["Station", Station];
dimCount++;
}
if (Category) // #8
{
accountCon += ["Category", Category];
dimCount++;
}
accountCon = conPoke(accountCon, 9 , dimCount);
}
//below code lines create ledgerdimension as per chart of account setup
dimensionStorage = DimensionStorage::findById(dimCombination.RecId);
if (dimensionStorage == null)
{
warning("This is a new COA + new Dimension");
if (CashFlow) // #1
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('CashFlow') ;
ValueContract.parmValue(CashFlow);
ListValueContract.addEnd(ValueContract);
}
if (Location) // #2
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Location') ;
ValueContract.parmValue(Location);
ListValueContract.addEnd(ValueContract);
}
if (Divison) // #3
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Divison') ;
ValueContract.parmValue(Divison);
ListValueContract.addEnd(ValueContract);
}
if (YOPID) // #4
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('YOPID') ;
ValueContract.parmValue(YOPID);
ListValueContract.addEnd(ValueContract);
}
if (Vehicle) // #5
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Vehicle') ;
ValueContract.parmValue(Vehicle);
ListValueContract.addEnd(ValueContract);
}
if (Fields) // #6
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Fields') ;
ValueContract.parmValue(Fields);
ListValueContract.addEnd(ValueContract);
}
if (Station) // #7
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Station') ;
ValueContract.parmValue(Station);
ListValueContract.addEnd(ValueContract);
}
if (Category) // #8
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Category') ;
ValueContract.parmValue(Category);
ListValueContract.addEnd(ValueContract);
}
LedgerAccountContract.parmMainAccount(_mainAccount);
LedgerAccountContract.parmValues(ListValueContract);
dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);
dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());
// _getJournalID.Qty = abs(_getJournalID.Qty) * -1;
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet1 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret1;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet2 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret2;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet3 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret3;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet4 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret4;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet5 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret5;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet6 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret6;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet7 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret7;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet8 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret8;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet9 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret9;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet10 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret10;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet11 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret11;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet12 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret12;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet13 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret13;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet14 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret14;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet15 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret15;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet16 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret16;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet17 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret17;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet18 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret18;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet19 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret19;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet20 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret20;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet21 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret21;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.InventDimId == '')
{
_inventdim.clear();
_inventdim.InventSiteId = 'KSR'; // must be create parameter
_inventdim = InventDim::findOrCreate(_inventdim);
inventPriceMap = _getJournalID.inventTable().inventCostPriceMap(_inventdim.inventDimId ,_inventDim, _inventTableModuleInvent, _getJournalID.TransDate);
_getJournalID.CostPrice = inventPriceMap.price();
_getJournalID.PriceUnit = inventPriceMap.priceUnit();
_getJournalID.CostMarkup = inventPriceMap.markup();
_getJournalID.CostAmount = _getJournalID.calcCostAmount();
}
else
{
inventPriceMap = _getJournalID.inventTable().inventCostPriceMap(_getJournalID.InventDimId ,inventDim::find(_getJournalID.InventDimId), _inventTableModuleInvent, _getJournalID.TransDate);
_getJournalID.CostPrice = inventPriceMap.price();
_getJournalID.PriceUnit = inventPriceMap.priceUnit();
_getJournalID.CostMarkup = inventPriceMap.markup();
_getJournalID.CostAmount = _getJournalID.calcCostAmount();
_getJournalID.InventDimId = _getJournalID.InventDimId;
}
_getJournalID.LedgerDimension = dimensionAttributeValueCombination.RecId;
_getJournalID.InventTransId = NumberSeq::newGetNum(InventParameters::numRefInventTransId()).num();
numberSeq = new NumberSeq();
numberSequenceReference = InventParameters::numRefInventJournalVoucherId();
numberseq = NumberSeq::newGetNum(numberSequenceReference);
_getJournalID.Voucher = numberseq.num();
info(strFmt("Account %1 has been inserted - JournalID %2", dimensionAttributeValueCombination.DisplayValue , _getJournalID.JournalID));
_getJournalID.update();
_getJournalID = InventJournalTrans_ds.getNext();
}
else
{
hierarchyCount = dimensionStorage.hierarchyCount();
for(hierarchyIndex = 1; hierarchyIndex <= hierarchyCount; hierarchyIndex++)
{
segmentCount = dimensionStorage.segmentCountForHierarchy(hierarchyIndex);
accountCon += [0];
//Loop through segments and display required values
for (segmentIndex = 1; segmentIndex <= segmentCount; segmentIndex++)
{
segment = dimensionStorage.getSegmentForHierarchy(hierarchyIndex, segmentIndex);
hierarchyLevel = DimensionHierarchyLevel::findByDimensionHierarchyAndLevel(recordvalue, segmentIndex);
dimAttribute = DimensionAttribute::find(hierarchyLevel.DimensionAttribute);
switch (dimAttribute.Name)
{
case "CashFlow" : // #1
if(CashFlow)
{
accountCon += ["CashFlow", CashFlow];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
case "Location": // #2
if(Location)
{
accountCon += ["Location", Location];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
case "Divison": // #3
if(Divison)
{
accountCon += ["Divison", Divison];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
case "YOPID": // #4
if(YOPID)
{
accountCon += ["YOPID", YOPID];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
case "Vehicle": // #5
if(Vehicle)
{
accountCon += ["Vehicle", Vehicle];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
case "Fields": // #6
if(Fields)
{
accountCon += ["Fields", Fields];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
case "Station": // #7
if(Station)
{
accountCon += ["Station", Station];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
case "Category": // #8
if(Category)
{
accountCon += ["Category", Category];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
}
}
}
// _getJournalID.Qty = abs(_getJournalID.Qty) * -1;
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet1 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret1;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet2 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret2;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet3 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret3;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet4 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret4;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet5 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret5;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet6 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret6;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet7 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret7;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet8 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret8;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet9 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret9;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet10 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret10;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet11 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret11;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet12 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret12;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet13 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret13;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet14 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret14;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet15 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret15;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet16 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret16;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet17 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret17;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet18 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret18;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet19 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret19;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet20 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret20;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet21 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret21;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.InventDimId == '')
{
_inventdim.clear();
_inventdim.InventSiteId = 'KSR'; // must be create parameter
_inventdim = InventDim::findOrCreate(_inventdim);
inventPriceMap = _getJournalID.inventTable().inventCostPriceMap(_inventdim.inventDimId ,_inventDim, _inventTableModuleInvent, _getJournalID.TransDate);
_getJournalID.CostPrice = inventPriceMap.price();
_getJournalID.PriceUnit = inventPriceMap.priceUnit();
_getJournalID.CostMarkup = inventPriceMap.markup();
_getJournalID.CostAmount = _getJournalID.calcCostAmount();
}
else
{
inventPriceMap = _getJournalID.inventTable().inventCostPriceMap(_getJournalID.InventDimId ,inventDim::find(_getJournalID.InventDimId), _inventTableModuleInvent, _getJournalID.TransDate);
_getJournalID.CostPrice = inventPriceMap.price();
_getJournalID.PriceUnit = inventPriceMap.priceUnit();
_getJournalID.CostMarkup = inventPriceMap.markup();
_getJournalID.CostAmount = _getJournalID.calcCostAmount();
_getJournalID.InventDimId = _getJournalID.InventDimId;
}
ledgerDimension = AxdDimensionUtil::getLedgerAccountId(accountCon);
select _DimensionAttributeValueCombination where _DimensionAttributeValueCombination.RecId == ledgerDimension;
_getJournalID.LedgerDimension = _DimensionAttributeValueCombination.RecId;
_getJournalID.InventTransId = NumberSeq::newGetNum(InventParameters::numRefInventTransId()).num();
numberSeq = new NumberSeq();
numberSequenceReference = InventParameters::numRefInventJournalVoucherId();
numberseq = NumberSeq::newGetNum(numberSequenceReference);
_getJournalID.Voucher = numberseq.num();
info(strFmt("Account %1 has been inserted - JournalID %2", _getJournalID.LedgerDimension, _getJournalID.JournalId));
_getJournalID.update();
_getJournalID = InventJournalTrans_ds.getNext();
}
}
ttsCommit;
InventJournalTrans_ds.executeQuery();
}
========================================================
======GENERATE ==================
public void Generate()
{
int rowCount = 0;
int i = 1;
boolean isCheckHG, isCheckPL, isCheckPR = false;
InventTransId inventTransID;
Object callerForm = element.args().caller();
InventJournalTrans _InventJournalTrans;
InventDim _Inventdim, _inventdim_getprice;
InventDimId _InventdimidHG, _InventdimidPC, _InventdimidPL;
/*EcoResProduct _EcoResProduct;
EcoResProductMaster _EcoResProductMaster;
EcoResProductMasterConfiguration _EcoResProductMasterConfiguration;
EcoResConfiguration _EcoResConfiguration;*/
inventPriceMap _inventPriceMapHG, _inventPriceMapPC, _inventPriceMapPL;
EcoResItemConfigurationName _Config;
str inventDimArray[3];
Qty qtyArray[3];
ItemCostPrice CostPrice[3];
PriceUnit PriceUnit[3];
MainAccountNum inventAccountNum;
DimensionAttributeValueCombination dimensionAttributeValueCombination;
str 10 ffbConfig[3];
if(BIT_TB_TemporaryCPO.InUse != NoYes::Yes
&& (BIT_TB_TemporaryCPO.QtyHG + BIT_TB_TemporaryCPO.QtyPC + BIT_TB_TemporaryCPO.QtyPL == BIT_TB_TemporaryCPO.Qty))
{
/*Select firstOnly _EcoResProduct where _EcoResProduct.DisplayProductNumber == BIT_TB_TemporaryCPO.ItemNumber;
Select firstOnly _EcoResProductMaster where _EcoResProductMaster.RecId == _EcoResProduct.RecId;
select firstOnly _EcoResProductMasterConfiguration where _EcoResProductMasterConfiguration.ConfigProductMaster == _EcoResProductMaster.RecId;
select firstOnly _EcoResConfiguration where _EcoResConfiguration.RecId == _EcoResProductMasterConfiguration.Configuration;
info(strFmt("%1", _EcoResConfiguration.Name));*/
if(BIT_TB_TemporaryCPO.HG)
{
_InventdimidHG = BIT_Tb_ParmCPO::find(BIT_TB_TemporaryCPO.ItemNumber, "HG").InventDimId;
rowCount++;
inventDimArray[rowCount] = _InventdimidHG;
qtyArray[rowCount] = BIT_TB_TemporaryCPO.QtyHG;
ffbConfig[rowCount] = BIT_Tb_ParmCPO::find(BIT_TB_TemporaryCPO.ItemNumber, "HG").Ref_CPO;
_InventJournalTrans.initFromInventJournalTable(_InventJournalTable);
_InventJournalTrans.initFromInventTable(InventTable::find(BIT_TB_TemporaryCPO.ItemNumber));
_inventPriceMapHG = _InventJournalTrans.inventTable().inventCostPriceMap(_InventdimidHG,
InventDim::find(_InventdimidHG), InventTableModule::find(BIT_TB_TemporaryCPO.ItemNumber, ModuleInventPurchSales::Invent) , BIT_TB_TemporaryCPO.Transdate);
CostPrice[rowCount] = _inventPriceMapHG.price();
PriceUnit[rowCount] = _inventPriceMapHG.priceUnit();
}
if(BIT_TB_TemporaryCPO.PC)
{
_InventdimidPC = BIT_Tb_ParmCPO::find(BIT_TB_TemporaryCPO.ItemNumber, "PC").InventDimId;
rowCount++;
inventDimArray[rowCount] = _InventdimidPC;
qtyArray[rowCount] = BIT_TB_TemporaryCPO.QtyPC;
ffbConfig[rowCount] = BIT_Tb_ParmCPO::find(BIT_TB_TemporaryCPO.ItemNumber, "PC").Ref_CPO;
_InventJournalTrans.initFromInventJournalTable(_InventJournalTable);
_InventJournalTrans.initFromInventTable(InventTable::find(BIT_TB_TemporaryCPO.ItemNumber));
_inventPriceMapPC = _InventJournalTrans.inventTable().inventCostPriceMap(InventDim::find(_InventdimidPC).inventDimId,
InventDim::find(_InventdimidHG), InventTableModule::find(BIT_TB_TemporaryCPO.ItemNumber, ModuleInventPurchSales::Invent), BIT_TB_TemporaryCPO.Transdate);
CostPrice[rowCount] = _inventPriceMapPC.price();
PriceUnit[rowCount] = _inventPriceMapPC.priceUnit();
}
if(BIT_TB_TemporaryCPO.Plasma)
{
_InventdimidPL = BIT_Tb_ParmCPO::find(BIT_TB_TemporaryCPO.ItemNumber, "PL").InventDimId;
rowCount++;
inventDimArray[rowCount] = _InventdimidPL;
qtyArray[rowCount] = BIT_TB_TemporaryCPO.QtyPL;
ffbConfig[rowCount] = BIT_Tb_ParmCPO::find(BIT_TB_TemporaryCPO.ItemNumber, "PL").Ref_CPO;
_InventJournalTrans.initFromInventJournalTable(_InventJournalTable);
_InventJournalTrans.initFromInventTable(InventTable::find(BIT_TB_TemporaryCPO.ItemNumber));
_inventPriceMapPL = _InventJournalTrans.inventTable().inventCostPriceMap(InventDim::find(_InventdimidPL).inventDimId,
InventDim::find(_InventdimidHG), InventTableModule::find(BIT_TB_TemporaryCPO.ItemNumber, moduleinventpurchsales::Invent), BIT_TB_TemporaryCPO.Transdate);
CostPrice[rowCount] = _inventPriceMapPL.price();
PriceUnit[rowCount] = _inventPriceMapPL.priceUnit();
}
ttsBegin;
for(i=1; i<= rowCount; i++)
{
_InventJournalTrans.clear();
_InventJournalTrans.LineNum = i;
_InventJournalTrans.initFromInventJournalTable(_InventJournalTable);
_InventJournalTrans.initFromInventTable(InventTable::find(BIT_TB_TemporaryCPO.ItemNumber));
_InventJournalTrans.TransDate = BIT_TB_TemporaryCPO.Transdate;
_InventJournalTrans.ItemId = BIT_TB_TemporaryCPO.ItemNumber;
inventTransID = NumberSeq::newGetNum(InventParameters::numRefInventTransId()).num();
_InventJournalTrans.InventTransId = inventTransID;
_InventJournalTrans.Voucher = NumberSeq::newGetNumFromId(_InventJournalTable.VoucherNumberSequenceTable).num();
_InventJournalTrans.Qty = qtyArray[i];
_InventJournalTrans.CostPrice = CostPrice[i];
_InventJournalTrans.PriceUnit = PriceUnit[i];
_InventJournalTrans.InventDimId = inventDimArray[i];
_InventJournalTrans.CostAmount = _InventJournalTrans.CostPrice * _InventJournalTrans.Qty;
// Get Main Account
inventAccountNum = BIT_Tb_ParmCPO::GetInventMainAccount(BIT_TB_TemporaryCPO.ItemNumber, ffbConfig[i]);
_InventJournalTrans.LedgerDimension = element.CreateDimensionRecid(inventAccountNum);
_InventJournalTrans.insert();
}
ttsCommit;
// .:: Auto Posting ::.
//if(InventJournalCheckPost::newPostJournal(_InventJournalTable).validate())
//{
//InventJournalCheckPost::newPostJournal(_InventJournalTable).run();
// info("Qty has been splited and Posted");
//}
ttsBegin;
BIT_TB_TemporaryCPO.InUse = NoYes::Yes;
BIT_TB_TemporaryCPO.update();
ttsCommit;
info("Qty has been splited");
element.close();
}
else
{
error(strFmt("Item %1 has been used at %2 Or Qty Homeground Or Qty Purchase Or Qty Plasma cannot not same Qty", BIT_TB_TemporaryCPO.ItemNumber, BIT_TB_TemporaryCPO.Transdate));
}
}
======GENERATE ==================
========= FULL CODE ======
void BIT_GetAccount8Dimesions()
{
container conDimValue;
RefRecId ledgerDimension;
DimensionAttributeValueCombination _DimensionAttributeValueCombination;
LedgerJournalTrans _getJournalnum, activeRow;
Common common;
int recordsCount;
str _mainAccount, CostCenterBSP, CashFlow, Intercompany, Location , Division, YOPID, Fields, Vehicle, Category, Station;
container con;
container accountCon;
MainAccount mainAcc;
DimensionStorage dimensionStorage;
DimensionAttributeValueCombination dimCombination;
int hierarchyCount, hierarchyIndex, segmentCount, segmentIndex;
RefRecId recordvalue;
int dimCount;
DimensionStorageSegment segment;
DimensionHierarchyLevel hierarchyLevel;
DimensionAttribute dimAttribute;
DimensionServiceProvider DimensionServiceProvider = new DimensionServiceProvider();
LedgerAccountContract LedgerAccountContract = new LedgerAccountContract();
DimensionAttributeValueContract ValueContract;
List ListValueContract = new List(Types::Class);
dimensionAttributeValueCombination dimensionAttributeValueCombination;
DimensionStorage dimStorage;
// Get Exchange Rate
ExchangeRateHelper exchangeRateHelper;
Transdate Transactiondate, FirstOfMth;
CurrencyCode transactionCurrency;
CurrencyExchangeRate exchangeRate1;
CurrencyExchangeRate exchangeRate2;
Real r=1;
str ExchRate;
;
recordsCount = LedgerJournalTrans_ds.recordsMarked().lastIndex(); // Total number of marked records.
_getJournalnum = LedgerJournalTrans_ds.getFirst(1);
while (_getJournalnum)
{
common = LedgerJournalTrans_ds.cursor();
activeRow = common;
_mainAccount = _getJournalnum.BIT_LedgerDimension;
CashFlow = _getJournalnum.BIT_CashFlow; // #1
Location = _getJournalnum.BIT_Location; // #2
Division = _getJournalnum.BIT_Division; // #3
YOPID = _getJournalnum.BIT_YOPid; // #4
Vehicle = _getJournalnum.BIT_Vehicle; // #5
Fields = _getJournalnum.BIT_Fields; // #6
Station = _getJournalnum.BIT_Station; // #7
Category = _getJournalnum.BIT_Category; // #8
//Resetting container
accountCon = conNull();
accountCon = [_mainAccount, _mainAccount];
mainAcc = MainAccount::findByMainAccountId(_mainAccount);
if(!mainAcc)
{
error ("COA does not exist in this company");
}
else
recordvalue = DimensionHierarchy::getAccountStructure(mainAcc.RecId);
// Get Exchange Rate
transactionCurrency = _getJournalnum.CurrencyCode;
FirstOfMth = mkdate(1,mthofyr(_getJournalnum.TransDate),year(_getJournalnum.TransDate));
exchangeRateHelper = ExchangeRateHelper::newExchangeDate(Ledger::current(), transactionCurrency, transactiondate);
exchangeRate1 = exchangeRateHelper.getExchangeRate1();
exchangeRate2 = exchangeRateHelper.getExchangeRate2();
ExchRate = num2str(r,0,17,1,3);
//If the ledgerDimension already created then we can find it in below table
select recid from dimCombination where dimCombination.MainAccount == mainAcc.RecId
&& dimCombination.AccountStructure == recordvalue;
if (!dimCombination)
{
accountCon = [_mainAccount, _mainAccount,''];
// #1
if (CashFlow)
{
accountCon += ["CashFlow", CashFlow];
dimCount++;
}
// #2
if (Location)
{
accountCon += ["Location", Location];
dimCount++;
}
// #3
if (Division)
{
accountCon += ["Divison", Division];
dimCount++;
}
// #4
if (YOPID)
{
accountCon += ["YOPID", YOPID];
dimCount++;
}
// #5
if (Vehicle)
{
accountCon += ["Vehicle", Vehicle];
dimCount++;
}
// #6
if (Fields)
{
accountCon += ["Fields", Fields];
dimCount++;
}
// #7
if (Station)
{
accountCon += ["Station", Station];
dimCount++;
}
// #8
if (Category)
{
accountCon += ["Category", Category];
dimCount++;
}
}
accountCon = conPoke(accountCon, 3 , dimCount);
//below code lines create ledgerdimension as per chart of account setup
dimensionStorage = DimensionStorage::findById(dimCombination.RecId);
if (dimensionStorage == null)
{
ttsBegin;
//#1
if (CashFlow)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('CashFlow') ;
ValueContract.parmValue(CashFlow);
ListValueContract.addEnd(ValueContract);
}
//#2
if (Location)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Location') ;
ValueContract.parmValue(Location);
ListValueContract.addEnd(ValueContract);
}
//#3
if (Division)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Divison') ;
ValueContract.parmValue(Division);
ListValueContract.addEnd(ValueContract);
}
//#4
if (YOPID)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('YOPID') ;
ValueContract.parmValue(YOPID);
ListValueContract.addEnd(ValueContract);
}
//#5
if (Vehicle)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Vehicle') ;
ValueContract.parmValue(Vehicle);
ListValueContract.addEnd(ValueContract);
}
//#6
if (Fields)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Fields') ;
ValueContract.parmValue(Fields);
ListValueContract.addEnd(ValueContract);
}
// #7
if (Station)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Station') ;
ValueContract.parmValue(Station);
ListValueContract.addEnd(ValueContract);
}
// #8
if (Category)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Category') ;
ValueContract.parmValue(Category);
ListValueContract.addEnd(ValueContract);
}
info(strFmt('NEW %1 & %2 %3',_mainAccount, ValueContract.parmName(), ValueContract.parmValue()));
LedgerAccountContract.parmMainAccount(_mainAccount);
LedgerAccountContract.parmValues(ListValueContract);
dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);
dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());
_getJournalnum.LedgerDimension = dimensionAttributeValueCombination.RecId;
//_getJournalnum.ExchRate = any2real(ExchRate);
_getJournalnum.editExchRate(false, 1);
info(strFmt("Account %1 has been inserted - Journalnum %2", dimensionAttributeValueCombination.DisplayValue , _getJournalnum.JournalNum));
_getJournalnum.update();
_getJournalnum = LedgerJournalTrans_ds.getNext();
ttsCommit;
}
else
{
ttsBegin;
hierarchyCount = dimensionStorage.hierarchyCount();
for(hierarchyIndex = 1; hierarchyIndex <= hierarchyCount; hierarchyIndex++)
{
segmentCount = dimensionStorage.segmentCountForHierarchy(hierarchyIndex);
// accountCon += [0];
//Loop through segments and display required values
for (segmentIndex = 1; segmentIndex <= segmentCount; segmentIndex++)
{
segment = dimensionStorage.getSegmentForHierarchy(hierarchyIndex, segmentIndex);
hierarchyLevel = DimensionHierarchyLevel::findByDimensionHierarchyAndLevel(recordvalue, segmentIndex);
dimAttribute = DimensionAttribute::find(hierarchyLevel.DimensionAttribute);
switch (dimAttribute.Name)
{
// #1
case "CashFlow" :
if(CashFlow)
{
accountCon += ["CashFlow", CashFlow];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
// #2
case "Location":
if(Location)
{
accountCon += ["Location", Location];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
// #3
case "Divison":
if(Division)
{
accountCon += ["Divison", Division];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
// #4
case "YOPID":
if(YOPID)
{
accountCon += ["YOPID", YOPID];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
// #5
case "Vehicle":
if(Vehicle)
{
accountCon += ["Vehicle", Vehicle];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
// #6
case "Fields":
if(Fields)
{
accountCon += ["Fields", Fields];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
// #7
case "Station":
if(Station)
{
accountCon += ["Station", Station];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
// #8
case "Category":
if(Category)
{
accountCon += ["Category", Category];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
default :
// info(strFmt('Error Looking for dimension %1',dimAttribute.Name));
break;
}
}
}
ledgerDimension = AxdDimensionUtil::getLedgerAccountId(accountCon);
select _DimensionAttributeValueCombination where _DimensionAttributeValueCombination.RecId == ledgerDimension;
_getJournalnum.LedgerDimension = _DimensionAttributeValueCombination.RecId;
//_getJournalnum.ExchRate = any2real(ExchRate);
_getJournalnum.editExchRate(false, 1);
info(strFmt("Account %1 has been inserted - Journalnum %2 Voucher Num %3 %4", _getJournalnum.LedgerDimension, _getJournalnum.JournalNum,_getJournalnum.Voucher, _getJournalnum.accountName()));
_getJournalnum.update();
_getJournalnum = LedgerJournalTrans_ds.getNext();
ttsCommit;
}
}
LedgerJournalTrans_ds.executeQuery();
LedgerJournalTrans_ds.reread();
LedgerJournalTrans_ds.refresh();
LedgerJournalTrans_ds.research(true);
}
==================== ATAU ==================================
private CostPriceAverage Addit_runningAvgCostPrice(ItemId _itemId = 'A01')
{
InventDim dim;
InventSum inventSum;
inventDim inventDim;
InventTable inventTable;
InventCostPriceCache inventCostPriceCache;
UnitOfMeasureConverter_Product secondaryToInventUnitConverter;
UnitOfMeasureRecId fromUnitOfMeasureRecId;
UnitOfMeasureRecId toUnitOfMeasureRecId;
select firstOnly inventSum
where inventSum.ItemId == _itemId
join inventDim;
if (!inventSum.InventDimId)
{
dim = InventDim::findDim(inventDim);
if (dim.InventDimId)
{
inventSum.InventDimId = dim.InventDimId;
}
}
inventCostPriceCache = InventCostPriceCache::construct();
inventTable = inventSum.inventTable();
fromUnitOfMeasureRecId = UnitOfMeasure::findBySymbol(inventTable.salesUnitId()).RecId;
toUnitOfMeasureRecId = UnitOfMeasure::findBySymbol(inventTable.inventUnitId()).RecId;
secondaryToInventUnitConverter = UnitOfMeasureConverter_Product::construct();
secondaryToInventUnitConverter.parmProduct(inventTable.Product);
secondaryToInventUnitConverter.parmFromUnitOfMeasure(fromUnitOfMeasureRecId);
secondaryToInventUnitConverter.parmToUnitOfMeasure(toUnitOfMeasureRecId);
secondaryToInventUnitConverter.parmRoundAbsoluteValue(NoYes::Yes);
secondaryToInventUnitConverter.parmApplyRounding(NoYes::Yes);
info(strFmt("%1", Currency::amount(inventCostPriceCache.costPricePcs(inventSum, inventDim) * secondaryToInventUnitConverter.convertValue(1))));
return Currency::amount(inventCostPriceCache.costPricePcs(inventSum, inventDim) * secondaryToInventUnitConverter.convertValue(1));
}
public static Price TIDgetSTDCostItemPrice(ItemId _itemId,TransDate _activationDate,InventSiteId _inventSiteId)
{
InventDim InventDimLoc;
InventItemPrice inventItemPriceLoc;
InventDimLoc.clear();
InventDimLoc.InventSiteId = _inventSiteId;
InventDimLoc = InventDim::findOrCreate(InventDimLoc);
inventItemPriceLoc = InventItemPrice::findCurrent(_itemId,CostingVersionPriceType::Cost,InventDimLoc.inventDimId,
_activationDate,_inventSiteId,InventItemCostingType::Standard);
return inventItemPriceLoc.Price;
}
oR
public static Price Addit_getSTDCostItemPrice(ItemId _itemId = 'A010001001',TransDate _activationDate = systemDateGet(),InventSiteId _inventSiteId = 'KSR')
{
InventDim InventDimLoc;
InventItemPrice inventItemPriceLoc;
InventDimLoc.clear();
InventDimLoc.InventSiteId = _inventSiteId;
InventDimLoc = InventDim::findOrCreate(InventDimLoc);
inventItemPriceLoc = InventItemPrice::findCurrent(_itemId,CostingVersionPriceType::Cost,InventDimLoc.inventDimId,
_activationDate,_inventSiteId,InventItemCostingType::Last);
info(strFmt("%1", inventItemPriceLoc.Price));
return inventItemPriceLoc.Price;
}
=OR=
void BIT_GetAccount8Dimesions()
{
container conDimValue;
RefRecId ledgerDimension;
DimensionAttributeValueCombination _DimensionAttributeValueCombination;
InventJournalTrans _getJournalID;
int recordsCount;
str _mainAccount, CashFlow, Location , Divison, YOPID, Fields, Vehicle, Station, Category;
container con;
container accountCon;
MainAccount mainAcc;
DimensionStorage dimensionStorage;
DimensionAttributeValueCombination dimCombination;
int hierarchyCount, hierarchyIndex, segmentCount, segmentIndex;
RefRecId recordvalue;
int dimCount;
DimensionStorageSegment segment;
DimensionHierarchyLevel hierarchyLevel;
DimensionAttribute dimAttribute;
DimensionServiceProvider DimensionServiceProvider = new DimensionServiceProvider();
LedgerAccountContract LedgerAccountContract = new LedgerAccountContract();
DimensionAttributeValueContract ValueContract;
List ListValueContract = new List(Types::Class);
dimensionAttributeValueCombination dimensionAttributeValueCombination;
DimensionStorage dimStorage;
// Get Voucher
NumberSeq numberSeq;
NumberSequenceReference numberSequenceReference;
inventItemPrice _inventItemPrice;
InventDim _InventDim;
InventTableModule _inventTableModuleInvent = null;
InventPriceMap inventPriceMap;
;
recordsCount = InventJournalTrans_ds.recordsMarked().lastIndex(); // Total number of marked records.
_getJournalID = InventJournalTrans_ds.getFirst(1);
ttsBegin;
while (_getJournalID)
{
_mainAccount = _getJournalID.BIT_MainAccountNum;
CashFlow = _getJournalID.BIT_CashFlow; // #1
Location = _getJournalID.BIT_Location; // #2
Divison = _getJournalID.BIT_Division; // #3
YOPID = _getJournalID.BIT_YOPid; // #4
Fields = _getJournalID.BIT_Fields; // #5
Vehicle = _getJournalID.BIT_Vehicle; // #6
Station = _getJournalID.BIT_Station; // #7
Category = _getJournalID.BIT_Category; // #8
accountCon = [_mainAccount, _mainAccount];
mainAcc = MainAccount::findByMainAccountId(_mainAccount);
if(!mainAcc)
{
error ("COA does not exist in this company");
}
else
recordvalue = DimensionHierarchy::getAccountStructure(mainAcc.RecId);
//If the ledgerDimension already created then we can find it in below table
select recid from dimCombination where dimCombination.MainAccount == mainAcc.RecId
&& dimCombination.AccountStructure == recordvalue;
if (!dimCombination)
{
accountCon = [_mainAccount, _mainAccount, 0];
if (CashFlow) // #1
{
accountCon += ["CashFlow", CashFlow];
dimCount++;
}
if (Location) // #2
{
accountCon += ["Location", Location];
dimCount++;
}
if (Divison) // #3
{
accountCon += ["Divison", Divison];
dimCount++;
}
if (YOPID) // #4
{
accountCon += ["YOPID", YOPID];
dimCount++;
}
}
if (Vehicle) // #5
{
accountCon += ["Vehicle", Vehicle];
dimCount++;
}
if (Fields) // #6
{
accountCon += ["Fields", Fields];
dimCount++;
if (Station) // #7
{
accountCon += ["Station", Station];
dimCount++;
}
if (Category) // #8
{
accountCon += ["Category", Category];
dimCount++;
}
accountCon = conPoke(accountCon, 9 , dimCount);
}
//below code lines create ledgerdimension as per chart of account setup
dimensionStorage = DimensionStorage::findById(dimCombination.RecId);
if (dimensionStorage == null)
{
warning("This is a new COA + new Dimension");
if (CashFlow) // #1
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('CashFlow') ;
ValueContract.parmValue(CashFlow);
ListValueContract.addEnd(ValueContract);
}
if (Location) // #2
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Location') ;
ValueContract.parmValue(Location);
ListValueContract.addEnd(ValueContract);
}
if (Divison) // #3
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Divison') ;
ValueContract.parmValue(Divison);
ListValueContract.addEnd(ValueContract);
}
if (YOPID) // #4
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('YOPID') ;
ValueContract.parmValue(YOPID);
ListValueContract.addEnd(ValueContract);
}
if (Vehicle) // #5
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Vehicle') ;
ValueContract.parmValue(Vehicle);
ListValueContract.addEnd(ValueContract);
}
if (Fields) // #6
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Fields') ;
ValueContract.parmValue(Fields);
ListValueContract.addEnd(ValueContract);
}
if (Station) // #7
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Station') ;
ValueContract.parmValue(Station);
ListValueContract.addEnd(ValueContract);
}
if (Category) // #8
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Category') ;
ValueContract.parmValue(Category);
ListValueContract.addEnd(ValueContract);
}
LedgerAccountContract.parmMainAccount(_mainAccount);
LedgerAccountContract.parmValues(ListValueContract);
dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);
dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());
// _getJournalID.Qty = abs(_getJournalID.Qty) * -1;
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet1 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret1;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet2 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret2;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet3 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret3;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet4 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret4;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet5 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret5;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet6 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret6;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet7 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret7;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet8 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret8;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet9 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret9;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet10 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret10;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet11 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret11;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet12 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret12;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet13 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret13;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet14 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret14;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet15 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret15;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet16 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret16;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet17 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret17;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet18 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret18;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet19 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret19;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet20 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret20;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet21 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret21;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.InventDimId == '')
{
_inventdim.clear();
_inventdim.InventSiteId = 'KSR'; // must be create parameter
_inventdim = InventDim::findOrCreate(_inventdim);
inventPriceMap = _getJournalID.inventTable().inventCostPriceMap(_inventdim.inventDimId ,_inventDim, _inventTableModuleInvent, _getJournalID.TransDate);
_getJournalID.CostPrice = inventPriceMap.price();
_getJournalID.PriceUnit = inventPriceMap.priceUnit();
_getJournalID.CostMarkup = inventPriceMap.markup();
_getJournalID.CostAmount = _getJournalID.calcCostAmount();
}
else
{
inventPriceMap = _getJournalID.inventTable().inventCostPriceMap(_getJournalID.InventDimId ,inventDim::find(_getJournalID.InventDimId), _inventTableModuleInvent, _getJournalID.TransDate);
_getJournalID.CostPrice = inventPriceMap.price();
_getJournalID.PriceUnit = inventPriceMap.priceUnit();
_getJournalID.CostMarkup = inventPriceMap.markup();
_getJournalID.CostAmount = _getJournalID.calcCostAmount();
_getJournalID.InventDimId = _getJournalID.InventDimId;
}
_getJournalID.LedgerDimension = dimensionAttributeValueCombination.RecId;
_getJournalID.InventTransId = NumberSeq::newGetNum(InventParameters::numRefInventTransId()).num();
numberSeq = new NumberSeq();
numberSequenceReference = InventParameters::numRefInventJournalVoucherId();
numberseq = NumberSeq::newGetNum(numberSequenceReference);
_getJournalID.Voucher = numberseq.num();
info(strFmt("Account %1 has been inserted - JournalID %2", dimensionAttributeValueCombination.DisplayValue , _getJournalID.JournalID));
_getJournalID.update();
_getJournalID = InventJournalTrans_ds.getNext();
}
else
{
hierarchyCount = dimensionStorage.hierarchyCount();
for(hierarchyIndex = 1; hierarchyIndex <= hierarchyCount; hierarchyIndex++)
{
segmentCount = dimensionStorage.segmentCountForHierarchy(hierarchyIndex);
accountCon += [0];
//Loop through segments and display required values
for (segmentIndex = 1; segmentIndex <= segmentCount; segmentIndex++)
{
segment = dimensionStorage.getSegmentForHierarchy(hierarchyIndex, segmentIndex);
hierarchyLevel = DimensionHierarchyLevel::findByDimensionHierarchyAndLevel(recordvalue, segmentIndex);
dimAttribute = DimensionAttribute::find(hierarchyLevel.DimensionAttribute);
switch (dimAttribute.Name)
{
case "CashFlow" : // #1
if(CashFlow)
{
accountCon += ["CashFlow", CashFlow];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
case "Location": // #2
if(Location)
{
accountCon += ["Location", Location];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
case "Divison": // #3
if(Divison)
{
accountCon += ["Divison", Divison];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
case "YOPID": // #4
if(YOPID)
{
accountCon += ["YOPID", YOPID];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
case "Vehicle": // #5
if(Vehicle)
{
accountCon += ["Vehicle", Vehicle];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
case "Fields": // #6
if(Fields)
{
accountCon += ["Fields", Fields];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
case "Station": // #7
if(Station)
{
accountCon += ["Station", Station];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
case "Category": // #8
if(Category)
{
accountCon += ["Category", Category];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
}
}
}
// _getJournalID.Qty = abs(_getJournalID.Qty) * -1;
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet1 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret1;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet2 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret2;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet3 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret3;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet4 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret4;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet5 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret5;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet6 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret6;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet7 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret7;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet8 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret8;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet9 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret9;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet10 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret10;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet11 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret11;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet12 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret12;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet13 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret13;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet14 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret14;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet15 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret15;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet16 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret16;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet17 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret17;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet18 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret18;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet19 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret19;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet20 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret20;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet21 && _getJournalID.LedgerDimension == 0)
{
_getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret21;
// _getJournalID.Qty = abs(_getJournalID.Qty);
}
if(_getJournalID.InventDimId == '')
{
_inventdim.clear();
_inventdim.InventSiteId = 'KSR'; // must be create parameter
_inventdim = InventDim::findOrCreate(_inventdim);
inventPriceMap = _getJournalID.inventTable().inventCostPriceMap(_inventdim.inventDimId ,_inventDim, _inventTableModuleInvent, _getJournalID.TransDate);
_getJournalID.CostPrice = inventPriceMap.price();
_getJournalID.PriceUnit = inventPriceMap.priceUnit();
_getJournalID.CostMarkup = inventPriceMap.markup();
_getJournalID.CostAmount = _getJournalID.calcCostAmount();
}
else
{
inventPriceMap = _getJournalID.inventTable().inventCostPriceMap(_getJournalID.InventDimId ,inventDim::find(_getJournalID.InventDimId), _inventTableModuleInvent, _getJournalID.TransDate);
_getJournalID.CostPrice = inventPriceMap.price();
_getJournalID.PriceUnit = inventPriceMap.priceUnit();
_getJournalID.CostMarkup = inventPriceMap.markup();
_getJournalID.CostAmount = _getJournalID.calcCostAmount();
_getJournalID.InventDimId = _getJournalID.InventDimId;
}
ledgerDimension = AxdDimensionUtil::getLedgerAccountId(accountCon);
select _DimensionAttributeValueCombination where _DimensionAttributeValueCombination.RecId == ledgerDimension;
_getJournalID.LedgerDimension = _DimensionAttributeValueCombination.RecId;
_getJournalID.InventTransId = NumberSeq::newGetNum(InventParameters::numRefInventTransId()).num();
numberSeq = new NumberSeq();
numberSequenceReference = InventParameters::numRefInventJournalVoucherId();
numberseq = NumberSeq::newGetNum(numberSequenceReference);
_getJournalID.Voucher = numberseq.num();
info(strFmt("Account %1 has been inserted - JournalID %2", _getJournalID.LedgerDimension, _getJournalID.JournalId));
_getJournalID.update();
_getJournalID = InventJournalTrans_ds.getNext();
}
}
ttsCommit;
InventJournalTrans_ds.executeQuery();
}
========================================================
======GENERATE ==================
public void Generate()
{
int rowCount = 0;
int i = 1;
boolean isCheckHG, isCheckPL, isCheckPR = false;
InventTransId inventTransID;
Object callerForm = element.args().caller();
InventJournalTrans _InventJournalTrans;
InventDim _Inventdim, _inventdim_getprice;
InventDimId _InventdimidHG, _InventdimidPC, _InventdimidPL;
/*EcoResProduct _EcoResProduct;
EcoResProductMaster _EcoResProductMaster;
EcoResProductMasterConfiguration _EcoResProductMasterConfiguration;
EcoResConfiguration _EcoResConfiguration;*/
inventPriceMap _inventPriceMapHG, _inventPriceMapPC, _inventPriceMapPL;
EcoResItemConfigurationName _Config;
str inventDimArray[3];
Qty qtyArray[3];
ItemCostPrice CostPrice[3];
PriceUnit PriceUnit[3];
MainAccountNum inventAccountNum;
DimensionAttributeValueCombination dimensionAttributeValueCombination;
str 10 ffbConfig[3];
if(BIT_TB_TemporaryCPO.InUse != NoYes::Yes
&& (BIT_TB_TemporaryCPO.QtyHG + BIT_TB_TemporaryCPO.QtyPC + BIT_TB_TemporaryCPO.QtyPL == BIT_TB_TemporaryCPO.Qty))
{
/*Select firstOnly _EcoResProduct where _EcoResProduct.DisplayProductNumber == BIT_TB_TemporaryCPO.ItemNumber;
Select firstOnly _EcoResProductMaster where _EcoResProductMaster.RecId == _EcoResProduct.RecId;
select firstOnly _EcoResProductMasterConfiguration where _EcoResProductMasterConfiguration.ConfigProductMaster == _EcoResProductMaster.RecId;
select firstOnly _EcoResConfiguration where _EcoResConfiguration.RecId == _EcoResProductMasterConfiguration.Configuration;
info(strFmt("%1", _EcoResConfiguration.Name));*/
if(BIT_TB_TemporaryCPO.HG)
{
_InventdimidHG = BIT_Tb_ParmCPO::find(BIT_TB_TemporaryCPO.ItemNumber, "HG").InventDimId;
rowCount++;
inventDimArray[rowCount] = _InventdimidHG;
qtyArray[rowCount] = BIT_TB_TemporaryCPO.QtyHG;
ffbConfig[rowCount] = BIT_Tb_ParmCPO::find(BIT_TB_TemporaryCPO.ItemNumber, "HG").Ref_CPO;
_InventJournalTrans.initFromInventJournalTable(_InventJournalTable);
_InventJournalTrans.initFromInventTable(InventTable::find(BIT_TB_TemporaryCPO.ItemNumber));
_inventPriceMapHG = _InventJournalTrans.inventTable().inventCostPriceMap(_InventdimidHG,
InventDim::find(_InventdimidHG), InventTableModule::find(BIT_TB_TemporaryCPO.ItemNumber, ModuleInventPurchSales::Invent) , BIT_TB_TemporaryCPO.Transdate);
CostPrice[rowCount] = _inventPriceMapHG.price();
PriceUnit[rowCount] = _inventPriceMapHG.priceUnit();
}
if(BIT_TB_TemporaryCPO.PC)
{
_InventdimidPC = BIT_Tb_ParmCPO::find(BIT_TB_TemporaryCPO.ItemNumber, "PC").InventDimId;
rowCount++;
inventDimArray[rowCount] = _InventdimidPC;
qtyArray[rowCount] = BIT_TB_TemporaryCPO.QtyPC;
ffbConfig[rowCount] = BIT_Tb_ParmCPO::find(BIT_TB_TemporaryCPO.ItemNumber, "PC").Ref_CPO;
_InventJournalTrans.initFromInventJournalTable(_InventJournalTable);
_InventJournalTrans.initFromInventTable(InventTable::find(BIT_TB_TemporaryCPO.ItemNumber));
_inventPriceMapPC = _InventJournalTrans.inventTable().inventCostPriceMap(InventDim::find(_InventdimidPC).inventDimId,
InventDim::find(_InventdimidHG), InventTableModule::find(BIT_TB_TemporaryCPO.ItemNumber, ModuleInventPurchSales::Invent), BIT_TB_TemporaryCPO.Transdate);
CostPrice[rowCount] = _inventPriceMapPC.price();
PriceUnit[rowCount] = _inventPriceMapPC.priceUnit();
}
if(BIT_TB_TemporaryCPO.Plasma)
{
_InventdimidPL = BIT_Tb_ParmCPO::find(BIT_TB_TemporaryCPO.ItemNumber, "PL").InventDimId;
rowCount++;
inventDimArray[rowCount] = _InventdimidPL;
qtyArray[rowCount] = BIT_TB_TemporaryCPO.QtyPL;
ffbConfig[rowCount] = BIT_Tb_ParmCPO::find(BIT_TB_TemporaryCPO.ItemNumber, "PL").Ref_CPO;
_InventJournalTrans.initFromInventJournalTable(_InventJournalTable);
_InventJournalTrans.initFromInventTable(InventTable::find(BIT_TB_TemporaryCPO.ItemNumber));
_inventPriceMapPL = _InventJournalTrans.inventTable().inventCostPriceMap(InventDim::find(_InventdimidPL).inventDimId,
InventDim::find(_InventdimidHG), InventTableModule::find(BIT_TB_TemporaryCPO.ItemNumber, moduleinventpurchsales::Invent), BIT_TB_TemporaryCPO.Transdate);
CostPrice[rowCount] = _inventPriceMapPL.price();
PriceUnit[rowCount] = _inventPriceMapPL.priceUnit();
}
ttsBegin;
for(i=1; i<= rowCount; i++)
{
_InventJournalTrans.clear();
_InventJournalTrans.LineNum = i;
_InventJournalTrans.initFromInventJournalTable(_InventJournalTable);
_InventJournalTrans.initFromInventTable(InventTable::find(BIT_TB_TemporaryCPO.ItemNumber));
_InventJournalTrans.TransDate = BIT_TB_TemporaryCPO.Transdate;
_InventJournalTrans.ItemId = BIT_TB_TemporaryCPO.ItemNumber;
inventTransID = NumberSeq::newGetNum(InventParameters::numRefInventTransId()).num();
_InventJournalTrans.InventTransId = inventTransID;
_InventJournalTrans.Voucher = NumberSeq::newGetNumFromId(_InventJournalTable.VoucherNumberSequenceTable).num();
_InventJournalTrans.Qty = qtyArray[i];
_InventJournalTrans.CostPrice = CostPrice[i];
_InventJournalTrans.PriceUnit = PriceUnit[i];
_InventJournalTrans.InventDimId = inventDimArray[i];
_InventJournalTrans.CostAmount = _InventJournalTrans.CostPrice * _InventJournalTrans.Qty;
// Get Main Account
inventAccountNum = BIT_Tb_ParmCPO::GetInventMainAccount(BIT_TB_TemporaryCPO.ItemNumber, ffbConfig[i]);
_InventJournalTrans.LedgerDimension = element.CreateDimensionRecid(inventAccountNum);
_InventJournalTrans.insert();
}
ttsCommit;
// .:: Auto Posting ::.
//if(InventJournalCheckPost::newPostJournal(_InventJournalTable).validate())
//{
//InventJournalCheckPost::newPostJournal(_InventJournalTable).run();
// info("Qty has been splited and Posted");
//}
ttsBegin;
BIT_TB_TemporaryCPO.InUse = NoYes::Yes;
BIT_TB_TemporaryCPO.update();
ttsCommit;
info("Qty has been splited");
element.close();
}
else
{
error(strFmt("Item %1 has been used at %2 Or Qty Homeground Or Qty Purchase Or Qty Plasma cannot not same Qty", BIT_TB_TemporaryCPO.ItemNumber, BIT_TB_TemporaryCPO.Transdate));
}
}
======GENERATE ==================
========= FULL CODE ======
void BIT_GetAccount8Dimesions()
{
container conDimValue;
RefRecId ledgerDimension;
DimensionAttributeValueCombination _DimensionAttributeValueCombination;
LedgerJournalTrans _getJournalnum, activeRow;
Common common;
int recordsCount;
str _mainAccount, CostCenterBSP, CashFlow, Intercompany, Location , Division, YOPID, Fields, Vehicle, Category, Station;
container con;
container accountCon;
MainAccount mainAcc;
DimensionStorage dimensionStorage;
DimensionAttributeValueCombination dimCombination;
int hierarchyCount, hierarchyIndex, segmentCount, segmentIndex;
RefRecId recordvalue;
int dimCount;
DimensionStorageSegment segment;
DimensionHierarchyLevel hierarchyLevel;
DimensionAttribute dimAttribute;
DimensionServiceProvider DimensionServiceProvider = new DimensionServiceProvider();
LedgerAccountContract LedgerAccountContract = new LedgerAccountContract();
DimensionAttributeValueContract ValueContract;
List ListValueContract = new List(Types::Class);
dimensionAttributeValueCombination dimensionAttributeValueCombination;
DimensionStorage dimStorage;
// Get Exchange Rate
ExchangeRateHelper exchangeRateHelper;
Transdate Transactiondate, FirstOfMth;
CurrencyCode transactionCurrency;
CurrencyExchangeRate exchangeRate1;
CurrencyExchangeRate exchangeRate2;
Real r=1;
str ExchRate;
;
recordsCount = LedgerJournalTrans_ds.recordsMarked().lastIndex(); // Total number of marked records.
_getJournalnum = LedgerJournalTrans_ds.getFirst(1);
while (_getJournalnum)
{
common = LedgerJournalTrans_ds.cursor();
activeRow = common;
_mainAccount = _getJournalnum.BIT_LedgerDimension;
CashFlow = _getJournalnum.BIT_CashFlow; // #1
Location = _getJournalnum.BIT_Location; // #2
Division = _getJournalnum.BIT_Division; // #3
YOPID = _getJournalnum.BIT_YOPid; // #4
Vehicle = _getJournalnum.BIT_Vehicle; // #5
Fields = _getJournalnum.BIT_Fields; // #6
Station = _getJournalnum.BIT_Station; // #7
Category = _getJournalnum.BIT_Category; // #8
//Resetting container
accountCon = conNull();
accountCon = [_mainAccount, _mainAccount];
mainAcc = MainAccount::findByMainAccountId(_mainAccount);
if(!mainAcc)
{
error ("COA does not exist in this company");
}
else
recordvalue = DimensionHierarchy::getAccountStructure(mainAcc.RecId);
// Get Exchange Rate
transactionCurrency = _getJournalnum.CurrencyCode;
FirstOfMth = mkdate(1,mthofyr(_getJournalnum.TransDate),year(_getJournalnum.TransDate));
exchangeRateHelper = ExchangeRateHelper::newExchangeDate(Ledger::current(), transactionCurrency, transactiondate);
exchangeRate1 = exchangeRateHelper.getExchangeRate1();
exchangeRate2 = exchangeRateHelper.getExchangeRate2();
ExchRate = num2str(r,0,17,1,3);
//If the ledgerDimension already created then we can find it in below table
select recid from dimCombination where dimCombination.MainAccount == mainAcc.RecId
&& dimCombination.AccountStructure == recordvalue;
if (!dimCombination)
{
accountCon = [_mainAccount, _mainAccount,''];
// #1
if (CashFlow)
{
accountCon += ["CashFlow", CashFlow];
dimCount++;
}
// #2
if (Location)
{
accountCon += ["Location", Location];
dimCount++;
}
// #3
if (Division)
{
accountCon += ["Divison", Division];
dimCount++;
}
// #4
if (YOPID)
{
accountCon += ["YOPID", YOPID];
dimCount++;
}
// #5
if (Vehicle)
{
accountCon += ["Vehicle", Vehicle];
dimCount++;
}
// #6
if (Fields)
{
accountCon += ["Fields", Fields];
dimCount++;
}
// #7
if (Station)
{
accountCon += ["Station", Station];
dimCount++;
}
// #8
if (Category)
{
accountCon += ["Category", Category];
dimCount++;
}
}
accountCon = conPoke(accountCon, 3 , dimCount);
//below code lines create ledgerdimension as per chart of account setup
dimensionStorage = DimensionStorage::findById(dimCombination.RecId);
if (dimensionStorage == null)
{
ttsBegin;
//#1
if (CashFlow)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('CashFlow') ;
ValueContract.parmValue(CashFlow);
ListValueContract.addEnd(ValueContract);
}
//#2
if (Location)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Location') ;
ValueContract.parmValue(Location);
ListValueContract.addEnd(ValueContract);
}
//#3
if (Division)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Divison') ;
ValueContract.parmValue(Division);
ListValueContract.addEnd(ValueContract);
}
//#4
if (YOPID)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('YOPID') ;
ValueContract.parmValue(YOPID);
ListValueContract.addEnd(ValueContract);
}
//#5
if (Vehicle)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Vehicle') ;
ValueContract.parmValue(Vehicle);
ListValueContract.addEnd(ValueContract);
}
//#6
if (Fields)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Fields') ;
ValueContract.parmValue(Fields);
ListValueContract.addEnd(ValueContract);
}
// #7
if (Station)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Station') ;
ValueContract.parmValue(Station);
ListValueContract.addEnd(ValueContract);
}
// #8
if (Category)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Category') ;
ValueContract.parmValue(Category);
ListValueContract.addEnd(ValueContract);
}
info(strFmt('NEW %1 & %2 %3',_mainAccount, ValueContract.parmName(), ValueContract.parmValue()));
LedgerAccountContract.parmMainAccount(_mainAccount);
LedgerAccountContract.parmValues(ListValueContract);
dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);
dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());
_getJournalnum.LedgerDimension = dimensionAttributeValueCombination.RecId;
//_getJournalnum.ExchRate = any2real(ExchRate);
_getJournalnum.editExchRate(false, 1);
info(strFmt("Account %1 has been inserted - Journalnum %2", dimensionAttributeValueCombination.DisplayValue , _getJournalnum.JournalNum));
_getJournalnum.update();
_getJournalnum = LedgerJournalTrans_ds.getNext();
ttsCommit;
}
else
{
ttsBegin;
hierarchyCount = dimensionStorage.hierarchyCount();
for(hierarchyIndex = 1; hierarchyIndex <= hierarchyCount; hierarchyIndex++)
{
segmentCount = dimensionStorage.segmentCountForHierarchy(hierarchyIndex);
// accountCon += [0];
//Loop through segments and display required values
for (segmentIndex = 1; segmentIndex <= segmentCount; segmentIndex++)
{
segment = dimensionStorage.getSegmentForHierarchy(hierarchyIndex, segmentIndex);
hierarchyLevel = DimensionHierarchyLevel::findByDimensionHierarchyAndLevel(recordvalue, segmentIndex);
dimAttribute = DimensionAttribute::find(hierarchyLevel.DimensionAttribute);
switch (dimAttribute.Name)
{
// #1
case "CashFlow" :
if(CashFlow)
{
accountCon += ["CashFlow", CashFlow];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
// #2
case "Location":
if(Location)
{
accountCon += ["Location", Location];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
// #3
case "Divison":
if(Division)
{
accountCon += ["Divison", Division];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
// #4
case "YOPID":
if(YOPID)
{
accountCon += ["YOPID", YOPID];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
// #5
case "Vehicle":
if(Vehicle)
{
accountCon += ["Vehicle", Vehicle];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
// #6
case "Fields":
if(Fields)
{
accountCon += ["Fields", Fields];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
// #7
case "Station":
if(Station)
{
accountCon += ["Station", Station];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
// #8
case "Category":
if(Category)
{
accountCon += ["Category", Category];
accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
}
break;
default :
// info(strFmt('Error Looking for dimension %1',dimAttribute.Name));
break;
}
}
}
ledgerDimension = AxdDimensionUtil::getLedgerAccountId(accountCon);
select _DimensionAttributeValueCombination where _DimensionAttributeValueCombination.RecId == ledgerDimension;
_getJournalnum.LedgerDimension = _DimensionAttributeValueCombination.RecId;
//_getJournalnum.ExchRate = any2real(ExchRate);
_getJournalnum.editExchRate(false, 1);
info(strFmt("Account %1 has been inserted - Journalnum %2 Voucher Num %3 %4", _getJournalnum.LedgerDimension, _getJournalnum.JournalNum,_getJournalnum.Voucher, _getJournalnum.accountName()));
_getJournalnum.update();
_getJournalnum = LedgerJournalTrans_ds.getNext();
ttsCommit;
}
}
LedgerJournalTrans_ds.executeQuery();
LedgerJournalTrans_ds.reread();
LedgerJournalTrans_ds.refresh();
LedgerJournalTrans_ds.research(true);
}
==================== ATAU ==================================
private CostPriceAverage Addit_runningAvgCostPrice(ItemId _itemId = 'A01')
{
InventDim dim;
InventSum inventSum;
inventDim inventDim;
InventTable inventTable;
InventCostPriceCache inventCostPriceCache;
UnitOfMeasureConverter_Product secondaryToInventUnitConverter;
UnitOfMeasureRecId fromUnitOfMeasureRecId;
UnitOfMeasureRecId toUnitOfMeasureRecId;
select firstOnly inventSum
where inventSum.ItemId == _itemId
join inventDim;
if (!inventSum.InventDimId)
{
dim = InventDim::findDim(inventDim);
if (dim.InventDimId)
{
inventSum.InventDimId = dim.InventDimId;
}
}
inventCostPriceCache = InventCostPriceCache::construct();
inventTable = inventSum.inventTable();
fromUnitOfMeasureRecId = UnitOfMeasure::findBySymbol(inventTable.salesUnitId()).RecId;
toUnitOfMeasureRecId = UnitOfMeasure::findBySymbol(inventTable.inventUnitId()).RecId;
secondaryToInventUnitConverter = UnitOfMeasureConverter_Product::construct();
secondaryToInventUnitConverter.parmProduct(inventTable.Product);
secondaryToInventUnitConverter.parmFromUnitOfMeasure(fromUnitOfMeasureRecId);
secondaryToInventUnitConverter.parmToUnitOfMeasure(toUnitOfMeasureRecId);
secondaryToInventUnitConverter.parmRoundAbsoluteValue(NoYes::Yes);
secondaryToInventUnitConverter.parmApplyRounding(NoYes::Yes);
info(strFmt("%1", Currency::amount(inventCostPriceCache.costPricePcs(inventSum, inventDim) * secondaryToInventUnitConverter.convertValue(1))));
return Currency::amount(inventCostPriceCache.costPricePcs(inventSum, inventDim) * secondaryToInventUnitConverter.convertValue(1));
}
0 comments:
Post a Comment