private bool IsFirstOrLastOrganizationFinYear(OrganizationFinYear organizationFinYear) { FinYear firstFinYear = FinPeriodRepository.FindFirstYear(organizationFinYear.OrganizationID, clearQueryCache: true); FinYear lastFinYear = FinPeriodRepository.FindLastYear(organizationFinYear.OrganizationID, clearQueryCache: true); return(organizationFinYear.Year == firstFinYear.Year || organizationFinYear.Year == lastFinYear.Year); }
protected virtual OrganizationFinYear GeneratePreviousOrganizationFinYear(OrganizationFinYear year) { string generatedYearNumber = $"{int.Parse(year.Year)-1:0000}"; MasterFinYear masterFinYear; while ((masterFinYear = FinPeriodRepository.FindMasterFinYearByID(generatedYearNumber, clearQueryCache: true)) == null) { MasterCalendarGraph.Clear(); MasterCalendarGraph.GenerateCalendar( FinPeriod.organizationID.MasterValue, int.Parse(generatedYearNumber), int.Parse(FinPeriodRepository.FindFirstYear(FinPeriod.organizationID.MasterValue, clearQueryCache: true).Year)); } short generatedFinPeriodsCount = (short)masterFinYear.FinPeriods; if (YearSetup.Current.HasAdjustmentPeriod == true) { generatedFinPeriodsCount--; } int generatedMasterYearNumber = int.Parse(FinPeriods.FinPeriodUtils.FiscalYear(year.StartMasterFinPeriodID)); List <MasterFinPeriod> masterFinPeriods; PXSelectBase <MasterFinPeriod> select = new PXSelectReadonly <MasterFinPeriod, Where <MasterFinPeriod.finPeriodID, Less <Required <MasterFinPeriod.finPeriodID> >, And <MasterFinPeriod.startDate, NotEqual <MasterFinPeriod.endDate> > >, OrderBy < Desc <MasterFinPeriod.finPeriodID> > >(this); select.View.Clear(); while ((masterFinPeriods = select .SelectWindowed(0, generatedFinPeriodsCount, year.StartMasterFinPeriodID) .RowCast <MasterFinPeriod>() .ToList()).Count < generatedFinPeriodsCount) { generatedMasterYearNumber--; MasterCalendarGraph.Clear(); MasterCalendarGraph.GenerateCalendar( FinPeriod.organizationID.MasterValue, generatedMasterYearNumber, int.Parse(FinPeriodRepository.FindFirstYear(FinPeriod.organizationID.MasterValue, clearQueryCache: true).Year)); select.View.Clear(); } MasterFinPeriod startMasterFinPeriod = masterFinPeriods.Last(); return(GenerateSingleOrganizationFinYear((int)year.OrganizationID, masterFinYear, startMasterFinPeriod)); }