出库单据批量填充序列号二开示例(以销售出库单为例)

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

出库单据批量填充序列号二开示例(以销售出库单为例)

在做单时,一行一行分录的去选择序列号比较繁琐,在没有严格管理一定要选择某个序列号时,可以通过自动批量填充的方式进行填写。


处理逻辑:找到符合对应分录库存维度的在库序列号,选出出库数量的序列号填写到单据上。


示例代码如下:

using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;


namespace CustomerPluginService.demo
{
    public class TESTEdit005 : AbstractBillPlugIn
    {
        public override void EntryBarItemClick(BarItemClickEventArgs e)
        {
            if (e.BarItemKey == "按钮标识")
            {
                //获取单据体所有分录
                List<Entity> entrys = this.View.Model.BusinessInfo.Entrys;
                Kingdee.BOS.Core.Metadata.EntityElement.SNSubEntryEntity snSubEntity = null;
                foreach (Kingdee.BOS.Core.Metadata.EntityElement.Entity item in entrys)
                {
                    if (item is Kingdee.BOS.Core.Metadata.EntityElement.SNSubEntryEntity)
                    {
						//找到序列号子单据体
                        snSubEntity = (item as Kingdee.BOS.Core.Metadata.EntityElement.SNSubEntryEntity);
                        break;
                    }
                }

                //获取本单据需要的所有在库序列号
                string sqlText = string.Format(@"SELECT TS.FID,TSE.FENTRYID,TSE.FSEQ,TSE.FBASEUNITQTY,INV.FBASEQTY,INV.FID INVID,MA.FMATERIALID,SM.FSERIALID ,
                                                        SM.FNUMBER AS FSerialNo 
                                                FROM    T_STK_INVENTORY INV --即时库存
                                                        INNER JOIN T_BD_SERIALBILLTRACE TRA ON INV.FID = TRA.FINVID --序列号追踪表
                                                        INNER JOIN ( SELECT MAX(T3.FBILLTRACEID) AS FBILLTRACEID
                                                                     FROM   T_BD_SERIALBILLTRACE T3
                                                                            INNER JOIN ( SELECT DISTINCT
                                                                                                FSERIALID
                                                                                         FROM   T_BD_SERIALBILLTRACE
                                                                                       ) T4 ON T4.FSERIALID = T3.FSERIALID
                                                                     WHERE  T3.FINVID <> ' '
                                                                     GROUP BY T3.FSERIALID
                                                                   ) TRA2 ON TRA2.FBILLTRACEID = TRA.FBILLTRACEID --一个序列号存在多条追踪记录时只取最近的
                                                        INNER JOIN T_BD_SERIALMASTER SM ON SM.FSERIALID = TRA.FSERIALID --序列号主档
                                                        INNER JOIN T_BD_MATERIAL MA ON MA.FMASTERID = INV.FMATERIALID  --物料主表
                                                                                       AND MA.FUSEORGID = INV.FSTOCKORGID
                                                        INNER JOIN T_BD_MATERIALSTOCK c_stock ON c_stock.FMATERIALID=MA.FMATERIALID
                                                        LEFT JOIN T_BD_LOTMASTER lot ON lot.FLOTID=INV.FLOT
                                                        LEFT JOIN T_ENG_BOM bom ON bom.FMASTERID=INV.FBOMID AND bom.FUSEORGID=INV.FSTOCKORGID														
                                                        LEFT JOIN V_ITEMCLASS_OWNER owner ON owner.fmasterid=INV.FOWNERID AND owner.fformid=INV.FOWNERTYPEID
                                                        LEFT JOIN V_ITEMCLASS_KEEPER keeper ON keeper.fmasterid=INV.FKEEPERID AND keeper.fformid=INV.FKEEPERTYPEID
                                                        INNER JOIN T_SAL_OUTSTOCKENTRY TSE ON TSE.FMATERIALID=MA.FMATERIALID AND TSE.FSTOCKID=INV.FSTOCKID
                                                        AND TSE.FAUXPROPID=inv.FAUXPROPID AND TSE.FSTOCKLOCID=INV.FSTOCKLOCID AND TSE.FSTOCKSTATUSID=INV.FSTOCKSTATUSID
                                                        AND ISNULL(TSE.FLOT_TEXT,' ')=ISNULL(lot.FNUMBER,' ') AND TSE.FBOMID=ISNULL(bom.FID,0) AND TSE.FOWNERTYPEID=INV.FOWNERTYPEID AND TSE.FOWNERID=owner.fitemid
                                                        AND TSE.FKEEPERTYPEID=INV.FKEEPERTYPEID AND TSE.FKEEPERID=keeper.fitemid 
                                                        AND ((c_stock.FISEXPPARTOFLOT='1' AND c_stock.FISKFPERIOD='1' AND TSE.FPRODUCEDATE=lot.FPRODUCEDATE AND TSE.FEXPIRYDATE=lot.FEXPIRYDATE)
                                                        OR (c_stock.FISEXPPARTOFLOT='0' AND c_stock.FISKFPERIOD='1' AND TSE.FPRODUCEDATE=INV.FPRODUCEDATE AND TSE.FEXPIRYDATE=INV.FEXPIRYDATE)
                                                        OR c_stock.FISKFPERIOD='0')
                                                        AND TSE.FMTONO=INV.FMTONO
                                                        INNER JOIN T_SAL_OUTSTOCK TS ON TS.FSTOCKORGID=INV.FSTOCKORGID AND TS.FID=TSE.FID
                                                WHERE   SM.FFORBIDSTATUS = 'A'
                                                        AND TRA.FSTATE = '1'
                                                        AND TS.FID={0}
                                                        ORDER BY TSE.FENTRYID,TSE.FSEQ,SM.FNUMBER", this.View.Model.GetPKValue().ToString());
                DynamicObjectCollection snAllData = DBServiceHelper.ExecuteDynamicObject(this.Context, sqlText);

                DynamicObjectCollection dyObjs = this.View.Model.GetEntityDataObject(snSubEntity.ParentEntity);
                //已经使用的序列号
                List<long> usedSns = new List<long>();
                foreach (DynamicObject dyObj in dyObjs)
                {
                    //获取序列号数量
                    int snQty = Convert.ToInt32(dyObj["SNQty"]);
                    if (snQty <= 0)
                    {
                        continue;
                    }

                    DynamicObjectCollection snDyObjs = dyObj[snSubEntity.EntryName] as DynamicObjectCollection;
                    //判断如果已经有不为空的序列号则跳过
                    if (snDyObjs != null && snDyObjs.Count > 0)
                    {
                        var existSNData = snDyObjs.Where(m => !string.IsNullOrWhiteSpace(m["SerialNo"].ToString())).ToArray();
                        if (existSNData.Length > 0)
                        {
                            continue;
                        }
                    }
                    snDyObjs.Clear();
                    //获取当前分录的序列号数据,排除已经使用过的
                    var snData = snAllData.Where(m => Convert.ToInt64(m["FENTRYID"]) == Convert.ToInt64(dyObj["Id"]) && !usedSns.Exists(n => n == Convert.ToInt64(m["FSERIALID"]))).ToArray();
                    int snDataLen = snData.Length;
                    int countNum = snDataLen > snQty ? snQty : snDataLen;
                    for (int i = 0; i < countNum; i++)
                    {
                        DynamicObject newSerialEntryData = new DynamicObject(snDyObjs.DynamicCollectionItemPropertyType);
                        newSerialEntryData["SerialId_Id"] = snData[i]["FSERIALID"];
                        newSerialEntryData["Seq"] = i + 1;
                        newSerialEntryData["SerialNo"] = Convert.ToString(snData[i]["FSerialNo"]);
                        snDyObjs.Add(newSerialEntryData);
                        usedSns.Add(Convert.ToInt64(snData[i]["FSERIALID"]));
                    }
                }

                this.View.UpdateView(snSubEntity.Key);
            }
        }
    }
}



单据表单插件示例代码参考附件。出库单据批量填充序列号二开示例(以销售出库单为例).zip


出库单据批量填充序列号二开示例(以销售出库单为例)

在做单时,一行一行分录的去选择序列号比较繁琐,在没有严格管理一定要选择某个序列号时,可以通过自动批量填充的方式进行填写。处理逻辑:...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息