コード例 #1
0
        public virtual IEnumerable generateYears(PXAdapter adapter)
        {
            IFinPeriodRepository finPeriodRepository = Base.GetService <IFinPeriodRepository>();
            IFinPeriodUtils      finPeriodUtils      = Base.GetService <IFinPeriodUtils>();
            PrimaryFinYear       primaryYear         = (PrimaryFinYear)Base.Caches <PrimaryFinYear>().Current;

            if (primaryYear == null)
            {
                throw new PXException(Messages.NeedToCreateFirstCalendarYear);
            }

            int?firstExistingYear = int.TryParse(finPeriodRepository.FindFirstYear(primaryYear.OrganizationID ?? 0, clearQueryCache: true)?.Year, out int parsedFirstExistingYear)
                                ? parsedFirstExistingYear
                                : (int?)null;
            int?lastExistingYear = int.TryParse(finPeriodRepository.FindLastYear(primaryYear.OrganizationID ?? 0, clearQueryCache: true)?.Year, out int parsedLastExistingYear)
                                ? parsedLastExistingYear
                                : (int?)null;

            bool generateCalendar = true;

            if (!Base.IsContractBasedAPI)
            {
                generateCalendar = GenerateParams.AskExtFullyValid((graph, viewName) =>
                {
                    FinPeriodGenerateParameters parameters = GenerateParams.Current;
                    parameters.OrganizationID = primaryYear.OrganizationID;
                    parameters.FromYear       =
                        parameters.ToYear     = lastExistingYear == null ? primaryYear.Year : (lastExistingYear + 1).ToString();
                    parameters.FirstFinYear   = firstExistingYear?.ToString();
                    parameters.LastFinYear    = lastExistingYear?.ToString();
                },
                                                                   DialogAnswerType.Positive);
            }

            if (generateCalendar)
            {
                int fromYear = int.Parse(GenerateParams.Current.FromYear);
                int toYear   = int.Parse(GenerateParams.Current.ToYear);

                IFinPeriodMaintenanceGraph processingGraph = Base.Clone();
                PXLongOperation.StartOperation(
                    Base,
                    delegate()
                {
                    finPeriodUtils.CheckParametersOfCalendarGeneration(primaryYear.OrganizationID, fromYear, toYear);
                    processingGraph.GenerateCalendar(primaryYear.OrganizationID, fromYear, toYear);
                });

                if (Base.IsContractBasedAPI)
                {
                    PXLongOperation.WaitCompletion(Base.UID);
                }
            }
            return(adapter.Get());
        }
コード例 #2
0
 public static int AgeByPeriods(
     DateTime currentDate,
     DateTime dateToAge,
     IFinPeriodRepository finPeriodRepository,
     AgingDirection agingDirection,
     int numberOfBuckets) => AgeByPeriods(
     currentDate,
     dateToAge,
     finPeriodRepository,
     agingDirection,
     numberOfBuckets,
     FinPeriod.organizationID.MasterValue);
コード例 #3
0
        public static IEnumerable <string> GetPeriodAgingBucketDescriptions(
            IFinPeriodRepository finPeriodRepository,
            DateTime currentDate,
            AgingDirection agingDirection,
            int numberOfBuckets,
            int calendarOrganizationID,
            bool usePeriodDescription)
        {
            if (finPeriodRepository == null)
            {
                throw new ArgumentNullException(nameof(finPeriodRepository));
            }
            if (numberOfBuckets <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(numberOfBuckets));
            }

            short periodStep = (short)(agingDirection == AgingDirection.Backwards ? -1 : 1);

            FinPeriod currentPeriod = finPeriodRepository.GetByID(
                finPeriodRepository.GetPeriodIDFromDate(currentDate, calendarOrganizationID),
                calendarOrganizationID);

            yield return(usePeriodDescription
                ? currentPeriod.Descr
                : FinPeriodUtils.FormatForError(currentPeriod.FinPeriodID));

            --numberOfBuckets;

            while (numberOfBuckets > 1)
            {
                currentPeriod = finPeriodRepository.GetByID(
                    finPeriodRepository.GetOffsetPeriodId(currentPeriod.FinPeriodID, periodStep, calendarOrganizationID),
                    calendarOrganizationID);

                yield return(usePeriodDescription
                                ? currentPeriod.Descr
                                : FinPeriodUtils.FormatForError(currentPeriod.FinPeriodID));

                --numberOfBuckets;
            }

            if (numberOfBuckets > 0)
            {
                yield return(PXMessages.LocalizeFormatNoPrefix(
                                 agingDirection == AgingDirection.Backwards
                                                ? Messages.BeforeMonth
                                                : Messages.AfterMonth,
                                 usePeriodDescription
                                        ? currentPeriod.Descr
                                        : FinPeriodUtils.FormatForError(currentPeriod.FinPeriodID)));
            }
        }
コード例 #4
0
        public static IEnumerable <string> GetPeriodAgingBucketDescriptions(
            IFinPeriodRepository finPeriodRepository,
            DateTime currentDate,
            AgingDirection agingDirection,
            int numberOfBuckets)
        {
            if (finPeriodRepository == null)
            {
                throw new ArgumentNullException(nameof(finPeriodRepository));
            }
            if (numberOfBuckets <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(numberOfBuckets));
            }

            short periodStep = (short)(agingDirection == AgingDirection.Backwards ? -1 : 1);

            // Must not re-use any existing graphs due to possible query
            // caching of financial periods, which can impact localization
            // of their descriptions, see AC-84505.
            // -
            PXGraph graph = new PXGraph();

            FinPeriod currentPeriod = finPeriodRepository.GetByID(
                finPeriodRepository.GetPeriodIDFromDate(currentDate, FinPeriod.organizationID.MasterValue),
                FinPeriod.organizationID.MasterValue);

            yield return(currentPeriod.Descr);

            --numberOfBuckets;

            while (numberOfBuckets > 1)
            {
                currentPeriod = finPeriodRepository.GetByID(
                    finPeriodRepository.GetOffsetPeriodId(currentPeriod.FinPeriodID, periodStep, FinPeriod.organizationID.MasterValue),
                    FinPeriod.organizationID.MasterValue);

                yield return(currentPeriod.Descr);

                --numberOfBuckets;
            }

            if (numberOfBuckets > 0)
            {
                yield return(PXMessages.LocalizeFormatNoPrefix(
                                 agingDirection == AgingDirection.Backwards
                                                ? Messages.BeforeMonth
                                                : Messages.AfterMonth,
                                 currentPeriod.Descr));
            }
        }
コード例 #5
0
        /// <summary>
        /// Given the current date and the number of period-based aging buckets,
        /// returns the zero-based number of bucket that the specified test date
        /// falls into.
        /// </summary>
        /// <param name="numberOfBuckets">
        /// The total number of period-based buckets, including the "Current"
        /// and "Over" bucket. For backwards aging, the "Current" bucket encompasses
        /// dates in the same (or later) financial period as the current date, and
        /// the "Over" bucket corresponds to dates that are at least (numberOfBuckets - 1)
        /// periods back in time from the current date.
        /// </param>
        public static int AgeByPeriods(
            DateTime currentDate,
            DateTime dateToAge,
            IFinPeriodRepository finPeriodRepository,
            AgingDirection agingDirection,
            int numberOfBuckets,
            int organizationID)
        {
            if (finPeriodRepository == null)
            {
                throw new ArgumentNullException(nameof(finPeriodRepository));
            }
            if (numberOfBuckets <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(numberOfBuckets));
            }

            if (agingDirection == AgingDirection.Forward)
            {
                agingDirection = AgingDirection.Backwards;
                Utilities.Swap(ref currentDate, ref dateToAge);
            }

            if (dateToAge > currentDate)
            {
                return(0);
            }

            int bucketNumber = finPeriodRepository
                               .PeriodsBetweenInclusive(dateToAge, currentDate, organizationID)
                               .Count();

            --bucketNumber;

            if (bucketNumber < 0)
            {
                // No financial periods found between the dates,
                // cannot proceed with aging.
                // -
                throw new PXException(GL.Messages.NoPeriodsDefined);
            }

            if (bucketNumber > numberOfBuckets - 1)
            {
                // Force into the last ("over") aging bucket.
                // -
                bucketNumber = numberOfBuckets - 1;
            }

            return(bucketNumber);
        }
コード例 #6
0
        /// <param name="roundingFunction">
        /// The function that should be used for rounding transaction amounts.
        /// </param>
        /// <param name="isDraft">
        /// Indicates whether the schedule to be created or reevaluated is a draft schedule.
        /// In particular, it affects whether credit line / deferral transactions would be
        /// generated for the schedule.
        /// </param>
        public SingleScheduleCreator(
            IDREntityStorage drEntityStorage,
            ISubaccountProvider subaccountProvider,
            IBusinessAccountProvider businessAccountProvider,
            IInventoryItemProvider inventoryItemProvider,
            IFinPeriodRepository finPeriodRepository,
            Func <decimal, decimal> roundingFunction,
            int?branchID,
            bool isDraft,
            Location location,
            CurrencyInfo currencyInfo)
        {
            if (drEntityStorage == null)
            {
                throw new ArgumentNullException(nameof(drEntityStorage));
            }
            if (subaccountProvider == null)
            {
                throw new ArgumentNullException(nameof(subaccountProvider));
            }
            if (businessAccountProvider == null)
            {
                throw new ArgumentNullException(nameof(businessAccountProvider));
            }
            if (inventoryItemProvider == null)
            {
                throw new ArgumentNullException(nameof(inventoryItemProvider));
            }
            if (roundingFunction == null)
            {
                throw new ArgumentNullException(nameof(roundingFunction));
            }

            FinPeriodRepository = finPeriodRepository;

            _drEntityStorage         = drEntityStorage;
            _subaccountProvider      = subaccountProvider;
            _businessAccountProvider = businessAccountProvider;
            _inventoryItemProvider   = inventoryItemProvider;

            _roundingFunction = roundingFunction;

            _isDraft      = isDraft;
            _branchID     = branchID;
            _location     = location;
            _currencyInfo = currencyInfo;
        }
コード例 #7
0
        public (int firstYear, int lastYear) GetFirstLastYearForGeneration(int?organizationID, int fromYear, int toYear, bool clearQueryCache = false)
        {
            IFinPeriodRepository finPeriodRepository = Graph.GetService <IFinPeriodRepository>();


            int?firstExistingYear = int.TryParse(finPeriodRepository.FindFirstYear(organizationID ?? 0, clearQueryCache)?.Year, out int parsedFirstExistingYear)
                                ? parsedFirstExistingYear
                                : (int?)null;
            int?lastExistingYear = int.TryParse(finPeriodRepository.FindLastYear(organizationID ?? 0, clearQueryCache)?.Year, out int parsedLastExistingYear)
                                ? parsedLastExistingYear
                                : (int?)null;

            int lastYear  = lastExistingYear ?? fromYear - 1;
            int firstYear = firstExistingYear ?? fromYear - 1;

            return(firstYear, lastYear);
        }
コード例 #8
0
        public virtual OrganizationFinPeriod GetNearestOpenOrganizationMappedFABookPeriodInSubledger <TClosedInSubledgerField>(int?bookID, int?sourceBranchID, string sourcefinPeriodID, int?targetBranchID)
            where TClosedInSubledgerField : IBqlField
        {
            if (!FABookPeriodRepositoryHelper.IsPostingFABook(bookID))
            {
                return(null);
            }

            IFinPeriodUtils         finPeriodUtils         = Graph.GetService <IFinPeriodUtils>();
            IFinPeriodRepository    finPeriodRepository    = Graph.GetService <IFinPeriodRepository>();
            IFABookPeriodRepository faBookPeriodRepository = Graph.GetService <IFABookPeriodRepository>();

            int?sourceOrganizationID = PXAccess.GetParentOrganizationID(sourceBranchID);
            int?targetOrganizationID = PXAccess.GetParentOrganizationID(targetBranchID);

            // Mapped book period - first way:
            // FABookPeriod of sourceBranchID -> master book Period -> FABookPeriod of targetBranchID
            //
            ProcessingResult <FABookPeriod> targetFABookPeriod = faBookPeriodRepository.FindMappedFABookPeriod(
                bookID,
                sourceOrganizationID,
                sourcefinPeriodID,
                targetOrganizationID);

            // Mapped book period - second way:
            // finPeriodID of sourceBranchID -> masterFinPeriod -> FinPeriodID of targetBranchID -> FABookPeriod of targetBranchID
            //
            if (targetFABookPeriod.Result == null)
            {
                ProcessingResult <FABookPeriod> targetFABookPeriodSecondWay = faBookPeriodRepository.FindMappedFABookPeriodUsingFinPeriod(
                    bookID,
                    sourceOrganizationID,
                    sourcefinPeriodID,
                    targetOrganizationID);

                targetFABookPeriodSecondWay.RaiseIfHasError();

                targetFABookPeriod = targetFABookPeriodSecondWay;
            }

            OrganizationFinPeriod period = finPeriodUtils.GetNearestOpenOrganizationFinPeriodInSubledger <TClosedInSubledgerField>(targetFABookPeriod.ThisOrRaiseIfHasError().Result);

            return(period);
        }
コード例 #9
0
        /// <param name="roundingFunction">
        /// An optional parameter specifying a function that would be used to round
        /// the calculated transaction amounts. If <c>null</c>, the generator will use
        /// <see cref="PXDBCurrencyAttribute.BaseRound(PXGraph, decimal)"/> by default.
        /// </param>
        /// <param name="financialPeriodProvider">
        /// An optional parameter specifying an object that would be used to manipulate
        /// financial periods, e.g. extract a start date or an end date for a given period ID.
        /// If <c>null</c>, the generator will use <see cref="FinancialPeriodProvider.Default"/>.
        /// </param>
        public TransactionsGenerator(
            PXGraph graph,
            DRDeferredCode code,
            IFinPeriodRepository finPeriodRepository = null,
            Func <decimal, decimal> roundingFunction = null)
        {
            if (graph == null)
            {
                throw new ArgumentNullException(nameof(graph));
            }
            if (code == null)
            {
                throw new ArgumentNullException(nameof(code));
            }

            _graph               = graph;
            _code                = code;
            _roundingFunction    = roundingFunction ?? (rawAmount => PXDBCurrencyAttribute.BaseRound(_graph, rawAmount));
            _finPeriodRepository = finPeriodRepository ?? _graph.GetService <IFinPeriodRepository>();
        }
コード例 #10
0
        /// <summary>
        /// Retrieves the first financial period of the year corresponding
        /// to the financial period specified.
        /// If no such period exists, returns <c>null</c>.
        /// </summary>
        public string GetFirstPeriodOfYear(string financialPeriodID)
        {
            if (financialPeriodID == null)
            {
                return(null);
            }

            PXGraph graph = PXGraph.CreateInstance <MasterFinPeriodMaint>();

            string firstPeriodOfYear = FinPeriodUtils.GetFirstFinPeriodIDOfYear(financialPeriodID);

            IFinPeriodRepository finPeriodRepository = graph.GetService <IFinPeriodRepository>();

            if (!finPeriodRepository.PeriodExists(financialPeriodID, FinPeriod.organizationID.MasterValue))
            {
                return(null);
            }

            return(FinPeriodIDFormattingAttribute.FormatForDisplay(firstPeriodOfYear));
        }
コード例 #11
0
 public SingleScheduleCreator(
     IDREntityStorage drEntityStorage,
     ISubaccountProvider subaccountProvider,
     IBusinessAccountProvider businessAccountProvider,
     IInventoryItemProvider inventoryItemProvider,
     ISingleScheduleViewProvider singleScheduleViewProvider,
     ISalesPriceProvider salesPriceProvider,
     IDRDataProvider dataProvider,
     IFinPeriodRepository finPeriodRepository,
     Func <decimal, decimal> roundingFunction,
     int?branchID,
     bool isDraft,
     Location location,
     CurrencyInfo currencyInfo)
     : this(drEntityStorage, subaccountProvider, businessAccountProvider, inventoryItemProvider, finPeriodRepository, roundingFunction, branchID, isDraft, location, currencyInfo)
 {
     _salesPriceProvider         = salesPriceProvider ?? throw new ArgumentNullException(nameof(salesPriceProvider));
     _singleScheduleViewProvider = singleScheduleViewProvider ?? throw new ArgumentNullException(nameof(singleScheduleViewProvider));
     _dataProvider = dataProvider ?? throw new ArgumentNullException(nameof(dataProvider));
 }
コード例 #12
0
        public virtual ProcessingResult <FABookPeriod> FindMappedFABookPeriodUsingFinPeriod(int?bookID, int?sourceOrganizationID, string sourcefinPeriodID, int?targetOrganizationID)
        {
            IFinPeriodRepository finPeriodRepository = Graph.GetService <IFinPeriodRepository>();

            string       targetFinPeriodID  = finPeriodRepository.GetMappedPeriod(sourceOrganizationID, sourcefinPeriodID, targetOrganizationID)?.FinPeriodID;
            FABookPeriod targetFABookPeriod = FindByKey(bookID, targetOrganizationID, targetFinPeriodID);

            ProcessingResult <FABookPeriod> result = ProcessingResult <FABookPeriod> .CreateSuccess(targetFABookPeriod);

            if (targetFABookPeriod == null)
            {
                string errorMessage = PXMessages.LocalizeFormat(
                    Messages.PeriodDoesNotExistForBookAndCompany,
                    PeriodIDAttribute.FormatForError(sourcefinPeriodID),
                    FindFABook(bookID).BookCode,
                    PXAccess.GetOrganizationCD(sourceOrganizationID));

                result.AddErrorMessage(errorMessage);
            }

            return(result);
        }
コード例 #13
0
        /// <summary>
        /// Retrieves the financial period with the same <see cref="MasterFinPeriod.PeriodNbr"/>
        /// as the one specified, but residing in the previous financial year.
        /// If no such period exists, returns <c>null</c>.
        /// </summary>
        public string GetSamePeriodInPreviousYear(string financialPeriodID)
        {
            if (financialPeriodID == null)
            {
                return(null);
            }

            PXGraph graph = PXGraph.CreateInstance <MasterFinPeriodMaint>();

            try
            {
                IFinPeriodRepository finPeriodRepository = graph.GetService <IFinPeriodRepository>();

                string resultingPeriodID = finPeriodRepository.GetSamePeriodInPreviousYear(financialPeriodID, FinPeriod.organizationID.MasterValue);

                return(FinPeriodIDFormattingAttribute.FormatForDisplay(resultingPeriodID));
            }
            catch (PXFinPeriodException)
            {
                return(null);
            }
        }
コード例 #14
0
 public Scheduler(PXGraph graph, IFinPeriodRepository finPeriodRepository = null)
 {
     _graph = graph;
     _finPeriodRepository = finPeriodRepository ?? Cached.GetValue(ref _finPeriodRepository, _graph.GetService <IFinPeriodRepository>);
 }
コード例 #15
0
 public static IEnumerable <string> GetPeriodAgingBucketDescriptions(
     IFinPeriodRepository finPeriodRepository,
     DateTime currentDate,
     AgingDirection agingDirection,
     int numberOfBuckets) =>
 GetPeriodAgingBucketDescriptions(finPeriodRepository, currentDate, agingDirection, numberOfBuckets, FinPeriod.organizationID.MasterValue, true);
コード例 #16
0
ファイル: Scheduler.cs プロジェクト: Vialythen/AcumaticaTest
 public Scheduler(PXGraph graph, IFinPeriodRepository finPeriodRepository = null)
 {
     _graph = graph;
     _finPeriodRepository = finPeriodRepository ?? _graph.GetService <IFinPeriodRepository>();
 }