新增物料二开设置默认物料计价方法
系统使用一段时间后,由于一些原因需要物料计价方法变更,变更成和核算范围的计价方法不一致的,系统中已有物料可以通过物料计价方法变更功能来处理,但是新增物料每次都需要重新去设置物料计价方法或者做物料计价方法变更,有时候可能忘记去变更,或者新增物料和成本核算的操作人员不是同一个人,难以保持同步,操作较困难。这个时候就可以通过简单的二开来解决此问题。本文以新增物料审核时自动设置物料计价方法为“加权平均法”为例,介绍怎样解决新增物料设置默认计价方法的问题(适应场景仅是新增物料需要设置的计价方法和核算范围的不一致,或者和按物料属性等设置的计价方法不一致时,如果本身是一致的,无需处理,默认就会按核算范围的计价方法或者按物料属性等设置的计价方法)。
一、增加二开审核插件,继承操作服务插件基类AbstractOperationServicePlugIn
重写AfterExecuteOperationTransaction方法,在此方法里面设置新增物料计价方法。只处理在成本核算维度中不存在的物料,并且在物料计价方法中不存在的物料,避免重复审核重复设置,避免分配组织下物料重复设置 ,同时排除不参与核算的物料。
二、在BOS IDE中拓展物料,在物料审核操作上配置第一步新增的插件
三、重启IIS,新增物料测试
新增物料审核后,可以自动生成物料计价方法(只会在已经结束存货核算初始化,并且对应物料的使用组织在核算组织的下级业务组织时,才会自动生成),可以在物料计价方法列表中查到,再次审核时不会重复产生。
附录代码:
/// <summary> /// /// </summary> [Description("二开-新增的物料审核时设置默认物料计价方法")] public class MaterialAuditSetValuationmenthod : AbstractOperationServicePlugIn { /// <summary> /// /// </summary> /// <param name="e"></param> public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e) { base.AfterExecuteOperationTransaction(e); if (e.DataEntitys == null || e.DataEntitys.Length == 0) { return; } var materialIds = e.DataEntitys.Select(k => Convert.ToInt64(k["ID"])).Distinct().ToList(); SetValuationmenthod(materialIds); } /// <summary> /// 根据新增物料设置默认计价方法 /// </summary> /// <param name="materialIds"></param> private void SetValuationmenthod(List<long> materialIds) { if (materialIds == null || materialIds.Count == 0) { return; } // 仅设置核算维度不存在的物料及核算范围,仅设置物料计价方法不存在的物料及核算范围 StringBuilder sqlStr = new StringBuilder(); sqlStr.AppendFormat(" select distinct MAT.FMATERIALID,T1.FACCTGRANGEID,T1.FACCTGSYSTEMID,T1.FACCTGORGID,T1.FACCTPOLICYID "); sqlStr.AppendFormat(" from T_HS_ACCTGRANGE T1 "); sqlStr.AppendFormat(" inner join T_BAS_SYSTEMPROFILE T2 on T1.FACCTGSYSTEMID = T2.FACCTSYSTEMID and T1.FACCTGORGID = T2.FORGID and T1.FACCTPOLICYID = T2.FACCTPOLICYID "); sqlStr.AppendFormat(" inner join T_ORG_ACCTSYSENTRY ACCORG on T1.FACCTGORGID = ACCORG.FMAINORGID and T1.FACCTGSYSTEMID = ACCORG.FACCTSYSTEMID "); sqlStr.AppendFormat(" inner join T_ORG_ACCTSYSDETAIL ACCORGE on ACCORG.FENTRYID = ACCORGE.FENTRYID "); sqlStr.AppendFormat(" inner join T_BD_MATERIAL MAT on ACCORGE.FSUBORGID = mat.FUSEORGID "); sqlStr.AppendFormat(" inner join T_BD_MATERIALBASE MATB on MAT.FMATERIALID = MATB.FMATERIALID "); sqlStr.AppendFormat(" where MAT.FMATERIALID in ({0}) ", string.Join(",", materialIds)); sqlStr.AppendFormat(" and {0} ", CommonFunction.GetMaterialPropertyFilter("MATB")); sqlStr.AppendFormat(" and T1.FFORBIDSTATUS = 'A' and T1.FDOCUMENTSTATUS = 'C' and T2.FCATEGORY = 'HS' and FKEY = 'IsEndInitial' and T2.FVALUE = '1' "); sqlStr.AppendFormat(" and not exists(select 1 from T_HS_STOCKDIMENSION dime "); sqlStr.AppendFormat(" where MAT.FMASTERID = dime.FMASTERID and T1.FACCTGRANGEID = dime.FACCTGRANGEID) "); sqlStr.AppendFormat(" and not exists(select 1 from T_HS_VALUATIONMETHODENTRY T3 "); sqlStr.AppendFormat(" inner join T_HS_VALUATIONMETHOD T4 on T3.FVALUATIONMETHODID = T4.FVALUATIONMETHODID "); sqlStr.AppendFormat(" inner join T_BD_MATERIAL t5 on t3.FMATERIALID = t5.FMATERIALID "); sqlStr.AppendFormat(" where MAT.FMASTERID = t5.FMASTERID and T4.FACCTGRANGEID = T1.FACCTGRANGEID) "); var dys = DBUtils.ExecuteDynamicObject(this.Context, sqlStr.ToString()); if (dys == null || dys.Count == 0) { return; } // 此处以设置“加权平均法”为例(加权平均法:0,移动平均法:1,先进先出法:2) SaveValuationmenthod(dys, "0"); } /// <summary> /// 保存计价方法 /// </summary> /// <param name="newMaterialInfos"></param> /// <param name="ValuationmenthodId">需要设置的计价方法ID,加权平均法:0,移动平均法:1,先进先出法:2</param> private void SaveValuationmenthod(DynamicObjectCollection newMaterialInfos, string ValuationmenthodId) { FormMetadata mete = (FormMetadata)Kingdee.K3.FIN.App.Core.AppServiceContext.MetadataService.Load(this.Context, BusinessObjectConst.HS_VALUATIONMETHOD); BusinessInfo funcInfo = mete.BusinessInfo; List<DynamicObject> bills = new List<DynamicObject>(); var dicInfos = PublicFunction.GetDictInfoFromDynamicObjData<long>(newMaterialInfos, "FACCTGRANGEID"); foreach (var group in dicInfos) { DynamicObject item = group.Value[0]; DynamicObject bill = new DynamicObject(funcInfo.GetDynamicObjectType()); long acctgRangeId = Convert.ToInt64(item["FACCTGRANGEID"]); long acctgSystemId = Convert.ToInt64(item["FACCTGSYSTEMID"]); long acctgOrgId = Convert.ToInt64(item["FACCTGORGID"]); long acctPolicyId = Convert.ToInt64(item["FACCTPOLICYID"]); bill["ACCTGRANGEID_ID"] = acctgRangeId; bill["ACCTGSYSTEMID_ID"] = acctgSystemId; bill["ACCTGORGID_ID"] = acctgOrgId; bill["FACCTPOLICYID_ID"] = acctPolicyId; // 按单个物料设置 bill["RANGEGROUP"] = "2"; bill["CreateOrgId_ID"] = acctgOrgId; bill["UseOrgId_ID"] = acctgOrgId; bill["ForbidStatus"] = "A"; bill["DOCUMENTSTATUS"] = "C"; var entrys = bill["HS_VALUATIONMETHODENTRY"] as DynamicObjectCollection; int rowIndex = 1; foreach (var materialId in group.Value) { DynamicObject newRow = new DynamicObject(entrys.DynamicCollectionItemPropertyType); newRow["SEQ"] = rowIndex++; newRow["MaterialID_ID"] = materialId["FMATERIALID"]; newRow["VALUATIONMETHOD"] = ValuationmenthodId; entrys.Add(newRow); } bills.Add(bill); } DynamicObject[] billArray = bills.ToArray(); AppServiceContext.DBService.LoadReferenceObject(this.Context, billArray, funcInfo.GetDynamicObjectType(), false); OperateOption option = OperateOption.Create(); option.SetVariableValue("BulkCopy", true); IOperationResult result = AppServiceContext.SaveService.Save(this.Context, funcInfo, billArray, option); // 设置不成功的时候提示错误信息 if (!result.IsSuccess) { foreach (var op in result.OperateResult) { if (!op.SuccessStatus) { this.OperationResult.OperateResult.Add(op); } } } }
新增物料二开设置默认物料计价方法
系统使用一段时间后,由于一些原因需要物料计价方法变更,变更成和核算范围的计价方法不一致的,系统中已有物料可以通过物料计价...
点击下载文档
上一篇:合同履约成本分配结果增加二开字段下一篇:存在账面负结存
本文2024-09-23 02:11:57发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-150857.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章