Beispiel #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();
		}
Beispiel #2
0
        public static int GetBookPeriodsInYear(PXGraph graph, int?BookID)
        {
            FABook book = PXSelect <FABook, Where <FABook.bookID, Equal <Required <FABook.bookID> > > > .Select(graph, BookID);

            IPeriodSetup periodsInYear;

            if (book.UpdateGL ?? false)
            {
                periodsInYear = (FinPeriodSetup)PXSelectGroupBy <FinPeriodSetup,
                                                                 Where <FinPeriodSetup.endDate, Greater <FinPeriodSetup.startDate> >,
                                                                 Aggregate <Max <FinPeriodSetup.periodNbr> > > .Select(graph);
            }
            else
            {
                periodsInYear = (FABookPeriodSetup)PXSelectGroupBy <FABookPeriodSetup,
                                                                    Where <FABookPeriodSetup.endDate, Greater <FABookPeriodSetup.startDate>,
                                                                           And <FABookPeriodSetup.bookID, Equal <Required <FABookPeriodSetup.bookID> > > >,
                                                                    Aggregate <Max <FABookPeriodSetup.periodNbr> > > .Select(graph, BookID);
            }
            if (periodsInYear == null || periodsInYear.PeriodNbr == null)
            {
                throw new PXFABookCalendarException();
            }
            return(Convert.ToInt32(periodsInYear.PeriodNbr));
        }
Beispiel #3
0
        public static string PeriodPlusPeriod(PXGraph graph, string FiscalPeriodID, int counter, int?BookID)
        {
            FABook book = PXSelect <FABook, Where <FABook.bookID, Equal <Required <FABook.bookID> > > > .Select(graph, BookID);

            IYearSetup setup;

            if (book.UpdateGL == true)
            {
                setup = (FinYearSetup)PXSelect <FinYearSetup> .Select(graph);
            }
            else
            {
                setup = (FABookYearSetup)PXSelect <FABookYearSetup, Where <FABookYearSetup.bookID, Equal <Required <FABookYearSetup.bookID> > > > .Select(graph, BookID);
            }

            IPeriodSetup periodsInYear;

            if (book.UpdateGL == true)
            {
                periodsInYear = (FinPeriodSetup)PXSelectGroupBy <FinPeriodSetup, Where <FinPeriodSetup.endDate, Greater <FinPeriodSetup.startDate> >,
                                                                 Aggregate <Max <FinPeriodSetup.periodNbr> > > .Select(graph);
            }
            else
            {
                periodsInYear = (FABookPeriodSetup)PXSelectGroupBy <FABookPeriodSetup, Where <FABookPeriodSetup.endDate, Greater <FABookPeriodSetup.startDate>, And <FABookPeriodSetup.bookID, Equal <Required <FABookPeriodSetup.bookID> > > >,
                                                                    Aggregate <Max <FABookPeriodSetup.periodNbr> > > .Select(graph, BookID);
            }

            if (setup != null && FiscalPeriodSetupCreator.IsFixedLengthPeriod(setup.FPType) &&
                periodsInYear != null && periodsInYear.PeriodNbr != null)
            {
                return(OffsetPeriod(graph, FiscalPeriodID, 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> > > > >, OrderBy <Asc <FABookPeriod.finPeriodID> > > .SelectWindowed(graph, 0, counter, FiscalPeriodID, BookID);

                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> > > > >, OrderBy <Desc <FABookPeriod.finPeriodID> > > .SelectWindowed(graph, 0, -counter, FiscalPeriodID, BookID);

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

                return(((FABookPeriod)res[res.Count - 1]).FinPeriodID);
            }
            else
            {
                return(FiscalPeriodID);
            }
        }
Beispiel #4
0
        public override void Persist()
        {
            foreach (FABookSettings set in this.DepreciationSettings.Cache.Inserted)
            {
                FABookPeriodSetup period = PXSelect <FABookPeriodSetup, Where <FABookPeriodSetup.bookID, Equal <Required <FABookPeriodSetup.bookID> > > > .SelectWindowed(this, 0, 1, set.BookID);

                if (period == null && set.UpdateGL == false)
                {
                    FABook book = PXSelect <FABook, Where <FABook.bookID, Equal <Required <FABook.bookID> > > > .SelectWindowed(this, 0, 1, set.BookID);

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

                if (period == null && set.UpdateGL == false)
                {
                    FABook book = PXSelect <FABook, Where <FABook.bookID, Equal <Required <FABook.bookID> > > > .SelectWindowed(this, 0, 1, set.BookID);

                    if (book != null)
                    {
                        this.DepreciationSettings.Cache.RaiseExceptionHandling <FABookSettings.bookID>(set, book.BookCode, new PXSetPropertyException <FABookSettings.bookID>(Messages.NoCalendarDefined));
                    }
                }
            }
            base.Persist();
        }
        protected virtual void _(Events.RowSelected <FABookYear> e)
        {
            FABook book =
                SelectFrom <FABook>
                .Where <FABook.bookID.IsEqual <@P.AsInt> >
                .View.SelectSingleBound(this, null, e.Row.BookID);

            PXUIFieldAttribute.SetVisible <FABookYear.organizationID>(BookYear.Cache, null, (book != null && book.UpdateGL == true && PXAccess.FeatureInstalled <FeaturesSet.multipleCalendarsSupport>()));
        }
Beispiel #6
0
        public override void FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            base.FieldDefaulting(sender, e);

            FABook book = PXSelect <FABook, Where <FABook.updateGL, Equal <boolTrue> > > .SelectSingleBound(sender.Graph, new object[0]);

            if (book != null)
            {
                e.NewValue = book.BookCode;
            }
        }
        public bool IsPostingFABook(int?bookID)
        {
            FABook book = FindFABook(bookID);

            if (book == null)
            {
                throw new ArgumentOutOfRangeException(nameof(bookID));
            }

            return(book.UpdateGL == true);
        }
		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;
		}
Beispiel #9
0
        public static IYearSetup GetBookCalendar(PXGraph graph, int?BookID)
        {
            FABook book = PXSelect <FABook, Where <FABook.bookID, Equal <Required <FABook.bookID> > > > .Select(graph, BookID);

            if (book.UpdateGL ?? false)
            {
                return((FinYearSetup)PXSelect <FinYearSetup> .Select(graph));
            }
            else
            {
                return((FABookYearSetup)PXSelect <FABookYearSetup, Where <FABookYearSetup.bookID, Equal <Required <FABookYearSetup.bookID> > > > .Select(graph, BookID));
            }
        }
        public FABookYear FindMasterFABookYearByID(FABook book, string yearNumber, bool clearQueryCache = false, bool mergeCache = false)
        {
            CheckNotNullObjectContract(book, nameof(book));
            CheckNotNullOrEmptyStringContract(yearNumber, nameof(yearNumber));

            return(new Select <
                       FABookYear,
                       Where <FABookYear.bookID, Equal <Required <FABook.bookID> >,
                              And <FABookYear.organizationID, Equal <FinPeriod.organizationID.masterValue>,
                                   And <FABookYear.year, Equal <Required <FABookYear.year> > > > > >()
                   .CreateView(Graph, clearQueryCache, mergeCache)
                   .SelectSingle(book.BookID, yearNumber)
                   as FABookYear);
        }
Beispiel #11
0
        protected virtual void FABook_RowDeleting(PXCache sender, PXRowDeletingEventArgs e)
        {
            FABook book = (FABook)e.Row;

            if (PXSelect <FABookSettings, Where <FABookSettings.bookID, Equal <Current <FABook.bookID> > > > .SelectSingleBound(this, new object[] { e.Row }).Count > 0)
            {
                throw new PXSetPropertyException(Messages.BookExistsHistory, book.BookCode);
            }

            if (PXSelect <FABookBalance, Where <FABookBalance.bookID, Equal <Current <FABook.bookID> > > > .SelectSingleBound(this, new object[] { e.Row }).Count > 0)
            {
                throw new PXSetPropertyException(Messages.BookExistsHistory, book.BookCode);
            }
        }
		public static int GetBookPeriodsInYear(PXGraph graph,FABook book, int Year)
		{
			FABookYear year = GetBookYear(graph, book.BookID, Year);
			if (year == null)
			{
				throw new PXException(Messages.FABookPeriodsNotDefined, book.BookCode, Year);
			}

			return PXSelectGroupBy<FABookPeriod, 
				Where<FABookPeriod.bookID, Equal<Required<FABookPeriod.bookID>>,
					And<FABookPeriod.finYear, Equal<Required<FABookPeriod.finYear>>,
					And<FABookPeriod.startDate, NotEqual<FABookPeriod.endDate>>>>,
				Aggregate<Count<FABookPeriod.finPeriodID>>>
				.Select(graph, book.BookID, year.Year).RowCount ?? 0;
		}
Beispiel #13
0
        protected virtual void FABook_UpdateGL_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            FABook book = (FABook)e.Row;

            if (book == null || !(book.UpdateGL ?? false))
            {
                return;
            }

            foreach (FABook other in PXSelect <FABook, Where <FABook.bookCode, NotEqual <Current <FABook.bookCode> > > > .SelectMultiBound(this, new object[] { book }))
            {
                other.UpdateGL = false;
                Book.Update(other);
            }
            Book.View.RequestRefresh();
        }
Beispiel #14
0
        protected virtual void FABook_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            FABook book = (FABook)e.Row;

            if (e.Operation == PXDBOperation.Delete)
            {
                if (PXSelect <FABookSettings, Where <FABookSettings.bookID, Equal <Current <FABook.bookID> > > > .SelectSingleBound(this, new object[] { e.Row }).Count > 0)
                {
                    throw new PXRowPersistingException("BookCode", book.BookCode, Messages.BookExistsHistory);
                }

                if (PXSelect <FABookBalance, Where <FABookBalance.bookID, Equal <Current <FABook.bookID> > > > .SelectSingleBound(this, new object[] { e.Row }).Count > 0)
                {
                    throw new PXRowPersistingException("BookCode", book.BookCode, Messages.BookExistsHistory);
                }
            }
        }
        public FABookPeriod FindNextNonAdjustmentMasterFABookPeriod(FABook book, string prevFABookPeriodID, bool clearQueryCache = false, bool mergeCache = false)
        {
            CheckNotNullObjectContract(book, nameof(book));
            CheckNotNullOrEmptyStringContract(prevFABookPeriodID, nameof(prevFABookPeriodID));

            return(new Select <
                       FABookPeriod,
                       Where <FABookPeriod.bookID, Equal <Required <FABook.bookID> >,
                              And <FABookPeriod.organizationID, Equal <FinPeriod.organizationID.masterValue>,
                                   And <FABookPeriod.finPeriodID, Greater <Required <FABookPeriod.finPeriodID> >,
                                        And <FABookPeriod.startDate, NotEqual <FABookPeriod.endDate> > > > >,
                       OrderBy <
                           Asc <FABookPeriod.finPeriodID> > >()
                   .CreateView(Graph, clearQueryCache, mergeCache)
                   .SelectSingle(book.BookID, prevFABookPeriodID)
                   as FABookPeriod);
        }
Beispiel #16
0
        protected virtual void FABook_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            FABook book = (FABook)e.Row;

            if (book == null)
            {
                return;
            }

            FABookYearSetup setup = PXSelect <FABookYearSetup, Where <FABookYearSetup.bookID, Equal <Current <FABook.bookID> > > > .SelectSingleBound(this, new object[] { book });

            if (setup == null && book.UpdateGL != true)
            {
                PXUIFieldAttribute.SetEnabled <FABook.selected>(sender, book, false);
                sender.RaiseExceptionHandling <FABook.selected>(book, null, new PXSetPropertyException(Messages.CalendarSetupNotFound, PXErrorLevel.RowWarning, book.BookCode));
            }
        }
Beispiel #17
0
        protected virtual void FABook_UpdateGL_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            FABook book = e.Row as FABook;

            if (book == null)
            {
                return;
            }

            if (Equals(e.NewValue, true))
            {
                FABookYearSetup setup = PXSelect <FABookYearSetup,
                                                  Where <FABookYearSetup.bookID, Equal <Current <FABook.bookID> > > > .SelectSingleBound(this, new object[] { book });

                if (setup != null)
                {
                    throw new PXSetPropertyException(Messages.UpdateGLBookHasFACalendar, PXErrorLevel.RowError, book.BookCode);
                }
            }
        }
        public static int GetBookPeriodsInYear(PXGraph graph, FABook book, int Year)
        {
            FABookYear year = GetBookYear(graph, book.BookID, Year);

            if (year == null)
            {
                throw new PXException(Messages.FABookPeriodsNotDefined, book.BookCode, Year);
            }

            // TODO: AC-106141
            // Use BranchID (OrganizationID) passed as parameter
            return(PXSelectGroupBy <
                       FABookPeriod,
                       Where <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >,
                              And <FABookPeriod.finYear, Equal <Required <FABookPeriod.finYear> >,
                                   And <FABookPeriod.startDate, NotEqual <FABookPeriod.endDate> > > >,
                       Aggregate <
                           Count <FABookPeriod.finPeriodID> > >
                   .Select(graph, book.BookID, year.Year)
                   .RowCount ?? 0);
        }
Beispiel #19
0
        protected override void ClosePeriodProc(FinPeriod p)
        {
            PXSelectBase select = new PXSelect <FARegister,
                                                Where <FARegister.finPeriodID, Equal <Required <FARegister.finPeriodID> >,
                                                       And <FARegister.released, Equal <False> > > >(this);
            FARegister doc = (FARegister)select.View.SelectSingle(p.FinPeriodID);

            if (doc != null)
            {
                throw new PXException(AP.Messages.PeriodHasUnreleasedDocs);
            }

            PXResult <FABookBalance, FixedAsset, FABook> res = (PXResult <FABookBalance, FixedAsset, FABook>) PXSelectJoin <FABookBalance,
                                                                                                                            LeftJoin <FixedAsset, On <FixedAsset.assetID, Equal <FABookBalance.assetID> >,
                                                                                                                                      LeftJoin <FABook, On <FABookBalance.bookID, Equal <FABook.bookID> >,
                                                                                                                                                LeftJoin <FADetails, On <FADetails.assetID, Equal <FABookBalance.assetID> > > > >,
                                                                                                                            Where <FABookBalance.deprFromPeriod, LessEqual <Current <FinPeriod.finPeriodID> >,
                                                                                                                                   And <FABookBalance.deprToPeriod, GreaterEqual <Current <FinPeriod.finPeriodID> >,
                                                                                                                                        And <FABookBalance.updateGL, Equal <True>,
                                                                                                                                             And <FABookBalance.depreciate, Equal <True>,
                                                                                                                                                  And <FixedAsset.suspended, NotEqual <True>,
                                                                                                                                                       And <FADetails.hold, NotEqual <True>,
                                                                                                                                                            And <FABookBalance.initPeriod, IsNotNull,
                                                                                                                                                                 And <Where <FABookBalance.currDeprPeriod, IsNull,
                                                                                                                                                                             And <FABookBalance.status, Equal <FixedAssetStatus.active>,
                                                                                                                                                                                  Or <FABookBalance.currDeprPeriod, LessEqual <Current <FinPeriod.finPeriodID> > > > > > > > > > > > > > .SelectSingleBound(this, new object[] { p });

            if (res != null)
            {
                FixedAsset asset = res;
                FABook     book  = res;
                throw new PXException(Messages.AssetNotDepreciatedInPeriod, asset.AssetCD, book.BookCode, FinPeriodIDAttribute.FormatForError(p.FinPeriodID));
            }

            p.FAClosed = true;
            Caches[typeof(FinPeriod)].Update(p);

            Actions.PressSave();
        }
        public IYearSetup FindFABookYearSetup(FABook book, bool clearQueryCache = false)
        {
            BqlCommand selectCommand;

            if (book.UpdateGL == true)
            {
                selectCommand = new Select <FinYearSetup>();
            }
            else
            {
                selectCommand = new Select <
                    FABookYearSetup,
                    Where <FABookYearSetup.bookID, Equal <Required <FABook.bookID> > > >();
            }
            PXView view = new PXView(Graph, true, selectCommand);

            if (clearQueryCache)
            {
                view.Clear();
            }
            return(view.SelectSingle(book.BookID) as IYearSetup);
        }
        public IEnumerable <IPeriodSetup> FindFABookPeriodSetup(FABook book, bool clearQueryCache = false)
        {
            BqlCommand selectCommand;

            if (book.UpdateGL == true)
            {
                selectCommand = new Select3 <FinPeriodSetup, OrderBy <Asc <FinPeriodSetup.periodNbr> > >();
            }
            else
            {
                selectCommand = new Select <
                    FABookPeriodSetup,
                    Where <FABookPeriodSetup.bookID, Equal <Required <FABook.bookID> > >,
                    OrderBy <Asc <FABookPeriodSetup.periodNbr> > >();
            }
            PXView view = new PXView(Graph, true, selectCommand);

            if (clearQueryCache)
            {
                view.Clear();
            }
            return(view.SelectMulti(book.BookID).Cast <IPeriodSetup>());
        }
		public static IYearSetup GetBookCalendar(PXGraph graph, int? BookID)
		{
			FABook book = PXSelect<FABook, Where<FABook.bookID, Equal<Required<FABook.bookID>>>>.Select(graph, BookID);
			return GetBookCalendar(graph, book);
		}
Beispiel #23
0
 public void SetBookID(FABook book)
 {
     BookID        = book.BookID;
     IsPostingBook = book.UpdateGL == true;
 }
Beispiel #24
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 FABookPeriod FindMasterFABookPeriodByID(FABook book, string periodID, bool clearQueryCache = false, bool mergeCache = false)
 {
     CheckNotNullObjectContract(book, nameof(book));
     return(FindMasterFABookPeriodByID(book.BookID, periodID, clearQueryCache, mergeCache));
 }
Beispiel #26
0
        public virtual void GeneratePeriodsProc(BoundaryYears filter, List <FABook> books)
        {
            for (int i = 0; i < books.Count; ++i)
            {
                FABook book = books[i];

                FieldDefaulting.AddHandler <FABookYear.bookID>(delegate(PXCache sender, PXFieldDefaultingEventArgs e)
                {
                    if (!e.Cancel)
                    {
                        e.NewValue = book.BookID;
                    }
                    e.Cancel = true;
                });

                FieldDefaulting.AddHandler <FABookPeriod.bookID>(delegate(PXCache sender, PXFieldDefaultingEventArgs e)
                {
                    if (!e.Cancel)
                    {
                        e.NewValue = book.BookID;
                    }
                    e.Cancel = true;
                });

                bool yearcreated = false;

                FABookYear bookyear = PXSelect <FABookYear, Where <FABookYear.bookID, Equal <Current <FABook.bookID> > >, OrderBy <Desc <FABookYear.year> > > .SelectSingleBound(this, new object[] { book });

                FABookYear newYear = new FABookYear {
                    Year = bookyear != null ? bookyear.Year : null
                };

                if (book.UpdateGL == false)
                {
                    FABookYearSetup calendar = PXSelect <FABookYearSetup, Where <FABookYearSetup.bookID, Equal <Current <FABook.bookID> > > > .SelectSingleBound(this, new object[] { book });

                    IEnumerable periods = PXSelect <FABookPeriodSetup, Where <FABookPeriodSetup.bookID, Equal <Current <FABook.bookID> > > > .SelectMultiBound(this, new object[] { book });

                    while (newYear != null && string.Compare(newYear.Year, filter.YearTo) < 0)
                    {
                        newYear = FiscalYearCreator <FABookYear, FABookPeriod, FABookPeriodSetup> .CreateNextYear(this, calendar, periods.RowCast <FABookPeriodSetup>(), bookyear);

                        bookyear = newYear;

                        yearcreated |= newYear != null;
                    }

                    bookyear = PXSelect <FABookYear, Where <FABookYear.bookID, Equal <Current <FABook.bookID> > >, OrderBy <Asc <FABookYear.year> > > .SelectSingleBound(this, new object[] { book });

                    newYear = new FABookYear {
                        Year = bookyear != null ? bookyear.Year : null
                    };
                    while (newYear != null && string.Compare(newYear.Year, calendar.FirstFinYear) > 0)
                    {
                        newYear = FiscalYearCreator <FABookYear, FABookPeriod, FABookPeriodSetup> .CreatePrevYear(this, calendar, periods.RowCast <FABookPeriodSetup>(), bookyear);

                        bookyear = newYear;

                        yearcreated |= newYear != null;
                    }
                }
                else
                {
                    FinYearSetup calendar = PXSelect <FinYearSetup> .Select(this);

                    IEnumerable periods = PXSelect <FinPeriodSetup> .Select(this);

                    while (newYear != null && string.Compare(newYear.Year, filter.YearTo) < 0)
                    {
                        newYear = FiscalYearCreator <FABookYear, FABookPeriod, FinPeriodSetup> .CreateNextYear(this, calendar, periods.RowCast <FinPeriodSetup>(), bookyear);

                        bookyear = newYear;

                        yearcreated |= newYear != null;
                    }

                    bookyear = PXSelect <FABookYear, Where <FABookYear.bookID, Equal <Current <FABook.bookID> > >, OrderBy <Asc <FABookYear.year> > > .SelectSingleBound(this, new object[] { book });

                    newYear = new FABookYear {
                        Year = bookyear != null ? bookyear.Year : null
                    };
                    while (newYear != null && string.Compare(newYear.Year, calendar.FirstFinYear) > 0)
                    {
                        newYear = FiscalYearCreator <FABookYear, FABookPeriod, FinPeriodSetup> .CreatePrevYear(this, calendar, periods.RowCast <FinPeriodSetup>(), bookyear);

                        bookyear = newYear;

                        yearcreated |= newYear != null;
                    }
                }

                if (!IsImport)
                {
                    if (yearcreated)
                    {
                        PXProcessing <FABook> .SetInfo(i, ActionsMessages.RecordProcessed);
                    }
                    else
                    {
                        PXProcessing <FABook> .SetWarning(i, Messages.CalendarAlreadyExists);
                    }
                }
            }

            Actions.PressSave();
        }