diff --git a/Pilot_KD_Parino/Sal_Order/PushSaleOutBillPlugIn.cs b/Pilot_KD_Parino/Sal_Order/PushSaleOutBillPlugIn.cs index 1a07541..0b72120 100644 --- a/Pilot_KD_Parino/Sal_Order/PushSaleOutBillPlugIn.cs +++ b/Pilot_KD_Parino/Sal_Order/PushSaleOutBillPlugIn.cs @@ -1,14 +1,18 @@ using Kingdee.BOS; using Kingdee.BOS.App; using Kingdee.BOS.Contracts; +using Kingdee.BOS.Core.Bill; +using Kingdee.BOS.Core; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.Operation; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; +using Kingdee.BOS.Core.Interaction; using Kingdee.BOS.Core.List; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Core.Metadata.ConvertElement; using Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs; +using Kingdee.BOS.Core.Metadata.FormElement; using Kingdee.BOS.Log; using Kingdee.BOS.Orm; using Kingdee.BOS.Orm.DataEntity; @@ -16,6 +20,7 @@ using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using Pilot_KD_Parino.Common; using System; +using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; @@ -28,10 +33,14 @@ namespace Pilot_KD_Parino.Sal_Order { long sScrId = 0; string sScrBillNo = ""; + string fid = "0"; + DynamicObject BillObj = null; + public override void AfterBarItemClick(AfterBarItemClickEventArgs e) { base.AfterBarItemClick(e); string tuiName = ""; + { //备货组织操作备货组织的发货出库单跨组织下推 @@ -39,7 +48,9 @@ namespace Pilot_KD_Parino.Sal_Order { var FEntity = this.View.Model.DataObject; + BillObj = FEntity; var id = FEntity["id"]; + fid = Convert.ToString(id); string formid = FEntity["FFormId"].ToString(); //var detailList = (FEntity["SAL_DELIVERYNOTICEENTRY"]); @@ -504,16 +515,40 @@ namespace Pilot_KD_Parino.Sal_Order ////合并转换操作结果 //result.MergeResult(convertResult); - + ////目标单据数据集合 DynamicObject[] destObjs = convertResult.TargetDataEntities.Select(r => r.DataEntity).ToArray(); + ////目标单元数据 + FormMetadata destFormMetadata = ServiceHelper.GetService().Load(this.Context, target) as FormMetadata; + var sdsas = JsonHelper.ToJson(destObjs); Logger.Error("目标单据数据集合", sdsas, new Exception()); int temStockId = stockId; if (target == "PUR_ReceiveBill")//收料通知单,强制没有配置仓库的物料进成品仓库 { - //var sheet = destObjs.FirstOrDefault(); PUR_ReceiveEntry + //var sheet = destObjs.FirstOrDefault(); PUR_ReceiveEntry + + //提取单签销售出库单物料和数量转为字典 + var itemList = BillObj["SAL_OUTSTOCKENTRY"] as DynamicObjectCollection; + Dictionary MaterialCode = new Dictionary(); + foreach (var item in itemList) + { + var Material = item["MaterialID"] as DynamicObject; + if (Material != null) + { + string code2 = (Material["Number"].ToString()); + decimal qty = decimal.Parse(item["RealQty"].ToString()); + if (!MaterialCode.ContainsKey(code2)) + { + MaterialCode.Add(code2, qty); + } + else + MaterialCode[code2] = MaterialCode[code2] + qty; + } + } + + string pur = ("PUR_ReceiveEntry"); var stocks3 = destObjs[0]; @@ -536,12 +571,40 @@ namespace Pilot_KD_Parino.Sal_Order var stocks = stocks333 as DynamicObjectCollection; var stock0 = stocks.ToList(); + //拆分下推情况下匹配物料自动删减数量或删减行 + List deleteItem = new List(); stock0.ForEach(t => { t["StockID_Id"] = temStockId; + + var Material = t["MaterialID"] as DynamicObject; + if (Material != null) + { + string code2 = (Material["Number"].ToString()); + decimal qty = decimal.Parse(t["ActReceiveQty"].ToString()); + if (MaterialCode.ContainsKey(code2)) + { + if (MaterialCode[code2] != qty) + { + t["ActReceiveQty"] = MaterialCode[code2]; + } + } + else + { + deleteItem.Add(t); + } + } }); - - + if (deleteItem.Count > 0) + { + deleteItem.ForEach(t => + { + stock0.Remove(t); + }); + } + IOperationResult saveResult0 = ServiceHelper.GetService().Save(this.Context, destFormMetadata.BusinessInfo, destObjs, OperateOption.Create()); + //调用FActReceiveQty字段值更新服务 + InvokeFieldUpdate(Convert.ToString(stocks3["Id"])); //if (stock0.Count > 0) //{ @@ -676,8 +739,7 @@ namespace Pilot_KD_Parino.Sal_Order //} //#endregion - ////目标单元数据 - FormMetadata destFormMetadata = ServiceHelper.GetService().Load(this.Context, target) as FormMetadata; + IOperationResult saveResult2 = BusinessDataServiceHelper.Draft(this.Context, destFormMetadata.BusinessInfo, destObjs, OperateOption.Create()); ////保存目标单据 IOperationResult saveResult = ServiceHelper.GetService().Save(this.Context, destFormMetadata.BusinessInfo, destObjs, OperateOption.Create()); @@ -715,6 +777,14 @@ namespace Pilot_KD_Parino.Sal_Order var errorInfo = string.Join(";", auditResult.InteractionContext.SimpleMessage); throw new KDBusinessException("", name+"自动审核失败!" + errorInfo); } + + //插入自动生成记录 + string insertSql = $@"/*dialect*/INSERT INTO zz_zTuiSongLog + (Fid,FromType,TargetType,TFid,Creater,CreateTime) + VALUES + ({fid},'SAL_OUTSTOCK','{target}',{Convert.ToString(destObjs[0]["Id"])},'{this.Context.UserName}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')"; + DBServiceHelper.Execute(this.Context, insertSql); + //显示下推后的单据 //ShowPushResult("k0f9e182dbc5247fcabc9479ddb300fa3", convertResult, destObjs); return result; @@ -729,7 +799,127 @@ namespace Pilot_KD_Parino.Sal_Order - + /// + /// 调用字段值更新服务 + /// + /// + private void InvokeFieldUpdate(string FID) + { + // 构建一个IBillView实例,通过此实例,可以方便的填写补卡申请单各属性 + IBillView billView = this.CreateBillView("PUR_ReceiveBill"); + // 加载一个发货通知单 + ((IBillViewService)billView).LoadData(); + // 触发插件的OnLoad事件: + // 组织控制基类插件,在OnLoad事件中,对主业务组织改变是否提示选项进行初始化。 + // 如果不触发OnLoad事件,会导致主业务组织赋值不成功 + DynamicFormViewPlugInProxy eventProxy = billView.GetService(); + eventProxy.FireOnLoad(); + ModifyBill(billView, FID); + int Rowcount = billView.Model.GetEntryRowCount("FDetailEntity"); + for (int j = 0; j < Rowcount; j++) + { + billView.InvokeFieldUpdateService("FActReceiveQty", j); + billView.UpdateView("FDetailEntity"); + } + // 保存补卡申请单 + OperateOption saveOption = OperateOption.Create(); + this.SaveBill(billView, saveOption); + } + + + public IBillView CreateBillView(string FKEY) + { + // 读取商品类型的元数据 + FormMetadata meta = MetaDataServiceHelper.Load(this.Context, FKEY) as FormMetadata; + Form form = meta.BusinessInfo.GetForm(); + // 创建用于引入数据的单据view + Type type = Type.GetType("Kingdee.BOS.Web.Import.ImportBillView,Kingdee.BOS.Web"); + var billView = (IDynamicFormViewService)Activator.CreateInstance(type); + // 开始初始化billView: + // 创建视图加载参数对象,指定各种参数,如FormId, 视图(LayoutId)等 + BillOpenParameter openParam = this.CreateOpenParameter(meta); + // 动态领域模型服务提供类,通过此类,构建MVC实例 + var provider = form.GetFormServiceProvider(); + billView.Initialize(openParam, provider); + return billView as IBillView; + } + + private BillOpenParameter CreateOpenParameter(FormMetadata meta) + { + Form form = meta.BusinessInfo.GetForm(); + // 指定FormId, LayoutId + BillOpenParameter openParam = new BillOpenParameter(form.Id, meta.GetLayoutInfo().Id); + // 数据库上下文 + openParam.Context = this.Context; + // 本单据模型使用的MVC框架 + openParam.ServiceName = form.FormServiceName; + // 随机产生一个不重复的PageId,作为视图的标识 + openParam.PageId = Guid.NewGuid().ToString(); + // 元数据 + openParam.FormMetaData = meta; + // 界面状态:新增 (修改、查看) + openParam.Status = OperationStatus.ADDNEW; + // 单据主键:本案例演示新建商品类型,不需要设置主键 + openParam.PkValue = null; + // 界面创建目的:普通无特殊目的 (为工作流、为下推、为复制等) + openParam.CreateFrom = CreateFrom.Default; + // 基础资料分组维度:基础资料允许添加多个分组字段,每个分组字段会有一个分组维度 + // 具体分组维度Id,请参阅 form.FormGroups 属性 + openParam.GroupId = ""; + // 基础资料分组:如果需要为新建的基础资料指定所在分组,请设置此属性 + openParam.ParentId = 0; + // 单据类型 + openParam.DefaultBillTypeId = ""; + // 业务流程 + openParam.DefaultBusinessFlowId = ""; + // 主业务组织改变时,不用弹出提示界面 + openParam.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false); + // 插件 + List plugs = form.CreateFormPlugIns(); + openParam.SetCustomParameter(FormConst.PlugIns, plugs); + PreOpenFormEventArgs args = new PreOpenFormEventArgs(this.Context, openParam); + foreach (var plug in plugs) + {// 触发插件PreOpenForm事件,供插件确认是否允许打开界面 + plug.PreOpenForm(args); + } + if (args.Cancel == true) + {// 插件不允许打开界面 + // 本案例不理会插件的诉求,继续.... + } + // 返回 + return openParam; + } + public void SaveBill(IBillView billView, OperateOption saveOption) + { + saveOption.SetIgnoreInteractionFlag(true); + //获取发货通知单表单结构 + Form form = billView.BillBusinessInfo.GetForm(); + if (form.FormIdDynamicProperty != null) + { + form.FormIdDynamicProperty.SetValue(billView.Model.DataObject, form.Id); + } + // 调用保存操作 + IOperationResult saveResult = BusinessDataServiceHelper.Save( + this.Context, + billView.BillBusinessInfo, + billView.Model.DataObject, + saveOption, "Save"); + billView.CommitNetworkCtrl(); + billView.Close(); + } + /// + /// 修改单据 + /// + /// + /// + private void ModifyBill(IBillView billView, string pkValue) + { + billView.OpenParameter.Status = OperationStatus.EDIT; + billView.OpenParameter.CreateFrom = CreateFrom.Default; + billView.OpenParameter.PkValue = pkValue; + billView.OpenParameter.DefaultBillTypeId = string.Empty; + ((IDynamicFormViewService)billView).LoadData(); + } } } diff --git a/Pilot_KD_Parino/Sal_Order/SalDeliveryNoticeAudit.cs b/Pilot_KD_Parino/Sal_Order/SalDeliveryNoticeAudit.cs index 59257cd..da950e4 100644 --- a/Pilot_KD_Parino/Sal_Order/SalDeliveryNoticeAudit.cs +++ b/Pilot_KD_Parino/Sal_Order/SalDeliveryNoticeAudit.cs @@ -2,14 +2,18 @@ using Kingdee.BOS; using Kingdee.BOS.App; using Kingdee.BOS.Contracts; +using Kingdee.BOS.Core.Bill; +using Kingdee.BOS.Core; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.Operation; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; +using Kingdee.BOS.Core.Interaction; using Kingdee.BOS.Core.List; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Core.Metadata.ConvertElement; using Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs; +using Kingdee.BOS.Core.Metadata.FormElement; using Kingdee.BOS.Log; using Kingdee.BOS.Orm; using Kingdee.BOS.Orm.DataEntity; @@ -21,6 +25,8 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; +using Kingdee.BOS.Core.Metadata.EntityElement; +using Kingdee.K3.SCM.Common.BusinessEntity.Sales; namespace Pilot_KD_Parino.Sal_Order { @@ -226,6 +232,11 @@ namespace Pilot_KD_Parino.Sal_Order if (MaterialCode[code2] != qty) { item["Qty"] = MaterialCode[code2]; + item["BaseOutMaxQty"] = MaterialCode[code2]; + item["BaseOutMinQty"] = MaterialCode[code2]; + item["RemainOutQty"] = MaterialCode[code2]; + item["OutMaxQty"] = MaterialCode[code2]; + item["OutMinQty"] = MaterialCode[code2]; } } else @@ -240,8 +251,18 @@ namespace Pilot_KD_Parino.Sal_Order { newItemlist.Remove(t); }); - saveResult = ServiceHelper.GetService().Save(this.Context, destFormMetadata.BusinessInfo, destObjs, OperateOption.Create()); + //saveResult = ServiceHelper.GetService().Save(this.Context, destFormMetadata.BusinessInfo, destObjs, OperateOption.Create()); } + saveResult = ServiceHelper.GetService().Save(this.Context, destFormMetadata.BusinessInfo, destObjs, OperateOption.Create()); + //调用Qty字段值更新服务 + InvokeFieldUpdate(Convert.ToString(stocks3["Id"])); + //插入自动生成记录 + string insertSql = $@"/*dialect*/INSERT INTO zz_zTuiSongLog + (Fid,FromType,TargetType,TFid,Creater,CreateTime) + VALUES + ({fid},'SAL_DELIVERYNOTICE','SAL_DELIVERYNOTICE',{Convert.ToString(stocks3["Id"])},'{this.Context.UserName}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')"; + DBServiceHelper.Execute(this.Context, insertSql); + ; } ////合并保存操作结果 @@ -288,6 +309,128 @@ namespace Pilot_KD_Parino.Sal_Order } + /// + /// 调用字段值更新服务 + /// + /// + private void InvokeFieldUpdate(string FID) + { + // 构建一个IBillView实例,通过此实例,可以方便的填写补卡申请单各属性 + IBillView billView = this.CreateBillView("SAL_DELIVERYNOTICE"); + // 加载一个发货通知单 + ((IBillViewService)billView).LoadData(); + // 触发插件的OnLoad事件: + // 组织控制基类插件,在OnLoad事件中,对主业务组织改变是否提示选项进行初始化。 + // 如果不触发OnLoad事件,会导致主业务组织赋值不成功 + DynamicFormViewPlugInProxy eventProxy = billView.GetService(); + eventProxy.FireOnLoad(); + ModifyBill(billView, FID); + int Rowcount = billView.Model.GetEntryRowCount("FEntity"); + for (int j = 0; j < Rowcount; j++) + { + billView.InvokeFieldUpdateService("FQty", j); + billView.UpdateView("FEntity"); + } + // 保存补卡申请单 + OperateOption saveOption = OperateOption.Create(); + this.SaveBill(billView, saveOption); + } + + + public IBillView CreateBillView(string FKEY) + { + // 读取商品类型的元数据 + FormMetadata meta = MetaDataServiceHelper.Load(this.Context, FKEY) as FormMetadata; + Form form = meta.BusinessInfo.GetForm(); + // 创建用于引入数据的单据view + Type type = Type.GetType("Kingdee.BOS.Web.Import.ImportBillView,Kingdee.BOS.Web"); + var billView = (IDynamicFormViewService)Activator.CreateInstance(type); + // 开始初始化billView: + // 创建视图加载参数对象,指定各种参数,如FormId, 视图(LayoutId)等 + BillOpenParameter openParam = this.CreateOpenParameter(meta); + // 动态领域模型服务提供类,通过此类,构建MVC实例 + var provider = form.GetFormServiceProvider(); + billView.Initialize(openParam, provider); + return billView as IBillView; + } + + private BillOpenParameter CreateOpenParameter(FormMetadata meta) + { + Form form = meta.BusinessInfo.GetForm(); + // 指定FormId, LayoutId + BillOpenParameter openParam = new BillOpenParameter(form.Id, meta.GetLayoutInfo().Id); + // 数据库上下文 + openParam.Context = this.Context; + // 本单据模型使用的MVC框架 + openParam.ServiceName = form.FormServiceName; + // 随机产生一个不重复的PageId,作为视图的标识 + openParam.PageId = Guid.NewGuid().ToString(); + // 元数据 + openParam.FormMetaData = meta; + // 界面状态:新增 (修改、查看) + openParam.Status = OperationStatus.ADDNEW; + // 单据主键:本案例演示新建商品类型,不需要设置主键 + openParam.PkValue = null; + // 界面创建目的:普通无特殊目的 (为工作流、为下推、为复制等) + openParam.CreateFrom = CreateFrom.Default; + // 基础资料分组维度:基础资料允许添加多个分组字段,每个分组字段会有一个分组维度 + // 具体分组维度Id,请参阅 form.FormGroups 属性 + openParam.GroupId = ""; + // 基础资料分组:如果需要为新建的基础资料指定所在分组,请设置此属性 + openParam.ParentId = 0; + // 单据类型 + openParam.DefaultBillTypeId = ""; + // 业务流程 + openParam.DefaultBusinessFlowId = ""; + // 主业务组织改变时,不用弹出提示界面 + openParam.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false); + // 插件 + List plugs = form.CreateFormPlugIns(); + openParam.SetCustomParameter(FormConst.PlugIns, plugs); + PreOpenFormEventArgs args = new PreOpenFormEventArgs(this.Context, openParam); + foreach (var plug in plugs) + {// 触发插件PreOpenForm事件,供插件确认是否允许打开界面 + plug.PreOpenForm(args); + } + if (args.Cancel == true) + {// 插件不允许打开界面 + // 本案例不理会插件的诉求,继续.... + } + // 返回 + return openParam; + } + public void SaveBill(IBillView billView, OperateOption saveOption) + { + saveOption.SetIgnoreInteractionFlag(true); + //获取发货通知单表单结构 + Form form = billView.BillBusinessInfo.GetForm(); + if (form.FormIdDynamicProperty != null) + { + form.FormIdDynamicProperty.SetValue(billView.Model.DataObject, form.Id); + } + // 调用保存操作 + IOperationResult saveResult = BusinessDataServiceHelper.Save( + this.Context, + billView.BillBusinessInfo, + billView.Model.DataObject, + saveOption, "Save"); + billView.CommitNetworkCtrl(); + billView.Close(); + } + /// + /// 修改单据 + /// + /// + /// + private void ModifyBill(IBillView billView, string pkValue) + { + billView.OpenParameter.Status = OperationStatus.EDIT; + billView.OpenParameter.CreateFrom = CreateFrom.Default; + billView.OpenParameter.PkValue = pkValue; + billView.OpenParameter.DefaultBillTypeId = string.Empty; + ((IDynamicFormViewService)billView).LoadData(); + } + } diff --git a/Pilot_KD_Parino/bin/Debug/IronPython.dll b/Pilot_KD_Parino/bin/Debug/IronPython.dll index c633a5a..94956a6 100644 Binary files a/Pilot_KD_Parino/bin/Debug/IronPython.dll and b/Pilot_KD_Parino/bin/Debug/IronPython.dll differ