Exemple #1
0
        protected virtual void FATran_FinPeriodID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            FATran tran = (FATran)e.Row;

            if (tran == null || tran.AssetID == null || tran.BookID == null)
            {
                return;
            }

            try
            {
                FABookPeriod p = PXSelect <FABookPeriod,
                                           Where <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >,
                                                  And <FABookPeriod.finPeriodID, Equal <Required <FABookPeriod.finPeriodID> > > > > .Select(this, tran.BookID, (string)e.NewValue);

                if (p == null)
                {
                    throw new PXSetPropertyException(Messages.NoPeriodsDefined);
                }

                FABookBalance bal = PXSelect <FABookBalance,
                                              Where <FABookBalance.assetID, Equal <Required <FABookBalance.assetID> >,
                                                     And <FABookBalance.bookID, Equal <Required <FABookBalance.bookID> > > > > .Select(this, tran.AssetID, tran.BookID);


                if ((tran.TranType == FATran.tranType.DepreciationPlus || tran.TranType == FATran.tranType.DepreciationMinus) && tran.Origin == FARegister.origin.Adjustment)
                {
                    if (!string.IsNullOrEmpty(bal.CurrDeprPeriod) && String.Compare((string)e.NewValue, bal.CurrDeprPeriod) >= 0)
                    {
                        throw new PXSetPropertyException(CS.Messages.Entry_LT, FinPeriodIDFormattingAttribute.FormatForError(bal.CurrDeprPeriod));
                    }
                    if (!string.IsNullOrEmpty(bal.LastDeprPeriod) && String.Compare((string)e.NewValue, bal.LastDeprPeriod) > 0)
                    {
                        throw new PXSetPropertyException(CS.Messages.Entry_LE, FinPeriodIDFormattingAttribute.FormatForError(bal.LastDeprPeriod));
                    }
                }
            }
            catch (PXSetPropertyException)
            {
                e.NewValue = FinPeriodSelectorAttribute.FormatForDisplay((string)e.NewValue);
                throw;
            }
        }