Ejemplo n.º 1
0
 protected virtual void showCalendar()
 {
     if (Book.Current.UpdateGL == true)
     {
         FiscalYearSetupMaint graph = CreateInstance <FiscalYearSetupMaint>();
         graph.FiscalYearSetup.Current = graph.FiscalYearSetup.Select();
         if (graph.FiscalYearSetup.Current == null)
         {
             FinYearSetup calendar = new FinYearSetup();
             graph.FiscalYearSetup.Cache.Insert(calendar);
             graph.FiscalYearSetup.Cache.IsDirty = false;
         }
         throw new PXRedirectRequiredException(graph, Messages.Calendar);
     }
     else
     {
         FABookYearSetupMaint graph = CreateInstance <FABookYearSetupMaint>();
         graph.FiscalYearSetup.Current = graph.FiscalYearSetup.Search <FABookYearSetup.bookID>(Book.Current.BookCode);
         if (graph.FiscalYearSetup.Current == null)
         {
             FABookYearSetup calendar = new FABookYearSetup {
                 BookID = Book.Current.BookID
             };
             graph.FiscalYearSetup.Cache.SetDefaultExt <FABookYearSetup.periodType>(calendar);
             graph.FiscalYearSetup.Cache.Insert(calendar);
             graph.FiscalYearSetup.Cache.IsDirty = false;
         }
         throw new PXRedirectRequiredException(graph, Messages.Calendar);
     }
 }
Ejemplo n.º 2
0
        public FinPeriod FindOffsetPeriod(string finPeriodID, int offset, int?organizationID)
        {
            FinYearSetup setup = PXSelect <FinYearSetup> .Select(Graph);

            //TODO: Need to refactor, duplicates the part of function FABookPeriodIDAttribute.GetBookPeriodsInYear
            FinPeriodSetup periodsInYear = PXSelectGroupBy <FinPeriodSetup, Where <FinPeriodSetup.endDate, Greater <FinPeriodSetup.startDate> >,
                                                            Aggregate <Max <FinPeriodSetup.periodNbr> > > .Select(Graph);

            if (setup != null && FiscalPeriodSetupCreator.IsFixedLengthPeriod(setup.FPType) &&
                periodsInYear != null && periodsInYear.PeriodNbr != null)
            {
                string offsetFinPeriodID = FinPeriodUtils.OffsetPeriod(finPeriodID, offset, Convert.ToInt32(periodsInYear.PeriodNbr));
                return(FindByID(organizationID, offsetFinPeriodID));
            }
            else if (offset > 0)
            {
                PXResultset <FinPeriod> res = PXSelect <
                    FinPeriod,
                    Where <
                        FinPeriod.finPeriodID, Greater <Required <FinPeriod.finPeriodID> >,
                        And <FinPeriod.startDate, NotEqual <FinPeriod.endDate>,
                             And <FinPeriod.organizationID, Equal <Required <FinPeriod.organizationID> > > > >,
                    OrderBy <
                        Asc <FinPeriod.finPeriodID> > >
                                              .SelectWindowed(Graph, 0, offset, finPeriodID, organizationID);

                if (res.Count < offset)
                {
                    return(null);
                }

                return((FinPeriod)res[res.Count - 1]);
            }
            else if (offset < 0)
            {
                PXResultset <FinPeriod> res = PXSelect <
                    FinPeriod,
                    Where <
                        FinPeriod.finPeriodID, Less <Required <FinPeriod.finPeriodID> >,
                        And <FinPeriod.startDate, NotEqual <FinPeriod.endDate>,
                             And <FinPeriod.organizationID, Equal <Required <FinPeriod.organizationID> > > > >,
                    OrderBy <
                        Desc <FinPeriod.finPeriodID> > >
                                              .SelectWindowed(Graph, 0, -offset, finPeriodID, organizationID);

                if (res.Count < -offset)
                {
                    return(null);
                }

                return((FinPeriod)res[res.Count - 1]);
            }
            else
            {
                return(FindByID(organizationID, finPeriodID));
            }
        }
Ejemplo n.º 3
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.º 4
0
 public GenerationPeriods()
 {
     FinYearSetup setup = FinYearSetup.Current;
 }