Example #1
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();
		}
        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());
        }
Example #3
0
		protected virtual void FixedAsset_UsefulLife_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
		{
			FixedAsset header = (FixedAsset)e.Row;
			if (header == null) return;

			foreach (FABookSettings newSettings in PXSelect<FABookSettings, Where<FABookSettings.assetID, Equal<Required<FABookSettings.assetID>>>>.Select(this, header.AssetID)
					.RowCast<FABookSettings>()
					.Select(set => (FABookSettings)DepreciationSettings.Cache.CreateCopy(set)))
			{
				FADepreciationMethod deprMethod = PXSelectorAttribute.Select<FABookSettings.depreciationMethodID>(DepreciationSettings.Cache, newSettings) as FADepreciationMethod;
				if (deprMethod?.DepreciationMethod != FADepreciationMethod.depreciationMethod.AustralianPrimeCost
					&& deprMethod?.DepreciationMethod != FADepreciationMethod.depreciationMethod.NewZealandStraightLine
					&& deprMethod?.DepreciationMethod != FADepreciationMethod.depreciationMethod.NewZealandStraightLineEvenly)
				{
					newSettings.UsefulLife = header.UsefulLife;
					DepreciationSettings.Update(newSettings);
				}
			}
		}
Example #4
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);
				}
			}
		}