Same voucher is created for multiple lines in Fixed asset journal.

Initially created a job to  create and post multiple lines in fixed asset journal but while posting only voucher gets created for multiple lines.
can anyone suggest me the solution

LedgerJournalTable      jourTable;
    LedgerJournalTrans      jourTrans;
    LedgerJournalTableData jourTableData;
    LedgerJournalTransData jourTransData;
    LedgerJournalCheckPost LedgerJournalCheckPost;
    LedgerJournalStatic jourStatic;
    DimensionDynamicAccount ledgerDim;
    LedgerJournalTrans_Asset    ledgerJournalTrans_Asset;
    RecId   offsetledgerDimension ;
    AssetLedgerAccounts assetLedgerAccounts ;
    DimensionAttributeValueCombination  dimensionAttributeValueCombination;
    LedgerJournalEngine ledgerJournalEngine;
    AssetTransType  assetTransType;
    AssetTransTypeJournal   assetTransTypeJournal;
    Ledgerjournalname ledgerjournalname;
    NumberSeq   numberSeq;
    int i;

    ttsBegin;
    select ledgerjournalname where ledgerjournalname.JournalName == "FAD";
    jourTableData = JournalTableData::newTable(jourTable);
    jourTable.JournalNum            = jourTableData.nextJournalId();
    jourTable.JournalType           = LedgerJournalType::Assets;
    jourTable.JournalName           = 'FAD';//Payment Journal Name
    //jourtable.NumberSequenceTable   = 5637145051;
     jourTableData.initFromJournalName(LedgerJournalName::find('FAD'));
    jourTable.insert();
       
       jourStatic = jourTableData.journalStatic();
    for(i = 1;i<=2;i++)
    {
        jourTrans.clear();
        if(i == 1)
        {
            assetTransType = AssetTransType::Acquisition;
        }
        else
        {
            assetTransType = AssetTransType::Depreciation;
        }
     select assetLedgerAccounts
        where assetLedgerAccounts.PostingProfile == "ALL" && assetLedgerAccounts.BookId == "COMP" && assetLedgerAccounts.TransType == assetTransType;

    select dimensionAttributeValueCombination where dimensionAttributeValueCombination.RecId == assetLedgerAccounts.OffsetLedgerDimension;

    ledgerDim = DimensionStorage::getDynamicAccount("COMP-004",LedgerJournalACType::FixedAssets);//Account
    offsetledgerDimension  = AxdDimensionUtil::getMultiTypeAccountId(enumNum(LedgerJournalACType),LedgerJournalACType::Ledger,[dimensionAttributeValueCombination.DisplayValue,dimensionAttributeValueCombination.DisplayValue]);
    jourTrans.CurrencyCode          = 'USD';
    jourTrans.initValue();
    jourTrans.TransDate             = systemDateGet();
    jourTrans.AccountType           = LedgerJournalACType::FixedAssets;
    jourTrans.LedgerDimension       = ledgerDim;

       if(i == 1)
        {
           jourTrans.AmountCurDebit = 190;
             jourTrans.Txt = 'Acquisition';
        }
        else if( i == 2)
        {
            jourTrans.AmountCurCredit=173;
            jourTrans.AmountCurDebit = 0;
            jourTrans.Txt = 'Depreciation';
        }
    //numberSeq = NumberSeq::newGetVoucherFromId((ledgerjournalname.NumberSequenceTable));
    //jourTrans.Voucher = numberSeq.voucher();
    jourTrans.OffsetAccountType     = LedgerJournalACType::Ledger;
    jourTrans.OffsetLedgerDimension = offsetledgerDimension;
        //jourTrans.insert();

 //instance creation
    jourTransData = jourStatic.newJournalTransData(jourTrans, jourTableData);//return instance
    jourTransData.initFromJournalTable();
    jourTransData.create(false,false);
    ledgerJournalTrans_Asset.clear();
    ledgerJournalTrans_Asset.AssetId = "COMP-004";
    ledgerJournalTrans_Asset.Company = "CEU";
    ledgerJournalTrans_Asset.BookId  = "COMP";
    if(i == 1)
    {
        assetTransTypeJournal = AssetTransTypeJournal::Acquisition;
    }
        else
        {
            assetTransTypeJournal = AssetTransTypeJournal::Depreciation;
        }

    ledgerJournalTrans_Asset.TransType =assetTransTypeJournal;
    ledgerJournalTrans_Asset.RefRecId = jourTrans.RecId;
    ledgerJournalTrans_Asset.Insert();
    }
    LedgerjournalCheckPost = LedgerjournalCheckPost::newLedgerJournalTable(jourTable,NoYes::Yes);
    LedgerjournalCheckPost.run();
    ttsCommit;
    info("Completed");
  

  • Try not posting the journal and bebug the voucher allocation in journal. What ever that is allocated while creation will be considered by the posting (unless the creation is set to while posting in journal names - Number allocation at posting).

  • In reply to Kranthi:

    navigation for voucher allocation?
  • In reply to $@n$h€46:

    I mean the voucher allocation code. I can see the code to generate the voucher is commented. Try to debug the code that is generating the voucher in your case. You might have simplified your code.
    Example - \Classes\AssetSplit\createTrans
  • In reply to Kranthi:

    In my case jourtransdata.create() creates the voucher for lines.I could see initvoucher method in jourtransdata creates voucher for lines.But in my case it creates only one voucher.

  • In reply to $@n$h€46:

    I don't see LedgerJournalTransData in Ax 2012.
    Does the code below in if loop being executed in your case in initVoucher method?
    if (voucherList.findIdx(this.voucherObjectKey()))
    {
    journalTrans.Voucher = voucherList.item().voucher();
    }
    else
    {
  • In reply to Kranthi:

    LedgerJournalTransData is there in AX2012 and it extends journaltransdata class.
    In above code "if" part is not executed for for first line but while creating second line "if" part gets executed.
    In my case "if" part doesn't executes for second line then there will be two vouchers created.
    How to do??
  • In reply to $@n$h€46:

    The voucherObjectKey is considering the transDate and if the lines has same date, it might be using the same voucher.
    Why cannot you generate the voucher in the code,
    journalTrans.Voucher = new JournalVoucherNum(jourTableData).getNew(false);

  • In reply to Kranthi:

    Thank you so much kranthi.
    But is that not possible to create different vouchers with same transdate?
    Actually when we create journals functionally in front end we can create with same transdate !!!
  • In reply to $@n$h€46:

    $@n$h€46
    But is that not possible to create different vouchers with same transdate?
    Actually when we create journals functionally in front end we can create with same transdate !!!

    It uses a different logic, to know more details - you can start debugging from \Classes\LedgerJournalEngine\initValue

  • In reply to Kranthi:

    Thank you kranthi
Related
Recommended