更新总账凭证号至对应单据.单据体

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-23浏览:3

更新总账凭证号至对应单据.单据体

【示例】:将付款单总账凭证的凭证号更新至应付票据单据体

1.扩展应付票据添加凭证信息单据体(因一张收款单可对应多张凭证)

2.添加凭证号字段


3.新增二开插件类。

需继承自AbstractBuildVchSecondDevPlugIn,并实现AfterBookBuildVoucher方法。注意如果是自己新增的类名,在第4步注册的时候,需使用自己的类名

using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.SqlBuilder;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.K3.FIN.Core.PlugIn;
using Kingdee.K3.FIN.Core.PlugIn.Arg;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;

namespace Kingdee.K3.FIN.App.Core.BuildVoucher.PlugIn
{
    [Description("凭证生成二开测试插件")]
    [Serializable]
    public class BuildVchSecondDevTestPlugIn : AbstractBuildVchSecondDevPlugIn
    {
        public override void AfterBookBuildVoucher(BuildVchSecondDevArgs e)
        {
            base.AfterBookBuildVoucher(e);

            if (e.GlVchIds.Count == 0)
            {
                return;
            }
            // 获取付款单对应的应付票据和凭证号

            string sql = string.Format(@"

                                 SELECT T3.FBILLID AS FID,T0.FVOUCHERGROUPNO AS FVCHGROUPNO

                                 FROM T_GL_VOUCHER T0
                                 INNER JOIN T_BAS_VOUCHER T1 ON T1.FGLVOUCHERID=T0.FVOUCHERID
                                 INNER JOIN T_AP_PAYBILL T2 ON T2.FID=T1.FSOURCEBILLID
                                 LEFT JOIN T_AP_PAYBILLPAYABLE T3 ON T3.FID=T2.FID
                                 LEFT JOIN T_AP_VCHINFOENTRY T4 ON T4.FID=T3.FBILLID
                                 WHERE  T1.FSOURCEBILLKEY='AP_PAYBILL' AND T0.FVOUCHERID IN({0})", string.Join(",", e.GlVchIds));

            DynamicObjectCollection dyc = DBUtils.ExecuteDynamicObject(e.Context, sql);
            if (dyc == null || dyc.Count == 0)
            {
                return;
            }

            // 获取分录id
            IDBService service = Kingdee.BOS.App.ServiceHelper.GetService<IDBService>();
            Int32[] entryIDs = service.GetSequenceInt32(e.Context, "T_AP_VCHINFOENTRY", dyc.Count);

            //更新应付票据凭证号
            string insertSql = "INSERT INTO T_AP_VCHINFOENTRY VALUES(@FID,@FENTRYID,@FVCHGROUPNO)";
            List<SqlObject> lstSqlObject = new List<SqlObject>();
            for (int i = 0; i < dyc.Count; i++)
            {
                List<SqlParam> paramList = new List<SqlParam>();
                paramList.Add(new SqlParam("@FID", KDDbType.Int64, Convert.ToInt64(dyc[i]["FID"])));
                paramList.Add(new SqlParam("@FENTRYID", KDDbType.Int64, entryIDs[i]));

                paramList.Add(new SqlParam("@FVCHGROUPNO"

                                                                 KDDbType.Int32, Convert.ToInt32(dyc[i]["FVCHGROUPNO"])));

                lstSqlObject.Add(new SqlObject(insertSql, paramList));
            }
            DBUtils.ExecuteBatch(e.Context, lstSqlObject);
        }
    }
}

4.注册插件,此处注意将蓝色路径改为自己创建的类所在路径

INSERT INTO T_BAS_VCHBUILDPLUGIN (FFORMID,FPLUGIN,FCUSTPLUGIN)

values( 'SECONDDEV','','Kingdee.K3.FIN.App.Core.BuildVoucher.PlugIn.BuildVchSecondDevTestPlugIn,Kingdee.K3.FIN.App.Core')

5.凭证生成测试


更新总账凭证号至对应单据.单据体

【示例】:将付款单总账凭证的凭证号更新至应付票据单据体1.扩展应付票据添加凭证信息单据体(因一张收款单可对应多张凭证)2.添加凭证号字...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息