private ARInvoice GetArInvoice(ARAdjust adjustment) { return(new PXSelect <ARInvoice, Where <ARInvoice.refNbr, Equal <Required <ARInvoice.refNbr> >, And <ARInvoice.docType, Equal <Required <ARInvoice.docType> > > > >(Base) .SelectSingle(adjustment.AdjdRefNbr, adjustment.AdjdDocType)); }
private ARAdjust AddAdjustment(ARAdjust adj) { if (Base.Document.Current.CuryUnappliedBal == 0m && Base.Document.Current.CuryOrigDocAmt > 0m) { throw new PXLoadInvoiceException(); } return(Base.Adjustments.Insert(adj)); }
public virtual void ReverseApplicationProc(ARAdjust application, ARPayment payment, Action <ARAdjust, ARPayment> baseMethod) { if (payment?.IsCancellation == true) { throw new PXException(Messages.CantReverseCancellationApplication, application.AdjgRefNbr, application.AdjdRefNbr); } baseMethod(application, payment); }
private static void CreateAdjustment(ARInvoiceEntry graph, ARRegister invoice, ARInvoice creditMemo) { ARAdjust applicationToCreditMemo = new ARAdjust { AdjgDocType = creditMemo.DocType, AdjgRefNbr = creditMemo.RefNbr, AdjdDocType = invoice.DocType, AdjdRefNbr = invoice.RefNbr, CuryAdjgAmt = creditMemo.CuryDocBal }; graph.Adjustments_1.Insert(applicationToCreditMemo); graph.Save.Press(); }
private void ValidateAdjustments <TInvoiceField, TCustomerField>(ARAdjust adjustment) where TInvoiceField : IBqlField where TCustomerField : IBqlField { var arInvoice = GetArInvoice(adjustment); if (arInvoice == null) { return; } var invoiceHasExpiredCompliance = service.ValidateRelatedField <ARAdjust, ComplianceDocument.invoiceID, TInvoiceField>(adjustment, ComplianceDocumentReferenceRetriever.GetComplianceDocumentReferenceId(Base, arInvoice)); var customerHasExpiredCompliance = service.ValidateRelatedField <ARAdjust, ComplianceDocument.customerID, TCustomerField>(adjustment, arInvoice.CustomerID); service.ValidateRelatedRow <ARAdjust, ArAdjustExt.hasExpiredComplianceDocuments>(adjustment, invoiceHasExpiredCompliance || customerHasExpiredCompliance); }
public static void CalculateBalancesAR <TInvoice>(PXGraph graph, PXSelectBase <CurrencyInfo> curyInfoSelect, ARAdjust adj, TInvoice invoice, bool isCalcRGOL, bool DiscOnDiscDate) where TInvoice : IInvoice { Customer currentCustomer = PXSelect <Customer, Where <Customer.bAccountID, Equal <Optional <CABankTran.payeeBAccountID> > > > .Select(graph); PaymentEntry.CalcBalances <TInvoice, ARAdjust>(curyInfoSelect, adj.AdjgCuryInfoID, adj.AdjdCuryInfoID, invoice, adj); if (DiscOnDiscDate) { PaymentEntry.CalcDiscount <TInvoice, ARAdjust>(adj.AdjgDocDate, invoice, adj); } PaymentEntry.WarnDiscount <TInvoice, ARAdjust>(graph, adj.AdjgDocDate, invoice, adj); CurrencyInfo pay_info = curyInfoSelect.Select(adj.AdjgCuryInfoID); CurrencyInfo vouch_info = curyInfoSelect.Select(adj.AdjdCuryInfoID); if (vouch_info != null && string.Equals(pay_info.CuryID, vouch_info.CuryID) == false) { adj.AdjdCuryRate = Math.Round((vouch_info.CuryMultDiv == "M" ? (decimal)vouch_info.CuryRate : 1 / (decimal)vouch_info.CuryRate) * (pay_info.CuryMultDiv == "M" ? 1 / (decimal)pay_info.CuryRate : (decimal)pay_info.CuryRate), 8, MidpointRounding.AwayFromZero); } else { adj.AdjdCuryRate = 1m; } if (currentCustomer != null && currentCustomer.SmallBalanceAllow == true && adj.AdjgDocType != ARDocType.Refund && adj.AdjdDocType != ARDocType.CreditMemo) { decimal payment_smallbalancelimit; CurrencyInfo payment_info = curyInfoSelect.Select(adj.AdjgCuryInfoID); PXDBCurrencyAttribute.CuryConvCury(curyInfoSelect.Cache, payment_info, currentCustomer.SmallBalanceLimit ?? 0m, out payment_smallbalancelimit); adj.CuryWOBal = payment_smallbalancelimit; adj.WOBal = currentCustomer.SmallBalanceLimit; } else { adj.CuryWOBal = 0m; adj.WOBal = 0m; } PaymentEntry.AdjustBalance <ARAdjust>(curyInfoSelect, adj); if (isCalcRGOL && (adj.Voided != true)) { PaymentEntry.CalcRGOL <TInvoice, ARAdjust>(curyInfoSelect, invoice, adj); adj.RGOLAmt = (bool)adj.ReverseGainLoss ? -1.0m * adj.RGOLAmt : adj.RGOLAmt; } }
/// <summary> /// Returnes <c>true</c> if the same document is entered as an adjusting and adjusted document. /// </summary> public static bool IsSelfAdjustment(this ARAdjust adj) { return(adj.AdjdDocType == adj.AdjgDocType && adj.AdjdRefNbr == adj.AdjgRefNbr); }
public virtual void LoadInvoicesProc(bool LoadExistingOnly, PX.Objects.AR.ARPaymentEntry.LoadOptions opts) { Dictionary <string, ARAdjust> existing = new Dictionary <string, ARAdjust>(); ARPayment currentDoc = Base.Document.Current; InternalCall = true; try { if (currentDoc == null || currentDoc.CustomerID == null || currentDoc.OpenDoc == false || currentDoc.DocType != ARDocType.Payment && currentDoc.DocType != ARDocType.Prepayment && currentDoc.DocType != ARDocType.CreditMemo) { throw new PXLoadInvoiceException(); } foreach (PXResult <ARAdjust> res in Base.Adjustments_Raw.Select()) { ARAdjust old_adj = (ARAdjust)res; if (LoadExistingOnly == false) { old_adj = PXCache <ARAdjust> .CreateCopy(old_adj); old_adj.CuryAdjgAmt = null; old_adj.CuryAdjgDiscAmt = null; } string s = string.Format("{0}_{1}", old_adj.AdjdDocType, old_adj.AdjdRefNbr); existing.Add(s, old_adj); Base.Adjustments.Cache.Delete((ARAdjust)res); } currentDoc.LineCntr++; if (Base.Document.Cache.GetStatus(currentDoc) == PXEntryStatus.Notchanged || Base.Document.Cache.GetStatus(currentDoc) == PXEntryStatus.Held) { Base.Document.Cache.SetStatus(currentDoc, PXEntryStatus.Updated); } Base.Document.Cache.IsDirty = true; foreach (KeyValuePair <string, ARAdjust> res in existing) { ARAdjust adj = new ARAdjust(); adj.AdjdDocType = res.Value.AdjdDocType; adj.AdjdRefNbr = res.Value.AdjdRefNbr; try { adj = PXCache <ARAdjust> .CreateCopy(AddAdjustment(adj)); if (res.Value.CuryAdjgDiscAmt != null && res.Value.CuryAdjgDiscAmt < adj.CuryAdjgDiscAmt) { adj.CuryAdjgDiscAmt = res.Value.CuryAdjgDiscAmt; adj = PXCache <ARAdjust> .CreateCopy((ARAdjust)Base.Adjustments.Cache.Update(adj)); } if (res.Value.CuryAdjgAmt != null && res.Value.CuryAdjgAmt < adj.CuryAdjgAmt) { adj.CuryAdjgAmt = res.Value.CuryAdjgAmt; Base.Adjustments.Cache.Update(adj); } } catch (PXSetPropertyException) { } } if (LoadExistingOnly) { return; } PXGraph graph = Base; PXResultset <ARInvoice> custdocs = GetCustDocs(opts, currentDoc, Base.arsetup.Current, graph); //changed from custdocs to Adjustments2.Cache.Updated foreach (ARInvoice invoice in Adjustments2.Cache.Updated) { //if it is not checked, skip. else, insert it. if (invoice.Selected != true) { continue; } string s = string.Format("{0}_{1}", invoice.DocType, invoice.RefNbr); if (existing.ContainsKey(s) == false) { ARAdjust adj = new ARAdjust(); adj.AdjdDocType = invoice.DocType; adj.AdjdRefNbr = invoice.RefNbr; AddAdjustment(adj); } } if (currentDoc.CuryApplAmt < 0m) { List <ARAdjust> credits = new List <ARAdjust>(); foreach (ARAdjust adj in Base.Adjustments_Raw.Select()) { if (adj.AdjdDocType == ARDocType.CreditMemo) { credits.Add(adj); } } credits.Sort((a, b) => { return(((IComparable)a.CuryAdjgAmt).CompareTo(b.CuryAdjgAmt)); }); foreach (ARAdjust adj in credits) { if (adj.CuryAdjgAmt <= -currentDoc.CuryApplAmt) { Base.Adjustments.Delete(adj); } else { ARAdjust copy = PXCache <ARAdjust> .CreateCopy(adj); copy.CuryAdjgAmt += currentDoc.CuryApplAmt; Base.Adjustments.Update(copy); } } } } catch (PXLoadInvoiceException) { } finally { InternalCall = false; } }