Example #1
0
        protected virtual void DRScheduleDetail_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
        {
            DRScheduleDetail row = e.Row as DRScheduleDetail;

            if (row != null && Schedule.Current != null)
            {
                row.Status     = DRScheduleStatus.Draft;
                row.IsCustom   = true;
                row.ScheduleID = Schedule.Current.ScheduleID;
                SyncProperties(Schedule.Current, row);


                if (row.ComponentID == null)
                {
                    row.ComponentID = DRScheduleDetail.EmptyComponentID;
                }
            }

            InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <DRScheduleDetail.componentID> > > > .Select(this, row.ComponentID);

            if (item != null)
            {
                row.AccountID = row.Module == BatchModule.AP ? item.COGSAcctID : item.SalesAcctID;
                row.SubID     = row.Module == BatchModule.AP ? item.COGSSubID : item.SalesSubID;

                DRDeferredCode defCode = PXSelect <DRDeferredCode, Where <DRDeferredCode.deferredCodeID, Equal <Required <DRScheduleDetail.defCode> > > > .Select(this, item.DeferredCode);

                if (defCode != null)
                {
                    row.DefCode   = defCode.DeferredCodeID;
                    row.DefAcctID = defCode.AccountID;
                    row.DefSubID  = defCode.SubID;
                }
            }
        }
Example #2
0
        protected virtual void DRScheduleDetail_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            DRScheduleDetail row = e.Row as DRScheduleDetail;

            if (row != null)
            {
                Delete.SetEnabled(false);
                row.DocumentType = DRScheduleDocumentType.BuildDocumentType(row.Module, row.DocType);

                release.SetVisible(row.IsCustom == true);
                release.SetEnabled(false);

                row.DefTotal = SumOpenAndProjectedTransactions(row);
                PXUIFieldAttribute.SetEnabled <DRScheduleDetail.componentID>(sender, row, row.ComponentID != DRScheduleDetail.EmptyComponentID);
                if (row.Status == DRScheduleStatus.Draft)
                {
                    release.SetEnabled(true);
                    Delete.SetEnabled(true);
                }



                Transactions.Cache.AllowInsert = row.Status != DRScheduleStatus.Closed;
                Transactions.Cache.AllowUpdate = row.Status != DRScheduleStatus.Closed;
                Transactions.Cache.AllowDelete = row.Status != DRScheduleStatus.Closed;
            }
        }
Example #3
0
        /// <summary>
        /// If applicable, creates a single related transaction for all original posted transactions
        /// whose recognition date is earlier than (or equal to) the current document date.
        /// Does not set any amounts.
        /// </summary>
        /// <param name="transactionList">
        /// Transaction list where the new transaction will be put (if created).
        /// </param>
        /// <param name="lineCounter">
        /// Transaction line counter. Will be incremented if any transactions are created by this procedure.
        /// </param>
        private void AddRelatedTransactionForPostedBeforeDocumentDate(
            IList <DRScheduleTran> transactionList,
            DRScheduleDetail relatedScheduleDetail,
            IEnumerable <DRScheduleTran> originalPostedTransactions,
            int?branchID,
            ref short lineCounter)
        {
            IEnumerable <DRScheduleTran> originalTransactionsPostedBeforeDocumentDate =
                originalPostedTransactions.Where(transaction => transaction.RecDate <= relatedScheduleDetail.DocDate);

            if (originalTransactionsPostedBeforeDocumentDate.Any())
            {
                ++lineCounter;

                DRScheduleTran relatedTransaction = new DRScheduleTran
                {
                    BranchID    = branchID,
                    AccountID   = relatedScheduleDetail.AccountID,
                    SubID       = relatedScheduleDetail.SubID,
                    RecDate     = relatedScheduleDetail.DocDate,
                    FinPeriodID = relatedScheduleDetail.FinPeriodID,
                    LineNbr     = lineCounter,
                    ScheduleID  = relatedScheduleDetail.ScheduleID,
                    ComponentID = relatedScheduleDetail.ComponentID,
                    Status      = DRScheduleTranStatus.Open
                };

                transactionList.Add(relatedTransaction);
            }
        }
Example #4
0
        private void AddComponentScheduleDetail(
            INComponent inventoryItemComponent,
            DRDeferredCode componentDeferralCode,
            InventoryItem inventoryItem,
            decimal amount,
            DRProcess.DRScheduleParameters tranInfo,
            int?overridenSubID)
        {
            if (amount == 0m)
            {
                return;
            }

            DRScheduleDetail scheduleDetail = InsertScheduleDetail(
                inventoryItem.InventoryID,
                componentDeferralCode,
                amount,
                GetDeferralAccountSubaccount(componentDeferralCode, inventoryItem, tranInfo),
                GetSalesOrExpenseAccountSubaccount(inventoryItemComponent, inventoryItem),
                overridenSubID);

            if (!_isDraft)
            {
                IEnumerable <DRScheduleTran> deferralTransactions
                    = _drEntityStorage.CreateDeferralTransactions(_schedule, scheduleDetail, componentDeferralCode, _branchID);

                _drEntityStorage.NonDraftDeferralTransactionsPrepared(scheduleDetail, componentDeferralCode, deferralTransactions);
            }
        }
Example #5
0
        protected virtual void DRScheduleDetail_DocumentType_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            DRScheduleDetail row = e.Row as DRScheduleDetail;

            if (row != null)
            {
                string newModule = DRScheduleDocumentType.ExtractModule(row.DocumentType);
                row.DocType = DRScheduleDocumentType.ExtractDocType(row.DocumentType);

                if (row.Module != newModule)
                {
                    row.Module     = newModule;
                    row.DefCode    = null;
                    row.DefAcctID  = null;
                    row.DefSubID   = null;
                    row.BAccountID = null;
                    row.AccountID  = null;
                    row.SubID      = null;

                    InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <DRScheduleDetail.componentID> > > > .Select(this, row.ComponentID);

                    if (item != null)
                    {
                        row.AccountID = row.Module == BatchModule.AP ? item.COGSAcctID : item.SalesAcctID;
                        row.SubID     = row.Module == BatchModule.AP ? item.COGSSubID : item.SalesSubID;
                    }
                }

                row.RefNbr = null;
            }
        }
Example #6
0
        protected virtual void DRScheduleDetail_ScheduleID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            DRScheduleDetail row = e.Row as DRScheduleDetail;

            if (row != null)
            {
                e.Cancel = true;
            }
        }
Example #7
0
        protected virtual void DRScheduleDetail_DocDate_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            DRScheduleDetail row = e.Row as DRScheduleDetail;

            if (row != null)
            {
                e.NewValue = Accessinfo.BusinessDate;
            }
        }
Example #8
0
        protected virtual void DRScheduleDetail_TotalAmt_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            DRScheduleDetail row = e.Row as DRScheduleDetail;

            if (row != null && row.Status == DRScheduleStatus.Draft)
            {
                row.DefAmt = row.TotalAmt;
            }
        }
Example #9
0
        /// <summary>
        /// Tries to perform a redirect to the original AR or AP document of a given
        /// <see cref="DRScheduleDetail"/>.
        /// </summary>
        /// <param name="sourceGraph">
        /// A graph through which the redirect will be processed.
        /// </param>
        /// <param name="scheduleDetail">
        /// The <see cref="DRScheduleDetail"/> object containing the document type and
        /// document reference number necessary for the redirect.
        /// </param>
        public static void NavigateToOriginalDocument(
            PXGraph sourceGraph,
            DRScheduleDetail scheduleDetail)
        {
            DRSchedule correspondingSchedule = PXSelect <
                DRSchedule,
                Where <DRSchedule.scheduleID, Equal <Required <DRScheduleDetail.scheduleID> > > >
                                               .Select(sourceGraph, scheduleDetail.ScheduleID);

            NavigateToOriginalDocument(sourceGraph, correspondingSchedule);
        }
Example #10
0
 private static void SyncProperties(DRSchedule row, DRScheduleDetail detail)
 {
     detail.Module       = row.Module;
     detail.DocumentType = row.DocumentType;
     detail.DocType      = row.DocType;
     detail.RefNbr       = row.RefNbr;
     detail.LineNbr      = row.LineNbr;
     detail.BAccountID   = row.BAccountID;
     detail.FinPeriodID  = row.FinPeriodID;
     detail.DocDate      = row.DocDate;
 }
        public static void ReleaseCustomSchedule(DRScheduleDetail item)
        {
            ScheduleMaint maint = PXGraph.CreateInstance <ScheduleMaint>();

            maint.Clear();
            maint.Document.Current = PXSelect <DR.DRScheduleDetail,
                                               Where <DR.DRScheduleDetail.scheduleID, Equal <Required <DR.DRScheduleDetail.scheduleID> >,
                                                      And <DR.DRScheduleDetail.componentID, Equal <Required <DR.DRScheduleDetail.componentID> > > > > .Select(maint, item.ScheduleID, item.ComponentID);

            maint.ReleaseCustomSchedule();
        }
Example #12
0
        /// <summary>
        /// For a given schedule detail, reevaluates deferral transactions
        /// if they exist, otherwise, creates them anew.
        /// </summary>
        private void ReevaluateOrCreateTransactions(DRScheduleDetail scheduleDetail)
        {
            DRDeferredCode detailDeferralCode = _drEntityStorage.GetDeferralCode(scheduleDetail.DefCode);

            IList <DRScheduleTran> transactionList =
                _drEntityStorage.GetDeferralTransactions(scheduleDetail.ScheduleID, scheduleDetail.ComponentID);

            if (!transactionList.Any() && !_isDraft)
            {
                _drEntityStorage.CreateDeferralTransactions(_schedule, scheduleDetail, detailDeferralCode, _branchID);
            }
            else
            {
                decimal?totalTransactionAmount = transactionList.Sum(transaction => transaction.Amount);

                if (totalTransactionAmount != scheduleDetail.TotalAmt)
                {
                    if (transactionList.IsSingleElement())
                    {
                        UpdateTransactionAmount(
                            scheduleDetail,
                            detailDeferralCode,
                            transactionList.Single(),
                            scheduleDetail.TotalAmt);
                    }
                    else if (transactionList.HasAtLeastTwoItems())
                    {
                        decimal correctedTotal = 0;

                        transactionList.SkipLast(1).ForEach(transaction =>
                        {
                            decimal correctedAmountRaw = transaction.Amount.Value * scheduleDetail.TotalAmt.Value / totalTransactionAmount.Value;
                            decimal correctedAmount    = _roundingFunction(correctedAmountRaw);

                            correctedTotal += correctedAmount;

                            UpdateTransactionAmount(
                                scheduleDetail,
                                detailDeferralCode,
                                transaction,
                                correctedAmount);
                        });

                        UpdateTransactionAmount(
                            scheduleDetail,
                            detailDeferralCode,
                            transactionList.Last(),
                            scheduleDetail.TotalAmt - correctedTotal);
                    }
                }
            }
        }
Example #13
0
        private DRScheduleDetail InsertScheduleDetail(
            int?componentID,
            DRDeferredCode defCode,
            decimal amount,
            AccountSubaccountPair deferralAccountSubaccount,
            AccountSubaccountPair salesOrExpenseAccountSubaccount,
            int?overridenSubID = null)
        {
            FinPeriod detailFinPeriod = FinPeriodRepository
                                        .GetFinPeriodByMasterPeriodID(PXAccess.GetParentOrganizationID(_branchID),
                                                                      _schedule.FinPeriodID).GetValueOrRaiseError();

            DRScheduleDetail scheduleDetail = new DRScheduleDetail
            {
                ScheduleID    = _schedule.ScheduleID,
                BranchID      = _branchID,
                ComponentID   = componentID,
                CuryTotalAmt  = amount,
                CuryDefAmt    = amount,
                DefCode       = defCode.DeferredCodeID,
                Status        = _isDraft ? DRScheduleStatus.Draft : DRScheduleStatus.Open,
                IsCustom      = false,
                IsOpen        = true,
                Module        = _schedule.Module,
                DocType       = _schedule.DocType,
                RefNbr        = _schedule.RefNbr,
                LineNbr       = _schedule.LineNbr,
                FinPeriodID   = detailFinPeriod.FinPeriodID,
                TranPeriodID  = detailFinPeriod.MasterFinPeriodID,
                BAccountID    = _schedule.BAccountID,
                AccountID     = salesOrExpenseAccountSubaccount.AccountID,
                SubID         = overridenSubID ?? salesOrExpenseAccountSubaccount.SubID,
                DefAcctID     = deferralAccountSubaccount.AccountID,
                DefSubID      = deferralAccountSubaccount.SubID,
                CreditLineNbr = 0,
                DocDate       = _schedule.DocDate,
                BAccountType  =
                    _schedule.Module == BatchModule.AP
                                                ? BAccountType.VendorType
                                                : BAccountType.CustomerType,
            };

            scheduleDetail = _drEntityStorage.Insert(scheduleDetail);

            if (!_isDraft)
            {
                _drEntityStorage.CreateCreditLineTransaction(scheduleDetail, defCode, _branchID);
            }

            return(scheduleDetail);
        }
Example #14
0
        private decimal SumOpenAndProjectedTransactions(DRScheduleDetail row)
        {
            decimal total = 0;

            foreach (DRScheduleTran tran in OpenTransactions.View.SelectMultiBound(new object[] { row }))
            {
                total += tran.Amount.Value;
            }

            foreach (DRScheduleTran tran in ProjectedTransactions.View.SelectMultiBound(new object[] { row }))
            {
                total += tran.Amount.Value;
            }

            return(total);
        }
Example #15
0
        /// <summary>
        /// Updates the transaction amount and performs the callback to
        /// <see cref="IDREntityStorage"/>, notifying about the update.
        /// </summary>
        private void UpdateTransactionAmount(
            DRScheduleDetail scheduleDetail,
            DRDeferredCode detailDeferralCode,
            DRScheduleTran transaction,
            decimal?newAmount)
        {
            DRScheduleTran oldTransaction = _drEntityStorage.CreateCopy(transaction);

            transaction.Amount = newAmount;

            _drEntityStorage.ScheduleTransactionModified(
                scheduleDetail,
                detailDeferralCode,
                oldTransaction,
                transaction);
        }
Example #16
0
        protected virtual void DRScheduleDetail_DefCode_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            DRScheduleDetail row = e.Row as DRScheduleDetail;

            if (row != null)
            {
                DRDeferredCode defCode = PXSelect <DRDeferredCode, Where <DRDeferredCode.deferredCodeID, Equal <Required <DRScheduleDetail.defCode> > > > .Select(this, row.DefCode);

                if (defCode != null)
                {
                    row.DefCode   = defCode.DeferredCodeID;
                    row.DefAcctID = defCode.AccountID;
                    row.DefSubID  = defCode.SubID;
                }
            }
        }
Example #17
0
        protected virtual void DRScheduleDetail_RowInserting(PXCache sender, PXRowInsertingEventArgs e, PXRowInserting baseDelegate)
        {
            if (Base.Schedule.Current?.Module == BatchModule.AP)
            {
                baseDelegate.Invoke(sender, e);
            }

            DRScheduleDetail scheduleDetail = e.Row as DRScheduleDetail;

            if (scheduleDetail == null || Base.Schedule.Current == null)
            {
                return;
            }

            scheduleDetail.ComponentID = scheduleDetail.ComponentID ?? DRScheduleDetail.EmptyComponentID;
            scheduleDetail.ScheduleID  = Base.Schedule.Current.ScheduleID;
        }
        public static void SetFairValueSalesPrice(DRSchedule schedule, DRScheduleDetail scheduleDetail, PXSelectBase <DRScheduleDetail> scheduleDetailsView, Location location, CurrencyInfo currencyInfo, bool takeInBaseCurrency)
        {
            if (takeInBaseCurrency)
            {
                currencyInfo.CuryID = currencyInfo.BaseCuryID;
            }

            var salesPriceItem = ARSalesPriceMaint.CalculateFairValueSalesPrice(scheduleDetailsView.Cache,
                                                                                location?.CPriceClassID,
                                                                                schedule.BAccountID,
                                                                                scheduleDetail.ComponentID,
                                                                                currencyInfo,
                                                                                scheduleDetail.Qty,
                                                                                scheduleDetail.UOM,
                                                                                schedule.DocDate.Value,
                                                                                takeInBaseCurrency);

            var newValue = salesPriceItem.Price;

            if (newValue == 0m)
            {
                InventoryItem inventoryItem = PXSelect <
                    InventoryItem,
                    Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > >
                                              .Select(scheduleDetailsView.Cache.Graph, scheduleDetail.ComponentID);

                if (scheduleDetail.ParentInventoryID == null)
                {
                    throw new NoFairValuePriceFoundException(inventoryItem.InventoryCD, scheduleDetail.UOM, currencyInfo.CuryID, schedule.DocDate.Value);
                }
                else
                {
                    InventoryItem parentInventoryItem = PXSelect <
                        InventoryItem,
                        Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > >
                                                        .Select(scheduleDetailsView.Cache.Graph, scheduleDetail.ParentInventoryID);

                    throw new NoFairValuePriceFoundException(inventoryItem.InventoryCD, parentInventoryItem.InventoryCD, scheduleDetail.UOM, currencyInfo.CuryID, schedule.DocDate.Value);
                }
            }

            scheduleDetail.FairValueCuryID         = salesPriceItem.CuryID;
            scheduleDetail.FairValuePrice          = newValue;
            scheduleDetail.EffectiveFairValuePrice = newValue * (salesPriceItem.Prorated ? scheduleDetail.CoTermRate : 1);
        }
Example #19
0
        /// <summary>
        /// For a given schedule detail, reevaluates deferral transactions if they exist.
        /// </summary>
        private void ReevaluateTransactionAmounts(
            DRScheduleDetail scheduleComponent,
            DRDeferredCode componentDeferralCode,
            IEnumerable <DRScheduleTran> componentTransactions)
        {
            decimal?totalTransactionAmount = componentTransactions.Sum(transaction => transaction.Amount);

            if (totalTransactionAmount == scheduleComponent.CuryTotalAmt)
            {
                return;
            }

            if (componentTransactions.IsSingleElement())
            {
                UpdateTransactionAmount(
                    scheduleComponent,
                    componentDeferralCode,
                    componentTransactions.Single(),
                    scheduleComponent.CuryTotalAmt);
            }
            else if (componentTransactions.HasAtLeastTwoItems())
            {
                decimal correctedTotal = 0;

                componentTransactions.SkipLast(1).ForEach(transaction =>
                {
                    decimal correctedAmountRaw = transaction.Amount.Value * scheduleComponent.CuryTotalAmt.Value / totalTransactionAmount.Value;
                    decimal correctedAmount    = _roundingFunction(correctedAmountRaw);

                    correctedTotal += correctedAmount;

                    UpdateTransactionAmount(
                        scheduleComponent,
                        componentDeferralCode,
                        transaction,
                        correctedAmount);
                });

                UpdateTransactionAmount(
                    scheduleComponent,
                    componentDeferralCode,
                    componentTransactions.Last(),
                    scheduleComponent.CuryTotalAmt - correctedTotal);
            }
        }
Example #20
0
        private DRScheduleDetail InsertScheduleDetail(
            int?componentID,
            DRDeferredCode defCode,
            decimal amount,
            AccountSubaccountPair deferralAccountSubaccount,
            AccountSubaccountPair salesOrExpenseAccountSubaccount)
        {
            DRScheduleDetail scheduleDetail = new DRScheduleDetail
            {
                ScheduleID    = _schedule.ScheduleID,
                ComponentID   = componentID,
                TotalAmt      = amount,
                DefAmt        = amount,
                DefCode       = defCode.DeferredCodeID,
                Status        = _isDraft ? DRScheduleStatus.Draft : DRScheduleStatus.Open,
                IsCustom      = false,
                IsOpen        = true,
                Module        = _schedule.Module,
                DocType       = _schedule.DocType,
                RefNbr        = _schedule.RefNbr,
                LineNbr       = _schedule.LineNbr,
                FinPeriodID   = _schedule.FinPeriodID,
                BAccountID    = _schedule.BAccountID,
                AccountID     = salesOrExpenseAccountSubaccount.AccountID,
                SubID         = salesOrExpenseAccountSubaccount.SubID,
                DefAcctID     = deferralAccountSubaccount.AccountID,
                DefSubID      = deferralAccountSubaccount.SubID,
                CreditLineNbr = 0,
                DocDate       = _schedule.DocDate,
                BAccountType  =
                    _schedule.Module == BatchModule.AP
                                                ? BAccountType.VendorType
                                                : BAccountType.CustomerType,
            };

            scheduleDetail = _drEntityStorage.Insert(scheduleDetail);

            if (!_isDraft)
            {
                _drEntityStorage.CreateCreditLineTransaction(scheduleDetail, defCode, _branchID);
            }

            return(scheduleDetail);
        }
        /// <summary>
        /// Adds a related transaction for every original transaction
        /// in <paramref name="originalTransactions"/> using information
        /// from the provided related <see cref="DRScheduleDetail"/>.
        /// Does not set any transaction amounts.
        /// </summary>
        /// <param name="transactionList">
        /// Transaction list where the new transaction will be put (if created).
        /// </param>
        /// <param name="lineCounter">
        /// Transaction line counter. Will be incremented if any transactions are created by this procedure.
        /// </param>
        private void AddRelatedTransactions(
            IList <DRScheduleTran> transactionList,
            DRScheduleDetail relatedScheduleDetail,
            IEnumerable <DRScheduleTran> originalTransactions,
            int?branchID,
            ref short lineCounter)
        {
            int?organizationID = PXAccess.GetParentOrganizationID(branchID);

            foreach (DRScheduleTran originalTransaction in originalTransactions)
            {
                ++lineCounter;

                DRScheduleTran relatedTransaction = new DRScheduleTran
                {
                    BranchID      = branchID,
                    AccountID     = relatedScheduleDetail.AccountID,
                    SubID         = relatedScheduleDetail.SubID,
                    LineNbr       = lineCounter,
                    DetailLineNbr = relatedScheduleDetail.DetailLineNbr,
                    ScheduleID    = relatedScheduleDetail.ScheduleID,
                    ComponentID   = relatedScheduleDetail.ComponentID,
                    Status        = DRScheduleTranStatus.Open
                };

                var maxDate = originalTransaction.RecDate.Value < relatedScheduleDetail.DocDate.Value
                                        ? relatedScheduleDetail.DocDate
                                        : originalTransaction.RecDate;

                relatedTransaction.RecDate = maxDate;

                var maxPeriod = string.CompareOrdinal(originalTransaction.FinPeriodID, relatedScheduleDetail.FinPeriodID) < 0
                                        ? relatedScheduleDetail.FinPeriodID
                                        : originalTransaction.FinPeriodID;

                FinPeriod maxFinPeriod = _finPeriodRepository.GetByID(maxPeriod, organizationID);

                relatedTransaction.FinPeriodID  = maxFinPeriod.FinPeriodID;
                relatedTransaction.TranPeriodID = maxFinPeriod.MasterFinPeriodID;

                transactionList.Add(relatedTransaction);
            }
        }
Example #22
0
        private void CreateDetails(
            DRProcess.DRScheduleParameters scheduleParameters,
            DRDeferredCode deferralCode,
            InventoryItem inventoryItem,
            AccountSubaccountPair salesOrExpenseAccountSubaccount,
            decimal?transactionAmount,
            decimal?fairUnitPrice,
            decimal?compoundDiscountRate,
            decimal?quantityInBaseUnit)
        {
            if (deferralCode.MultiDeliverableArrangement == true && inventoryItem != null && inventoryItem.IsSplitted == true)
            {
                CreateDetailsForSplitted(
                    scheduleParameters,
                    inventoryItem,
                    salesOrExpenseAccountSubaccount.SubID,
                    transactionAmount,
                    fairUnitPrice,
                    compoundDiscountRate ?? 1.0m,
                    quantityInBaseUnit ?? 0.0m);
            }
            else
            {
                var deferralAccountSubaccount = GetDeferralAccountSubaccount(deferralCode, inventoryItem, scheduleParameters);

                int?componentID = inventoryItem == null ? DRScheduleDetail.EmptyComponentID : inventoryItem.InventoryID;

                DRScheduleDetail scheduleDetail = InsertScheduleDetail(
                    componentID,
                    deferralCode,
                    transactionAmount.Value,
                    deferralAccountSubaccount,
                    salesOrExpenseAccountSubaccount);

                if (!_isDraft)
                {
                    IEnumerable <DRScheduleTran> deferralTransactions =
                        _drEntityStorage.CreateDeferralTransactions(_schedule, scheduleDetail, deferralCode, _branchID);

                    _drEntityStorage.NonDraftDeferralTransactionsPrepared(scheduleDetail, deferralCode, deferralTransactions);
                }
            }
        }
Example #23
0
        protected virtual void DRScheduleDetail_BAccountID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            DRScheduleDetail row = e.Row as DRScheduleDetail;

            if (row != null)
            {
                if (row.ComponentID == null || row.ComponentID == DRScheduleDetail.EmptyComponentID || row.AccountID == null)
                {
                    switch (row.Module)
                    {
                    case BatchModule.AP:
                        PXResultset <Vendor> res = PXSelectJoin <Vendor,
                                                                 InnerJoin <Location, On <Vendor.bAccountID, Equal <Location.bAccountID>,
                                                                                          And <Vendor.defLocationID, Equal <Location.locationID> > > >,
                                                                 Where <Vendor.bAccountID, Equal <Current <DRScheduleDetail.bAccountID> > > > .Select(this);

                        Location loc = (Location)res[0][1];

                        if (loc.VExpenseAcctID != null)
                        {
                            row.AccountID = loc.VExpenseAcctID;
                            row.SubID     = loc.VExpenseSubID;
                        }
                        break;

                    case BatchModule.AR:
                        PXResultset <Customer> res2 = PXSelectJoin <Customer,
                                                                    InnerJoin <Location, On <Customer.bAccountID, Equal <Customer.bAccountID>,
                                                                                             And <Customer.defLocationID, Equal <Location.locationID> > > >,
                                                                    Where <Customer.bAccountID, Equal <Current <DRScheduleDetail.bAccountID> > > > .Select(this);

                        Location loc2 = (Location)res2[0][1];

                        if (loc2.CSalesAcctID != null)
                        {
                            row.AccountID = loc2.CSalesAcctID;
                            row.SubID     = loc2.CSalesSubID;
                        }
                        break;
                    }
                }
            }
        }
Example #24
0
        private void InsertResidualScheduleDetail(int?componentID, decimal amount, int?acctID, int?subID)
        {
            FinPeriod detailFinPeriod = FinPeriodRepository
                                        .GetFinPeriodByMasterPeriodID(PXAccess.GetParentOrganizationID(_branchID),
                                                                      _schedule.FinPeriodID).GetValueOrRaiseError();

            DRScheduleDetail residualScheduleDetail = new DRScheduleDetail
            {
                ScheduleID    = _schedule.ScheduleID,
                BranchID      = _branchID,
                ComponentID   = componentID,
                CuryTotalAmt  = amount,
                CuryDefAmt    = 0.0m,
                DefCode       = null,
                IsCustom      = false,
                IsResidual    = true,
                IsOpen        = false,
                Module        = _schedule.Module,
                DocType       = _schedule.DocType,
                RefNbr        = _schedule.RefNbr,
                LineNbr       = _schedule.LineNbr,
                FinPeriodID   = detailFinPeriod.FinPeriodID,
                TranPeriodID  = detailFinPeriod.MasterFinPeriodID,
                BAccountID    = _schedule.BAccountID,
                AccountID     = acctID,
                SubID         = subID,
                DefAcctID     = acctID,
                DefSubID      = subID,
                CreditLineNbr = 0,
                DocDate       = _schedule.DocDate,
                BAccountType  = _schedule.Module == BatchModule.AP ?
                                BAccountType.VendorType :
                                BAccountType.CustomerType,
                Status = _isDraft ?
                         DRScheduleStatus.Draft :
                         DRScheduleStatus.Closed,
            };

            residualScheduleDetail.CloseFinPeriodID = residualScheduleDetail.FinPeriodID;

            _drEntityStorage.Insert(residualScheduleDetail);
        }
Example #25
0
        public static void ReleaseCustomSchedule(DRScheduleDetail item)
        {
            ScheduleMaint maint = PXGraph.CreateInstance <ScheduleMaint>();

            var details = PXSelect <
                DRScheduleDetail,
                Where <DRScheduleDetail.scheduleID, Equal <Required <DRSchedule.scheduleID> >,
                       And <DRScheduleDetail.isResidual, Equal <False> > > >
                          .Select(maint, item.ScheduleID)
                          .RowCast <DRScheduleDetail>();

            maint.GetService <IFinPeriodUtils>().ValidateFinPeriod <DRScheduleDetail>(details, m => item.FinPeriodID, m => m.BranchID.SingleToArray());

            maint.Clear();
            maint.Document.Current = PXSelect <DR.DRScheduleDetail,
                                               Where <DR.DRScheduleDetail.scheduleID, Equal <Required <DR.DRScheduleDetail.scheduleID> >,
                                                      And <DR.DRScheduleDetail.componentID, Equal <Required <DR.DRScheduleDetail.componentID> > > > > .Select(maint, item.ScheduleID, item.ComponentID);

            maint.ReleaseCustomScheduleDetail();
        }
        protected virtual void ValidateTerms(DRScheduleDetail deferralDetail)
        {
            if (!DeferredMethodType.RequiresTerms(_code))
            {
                return;
            }

            if (!deferralDetail.TermStartDate.HasValue ||
                !deferralDetail.TermEndDate.HasValue)
            {
                throw new PXException(Messages.CannotGenerateTransactionsWithoutTerms);
            }

            if (deferralDetail.TermStartDate > deferralDetail.TermEndDate)
            {
                throw new PXException(
                          Messages.TermCantBeNegative,
                          deferralDetail.TermEndDate,
                          deferralDetail.TermStartDate);
            }
        }
        private void InsertResidualScheduleDetail(int?componentID, decimal amount, int?acctID, int?subID)
        {
            DRScheduleDetail residualScheduleDetail = new DRScheduleDetail
            {
                ScheduleID    = _schedule.ScheduleID,
                BranchID      = _branchID,
                ComponentID   = componentID,
                TotalAmt      = amount,
                DefAmt        = 0.0m,
                DefCode       = null,
                IsCustom      = false,
                IsResidual    = true,
                IsOpen        = false,
                Module        = _schedule.Module,
                DocType       = _schedule.DocType,
                RefNbr        = _schedule.RefNbr,
                LineNbr       = _schedule.LineNbr,
                FinPeriodID   = _schedule.FinPeriodID,
                BAccountID    = _schedule.BAccountID,
                AccountID     = acctID,
                SubID         = subID,
                DefAcctID     = acctID,
                DefSubID      = subID,
                CreditLineNbr = 0,
                DocDate       = _schedule.DocDate,
                BAccountType  = _schedule.Module == BatchModule.AP ?
                                BAccountType.VendorType :
                                BAccountType.CustomerType,
                Status = _isDraft ?
                         DRScheduleStatus.Draft :
                         DRScheduleStatus.Closed,
            };

            residualScheduleDetail.CloseFinPeriodID = residualScheduleDetail.FinPeriodID;

            _drEntityStorage.Insert(residualScheduleDetail);
        }
Example #28
0
        /// <summary>
        /// Adds a related transaction for every original transaction
        /// in <paramref name="originalTransactions"/> using information
        /// from the provided related <see cref="DRScheduleDetail"/>.
        /// Does not set any transaction amounts.
        /// </summary>
        /// <param name="transactionList">
        /// Transaction list where the new transaction will be put (if created).
        /// </param>
        /// <param name="lineCounter">
        /// Transaction line counter. Will be incremented if any transactions are created by this procedure.
        /// </param>
        private void AddRelatedTransactions(
            IList <DRScheduleTran> transactionList,
            DRScheduleDetail relatedScheduleDetail,
            IEnumerable <DRScheduleTran> originalTransactions,
            int?branchID,
            ref short lineCounter)
        {
            foreach (DRScheduleTran originalTransaction in originalTransactions)
            {
                ++lineCounter;

                DRScheduleTran relatedTransaction = new DRScheduleTran
                {
                    BranchID    = branchID,
                    AccountID   = relatedScheduleDetail.AccountID,
                    SubID       = relatedScheduleDetail.SubID,
                    LineNbr     = lineCounter,
                    ScheduleID  = relatedScheduleDetail.ScheduleID,
                    ComponentID = relatedScheduleDetail.ComponentID,
                    Status      = DRScheduleTranStatus.Open
                };

                var maxDate = originalTransaction.RecDate.Value < relatedScheduleDetail.DocDate.Value
                                        ? relatedScheduleDetail.DocDate
                                        : originalTransaction.RecDate;

                relatedTransaction.RecDate = maxDate;

                var maxPeriod = string.CompareOrdinal(originalTransaction.FinPeriodID, relatedScheduleDetail.FinPeriodID) < 0
                                        ? relatedScheduleDetail.FinPeriodID
                                        : originalTransaction.FinPeriodID;

                relatedTransaction.FinPeriodID = maxPeriod;

                transactionList.Add(relatedTransaction);
            }
        }
Example #29
0
        private void AddComponentScheduleDetail(
            INComponent inventoryItemComponent,
            DRDeferredCode componentDeferralCode,
            InventoryItem inventoryItem,
            decimal amount,
            DRProcess.DRScheduleParameters tranInfo)
        {
            if (amount == 0m)
            {
                return;
            }

            DRScheduleDetail scheduleDetail = InsertScheduleDetail(
                inventoryItem.InventoryID,
                componentDeferralCode,
                amount,
                GetDeferralAccountSubaccount(componentDeferralCode, inventoryItem, tranInfo),
                GetSalesOrExpenseAccountSubaccount(inventoryItemComponent, inventoryItem));

            if (!_isDraft)
            {
                _drEntityStorage.CreateDeferralTransactions(_schedule, scheduleDetail, componentDeferralCode, _branchID);
            }
        }
        protected virtual IEnumerable items()
        {
            ScheduleRecognitionFilter filter = Filter.Current;

            if (filter == null)
            {
                yield break;
            }
            bool found = false;

            foreach (ScheduledTran item in Items.Cache.Inserted)
            {
                found = true;
                yield return(item);
            }
            if (found)
            {
                yield break;
            }


            PXSelectBase <DRScheduleTran> select = new PXSelectJoin <DRScheduleTran,
                                                                     InnerJoin <DRScheduleDetail, On <DRScheduleTran.scheduleID, Equal <DRScheduleDetail.scheduleID>, And <DRScheduleTran.componentID, Equal <DRScheduleDetail.componentID> > >,
                                                                                InnerJoin <DRSchedule, On <DRScheduleTran.scheduleID, Equal <DRSchedule.scheduleID> >,
                                                                                           LeftJoin <InventoryItem, On <DRScheduleTran.componentID, Equal <InventoryItem.inventoryID> > > > >,
                                                                     Where <DRScheduleTran.recDate, LessEqual <Current <ScheduleRecognitionFilter.recDate> >,
                                                                            And <DRScheduleTran.status, Equal <DRScheduleTranStatus.OpenStatus>,
                                                                                 And <DRScheduleDetail.status, NotEqual <DRScheduleStatus.DraftStatus> > > >,
                                                                     OrderBy <Asc <DRScheduleTran.scheduleID, Asc <DRScheduleTran.componentID, Asc <DRScheduleTran.recDate, Asc <DRScheduleTran.lineNbr> > > > > >(this);

            if (!string.IsNullOrEmpty(filter.DeferredCode))
            {
                select.WhereAnd <Where <DRScheduleDetail.defCode, Equal <Current <ScheduleRecognitionFilter.deferredCode> > > >();
            }

            if (filter.BranchID != null)
            {
                select.WhereAnd <Where <DRScheduleDetail.branchID, Equal <Current <ScheduleRecognitionFilter.branchID> > > >();
            }

            Dictionary <string, string> added = new Dictionary <string, string>();

            foreach (PXResult <DRScheduleTran, DRScheduleDetail, DRSchedule, InventoryItem> resultSet in select.Select())
            {
                DRScheduleTran   tran           = (DRScheduleTran)resultSet;
                DRSchedule       schedule       = (DRSchedule)resultSet;
                DRScheduleDetail scheduleDetail = (DRScheduleDetail)resultSet;
                InventoryItem    item           = (InventoryItem)resultSet;

                string key = string.Format("{0}.{1}", tran.ScheduleID, tran.ComponentID);

                bool doInsert = false;

                if (added.ContainsKey(key))
                {
                    string addedFinPeriod = added[key];

                    if (tran.FinPeriodID == addedFinPeriod)
                    {
                        doInsert = true;
                    }
                }
                else
                {
                    doInsert = true;
                    added.Add(key, tran.FinPeriodID);
                }

                if (doInsert)
                {
                    ScheduledTran result = new ScheduledTran();
                    result.BranchID    = tran.BranchID;
                    result.AccountID   = tran.AccountID;
                    result.Amount      = tran.Amount;
                    result.ComponentID = tran.ComponentID;
                    result.DefCode     = scheduleDetail.DefCode;
                    result.FinPeriodID = tran.FinPeriodID;
                    result.LineNbr     = tran.LineNbr;
                    result.RecDate     = tran.RecDate;
                    result.ScheduleID  = tran.ScheduleID;
                    result.ScheduleNbr = schedule.ScheduleNbr;
                    result.SubID       = tran.SubID;
                    result.ComponentCD = item.InventoryCD;
                    result.DocType     = DRScheduleDocumentType.BuildDocumentType(scheduleDetail.Module, scheduleDetail.DocType);

                    Items.Cache.SetStatus(result, PXEntryStatus.Inserted);
                    yield return(result);                   // Items.Insert(result);
                }
            }


            //Virtual Records (CashReceipt):

            PXSelectBase <ARInvoice> s = null;

            if (!string.IsNullOrEmpty(filter.DeferredCode))
            {
                s = new PXSelectJoinGroupBy <ARInvoice,
                                             InnerJoin <ARTran, On <ARTran.tranType, Equal <ARInvoice.docType>,
                                                                    And <ARTran.refNbr, Equal <ARInvoice.refNbr> > >,
                                                        InnerJoin <DRDeferredCode, On <ARTran.deferredCode, Equal <DRDeferredCode.deferredCodeID>,
                                                                                       And <DRDeferredCode.method, Equal <DeferredMethodType.cashReceipt>,
                                                                                            And <DRDeferredCode.deferredCodeID, Equal <Current <ScheduleRecognitionFilter.deferredCode> > > > >,
                                                                   InnerJoin <DRSchedule, On <ARTran.tranType, Equal <DRSchedule.docType>,
                                                                                              And <ARTran.refNbr, Equal <DRSchedule.refNbr>,
                                                                                                   And <ARTran.lineNbr, Equal <DRSchedule.lineNbr> > > >,
                                                                              InnerJoin <DRScheduleDetail, On <DRSchedule.scheduleID, Equal <DRScheduleDetail.scheduleID> > > > > >,
                                             Where <ARInvoice.released, Equal <True>,
                                                    And <DRScheduleDetail.isOpen, Equal <True> > >,
                                             Aggregate <GroupBy <ARInvoice.docType, GroupBy <ARInvoice.refNbr> > > >(this);
            }
            else
            {
                s = new PXSelectJoinGroupBy <ARInvoice,
                                             InnerJoin <ARTran, On <ARTran.tranType, Equal <ARInvoice.docType>,
                                                                    And <ARTran.refNbr, Equal <ARInvoice.refNbr> > >,
                                                        InnerJoin <DRDeferredCode, On <ARTran.deferredCode, Equal <DRDeferredCode.deferredCodeID>,
                                                                                       And <DRDeferredCode.method, Equal <DeferredMethodType.cashReceipt> > >,
                                                                   InnerJoin <DRSchedule, On <ARTran.tranType, Equal <DRSchedule.docType>,
                                                                                              And <ARTran.refNbr, Equal <DRSchedule.refNbr>,
                                                                                                   And <ARTran.lineNbr, Equal <DRSchedule.lineNbr> > > >,
                                                                              InnerJoin <DRScheduleDetail, On <DRSchedule.scheduleID, Equal <DRScheduleDetail.scheduleID> > > > > >,
                                             Where <ARInvoice.released, Equal <True>,
                                                    And <DRScheduleDetail.isOpen, Equal <True> > >,
                                             Aggregate <GroupBy <ARInvoice.docType, GroupBy <ARInvoice.refNbr> > > >(this);
            }


            foreach (ARInvoice inv in s.Select())
            {
                PXSelectBase <ARTran> trs =
                    new PXSelectJoin <ARTran,
                                      InnerJoin <DRDeferredCode, On <ARTran.deferredCode, Equal <DRDeferredCode.deferredCodeID>,
                                                                     And <DRDeferredCode.method, Equal <DeferredMethodType.cashReceipt> > > >,
                                      Where <ARTran.tranType, Equal <Required <ARTran.tranType> >,
                                             And <ARTran.refNbr, Equal <Required <ARTran.refNbr> > > > >(this);

                foreach (PXResult <ARTran, DRDeferredCode> res in trs.Select(inv.DocType, inv.RefNbr))
                {
                    List <ScheduledTran> virtualRecords       = new List <ScheduledTran>();
                    List <ScheduledTran> virtualVoidedRecords = new List <ScheduledTran>();

                    ARTran         tr = (ARTran)res;
                    DRDeferredCode dc = (DRDeferredCode)res;

                    decimal trPart = 0;
                    if (inv.LineTotal.Value != 0)
                    {
                        trPart = tr.TranAmt.Value / inv.LineTotal.Value;
                    }
                    decimal trPartRest = tr.TranAmt.Value;

                    InventoryItem invItem = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, tr.InventoryID);

                    //NOTE: Multiple Components are not supported in CashReceipt Deferred Revenue Recognition.
                    DRSchedule       schedule       = GetScheduleByFID(BatchModule.AR, inv.DocType, inv.RefNbr, tr.LineNbr);
                    DRScheduleDetail scheduleDetail = GetScheduleDetailbyID(schedule.ScheduleID, tr.InventoryID != null ? tr.InventoryID : DRScheduleDetail.EmptyComponentID);
                    int lineNbr = scheduleDetail.LineCntr ?? 0;


                    PXSelectBase <ARAdjust> ads =
                        new PXSelectJoin <ARAdjust,
                                          LeftJoin <DRScheduleTran, On <ARAdjust.adjgDocType, Equal <DRScheduleTran.adjgDocType>,
                                                                        And <ARAdjust.adjgRefNbr, Equal <DRScheduleTran.adjgRefNbr> > > >,
                                          Where <ARAdjust.adjdDocType, Equal <Required <ARAdjust.adjdDocType> >,
                                                 And <ARAdjust.adjdRefNbr, Equal <Required <ARAdjust.adjdRefNbr> >,
                                                      And <DRScheduleTran.scheduleID, IsNull,
                                                           And <ARAdjust.adjgDocType, NotEqual <ARDocType.creditMemo> > > > >,
                                          OrderBy <Asc <ARAdjust.adjgDocDate> > >(this);

                    foreach (ARAdjust ad in ads.Select(inv.DocType, inv.RefNbr))
                    {
                        lineNbr++;
                        decimal amtRaw = Math.Min(trPart * ad.AdjAmt.Value, trPartRest);
                        trPartRest -= amtRaw;
                        decimal amt = PXDBCurrencyAttribute.BaseRound(this, amtRaw);

                        ScheduledTran result = new ScheduledTran();

                        result.BranchID    = ad.AdjgBranchID;
                        result.Amount      = amt;
                        result.ComponentID = tr.InventoryID;
                        result.DefCode     = tr.DeferredCode;
                        result.FinPeriodID = FinPeriodRepository.GetPeriodIDFromDate(ad.AdjgDocDate, PXAccess.GetParentOrganizationID(ad.AdjgBranchID));
                        result.LineNbr     = lineNbr;
                        result.Module      = schedule.Module;
                        result.RecDate     = ad.AdjgDocDate;
                        result.ScheduleID  = schedule.ScheduleID;
                        result.ScheduleNbr = schedule.ScheduleNbr;
                        result.DocType     = schedule.DocType;
                        result.AdjgDocType = ad.AdjgDocType;
                        result.AdjgRefNbr  = ad.AdjgRefNbr;
                        result.AdjNbr      = ad.AdjNbr;
                        result.IsVirtual   = true;
                        result.AccountID   = scheduleDetail.AccountID;
                        result.SubID       = scheduleDetail.SubID;
                        result.ComponentCD = invItem == null ? "" : invItem.InventoryCD;

                        if (ad.Voided == true)
                        {
                            if (ad.AdjgDocType == ARDocType.VoidPayment && virtualVoidedRecords.Count > 0)
                            {
                                ScheduledTran tran = virtualVoidedRecords.Where <ScheduledTran>(v => (v.AdjgDocType == ARDocType.Payment && v.AdjgRefNbr == ad.AdjgRefNbr && v.AdjNbr == ad.AdjNbr)).First <ScheduledTran>();
                                if (tran != null)
                                {
                                    virtualVoidedRecords.Remove(tran);
                                }
                            }
                            else
                            {
                                virtualVoidedRecords.Add(result);
                            }
                        }
                        else
                        {
                            virtualRecords.Add(result);
                        }
                    }

                    foreach (ScheduledTran v in virtualRecords)
                    {
                        Items.Cache.SetStatus(v, PXEntryStatus.Inserted);
                        yield return(v);                       // Items.Insert(v);
                    }

                    foreach (ScheduledTran v in virtualVoidedRecords)
                    {
                        Items.Cache.SetStatus(v, PXEntryStatus.Inserted);
                        yield return(v);                       // Items.Insert(v);
                    }
                }
            }


            Items.Cache.IsDirty = false;
        }