private void RecalcFormulas(RUTROT rutrot, DocExt document) { if (document.IsRUTROTDeductible == true) { foreach (Tran tran in Transactions.Select()) { if (PXCache <Tran> .GetExtension <TranExt>(tran)?.IsRUTROTDeductible == true) { Transactions.Cache.RaiseFieldUpdated("IsRUTROTDeductible", tran, false); //this is required for updating formula on ARTranRUTROT.CuryRUTROTAvailableAmt } } foreach (RUTROTDistribution distribution in RRDistribution.Select()) { RRDistribution.Cache.RaiseFieldUpdated <RUTROTDistribution.extra>(distribution, !distribution.Extra); //this is required for updating formula on RUTROTDistribution.curyAllowance } PXUnboundFormulaAttribute.CalcAggregate <ARTranRUTROT.curyRUTROTTotal>(Transactions.Cache, rutrot); PXFormulaAttribute.CalcAggregate <ARTranRUTROT.curyRUTROTAvailableAmt>(Transactions.Cache, rutrot); PXUnboundFormulaAttribute.CalcAggregate <SOLineRUTROT.curyRUTROTTotal>(Transactions.Cache, rutrot); PXFormulaAttribute.CalcAggregate <SOLineRUTROT.curyRUTROTAvailableAmt>(Transactions.Cache, rutrot); PXFormulaAttribute.CalcAggregate <RUTROTDistribution.curyAllowance>(RRDistribution.Cache, rutrot); } }
public virtual void CopyOrderProc(SOOrder order, CopyParamFilter copyFilter, CopyOrderProcDelegate baseMethod) { RUTROT rutrotRecord = null; PXResultset <RUTROTDistribution> rutrotDistribution = null; SOOrderRUTROT orderRR = RUTROTHelper.GetExtensionNullable <SOOrder, SOOrderRUTROT>(order); if (RUTROTHelper.IsRUTROTcompatibleType(order.OrderType) && orderRR?.IsRUTROTDeductible == true) { rutrotRecord = Rutrots.SelectSingle(); rutrotDistribution = RRDistribution.Select(); } baseMethod(order, copyFilter); if (RUTROTHelper.IsRUTROTcompatibleType(copyFilter.OrderType) && rutrotRecord != null && rutrotDistribution != null) { rutrotRecord = (RUTROT)Rutrots.Cache.CreateCopy(rutrotRecord); rutrotRecord.RefNbr = Base.Document.Current.OrderNbr; rutrotRecord.DocType = Base.Document.Current.OrderType; rutrotRecord.CuryDistributedAmt = 0m; rutrotRecord.CuryUndistributedAmt = 0m; rutrotRecord = Rutrots.Update(rutrotRecord); foreach (RUTROTDistribution distribution in rutrotDistribution) { RUTROTDistribution new_distribution = (RUTROTDistribution)RRDistribution.Cache.CreateCopy(distribution); new_distribution.RefNbr = null; new_distribution.DocType = null; RRDistribution.Insert(new_distribution); } } else { Base.Document.Cache.SetValueExt <SOOrderRUTROT.isRUTROTDeductible>(Base.Document.Current, false); Base.Document.Update(Base.Document.Current); } }
public virtual void InvoiceOrder(DateTime invoiceDate, PXResult <SOOrderShipment, SOOrder, CurrencyInfo, SOAddress, SOContact, SOOrderType> order, PXResultset <SOShipLine, SOLine> details, Customer customer, DocumentList <ARInvoice, SOInvoice> list, InvoiceOrderDelegate baseMethod) { baseMethod(invoiceDate, order, details, customer, list); SOOrder soorder = (SOOrder)order; SOOrderRUTROT orderRR = PXCache <SOOrder> .GetExtension <SOOrderRUTROT>(soorder); if (orderRR?.IsRUTROTDeductible == true && Base.Document.Current != null) { Base.Document.SetValueExt <ARInvoiceRUTROT.isRUTROTDeductible>(Base.Document.Current, true); Base.Document.Update(Base.Document.Current); RUTROT rutrot = PXSelect <RUTROT, Where <RUTROT.docType, Equal <Required <SOOrder.orderType> >, And <RUTROT.refNbr, Equal <Required <SOOrder.orderNbr> > > > > .Select(Base, soorder.OrderType, soorder.OrderNbr); rutrot = (RUTROT)Base.Rutrots.Cache.CreateCopy(rutrot); rutrot.DocType = Base.Document.Current.DocType; rutrot.RefNbr = Base.Document.Current.RefNbr; rutrot.CuryDistributedAmt = 0m; rutrot.CuryUndistributedAmt = 0m; rutrot = Base.Rutrots.Update(rutrot); RecalcFormulas(rutrot, PXCache <ARInvoice> .GetExtension <ARInvoiceRUTROT>(Base.Document.Current)); foreach (RUTROTDistribution rutrotDetail in PXSelect <RUTROTDistribution, Where <RUTROTDistribution.docType, Equal <Required <SOOrder.orderType> >, And <RUTROTDistribution.refNbr, Equal <Required <SOOrder.orderNbr> > > > > .Select(Base, soorder.OrderType, soorder.OrderNbr)) { RUTROTDistribution new_detail = (RUTROTDistribution)Base.RRDistribution.Cache.CreateCopy(rutrotDetail); new_detail.RefNbr = null; new_detail.DocType = null; Base.RRDistribution.Insert(new_detail); } Base.Save.Press(); } }
public void Update(Doc document) { if (document == null) { return; } RUTROT rutrot = Rutrots.Current ?? Rutrots.SelectSingle(); DocExt documentRR = PXCache <Doc> .GetExtension <DocExt>(document); Branch branch = PXSelect <Branch, Where <Branch.branchID, Equal <Required <Branch.branchID> > > > .Select(Base, documentRR.GetDocumentBranchID()); BranchRUTROT branchRR = RUTROTHelper.GetExtensionNullable <Branch, BranchRUTROT>(branch); PXErrorLevel errorLevel = documentRR.GetDocumentHold() != true ? PXErrorLevel.Error : PXErrorLevel.Warning; bool enableEdit = documentRR.GetRUTROTCompleted() != true && RUTROTHelper.CurrenciesMatch(branchRR, documentRR); bool showSection = documentRR.IsRUTROTDeductible == true; bool showROTSection = showSection && rutrot?.RUTROTType == RUTROTTypes.ROT; bool isAutoDistribution = rutrot?.AutoDistribution == true; UpdateRUTROTCheckbox(enableEdit, RUTROTHelper.IsRUTROTAllowed(branchRR, documentRR)); UpdateRUTROTSection(showSection, enableEdit, showROTSection); UpdateDistributionControls(showSection, enableEdit, isAutoDistribution); SetPersistingChecks(documentRR, rutrot); WarnOnDeductionExceedsAllowance(documentRR, rutrot, errorLevel); WarnUndistributedAmount(documentRR, rutrot, errorLevel, currencyinfo.Current ?? currencyinfo.SelectSingle()); }
public IEnumerable Release(PXAdapter adapter) { if (RUTROTHelper.IsNeedBalancing(Base, Base.Document.Current, RUTROTBalanceOn.Release)) { Base.Save.Press(); ARInvoice doc = Base.Document.Current; PXLongOperation.StartOperation(Base, delegate() { RUTROT rutrot = PXSelect <RUTROT, Where <RUTROT.refNbr, Equal <Required <ARInvoice.refNbr> >, And <RUTROT.docType, Equal <Required <ARInvoice.docType> > > > > .Select(Base, doc.RefNbr, doc.DocType); ARInvoiceEntry invoiceEntryGraph = PXGraph.CreateInstance <ARInvoiceEntry>(); RUTROTHelper.BalanceARInvoiceRUTROT(invoiceEntryGraph, doc, OnRelease: true, rutrot: rutrot); RUTROTHelper.CreateAdjustment(Base, doc, rutrot); Base.ReleaseProcess(new List <ARRegister> { doc }); }); return(new List <ARInvoice> { Base.Document.Current }); } return(Base.Release(adapter)); }
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); } }
public virtual void InvoiceCreated(ARInvoice invoice, SOOrder source, SOInvoiceEntry.InvoiceCreatedDelegate baseMethod) { baseMethod(invoice, source); SOOrderRUTROT orderRR = PXCache <SOOrder> .GetExtension <SOOrderRUTROT>(source); if (orderRR?.IsRUTROTDeductible == true && invoice != null) { ARInvoiceRUTROT invoiceRR = PXCache <ARInvoice> .GetExtension <ARInvoiceRUTROT>(invoice); Base.Document.SetValueExt <ARInvoiceRUTROT.isRUTROTDeductible>(invoice, true); Base.Document.Update(invoice); RUTROT rutrot = PXSelect <RUTROT, Where <RUTROT.docType, Equal <Required <SOOrder.orderType> >, And <RUTROT.refNbr, Equal <Required <SOOrder.orderNbr> > > > > .Select(Base, source.OrderType, source.OrderNbr); rutrot = RUTROTHelper.CreateCopy(Base.Rutrots.Cache, rutrot, invoice.DocType, invoice.RefNbr); rutrot = Base.Rutrots.Update(rutrot); foreach (RUTROTDistribution rutrotDetail in PXSelect <RUTROTDistribution, Where <RUTROTDistribution.docType, Equal <Required <SOOrder.orderType> >, And <RUTROTDistribution.refNbr, Equal <Required <SOOrder.orderNbr> > > > > .Select(Base, source.OrderType, source.OrderNbr)) { RUTROTDistribution new_detail = (RUTROTDistribution)Base.RRDistribution.Cache.CreateCopy(rutrotDetail); new_detail.RefNbr = null; new_detail.DocType = null; Base.RRDistribution.Insert(new_detail); } } }
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(); }
public static void CreateAdjustment(ARInvoiceEntry graph, ARInvoice invoice, RUTROT rutrot) { ARPayment creditMemo = PXSelect <ARPayment, Where <ARPayment.docType, Equal <Required <RUTROT.docType> >, And <ARPayment.refNbr, Equal <Required <RUTROT.refNbr> > > > > .Select(graph, rutrot.BalancingCreditMemoDocType, rutrot.BalancingCreditMemoRefNbr); ARAdjust2 applicationToCreditMemo = new ARAdjust2 { AdjdDocType = invoice.DocType, AdjdRefNbr = invoice.RefNbr, AdjgDocType = creditMemo.DocType, AdjgRefNbr = creditMemo.RefNbr, AdjNbr = creditMemo.AdjCntr, CustomerID = creditMemo.CustomerID, AdjdCustomerID = invoice.CustomerID, AdjdBranchID = invoice.BranchID, AdjgBranchID = creditMemo.BranchID, AdjgCuryInfoID = creditMemo.CuryInfoID, AdjdOrigCuryInfoID = invoice.CuryInfoID, AdjdCuryInfoID = invoice.CuryInfoID, CuryAdjdAmt = creditMemo.CuryDocBal }; graph.Adjustments.Insert(applicationToCreditMemo); graph.Save.Press(); }
/// <summary> /// Creates a copy of <see cref="RUTROT"/> and sets all calculated fields to initial state. /// </summary> /// <param name="cache">The cache object to be used to create a copy of the <see cref="RUTROT"/> object.</param> /// <param name="source">The source <see cref="RUTROT"/> object to be used as a template for a new one.</param> /// <param name="newDocType">The document type to be set for a new <see cref="RUTROT"/> object.</param> /// <param name="newRefNbr">The reference number to be set for a new <see cref="RUTROT"/> object.</param> /// <returns>A new <see cref="RUTROT"/> object.</returns> public static RUTROT CreateCopy(PXCache cache, RUTROT source, string newDocType, string newRefNbr) { if (source == null) { return(null); } RUTROT rutrot = (RUTROT)cache.CreateCopy(source); rutrot.DocType = newDocType; rutrot.RefNbr = newRefNbr; rutrot.CuryDistributedAmt = 0m; rutrot.CuryUndistributedAmt = 0m; rutrot.CuryTotalAmt = 0m; rutrot.CuryOtherCost = 0m; rutrot.CuryMaterialCost = 0m; rutrot.CuryWorkPrice = 0m; rutrot.DistributedAmt = 0m; rutrot.UndistributedAmt = 0m; rutrot.TotalAmt = 0m; rutrot.OtherCost = 0m; rutrot.MaterialCost = 0m; rutrot.WorkPrice = 0m; rutrot.DistributionLineCntr = 0; rutrot.IsClaimed = false; rutrot.ClaimDate = null; rutrot.ClaimFileName = null; cache.SetDefaultExt <RUTROT.noteID>(rutrot); return(rutrot); }
public virtual ARInvoice InsertDocument(ARInvoiceEntry docgraph, ScheduleDet sdet, Customer customer, ARInvoice ardoc, CurrencyInfo info, InsertDocumentDelegate baseMethod) { ARInvoice new_ardoc = baseMethod(docgraph, sdet, customer, ardoc, info); if (PXCache <ARInvoice> .GetExtension <ARInvoiceRUTROT>(ardoc)?.IsRUTROTDeductible == true) { RUTROT rutrot = PXSelect <RUTROT, Where <RUTROT.docType, Equal <Required <ARInvoice.docType> >, And <RUTROT.refNbr, Equal <Required <ARInvoice.refNbr> > > > > .Select(docgraph, ardoc.DocType, ardoc.RefNbr); RUTROT new_rutrot = PXCache <RUTROT> .CreateCopy(rutrot); new_rutrot.CuryDistributedAmt = 0m; new_rutrot.CuryTotalAmt = 0m; new_rutrot.CuryUndistributedAmt = 0m; new_rutrot.DistributedAmt = 0m; new_rutrot.TotalAmt = 0m; new_rutrot.UndistributedAmt = 0m; new_rutrot.WorkPrice = 0m; new_rutrot.MaterialCost = 0m; new_rutrot.OtherCost = 0m; new_rutrot.CuryWorkPrice = 0m; new_rutrot.CuryMaterialCost = 0m; new_rutrot.CuryOtherCost = 0m; new_rutrot.RefNbr = null; new_rutrot.NoteID = null; docgraph.Rutrots.Insert(new_rutrot); } return(new_ardoc); }
public virtual void InsertSOAdjustments(SOOrder order, ARPaymentEntry docgraph, ARPayment payment, InsertSOAdjustmentsDelegate baseMethod) { baseMethod(order, docgraph, payment); SOOrderRUTROT orderRR = RUTROTHelper.GetExtensionNullable <SOOrder, SOOrderRUTROT>(order); if (orderRR.IsRUTROTDeductible == true) { RUTROT rutrot = PXSelect <RUTROT, Where <RUTROT.docType, Equal <Required <SOOrder.orderType> >, And <RUTROT.refNbr, Equal <Required <SOOrder.orderNbr> > > > > .Select(Base, order.OrderType, order.OrderNbr); foreach (SOAdjust adj in docgraph.SOAdjustments.Select()) { SOAdjust other = PXSelectGroupBy <SOAdjust, Where <SOAdjust.voided, Equal <False>, And <SOAdjust.adjdOrderType, Equal <Required <SOAdjust.adjdOrderType> >, And <SOAdjust.adjdOrderNbr, Equal <Required <SOAdjust.adjdOrderNbr> >, And <Where <SOAdjust.adjgDocType, NotEqual <Required <SOAdjust.adjgDocType> >, Or <SOAdjust.adjgRefNbr, NotEqual <Required <SOAdjust.adjgRefNbr> > > > > > > >, Aggregate <GroupBy <SOAdjust.adjdOrderType, GroupBy <SOAdjust.adjdOrderNbr, Sum <SOAdjust.curyAdjdAmt, Sum <SOAdjust.adjAmt> > > > > > .Select(Base, adj.AdjdOrderType, adj.AdjdOrderNbr, adj.AdjgDocType, adj.AdjgRefNbr); if (other == null || other.AdjdOrderNbr == null) { docgraph.SOAdjustments.Cache.SetValueExt <SOAdjust.curyAdjgAmt>(adj, adj.CuryAdjgAmt - rutrot.CuryTotalAmt); docgraph.SOAdjustments.Update(adj); } } } }
public virtual void CreatePayment(ARInvoice ardoc) { Base.CreatePayment(ardoc, null, null, null, true); RUTROT rowRR = PXSelect <RUTROT, Where <RUTROT.docType, Equal <Required <ARInvoice.docType> >, And <RUTROT.refNbr, Equal <Required <ARInvoice.refNbr> > > > > .Select(this.Base, ardoc.DocType, ardoc.RefNbr); if (PXAccess.FeatureInstalled <FeaturesSet.rutRotDeduction>() && ardoc != null && PXCache <ARInvoice> .GetExtension <ARInvoiceRUTROT>(ardoc)?.IsRUTROTDeductible == true && Base.Document.Current.DocType == ARDocType.Payment) { bool isInvoiceBalanced = rowRR.BalancingCreditMemoRefNbr != null && rowRR.BalancingDebitMemoRefNbr != null; if (rowRR.IsClaimed != true) { decimal curyDistributedAmt = 0m; if (isInvoiceBalanced == false) { PXCache rUTROTCache = Base.Caches[typeof(RUTROT)]; CM.PXCurrencyAttribute.CuryConvCury <ARPayment.curyInfoID>(Base.Document.Cache, Base.Document.Current, rowRR.DistributedAmt ?? 0m, out curyDistributedAmt); rUTROTCache.SetValue <RUTROT.curyDistributedAmt>(rowRR, curyDistributedAmt); } SetPaymentAmount(Math.Max((Base.Document.Current.CuryDocBal - curyDistributedAmt) ?? 0m, 0m)); } } }
protected virtual void RUTROT_RUTROTType_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e) { DocExt document = RUTROTHelper.GetExtensionNullable <Doc, DocExt>(Document.Current); RUTROT rutrot = (RUTROT)e.Row; if (document != null && document.IsRUTROTDeductible == true) { string value = (string)e.NewValue; foreach (Tran tran in Transactions.Select()) { TranExt tranRR = RUTROTHelper.GetExtensionNullable <Tran, TranExt>(tran); if (tranRR.GetInventoryID() != null) { InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(Base, tranRR.GetInventoryID()); InventoryItemRUTROT itemRR = PXCache <InventoryItem> .GetExtension <InventoryItemRUTROT>(item); if (!RUTROTHelper.IsItemMatchRUTROTType(value, item, itemRR, itemRR?.IsRUTROTDeductible == true)) { sender.RaiseExceptionHandling <RUTROT.rUTROTType>(rutrot, rutrot.RUTROTType, new PXSetPropertyException <RUTROT.rUTROTType>(RUTROTMessages.LineDoesNotMatchDoc)); e.NewValue = rutrot.RUTROTType; break; } } } } }
private void ClearROTFields(RUTROT rutrot) { if (rutrot != null && rutrot.RUTROTType == RUTROTTypes.RUT) { rutrot.ROTAppartment = null; rutrot.ROTEstate = null; rutrot.ROTOrganizationNbr = null; } }
protected virtual void RUTROT_RUTROTType_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e) { DocExt document = RUTROTHelper.GetExtensionNullable <Doc, DocExt>(Document.Current); RUTROT rutrot = (RUTROT)e.Row; ClearROTFields(rutrot); ClearWorkTypes(rutrot); RecalcFormulas(rutrot, document); }
public virtual void ARInvoiceCreated(ARInvoice invoice, ARRegister doc, ARInvoiceEntry.ARInvoiceCreatedDelegate baseMethod) { baseMethod(invoice, doc); RUTROT rutrot = PXSelect <RUTROT, Where <RUTROT.docType, Equal <Required <ARRegister.docType> >, And <RUTROT.refNbr, Equal <Required <ARRegister.refNbr> > > > > .Select(Base, doc.DocType, doc.RefNbr); rutrot = RUTROTHelper.CreateCopy(Base.Rutrots.Cache, rutrot, invoice.DocType, invoice.RefNbr); rutrot = Base.Rutrots.Update(rutrot); }
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(); }
protected virtual void RUTROT_RowInserted(PXCache sender, PXRowInsertedEventArgs e) { RUTROT rutrot = (RUTROT)e.Row; rutrot.CuryAllowedAmt = 0m; rutrot.CuryMaterialCost = 0m; rutrot.CuryOtherCost = 0m; rutrot.CuryWorkPrice = 0m; RecalcFormulas(rutrot, RUTROTHelper.GetExtensionNullable <Doc, DocExt>(Document.Current)); }
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 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); } } }
private void ClearWorkTypes(RUTROT rutrot) { foreach (Tran line in Transactions.Select()) { TranExt lineRR = RUTROTHelper.GetExtensionNullable <Tran, TranExt>(line); RUTROTWorkType workType = PXSelect <RUTROTWorkType, Where <RUTROTWorkType.workTypeID, Equal <Required <RUTROTWorkType.workTypeID> > > > .Select(this.Base, lineRR.RUTROTWorkTypeID); if (workType?.RUTROTType != rutrot.RUTROTType) { lineRR.RUTROTWorkTypeID = null; Transactions.Update(line); } } }
private DocumentDetails GetExtendedDoc(RUTROT inv) { ARInvoice origInv = Documents.Select(inv.DocType, inv.RefNbr); return(new DocumentDetails { ClaimNbr = GetClaimNumber(), Document = origInv, Rutrot = inv, Distribution = Distribution.Select(inv.DocType, inv.RefNbr).Select(r => (RUTROTDistribution)r).ToList(), Lines = GetLines(origInv), Payments = GetPayments(origInv), Distributor = GetDistributor(origInv.CuryInfoID) }); }
private void BalanceProc(ARInvoiceEntry graph, ARRegister register) { ARInvoice invoice = PXSelect <ARInvoice, Where <ARInvoice.docType, Equal <Required <ARRegister.docType> >, And <ARInvoice.refNbr, Equal <Required <ARRegister.refNbr> > > > > .Select(graph, register.DocType, register.RefNbr); if (RUTROTHelper.IsNeedBalancing(graph, invoice, RUTROTBalanceOn.Release)) { RUTROT rutrot = PXSelect <RUTROT, Where <RUTROT.refNbr, Equal <Required <ARInvoice.refNbr> >, And <RUTROT.docType, Equal <Required <ARInvoice.docType> > > > > .Select(graph, invoice.RefNbr, invoice.DocType); RUTROTHelper.BalanceARInvoiceRUTROT(graph, invoice, OnRelease: true, rutrot: rutrot); RUTROTHelper.CreateAdjustment(graph, invoice, rutrot); } }
public void RecalcFormulas(RUTROT rowRR, ARInvoiceRUTROT row) { if (row.IsRUTROTDeductible == true) { foreach (ARTran tran in Base.Transactions.Select()) { if (PXCache <ARTran> .GetExtension <ARTranRUTROT>(tran).IsRUTROTDeductible == true) { Base.Transactions.Cache.RaiseFieldUpdated <ARTranRUTROT.isRUTROTDeductible>(tran, false); //this is required for updating formula on ARTranRUTROT.CuryRUTROTAvailableAmt Base.Transactions.Update(tran); } } PXUnboundFormulaAttribute.CalcAggregate <ARTranRUTROT.curyRUTROTTotal>(Base.Transactions.Cache, rowRR); PXFormulaAttribute.CalcAggregate <ARTranRUTROT.curyRUTROTAvailableAmt>(Base.Transactions.Cache, rowRR); } }
protected virtual void RUTROT_RowPersisting(PXCache sender, PXRowPersistingEventArgs e) { RUTROT rutrot = (RUTROT)e.Row; DocExt doc = RUTROTHelper.GetExtensionNullable <Doc, DocExt>(Document.Current); bool treatAsError = doc?.GetDocumentHold() != true; PXErrorLevel errorLevel = treatAsError ? PXErrorLevel.Error : PXErrorLevel.Warning; if (WarnOnDeductionExceedsAllowance(doc, rutrot, errorLevel) && treatAsError) { throw new PXSetPropertyException(Rutrots.Current.CuryAllowedAmt == 0.0m ? RUTROTMessages.PeopleAreRequiredForDeduction : RUTROTMessages.DeductibleExceedsAllowance, PXErrorLevel.Error); } if (WarnUndistributedAmount(doc, rutrot, errorLevel, currencyinfo.Current ?? currencyinfo.SelectSingle()) && treatAsError) { throw new PXSetPropertyException(RUTROTMessages.UndistributedAmount, PXErrorLevel.Error); } }
public virtual void CreatePayment(ARInvoice ardoc) { Base.CreatePayment(ardoc, null, null, null, true); RUTROT rowRR = PXSelect <RUTROT, Where <RUTROT.docType, Equal <Required <ARInvoice.docType> >, And <RUTROT.refNbr, Equal <Required <ARInvoice.refNbr> > > > > .Select(this.Base, ardoc.DocType, ardoc.RefNbr); if (PXAccess.FeatureInstalled <FeaturesSet.rutRotDeduction>() && ardoc != null && PXCache <ARInvoice> .GetExtension <ARInvoiceRUTROT>(ardoc)?.IsRUTROTDeductible == true) { if (rowRR.IsClaimed != true) { SetPaymentAmount(Math.Max((ardoc.CuryDocBal - rowRR.CuryDistributedAmt) ?? 0m, 0m)); } else if (rowRR.IsClaimed == true && ardoc.CuryDocBal == rowRR.CuryDistributedAmt) { PXCache <ARPayment> .GetExtension <ARPaymentRUTROT>(Base.Document.Current).IsRUTROTPayment = true; Base.Document.Update(Base.Document.Current); } } }
protected virtual void RUTROT_RowPersisting(PXCache sender, PXRowPersistingEventArgs e) { RUTROT rutrot = (RUTROT)e.Row; DocExt doc = RUTROTHelper.GetExtensionNullable <Doc, DocExt>(Document.Current); bool treatAsError = doc?.GetDocumentHold() != true; PXErrorLevel errorLevel = treatAsError ? PXErrorLevel.Error : PXErrorLevel.Warning; if (WarnOnDeductionExceedsAllowance(doc, rutrot, errorLevel) && treatAsError) { sender.RaiseExceptionHandling <RUTROT.curyTotalAmt>(rutrot, rutrot.CuryTotalAmt, new PXSetPropertyException(rutrot.CuryAllowedAmt == 0.0m ? RUTROTMessages.PeopleAreRequiredForDeduction : RUTROTMessages.DeductibleExceedsAllowance, PXErrorLevel.Error)); } if (WarnUndistributedAmount(doc, rutrot, errorLevel, currencyinfo.Current ?? currencyinfo.SelectSingle()) && treatAsError) { sender.RaiseExceptionHandling <RUTROT.curyTotalAmt>(rutrot, rutrot.CuryTotalAmt, new PXSetPropertyException(RUTROTMessages.UndistributedAmount, PXErrorLevel.Error)); } if (doc != null && doc.IsRUTROTDeductible == true) { foreach (Tran tran in Transactions.Select()) { TranExt tranRR = RUTROTHelper.GetExtensionNullable <Tran, TranExt>(tran); if (tranRR.GetInventoryID() != null) { InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(Base, tranRR.GetInventoryID()); InventoryItemRUTROT itemRR = PXCache <InventoryItem> .GetExtension <InventoryItemRUTROT>(item); if (!RUTROTHelper.IsItemMatchRUTROTType(rutrot.RUTROTType, item, itemRR, itemRR?.IsRUTROTDeductible == true)) { var exception = new PXSetPropertyException(RUTROTMessages.LineDoesNotMatchDoc, PXErrorLevel.RowError); Transactions.Cache.RaiseExceptionHandling(RUTROTHelper.IsRUTROTDeductible, tran, tranRR.IsRUTROTDeductible, exception); throw exception; } } } } }
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); } } }
public virtual void OrderCreated(SOOrder document, SOOrder source, SOOrderEntry.OrderCreatedDelegate baseMethod) { baseMethod(document, source); SOOrderRUTROT sourceRR = RUTROTHelper.GetExtensionNullable <SOOrder, SOOrderRUTROT>(source); if (RUTROTHelper.IsRUTROTcompatibleType(source.OrderType) && sourceRR?.IsRUTROTDeductible == true) { if (RUTROTHelper.IsRUTROTcompatibleType(document.OrderType)) { RUTROT rutrotRecord = PXSelect <RUTROT, Where <RUTROT.docType, Equal <Required <SOOrder.orderType> >, And <RUTROT.refNbr, Equal <Required <SOOrder.orderNbr> > > > > .Select(this.Base, source.OrderType, source.OrderNbr); rutrotRecord = RUTROTHelper.CreateCopy(Rutrots.Cache, rutrotRecord, Base.Document.Current.OrderType, Base.Document.Current.OrderNbr); rutrotRecord = Rutrots.Update(rutrotRecord); } else { Base.Document.Cache.SetValueExt <SOOrderRUTROT.isRUTROTDeductible>(document, false); Base.Document.Update(document); } } }