private void RedistributeDeduction(IRUTROTable document, RUTROT rutrot, ARSetup setup, CurrencyInfo curyInfo) { if (document == null || document.IsRUTROTDeductible != true || rutrot == null) { return; } var persons = RRDistribution.Select().ToList(); int count = persons.Count; if (rutrot.AutoDistribution == true && count != 0) { decimal totalFromTrans = rutrot.CuryTotalAmt ?? 0.0m; var distributor = new DistributionRounding(setup, PXAccess.FeatureInstalled <PX.Objects.CS.FeaturesSet.invoiceRounding>()) { PreventOverflow = true, CuryPlaces = curyInfo?.CuryPrecision ?? 0 }; var amts = distributor.DistributeEven(totalFromTrans, count); foreach (var p in persons.Zip(amts, (p, a) => new { DistributionItem = p, Amount = a })) { var item = (RUTROTDistribution)RRDistribution.Cache.CreateCopy((RUTROTDistribution)p.DistributionItem); if (item.CuryAmount != p.Amount) { item.CuryAmount = p.Amount; RRDistribution.Cache.Update(item); } } } RRDistribution.View.RequestRefresh(); }
private void RedistributeDeduction(IRUTROTable document, RUTROT rutrot, ARSetup setup, CurrencyInfo curyInfo) { if (document == null || document.IsRUTROTDeductible != true || rutrot == null) { return; } var persons = RRDistribution.Select().ToList(); int count = persons.Count; if (rutrot.AutoDistribution == true && count != 0) { decimal totalFromTrans = rutrot.CuryTotalAmt ?? 0.0m; DistributionRounding distributor; PXCache currencyInfoCache = Base.Caches[typeof(CurrencyInfo)]; Currency currency = null; if (currencyInfoCache.Current != null) { currency = PXSelect <Currency, Where <Currency.curyID, Equal <Required <CurrencyInfo.curyID> > > > .Select(Base, (currencyInfoCache.Current as CurrencyInfo).CuryID); } if (currency?.UseARPreferencesSettings == false) { distributor = new DistributionRounding(currency, PXAccess.FeatureInstalled <PX.Objects.CS.FeaturesSet.invoiceRounding>()) { PreventOverflow = true, CuryPlaces = curyInfo?.CuryPrecision ?? 0 }; } else { distributor = new DistributionRounding(setup, PXAccess.FeatureInstalled <PX.Objects.CS.FeaturesSet.invoiceRounding>()) { PreventOverflow = true, CuryPlaces = curyInfo?.CuryPrecision ?? 0 }; } var amts = distributor.DistributeEven(totalFromTrans, count); foreach (var p in persons.Zip(amts, (p, a) => new { DistributionItem = p, Amount = a })) { var item = (RUTROTDistribution)RRDistribution.Cache.CreateCopy((RUTROTDistribution)p.DistributionItem); if (item.CuryAmount != p.Amount) { item.CuryAmount = p.Amount; RRDistribution.Cache.Update(item); } } } RRDistribution.View.RequestRefresh(); }
private bool WarnUndistributedAmount(IRUTROTable document, RUTROT rutrot, PXErrorLevel errorLevel, CurrencyInfo currencyInfo) { if (document == null || rutrot == null || document.IsRUTROTDeductible != true) { return(false); } decimal maxDiff = 0.0m; if (PXAccess.FeatureInstalled <PX.Objects.CS.FeaturesSet.invoiceRounding>() && currencyInfo != null) { var distributor = new DistributionRounding(ARSetup.Current, true) { CuryPlaces = currencyInfo.CuryPrecision ?? 0 }; maxDiff = distributor.FinishStep; } Action <string> setNotification = null; if (errorLevel == PXErrorLevel.Error) { setNotification = m => Rutrots.Cache.RaiseExceptionHandling <RUTROT.curyUndistributedAmt>(rutrot, rutrot.CuryUndistributedAmt, new PXSetPropertyException(m, errorLevel)); } else { setNotification = m => PXUIFieldAttribute.SetWarning <RUTROT.curyUndistributedAmt>(Rutrots.Cache, rutrot, m); } if (rutrot.CuryUndistributedAmt > maxDiff) { if (rutrot.AutoDistribution == true) { setNotification(RUTROTMessages.PositiveUndistributedAmount); return(true); } else { PXUIFieldAttribute.SetWarning <RUTROT.curyUndistributedAmt>(Rutrots.Cache, rutrot, RUTROTMessages.PositiveUndistributedAmount); return(false); } } else if (rutrot.CuryUndistributedAmt < 0.0m) { setNotification(RUTROTMessages.NegativeUndistributedAmount); return(true); } else { Rutrots.Cache.RaiseExceptionHandling <RUTROT.curyUndistributedAmt>(rutrot, rutrot.CuryUndistributedAmt, null); return(false); } }