Reconciling Asset Acquisition Discrepancy

We came across an issue in our system where a set of assets had value updated on their value model, but no acquisition was posted to support the updated values. As a result, when depreciation was run for these assets they would not depreciate past the acquisition posted to the asset account, even though it appeared there was substantial life/value on the value model.

I wrote the following job to remedy this. The code creates an acquisition journal, then loops through each asset’s value model and compares the value to the posted acquisition. A journal transaction is created for any difference. The code does not post the journal, allowing review of the transactions prior to posting.

static void assetValueLineup(Args _args)
    AssetTable                  assetTable;
    AssetBook                   assetBook;

    AssetSumCalc                assetSumTrans;
    AmountMST                   acquired, depped, lapse;
    AmountMST                   dif;
    Date                        thisDate = today();

    LedgerJournalTable          journalTable;
    LedgerJournalTrans          ledgerJournalTrans;

    Dimension                   dim;
    str                         jourName;
    NumberSeq                   numSeq;
    Real                        deptime = 0;
    LedgerJournalTrans_Asset    ledgerJournalTrans_asset;
    LedgerJournalACType         ledgerJournalACType;

    journalTable.JournalNum    = JournalTableData::newTable(journalTable).nextJournalId();
    journalTable.journalType   = LedgerJournalType::Assets;
    journalTable.JournalName   = "FAA";

    jourName = journalTable.JournalName;


    while select forupdate assetBook
        assetSumTrans = null;

        // check acquisition vs depreciation
        // acquired => total amount of acquisition posted to ledger
        // dif      => value model acquisition price MINUS acquired (from ledger)
        // depped   => total amount of depreciation that has been posted for the asset
        // lapse    => amount remaining after subtracting depreciated amount from difference from value model acquisition MINUS ledger acquired
        // the 'lapse' value is what should be posted back to the ledger for acquisition
        // to ensure the amount of remaining life lines up with the amount added to the asset's account balance,
        // assign the life time remaining of the value model to:
        // (lapse / value model acquisition price) * total lifetime on value model

        assetSumTrans = AssetSumCalc_Trans::newAssetYear (assetBook.AssetId, assetBook.BookId, systemdateget(), year(thisDate));
        acquired = assetSumTrans.acquisitionPrice();
        depped = assetSumTrans.depreciationValue();

        dif = assetBook.AcquisitionPrice - acquired;

        if (acquired < assetBook.AcquisitionPrice && assetBook.AcquisitionPrice > 0)
            lapse = dif - depped;

            if (lapse <= 0)
                assetBook.LifeTimeRest = 0;


            assetBook.LifeTimeRest = (lapse / assetBook.AcquisitionPrice) * assetBook.LifeTime;


            dim[1] = assetBook.Dimension[1];
            dim[2] = assetBook.Dimension[2];

            numSeq = NumberSeq::newGetVoucherFromCode(LedgerJournalName::find(jourName).VoucherSeries, true );

             error(strfmt("Number sequence set up does not exists for journal %1", jourName));

            ledgerJournalTrans.Voucher   =  numSeq.voucher();
            ledgerJournalTrans.Dimension = dim;
            ledgerJournalTrans.TransDate =  today();
            ledgerJournalTrans.JournalNum = journalTable.JournalNum;
            ledgerJournalTrans.Company    = curext();
            ledgerJournalTrans.txt        = "Value Update";
            ledgerJournalTrans.AccountType = LedgerJournalACType::FixedAssets;

            ledgerJournalTrans.AccountNum = assetBook.AssetId;

            ledgerJournalTrans.AmountCurDebit = lapse;

            ledgerJournalTrans.currencyCode = "USD";
            ledgerJournalTrans.ExchRate  = Currency::exchRate(ledgerJournalTrans.currencyCode);

            ledgerJournalTrans.OffsetAccountType =  LedgerJournalACType::Ledger;
            ledgerJournalTrans.OffsetAccount = "16900"; // change to whatever offset account should be for your chart of accounts


               ledgerJournalTrans_asset.RefRecId = ledgerJournalTrans.RecId;
               ledgerJournalTrans_asset.AssetId  = ledgerJournalTrans.getAssetId();
               ledgerJournalTrans_Asset.Company  = ledgerJournalTrans.getAssetCompany();
               ledgerJournalTrans_asset.BookId   = assetBook.BookId;
               ledgerJournalTrans_asset.DepreciationTime = deptime;
               ledgerJournalTrans_asset.DepreciationStartDate = today();

               ledgerJournalTrans_asset.TransType = AssetTransTypeJournal::Acquisition;



            info(strfmt("Asset %1 adjustment. %2 : %3", assetBook.AssetId, assetBook.AcquisitionPrice, acquired));