如何在普通期刊上发布文件日期和文件编号

时间:2015-01-08 22:35:43

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

我想知道是否有人可以帮助我弄清楚如何在标签发票下以编程方式在通用期刊trans中设置文档编号和日期。我试图用x ++在ax2012上发布一般期刊。我目前有这个代码可以工作,但在ledgerjournal trans下没有方法来设置文件号或日期。事实上很多人都缺少了setter账户类型,期刊数量等等。 我该如何设置这些字段?下面我有一些代码

static void TestLedgerJournalImport(Args _args)
{
// Set these variables.
LedgerJournalNameId                     journalName = 'GenJrn';
SelectableDataArea                      company = '019';
TransDate                               transactionDate = 30\6\2012;

str                                     line1MainAccount = '131310';
str                                     line1FullAccount = '131310--';

str                                     line2MainAccount = '131310';
str                                     line2FullAccount = '131310-10-';
str                                     line2Dimension1Name = 'Department';
str                                     line2Dimension1Value = 'ACCT';

LedgerGeneralJournalService             ledgerGeneralJournalService;
LedgerGeneralJournal                    ledgerGeneralJournal;

AfStronglyTypedDataContainerList        journalHeaderCollection;
LedgerGeneralJournal_LedgerJournalTable journalHeader;
AifEntityKeyList                        journalHeaderCollectionKeyList;
RecId                                   journalHeaderRecId;

AfStronglyTypedDataContainerList        journalLineCollection;
LedgerGeneralJournal_LedgerJournalTrans journalLine1;
AifMultiTypeAccount                     journalLine1LedgerDimension;
LedgerGeneralJournal_LedgerJournalTrans journalLine2;
AifMultiTypeAccount                     journalLine2LedgerDimension;
AifDimensionAttributeValue              journalLine2Dim1;
AfStronglyTypedDataContainerList        journalLine2DimensionCollection;
;

ledgerGeneralJournalService = LedgerGeneralJournalService::construct();
ledgerGeneralJournal = new LedgerGeneralJournal();

// Create journal header.
journalHeaderCollection = ledgerGeneralJournal.createLedgerJournalTable();
journalHeader = journalHeaderCollection.insertNew(1);
journalHeader.parmJournalName(journalName);

// Create journal lines.
journalLineCollection = journalHeader.createLedgerJournalTrans();

// Line 1
journalLine1 = journalLineCollection.insertNew(1);
journalLine1.parmLineNum(1.00);
journalLine1.parmCompany(company);
journalLine1.parmTransDate(transactionDate);
journalLine1.parmAccountType(LedgerJournalACType::Ledger);
journalLine1.parmTxt('Test journal transaction');
journalLine1.parmAmountCurDebit(100.00);
journalLine1LedgerDimension = journalLine1.createLedgerDimension();
journalLine1LedgerDimension.parmAccount(line1MainAccount);
journalLine1LedgerDimension.parmDisplayValue(line1FullAccount);
journalLine1.parmLedgerDimension(journalLine1LedgerDimension);

// Line 2
journalLine2 = journalLineCollection.insertNew(2);
journalLine2.parmLineNum(2.00);
journalLine2.parmCompany(company);
journalLine2.parmTransDate(transactionDate);
journalLine2.parmAccountType(LedgerJournalACType::Ledger);
journalLine2.parmTxt('Test journal transaction');
journalLine2.parmAmountCurCredit(100.00);
journalLine2LedgerDimension = journalLine2.createLedgerDimension();
journalLine2DimensionCollection = journalLine2LedgerDimension.createValues();
journalLine2Dim1 = new AifDimensionAttributeValue();
journalLine2Dim1.parmName(line2Dimension1Name);
journalLine2Dim1.parmValue(line2Dimension1Value);
journalLine2DimensionCollection.add(journalLine2Dim1);
journalLine2LedgerDimension.parmAccount(line2MainAccount);
journalLine2LedgerDimension.parmDisplayValue(line2FullAccount);
journalLine2LedgerDimension.parmValues(journalLine2DimensionCollection);
journalLine2.parmLedgerDimension(journalLine2LedgerDimension);

// Insert records.
journalHeader.parmLedgerJournalTrans(journalLineCollection);
ledgerGeneralJournal.parmLedgerJournalTable(journalHeaderCollection);
journalHeaderCollectionKeyList =
    LedgerGeneralJournalService.create(ledgerGeneralJournal);
journalHeaderRecId =
    journalHeaderCollectionKeyList.getEntityKey(1).parmRecId();

info(strFmt("LedgerJournalTable.Recid = %1", int642str(journalHeaderRecId)));

}

1 个答案:

答案 0 :(得分:0)

不要这样做,你为自己做更多的工作。我刚刚为你写了这个例子。我编写了一个更复杂的代码片段,所以我刚刚留下了offsetDefaultDimension代码示例。

static void Job3(Args _args)
{
    AxLedgerJournalTable                journalTable = AxLedgerJournalTable::construct();
    LedgerJournalTable                  ledgerJournalTable;
    LedgerJournalName                   ledgerJournalName = LedgerJournalName::find('GenJrn');
    AxLedgerJournalTrans                journalTrans = AxLedgerJournalTrans::construct();
    DimensionAttribute                  dimensionAttribute;
    DimensionAttributeValue             dimensionAttributeValue;
    DimensionAttributeValueSetStorage   dimStorage;
    LedgerDimensionAccount              ledgerDimension = DimensionDefaultingService::serviceCreateLedgerDimension(DimensionStorage::getDefaultAccountForMainAccountNum('131310'));

    journalTable.parmJournalName(ledgerJournalName.JournalName);
    journalTable.parmJournalType(ledgerJournalName.JournalType);
    journalTable.save();

    ttsBegin;
    ledgerJournalTable = LedgerJournalTable::findByRecId(journalTable.ledgerJournalTable().RecId, true);

    // The name gets reset if no journal number is provided, so we can just update afterwords
    ledgerJournalTable.Name = 'My Custom Journal Name/Description';
    ledgerJournalTable.update();
    ttsCommit;

    journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
    journalTrans.parmTransDate(today());
    journalTrans.parmCurrencyCode('USD');
    journalTrans.parmTxt('AlexOnDAX.blogspot.com');
    journalTrans.parmDocumentNum('MyDocNumber');
    journalTrans.parmDocumentDate(today() - 1);

    journalTrans.parmAccountType(LedgerJournalACType::Ledger);
    journalTrans.parmLedgerDimension(DimensionAttributeValueCombination::find(ledgerDimension).RecId);

    journalTrans.parmAmountCurDebit(100.00);
    journalTrans.save();

    info("Done");
}