/// <summary> /// 审核 /// </summary> /// <param name="ctx"></param> /// <param name="FormID"></param> /// <param name="ids"></param> /// <returns></returns> public IOperationResult AuditBill(Context ctx, string FormID, object[] ids) { IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>(); //元数据服务 FormMetadata Meta = metaService.Load(ctx, FormID) as FormMetadata; //获取元数据 OperateOption AuditOption = OperateOption.Create(); AuditOption.SetIgnoreWarning(true); AuditOption.SetIgnoreInteractionFlag(true); IOperationResult AuditResult = BusinessDataServiceHelper.Audit(ctx, Meta.BusinessInfo, ids, AuditOption); return(AuditResult); }
}//end method public static IOperationResult DoNothing(this IEnumerable <DynamicObject> dataObject, Context ctx, BusinessInfo businessInfo, string operationNumber, OperateOption option = null) { if (option == null) { option = OperateOption.Create(); } option.SetIgnoreWarning(true); option.SetIgnoreInteractionFlag(true); IOperationResult result = BusinessDataServiceHelper.DoNothingWithDataEntity(ctx, businessInfo, dataObject.ToArray(), operationNumber, option); return(result); } //end method
}//end method public static IOperationResult Submit(this IEnumerable <DynamicObject> dataObject, Context ctx, BusinessInfo businessInfo, OperateOption option = null, Func <DynamicObject, object> selector = null) { if (option == null) { option = OperateOption.Create(); } option.SetIgnoreWarning(true); option.SetIgnoreInteractionFlag(true); object[] pkIds = selector != null?dataObject.Select(selector).ToArray() : dataObject.Select(data => data.PkId()).ToArray(); IOperationResult result = BusinessDataServiceHelper.Submit(ctx, businessInfo, pkIds, "Submit", option); return(result); }//end method
/// <summary> /// 提交进入工作流 /// </summary> /// <param name="ctx"></param> /// <param name="FormID"></param> /// <param name="ids"></param> /// <returns></returns> public IOperationResult SubmitWorkFlowBill(Context ctx, string FormID, string billId) { IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>(); //元数据服务 FormMetadata Meta = metaService.Load(ctx, FormID) as FormMetadata; //获取元数据 // 首先判断单据是否已经有未完成的工作流 IProcInstService procInstService = Kingdee.BOS.Workflow.Contracts.ServiceFactory.GetProcInstService(ctx); bool isExist = procInstService.CheckUnCompletePrcInstExsit(ctx, FormID, billId); if (isExist) { throw new KDBusinessException("AutoSubmit-001", "该单据已经启动了流程,不允许重复提交!"); } // 读取单据的工作流配置模板 IWorkflowTemplateService wfTemplateService = Kingdee.BOS.Workflow.Contracts.ServiceFactory.GetWorkflowTemplateService(ctx); List <FindPrcResult> findProcResultList = wfTemplateService.GetPrcListByFormID( FormID, new string[] { billId }, ctx); if (findProcResultList == null || findProcResultList.Count == 0) { throw new KDBusinessException("AutoSubmit-002", "查找单据适用的流程模板失败,不允许提交工作流!"); } // 设置提交参数:忽略操作过程中的警告,避免与用户交互 OperateOption submitOption = OperateOption.Create(); submitOption.SetIgnoreWarning(true); IOperationResult submitResult = null; FindPrcResult findProcResult = findProcResultList[0]; if (findProcResult.Result == TemplateResultType.Error) { throw new KDBusinessException("AutoSubmit-003", "单据不符合流程启动条件,不允许提交工作流!"); } else if (findProcResult.Result != TemplateResultType.Normal) { // 本单无适用的流程图,直接走传统审批 ISubmitService submitService = ServiceHelper.GetService <ISubmitService>(); submitResult = submitService.Submit(ctx, Meta.BusinessInfo, new object[] { billId }, "Submit", submitOption); } else { // 走工作流 IBOSWorkflowService wfService = Kingdee.BOS.Workflow.Contracts.ServiceFactory.GetBOSWorkflowService(ctx); submitResult = wfService.ListSubmit(ctx, Meta.BusinessInfo, 0, new object[] { billId }, findProcResultList, submitOption); } return(submitResult); }
}//end method public static IOperationResult Forbid(this IEnumerable <DynamicObject> dataObject, Context ctx, BusinessInfo businessInfo, OperateOption option = null, Func <DynamicObject, object> selector = null) { if (option == null) { option = OperateOption.Create(); } option.SetIgnoreWarning(true); option.SetIgnoreInteractionFlag(true); var pkIds = dataObject.Select(data => new KeyValuePair <object, object>(selector != null ? selector(data) : data.PkId(), "")) .ToList(); IOperationResult result = BusinessDataServiceHelper.SetBillStatus(ctx, businessInfo, pkIds, null, OperationNumberConst.OperationNumber_Forbid, option); return(result); }//end method
/// <summary> /// 保存 /// </summary> /// <param name="ctx"></param> /// <param name="FormID">业务对象标识</param> /// <param name="dyObject">保存业务对象集合</param> /// <returns></returns> public IOperationResult SaveBill(Context ctx, string FormID, DynamicObject[] dyObject) { IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>(); FormMetadata targetBillMeta = metaService.Load(ctx, FormID) as FormMetadata; // 构建保存操作参数:设置操作选项值,忽略交互提示 OperateOption saveOption = OperateOption.Create(); // 忽略全部需要交互性质的提示,直接保存; //saveOption.SetIgnoreWarning(true); // 忽略交互提示 //saveOption.SetInteractionFlag(this.Option.GetInteractionFlag()); // 如果有交互,传入用户选择的交互结果 // using Kingdee.BOS.Core.Interaction; //saveOption.SetIgnoreInteractionFlag(this.Option.GetIgnoreInteractionFlag()); //// 如下代码,强制要求忽略交互提示(演示案例不需要,注释掉) saveOption.SetIgnoreWarning(true); //// using Kingdee.BOS.Core.Interaction; saveOption.SetIgnoreInteractionFlag(true); // 调用保存服务,自动保存 ISaveService saveService = ServiceHelper.GetService <ISaveService>(); IOperationResult saveResult = saveService.Save(ctx, targetBillMeta.BusinessInfo, dyObject, saveOption, "Save"); ISubmitService save1Service = ServiceHelper.GetService <ISubmitService>(); return(saveResult); }
/// <summary> /// 保存操作完毕,事务结束之前,进行自动提交、审核 /// </summary> /// <param name="e"></param> public override void EndOperationTransaction(EndOperationTransactionArgs e) { // 取到需要自动提交、审核的单据内码 object[] pkArray = (from p in e.DataEntitys select p[0]).ToArray(); // 设置提交参数 // using Kingdee.BOS.Orm; OperateOption submitOption = OperateOption.Create(); submitOption.SetIgnoreWarning(this.Option.GetIgnoreWarning()); submitOption.SetInteractionFlag(this.Option.GetInteractionFlag()); submitOption.SetIgnoreInteractionFlag(this.Option.GetIgnoreInteractionFlag()); // 创建提交服务:using Kingdee.BOS.Contracts; using Kingdee.BOS.App; ISubmitService submitService = ServiceHelper.GetService <ISubmitService>(); IOperationResult submitResult = submitService.Submit( this.Context, this.BusinessInfo, pkArray, "Submit", submitOption); // 判断提交结果,如果失败,则内部会抛出错误,回滚代码 if (CheckOpResult(submitResult) == false) { return; } // 构建操作可选参数对象 OperateOption auditOption = OperateOption.Create(); auditOption.SetIgnoreWarning(this.Option.GetIgnoreWarning()); auditOption.SetInteractionFlag(this.Option.GetInteractionFlag()); auditOption.SetIgnoreInteractionFlag(this.Option.GetIgnoreInteractionFlag()); // 构建单据主键参数 List <KeyValuePair <object, object> > pkEntityIds = new List <KeyValuePair <object, object> >(); foreach (var pkValue in pkArray) { pkEntityIds.Add(new KeyValuePair <object, object>(pkValue, "")); } List <object> paras = new List <object>(); paras.Add("1"); paras.Add(""); // 调用审核操作 ISetStatusService setStatusService = ServiceHelper.GetService <ISetStatusService>(); // 如下调用方式,需显示交互信息 IOperationResult auditResult = setStatusService.SetBillStatus(this.Context, this.BusinessInfo, pkEntityIds, paras, "Audit", auditOption); // 判断审核结果,如果失败,则内部会抛出错误,回滚代码 if (CheckOpResult(auditResult) == false) { return; } }
/// <summary> /// 自动下推并保存 /// </summary> /// <param name="sourceFormId">源单FormId</param> /// <param name="targetFormId">目标单FormId</param> /// <param name="sourceBillIds">源单内码</param> private IOperationResult DoPush(string sourceFormId, string targetFormId, long targetOrgId, List <long> sourceBillIds) { IOperationResult result = new OperationResult(); result.IsSuccess = false; // 获取源单与目标单的转换规则 IConvertService convertService = Kingdee.BOS.App.ServiceHelper.GetService <IConvertService>(); var rules = convertService.GetConvertRules(this.Context, sourceFormId, targetFormId); if (rules == null || rules.Count == 0) { throw new KDBusinessException("", string.Format("未找到{0}到{1}之间,启用的转换规则,无法自动下推!", sourceFormId, targetFormId)); } // 取勾选了默认选项的规则 var rule = rules.FirstOrDefault(t => t.IsDefault); //var rule = rules. // 如果无默认规则,则取第一个 if (rule == null) { rule = rules[0]; } // 开始构建下推参数: // 待下推的源单数据行 List <ListSelectedRow> srcSelectedRows = new List <ListSelectedRow>(); foreach (var billId in sourceBillIds) {// 把待下推的源单内码,逐个创建ListSelectedRow对象,添加到集合中 srcSelectedRows.Add(new ListSelectedRow(billId.ToString(), string.Empty, 0, sourceFormId)); // 特别说明:上述代码,是整单下推; // 如果需要指定待下推的单据体行,请参照下句代码,在ListSelectedRow中,指定EntryEntityKey以及EntryId //srcSelectedRows.Add(new ListSelectedRow(billId.ToString(), entityId, 0, sourceFormId) { EntryEntityKey = "FEntity" }); } // 指定目标单单据类型:情况比较复杂,没有合适的案例做参照,示例代码暂略,直接留空,会下推到默认的单据类型 string targetBillTypeId = string.Empty; // 指定目标单据主业务组织:情况更加复杂,需要涉及到业务委托关系,缺少合适案例,示例代码暂略 // 建议在转换规则中,配置好主业务组织字段的映射关系:运行时,由系统根据映射关系,自动从上游单据取主业务组织,避免由插件指定 //long targetOrgId = 0; // 自定义参数字典:把一些自定义参数,传递到转换插件中;转换插件再根据这些参数,进行特定处理 Dictionary <string, object> custParams = new Dictionary <string, object>(); // 组装下推参数对象 PushArgs pushArgs = new PushArgs(rule, srcSelectedRows.ToArray()) { TargetBillTypeId = targetBillTypeId, TargetOrgId = targetOrgId, CustomParams = custParams }; // 调用下推服务,生成下游单据数据包 ConvertOperationResult operationResult = convertService.Push(this.Context, pushArgs, OperateOption.Create()); // 开始处理下推结果: // 获取下推生成的下游单据数据包 DynamicObject[] targetBillObjs = (from p in operationResult.TargetDataEntities select p.DataEntity).ToArray(); if (targetBillObjs.Length == 0) { // 未下推成功目标单,抛出错误,中断审核 throw new KDBusinessException("", string.Format("由{0}自动下推{1},没有成功生成数据包,自动下推失败!", sourceFormId, targetFormId)); } // 对下游单据数据包,进行适当的修订,以避免关键字段为空,自动保存失败 // 示例代码略 // 读取目标单据元数据 IMetaDataService metaService = Kingdee.BOS.App.ServiceHelper.GetService <IMetaDataService>(); var targetBillMeta = metaService.Load(this.Context, targetFormId) as FormMetadata; // 构建保存操作参数:设置操作选项值,忽略交互提示 OperateOption saveOption = OperateOption.Create(); // 忽略全部需要交互性质的提示,直接保存; saveOption.SetIgnoreWarning(true); // 忽略交互提示 saveOption.SetInteractionFlag(this.Option.GetInteractionFlag()); // 如果有交互,传入用户选择的交互结果 // using Kingdee.BOS.Core.Interaction; saveOption.SetIgnoreInteractionFlag(this.Option.GetIgnoreInteractionFlag()); // 调用保存服务,自动保存 ISaveService saveService = Kingdee.BOS.App.ServiceHelper.GetService <ISaveService>(); var saveResult = saveService.Save(this.Context, targetBillMeta.BusinessInfo, targetBillObjs, saveOption, "Save"); // 判断自动保存结果:只有操作成功,才会继续 if (saveResult.SuccessDataEnity != null) { var submitRet = AppServiceContext.SubmitService.Submit(this.Context, targetBillMeta.BusinessInfo, saveResult.SuccessDataEnity.Select(o => o["Id"]).ToArray(), "Submit", saveOption); result.MergeResult(submitRet); if (submitRet.SuccessDataEnity != null) { var auditResult = AppServiceContext.SetStatusService.SetBillStatus(this.Context, targetBillMeta.BusinessInfo, submitRet.SuccessDataEnity.Select(o => new KeyValuePair <object, object>(o["Id"], 0)).ToList(), new List <object> { "1", "" }, "Audit", saveOption); result.MergeResult(auditResult); } } if (this.CheckOpResult(saveResult, saveOption)) { return(result); } return(result); }
/// <summary> /// 根据单据唯一标识下推单据 /// </summary> private void PushFormByFormId() { string status = this.View.BillModel.GetValue("FDocumentStatus").ToString(); if (status == "Z") { return; } string formId = this.View.BillView.GetFormId(); string targetFormId = "k0c6b452fa8154c4f8e8e5f55f96bcfac"; // 个人资金 var rules = ConvertServiceHelper.GetConvertRules(this.View.Context, formId, targetFormId); var rule = rules.FirstOrDefault(t => t.IsDefault); string fid = this.View.BillModel.GetPKValue().ToString(); ListSelectedRow[] selectedRows; if (formId == "k0c30c431418e4cf4a60d241a18cb241c") // 出差申请 { int count = this.View.BillModel.GetEntryRowCount("FEntity"); selectedRows = new ListSelectedRow[count]; for (int i = 0; i < count; i++) { string entryId = this.View.BillModel.GetEntryPKValue("FEntryID", i).ToString(); selectedRows[i] = new ListSelectedRow(fid, entryId, i, formId); } } else { ListSelectedRow row = new ListSelectedRow(fid, string.Empty, 0, formId); selectedRows = new ListSelectedRow[] { row }; } // 调用下推服务,生成下游单据数据包 ConvertOperationResult operationResult = null; PushArgs pushArgs = new PushArgs(rule, selectedRows) { TargetBillTypeId = "", TargetOrgId = 0, }; try { //执行下推操作,并获取下推结果 operationResult = ConvertServiceHelper.Push(this.View.Context, pushArgs, OperateOption.Create()); } catch (KDExceptionValidate ex) { this.View.ShowErrMessage(ex.Message, ex.ValidateString); return; } catch (Exception ex) { this.View.ShowErrMessage(ex.Message); return; } // 获取生成的目标单据数据包 DynamicObject[] objs = operationResult.TargetDataEntities.Select(p => p.DataEntity).ToArray(); // 读取目标单据元数据 var targetBillMeta = MetaDataServiceHelper.Load(this.View.Context, targetFormId) as FormMetadata; OperateOption option = OperateOption.Create(); // 忽略全部需要交互性质的提示 option.SetIgnoreWarning(true); // 暂存数据 var saveResult = BusinessDataServiceHelper.Draft(this.View.Context, targetBillMeta.BusinessInfo, objs, option); string targetId = saveResult.SuccessDataEnity.Select(item => item["Id"].ToString()).Distinct().FirstOrDefault(); // 打开目标单据 if (targetId != null) { MobileShowParameter param = new MobileShowParameter(); param.Caption = "个人资金申请"; param.FormId = "ora_GRZJJZ"; param.PKey = targetId; param.ParentPageId = this.View.PageId; param.Status = OperationStatus.EDIT; param.OpenStyle.ShowType = ShowType.Default; this.View.ShowForm(param); } }
/// <summary> /// 后台调用单据转换生成目标单 /// </summary> /// <param name="ctx"></param> /// <param name="option"></param> /// <returns></returns> public static IOperationResult ConvertBills(Context ctx, BillConvertOption option) { IOperationResult result = new OperationResult(); List <DynamicObject> list = new List <DynamicObject>(); ConvertRuleElement rule = AppServiceContext.ConvertService.GetConvertRules(ctx, option.sourceFormId, option.targetFormId) .FirstOrDefault(w => w.Id == option.ConvertRuleKey); FormMetadata metaData = (FormMetadata)AppServiceContext.MetadataService.Load(ctx, option.targetFormId, true); if ((rule != null) && option.BizSelectRows != null && option.BizSelectRows.Count() > 0) { PushArgs serviceArgs = new PushArgs(rule, option.BizSelectRows); serviceArgs.CustomParams.Add("CustomConvertOption", option); serviceArgs.CustomParams.Add("CustomerTransParams", option.customParams); OperateOption operateOption = OperateOption.Create(); operateOption.SetVariableValue("ValidatePermission", true); ConvertOperationResult convertOperationResult = AppServiceContext.ConvertService.Push(ctx, serviceArgs, operateOption); if (!convertOperationResult.IsSuccess) { result = convertOperationResult as IOperationResult; return(result); } DynamicObject[] collection = convertOperationResult.TargetDataEntities .Select(s => s.DataEntity).ToArray(); list.AddRange(collection); } if (list.Count > 0) { AppServiceContext.DBService.LoadReferenceObject(ctx, list.ToArray(), metaData.BusinessInfo.GetDynamicObjectType(), false); } if (option.IsDraft && list.Count > 0) { result = AppServiceContext.DraftService.Draft(ctx, metaData.BusinessInfo, list.ToArray()); } if (!result.IsSuccess) { return(result); } if (option.IsSave && !option.IsDraft && list.Count > 0) { OperateOption operateOption = OperateOption.Create(); operateOption.SetVariableValue("ValidatePermission", true); operateOption.SetIgnoreWarning(true); result = AppServiceContext.SaveService.Save(ctx, metaData.BusinessInfo, list.ToArray(), operateOption); //result = AppServiceContext.SaveService.Save(ctx, metaData.BusinessInfo, list.ToArray()); } if (!result.IsSuccess) { return(result); } if (option.IsSubmit && list.Count > 0) { result = AppServiceContext.SubmitService.Submit(ctx, metaData.BusinessInfo, list.Select(item => ((Object)(Convert.ToInt64(item["Id"])))).ToArray(), "Submit"); } if (!result.IsSuccess) { return(result); } if (option.IsAudit && list.Count > 0) { result = AppServiceContext.SubmitService.Submit(ctx, metaData.BusinessInfo, list.Select(item => ((Object)(Convert.ToInt64(item["Id"])))).ToArray(), "Submit"); if (!result.IsSuccess) { return(result); } List <KeyValuePair <object, object> > keyValuePairs = new List <KeyValuePair <object, object> >(); list.ForEach(item => { keyValuePairs.Add(new KeyValuePair <object, object>(item.GetPrimaryKeyValue(), item)); } ); List <object> auditObjs = new List <object>(); auditObjs.Add("1"); auditObjs.Add(""); //Kingdee.BOS.Util.OperateOptionUtils oou = null; OperateOption ooption = OperateOption.Create(); ooption.SetIgnoreWarning(false); ooption.SetIgnoreInteractionFlag(true); ooption.SetIsThrowValidationInfo(false); result = AppServiceContext.SetStatusService.SetBillStatus(ctx, metaData.BusinessInfo, keyValuePairs, auditObjs, "Audit", ooption); option.BillStatusOptionResult = ooption; if (!result.IsSuccess) { return(result); } } return(result); }
/// <summary> /// 审核结束自动下推(应付单下推付款申请单) /// </summary> /// <param name="e"></param> public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e) { base.AfterExecuteOperationTransaction(e); try { string sql = string.Empty; if (e.DataEntitys != null && e.DataEntitys.Count <DynamicObject>() > 0) { foreach (DynamicObject item in e.DataEntitys) { //收款单id string Fid = item["Id"].ToString(); string sql2 = ""; //收款单源单明细 DynamicObjectCollection RECEIVEBILLSRCENTRYList = item["RECEIVEBILLSRCENTRY"] as DynamicObjectCollection; foreach (var entry in RECEIVEBILLSRCENTRYList) { //销售订单明细内码 string FORDERENTRYID = entry["FSRCORDERENTRYID"].ToString(); //本次收款金额 decimal FREALRECAMOUNT = Convert.ToDecimal(entry["REALRECAMOUNT"].ToString()); if (!string.IsNullOrEmpty(FORDERENTRYID)) { //查询采购订单 sql = string.Format(@"select a.FBILLNO,b.FENTRYID as 采购订单明细内码 ,f.F_YBG_BUSINESSMODEL as 业务模式 from t_PUR_POOrder a inner join t_PUR_POOrderEntry b on a.fID=b.FID inner join T_PUR_POORDERENTRY_LK c on c.FENTRYID=b.FENTRYID left join T_SAL_ORDERENTRY d on d.FENTRYID=c.FSID left join T_SAL_ORDER f on f.FID=d.FID where FSID='{0}'", FORDERENTRYID); DataSet ds = DBServiceHelper.ExecuteDataSet(this.Context, sql); DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { string F_YBG_BUSINESSMODEL = dt.Rows[i]["采购订单明细内码"].ToString(); if (F_YBG_BUSINESSMODEL == "01" || F_YBG_BUSINESSMODEL == "04") //挂靠的采用自动生成付款申请单 { string POFENTRYID = dt.Rows[i]["采购订单明细内码"].ToString(); if (string.IsNullOrEmpty(sql2)) { sql2 += " FPAYABLEENTRYID='" + POFENTRYID + "' "; } else { sql2 += " or FPAYABLEENTRYID='" + POFENTRYID + "' "; } } } } } } if (!string.IsNullOrEmpty(sql2)) { #region 应付单下推付款申请单 string srcFormId = "AP_Payable"; //应付单 string destFormId = "CN_PAYAPPLY"; //付款申请单 IMetaDataService mService = Kingdee.BOS.App.ServiceHelper.GetService <IMetaDataService>(); IViewService vService = Kingdee.BOS.App.ServiceHelper.GetService <IViewService>(); FormMetadata destmeta = mService.Load(this.Context, destFormId) as FormMetadata; //转换规则的唯一标识 string ruleKey = "AP_PayableToPayApply"; //var rules = ConvertServiceHelper.GetConvertRules(Context, srcFormId, destFormId); //var rule = rules.FirstOrDefault(t => t.IsDefault); ConvertRuleElement rule = GetDefaultConvertRule(Context, srcFormId, destFormId, ruleKey); List <ListSelectedRow> lstRows = new List <ListSelectedRow>(); string strsql = "select a.FID , a.FENTRYID from T_AP_PAYABLEPLAN a left join T_AP_PAYABLE b on a.FID=b.FID where b.FDOCUMENTSTATUS='C' and (" + sql2 + ") "; DataSet ds2 = DBServiceHelper.ExecuteDataSet(Context, strsql); if (ds2.Tables[0].Rows.Count > 0) { HashSet <string> hasset = new HashSet <string>(); for (int j = 0; j < ds2.Tables[0].Rows.Count; j++) { hasset.Add(ds2.Tables[0].Rows[j]["FID"].ToString()); long entryId = Convert.ToInt64(ds2.Tables[0].Rows[j]["FENTRYID"]); //源单单据标识 ListSelectedRow row = new ListSelectedRow(ds2.Tables[0].Rows[j]["FID"].ToString(), entryId.ToString(), 0, "AP_Payable"); //源单单据体标识 row.EntryEntityKey = "FEntityPlan"; lstRows.Add(row); } PushArgs pargs = new PushArgs(rule, lstRows.ToArray()); IConvertService cvtService = Kingdee.BOS.App.ServiceHelper.GetService <IConvertService>(); OperateOption option = OperateOption.Create(); option.SetIgnoreWarning(true); option.SetVariableValue("ignoreTransaction", false); option.SetIgnoreInteractionFlag(true); #region 提交审核 //OperateOption option2 = OperateOption.Create(); //option2.SetIgnoreWarning(true); //option2.SetVariableValue("ignoreTransaction", true); //foreach (var hid in hasset) //{ // //如果应付单没有提交先提交审核 // IMetaDataService BomService = Kingdee.BOS.App.ServiceHelper.GetService<IMetaDataService>(); // //应付单元素包 // FormMetadata APMeta = BomService.Load(Context, "AP_Payable") as FormMetadata; // IViewService APVService = Kingdee.BOS.App.ServiceHelper.GetService<IViewService>(); // //应付单数据包 // DynamicObject APmd = APVService.LoadSingle(Context, hid, APMeta.BusinessInfo.GetDynamicObjectType()); // DynamicObject[] dy = new DynamicObject[] { APmd }; // object[] items = dy.Select(p => p["Id"]).ToArray(); // ISubmitService submitService = Kingdee.BOS.App.ServiceHelper.GetService<ISubmitService>(); // IOperationResult submitresult = submitService.Submit(Context, APMeta.BusinessInfo, items, "Submit", option2); // IAuditService auditService = Kingdee.BOS.App.ServiceHelper.GetService<IAuditService>(); // IOperationResult auditresult = auditService.Audit(Context, APMeta.BusinessInfo, items, option2); //} #endregion ConvertOperationResult cvtResult = cvtService.Push(Context, pargs, option, false); if (cvtResult.IsSuccess) { DynamicObject[] dylist = (from p in cvtResult.TargetDataEntities select p.DataEntity).ToArray(); //修改应收单里面数据 for (int K = 0; K < dylist.Length; K++) { //付款原因 dylist[K]["F_YBG_Remarks"] = "供应商付款"; //明细信息 DynamicObjectCollection RECEIVEBILLENTRYList = dylist[K]["FPAYAPPLYENTRY"] as DynamicObjectCollection; foreach (var Entry in RECEIVEBILLENTRYList) { //结算方式 BaseDataField FSETTLETYPEID = destmeta.BusinessInfo.GetField("FSETTLETYPEID") as BaseDataField; Entry["FSETTLETYPEID_Id"] = 4; Entry["FSETTLETYPEID"] = vService.LoadSingle(Context, 4, FSETTLETYPEID.RefFormDynamicObjectType); } } //保存 ISaveService saveService = Kingdee.BOS.App.ServiceHelper.GetService <ISaveService>(); IOperationResult saveresult = saveService.Save(Context, destmeta.BusinessInfo, dylist, option); bool reult = CheckResult(saveresult, out string mssg); if (!reult) { throw new Exception("收款款单审核成功,生成付款申请单失败:"); } else { //纪录核销的纪录 OperateResultCollection operateResults = saveresult.OperateResult; string fnmber = operateResults[0].Number; string fid = operateResults[0].PKValue.ToString(); } } } else { throw new KDException("", "应付单不存在或者未审核,下推付款申请单失败"); } #endregion } } } } catch (Exception ex) { throw new KDException("", "应付单下推付款申请单失败:" + ex.ToString()); } }
/// <summary> /// 后台调用单据转换生成目标单 /// </summary> /// <param name="ctx"></param> /// <param name="option"></param> /// <returns></returns> public static IOperationResult ConvertBills(Context ctx, BillConvertOption option,string billtype) { //return AppServiceContext.ConvertBills(ctx, option); //判断单据类型资产接收单转化为资产应付;费用物料转为办公应付 string billtypeid = ""; if (billtype == "SLD04_SYS") { billtypeid = "56e224fd183867"; } if (billtype == "SLD05_SYS") { billtypeid = "777f5fd25084498a9e77e1ef2a72e645"; } IOperationResult result = new OperationResult(); List<DynamicObject> list = new List<DynamicObject>(); ConvertRuleElement rule = AppServiceContext.ConvertService.GetConvertRules(ctx, option.sourceFormId, option.targetFormId) .FirstOrDefault(w => w.Id == option.ConvertRuleKey); FormMetadata metaData = (FormMetadata)AppServiceContext.MetadataService.Load(ctx, option.targetFormId, true); if ((rule != null) && option.BizSelectRows != null && option.BizSelectRows.Count() > 0) { PushArgs serviceArgs = new PushArgs(rule, option.BizSelectRows) { TargetBillTypeId = billtypeid, }; serviceArgs.CustomParams.Add("CustomConvertOption", option); serviceArgs.CustomParams.Add("CustomerTransParams", option.customParams); OperateOption operateOption = OperateOption.Create(); operateOption.SetVariableValue("ValidatePermission", true); ConvertOperationResult convertOperationResult = AppServiceContext.ConvertService.Push(ctx, serviceArgs, operateOption); if (!convertOperationResult.IsSuccess) { result = convertOperationResult as IOperationResult; return result; } DynamicObject[] collection = convertOperationResult.TargetDataEntities .Select(s => s.DataEntity).ToArray(); list.AddRange(collection); } if (list.Count > 0) { AppServiceContext.DBService.LoadReferenceObject(ctx, list.ToArray(), metaData.BusinessInfo.GetDynamicObjectType(), false); } if (option.IsDraft && list.Count > 0) { result = AppServiceContext.DraftService.Draft(ctx, metaData.BusinessInfo, list.ToArray()); } if (!result.IsSuccess) { return result; } if (option.IsSave && !option.IsDraft && list.Count > 0) { OperateOption operateOption = OperateOption.Create(); operateOption.SetVariableValue("ValidatePermission", true); operateOption.SetIgnoreWarning(true); result = AppServiceContext.SaveService.Save(ctx, metaData.BusinessInfo, list.ToArray(), operateOption); //result = AppServiceContext.SaveService.Save(ctx, metaData.BusinessInfo, list.ToArray()); } if (!result.IsSuccess) { return result; } if (option.IsSubmit && list.Count > 0) { result = AppServiceContext.SubmitService.Submit(ctx, metaData.BusinessInfo, list.Select(item => ((Object)(Convert.ToInt64(item["Id"])))).ToArray(), "Submit"); } if (!result.IsSuccess) { return result; } bool systemParamter = Convert.ToBoolean(Kingdee.BOS.ServiceHelper.SystemParameterServiceHelper.GetParamter(ctx, OrgId, 0, "AP_SystemParameter", "F_VTRAutoReceiveBillPayable"));//获取系统参数生成应付单是否创建状态 if (option.IsAudit && list.Count > 0 && systemParamter==false) { result = AppServiceContext.SubmitService.Submit(ctx, metaData.BusinessInfo, list.Select(item => ((Object)(Convert.ToInt64(item["Id"])))).ToArray(), "Submit"); if (!result.IsSuccess) { return result; } List<KeyValuePair<object, object>> keyValuePairs = new List<KeyValuePair<object, object>>(); list.ForEach(item => { keyValuePairs.Add(new KeyValuePair<object, object>(item.GetPrimaryKeyValue(), item)); } ); List<object> auditObjs = new List<object>(); auditObjs.Add("1"); auditObjs.Add(""); //Kingdee.BOS.Util.OperateOptionUtils oou = null; OperateOption ooption = OperateOption.Create(); ooption.SetIgnoreWarning(false); ooption.SetIgnoreInteractionFlag(true); ooption.SetIsThrowValidationInfo(false); result = AppServiceContext.SetStatusService.SetBillStatus(ctx, metaData.BusinessInfo, keyValuePairs, auditObjs, "Audit", ooption); option.BillStatusOptionResult = ooption; if (!result.IsSuccess) { return result; } } return result; }