Esempio n. 1
0
        private DateTime?GetFirstActivityDate()
        {
            MasterFinYear minYear = PXSelect <MasterFinYear, Where <True, Equal <True> >, OrderBy <Desc <MasterFinYear.year> > > .Select(this);

            int minWeek;

            if (minYear != null && int.TryParse(minYear.Year + "01", out minWeek))
            {
                CRPMTimeActivity firstActivity = PXSelect <CRPMTimeActivity,
                                                           Where <CRPMTimeActivity.weekID, GreaterEqual <Required <CRPMTimeActivity.weekID> >,
                                                                  And <CRPMTimeActivity.trackTime, Equal <True>,
                                                                       And <CRPMTimeActivity.classID, NotEqual <CRActivityClass.emailRouting>,
                                                                            And <CRPMTimeActivity.classID, NotEqual <CRActivityClass.task>,
                                                                                 And <CRPMTimeActivity.classID, NotEqual <CRActivityClass.events> > > > > >,
                                                           OrderBy <
                                                               Asc <CRPMTimeActivity.weekID> > > .Select(this, minWeek);

                if (firstActivity != null)
                {
                    return(firstActivity.StartDate.Value);
                }
            }

            return(null);
        }
        protected virtual OrganizationFinYear GenerateSingleOrganizationFinYear(int organizationID, string startYearNumber, string startMasterFinPeriodID)
        {
            MasterFinYear   startYear            = FinPeriodRepository.FindMasterFinYearByID(startYearNumber);
            MasterFinPeriod startMasterFinPeriod = FinPeriodRepository.FindMasterFinPeriodByID(startMasterFinPeriodID);

            return(GenerateSingleOrganizationFinYear(organizationID, startYear, startMasterFinPeriod));
        }
        protected virtual OrganizationFinPeriod GenerateAdjustmentOrganizationFinPeriod(int organizationID, OrganizationFinPeriod prevFinPeriod)
        {
            (string masterYearNumber, string masterPeriodNumber) = FinPeriodUtils.ParseFinPeriodID(prevFinPeriod.FinPeriodID);
            MasterFinYear masterFinYear = FinPeriodRepository.FindMasterFinYearByID(masterYearNumber, clearQueryCache: true);
            string        adjustmentMasterFinPeriodID = $"{masterYearNumber:0000}{masterFinYear.FinPeriods:00}";

            (string yearNumber, string periodNumber) = FinPeriodUtils.ParseFinPeriodID(prevFinPeriod.FinPeriodID);
            periodNumber = $"{int.Parse(periodNumber) + 1:00}";
            OrganizationFinPeriod orgFinPeriod = new OrganizationFinPeriod
            {
                OrganizationID    = organizationID,
                FinPeriodID       = FinPeriodUtils.ComposeFinPeriodID(yearNumber, periodNumber),
                MasterFinPeriodID = adjustmentMasterFinPeriodID,
                FinYear           = yearNumber,
                PeriodNbr         = periodNumber,
                Custom            = prevFinPeriod.Custom,
                DateLocked        = prevFinPeriod.DateLocked,
                StartDate         = prevFinPeriod.EndDate,
                EndDate           = prevFinPeriod.EndDate,

                Status   = prevFinPeriod.Status,
                ARClosed = prevFinPeriod.ARClosed,
                APClosed = prevFinPeriod.APClosed,
                FAClosed = prevFinPeriod.FAClosed,
                CAClosed = prevFinPeriod.CAClosed,
                INClosed = prevFinPeriod.INClosed,

                Descr = Messages.AdjustmentPeriod,
            };

            MasterFinPeriod masterFinPeriod = FinPeriodRepository.FindMasterFinPeriodByID(adjustmentMasterFinPeriodID);

            PXDBLocalizableStringAttribute.CopyTranslations <MasterFinPeriod.descr, OrganizationFinPeriod.descr>(this, masterFinPeriod, orgFinPeriod);

            return(orgFinPeriod);
        }
        protected virtual OrganizationFinYear GenerateSingleOrganizationFinYear(int organizationID, MasterFinYear startMasterYear, MasterFinPeriod startMasterFinPeriod)
        {
            if (startMasterYear == null)
            {
                throw new ArgumentNullException(nameof(startMasterYear));
            }
            if (startMasterFinPeriod == null)
            {
                throw new ArgumentNullException(nameof(startMasterFinPeriod));
            }

            OrganizationFinYear newOrganizationFinYear = (OrganizationFinYear)this.Caches <OrganizationFinYear>().Insert(
                new OrganizationFinYear
            {
                OrganizationID         = organizationID,
                Year                   = startMasterYear.Year,
                FinPeriods             = startMasterYear.FinPeriods,
                StartMasterFinPeriodID = startMasterFinPeriod.FinPeriodID,
                StartDate              = startMasterFinPeriod.StartDate,
            });

            short           periodNumber          = 1;
            MasterFinPeriod sourceMasterFinPeriod = startMasterFinPeriod;
            int             periodsCountForCopy   = (int)newOrganizationFinYear.FinPeriods;

            if (YearSetup.Current.HasAdjustmentPeriod == true)
            {
                periodsCountForCopy--;
            }
            OrganizationFinPeriod newOrganizationFinPeriod = null;

            FinPeriod firstOrgFinPeriod = FinPeriodRepository.FindFirstPeriod(organizationID, clearQueryCache: true);

            while (periodNumber <= periodsCountForCopy)
            {
                newOrganizationFinPeriod = (OrganizationFinPeriod)this.Caches <OrganizationFinPeriod>().Insert(
                    CopyOrganizationFinPeriodFromMaster(
                        organizationID,
                        sourceMasterFinPeriod,
                        firstOrgFinPeriod != null && Convert.ToInt32(firstOrgFinPeriod.FinYear) > Convert.ToInt32(newOrganizationFinYear.Year) ? firstOrgFinPeriod : null,
                        newOrganizationFinYear.Year,
                        $"{periodNumber:00}"));

                if (periodNumber < periodsCountForCopy)                 // no need to search for the next master period if last organization period is generated
                {
                    string sourceMasterFinPeriodID = sourceMasterFinPeriod.FinPeriodID;
                    while ((sourceMasterFinPeriod = FinPeriodRepository.FindNextNonAdjustmentMasterFinPeriod(sourceMasterFinPeriodID, clearQueryCache: true)) == null)
                    {
                        MasterCalendarGraph.Clear();
                        MasterCalendarGraph.GenerateNextMasterFinYear();
                    }
                }

                periodNumber++;
            }
            newOrganizationFinYear.EndDate = newOrganizationFinPeriod.EndDate;
            if (YearSetup.Current.HasAdjustmentPeriod == true)
            {
                this.Caches <OrganizationFinPeriod>().Insert(GenerateAdjustmentOrganizationFinPeriod(organizationID, newOrganizationFinPeriod));
            }

            return(newOrganizationFinYear);
        }