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 GenerateNextOrganizationFinYear(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(FinPeriodRepository.FindLastYear(FinPeriod.organizationID.MasterValue, clearQueryCache: true).Year), int.Parse(generatedYearNumber)); } short generatedFinPeriodsCount = (short)masterFinYear.FinPeriods; if (YearSetup.Current.HasAdjustmentPeriod == true) { generatedFinPeriodsCount--; } OrganizationFinPeriod lastNonAdjustmentOrgFinPeriod = this.FinPeriodRepository.FindLastNonAdjustmentOrganizationFinPeriodOfYear(year.OrganizationID, year.Year, clearQueryCache: true); int generatedMasterYearNumber = int.Parse(lastNonAdjustmentOrgFinPeriod.FinYear); List <MasterFinPeriod> masterFinPeriods; PXSelectBase <MasterFinPeriod> select = new PXSelectReadonly < MasterFinPeriod, Where <MasterFinPeriod.finPeriodID, Greater <Required <MasterFinPeriod.finPeriodID> >, And <MasterFinPeriod.startDate, NotEqual <MasterFinPeriod.endDate> > >, OrderBy < Asc <MasterFinPeriod.finPeriodID> > >(this); select.View.Clear(); while ((masterFinPeriods = select .SelectWindowed(0, generatedFinPeriodsCount, lastNonAdjustmentOrgFinPeriod.MasterFinPeriodID) .RowCast <MasterFinPeriod>() .ToList()).Count < generatedFinPeriodsCount) { generatedMasterYearNumber++; MasterCalendarGraph.Clear(); MasterCalendarGraph.GenerateCalendar( FinPeriod.organizationID.MasterValue, int.Parse(FinPeriodRepository.FindLastYear(FinPeriod.organizationID.MasterValue, clearQueryCache: true).Year), generatedMasterYearNumber); select.View.Clear(); } MasterFinPeriod startMasterFinPeriod = masterFinPeriods.First(); return(GenerateSingleOrganizationFinYear((int)year.OrganizationID, masterFinYear, startMasterFinPeriod)); }