Ejemplo n.º 1
0
 public static bool ParseFiscalPeriodID(string fiscalPeriodID, out int year, out int periodNbr)
 {
     try
     {
         year      = int.Parse(FiscalPeriodUtils.FiscalYear(fiscalPeriodID));
         periodNbr = int.Parse(FiscalPeriodUtils.PeriodInYear(fiscalPeriodID));
     }
     catch (FormatException)
     {
         year      = -1;
         periodNbr = -1;
         return(false);
     }
     return(true);
 }
        protected virtual void AccountByYearFilter_RowInserted(PXCache cache, PXRowInsertedEventArgs e)
        {
            AccountByYearFilter filter = e.Row as AccountByYearFilter;

            if (filter != null)
            {
                if (filter.FinPeriodID != null && filter.FinPeriodID != "")
                {
                    filter.FinYear = FiscalPeriodUtils.FiscalYear(filter.FinPeriodID);                     //Fill year from finPeriodID
                }

                if (filter.FinYear == null || filter.FinYear == "")
                {
                    DateTime businessDate = this.Accessinfo.BusinessDate.Value;
                    filter.FinYear = businessDate.Year.ToString("0000");
                }
            }
        }
        protected virtual void GLAllocation_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
        {
            GLAllocation row = (GLAllocation)e.Row;

            if ((e.Operation & PXDBOperation.Command) != PXDBOperation.Delete)
            {
                if (row.Active == true && (this.Source.Select().Count == 0))
                {
                    throw new PXException(Messages.SourceAccountNotSpecified);
                }

                //In the case of external rule Distribution is defined dynamically in external table
                if (row.Active == true &&
                    row.AllocMethod != Constants.AllocationMethod.ByExternalRule &&
                    this.Destination.Select().Count == 0)
                {
                    throw new PXException(Messages.DestAccountNotSpecified);
                }

                if (row.StartFinPeriodID != null && row.EndFinPeriodID != null)
                {
                    int startYr, endYr;
                    int startNbr, endNbr;
                    if (!FiscalPeriodUtils.TryParse(row.StartFinPeriodID, out startYr, out startNbr))
                    {
                        cache.RaiseExceptionHandling <GLAllocation.startFinPeriodID>(e.Row, row.StartFinPeriodID, new PXSetPropertyException(Messages.AllocationStartPeriodHasIncorrectFormat));
                    }

                    if (!FiscalPeriodUtils.TryParse(row.EndFinPeriodID, out endYr, out endNbr))
                    {
                        cache.RaiseExceptionHandling <GLAllocation.endFinPeriodID>(e.Row, row.EndFinPeriodID, new PXSetPropertyException(Messages.AllocationEndPeriodHasIncorrectFormat));
                    }
                    bool isReversed = (endYr < startYr) || (endYr == startYr && startNbr > endNbr);
                    if (isReversed)
                    {
                        cache.RaiseExceptionHandling <GLAllocation.endFinPeriodID>(e.Row, row.EndFinPeriodID, new PXSetPropertyException(Messages.AllocationEndPeriodIsBeforeStartPeriod));
                    }
                }
                if (!this.ValidateSrcAccountsForCurrency())
                {
                    throw new PXException(Messages.AccountsNotInBaseCury);
                }

                GLAllocationSource src;
                if (!this.ValidateSrcAccountsForInterlacing(out src))
                {
                    this.Source.Cache.RaiseExceptionHandling <GLAllocationSource.accountCD>(src, src.AccountCD, new PXSetPropertyException(Messages.AllocationSourceAccountSubInterlacingDetected, PXErrorLevel.RowError));
                }

                if (row.Active == true &&
                    this.isWeigthRecalcRequired())
                {
                    decimal total = 0.00m;
                    GLAllocationDestination dest = null;
                    foreach (GLAllocationDestination iDest in this.Destination.Select())
                    {
                        if (iDest.Weight.HasValue)
                        {
                            total += iDest.Weight.Value;
                            decimal weight = (decimal)iDest.Weight.Value;
                            if (weight <= 0.00m || weight > 100.00m)
                            {
                                this.Destination.Cache.RaiseExceptionHandling <GLAllocationDestination.weight>(iDest, iDest.Weight,
                                                                                                               new PXSetPropertyException(PXMessages.LocalizeFormatNoPrefix(Messages.ValueForWeight, 0, 100)));
                                return;
                            }
                        }
                        if (dest == null)
                        {
                            dest = iDest;
                        }
                    }
                    if (Math.Abs(total - 100.0m) >= 0.000001m)
                    {
                        if (dest != null)
                        {
                            this.Destination.Cache.RaiseExceptionHandling <GLAllocationDestination.weight>(dest, dest.Weight,
                                                                                                           new PXSetPropertyException(Messages.SumOfDestsMustBe100));
                        }
                        else
                        {
                            throw new PXException(Messages.SumOfDestsMustBe100);
                        }
                    }
                }
            }
        }