云星空即时库存及即时库存汇总增加字段原创
3人赞赏了该文章
791次浏览
编辑于2023年12月21日 16:21:24
增加辅助属性字段,比如物料中的单位
先在即时库存增加 基础资料属性字段 修改标识 名称 标题
修改基础资料字段
保存之后查看结果
即时库存汇总同上
增加数值字段
然后编写插件
using Kingdee.BOS; using Kingdee.BOS.Core.List.PlugIn; using Kingdee.BOS.Core.List.PlugIn.Args; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; namespace RealTime.Test { [HotUpdate] [Description("即时库存列表")] public class JskcList : AbstractListPlugIn { /// <summary> /// 是否存在字段 /// </summary> /// <param name="Context"></param> /// <param name="tableName"></param> /// <param name="fields"></param> /// <returns></returns> private static List<string> ExistCol(Context Context, string tableName, List<string> fields) { if (string.IsNullOrWhiteSpace(tableName) || fields == null || fields.Count == 0) { return null; } string sql = @"/*dialect*/ select name FROM syscolumns with(nolock) where id=object_id('{0}') and name IN ({1}) "; var dyo = DBServiceHelper.ExecuteDynamicObject(Context, string.Format(sql, tableName, string.Join(",", fields.Select(s => "'" + s + "'")))); if (dyo != null && dyo.Count > 0) { return dyo.Select(s => s["name"].GetString()).ToList(); } else { return null; } } public override void BeforeGetDataForTempTableAccess(BeforeGetDataForTempTableAccessArgs e) { base.BeforeGetDataForTempTableAccess(e); var fields = new List<string>() { "F_HSSL" }; var haveFields = ExistCol(Context, e.TableName, fields); if (haveFields == null || haveFields.Count == 0) { return; } StringBuilder sql = new StringBuilder(); sql.Append("/*dialect*/ "); sql.Append(" UPDATE a SET "); for (int i = 0; i < haveFields.Count; i++) { if (i > 0) { sql.Append(" , "); } if (haveFields[i].Equals("F_HSSL",System.StringComparison.OrdinalIgnoreCase)) { sql.Append(" a.F_HSSL=a.FQty* isnull(c.F_HSL,0) "); } } sql.AppendFormat(@" from {0} a left join T_BD_MATERIAL c on c.FMATERIALID=a.fmaterialid_id", e.TableName); DBServiceHelper.Execute(Context, sql.ToString()); } } }
即时库存汇总新增数量字段,必须要和即时库存保持一致,不然会找不到字段
编写即时库存汇总列表插件
需继承 Kingdee.K3.SCM.Stock.Business.PlugIn.InvSumQueryList
using Kingdee.BOS.Core.List.PlugIn.Args; using Kingdee.BOS.Util; using System.ComponentModel; using Kingdee.K3.SCM.Stock.Business.PlugIn; using Kingdee.BOS.ServiceHelper; namespace RealTime.Test { [HotUpdate] [Description("即时库存汇总列表")] public class JskchzList : InvSumQueryList { public override void PrepareFilterParameter(FilterArgs e) { base.PrepareFilterParameter(e); string sql = $@"/*dialect*/ UPDATE a SET F_HSSL = a.FQTY * ISNULL(b.F_HSL, 0) FROM T_STK_INVSUMQUERY a LEFT JOIN T_BD_MATERIAL b ON b.FMATERIALID = a.FMATERIALID WHERE FTRANSID = '{ this.TransactionID }' "; DBServiceHelper.Execute(Context, sql); } } }
即时库存汇总列表注册插件的时候需要去除原生的那个Kingdee.K3.SCM.Stock.Business.PlugIn.InvSumQueryList
最后查看效果
推荐阅读