How to paste custom field values from the AR Invoice and AP Bill details directly into GL Transactions?

三世轮回 提交于 2019-12-11 16:07:06

问题


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:


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: after the release of the AR Invoice below:

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: generated during the release of the AP Bill below:



来源:https://stackoverflow.com/questions/48757438/how-to-paste-custom-field-values-from-the-ar-invoice-and-ap-bill-details-directl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!