Ejemplo n.º 1
0
 protected virtual void BoundaryYears_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
 {
     if (e.Row != null)
     {
         BoundaryYears filter = (BoundaryYears)e.Row;
         Books.SetProcessDelegate(list => GeneratePeriods(filter, list));
     }
 }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
0
        public static void GeneratePeriods(BoundaryYears filter, List <FABook> books)
        {
            GenerationPeriods graph = PXGraph.CreateInstance <GenerationPeriods>();

            graph.GeneratePeriodsProc(filter, books);
        }