单据转换插件,动态表单插件,表单插件,服务插件,多单据体 应用

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

单据转换插件,动态表单插件,表单插件,服务插件,多单据体 应用

image.webp

多单据体,要二开绑定列上所有数据,二开的单据转换插件

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);
                        }
                    }
                }
            }

        }

    }
}


image.webp

表单插件:
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;
                }

         &nbs

单据转换插件,动态表单插件,表单插件,服务插件,多单据体 应用

多单据体,要二开绑定列上所有数据,二开的单据转换插件using Kingdee.BOS;using Kingdee.BOS.App;using Kingdee.BOS.Contracts;using Kingde...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息