How to paste custom field values from the AR Invoi

2019-08-26 11:43发布

I have created a custom DB-bound field, called Stock Number, in the ARTran, APTran, and GLTran DACs:

public class ARTranExt : PXCacheExtension<PX.Objects.AR.ARTran>
{
    public abstract class usrLineStockNbr : IBqlField { }

    [PXDBString(10)]
    [PXUIField(DisplayName = "Stock Number")]
    public virtual string UsrLineStockNbr { get; set; }
}

public class APTranExt : PXCacheExtension<PX.Objects.AP.APTran>
{
    public abstract class usrLineStockNbr : IBqlField { }

    [PXDBString(10)]
    [PXUIField(DisplayName = "Stock Number")]
    public virtual string UsrLineStockNbr { get; set; }
}

public class GLTranExt : PXCacheExtension<PX.Objects.GL.GLTran>
{
    public abstract class usrLineStockNbr : IBqlField { }

    [PXDBString(10)]
    [PXUIField(DisplayName = "Stock Number")]
    public virtual string UsrLineStockNbr { get; set; }
}

How would I go about pasting my custom field values from the AR Invoice and AP Bill details directly into GL Transactions?

1条回答
Fickle 薄情
2楼-- · 2019-08-26 12:22

To paste custom field value from ARTran to GLTran, you should create an extension for the ARReleaseProcess BLC and override the ReleaseInvoice method as shown in the following sample below:

public class ARReleaseProcess_Extension : PXGraphExtension<PX.Objects.AR.ARReleaseProcess>
{
    public delegate List<ARRegister> ReleaseInvoiceDel(
        JournalEntry je,
        ref ARRegister doc,
        PXResult<ARInvoice, CurrencyInfo, Terms, Customer, Account> res,
        out PMRegister pmDoc);

    [PXOverride]
    public List<ARRegister> ReleaseInvoice(
        JournalEntry je,
        ref ARRegister doc,
        PXResult<ARInvoice, CurrencyInfo, Terms, Customer, Account> res,
        out PMRegister pmDoc,
        ReleaseInvoiceDel del)
    {
        je.RowInserting.AddHandler<GLTran>((s, a) =>
        {
            var tran = (GLTran)a.Row;
            var arTran = (ARTran)PXResult<ARTran>.Current;

            if (tran != null && tran.TranLineNbr != null &&
                arTran != null && arTran.TranType == tran.TranType &&
                arTran.RefNbr == tran.RefNbr && arTran.LineNbr == tran.TranLineNbr)
            {
                var stockNbr = arTran.GetExtension<ARTranExt>().UsrLineStockNbr;
                if (!string.IsNullOrEmpty(stockNbr))
                    tran.GetExtension<GLTranExt>().UsrLineStockNbr = stockNbr;
            }
        });

        return del(je, ref doc, res, out pmDoc);
    }
}

This is how a newly generated GL Batch should look like: enter image description here after the release of the AR Invoice below: enter image description here

To paste custom field value from APTran to GLTran, you should create an extension for the APReleaseProcess BLC and override the ReleaseInvoice method as shown in the following sample below:

public class APReleaseProcess_Extension : PXGraphExtension<PX.Objects.AP.APReleaseProcess>
{
    public delegate List<APRegister> ReleaseInvoiceDel(
        JournalEntry je,
        ref APRegister doc,
        PXResult<APInvoice, CurrencyInfo, Terms, Vendor> res,
        bool isPrebooking,
        out List<INRegister> inDocs);

    [PXOverride]
    public virtual List<APRegister> ReleaseInvoice(
        JournalEntry je,
        ref APRegister doc,
        PXResult<APInvoice, CurrencyInfo, Terms, Vendor> res,
        bool isPrebooking,
        out List<INRegister> inDocs,
        ReleaseInvoiceDel del)
    {
        je.RowInserting.AddHandler<GLTran>((s, a) =>
        {
            var tran = (GLTran)a.Row;
            var apTran = (APTran)PXResult<APTran>.Current;

            if (tran != null && tran.TranLineNbr != null &&
                apTran != null && apTran.TranType == tran.TranType &&
                apTran.RefNbr == tran.RefNbr && apTran.LineNbr == tran.TranLineNbr)
            {
                var stockNbr = apTran.GetExtension<APTranExt>().UsrLineStockNbr;
                if (!string.IsNullOrEmpty(stockNbr))
                    tran.GetExtension<GLTranExt>().UsrLineStockNbr = stockNbr;
            }
        });

        return del(je, ref doc, res, isPrebooking, out inDocs);
    }
}

Here is an example of a new GL Batch: enter image description here generated during the release of the AP Bill below: enter image description here

查看更多
登录 后发表回答