public void UpdateTranDeductibleFromInventory(IRUTROTableLine line, IRUTROTable document) { if (line == null) { return; } InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(Base, line.GetInventoryID()); InventoryItemRUTROT itemRR = RUTROTHelper.GetExtensionNullable <InventoryItem, InventoryItemRUTROT>(item); if (itemRR == null) { return; } if (document?.IsRUTROTDeductible == true) { line.IsRUTROTDeductible = itemRR.IsRUTROTDeductible == true; } else { line.IsRUTROTDeductible = false; } if (itemRR.RUTROTItemType != null) { line.RUTROTItemType = itemRR.RUTROTItemType; } if (itemRR.RUTROTWorkTypeID != null) { line.RUTROTWorkTypeID = itemRR.RUTROTWorkTypeID; } }
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 bool WarnOnDeductionExceedsAllowance(IRUTROTable document, RUTROT rutrot, PXErrorLevel errorLevel) { if (document == null || rutrot == null || document.IsRUTROTDeductible != true || rutrot.CuryAllowedAmt == null) { return(false); } Rutrots.Cache.RaiseExceptionHandling <RUTROT.curyTotalAmt>(rutrot, rutrot.CuryTotalAmt, null); Action <string> setNotification = null; if (errorLevel == PXErrorLevel.Error) { setNotification = m => Rutrots.Cache.RaiseExceptionHandling <RUTROT.curyTotalAmt>(rutrot, rutrot.CuryTotalAmt, new PXSetPropertyException(m, errorLevel)); } else { setNotification = m => PXUIFieldAttribute.SetWarning <RUTROT.curyTotalAmt>(Rutrots.Cache, rutrot, m); } if (rutrot.CuryTotalAmt <= rutrot.CuryAllowedAmt) { return(false); } else if (rutrot.CuryAllowedAmt > 0.0m) { PXUIFieldAttribute.SetWarning <RUTROT.curyTotalAmt>(Rutrots.Cache, rutrot, RUTROTMessages.DeductibleExceedsAllowance); return(false); } else { setNotification(RUTROTMessages.PeopleAreRequiredForDeduction); return(true); } }
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); } }
public void UncheckRUTROTIfProhibited(IRUTROTable document, Branch branch) { if (branch == null || document == null) { return; } BranchRUTROT branchRR = PXCache <Branch> .GetExtension <BranchRUTROT>(branch); if (RUTROTHelper.IsRUTROTAllowed(branchRR, document) == false && document.IsRUTROTDeductible == true) { document.IsRUTROTDeductible = false; Document.Cache.Update(document.GetBaseDocument()); } }
public void RUTROTDeductibleUpdated(IRUTROTable row, IRUTROTable oldRow, RUTROT rutrot) { if (row != null && oldRow?.IsRUTROTDeductible != row.IsRUTROTDeductible) { if ((rutrot == null || rutrot.RefNbr == null) && row.IsRUTROTDeductible == true) { rutrot = (RUTROT)Rutrots.Insert(new RUTROT()); } else if (row.IsRUTROTDeductible != true) { Rutrots.Delete(rutrot); } } }
public void CheckRUTROTLine(PXCache sender, IRUTROTable document, IRUTROTableLine line, RUTROT rutrot) { if (line != null && document != null && rutrot != null) { if (document.IsRUTROTDeductible == true) { if (line.GetInventoryID() != null) { string value = rutrot.RUTROTType; InventoryItem item = (InventoryItem)PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(Base, line.GetInventoryID()); InventoryItemRUTROT itemRR = RUTROTHelper.GetExtensionNullable <InventoryItem, InventoryItemRUTROT>(item); if (!RUTROTHelper.IsItemMatchRUTROTType(value, item, itemRR, itemRR?.IsRUTROTDeductible == true)) { Base.Transactions.Cache.RaiseExceptionHandling <SOLine.inventoryID>(line, item.InventoryCD, new PXSetPropertyException <SOLine.inventoryID>(RUTROTMessages.LineDoesNotMatchDoc)); throw new PXSetPropertyException <SOLine.inventoryID>(RUTROTMessages.LineDoesNotMatchDoc); } } } } }
private void RUTROTDeductibleUpdated(IRUTROTable row, IRUTROTable oldRow, RUTROT rutrot) { if (row != null) { if (oldRow?.IsRUTROTDeductible != row.IsRUTROTDeductible) { if ((rutrot == null || rutrot.RefNbr == null) && row.IsRUTROTDeductible == true) { rutrot = (RUTROT)Rutrots.Insert(new RUTROT()); } else if (row.IsRUTROTDeductible != true) { Rutrots.Delete(rutrot); } } else if (row.IsRUTROTDeductible == true && rutrot != null && Rutrots.Cache.GetStatus(rutrot) == PXEntryStatus.Notchanged) { //we need this to raise RowPersisting on RUTROT even it was not changed Rutrots.Cache.SetStatus(rutrot, PXEntryStatus.Updated); } } }
private void SetPersistingChecks(IRUTROTable document, RUTROT rutrot) { PXPersistingCheck check = document.IsRUTROTDeductible == true ? PXPersistingCheck.NullOrBlank : PXPersistingCheck.Nothing; PXPersistingCheck rotCheck = document.IsRUTROTDeductible == true && rutrot?.RUTROTType == RUTROTTypes.ROT ? PXPersistingCheck.NullOrBlank : PXPersistingCheck.Nothing; PXDefaultAttribute.SetPersistingCheck <RUTROT.rUTROTType>(Rutrots.Cache, rutrot, check); PXDefaultAttribute.SetPersistingCheck <RUTROT.rOTDeductionPct>(Rutrots.Cache, rutrot, check); PXDefaultAttribute.SetPersistingCheck <RUTROT.curyROTPersonalAllowance>(Rutrots.Cache, rutrot, check); PXDefaultAttribute.SetPersistingCheck <RUTROT.curyROTExtraAllowance>(Rutrots.Cache, rutrot, check); PXDefaultAttribute.SetPersistingCheck <RUTROT.rUTDeductionPct>(Rutrots.Cache, rutrot, check); PXDefaultAttribute.SetPersistingCheck <RUTROT.curyRUTPersonalAllowance>(Rutrots.Cache, rutrot, check); PXDefaultAttribute.SetPersistingCheck <RUTROT.curyRUTExtraAllowance>(Rutrots.Cache, rutrot, check); if (!String.IsNullOrWhiteSpace(rutrot?.ROTOrganizationNbr)) { PXDefaultAttribute.SetPersistingCheck <RUTROT.rOTAppartment>(Rutrots.Cache, rutrot, rotCheck); PXDefaultAttribute.SetPersistingCheck <RUTROT.rOTEstate>(Rutrots.Cache, rutrot, PXPersistingCheck.Nothing); } else { PXDefaultAttribute.SetPersistingCheck <RUTROT.rOTEstate>(Rutrots.Cache, rutrot, rotCheck); PXDefaultAttribute.SetPersistingCheck <RUTROT.rOTAppartment>(Rutrots.Cache, rutrot, PXPersistingCheck.Nothing); } }
private void WarnPersonAmount(RUTROTDistribution personalAmount, RUTROT rutrot, IRUTROTable document) { if (document == null || rutrot == null || document.IsRUTROTDeductible != true || personalAmount == null) { return; } bool treatAsError = document.GetDocumentHold() != true; PXErrorLevel errorLevel = treatAsError ? PXErrorLevel.Error : PXErrorLevel.Warning; PXSetPropertyException <RUTROTDistribution.curyAmount> error = null; if (personalAmount.CuryAmount < 0.0m && rutrot.CuryTotalAmt != 0.0m) { error = new PXSetPropertyException <RUTROTDistribution.curyAmount>(RUTROTMessages.NonpositivePersonAmount, errorLevel); } else if (personalAmount.CuryAmount > personalAmount.CuryAllowance) { error = new PXSetPropertyException <RUTROTDistribution.curyAmount>(RUTROTMessages.PersonExceedsAllowance, PXErrorLevel.Error); } RRDistribution.Cache.RaiseExceptionHandling <RUTROTDistribution.curyAmount>(personalAmount, personalAmount.CuryAmount, error); }
public static bool IsRUTROTAllowed(BranchRUTROT branchRR, IRUTROTable document) { return(branchRR?.AllowsRUTROT == true && IsRUTROTcompatibleType(document?.GetDocumentType()) && CurrenciesMatch(branchRR, document)); }
public static bool CurrenciesMatch(BranchRUTROT branchRR, IRUTROTable document) { return(branchRR?.RUTROTCuryID == document?.GetDocumentCuryID()); }