Показать сообщение отдельно
Старый 06.06.2013, 10:34   #1  
trud is offline
trud
Участник
Лучший по профессии 2017
 
1,039 / 1633 (57) ++++++++
Регистрация: 07.06.2003
Записей в блоге: 1
Округление при разноске в ГК в 2012
интересный метод
\Classes\SubledgerJournalizer\roundSubledgerJournalTmpDetail

X++:
    while select sum(TransactionCurrencyAmount), sum(AccountingCurrencyAmount), sum(ReportingCurrencyAmount)
        from subledgerJournalAccountEntryTmpDetail
        group by TransactionCurrencyCode,
                    ExchangeRate1, ExchangeRate2,
                    ReportingExchangeRate1, ReportingExchangeRate2,
                    ExchangeRateDate,
                    FiscalCalendarPeriod, Ledger, PostingLayer, SubledgerJournalEntryType //this subgrouping ensures we round each future SLJE separately
        where subledgerJournalAccountEntryTmpDetail.DebitCredit == DebitCredit::Debit
            && subledgerJournalAccountEntryTmpDetail.IsReversal == NoYes::No //reversal/relieving entries are backing out already rounded entries and should stay as they are
            // <GEEHU><GEECZ>
            && subledgerJournalAccountEntryTmpDetail.TransactionCurrencyAmount != 0
            && subledgerJournalAccountEntryTmpDetail.ExchangeRate1 != 0
            // </GEECZ></GEEHU>
    {
..Здесь берем общую сумму в валюте переводим ее в первичную валюту и смотрим совпадает ли она с суммой в первичной валюте отдельных проводок
...если не совпадает
X++:
        if (accountingCurrencyAmountToRound != 0 || reportingCurrencyAmountToRound != 0)
        {
            while select maxof(RecId) from roundingEntrySubledgerJournalAccountEntryTmpDetail
                    group by TransactionCurrencyCode,
                            ExchangeRate1,
                            ExchangeRate2,
                            ReportingExchangeRate1,
                            ReportingExchangeRate2,
                            ExchangeRateDate,
                            DebitCredit
                where roundingEntrySubledgerJournalAccountEntryTmpDetail.Ledger == subledgerJournalAccountEntryTmpDetail.Ledger
                    && roundingEntrySubledgerJournalAccountEntryTmpDetail.FiscalCalendarPeriod == subledgerJournalAccountEntryTmpDetail.FiscalCalendarPeriod
                    && roundingEntrySubledgerJournalAccountEntryTmpDetail.PostingLayer == subledgerJournalAccountEntryTmpDetail.PostingLayer
                    && roundingEntrySubledgerJournalAccountEntryTmpDetail.SubledgerJournalEntryType == subledgerJournalAccountEntryTmpDetail.SubledgerJournalEntryType
                    && roundingEntrySubledgerJournalAccountEntryTmpDetail.IsReversal == NoYes::No   //reversal/relieving entries should not be modified, don't pick them to apply difference to
                    // <GEEHU><GEECZ>
                    && roundingEntrySubledgerJournalAccountEntryTmpDetail.TransactionCurrencyAmount != 0
                    && roundingEntrySubledgerJournalAccountEntryTmpDetail.ExchangeRate1 != 0
                    // </GEECZ></GEEHU>
            {
                select firstonly forupdate updateEntrySubledgerJournalAccountEntryTmpDetail
                    where updateEntrySubledgerJournalAccountEntryTmpDetail.RecId == roundingEntrySubledgerJournalAccountEntryTmpDetail.RecId;
.. берем проводку с максимальным RecId и накидываем на нее разницу

Теперь вопрос - а не надо ли во втором запросе(который выбирает максимальный RecId) добавить условие
roundingEntrySubledgerJournalAccountEntryTmpDetail.TransactionCurrencyCode == subledgerJournalAccountEntryTmpDetail.TransactionCurrencyCode
??