Ejemplo n.º 1
0
        protected virtual void distributePercentOf(GLAllocationDestination row)
        {
            if (row != null && row.Weight.HasValue && row.Weight != null)
            {
                //Find last
                GLAllocationDestination lastRow = null;
                Decimal total = Decimal.Zero;
                foreach (GLAllocationDestination it in this.Destination.Select())
                {
                    if (object.ReferenceEquals(it, row))
                    {
                        continue;
                    }
                    total += it.Weight ?? Decimal.Zero;
                    if (lastRow == null || (it.LineID.HasValue && it.LineID.Value > lastRow.LineID.Value))
                    {
                        lastRow = it;
                    }
                }

                Decimal remainder = (100.0m - total);
                remainder = remainder < row.Weight.Value ? remainder : row.Weight.Value;
                if (lastRow != null && remainder > Decimal.Zero)
                {
                    lastRow.Weight += remainder;
                }
            }
        }
Ejemplo n.º 2
0
        protected virtual void GLAllocationDestination_RowInserting(PXCache cache, PXRowInsertingEventArgs e)
        {
            if (this.isWeigthRecalcRequired())
            {
                GLAllocationDestination record = (GLAllocationDestination)e.Row;
                if (record.Weight == null)
                {
                    record.Weight = 100;
                    foreach (GLAllocationDestination it in this.Destination.Select())
                    {
                        if (object.ReferenceEquals(it, record))
                        {
                            continue;
                        }
                        record.Weight -= it.Weight;
                    }

                    this.justInserted = record.LineID;
                }
            }
            else
            {
                this.justInserted = null;
            }
        }
Ejemplo n.º 3
0
        protected virtual void GLAllocationDestination_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
        {
            GLAllocationDestination row = (GLAllocationDestination)e.Row;

            if ((e.Operation & PXDBOperation.Command) != PXDBOperation.Delete)
            {
                VerifyAccountIDToBeNoControl <GLAllocationDestination.accountID, Account.accountID>(cache, e, row.AccountID, Allocation.Current?.AllocLedgerID);
                VerifyAccountIDToBeNoControl <GLAllocationDestination.basisAccountCD, Account.accountCD>(cache, e, row.BasisAccountCD, Allocation.Current?.AllocLedgerID);

                GLAllocation parent = this.Allocation.Current;
                List <GLAllocationDestination> duplicated = FindDuplicated(row, parent);
                //if (parent.AllocMethod == Constants.AllocationMethod.ByAcctPTD || parent.AllocMethod == Constants.AllocationMethod.ByAcctYTD)
                {
                    if (duplicated.Count > 0)
                    {
                        duplicated.Add(row);
                        foreach (GLAllocationDestination it in duplicated)
                        {
                            PXErrorLevel level   = (parent.AllocMethod == Constants.AllocationMethod.ByAcctPTD || parent.AllocMethod == Constants.AllocationMethod.ByAcctYTD) ? PXErrorLevel.RowError : PXErrorLevel.RowWarning;
                            string       message = (parent.AllocMethod == Constants.AllocationMethod.ByAcctPTD || parent.AllocMethod == Constants.AllocationMethod.ByAcctYTD) ? Messages.ERR_AllocationDestinationAccountMustNotBeDuplicated : Messages.AllocationDestinationAccountAreIdentical;
                            cache.RaiseExceptionHandling <GLAllocationDestination.accountID>(it, it.AccountID, new PXSetPropertyException(message, level));
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 protected virtual void GLAllocationDestination_Weight_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
 {
     if (this.isWeigthRecalcRequired())
     {
         GLAllocationDestination dest = (GLAllocationDestination)e.Row;
         decimal newWeght             = (decimal)e.NewValue;
         if (newWeght <= 0.00m || newWeght > 100.00m)
         {
             throw new PXSetPropertyException(string.Format(Messages.ValueForWeight, 0, 100));
         }
     }
 }
Ejemplo n.º 5
0
        protected virtual void GLAllocationDestination_RowDeleted(PXCache cache, PXRowDeletedEventArgs e)
        {
            if (this.Allocation.Cache.GetStatus(this.Allocation.Current) != PXEntryStatus.Deleted && this.isWeigthRecalcRequired())
            {
                GLAllocationDestination row = (GLAllocationDestination)e.Row;

                if (!this.isMassDelete)
                {
                    if (!(this.justInserted.HasValue && this.justInserted.Value == row.LineID))
                    {
                        this.distributePercentOf(row);
                        this.Destination.View.RequestRefresh();
                    }
                    this.Allocation.Cache.Update(this.Allocation.Current);
                }
            }
        }
Ejemplo n.º 6
0
        protected virtual List <GLAllocationDestination> FindDuplicated(GLAllocationDestination aDest, GLAllocation aDefinition)
        {
            List <GLAllocationDestination> duplicated = new List <GLAllocationDestination>();
            bool includeBasis = (aDefinition.AllocMethod == Constants.AllocationMethod.ByAcctPTD || aDefinition.AllocMethod == Constants.AllocationMethod.ByAcctYTD);

            foreach (GLAllocationDestination jDest in this.Destination.Select())
            {
                if (object.ReferenceEquals(aDest, jDest) ||
                    (aDest.GLAllocationID == jDest.GLAllocationID && aDest.LineID == jDest.LineID))
                {
                    continue;                                                                                       //Skip self
                }
                if (aDest.AccountID == jDest.AccountID &&
                    aDest.SubID == jDest.SubID &&
                    aDest.BranchID == jDest.SubID)
                {
                    duplicated.Add(jDest);
                }
            }
            return(duplicated);
        }
Ejemplo n.º 7
0
        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 (!ParseFiscalPeriodID(row.StartFinPeriodID, out startYr, out startNbr))
                    {
                        cache.RaiseExceptionHandling <GLAllocation.startFinPeriodID>(e.Row, row.StartFinPeriodID, new PXSetPropertyException(Messages.AllocationStartPeriodHasIncorrectFormat));
                    }

                    if (!ParseFiscalPeriodID(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(string.Format(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);
                        }
                    }
                }
            }
        }