Wednesday, February 10, 2016

Issue with Intercompany GL journal Validation of Rounding off Amount... rounding Differ

// Issue with Intercompany Validation of Rounding off Amount
Class --> LedgerVoucherTransObject
Replace Method


private boolean checkRounding(LedgerPostingMessageLog _ledgerPostingMessageCollection)
{
    AmountMST roundedAmount,beforeRound;
    CurrencyCode accountingCurrency;
    accountingCurrency = CompanyInfo::standardCurrency();
    beforeRound = generalJournalAccountEntry.AccountingCurrencyAmount;
    if(Currency::find(accountingCurrency).RoundingPrecision >= 0.010
        && Currency::find(accountingCurrency).RoundingPrecision <= 0.090)
    {
        generalJournalAccountEntry.AccountingCurrencyAmount = decRound(generalJournalAccountEntry.AccountingCurrencyAmount,2);
    }
    else if(Currency::find(accountingCurrency).RoundingPrecision >= 0.001)
    {
        generalJournalAccountEntry.AccountingCurrencyAmount = decRound(generalJournalAccountEntry.AccountingCurrencyAmount,3);
    }
    else if(Currency::find(accountingCurrency).RoundingPrecision >= 0.100)
    {
        generalJournalAccountEntry.AccountingCurrencyAmount = decRound(generalJournalAccountEntry.AccountingCurrencyAmount,1);
    }
    roundedAmount = CurrencyExchangeHelper::round(generalJournalAccountEntry.AccountingCurrencyAmount, accountingCurrency);
    if (generalJournalAccountEntry.AccountingCurrencyAmount != roundedAmount)
    {
        error(strFmt(
            "@SYS27168",
            accountingCurrency,
            Currency::roundingPrecisionAdjusted(accountingCurrency)));
            //the message includes "penny rounding threshhold" which seems wrong
            //The unit of %1 %2 being posted to account %3 is outside the current penny rounding threshold.
        return _ledgerPostingMessageCollection.logCheckFailed(strFmt(
            "@SYS18429",
            num2str(generalJournalAccountEntry.AccountingCurrencyAmount, 0, 16, -1, -1),
            accountingCurrency,
            DimensionAttributeValueCombination::getDisplayValue(generalJournalAccountEntry.LedgerDimension)));
    }
    generalJournalAccountEntry.AccountingCurrencyAmount = beforeRound;
    beforeRound = 0;
    if (generalJournalAccountEntry.TransactionCurrencyCode != ''
            && generalJournalAccountEntry.TransactionCurrencyCode == accountingCurrency)
    {
        roundedAmount =
            CurrencyExchangeHelper::round(generalJournalAccountEntry.TransactionCurrencyAmount, generalJournalAccountEntry.TransactionCurrencyCode);
        if (generalJournalAccountEntry.TransactionCurrencyAmount != roundedAmount)
        {
            error(strFmt(
                "@SYS27168",
                generalJournalAccountEntry.TransactionCurrencyCode,
                Currency::roundingPrecisionAdjusted(generalJournalAccountEntry.TransactionCurrencyCode)));
            return _ledgerPostingMessageCollection.logCheckFailed(strFmt(
                "@SYS18429",
                num2str(generalJournalAccountEntry.TransactionCurrencyAmount, 0, 16, -1, -1),
                generalJournalAccountEntry.TransactionCurrencyCode,
                DimensionAttributeValueCombination::getDisplayValue(generalJournalAccountEntry.LedgerDimension)));
        }
    }
    else if (generalJournalAccountEntry.TransactionCurrencyCode != ''
            && generalJournalAccountEntry.TransactionCurrencyCode != accountingCurrency)
    {
         beforeRound = generalJournalAccountEntry.TransactionCurrencyAmount;
        if(Currency::find(accountingCurrency).RoundingPrecision >= 0.010
            && Currency::find(accountingCurrency).RoundingPrecision <= 0.090)
        {
            generalJournalAccountEntry.TransactionCurrencyAmount = decRound(generalJournalAccountEntry.TransactionCurrencyAmount,2);
        }
        else if(Currency::find(accountingCurrency).RoundingPrecision >= 0.001)
        {
            generalJournalAccountEntry.TransactionCurrencyAmount = decRound(generalJournalAccountEntry.TransactionCurrencyAmount,3);
        }
        else if(Currency::find(accountingCurrency).RoundingPrecision >= 0.100)
        {
            generalJournalAccountEntry.TransactionCurrencyAmount = decRound(generalJournalAccountEntry.TransactionCurrencyAmount,1);
        }
       roundedAmount =
            CurrencyExchangeHelper::round(generalJournalAccountEntry.TransactionCurrencyAmount, accountingCurrency);
        if (generalJournalAccountEntry.TransactionCurrencyAmount != roundedAmount)
        {
            error(strFmt(
                "@SYS27168",
                accountingCurrency,
                Currency::roundingPrecisionAdjusted(accountingCurrency)));
            return _ledgerPostingMessageCollection.logCheckFailed(strFmt(
                "@SYS18429",
                num2str(generalJournalAccountEntry.TransactionCurrencyAmount, 0, 16, -1, -1),
                accountingCurrency,
                DimensionAttributeValueCombination::getDisplayValue(generalJournalAccountEntry.LedgerDimension)));
        }
        generalJournalAccountEntry.TransactionCurrencyAmount = beforeRound;
        beforeRound = 0;
    }
    return true;
}

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...