protected IEnumerable bookYear()
        {
            if (BookYear.Cache.InternalCurrent == null)
            {
                FABookYear defaultYear =
                    SelectFrom <FABookYear>
                    .InnerJoin <FABook> .On <FABookYear.bookID.IsEqual <FABook.bookID> >
                    .Where <FABookYear.organizationID.IsEqual <@P.AsInt>
                            .And <FABookYear.endDate.IsGreater <@P.AsDateTime> > >
                    .OrderBy <
                        Desc <FABook.updateGL>,
                        Asc <FABookYear.year> >
                    .View.SelectSingleBound(this, null, PXAccess.GetParentOrganizationID(Accessinfo.BranchID), Accessinfo.BusinessDate);

                if (defaultYear == null)
                {
                    defaultYear = SelectFrom <FABookYear>
                                  .InnerJoin <FABook> .On <FABookYear.bookID.IsEqual <FABook.bookID> >
                                  .Where <FABookYear.organizationID.IsEqual <@P.AsInt>
                                          .And <FABookYear.endDate.IsLess <@P.AsDateTime> > >
                                  .OrderBy <
                        Desc <FABook.updateGL>,
                        Desc <FABookYear.year> >
                                  .View.SelectSingleBound(this, null, PXAccess.GetParentOrganizationID(Accessinfo.BranchID), Accessinfo.BusinessDate);
                }

                return(new object[] { defaultYear ?? throw new PXSetupNotEnteredException <FABookYear>(Messages.NoCalendarDefined) });
        protected bool IsValidCurrent()
        {
            if (BookYear.Cache.InternalCurrent == null)
            {
                return(false);
            }

            FABookYear current = BookYear.Cache.Current as FABookYear;

            if (current.BookID == null || current.OrganizationID == null)
            {
                return(false);
            }

            FABookYear existYear = SelectFrom <FABookYear>
                                   .Where <FABookYear.bookID.IsEqual <@P.AsInt> >
                                   .View.ReadOnly.SelectSingleBound(this, null, current.BookID);

            if (existYear == null)
            {
                return(false);
            }

            return(true);
        }
Beispiel #3
0
        protected override bool CheckForPartiallyDefinedYear()
        {
            //Validates if there are FiscalYears with incomplete set of periods - not all the periods are defined;
            FABookYear unclosedYear = null;

            foreach (FABookYear fy in PXSelect <FABookYear,
                                                Where <FABookYear.bookID, Equal <Current <FABookYearSetup.bookID> >,
                                                       And <FABookYear.organizationID, Equal <FinPeriod.organizationID.masterValue> > > > .Select(this))
            {
                int count = 0;
                foreach (FABookPeriod fp in PXSelect <
                             FABookPeriod,
                             Where <FABookPeriod.finYear, Equal <Required <FABookPeriod.finYear> >,
                                    And <FABookPeriod.organizationID, Equal <FinPeriod.organizationID.masterValue> > > > .Select(this, fy.Year))
                {
                    count++;
                }
                if (count < fy.FinPeriods)
                {
                    unclosedYear = fy;
                    break;
                }
            }
            return(unclosedYear != null);
        }
        protected virtual IEnumerable first(PXAdapter adapter)
        {
            if (!IsValidCurrent())
            {
                yield break;
            }

            FABookYear bookYear = SelectSingleBookYear(LastFirstYear.First);

            BookYear.Cache.Clear();

            yield return(bookYear);
        }
Beispiel #5
0
        protected override void TYearSetupOnRowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            base.TYearSetupOnRowSelected(cache, e);
            FABookYearSetup yearSetup = (FABookYearSetup)e.Row;
            FABookBalance   bal       = PXSelect <FABookBalance, Where <FABookBalance.bookID, Equal <Current <FABookYearSetup.bookID> > > > .SelectSingleBound(this, new object[] { yearSetup });

            FABookYear year = null;

            if (bal == null)
            {
                year = PXSelect <FABookYear, Where <FABookYear.bookID, Equal <Current <FABookYearSetup.bookID> > > > .SelectSingleBound(this, new object[] { yearSetup });
            }
            DeleteGeneratedPeriods.SetEnabled(bal == null && year != null);
        }
		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;
		}
        protected virtual IEnumerable next(PXAdapter adapter)
        {
            if (!IsValidCurrent())
            {
                yield break;
            }

            FABookYear current = BookYear.Cache.Current as FABookYear;

            FABookYear bookYear = SelectSingleBookYear(PrevNextYear.Next, current.Year);

            if (bookYear == null)
            {
                bookYear = SelectSingleBookYear(LastFirstYear.First);
            }

            BookYear.Cache.Clear();

            yield return(bookYear);
        }
        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 #9
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();
        }