按代码计算预算余额

时间:2016-09-22 20:30:17

标签: axapta x++ dynamics-ax-2012-r2

我需要计算任何特定维度的预算余额( AX 2012 R2 )。

我执行以下代码正常工作,但需要很长时间才能完成。

这是因为这计算了所有具有AX的预算余额,而不仅仅是我想要的预算余额。

最后,变量BudgetTmpBalance它包含所有预算条目的记录。

有些事我不考虑。谁知道是什么?

提前致谢。

代码:

BudgetTransactionLine              recBudgetTransactionLine;
DimensionAttributeValueCombination recDimensionAttributeValueCombination;        
date                               FiscalYearStart, FiscalYearEnd;
AccountingDistribution             recAccountingDistribution;    
Query                              query = new Query();
QueryBuildDataSource               qbds;
QueryBuildDataSource               qbdsJoin;
QueryBuildRange                    qbr;
BudgetCalculateBalance             budgetCalculateBalance = new BudgetCalculateBalance();
BudgetTmpBalance                   budgetTmpBalance;
DimensionDisplayValue              pDimensionDisplayValue;

;

pDimensionDisplayValue = "Correct Value"; 

select * from recDimensionAttributeValueCombination where recDimensionAttributeValueCombination.LedgerDimensionType == LedgerDimensionType::Budget &&
                                                          recDimensionAttributeValueCombination.DisplayValue        == pDimensionDisplayValue;

FiscalYearStart = str2Date("01/04/" + int2str(year(today())), 123);
FiscalYearEnd   = str2Date("31/03/" + int2str(year(today()) + 1), 123);

//Find recId of header that I Want (Works fine)
select BudgetTransactionHeader from recBudgetTransactionLine where recBudgetTransactionLine.LedgerDimension == recDimensionAttributeValueCombination.RecId &&
                                                                      (recBudgetTransactionLine.Date >= FiscalYearStart &&  recBudgetTransactionLine.Date <= FiscalYearEnd);

qbds = query.addDataSource(tableNum(BudgetTransactionHeader));
qbr  = qbds.addRange(FieldNum(BudgetTransactionHeader, TransactionStatus));
qbr.value(queryValue(1));
qbr  = qbds.addRange(FieldNum(BudgetTransactionHeader, RecId));
qbr.value(queryValue(recBudgetTransactionLine.BudgetTransactionHeader));//Header RecId (correct value)
qbdsJoin= qbds.addDataSource(tableNum(BudgetTransactionLine));
qbdsJoin.relations(false);
qbdsJoin.fields().dynamic(NoYes::Yes);
qbdsJoin.addLink(fieldNum(BudgetTransactionHeader, RecId), fieldNum(BudgetTransactionLine, BudgetTransactionHeader));
qbdsJoin.joinMode(JoinMode::InnerJoin);

budgetCalculateBalance.parmDimensionFocus("CTA+UN+CC");    
budgetCalculateBalance.parmCalculateLedgerAmounts(NoYes::Yes);
budgetCalculateBalance.parmFiscalCalendarRecId(Ledger::fiscalCalendar());
budgetCalculateBalance.parmStartDate(FiscalYearStart);
budgetCalculateBalance.parmEndDate(FiscalYearEnd);
budgetCalculateBalance.parmIncludeSubModels(NoYes::No);
budgetCalculateBalance.parmIncludeAllBudgetModelsIfNotSpecified(NoYes::No);
budgetCalculateBalance.parmBudgetModelId("TOTAL");
budgetCalculateBalance.parmBudgetType();
budgetCalculateBalance.parmAccumulateAmounts(NoYes::No);
budgetCalculateBalance.parmLedgerCategory(CurrentOperationsTax::Current);
budgetCalculateBalance.parmQuery(query);
budgetTmpBalance = budgetCalculateBalance.calculatePeriodBalances();

1 个答案:

答案 0 :(得分:0)

<强>解决 现在这个过程在5秒钟内完成!

此处为正确代码:

BudgetTransactionLine              recBudgetTransactionLine;
DimensionAttributeValueCombination recDimensionAttributeValueCombination;        
date                               FiscalYearStart, FiscalYearEnd;
AccountingDistribution             recAccountingDistribution;    
Query                              query;
QueryBuildDataSource               qbds;
QueryBuildDataSource               qbdsJoin;
QueryBuildRange                    qbr;
BudgetCalculateBalance             budgetCalculateBalance = new BudgetCalculateBalance();
BudgetTmpBalance                   budgetTmpBalance;
DimensionDisplayValue              pDimensionDisplayValue;
#define.LedgerDimensionDataSourceName('BudgetTransactionLine_1')

;

pDimensionDisplayValue = "Correct Value"; 

select * from recDimensionAttributeValueCombination where recDimensionAttributeValueCombination.LedgerDimensionType == LedgerDimensionType::Budget &&
                                                      recDimensionAttributeValueCombination.DisplayValue        == pDimensionDisplayValue;

FiscalYearStart = str2Date("01/04/" + int2str(year(today())), 123);
FiscalYearEnd   = str2Date("31/03/" + int2str(year(today()) + 1), 123);

//Find recId of header that I Want (Works fine)
select BudgetTransactionHeader from recBudgetTransactionLine where recBudgetTransactionLine.LedgerDimension == recDimensionAttributeValueCombination.RecId &&
                                                                  (recBudgetTransactionLine.Date >= FiscalYearStart &&  recBudgetTransactionLine.Date <= FiscalYearEnd);

budgetCalculateBalance.parmDimensionFocus("CTA+UN+CC");    
budgetCalculateBalance.parmFiscalCalendarRecId(Ledger::fiscalCalendar());
budgetCalculateBalance.parmCalculateLedgerAmounts(NoYes::Yes);
budgetCalculateBalance.parmFilterByBudgetType(NoYes::Yes);
budgetCalculateBalance.parmIncludeSubModels(NoYes::Yes);
budgetCalculateBalance.parmStartDate(FiscalYearStart);
budgetCalculateBalance.parmEndDate(FiscalYearEnd);
if(TieneCC)
    budgetCalculateBalance.parmDimensionFocus("CTA+UN+CC");
else
    budgetCalculateBalance.parmDimensionFocus("CTA+UN");

query = new Query(querystr(BudgetCalculateBalance));
BudgetTransactionManager::addDimensionCriteriaForLedgerDimension(query, recDimensionAttributeValueCombination.RecId, #LedgerDimensionDataSourceName);
budgetCalculateBalance.parmQuery(query);        
budgetTmpBalance = budgetCalculateBalance.calculatePeriodBalances();