二开方案示例:根据凭证生成过滤方案调用凭证生成服务(仅供参考)

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

二开方案示例:根据凭证生成过滤方案调用凭证生成服务(仅供参考)

**调用方式:** VoucherBuild.BuildVoucher(context,filterSchemeId); **查询本次生成凭证报告:** ShowGenerateResult(view); ```c# using Kingdee.BOS; using Kingdee.BOS.Core.Bill; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.List; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Core.SqlBuilder; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using Kingdee.K3.FIN.Core; using Kingdee.K3.FIN.GL.ServiceHelper; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Kingdee.K3.FIN.GL.Business.PlugIn.BizVoucher { /// /// 二开方案示例:根据凭证生成过滤方案调用凭证生成服务 /// public static class VoucherBuild { private static string text = Kingdee.BOS.Resource.ResManager.LoadKDString("全部", "003032000001777", Kingdee.BOS.Resource.SubSystemType.FIN); /// /// 会计日历 /// private static DynamicObjectCollection calendarObject = null; /// /// 事务id:联查凭证报告 /// private static string TransactionID = SequentialGuid.NewGuid().ToString(); /// /// 调用凭证生成服务 /// /// <param name="ctx">上下文</param> /// <param name="filterSchemeId">过滤方案Id:可查询T_BAS_VCHGENESCHEME、T_BAS_VCHGENESCHEME_L表获取方案id</param> public static void BuildVoucher(Context ctx, int filterSchemeId) { List<VchSelectBookInfor> lstVchSelectBookInfor = GetBookPara(ctx, filterSchemeId); if (lstVchSelectBookInfor!=null && lstVchSelectBookInfor.Count > 0) { //调用凭证生成服务 BizVchMakeSchemeInfor bizVchMakeSchemeInfor = new BizVchMakeSchemeInfor(); bizVchMakeSchemeInfor.SelectBooks = lstVchSelectBookInfor; bizVchMakeSchemeInfor.JumpFromWhere = JumpFromWhere.No; BuildVoucherServiceHelper.BuildVoucher(ctx, bizVchMakeSchemeInfor); } } /// /// 联查本次凭证生成报告 /// /// <param name="view"></param> public static void ShowGenerateResult(IBillView view) { ListShowParameter listpara = new ListShowParameter(); listpara.FormId = "BAS_VchBuildReport"; listpara.ParentPageId = view.PageId; listpara.PageId = Guid.NewGuid().ToString(); listpara.OpenStyle.ShowType = ShowType.MainNewTabPage; listpara.IsShowFilter = false; listpara.CustomParams.Add("SubSystemId", SystemKeyConst.SYSTEM_FINBI); listpara.ListFilterParameter.Filter = string.Format(" FMakeGroupID = '{0}' ", TransactionID); view.ShowForm(listpara); } /// /// 根据过滤方案填充凭证生成账簿等信息 /// /// <param name="ctx"></param> /// <param name="filterSchemeId"></param> /// <returns></returns> private static List<VchSelectBookInfor> GetBookPara(Context ctx, int filterSchemeId) { // 获取过滤方案 FormMetadata metaData = MetaDataServiceHelper.GetFormMetaData(ctx, BusinessObjectConst.Bas_MakeBizVchWizard); DynamicObject scheme = BusinessDataServiceHelper.LoadSingle(ctx, filterSchemeId, metaData.BusinessInfo.GetDynamicObjectType()); DynamicObjectCollection doBookColc = scheme["VchGeneScmEntry"] as DynamicObjectCollection; if (doBookColc == null || doBookColc.Count == 0) { return new List<VchSelectBookInfor> (); } // 构造凭证生成所需账簿和单据信息(类似凭证生成界面选账簿和单据) List<VchSelectBookInfor> lstVchSelectBookInfor = new List<VchSelectBookInfor>(); for (int i = 0; i < doBookColc.Count; i++) { DynamicObject bookInfoDyc = doBookColc[i]["ACCTBOOKID"] as DynamicObject; if (bookInfoDyc == null || !(bookInfoDyc is DynamicObject)) { continue; } DynamicObjectCollection doBillColc = doBookColc[i]["VchGeneScmDetail"] as DynamicObjectCollection; if (doBillColc == null) { continue; } // 账簿及凭证生成方式相关信息 VchSelectBookInfor vchSelectBookInfor = new VchSelectBookInfor(); vchSelectBookInfor.AccountTableID = Convert.ToInt64(bookInfoDyc["AccountTable_Id"]);// 科目表内码 vchSelectBookInfor.AcctSystemID = Convert.ToInt64(bookInfoDyc["AcctSystemID_Id"]);//核算体系内码 vchSelectBookInfor.BookID = Convert.ToInt64(bookInfoDyc["Id"]);//账簿内码 vchSelectBookInfor.GenerateType = Convert.ToString(doBookColc[i]["ACTIONTYPE"]);//凭证生成方式:0代表仅生成业务凭证,1代表业务凭证生成总账凭证,2代表单据生成业务凭证和总账凭证 vchSelectBookInfor.Period = Convert.ToString(doBookColc[i]["Period"]); //凭证生成的年度期间 vchSelectBookInfor.TransactionID = TransactionID;//事务ID vchSelectBookInfor.AcctOrgID = Convert.ToInt64(bookInfoDyc["AccountOrgID_Id"]);//核算组织内码 vchSelectBookInfor.AcctBookCalID = Convert.ToInt64(bookInfoDyc["AccountCalendar_Id"]);//会计日历内码 vchSelectBookInfor.AcctPolicyID = Convert.ToInt64(bookInfoDyc["AcctPolicyID_Id"]);//会计政策内码 int currentYear = bookInfoDyc["CURRENTYEAR"] == null ? 0 : Convert.ToInt32(bookInfoDyc["CURRENTYEAR"]); int currentPeriod = bookInfoDyc["CURRENTPERIOD"] == null ? 0 : Convert.ToInt32(bookInfoDyc["CURRENTPERIOD"]); string strPeriod = string.Empty; if (string.IsNullOrWhiteSpace(doBookColc[i].GetValue<string>("PERIOD"))) { //设置账簿的期间默认为当前期间 strPeriod = string.Format("{0}.{1}", currentYear, currentPeriod); } else { string[] yearAndPeriod = doBookColc[i].GetValue<string>("PERIOD", "").Split('.'); if (yearAndPeriod.Count() != 2 || (Convert.ToInt32(yearAndPeriod[0]) * 100 + Convert.ToInt32(yearAndPeriod[1])) < (currentYear * 100 + currentPeriod)) { //设置账簿的期间默认为当前期间 strPeriod = string.Format("{0}.{1}", currentYear, currentPeriod); } else { strPeriod = doBookColc[i].GetValue<string>("PERIOD"); } } vchSelectBookInfor.Period = strPeriod; SetBookStartEndDate(vchSelectBookInfor, ctx); SetBillScope(doBillColc, vchSelectBookInfor); if (vchSelectBookInfor.SelectSourceBills == null || vchSelectBookInfor.SelectSourceBills.Count <= 0) { continue; } lstVchSelectBookInfor.Add(vchSelectBookInfor); } return lstVchSelectBookInfor; } /// /// 设置单据信息 /// /// <param name="doBillColc"></param> /// <param name="vchSelectBookInfor"></param> private static void SetBillScope(DynamicObjectCollection doBillColc, VchSelectBookInfor vchSelectBookInfor) { for (int j = 0; j < doBillColc.Count; j++) { DynamicObject souurceBillKey = doBillColc[j]["SOURCEBILLKEY"] as DynamicObject; if (souurceBillKey == null) { continue; } //设置子单据体的单据范围为全部 doBillColc[j]["BILLFILTER"] = text; // 账簿下的单据 VchSelectSourceBillInfor vchSelectSourceBillInfor = new VchSelectSourceBillInfor(); vchSelectSourceBillInfor.SystemID = Convert.ToString(souurceBillKey["SubSysID_Id"]); //子系统内码,财务会计-应收款管理 vchSelectSourceBillInfor.SourceBillKey = doBillColc[j]["SOURCEBILLKEY_ID"] == null ? string.Empty : doBillColc[j]["SOURCEBILLKEY_ID"].ToString(); ;//单据标识 vchSelectSourceBillInfor.UnoinType = VoucherUnionType.UnoinAll;//一对一生成凭证、汇总生成凭证、全部汇总生成凭证 if (doBillColc[j]["GenerateType"] != null) { switch (doBillColc[j]["GenerateType"].ToString()) { case "0": vchSelectSourceBillInfor.UnoinType = VoucherUnionType.Sigle; break; case "1": vchSelectSourceBillInfor.UnoinType = VoucherUnionType.UnoinAll; break; case "2": vchSelectSourceBillInfor.UnoinType = VoucherUnionType.UnoinField; break; } } vchSelectSourceBillInfor.UnoinField = doBillColc[j]["MATCHVALUE"] == null ? string.Empty : doBillColc[j]["MATCHVALUE"].ToString(); ;//汇总生成凭证匹配字段 vchSelectSourceBillInfor.UnoinFieldDesc = doBillColc[j]["MATCHNAME"] == null ? string.Empty : doBillColc[j]["MATCHNAME"].ToString();//匹配字段名称 vchSelectSourceBillInfor.BillIDS = new string[] { };//单据id集合 vchSelectSourceBillInfor.IgnoreBillNetControl = false; vchSelectBookInfor.SelectSourceBills.Add(vchSelectSourceBillInfor); } } /// /// 设置账簿开始结束日期 /// /// <param name="bookInfor"></param> /// <param name="ctx"></param> private static void SetBookStartEndDate(VchSelectBookInfor bookInfor, Context ctx) { if (bookInfor == null || string.IsNullOrWhiteSpace(bookInfor.Period) || bookInfor.Period.IndexOf('.') < 0) { return; } if (calendarObject == null) { GetCalendarInfor(ctx); } long year = 0; long.TryParse(bookInfor.Period.Split('.')[0], out year); long period = 0; long.TryParse(bookInfor.Period.Split('.')[1], out period); DynamicObject calen = calendarObject.FirstOrDefault(e => e.GetValue<long>("FID", 0) == bookInfor.AcctBookCalID && e.GetValue<long>("FYEAR", 0) == year && e.GetValue<long>("FPERIOD", 0) == period); DateTime dtNow = Kingdee.BOS.ServiceHelper.TimeServiceHelper.GetSystemDateTime(ctx); if (calen != null) { bookInfor.SelectDateStart = calen.GetValue<DateTime>("FPERIODSTARTDATE", dtNow.AddYears(500)); bookInfor.SelectDateEnd = calen.GetValue<DateTime>("FPERIODENDDATE", dtNow.AddYears(500)); } } /// /// 获取日历信息 /// /// <param name="ctx"></param> private static void GetCalendarInfor(Context ctx) { string field = "FID,FNumber,FName,FYEAR,FPERIOD,"; field += "FPERIODSTARTDATE,FPERIODENDDATE"; QueryBuilderParemeter para = new QueryBuilderParemeter(); para.FormId = "BD_ACCOUNTCALENDAR"; para.SelectItems = SelectorItemInfo.CreateItems(field); para.OrderByClauseWihtKey = "FID,FYEAR,FPERIOD"; calendarObject = QueryServiceHelper.GetDynamicObjectCollection(ctx, para); } } } ```

二开方案示例:根据凭证生成过滤方案调用凭证生成服务(仅供参考)

**调用方式:**VoucherBuild.BuildVoucher(context,filterSchemeId);**查询本次生成凭证报告:**ShowGenerateResult(view);```c#using Kin...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息