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");
  

Related
Recommended