public FABookPeriod FindFABookPeriodOfDate(DateTime?date, int?bookID, int?assetID, bool check = true)
        {
            if (check)
            {
                CheckNotNullObjectContract(date, nameof(date));
                CheckNotNullIDContract(bookID, nameof(bookID));
                CheckNotNullIDContract(assetID, nameof(assetID));
            }

            FABookPeriod period = (FABookPeriod) new Select <
                FABookPeriod,
                Where <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >,
                       And <FABookPeriod.organizationID, Equal <Required <FABookPeriod.organizationID> >,
                            And <FABookPeriod.startDate, LessEqual <Required <FABookPeriod.startDate> >,
                                 And <FABookPeriod.endDate, Greater <Required <FABookPeriod.endDate> > > > > > >()
                                  .CreateView(Graph, clearQueryCache: true, mergeCache: false)
                                  .SelectSingle(
                bookID,
                GetFABookPeriodOrganizationID(bookID, assetID, check),
                date,
                date);

            if (check && period == null)
            {
                throw new PXFABookPeriodException();
            }

            return(period);
        }
        public FABookPeriod FindFABookPeriodOfDateByBranchID(DateTime?date, int?bookID, int?branchID, bool check = true)
        {
            CheckNotNullObjectContract(date, nameof(date));
            CheckNotNullIDContract(bookID, nameof(bookID));
            CheckNotNullIDContract(branchID, nameof(branchID));

            FABookPeriod period = PXSelect <
                FABookPeriod,
                Where <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >,
                       And <FABookPeriod.organizationID, Equal <Required <FABookPeriod.organizationID> >,
                            And <FABookPeriod.startDate, LessEqual <Required <FABookPeriod.startDate> >,
                                 And <FABookPeriod.endDate, Greater <Required <FABookPeriod.endDate> > > > > > >
                                  .Select(
                Graph,
                bookID,
                IsPostingFABook(bookID)
                ?PXAccess.GetParentOrganizationID(branchID)
                : FinPeriod.organizationID.MasterValue,
                date,
                date);

            if (check && period == null)
            {
                throw new PXFABookPeriodException();
            }

            return(period);
        }
        public void SplitFilter_SplitDate_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            SplitFilter filter = (SplitFilter)e.Row;

            if (filter == null)
            {
                return;
            }

            FABookBalance bal = PXSelect <FABookBalance, Where <FABookBalance.assetID, Equal <Current <SplitFilter.assetID> > >, OrderBy <Desc <FABookBalance.updateGL> > > .SelectSingleBound(this, new object[] { filter });

            if (bal != null)
            {
                if (string.IsNullOrEmpty(bal.CurrDeprPeriod) && !string.IsNullOrEmpty(bal.LastDeprPeriod))
                {
                    e.NewValue = FABookPeriodIDAttribute.PeriodStartDate(this, FABookPeriodIDAttribute.PeriodPlusPeriod(this, bal.LastDeprPeriod, 1, bal.BookID), bal.BookID);
                }
                else
                {
                    FABookPeriod todayPeriod = FABookPeriodIDAttribute.FABookPeriodFromDate(this, Accessinfo.BusinessDate, bal.BookID);
                    e.NewValue = string.CompareOrdinal(bal.CurrDeprPeriod, todayPeriod.FinPeriodID) > 0 ? FABookPeriodIDAttribute.PeriodStartDate(this, bal.CurrDeprPeriod, bal.BookID) : Accessinfo.BusinessDate;
                }
            }
            else
            {
                e.NewValue = Accessinfo.BusinessDate;
            }
        }
Пример #4
0
        protected override string GetMappedPeriodID(PXCache cache, OrganizationDependedPeriodKey newPeriodKey,
                                                    OrganizationDependedPeriodKey oldPeriodKey)
        {
            IFABookPeriodRepository periodRepository = cache.Graph.GetService <IFABookPeriodRepository>();

            FABookPeriod mappedPeriod = periodRepository.FindMappedPeriod((FABookPeriod.Key)oldPeriodKey, (FABookPeriod.Key)newPeriodKey);

            return(mappedPeriod?.FinPeriodID);
        }
Пример #5
0
        public override void FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            base.FieldDefaulting(sender, e);

            FABookPeriod period = PXSelectJoin <FABookPeriod, LeftJoin <FABook, On <FABookPeriod.bookID, Equal <FABook.bookID> > >,
                                                Where <FABookPeriod.startDate, LessEqual <Current <AccessInfo.businessDate> >, And <FABookPeriod.endDate, Greater <Current <AccessInfo.businessDate> >, And <FABook.updateGL, Equal <boolTrue> > > > > .SelectSingleBound(sender.Graph, new object[0]);

            if (period != null)
            {
                e.NewValue = FinPeriodIDFormattingAttribute.FormatForDisplay(period.FinPeriodID);
            }
        }
Пример #6
0
        public static FABookPeriod FABookPeriodFromDate(PXGraph graph, DateTime?d, int?BookID)
        {
            FABookPeriod p = PXSelect <FABookPeriod,
                                       Where <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >,
                                              And <FABookPeriod.startDate, LessEqual <Required <FABookPeriod.startDate> >,
                                                   And <FABookPeriod.endDate, Greater <Required <FABookPeriod.endDate> > > > > > .Select(graph, BookID, d, d);

            if (p == null)
            {
                throw new PXFABookPeriodException();
            }
            return(p);
        }
Пример #7
0
        public static DateTime PeriodEndDate(PXGraph graph, string FiscalPeriodID, int?BookID)
        {
            FABookPeriod p = PXSelect <FABookPeriod,
                                       Where <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >,
                                              And <FABookPeriod.finPeriodID, Equal <Required <FABookPeriod.finPeriodID> > > > > .Select(graph, BookID, FiscalPeriodID);

            if (p == null || p.EndDate == null)
            {
                throw new PXFABookPeriodException();
            }

            return(((DateTime)p.EndDate).AddDays(-1));
        }
        protected virtual void FATran_FinPeriodID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            FATran tran = (FATran)e.Row;

            if (tran?.AssetID == null || tran.BookID == null || tran.TranDate == null)
            {
                return;
            }

            try
            {
                // TODO: AC-106141
                // Use BranchID of the fixed asset referenced by local FATran
                FABookPeriod period = PXSelect <
                    FABookPeriod,
                    Where <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >,
                           And <FABookPeriod.finPeriodID, Equal <Required <FABookPeriod.finPeriodID> > > > >
                                      .Select(this, tran.BookID, (string)e.NewValue);

                if (period == null)
                {
                    throw new PXSetPropertyException(Messages.NoPeriodsDefined);
                }

                FABookBalance bal = bookbalances.SelectSingle(tran.AssetID, tran.BookID);


                if ((tran.TranType == FATran.tranType.DepreciationPlus || tran.TranType == FATran.tranType.DepreciationMinus) && tran.Origin == FARegister.origin.Adjustment)
                {
                    if (!string.IsNullOrEmpty(bal.CurrDeprPeriod) && string.CompareOrdinal((string)e.NewValue, bal.CurrDeprPeriod) >= 0)
                    {
                        throw new PXSetPropertyException(CS.Messages.Entry_LT, FinPeriodIDFormattingAttribute.FormatForError(bal.CurrDeprPeriod));
                    }
                    if (!string.IsNullOrEmpty(bal.LastDeprPeriod) && string.CompareOrdinal((string)e.NewValue, bal.LastDeprPeriod) > 0)
                    {
                        throw new PXSetPropertyException(CS.Messages.Entry_LE, FinPeriodIDFormattingAttribute.FormatForError(bal.LastDeprPeriod));
                    }
                    if (!string.IsNullOrEmpty(bal.DeprFromPeriod) && string.CompareOrdinal((string)e.NewValue, bal.DeprFromPeriod) < 0)
                    {
                        throw new PXSetPropertyException(CS.Messages.Entry_GE, FinPeriodIDFormattingAttribute.FormatForError(bal.DeprFromPeriod));
                    }
                }
            }
            catch (PXSetPropertyException)
            {
                e.NewValue = FinPeriodIDAttribute.FormatForDisplay((string)e.NewValue);
                throw;
            }
        }
Пример #9
0
        public DateTime GetFABookPeriodEndDate(string finPeriodID, int?bookID, int?assetID)
        {
            FABookPeriod period = PXSelect <
                FABookPeriod,
                Where <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >,
                       And <FABookPeriod.organizationID, Equal <Required <FABookPeriod.organizationID> >,
                            And <FABookPeriod.finPeriodID, Equal <Required <FABookPeriod.finPeriodID> > > > > >
                                  .Select(Graph, bookID, FABookPeriodRepositoryHelper.GetFABookPeriodOrganizationID(bookID, assetID), finPeriodID);

            if (period?.EndDate == null)
            {
                throw new PXFABookPeriodException();
            }

            return(((DateTime)period.EndDate).AddDays(-1));
        }
        public FABookPeriod FindMappedPeriod(FABookPeriod.Key fromPeriodKey, FABookPeriod.Key toPeriodKey)
        {
            if (fromPeriodKey.BookID != toPeriodKey.BookID)
            {
                return(null);
            }

            if (!IsPostingFABook(fromPeriodKey.BookID))
            {
                return(null);
            }

            FABookPeriod oldPeriod = FindByKey(fromPeriodKey.BookID, fromPeriodKey.OrganizationID, fromPeriodKey.PeriodID);

            return(FindPeriodByMasterPeriodID(toPeriodKey.BookID, toPeriodKey.OrganizationID, oldPeriod?.MasterFinPeriodID));
        }
        public static DateTime PeriodStartDate(PXGraph graph, string FiscalPeriodID, int?BookID)
        {
            // TODO: AC-106141
            // Use BranchID (OrganizationID) passed as parameter
            FABookPeriod p = PXSelect <
                FABookPeriod,
                Where <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >,
                       And <FABookPeriod.finPeriodID, Equal <Required <FABookPeriod.finPeriodID> > > > >
                             .Select(graph, BookID, FiscalPeriodID);

            if (p == null || p.StartDate == null)
            {
                throw new PXFABookPeriodException();
            }

            return((DateTime)p.StartDate);
        }
        public static FABookPeriod FABookPeriodFromDate(PXGraph graph, DateTime?d, int?BookID, bool check = true)
        {
            // TODO: AC-106141
            // Use BranchID (OrganizationID) passed as parameter
            FABookPeriod p = PXSelect <
                FABookPeriod,
                Where <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >,
                       And <FABookPeriod.startDate, LessEqual <Required <FABookPeriod.startDate> >,
                            And <FABookPeriod.endDate, Greater <Required <FABookPeriod.endDate> > > > > >
                             .Select(graph, BookID, d, d);

            if (check && p == null)
            {
                throw new PXFABookPeriodException();
            }

            return(p);
        }
Пример #13
0
        protected virtual void FATran_FinPeriodID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            FATran tran = (FATran)e.Row;

            if (tran == null || tran.AssetID == null || tran.BookID == null)
            {
                return;
            }

            try
            {
                FABookPeriod p = PXSelect <FABookPeriod,
                                           Where <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >,
                                                  And <FABookPeriod.finPeriodID, Equal <Required <FABookPeriod.finPeriodID> > > > > .Select(this, tran.BookID, (string)e.NewValue);

                if (p == null)
                {
                    throw new PXSetPropertyException(Messages.NoPeriodsDefined);
                }

                FABookBalance bal = PXSelect <FABookBalance,
                                              Where <FABookBalance.assetID, Equal <Required <FABookBalance.assetID> >,
                                                     And <FABookBalance.bookID, Equal <Required <FABookBalance.bookID> > > > > .Select(this, tran.AssetID, tran.BookID);


                if ((tran.TranType == FATran.tranType.DepreciationPlus || tran.TranType == FATran.tranType.DepreciationMinus) && tran.Origin == FARegister.origin.Adjustment)
                {
                    if (!string.IsNullOrEmpty(bal.CurrDeprPeriod) && String.Compare((string)e.NewValue, bal.CurrDeprPeriod) >= 0)
                    {
                        throw new PXSetPropertyException(CS.Messages.Entry_LT, FinPeriodIDFormattingAttribute.FormatForError(bal.CurrDeprPeriod));
                    }
                    if (!string.IsNullOrEmpty(bal.LastDeprPeriod) && String.Compare((string)e.NewValue, bal.LastDeprPeriod) > 0)
                    {
                        throw new PXSetPropertyException(CS.Messages.Entry_LE, FinPeriodIDFormattingAttribute.FormatForError(bal.LastDeprPeriod));
                    }
                }
            }
            catch (PXSetPropertyException)
            {
                e.NewValue = FinPeriodSelectorAttribute.FormatForDisplay((string)e.NewValue);
                throw;
            }
        }
Пример #14
0
        public DateTime GetFABookPeriodStartDate(string finPeriodID, int?bookID, int?assetID)
        {
            FABookPeriodRepository.CheckNotNullOrEmptyStringContract(finPeriodID, nameof(finPeriodID));
            FABookPeriodRepository.CheckNotNullIDContract(bookID, nameof(bookID));
            FABookPeriodRepository.CheckNotNullIDContract(assetID, nameof(assetID));

            FABookPeriod period = PXSelect <
                FABookPeriod,
                Where <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >,
                       And <FABookPeriod.organizationID, Equal <Required <FABookPeriod.organizationID> >,
                            And <FABookPeriod.finPeriodID, Equal <Required <FABookPeriod.finPeriodID> > > > > >
                                  .Select(Graph, bookID, FABookPeriodRepositoryHelper.GetFABookPeriodOrganizationID(bookID, assetID), finPeriodID);

            if (period?.StartDate == null)
            {
                throw new PXFABookPeriodException();
            }

            return((DateTime)period.StartDate);
        }
        public virtual ProcessingResult <FABookPeriod> FindMappedFABookPeriodUsingFinPeriod(int?bookID, int?sourceOrganizationID, string sourcefinPeriodID, int?targetOrganizationID)
        {
            IFinPeriodRepository finPeriodRepository = Graph.GetService <IFinPeriodRepository>();

            string       targetFinPeriodID  = finPeriodRepository.GetMappedPeriod(sourceOrganizationID, sourcefinPeriodID, targetOrganizationID)?.FinPeriodID;
            FABookPeriod targetFABookPeriod = FindByKey(bookID, targetOrganizationID, targetFinPeriodID);

            ProcessingResult <FABookPeriod> result = ProcessingResult <FABookPeriod> .CreateSuccess(targetFABookPeriod);

            if (targetFABookPeriod == null)
            {
                string errorMessage = PXMessages.LocalizeFormat(
                    Messages.PeriodDoesNotExistForBookAndCompany,
                    PeriodIDAttribute.FormatForError(sourcefinPeriodID),
                    FindFABook(bookID).BookCode,
                    PXAccess.GetOrganizationCD(sourceOrganizationID));

                result.AddErrorMessage(errorMessage);
            }

            return(result);
        }
        public virtual ProcessingResult <FABookPeriod> FindMappedFABookPeriod(int?bookID, int?sourceOrganizationID, string sourcefinPeriodID, int?targetOrganizationID)
        {
            FABookPeriod sourceFABookPeriod = FindByKey(bookID, sourceOrganizationID, sourcefinPeriodID);

            ProcessingResult <FABookPeriod> result = ProcessingResult <FABookPeriod> .CreateSuccess(sourceFABookPeriod);

            if (sourceFABookPeriod == null)
            {
                string errorMessage = PXMessages.LocalizeFormat(
                    Messages.PeriodDoesNotExistForBookAndCompany,
                    PeriodIDAttribute.FormatForError(sourcefinPeriodID),
                    FindFABook(bookID).BookCode,
                    PXAccess.GetOrganizationCD(sourceOrganizationID));

                result.AddErrorMessage(errorMessage);
            }
            else if (IsPostingFABook(bookID) && sourceOrganizationID != targetOrganizationID)
            {
                result = GetFABookPeriodByMasterPeriodID(bookID, targetOrganizationID, sourceFABookPeriod?.MasterFinPeriodID);
            }

            return(result);
        }
        public virtual ProcessingResult <FABookPeriod> GetFABookPeriodByMasterPeriodID(int?bookID, int?organizationID, string masterFinPeriodID)
        {
            FABookPeriod period = SelectFrom <FABookPeriod>
                                  .Where <FABookPeriod.bookID.IsEqual <@P.AsInt>
                                          .And <FABookPeriod.organizationID.IsEqual <@P.AsInt> >
                                          .And <FABookPeriod.masterFinPeriodID.IsEqual <@P.AsString> > >
                                  .View
                                  .ReadOnly
                                  .Select(Graph, bookID, organizationID, masterFinPeriodID);

            ProcessingResult <FABookPeriod> result = ProcessingResult <FABookPeriod> .CreateSuccess(period);

            if (period == null)
            {
                string errorMessage = PXMessages.LocalizeFormatNoPrefix(
                    GL.Messages.RelatedFinPeriodsForMasterDoesNotExistForCompany,
                    PeriodIDAttribute.FormatForError(masterFinPeriodID),
                    PXAccess.GetOrganizationCD(organizationID));

                result.AddErrorMessage(errorMessage);
            }

            return(result);
        }
Пример #18
0
        protected override void ValidatePeriodAndSourcesImpl(PXCache cache, object oldRow, object newRow, bool externalCall)
        {
            PeriodKeyProviderBase.KeyWithSourceValuesCollection <
                FABookPeriodKeyProvider.FAKeyWithSourceValues,
                FABookPeriodKeyProvider.FASourceSpecificationItem,
                FABookPeriod.Key> newKeyWithSourceValues =
                FABookPeriodKeyProvider.GetKeys(cache.Graph, cache, newRow);

            PeriodKeyProviderBase.KeyWithSourceValuesCollection <
                FABookPeriodKeyProvider.FAKeyWithSourceValues,
                FABookPeriodKeyProvider.FASourceSpecificationItem,
                FABookPeriod.Key> oldKeyWithSourceValues =
                FABookPeriodKeyProvider.GetKeys(cache.Graph, cache, oldRow);

            FABookPeriod.Key newPeriodKey = newKeyWithSourceValues.ConsolidatedKey;

            newPeriodKey.PeriodID = (string)cache.GetValue(newRow, _FieldName);

            if (!newPeriodKey.Defined)
            {
                return;
            }

            IFABookPeriodRepository periodRepository = cache.Graph.GetService <IFABookPeriodRepository>();

            FABookPeriod period = periodRepository.FindByKey(newPeriodKey.BookID, newPeriodKey.OrganizationID,
                                                             newPeriodKey.PeriodID);

            if (period == null)
            {
                PXSetPropertyException exception = null;

                FABook book = BookMaint.FindByID(cache.Graph, newPeriodKey.BookID);

                if (book.UpdateGL == true)
                {
                    exception = new PXSetPropertyException(PXMessages.LocalizeFormatNoPrefix(
                                                               Messages.PeriodDoesNotExistForBookAndCompany,
                                                               FormatForError(newPeriodKey.PeriodID),
                                                               book.BookCode,
                                                               PXAccess.GetOrganizationCD(newPeriodKey.OrganizationID)));

                    if (FAMainSpecificationItem.OrganizationSourceType != null &&
                        newKeyWithSourceValues.MainItem.SourceOrganizationIDs.First() != null &&
                        newKeyWithSourceValues.MainItem.SourceOrganizationIDs.First() != oldKeyWithSourceValues.MainItem.SourceOrganizationIDs.First())
                    {
                        SetErrorAndResetToOldForField(
                            cache,
                            oldRow,
                            newRow,
                            FAMainSpecificationItem.OrganizationSourceType.Name,
                            exception,
                            externalCall);
                    }

                    if (FAMainSpecificationItem.BranchSourceType != null &&
                        newKeyWithSourceValues.MainItem.SourceBranchIDs.First() != null &&
                        newKeyWithSourceValues.MainItem.SourceBranchIDs.First() != oldKeyWithSourceValues.MainItem.SourceBranchIDs.First())
                    {
                        SetErrorAndResetToOldForField(
                            cache,
                            oldRow,
                            newRow,
                            FAMainSpecificationItem.BranchSourceType.Name,
                            exception,
                            externalCall);
                    }

                    if (FAMainSpecificationItem.AssetSourceType != null &&
                        newKeyWithSourceValues.MainItem.SourceAssetIDs.First() != null &&
                        newKeyWithSourceValues.MainItem.SourceAssetIDs.First() != oldKeyWithSourceValues.MainItem.SourceAssetIDs.First())
                    {
                        SetErrorAndResetToOldForField(
                            cache,
                            oldRow,
                            newRow,
                            FAMainSpecificationItem.AssetSourceType.Name,
                            exception,
                            externalCall);
                    }
                }
                else
                {
                    exception = new PXSetPropertyException(PXMessages.LocalizeFormatNoPrefix(
                                                               Messages.PeriodDoesNotExistForBook,
                                                               FormatForError(newPeriodKey.PeriodID)));
                }

                cache.RaiseExceptionHandling(
                    _FieldName,
                    newRow,
                    FormatForDisplay(newPeriodKey.PeriodID),
                    exception);

                cache.SetValue(
                    newRow,
                    _FieldName,
                    cache.GetValue(oldRow, _FieldName));

                if (FAMainSpecificationItem.BookSourceType != null &&
                    newKeyWithSourceValues.MainItem.SourceBookIDs.First() != null &&
                    newKeyWithSourceValues.MainItem.SourceBookIDs.First() != oldKeyWithSourceValues.MainItem.SourceBookIDs.First())
                {
                    SetErrorAndResetToOldForField(
                        cache,
                        oldRow,
                        newRow,
                        FAMainSpecificationItem.BookSourceType.Name,
                        exception,
                        externalCall);
                }
            }
        }
        public virtual IEnumerable amts(PXAdapter adapter)
        {
            FixedAssetFilter filter = Filter.Current;

            if (filter == null || filter.AssetID == null || filter.PeriodID == null)
            {
                yield break;
            }

            FixedAsset asset = PXSelect <FixedAsset, Where <FixedAsset.assetID, Equal <Current <FixedAssetFilter.assetID> > > > .Select(this);

            PXSelectBase <FATran> select = new PXSelectJoin <FATran,
                                                             LeftJoin <Account, On <FATran.debitAccountID, Equal <Account.accountID> >,
                                                                       LeftJoin <Sub, On <FATran.debitSubID, Equal <Sub.subID> >,
                                                                                 LeftJoin <CreditAccount, On <FATran.creditAccountID, Equal <CreditAccount.accountID> >,
                                                                                           LeftJoin <CreditSub, On <FATran.creditSubID, Equal <CreditSub.subID> >,
                                                                                                     LeftJoin <FABookPeriod, On <FATran.bookID, Equal <FABookPeriod.bookID>,
                                                                                                                                 And <FATran.finPeriodID, Equal <FABookPeriod.finPeriodID> > >,
                                                                                                               LeftJoin <FABook, On <FATran.bookID, Equal <FABook.bookID> > > > > > > >,
                                                             Where <FATran.assetID, Equal <Current <FixedAssetFilter.assetID> >,
                                                                    And <FATran.finPeriodID, LessEqual <Current <FixedAssetFilter.periodID> >,
                                                                         And <FATran.released, Equal <True>,
                                                                              And <Where <FATran.tranType, NotEqual <FATran.tranType.calculatedPlus>,
                                                                                          And <FATran.tranType, NotEqual <FATran.tranType.calculatedMinus>,
                                                                                               And <FATran.tranType, NotEqual <FATran.tranType.reconcilliationPlus>,
                                                                                                    And <FATran.tranType, NotEqual <FATran.tranType.reconcilliationMinus> > > > > > > > > >(this);

            if (filter.BookID != null)
            {
                select.WhereAnd <Where <FATran.bookID, Equal <Current <FixedAssetFilter.bookID> > > >();
            }

            Dictionary <string, Amounts> dict = new Dictionary <string, Amounts>();

            foreach (PXResult <FATran, Account, Sub, CreditAccount, CreditSub, FABookPeriod> res in select.Select())
            {
                Account       dacct  = res;
                Sub           dsub   = res;
                CreditAccount cacct  = res;
                CreditSub     csub   = res;
                FATran        tran   = res;
                FABookPeriod  period = res;

                if (!IsAccrualAccount <FATran.debitAccountID, FATran.debitSubID>(tran, asset))
                {
                    Amounts record = null;
                    string  dkey   = string.Format("{0}{1}", dacct.AccountCD, dsub.SubCD);
                    if (!dict.TryGetValue(dkey, out record))
                    {
                        record = new Amounts
                        {
                            BookID    = tran.BookID,
                            AccountID = tran.DebitAccountID,
                            SubID     = tran.DebitSubID,
                            AcctDescr = dacct.Description,
                            SubDescr  = dsub.Description,
                            BranchID  = tran.BranchID,
                            ItdAmt    = 0m,
                            YtdAmt    = 0m,
                            PtdAmt    = 0m
                        };
                    }
                    record.ItdAmt += tran.TranAmt;
                    if (filter.PeriodID.Substring(0, 4) == period.FinYear)
                    {
                        record.YtdAmt += tran.TranAmt;
                    }
                    if (filter.PeriodID == tran.FinPeriodID)
                    {
                        record.PtdAmt += tran.TranAmt;
                    }
                    dict[dkey] = record;
                }

                if (!IsAccrualAccount <FATran.creditAccountID, FATran.creditSubID>(tran, asset))
                {
                    Amounts record = null;
                    string  ckey   = string.Format("{0}{1}", cacct.AccountCD, csub.SubCD);
                    if (!dict.TryGetValue(ckey, out record))
                    {
                        record = new Amounts
                        {
                            BookID    = tran.BookID,
                            AccountID = tran.CreditAccountID,
                            SubID     = tran.CreditSubID,
                            AcctDescr = cacct.Description,
                            SubDescr  = csub.Description,
                            BranchID  = tran.BranchID,
                            ItdAmt    = 0m,
                            YtdAmt    = 0m,
                            PtdAmt    = 0m
                        };
                    }
                    record.ItdAmt -= tran.TranAmt;
                    if (filter.PeriodID.Substring(0, 4) == period.FinYear)
                    {
                        record.YtdAmt -= tran.TranAmt;
                    }
                    if (filter.PeriodID == tran.FinPeriodID)
                    {
                        record.PtdAmt -= tran.TranAmt;
                    }
                    dict[ckey] = record;
                }
            }

            foreach (Amounts amt in dict.Values)
            {
                if (amt.ItdAmt != 0m || amt.YtdAmt != 0m || amt.PtdAmt != 0m)
                {
                    yield return(amt);
                }
            }
        }