单据转换插件,动态表单插件,表单插件,服务插件,多单据体 应用原创
10人赞赏了该文章
2,754次浏览
编辑于2022年04月13日 11:40:06
摘要由AI智能服务提供
该文本描述了一个名为`PoToPocPaymentPlan`的类,该类继承自`AbstractConvertPlugIn`,用于金蝶BOS平台中的单据转换插件。此插件主要处理采购订单(PO)到采购订单变更单(PO变更单)的转换,并在转换过程中携带付款计划信息。插件通过重写`OnGetSourceData`和`AfterConvert`方法来实现其功能。`OnGetSourceData`方法用于从源单据中获取所有相关的采购订单号(FBillNo),并在转换完成后,`AfterConvert`方法用于在目标单据(采购订单变更单)的付款计划(FIinstallment)中插入或更新付款计划信息。该信息通过查询数据库中的相关采购订单安装款记录并动态生成新的付款计划行来实现。插件使用了金蝶BOS的多种服务类和工具类,如`DBServiceHelper`、`IViewService`等,来执行数据库操作和视图服务调用。
多单据体,要二开绑定列上所有数据,二开的单据转换插件 using Kingdee.BOS; using Kingdee.BOS.App; using Kingdee.BOS.Contracts; using Kingdee.BOS.Core; using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn; using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args; using Kingdee.BOS.Core.Metadata.EntityElement; using Kingdee.BOS.Core.Metadata.FieldElement; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace HANS.SalesOutboundSave { [Description("采购订单下推采购订单变更单携带付款计划到付款计划"), HotUpdate] public class PoToPocPaymentPlan : AbstractConvertPlugIn { List<string> FBillNo = new List<string>(); public override void OnGetSourceData(GetSourceDataEventArgs e) { var sourceData = e.SourceData; if (!sourceData.IsEmpty()) { for (int i = 0, ilen = sourceData.Count; i < ilen; i++) { FBillNo.Add(Convert.ToString(sourceData[i]["FBillNo"])); } FBillNo = FBillNo.Distinct().ToList(); } } public override void AfterConvert(AfterConvertEventArgs e) { base.AfterConvert(e); // 获取生成的全部下游单据 Entity mainEntity = e.TargetBusinessInfo.GetEntity("FIinstallment"); ExtendedDataEntity[] billDataEntitys = e.Result.FindByEntityKey("FBillHead"); // 对下游单据,逐张单据进行处理 Entity obj = e.TargetBusinessInfo.GetEntryEntity("FIinstallment");//单据体标识 foreach (var item in billDataEntitys) { DynamicObject dataObject = item.DataEntity; DynamicObjectCollection SaleOrderEntry = dataObject["POChangeEntry"] as DynamicObjectCollection; string srcBillNo = Convert.ToString(SaleOrderEntry[0]["OrderFBillNo"]); DynamicObjectCollection secondEntryRows = mainEntity.DynamicProperty.GetValue(dataObject) as DynamicObjectCollection; secondEntryRows.Remove(secondEntryRows[0]); List<SqlParam> ___SqlParam = new List<SqlParam>(); foreach (string billNo in FBillNo) { string SQL = String.Format(@"select x.* from T_PUR_POORDERINSTALLMENT x inner join t_PUR_POOrder y on x.fid=y.fid where y.FBILLNO=@FBILLNO order by x.FSEQ ASC "); ___SqlParam.Add(new SqlParam("@FBILLNO", KDDbType.String, billNo)); DynamicObjectCollection doc = DBServiceHelper.ExecuteDynamicObject(this.Context, SQL, null, null, System.Data.CommandType.Text, ___SqlParam.ToArray()); ___SqlParam.Clear(); foreach (DynamicObject OB in doc) { DynamicObject newRow = new DynamicObject(obj.DynamicObjectType); DynamicObject Material = null; IViewService Service = ServiceHelper.GetService<IViewService>(); if (billNo.Equals(srcBillNo)) { newRow["Seq"] = Convert.ToString(OB["FSEQ"]); //应付比例(%),应付金额 newRow["YFRATIO"] = Convert.ToString(OB["FYFRATIO"]); newRow["YFAMOUNT"] = Convert.ToString(OB["FYFAMOUNT"]); //新应付比例(%),新应付金额 newRow["FYFRATIOEDIT"] = Convert.ToString(OB["FYFRATIO"]); newRow["FYFAMOUNTEDIT"] = Convert.ToString(OB["FYFAMOUNT"]); string FISPREPAYMENT = Convert.ToString(OB["FISPREPAYMENT"]); newRow["ISPREPAYMENT"] = string.IsNullOrEmpty(FISPREPAYMENT) ?false:(FISPREPAYMENT.Equals("1") ? true : false); newRow["RelBillNo"] = Convert.ToString(OB["FRELBILLNO"]); newRow["InsPrepaidAmount"] = Convert.ToString(OB["FPREPAIDAMOUNT"]); newRow["ACTUALAMOUNT"] = Convert.ToString(OB["FACTUALAMOUNT"]); newRow["PayJoinAmount"] = Convert.ToString(OB["FPAYJOINAMOUNT"]); newRow["FREMARKS"] = Convert.ToString(OB["FREMARKS"]); //物料 string FPAYMATERIALID = Convert.ToString(OB["FPAYMATERIALID"]); if (!FPAYMATERIALID.IsNullOrEmptyOrWhiteSpace() && Convert.ToInt64(FPAYMATERIALID)>0) { BaseDataField baseDataField = e.TargetBusinessInfo.GetField("FPayMaterialId") as BaseDataField; Utils.SetBaseDataValue(Service, newRow, baseDataField, Convert.ToInt64(FPAYMATERIALID), ref Material,this.Context); Material = null; } //物料行号 newRow["FMATERIALSEQ"] = Convert.ToString(OB["FMATERIALSEQ"]); newRow["PayPlanQty"] = Convert.ToString(OB["FPAYPLANQTY"]); newRow["PayPlanPrice"] = Convert.ToString(OB["FPAYPLANPRICE"]); newRow["AppliedQty"] = Convert.ToString(OB["FAPPLIEDQTY"]); newRow["ActualPayQty"] = Convert.ToString(OB["FACTUALPAYQTY"]); newRow["APPLYAMOUNT"] = Convert.ToString(OB["FAPPLYAMOUNT"]); newRow["FPURCHASEORDERNO"] = Convert.ToString(OB["FPURCHASEORDERNO"]); newRow["OrderEntryId"] = Convert.ToString(OB["FORDERENTRYID"]); newRow["InsPayAdvanceRate"] = Convert.ToString(OB["FPAYADVANCERATE"]); newRow["InsPayAdvanceAmount"] = Convert.ToString(OB["FPAYADVANCEAMOUNT"]); // string FPAYPLANPRICEUNITID = Convert.ToString(OB["FPAYPLANPRICEUNITID"]); if (!FPAYPLANPRICEUNITID.IsNullOrEmptyOrWhiteSpace() && Convert.ToInt64(FPAYPLANPRICEUNITID) > 0) { BaseDataField baseDataField = e.TargetBusinessInfo.GetField("FPAYPLANPRICEUNITID") as BaseDataField; Utils.SetBaseDataValue(Service, newRow, baseDataField, Convert.ToInt64(FPAYPLANPRICEUNITID), ref Material, this.Context); Material = null; } string FBASEPRICEUNIT = Convert.ToString(OB["FBASEPRICEUNIT"]); if (!FBASEPRICEUNIT.IsNullOrEmptyOrWhiteSpace() && Convert.ToInt64(FBASEPRICEUNIT) > 0) { BaseDataField baseDataField = e.TargetBusinessInfo.GetField("FBASEPRICEUNIT") as BaseDataField; Utils.SetBaseDataValue(Service, newRow, baseDataField, Convert.ToInt64(FBASEPRICEUNIT), ref Material, this.Context); Material = null; } newRow["BasePayPlanQty"] = Convert.ToString(OB["FBASEPAYPLANQTY"]); newRow["PayMaterialDesc"] = Convert.ToString(OB["FPAYMATERIALDESC"]); //PayModel string FPAYAUXPROPID = Convert.ToString(OB["FPAYAUXPROPID"]); if (!FPAYAUXPROPID.IsNullOrEmptyOrWhiteSpace() && Convert.ToInt64(FPAYAUXPROPID) > 0) { RelatedFlexGroupField baseDataField = e.TargetBusinessInfo.GetField("FPAYAUXPROPID") as RelatedFlexGroupField; Utils.SetFlexDataValue(Service, newRow, baseDataField, Convert.ToInt64(FPAYAUXPROPID), ref Material, this.Context); Material = null; } newRow["F_HANS_APPLYAMOUNT"] = Convert.ToString(OB["F_HANS_APPLYAMOUNT"]); newRow["F_HANS_APPLIEDQTY"] = Convert.ToString(OB["F_HANS_APPLIEDQTY"]); //付款申请项目中心是否审批 string F_HANS_WETHERPUSH = Convert.ToString(OB["F_HANS_WETHERPUSH"]); newRow["F_HANS_WETHERPUSH"] = string.IsNullOrEmpty(F_HANS_WETHERPUSH) ? false : (F_HANS_WETHERPUSH.Equals("1") ? true : false); string F_HANS_LASTAUDIT = Convert.ToString(OB["F_HANS_LASTAUDIT"]); if (!F_HANS_LASTAUDIT.IsNullOrEmptyOrWhiteSpace() && Convert.ToInt64(F_HANS_LASTAUDIT) > 0) { BaseDataField baseDataField = e.TargetBusinessInfo.GetField("F_HANS_LASTAUDIT") as BaseDataField; Utils.SetBaseDataValue(Service, newRow, baseDataField, Convert.ToInt64(F_HANS_LASTAUDIT), ref Material, this.Context); Material = null; } //是否已下推项目中心付款申请 string F_HANS_PAYPUSHED = Convert.ToString(OB["F_HANS_PAYPUSHED"]); newRow["F_HANS_PAYPUSHED"] = string.IsNullOrEmpty(F_HANS_PAYPUSHED) ? false : (F_HANS_PAYPUSHED.Equals("1") ? true : false); newRow["F_HANS_INIAMOUNT"] = Convert.ToString(OB["F_HANS_INIAMOUNT"]); //添加 secondEntryRows.Add(newRow); } } } } } } }
表单插件: using Kingdee.BOS; using Kingdee.BOS.Core.Bill.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.Util; using Kingdee.K3.Core.MFG.EntityHelper; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace HANS.SalesOutboundSave { //新应付金额录入 值更新事件 [Description("采购订单变更单_付款计划_根据新应付金额录入计算出新应付比率"), HotUpdate] public class PocPaymentPlanBillPlugIn : AbstractBillPlugIn { //新应付比例(%): FYFRATIOEDIT //新应付金额: FYFAMOUNTEDIT public override void DataChanged(DataChangedEventArgs e) { base.DataChanged(e); if (e.Field.OriginKey.EqualsIgnoreCase("FYFAMOUNTEDIT")) { int i = e.Row; if (!this.View.GetFieldEditor("FYFAMOUNTEDIT", i).Enabled) return; //历史应付金额 decimal oldFYFAMOUNTEDIT = Convert.ToDecimal(e.OldValue); //新应付金额 decimal newFYFAMOUNTEDIT = Convert.ToDecimal(e.NewValue); DynamicObject o = this.View.Model.DataObject; if (o == null) return; //业务类型:采购订单变更单(业务类型=资产采购订单)时处理,其他情况不处理 var strBusinessType = o.GetDynamicValue<string>("BusinessType"); if (string.IsNullOrEmpty(strBusinessType) || !strBusinessType.Equals("ZCCG", StringComparison.OrdinalIgnoreCase)) return; //原单价之和:POChangeEntry OldPrice decimal totalOldPrice = ((DynamicObjectCollection)o["POChangeEntry"]) .Where(p => p.GetDynamicValue<decimal>("OldPrice") > 0M && p.GetDynamicValue<decimal>("OldQty") > 0M) .Sum(p => (p.GetDynamicValue<decimal>("OldPrice") * p.GetDynamicValue<decimal>("OldQty"))); //最新含税单价之和:POChangeEntry NewPrice decimal totalNewPrice = ((DynamicObjectCollection)o["POChangeEntry"]) .Where(p => p.GetDynamicValue<decimal>("NewPrice") > 0M && p.GetDynamicValue<decimal>("NewQty") > 0M ) .Sum(p => (p.GetDynamicValue<decimal>("NewPrice")* p.GetDynamicValue<decimal>("NewQty"))); /* 情况1:采购订单变更单 金额 变大时,采购订单付款计划可以正常按原应付比例来调整应付金额。付款计划行明细多行数据都会按比例变大。不能手工调整 */ if (totalNewPrice > totalOldPrice) return; if (totalNewPrice <= 0M) return; //付款计划 var PaymentPlanDtolist = o.GetDynamicValue<DynamicObjectCollection>("FIinstallment") .Select(p=> new PaymentPlanDto() { Seq=p.GetDynamicValue<int>("Seq") ,Amted=p.GetDynamicValue<decimal>("YFAMOUNT") ,Rated= p.GetDynamicValue<decimal>("YFRATIO") ,AmtEdit = p.GetDynamicValue<decimal>("FYFAMOUNTEDIT") ,RateEdit= p.GetDynamicValue<decimal>("FYFRATIOEDIT") //实际预付金额,付款关联金额,付款申请关联金额,项目中心付款申请关联金额,初始化已预付金额 ,AmtList = new List<decimal> { p.GetDynamicValue<decimal>("ACTUALAMOUNT",0M) , p.GetDynamicValue<decimal>("PayJoinAmount", 0M) , p.GetDynamicValue<decimal>("APPLYAMOUNT", 0M) , p.GetDynamicValue<decimal>("F_HANS_APPLYAMOUNT", 0M) , p.GetDynamicValue<decimal>("F_HANS_INIAMOUNT", 0M) } }).ToList(); //根据新应付金额计算新应付比率 if (PaymentPlanDtolist.IsEmpty()) return; for (int idx = 0, ilen = PaymentPlanDtolist.Count; idx < ilen; idx++) { PaymentPlanDto dto= PaymentPlanDtolist[idx]; //获取 已经发生的交易金额 中最小值,如果为0,则不受此规则限制 decimal maxAmt = dto.AmtList.Max(x=>x); if(maxAmt <= 0M) { if (idx < (ilen - 1)) { //计算除最后一笔的新应付比率 decimal tmpRatio = (dto.AmtEdit * 100.0M) / totalNewPrice; dto.RateEdit = tmpRatio; } else { //用100去减去除最后一笔的新应付比率之和 dto.RateEdit = 100.00000M - PaymentPlanDtolist.Where(p => p.Seq != ilen).Sum(x => x.RateEdit); } } else { decimal currentAmtEdit = dto.AmtEdit; if(currentAmtEdit< maxAmt) { throw new KDBusinessException("", string.Format("失败原因:付款计划,序号:【{0}】的【新应付金额:{1}】不能小于【{2}】,请调整!", dto.Seq, dto.AmtEdit,maxAmt)); } else { if (idx < (ilen - 1)) { //计算除最后一笔的新应付比率 decimal tmpRatio = (dto.AmtEdit * 100.0M) / totalNewPrice; dto.RateEdit = tmpRatio; } else { //用100去减去除最后一笔的新应付比率之和 dto.RateEdit = 100.00000M - PaymentPlanDtolist.Where(p => p.Seq != ilen).Sum(x => x.RateEdit); } } } } decimal finalTotalAmtEdit = PaymentPlanDtolist.Sum(p => p.AmtEdit); if (finalTotalAmtEdit != totalNewPrice) { throw new KDBusinessException("", string.Format("失败原因:【新采购数量x新单价({0})】不等于【新应付金额({1})】之和,请调整!",totalNewPrice, finalTotalAmtEdit)); } //将计算后的值刷新到视图及模型中 int iLoop=0; PaymentPlanDtolist.OrderBy(p=>p.Seq).ToList().ForEach(x => { this.Model.SetValue("FYFRATIOEDIT", x.RateEdit, iLoop); this.Model.SetValue("FYFAMOUNTEDIT",x.AmtEdit, iLoop); this.View.UpdateView("FYFRATIOEDIT", iLoop); this.View.UpdateView("FYFAMOUNTEDIT", iLoop); iLoop= iLoop+1; }); this.View.UpdateView("FIinstallment"); } } public override void AfterBindData(EventArgs e) { DynamicObject o = this.View.Model.DataObject; if (o == null) return; //业务类型:采购订单变更单(业务类型=资产采购订单)时处理,其他情况不处理 var strBusinessType = o.GetDynamicValue<string>("BusinessType"); if (!string.IsNullOrEmpty(strBusinessType) && strBusinessType.Equals("ZCCG", StringComparison.OrdinalIgnoreCase)) { //更新付款计划 this.View.GetBarItem("", "HANS_tbPaymentPlanEdit").Visible = true; //还原付款计划 this.View.GetBarItem("", "HANS_tbRestorePaymentPlan").Visible = true; //付款计划 页签 this.View.GetControl("FTab_HANS_Update").Visible = true; //付款计划 this.View.GetControl("FIinstallment").Visible = true; } else { //更新付款计划 this.View.GetBarItem("", "HANS_tbPaymentPlanEdit").Visible = false; //还原付款计划 this.View.GetBarItem("", "HANS_tbRestorePaymentPlan").Visible = false; //付款计划 页签 this.View.GetControl("FTab_HANS_Update").Visible = false; //付款计划 this.View.GetControl("FIinstallment").Visible = false; } } } /// <summary> /// 用于临时存储计算出来的金额,比率等数据 /// </summary> public class PaymentPlanDto { public PaymentPlanDto() { } public PaymentPlanDto(int _Seq, decimal _AmtEdit, decimal _RateEdit, decimal _Amted, decimal _Rated,string _poNo) : this() { Seq = _Seq; AmtEdit = _AmtEdit; RateEdit = _RateEdit; Amted = _Amted; Rated = _Rated; poNo = _poNo; AmtList= new List<decimal>(); } /// <summary> /// 采购订单号 /// </summary> public string poNo { get; set; } /// <summary> /// 序号 /// </summary> public int Seq { get; set; } /// <summary> /// 可编辑的金额 /// </summary> public decimal AmtEdit { get; set; } /// <summary> /// 动态计算出来的应付比例 /// </summary> public decimal RateEdit { get; set; } /// <summary> /// 已经发生的金额 /// </summary> public decimal Amted { get; set; } /// <summary> /// 原始 应付比例 /// </summary> public decimal Rated { get; set; } /// <summary> /// 已经发生的交易金额,可能有多个值 /// </summary> public List<decimal> AmtList { get; set; } } } using Kingdee.BOS; using Kingdee.BOS.Core.Bill.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using Kingdee.K3.Core.MFG.EntityHelper; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace HANS.SalesOutboundSave { /* 需求: 1,采购订单变更单变更金额后,需要按照以下情况 处理付款计划明细信息。 2,需要在采购订单变更单上新增付款计划页签,将采购订单上的付款计划页签携带过来变更。不能新增或删除该页签行。 3,变更单上应收金额和比例都需要随着变更后金额变动。变动方式符合以下情况。 条件 1,采购订单 单据类型 = 资产采购订单,其他单据类型不参与变更付款计划。 2,采购订单和变更单的付款计划行应付比例需要等于100% 3,采购订单和变更单的应付比例字段需要保留6位小数 情况1: 采购订单变更单 金额 变大时,采购订单付款计划可以正常按原应付比例来调整应付金额。付款计划行明细多行数据都会按比例变大。不能手工调整 情况2: 采购订单变更单 金额 变小时,采购订单付款计划需要判断是否其他关联预付信息(下游是否有关联付款申请单,如有关联,该行付款计划其他字段会有值),通过手动调整应付金额来修改应付比例。 一:已关联预付信息行:(预付信息金额 等于 实际预付金额,付款关联金额,付款申请关联金额,项目中心付款申请关联金额,初始化已预付金额 中的 最大值) 1,变更金额 少于 预付信息金额,不能变更 , 2,变更金额 等于 预付信息金额,可以变更, 3,变更金额 大于 预付信息金额,可以变更, 二:没关联预付信息行: 需要手动来修改应付金额来重新计算应付比例(注意是采购订单变更单变更后金额进行比例计算)。 */ //更新付款计划 操作绑定的事件 [Description("采购订单变更单点击更新付款计划时,反写变更后的付款计划到采购订单,单据类型等于资产采购订单的付款计划"),HotUpdate] public class PocPaymentPlanReWriteOrderBillPlugIn : AbstractBillPlugIn { public override void BarItemClick(BarItemClickEventArgs e) { if (e.BarItemKey.Equals("HANS_tbPaymentPlanEdit", StringComparison.OrdinalIgnoreCase)) { DynamicObject o = this.Model.DataObject as DynamicObject; if (o == null) return; //业务类型:采购订单变更单(业务类型=资产采购订单)时处理,其他情况不处理 var strBusinessType = o.GetDynamicValue<string>("BusinessType"); var strDocumentStatus = o.GetDynamicValue<string>("DocumentStatus"); if (string.IsNullOrEmpty(strBusinessType) || !strBusinessType.Equals("ZCCG", StringComparison.OrdinalIgnoreCase)) return; if(!string.IsNullOrEmpty(strDocumentStatus) && strDocumentStatus != "C") { this.View.ShowErrMessage("采购订单变更单没有审核通过,不能更新付款计划!"); return; } //原单价之和:POChangeEntry OldPrice decimal totalOldPrice = ((DynamicObjectCollection)o["POChangeEntry"]) .Where(p => p.GetDynamicValue<decimal>("OldPrice") > 0M && p.GetDynamicValue<decimal>("OldQty") > 0M) .Sum(p => (p.GetDynamicValue<decimal>("OldPrice") * p.GetDynamicValue<decimal>("OldQty"))); //最新含税单价之和:POChangeEntry NewPrice decimal totalNewPrice = ((DynamicObjectCollection)o["POChangeEntry"]) .Where(p => p.GetDynamicValue<decimal>("NewPrice") > 0M && p.GetDynamicValue<decimal>("NewQty") > 0M) .Sum(p => (p.GetDynamicValue<decimal>("NewPrice") * p.GetDynamicValue<decimal>("NewQty"))); /* 情况1:采购订单变更单 金额 变大时,采购订单付款计划可以正常按原应付比例来调整应付金额。付款计划行明细多行数据都会按比例变大。不能手工调整 */ if (totalNewPrice > totalOldPrice) { this.View.ShowErrMessage(string.Format("【新变更价总金额:{0}】大于【原变更价总金额:{1}】,不能通过点击【更新付款计划】来更新采购订单的付款计划!", totalNewPrice, totalOldPrice)); return; } /* 情况2: 采购订单变更单 金额 变小时,采购订单付款计划需要判断是否其他关联预付信息(下游是否有关联付款申请单,如有关联,该行付款计划其他字段会有值),通过手动调整应付金额来修改应付比例。 一:已关联预付信息行:(预付信息金额 等于 实际预付金额,付款关联金额,付款申请关联金额,项目中心付款申请关联金额,初始化已预付金额 中的 最大值) 1,变更金额 少于 预付信息金额,不能变更 , 2,变更金额 等于 预付信息金额,可以变更, 3,变更金额 大于 预付信息金额,可以变更, 二:没关联预付信息行: 需要手动来修改应付金额来重新计算应付比例(注意是采购订单变更单变更后金额进行比例计算)。 */ //付款计划 var PaymentPlanDtolist = o.GetDynamicValue<DynamicObjectCollection>("FIinstallment") .Select(p => new PaymentPlanDto() { Seq = p.GetDynamicValue<int>("Seq") ,AmtEdit = p.GetDynamicValue<decimal>("FYFAMOUNTEDIT") ,RateEdit= p.GetDynamicValue<decimal>("FYFRATIOEDIT") ,poNo = p.GetDynamicValue<string>("FPURCHASEORDERNO") }).ToList(); if (PaymentPlanDtolist.IsEmpty()) return; decimal finalTotalAmtEdit = PaymentPlanDtolist.Sum(p => p.AmtEdit); if (finalTotalAmtEdit != totalNewPrice) { throw new KDBusinessException("", string.Format("失败原因:【新采购数量x新单价({0})】不等于【新应付金额({1})】之和.",totalNewPrice,finalTotalAmtEdit)); } decimal finalTotalRatio= PaymentPlanDtolist.Sum(p => p.RateEdit); if (finalTotalRatio != 100.00000M) { throw new KDBusinessException("", string.Format("失败原因:【新应付比例(%)({0})】之和不等于100.00000M.", finalTotalRatio)); } //更新表数据 List<SqlParam> ___SqlParam = new List<SqlParam>(); PaymentPlanDtolist.ForEach(p => { string SQL = @"update T_PUR_POORDERINSTALLMENT set FYFRATIO=@FYFRATIO,FYFAMOUNT=@FYFAMOUNT WHERE FSEQ=@FSEQ AND FPURCHASEORDERNO=@FPURCHASEORDERNO"; ___SqlParam.Add(new SqlParam("@FYFRATIO", KDDbType.Decimal, p.RateEdit)); ___SqlParam.Add(new SqlParam("@FYFAMOUNT", KDDbType.Decimal, p.AmtEdit)); ___SqlParam.Add(new SqlParam("@FSEQ", KDDbType.Int64, p.Seq)); ___SqlParam.Add(new SqlParam("@FPURCHASEORDERNO", KDDbType.String, p.poNo)); DynamicObjectCollection dzs = DBServiceHelper.ExecuteDynamicObject(this.Context, SQL, null, null, System.Data.CommandType.Text, ___SqlParam.ToArray()); ___SqlParam.Clear(); }); //刷新视图 this.View.UpdateView(); this.View.ShowMessage("采购订单中的付款计划更新成功!"); } } } } using Kingdee.BOS; using Kingdee.BOS.Core.Bill.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using Kingdee.K3.Core.MFG.EntityHelper; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace HANS.SalesOutboundSave { //还原付款计划 操作绑定的事件 //采购订单 单据类型 = 资产采购订单,其他单据类型不参与变更付款计划。 [Description("采购订单变更单点还原付款计划时,反写变更后的付款计划到采购订单,单据类型等于资产采购订单的付款计划"),HotUpdate] public class PocPaymentPlanCancelBillPlugIn: AbstractBillPlugIn { public override void BarItemClick(BarItemClickEventArgs e) { if (e.BarItemKey.Equals("HANS_tbRestorePaymentPlan", StringComparison.OrdinalIgnoreCase)) { DynamicObject o = this.Model.DataObject as DynamicObject; if (o == null) return; //业务类型:采购订单变更单(业务类型=资产采购订单)时处理,其他情况不处理 var strBusinessType = o.GetDynamicValue<string>("BusinessType"); var strDocumentStatus = o.GetDynamicValue<string>("DocumentStatus"); if (string.IsNullOrEmpty(strBusinessType) || !strBusinessType.Equals("ZCCG", StringComparison.OrdinalIgnoreCase)) return; if (!string.IsNullOrEmpty(strDocumentStatus) && strDocumentStatus != "C") { this.View.ShowErrMessage("采购订单变更单没有审核通过,不能还原付款计划!"); return; } //原单价之和:POChangeEntry OldPrice decimal totalOldPrice = ((DynamicObjectCollection)o["POChangeEntry"]) .Where(p => p.GetDynamicValue<decimal>("OldPrice") > 0M && p.GetDynamicValue<decimal>("OldQty") > 0M) .Sum(p => (p.GetDynamicValue<decimal>("OldPrice") * p.GetDynamicValue<decimal>("OldQty"))); //最新含税单价之和:POChangeEntry NewPrice decimal totalNewPrice = ((DynamicObjectCollection)o["POChangeEntry"]) .Where(p => p.GetDynamicValue<decimal>("NewPrice") > 0M && p.GetDynamicValue<decimal>("NewQty") > 0M) .Sum(p => (p.GetDynamicValue<decimal>("NewPrice") * p.GetDynamicValue<decimal>("NewQty"))); /* 情况1:采购订单变更单 金额 变大时,采购订单付款计划可以正常按原应付比例来调整应付金额。付款计划行明细多行数据都会按比例变大。不能手工调整 */ if (totalNewPrice > totalOldPrice) { this.View.ShowErrMessage(string.Format("【新变更价总金额:{0}】大于【原变更价总金额:{1}】,不能通过点击【还原付款计划】来更新采购订单的付款计划!", totalNewPrice, totalOldPrice)); return; } /* 情况2: 采购订单变更单 金额 变小时,采购订单付款计划需要判断是否其他关联预付信息(下游是否有关联付款申请单,如有关联,该行付款计划其他字段会有值),通过手动调整应付金额来修改应付比例。 一:已关联预付信息行:(预付信息金额 等于 实际预付金额,付款关联金额,付款申请关联金额,项目中心付款申请关联金额,初始化已预付金额 中的 最大值) 1,变更金额 少于 预付信息金额,不能变更 , 2,变更金额 等于 预付信息金额,可以变更, 3,变更金额 大于 预付信息金额,可以变更, 二:没关联预付信息行: 需要手动来修改应付金额来重新计算应付比例(注意是采购订单变更单变更后金额进行比例计算)。 */ //付款计划 var PaymentPlanDtolist = o.GetDynamicValue<DynamicObjectCollection>("FIinstallment") .Select(p => new PaymentPlanDto() { Seq = p.GetDynamicValue<int>("Seq") , Amted = p.GetDynamicValue<decimal>("YFAMOUNT") , Rated = p.GetDynamicValue<decimal>("YFRATIO") , poNo = p.GetDynamicValue<string>("FPURCHASEORDERNO") }).ToList(); if (PaymentPlanDtolist.IsEmpty()) return; //更新表数据 List<SqlParam> ___SqlParam = new List<SqlParam>(); PaymentPlanDtolist.ForEach(p => { string SQL = @"update T_PUR_POORDERINSTALLMENT set FYFRATIO=@FYFRATIO,FYFAMOUNT=@FYFAMOUNT WHERE FSEQ=@FSEQ AND FPURCHASEORDERNO=@FPURCHASEORDERNO"; ___SqlParam.Add(new SqlParam("@FYFRATIO", KDDbType.Decimal, p.Rated)); ___SqlParam.Add(new SqlParam("@FYFAMOUNT", KDDbType.Decimal, p.Amted)); ___SqlParam.Add(new SqlParam("@FSEQ", KDDbType.Int64, p.Seq)); ___SqlParam.Add(new SqlParam("@FPURCHASEORDERNO", KDDbType.String, p.poNo)); DynamicObjectCollection dzs = DBServiceHelper.ExecuteDynamicObject(this.Context, SQL, null, null, System.Data.CommandType.Text, ___SqlParam.ToArray()); ___SqlParam.Clear(); }); //刷新视图 this.View.UpdateView(); this.View.ShowMessage("采购订单中的付款计划还原成功!"); } } } }
操作插件(审核): using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Util; using System.ComponentModel; namespace HANS.SalesOutboundSave { [Description("采购订单变更单审核时,检查业务类型为资产采购的付款计划计算是否正确"), HotUpdate] public class PocPaymentPlanAudit : AbstractOperationServicePlugIn { public override void OnPreparePropertys(PreparePropertysEventArgs e) { base.OnPreparePropertys(e); //单据编号 e.FieldKeys.Add("FBillNo"); //业务类型 e.FieldKeys.Add("FBUSINESSTYPE"); //原采购数量 e.FieldKeys.Add("FOQty"); //原单价 e.FieldKeys.Add("FOPrice"); //新采购数量 e.FieldKeys.Add("FNQty"); //新单价 e.FieldKeys.Add("FNPrice"); //新应付比例(%) e.FieldKeys.Add("FYFRATIOEDIT"); //新应付金额 e.FieldKeys.Add("FYFAMOUNTEDIT"); } public override void OnAddValidators(AddValidatorsEventArgs e) { base.OnAddValidators(e); PocPaymentPlanValidator validator = new PocPaymentPlanValidator(); validator.AlwaysValidate = true; validator.EntityKey = "FBillHead"; e.Validators.Add(validator); } } } using Kingdee.BOS; using Kingdee.BOS.Core; using Kingdee.BOS.Core.Validation; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.Util; using Kingdee.K3.Core.MFG.EntityHelper; using System; using System.Linq; namespace HANS.SalesOutboundSave { public class PocPaymentPlanValidator : AbstractValidator { public override string EntityKey { get { // 根据实际校验要求,返回单据头或者单据体Key return "FBillHead"; } } public override void Validate(ExtendedDataEntity[] dataEntities, ValidateContext validateContext, Context ctx) { if (dataEntities.IsEmpty()) return; //业务类型: 采购订单变更单(业务类型 = 资产采购订单)时处理,其他情况不处理 var result = dataEntities.Where(o => Convert.ToString(o["BusinessType"]).EqualsIgnoreCase("ZCCG")) .Select(o => new { FBillNo = Convert.ToString(o["FBillNO"]) ,totalOldPrice = ((DynamicObjectCollection)o["POChangeEntry"]) .Where(p => p.GetDynamicValue<decimal>("OldPrice") > 0M && p.GetDynamicValue<decimal>("OldQty") > 0M) .Sum(p => (p.GetDynamicValue<decimal>("OldPrice") * p.GetDynamicValue<decimal>("OldQty"))) ,totalNewPrice = ((DynamicObjectCollection)o["POChangeEntry"]) .Where(p => p.GetDynamicValue<decimal>("NewPrice") > 0M && p.GetDynamicValue<decimal>("NewQty") > 0M) .Sum(p => (p.GetDynamicValue<decimal>("NewPrice") * p.GetDynamicValue<decimal>("NewQty"))) ,totalPayAmt = ((DynamicObjectCollection)o["FIinstallment"]) .Where(p => p.GetDynamicValue<decimal>("FYFAMOUNTEDIT") > 0M) .Sum(p => (p.GetDynamicValue<decimal>("FYFAMOUNTEDIT"))) ,totalRatio = ((DynamicObjectCollection)o["FIinstallment"]) .Where(p => p.GetDynamicValue<decimal>("FYFRATIOEDIT") > 0M) .Sum(p => (p.GetDynamicValue<decimal>("FYFRATIOEDIT"))) }).ToList(); if (!result.IsEmpty()) { result = result.Where(p => p.totalNewPrice <= p.totalOldPrice).ToList(); foreach (var dataEntity in dataEntities) { DynamicObject billHead = dataEntity.DataEntity; string billNo = billHead.GetDynamicValue<string>("FBillNo"); var errorItem = result.Where(p => p.FBillNo == billNo && (p.totalPayAmt != p.totalNewPrice || p.totalRatio != 100.000000M)).FirstOrDefault(); if (errorItem != null) { validateContext.AddError(dataEntity.DataEntity , dataEntity.DataEntityIndex , Kingdee.BOS.Resource.ResManager.LoadKDString(string.Format("单据编号为:{0},失败原因:【新采购数量x新单价:{1}】不等于【新应付金额:{2}】之和,【新应付比例(%):{3}】!!!" , errorItem.FBillNo, errorItem.totalNewPrice, errorItem.totalPayAmt, errorItem.totalRatio) , "015084000025235", Kingdee.BOS.Resource.SubSystemType.SCM)); } } } //throw new KDBusinessException("", string.Format("审核失败")); } } }
动态表单: using Kingdee.BOS; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using Kingdee.K3.Core.MFG.EntityHelper; using System; using System.ComponentModel; namespace HANS.K3.SCM.Bill.Oprate { [Description("动态表单_应用于应收单_收款单,根据单据编号更新销售订单号到单据明细中的销售订单号字段中"), HotUpdate] public class ARReceivableUpdateBillNo : AbstractDynamicFormPlugIn { /// <summary> /// 按钮点击事件 /// </summary> /// <param name="e"></param> public override void ButtonClick(ButtonClickEventArgs e) { if (e.Key.EqualsIgnoreCase("FOkButton")) { // 确定 string billNO = this.View.Model.DataObject.GetDynamicValue<string>("F_HANS_BillNo", string.Empty); if(string.IsNullOrEmpty(billNO)) { e.Cancel = true; this.View.ShowMessage("【销售订单号】必填!"); return; } string SQL = String.Format(@"select t.fid from T_SAL_ORDER t where t.fbillno=@FBILLNO"); billNO = billNO.Trim(); DynamicObjectCollection doc = DBServiceHelper.ExecuteDynamicObject(this.Context, SQL, null, null, System.Data.CommandType.Text, new SqlParam[] { new SqlParam("@FBILLNO", KDDbType.String, billNO)}); if (doc.IsEmpty()) { this.View.ShowMessage("填写的【销售订单号】不存在,请重新填写!"); return; } this.View.ReturnToParentWindow(new FormResult(billNO)); this.View.Close(); } else { // 取消 this.View.Close(); } } } }
列表按钮插件: using Kingdee.BOS; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.List.PlugIn; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; namespace HANS.K3.SCM.Bill.Oprate { [Description("应收单_刷销售订单号,根据单据编号更新销售订单号到单据明细中的销售订单号字段中"), HotUpdate] public class ARReceivableUpdateBillNoListPlugIn : AbstractListPlugIn { /// <summary> /// 列表菜单点击事件 /// </summary> /// <param name="e"></param> public override void BarItemClick(BarItemClickEventArgs e) { if (e.BarItemKey.EqualsIgnoreCase("HANS_tbUpdateOrderNo")) { if (this.ListView.SelectedRowsInfo.IsEmpty()) { this.View.ShowMessage("没有选择任何数据,请先选择数据!"); return; } //获取单据内码及编码 var dtolist = this.ListView.SelectedRowsInfo .Select(p => new Dto(Convert.ToInt64(p.PrimaryKeyValue), Convert.ToString(p.BillNo))) .GroupBy(p => new { Id = p.Id, BillNo = p.BillNo }) .Select(p => new Dto(p.Key.Id, p.Key.BillNo)) .ToList(); if ((!dtolist.IsEmpty()) && dtolist.Count > 1) { this.View.ShowMessage("一次只能选择一条单据数据,请先调整!"); return; } DynamicFormShowParameter showParam = new DynamicFormShowParameter(); showParam.FormId = "HANS_UpdateOrderNo"; this.View.ShowForm(showParam, new Action<FormResult>((formResult) => { if (formResult != null && formResult.ReturnData != null) { string data = formResult.ReturnData.ToString(); if (!string.IsNullOrEmpty(data)) { List<SqlParam> ___SqlParam = new List<SqlParam>(); string SQL = String.Format(@"update t_AR_receivableEntry set FORDERNUMBER=@FORDERNUMBER where exists( select 1 from t_AR_receivable a inner join t_AR_receivableEntry b on a.fid=b.fid where a.fid=@FID and a.fbillno=@FBILLNO and b.fentryid=t_AR_receivableEntry.fentryid )"); var dto = dtolist.First(); ___SqlParam.Add(new SqlParam("@FID", KDDbType.Int64, dto.Id)); ___SqlParam.Add(new SqlParam("@FBILLNO", KDDbType.String, dto.BillNo)); ___SqlParam.Add(new SqlParam("@FORDERNUMBER", KDDbType.String, data)); DynamicObjectCollection doc = DBServiceHelper.ExecuteDynamicObject(this.Context, SQL, null, null, System.Data.CommandType.Text, ___SqlParam.ToArray()); ___SqlParam.Clear(); this.View.ShowMessage("刷销售订单号成功!"); } } })); } } } /// <summary> /// 用于存储单据内码及单据编号 /// </summary> public class Dto { public Dto() { } public Dto(Int64 _Id, string _BillNo) : this() { Id = _Id; BillNo = _BillNo; } /// <summary> /// 内码 /// </summary> public Int64 Id { get; set; } /// <summary> /// 单据编号 /// </summary> public string BillNo { get; set; } } }
using Kingdee.BOS; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.List.PlugIn; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; namespace HANS.K3.SCM.Bill.Oprate { [Description("收款单_刷销售订单号,根据单据编号更新销售订单号到单据明细中的销售订单号字段中"), HotUpdate] public class ARReceivebillUpdateBillNoListPlugIn : AbstractListPlugIn { /// <summary> /// 列表菜单点击事件 /// </summary> /// <param name="e"></param> public override void BarItemClick(BarItemClickEventArgs e) { if (e.BarItemKey.EqualsIgnoreCase("HANS_tbUpdateOrderNo")) { if (this.ListView.SelectedRowsInfo.IsEmpty()) { this.View.ShowMessage("没有选择任何数据,请先选择数据!"); return; } //获取单据内码及编码 var dtolist = this.ListView.SelectedRowsInfo .Select(p => new ___Dto(Convert.ToInt64(p.PrimaryKeyValue), Convert.ToString(p.BillNo))) .GroupBy(p => new { Id = p.Id, BillNo = p.BillNo }) .Select(p => new ___Dto(p.Key.Id, p.Key.BillNo)) .ToList(); if ((!dtolist.IsEmpty()) && dtolist.Count > 1) { this.View.ShowMessage("一次只能选择一条单据数据,请先调整!"); return; } DynamicFormShowParameter showParam = new DynamicFormShowParameter(); showParam.FormId = "HANS_UpdateOrderNo"; this.View.ShowForm(showParam, new Action<FormResult>((formResult) => { if (formResult != null && formResult.ReturnData != null) { string data = formResult.ReturnData.ToString(); if (!string.IsNullOrEmpty(data)) { List<SqlParam> ___SqlParam = new List<SqlParam>(); string SQL = String.Format(@"update T_AR_RECEIVEBILLENTRY set FSALEORDERNO=@FSALEORDERNO where exists( select 1 from T_AR_RECEIVEBILL a inner join T_AR_RECEIVEBILLENTRY b on a.fid=b.fid where a.fid=@FID and a.fbillno=@FBILLNO and T_AR_RECEIVEBILLENTRY.fentryid=b.fentryid )"); var dto = dtolist.First(); ___SqlParam.Add(new SqlParam("@FID", KDDbType.Int64, dto.Id)); ___SqlParam.Add(new SqlParam("@FBILLNO", KDDbType.String, dto.BillNo)); ___SqlParam.Add(new SqlParam("@FSALEORDERNO", KDDbType.String, data)); DynamicObjectCollection doc = DBServiceHelper.ExecuteDynamicObject(this.Context, SQL, null, null, System.Data.CommandType.Text, ___SqlParam.ToArray()); ___SqlParam.Clear(); this.View.ShowMessage("刷销售订单号成功!"); } } })); } } } /// <summary> /// 用于存储单据内码及单据编号 /// </summary> public class ___Dto { public ___Dto() { } public ___Dto(Int64 _Id, string _BillNo) : this() { Id = _Id; BillNo = _BillNo; } /// <summary> /// 内码 /// </summary> public Int64 Id { get; set; } /// <summary> /// 单据编号 /// </summary> public string BillNo { get; set; } } }
赞 10
10人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读