protected virtual void FABookSettings_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            FABookSettings set = (FABookSettings)e.Row;

            if (set == null)
            {
                return;
            }

            PXUIFieldAttribute.SetEnabled <FABookSettings.bookID>(sender, set, set.BookID == null);

            IYearSetup           yearSetup = FABookPeriodIDAttribute.GetBookCalendar(this, set.BookID);
            FADepreciationMethod method    = PXSelect <FADepreciationMethod, Where <FADepreciationMethod.methodID, Equal <Current <FABookSettings.depreciationMethodID> > > > .SelectSingleBound(this, new object[] { set });

            List <KeyValuePair <object, Dictionary <object, string[]> > > parsList = new List <KeyValuePair <object, Dictionary <object, string[]> > >();

            if (method != null)
            {
                parsList.Add(method.IsTableMethod == true
                                        ? new KeyValuePair <object, Dictionary <object, string[]> >(method.RecordType, FAAveragingConvention.RecordTypeDisabledValues)
                                        : new KeyValuePair <object, Dictionary <object, string[]> >(method.DepreciationMethod, FAAveragingConvention.DeprMethodDisabledValues));
            }
            if (yearSetup != null)
            {
                parsList.Add(new KeyValuePair <object, Dictionary <object, string[]> >(yearSetup.IsFixedLengthPeriod, FAAveragingConvention.FixedLengthPeriodDisabledValues));
            }

            FAAveragingConvention.SetAveragingConventionsList <FADepreciationMethod.averagingConvention>(sender, set, parsList.ToArray());
        }
示例#2
0
		public override void Persist()
		{
			foreach (FABookSettings set in DepreciationSettings.Cache.Inserted.Cast<FABookSettings>().Concat<FABookSettings>(DepreciationSettings.Cache.Updated.Cast<FABookSettings>()))
			{
				FABook book = PXSelect<FABook, Where<FABook.bookID, Equal<Required<FABook.bookID>>>>.SelectWindowed(this, 0, 1, set.BookID);
				IYearSetup yearSetup = FABookPeriodRepository.FindFABookYearSetup(book);

				if (yearSetup == null || !yearSetup.IsFixedLengthPeriod)
				{
					FABookPeriodSetup period = PXSelect<FABookPeriodSetup, Where<FABookPeriodSetup.bookID, Equal<Required<FABookPeriodSetup.bookID>>>>.SelectWindowed(this, 0, 1, set.BookID);
					if (period == null && set.UpdateGL == false && book != null)
					{
						DepreciationSettings.Cache.RaiseExceptionHandling<FABookSettings.bookID>(set, book.BookCode,
							new PXSetPropertyException<FABookSettings.bookID>(Messages.NoCalendarDefined));
					}
				}

				FADepreciationMethod method = PXSelect<FADepreciationMethod, Where<FADepreciationMethod.methodID, Equal<Required<FABookSettings.depreciationMethodID>>>>.SelectWindowed(this, 0, 1, set.DepreciationMethodID);
				if (method != null && method.IsTableMethod == true && method.UsefulLife != set.UsefulLife)
				{
					DepreciationSettings.Cache.RaiseExceptionHandling<FABookSettings.usefulLife>(set, set.UsefulLife, new PXSetPropertyException<FABookSettings.usefulLife>(Messages.UsefulLifeNotMatchDeprMethod));
				}
			}
			base.Persist();
		}
        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);
            }
        }
		public static IYearSetup GetBookCalendar(PXGraph graph, FABook book)
		{
			IYearSetup calendar = null;
			if (book != null)
			{
				calendar = book.UpdateGL == true
					? (IYearSetup)(FinYearSetup)PXSelect<FinYearSetup>.Select(graph)
					: (FABookYearSetup)PXSelect<FABookYearSetup, Where<FABookYearSetup.bookID, Equal<Required<FABookYearSetup.bookID>>>>.Select(graph, book.BookID);
			}

			return calendar;
		}
		public static short QuarterNumFromDate(PXGraph graph, DateTime? d, int? BookID)
		{
			decimal PeriodNbr = Convert.ToDecimal(FABookPeriodFromDate(graph, d, BookID).PeriodNbr);
			IYearSetup yearSetup = GetBookCalendar(graph, BookID);
			switch (yearSetup.FPType)
			{
				case FiscalPeriodSetupCreator.FPType.Month:
					return (short)decimal.Ceiling(PeriodNbr / 3);
				case FiscalPeriodSetupCreator.FPType.Quarter:
					return (short)PeriodNbr;
				default:
					throw new PXException(Messages.QuarterIsUndefined);
			}
		}
        public short GetQuarterNumberOfDate(DateTime?date, int?bookID, int?assetID)
        {
            CheckNotNullObjectContract(date, nameof(date));
            CheckNotNullIDContract(bookID, nameof(bookID));
            CheckNotNullIDContract(assetID, nameof(assetID));

            decimal    PeriodNbr = Convert.ToDecimal(FindFABookPeriodOfDate(date, bookID, assetID).PeriodNbr);
            IYearSetup yearSetup = FindFABookYearSetup(bookID);

            switch (yearSetup.FPType)
            {
            case FiscalPeriodSetupCreator.FPType.Month:
                return((short)decimal.Ceiling(PeriodNbr / 3));

            case FiscalPeriodSetupCreator.FPType.Quarter:
                return((short)PeriodNbr);

            default:
                throw new PXException(Messages.QuarterIsUndefined);
            }
        }
示例#7
0
		protected virtual void FABookSettings_DepreciationMethodID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
		{
			FABookSettings bookSettings = (FABookSettings)e.Row;
			if (bookSettings == null) return;

			if (bookSettings.BookID != null)
			{
				IYearSetup yearSetup = FABookPeriodRepository.FindFABookYearSetup(bookSettings.BookID);
				FADepreciationMethod deprMethod = PXSelectorAttribute.Select<FABookSettings.depreciationMethodID>(DepreciationSettings.Cache, bookSettings, e.NewValue) as FADepreciationMethod;

				if ((yearSetup.PeriodType == FinPeriodType.Week
						|| yearSetup.PeriodType == FinPeriodType.BiWeek
						|| yearSetup.PeriodType == FinPeriodType.FourWeek)
					&& (deprMethod?.IsNewZealandMethod == true))
				{
					e.NewValue = deprMethod?.MethodCD;
					
					string errorMessage = PXMessages.LocalizeFormat(Messages.WeeklyBooksDisabledForCalcMethod,
														PXStringListAttribute.GetLocalizedLabel<FADepreciationMethod.depreciationMethod>(Caches[typeof(FADepreciationMethod)], deprMethod));
					throw new PXSetPropertyException(errorMessage);
				}
			}
		}