BLC中的自定义方法

时间:2018-09-05 23:00:56

标签: acumatica

我需要修改以下方法。我想让未用余额变为负数。我有一个付款流程,将所有发票添加到付款中。然后,用户将添加平衡收支所需的任何贷项通知单。我知道需要更改哪些代码,但它在方法的中间。我可以重写该方法,但是不确定在哪里调用基本处理程序。我一直在审查T300,但它没有在我的大脑中点击。我应该先调用基本库,然后在扩展中重新编码最后几行吗?

    private void ARAdjust_AdjdRefNbr_FieldUpdated<T>(PXResult<T, CurrencyInfo> res, ARAdjust adj)
        where T : ARRegister, IInvoice, new()
    {
        CurrencyInfo info_copy = PXCache<CurrencyInfo>.CreateCopy((CurrencyInfo)res);
        info_copy.CuryInfoID = null;
        info_copy = (CurrencyInfo)currencyinfo.Cache.Insert(info_copy);
        T invoice = (T)res;

        //currencyinfo.Cache.SetValueExt<CurrencyInfo.curyEffDate>(info_copy, Document.Current.DocDate);
        info_copy.SetCuryEffDate(currencyinfo.Cache, Document.Current.DocDate);

        adj.CustomerID = Document.Current.CustomerID;
        adj.AdjgDocDate = Document.Current.AdjDate;
        adj.AdjgCuryInfoID = Document.Current.CuryInfoID;
        adj.AdjdCustomerID = invoice.CustomerID;
        adj.AdjdCuryInfoID = info_copy.CuryInfoID;
        adj.AdjdOrigCuryInfoID = invoice.CuryInfoID;
        adj.AdjdBranchID = invoice.BranchID;
        adj.AdjdARAcct = invoice.ARAccountID;
        adj.AdjdARSub = invoice.ARSubID;
        adj.AdjdDocDate = invoice.DocDate;
        adj.AdjdFinPeriodID = invoice.FinPeriodID;
        adj.AdjdHasPPDTaxes = invoice.HasPPDTaxes;
        adj.Released = false;
        adj.PendingPPD = false;

        CalcBalances<T>(adj, invoice, false);

        decimal? CuryApplAmt = adj.CuryDocBal - adj.CuryDiscBal;
        decimal? CuryApplDiscAmt = adj.CuryDiscBal;
        decimal? CuryUnappliedBal = Document.Current.CuryUnappliedBal;

//=======================================================================
// I need to add this compare to stop the existing Acumatica logic from
// limiting the application amount to the amount of the unapplied balance 
// for payments generated by my EDI import.  See comment below
//
        if (Document.Current != null && Document.Current.docDesc.Substring(0, 4) == "EDI:")
            return;
//======================================================================

        if (adj.CuryDiscBal >= 0m && adj.CuryDocBal - adj.CuryDiscBal <= 0m)
        {
            //no amount suggestion is possible
            return;
        }

        if (Document.Current != null && adj.AdjgBalSign < 0m)
        {
            if (CuryUnappliedBal < 0m)
            {
                CuryApplAmt = Math.Min((decimal)CuryApplAmt, Math.Abs((decimal)CuryUnappliedBal));
            }
        }
//=================================================================
// This code is part of original Acumatica and will not apply more to an 
// invoice than is available in the payment amount.  It will only apply
// the minimum of document amount or unapplied balance.
//
        else if (Document.Current != null && CuryUnappliedBal > 0m && adj.AdjgBalSign > 0m)
        {
            CuryApplAmt = Math.Min((decimal)CuryApplAmt, (decimal)CuryUnappliedBal);
//=========================================================================
            if (CuryApplAmt + CuryApplDiscAmt < adj.CuryDocBal)
            {
                CuryApplDiscAmt = 0m;
            }
        }
        else if (Document.Current != null && CuryUnappliedBal <= 0m && ((ARPayment)Document.Current).CuryOrigDocAmt > 0)
        {
            CuryApplAmt = 0m;
            CuryApplDiscAmt = 0m;
        }

        adj.CuryAdjgAmt = CuryApplAmt;
        adj.CuryAdjgDiscAmt = CuryApplDiscAmt;
        adj.CuryAdjgPPDAmt = CuryApplDiscAmt;
        adj.CuryAdjgWOAmt = 0m;

        CalcBalances<T>(adj, invoice, true);
    }

1 个答案:

答案 0 :(得分:0)

我找到了一个似乎可行的解决方案,但如果发现问题,请对此发表评论。遍历基本代码后,我确定了需要更改哪些字段以始终支付剩余的发票余额。我唯一的问题(我认为)是我无法从扩展名中调用ARPaymentEntry图中的CalcBalances方法。我能够调用公共的PaymentEntry.CalcBalances方法,所以我希望可以。如果付款没有被搁置且余额不平衡,我还为付款添加了一个例外。请对任何看起来不正确的内容发表评论。

using PX.Data;
using PX.Objects.CM;

namespace PX.Objects.AR
{
    public class ARPaymentEntry_Extension : PXGraphExtension<ARPaymentEntry>
    {
        #region Event Handlers
        protected void ARPayment_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e,
            PXRowUpdated InvokeBaseHandler)
        {
            if (InvokeBaseHandler != null)
                InvokeBaseHandler(sender, e);
            ARPayment payment = (ARPayment)e.Row;
            if (payment.OpenDoc == true && payment.Hold != true)
            {
                if ((payment.CuryUnappliedBal != 0m) && !(bool)payment.Hold)
                {
                    sender.RaiseExceptionHandling<ARPayment.curyOrigDocAmt>(payment, 
                        payment.CuryOrigDocAmt, 
                        new PXSetPropertyException(Messages.DocumentOutOfBalance));
                }
                else
                {
                    sender.RaiseExceptionHandling<ARPayment.curyOrigDocAmt>
                        (payment, null, null);
                }
            }
        }

        protected void ARAdjust_AdjdRefNbr_FieldUpdated(PXCache cache, 
            PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
        {
            if (InvokeBaseHandler != null)
                InvokeBaseHandler(cache, e);

            ARAdjust adj = (ARAdjust)e.Row;

            foreach (PXResult<ARInvoice, CurrencyInfo> res in
                Base.ARInvoice_DocType_RefNbr.Select(adj.AdjdDocType, adj.AdjdRefNbr))
            {
                ARInvoice invoice = (ARInvoice)res;
                CurrencyInfo curInfo = (CurrencyInfo)res;
                if (Base.Document.Current != null && 
                    Base.Document.Current.DocDesc.Substring(0, 4) == "EDI:")
                {
                    adj.CuryAdjgAmt = invoice.CuryOrigDocAmt;
                    PaymentEntry.CalcBalances<ARInvoice, ARAdjust>
                        (Base.CurrencyInfo_CuryInfoID, adj.AdjdCuryInfoID, 
                             Base.Document.Current.DocDate, invoice, adj);
                }
            }
        }
        #endregion
    }
}