采购发票校验文本字段里面的发票号是否跟别的单据重复

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

采购发票校验文本字段里面的发票号是否跟别的单据重复

发票已开始慢慢从以前的纸质发票过渡到电子发票,因电子发票可以重复打印,为了避免重复做账。二开操作插件,录入发票号码时务必录完整,多张发票时以英文的逗号隔开,例如:530201,530202,530203.....


public class OnAddValidatorsHead : AbstractOperationServicePlugIn
    {
        //OnPreparePropertys 数据加载前,确保需要的属性被加载
        //因为需要读取发票号码信息,先必须加载
        public override void OnPreparePropertys(PreparePropertysEventArgs e)
        {
            base.OnPreparePropertys(e);
            //发票号码
            e.FieldKeys.Add("FINVOICENO");
            //单据编号FBillNo
            e.FieldKeys.Add("FBillNo");

        }

        //OnAddValidators操作执行前,加载操作校验器
        public override void OnAddValidators(AddValidatorsEventArgs e)
        {
            base.OnAddValidators(e);
            TestValidator validator = new TestValidator();
            //是否需要校验,true需要
            validator.AlwaysValidate = true;
            //校验单据头FBillHead
            validator.EntityKey = "FBillHead";
            //加载校验器
           
            e.Validators.Add(validator);

        }
        //自定义校验器.派生:AbstractValidator
        private class TestValidator : AbstractValidator
        {
            private string billNo1 = string.Empty;

            //重写方法
            //数组ExtendedDataEntity,传递全部的信息
            public override void Validate(ExtendedDataEntity[] dataEntities, ValidateContext validateContext, Context ctx)
            {   //for循环,读取数据
                foreach (var billFid in dataEntities)
                {
                    //string billNo1 = string.Empty;
                    //string billNo = "";
                    long bill = Convert.ToInt64(billFid["Id"]);
                    string billTypeField = Convert.ToString(billFid["FFormId"]);
                    //string bill = this.View.Model.DataObject["Id"].ToString();
                    string sql = string.Format(@"/*dialect*/SELECT FINVOICENO FROM T_IV_PURCHASEIC WHERE FID <>{0} and FFORMID='{1}'", bill.ToString(), billTypeField.ToString());
                    DynamicObjectCollection doc = DBUtils.ExecuteDynamicObject(this.Context, sql);
                    List<string> list1 = new List<string>();
                    foreach (DynamicObject obj in doc)
                    {
                        list1.Add(obj["FINVOICENO"].ToString());
                    }
                    billNo1 = string.Join(",", list1.ToArray());
                    List<string> IdList = billNo1.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(m => Convert.ToString(m)).ToList();

                    string sql1 = string.Format(@"/*dialect*/SELECT FINVOICENO FROM T_IV_PURCHASEIC WHERE FID ={0}and FFORMID='{1}'", bill.ToString(), billTypeField.ToString());
                    DynamicObjectCollection doc1 = DBUtils.ExecuteDynamicObject(this.Context, sql1);
                    string[] strFID;
                    if (doc1 == null) return;
                    foreach (DynamicObject obj1 in doc1)
                    {

                        strFID = obj1["FINVOICENO"].ToString().Trim().Split(',');
                        for (int row = 0; row < strFID.Length; row++)
                        {
                            var stingfid = strFID[row];
                            //是否包含发票号
                            if (IdList.Contains(stingfid))
                            {   //报错
                                validateContext.AddError(billFid.DataEntity,
                                    new ValidationErrorInfo
                                    ("PurchaserId",//出错的字段Key,可以空
                                    billFid.DataEntity["Id"].ToString(),// 出错的字段Key,可以空
                                    billFid.DataEntityIndex, // 出错的数据包在全部数据包中的顺序
                                    billFid.RowIndex,// 出错的数据行在全部数据行中的顺序,如果校验基于单据头,此为0
                                    "001",//错误编码,可以任意设定一个字符,主要用于追查错误来源
                                    "发票号码 '" + stingfid.ToString() + "' 重复",//错误的详细提示信息 
                                    billFid.BillNo.ToString(),// 错误的简明提示信息
                                    Kingdee.BOS.Core.Validation.ErrorLevel.Error// 错误级别:警告、错误...
                                    ));
                            }

                        }
                    }
                }
                
            }
        }
    }


采购发票校验文本字段里面的发票号是否跟别的单据重复

发票已开始慢慢从以前的纸质发票过渡到电子发票,因电子发票可以重复打印,为了避免重复做账。二开操作插件,录入发票号码时务必录完整,多...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息