Esempio n. 1
0
        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 = FABookPeriodUtils.GetFABookPeriodStartDate(FABookPeriodUtils.PeriodPlusPeriodsCount(bal.LastDeprPeriod, 1, bal.BookID, bal.AssetID), bal.BookID, bal.AssetID);
                }
                else
                {
                    FABookPeriod todayPeriod = FABookPeriodRepository.FindFABookPeriodOfDate(Accessinfo.BusinessDate, bal.BookID, bal.AssetID);
                    e.NewValue = string.CompareOrdinal(bal.CurrDeprPeriod, todayPeriod.FinPeriodID) > 0 ? FABookPeriodUtils.GetFABookPeriodStartDate(bal.CurrDeprPeriod, bal.BookID, bal.AssetID) : Accessinfo.BusinessDate;
                }
            }
            else
            {
                e.NewValue = Accessinfo.BusinessDate;
            }
        }
        public string PeriodPlusPeriodsCount(string finPeriodID, int counter, int?bookID, int?assetID)
        {
            FABookPeriodRepository.CheckNotNullOrEmptyStringContract(finPeriodID, nameof(finPeriodID));
            FABookPeriodRepository.CheckNotNullIDContract(bookID, nameof(bookID));
            FABookPeriodRepository.CheckNotNullIDContract(assetID, nameof(assetID));

            IYearSetup   setup         = FABookPeriodRepositoryHelper.FindFABookYearSetup(bookID);
            IPeriodSetup periodsInYear = FABookPeriodRepositoryHelper.FindFABookPeriodSetup(bookID).LastOrDefault();

            int organizationID = FABookPeriodRepositoryHelper.GetFABookPeriodOrganizationID(bookID, assetID);

            if (setup != null && FiscalPeriodSetupCreator.IsFixedLengthPeriod(setup.FPType) &&
                periodsInYear != null && periodsInYear.PeriodNbr != null)
            {
                return(FinPeriodUtils.OffsetPeriod(finPeriodID, counter, Convert.ToInt32(periodsInYear.PeriodNbr)));
            }
            else if (counter > 0)
            {
                PXResultset <FABookPeriod> res = PXSelect <
                    FABookPeriod,
                    Where <FABookPeriod.finPeriodID, Greater <Required <FABookPeriod.finPeriodID> >,
                           And <FABookPeriod.startDate, NotEqual <FABookPeriod.endDate>,
                                And <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >,
                                     And <FABookPeriod.organizationID, Equal <Required <FABookPeriod.organizationID> > > > > >,
                    OrderBy <
                        Asc <FABookPeriod.finPeriodID> > >
                                                 .SelectWindowed(Graph, 0, counter, finPeriodID, bookID, organizationID);

                if (res.Count < counter)
                {
                    throw new PXFABookPeriodException();
                }

                return(((FABookPeriod)res[res.Count - 1]).FinPeriodID);
            }
            else if (counter < 0)
            {
                PXResultset <FABookPeriod> res = PXSelect <
                    FABookPeriod,
                    Where <FABookPeriod.finPeriodID, Less <Required <FABookPeriod.finPeriodID> >,
                           And <FABookPeriod.startDate, NotEqual <FABookPeriod.endDate>,
                                And <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >,
                                     And <FABookPeriod.organizationID, Equal <Required <FABookPeriod.organizationID> > > > > >,
                    OrderBy <
                        Desc <FABookPeriod.finPeriodID> > >
                                                 .SelectWindowed(Graph, 0, -counter, finPeriodID, bookID, organizationID);

                if (res.Count < -counter)
                {
                    throw new PXFABookPeriodException();
                }

                return(((FABookPeriod)res[res.Count - 1]).FinPeriodID);
            }
            else
            {
                return(finPeriodID);
            }
        }
Esempio n. 3
0
        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
            {
                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(this, tran.BookID, FABookPeriodRepository.GetFABookPeriodOrganizationID(tran.BookID, tran.AssetID), (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;
            }
        }
        public int?PeriodMinusPeriod(string finPeriodID1, string finPeriodID2, int?bookID, int?assetID)
        {
            FABookPeriodRepository.CheckNotNullOrEmptyStringContract(finPeriodID1, nameof(finPeriodID1));
            FABookPeriodRepository.CheckNotNullOrEmptyStringContract(finPeriodID2, nameof(finPeriodID2));
            FABookPeriodRepository.CheckNotNullIDContract(bookID, nameof(bookID));
            FABookPeriodRepository.CheckNotNullIDContract(assetID, nameof(assetID));

            int count = PXSelect <
                FABookPeriod,
                Where <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >,
                       And <FABookPeriod.organizationID, Equal <Required <FABookPeriod.organizationID> >,
                            And <Where <FABookPeriod.finPeriodID, Equal <Required <FABookPeriod.finPeriodID> >,
                                        Or <FABookPeriod.finPeriodID, Equal <Required <FABookPeriod.finPeriodID> > > > > > > >
                        .Select(
                Graph,
                bookID,
                FABookPeriodRepositoryHelper.GetFABookPeriodOrganizationID(bookID, assetID),
                finPeriodID1,
                finPeriodID2)
                        .Count;

            if (count < 2 && string.Equals(finPeriodID1, finPeriodID2) == false)
            {
                throw new PXException(Messages.NoCalendarDefined);
            }

            PXResult res = PXSelectGroupBy <
                FABookPeriod,
                Where <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >,
                       And <FABookPeriod.organizationID, Equal <Required <FABookPeriod.organizationID> >,
                            And <FABookPeriod.finPeriodID, LessEqual <Required <FABookPeriod.finPeriodID> >,
                                 And <FABookPeriod.finPeriodID, Greater <Required <FABookPeriod.finPeriodID> >,
                                      And <FABookPeriod.endDate, Greater <FABookPeriod.startDate> > > > > >,
                Aggregate <
                    GroupBy <FABookPeriod.bookID,
                             GroupBy <FABookPeriod.organizationID,
                                      Count> > > >
                           .Select(
                Graph,
                bookID,
                FABookPeriodRepositoryHelper.GetFABookPeriodOrganizationID(bookID, assetID),
                finPeriodID1,
                finPeriodID2);

            return(res != null ? res.RowCount : null);
        }
        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);
        }