Page 1 of 1

Unlocking a ledger for a Void

Posted: Mon Oct 31, 2022 4:51 pm
by KWoods
So, I have an issue that occurs when unlocking a ledger for a void.
I check the ledger in the code to see if it is dormancy locked and it says it is not.

Code: Select all

 
 		if(ledger.IsDormancyLocked)
                {
                    PERFUTIL.Log("Ledger " + ledger.Name + " is Locked");
                    ledger.IsDormancyLocked = false;
                    lm.ApplyChanges(ledger);
                    PERFUTIL.Log("Ledger Unlocked");
                }
                else
                {
                    PERFUTIL.Log("Ledger " + ledger.Name + " is not locked");
                }
Then after I try to void the ledger it tells me it is locked.

Even if I step through the code and it sets the IsDormancyLocked to false I still get the error.


Logs from my run:
2022-10-31 02:43:12- Ledger 01QA-0418-143156-CDFValidCML is not locked
2022-10-31 02:43:12- Void Ledger
2022-10-31 02:43:12- EXCEPTION1: You cannot void transfers that are associated with ledgers that have either been manually locked or auto-locked due to dormancy.

Is there something I am missing or is there something else I need to set?

Re: Unlocking a ledger for a Void

Posted: Mon Oct 31, 2022 5:52 pm
by BobRichards
If the transaction is part of a ledger to ledger transfer, then the related ledger cannot be dormancy locked either. That is apparently what is going on from the error message you are getting.

For example, if the transaction is a LedgerTransferOutTransaction, then if its TransferIn property is not null, you need to check the related transaction for lock.

Code: Select all

// "t" is Transaction we want to modify. We need to find any related transaction.

Transaction relatedTransaction = null;
if (t.Kind.IsBankTransaction())
{
    return null;
}
if (t is LedgerTransferOutTransaction
        && ((LedgerTransferOutTransaction)t).TransferIn != null)
{
    relatedTransaction = (Transaction)((LedgerTransferOutTransaction)t).TransferIn;
}
if (t is LedgerTransferInTransaction
    && ((LedgerTransferInTransaction)t).TransferOut != null)
{
    relatedTransaction = (Transaction)((LedgerTransferInTransaction)t).TransferOut;
}
...

// Do same for...
//	HudTransferOutTransaction, HudTransferInTransaction
//	CDFTransferOutTransaction, CDFTransferInTransaction

return relatedTransaction;

Re: Unlocking a ledger for a Void

Posted: Tue Nov 01, 2022 11:16 am
by KWoods
Thanks! I was able to get it to work by checking the Revenue Ledger and unlocking it as well.
I got the Revenue Ledger name from the RelatedTransferDescription field associated to the TransactionInfo of the LedgerTransferOut.

Code: Select all

ITransactionsManager tm = userObject.sps.GetService<ITransactionsManager>();
ITransactionInfo ti = ledger.Transactions.Where(t => (t.Status == TransactionStatus.Posted) &&
                                                                      (t.IsCurrent) &&
                                                                      (t.Kind == TransactionKind.LedgerTransferOut) &&
                                                                      (t.Amount.Equals(new decimal(amount)))).FirstOrDefault();

Assert.IsNotNull(ti, "Pending LedgerTransferOut - Not found");
               
ILedgerTransferOutTransaction lo = (ILedgerTransferOutTransaction)tm.GetTransaction(ti);

//Check if the Rev Ledger is DormancyLocked
Guid ledgertacID = lo.Account.ID;
ILedgerInfo destinationLedger = lm.Ledgers.Where(l => l.Name == ti.RelatedTransferDescription && (l.TrustAccount.ID == ledgertacID)).FirstOrDefault();

if (destinationLedger.IsDormancyLocked)
{
    PERFUTIL.Log("Rev Ledger " + destinationLedger.Name + " is Locked");
    IRevenueLedger revLedger = (IRevenueLedger)lm.GetLedger(destinationLedger);
    revLedger.IsDormancyLocked = false;
    lm.ApplyChanges(revLedger);
    PERFUTIL.Log("Rev Ledger Unlocked");
}
else
{
    PERFUTIL.Log("Rev Ledger " + destinationLedger.Name + " is not locked");
}