生产订单保存生成生产用料清单,应发数量根据子项单位的单位精度进位或舍位二开方案
1、生产用料清单保存操作上注册二开插件,如下图:
![image.webp](/download/0100b2ff9cd795da471483a7fd97c0041b2b.webp)
2、二开代码示例如下:
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Util;
using Kingdee.K3.Core.MFG.EntityHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS;
using Kingdee.K3.MFG.App;
using Kingdee.K3.Core.BD;
using Kingdee.K3.Core.BD.ServiceArgs;
using Kingdee.K3.Core.MFG.EnumConst;
using Kingdee.BOS.Core.Metadata;
using Kingdee.K3.MFG.Contracts.PRD;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Enums;
namespace EK.Kingdee.K3.MFG.PRD.App.ServicePlugIn
{
[Description("生产订单生成用料清单,应发数量按单位精度取整")]
public class PPBOMCalMustQtyByPresion : AbstractOperationServicePlugIn
{
public override void BeginOperationTransaction(global::Kingdee.BOS.Core.DynamicForm.PlugIn.Args.BeginOperationTransactionArgs e)
{
base.BeginOperationTransaction(e);
if (e.DataEntitys.IsEmpty()) return;
foreach (DynamicObject ppbomData in e.DataEntitys)
{
DynamicObjectCollection ppbomEntryDatas = ppbomData.GetDynamicValue<DynamicObjectCollection>("PPBomEntry");
foreach (DynamicObject entryData in ppbomEntryDatas)
{
//计算应发,需求,标准
int rowIndex = ppbomEntryDatas.ToList().IndexOf(entryData);
RecomputeQty(ppbomData, rowIndex); //这段逻辑里面是根据生产订单数量重算了应发,标准,需求等数量(是根据单位精度强制进位)
}
}
UpdateNoPickedQty(this.Context, e.DataEntitys);
}
/// <summary>
/// 重算数量
/// </summary>
/// <param name="ppbomData"></param>
/// <param name="row"></param>
protected virtual void RecomputeQty(DynamicObject ppbomData, int row)
{
DynamicObjectCollection ppbomEntrys = ppbomData.GetDynamicValue<DynamicObjectCollection>(CONST_PRD_PPBOM.CONST_FEntity.ENTITY_ORM_PPBomEntry);
DynamicObject ppbomEntry = ppbomEntrys[row];
UnitConvert qtyConvert = GetUnitRateConvert(ppbomEntry);
long precison = 0;
DynamicObject unitObj = ppbomEntry.GetDynamicValue<DynamicObject>(CONST_PRD_PPBOM.CONST_FEntity.ORM_UnitID);
if (unitObj.IsNullOrEmptyOrWhiteSpace())
{
long unitId = ppbomEntry.GetDynamicValue<long>(CONST_PRD_PPBOM.CONST_FEntity.ORM_UnitID_Id);
FormMetadata metadata = AppMetadataContext.LoadWithNoVerCheck(this.Context, "BD_UNIT") as FormMetadata;
//获取时间组基本计量单位
unitObj = AppServiceContext.ViewService.LoadSingle(this.Context, unitId, metadata.BusinessInfo.GetDynamicObjectType());
precison = unitObj.GetDynamicValue<long>("Precision");
}
else
{
precison = ppbomEntry.GetDynamicValue<DynamicObject>(CONST_PRD_PPBOM.CONST_FEntity.ORM_UnitID)
.GetDynamicValue<long>("Precision");
}
IPPBOMCalQtyService service = AppServiceContext.GetService<IPPBOMCalQtyService>();
decimal stdQty = service.CalStdQty(this.Context, ppbomData, row);
//这里来处理根据单位精度取整,下面的默认进位的
//用户根据自身业务,设置舍位
stdQty = this.RoundQty(stdQty, precison, BOSEnums.Enu_RoundType.KdCeiling.ToString("D"));
ppbomEntry.SetDynamicObjectItemValue(CONST_PRD_PPBOM.CONST_FEntity.ORM_StdQty, stdQty);
ppbomEntry.SetDynamicObjectItemValue(CONST_PRD_PPBOM.CONST_FEntity.ORM_BaseStdQty, qtyConvert.ConvertQty(stdQty));
decimal needQty = service.CalNeedQty(this.Context, ppbomData, row);
needQty = this.RoundQty(needQty, precison, BOSEnums.Enu_RoundType.KdCeiling.ToString("D"));
ppbomEntry.SetDynamicObjectItemValue(CONST_PRD_PPBOM.CONST_FEntity.ORM_NeedQty, needQty);
ppbomEntry.SetDynamicObjectItemValue(CONST_PRD_PPBOM.CONST_FEntity.ORM_BaseNeedQty, qtyConvert.ConvertQty(needQty));
decimal mustQty = service.CalMustQty(this.Context, ppbomData, row);
mustQty = this.RoundQty(mustQty, precison, BOSEnums.Enu_RoundType.KdCeiling.ToString("D"));
ppbomEntry.SetDynamicObjectItemValue(CONST_PRD_PPBOM.CONST_FEntity.ORM_MustQty, mustQty);
ppbomEntry.SetDynamicObjectItemValue(CONST_PRD_PPBOM.CONST_FEntity.ORM_BaseMustQty, qtyConvert.ConvertQty(mustQty));
}
/// <summary>
/// 获取子项的单位换算率
/// </summary>
/// <param name="ppbomEntry">分录</param>
/// <returns></returns>
protected virtual UnitConvert GetUnitRateConvert(DynamicObject ppbomEntry)
{
//获取单位换算率
GetUnitConvertRateArgs unitConvertRateArgs = new GetUnitConvertRateArgs()
{
MaterialId = ppbomEntry.GetDynamicValue<long>(CONST_PRD_PPBOM.CONST_FEntity.ORM_MaterialID_Id),
SourceUnitId = ppbomEntry.GetDynamicValue<long>(CONST_PRD_PPBOM.CONST_FEntity.ORM_UnitID_Id),
DestUnitId = ppbomEntry.GetDynamicValue<long>(CONST_PRD_PPBOM.CONST_FEntity.ORM_BaseUnitID_Id),
};
UnitConvert convert = AppServiceContext.BDService.GetUnitConvertRate(this.Context, unitConvertRateArgs);
return convert;
}
/// <summary>
/// 转换源单位数量到目标单位数量
/// </summary>
/// <param name="sourceQty"></param>
/// <param name="precision"></param>
/// <param name="roundType">舍入类型:强制舍位请传入BOSEnums.Enu_RoundType的枚举值(int)</param>
/// <returns></returns>
protected decimal RoundQty(decimal sourceQty, long precision, string roundType = "")
{
//默认四舍五入
RoundMode roundMode = RoundMode.AwayFromZero;
if (!string.IsNullOrWhiteSpace(roundType))
{
int round = 0;
if (Int32.TryParse(roundType, out round))
{
switch (round)
{
case (int)BOSEnums.Enu_RoundType.KdFloor:
roundMode = RoundMode.Truncation;
break;
case (int)BOSEnums.Enu_RoundType.KdCeiling:
roundMode = RoundMode.Carry;
break;
default:
roundMode = RoundMode.AwayFromZero;
break;
}
}
}
return MathUtil.Round(sourceQty, (int)precision, roundMode);
}
/// <summary>
/// 更新未领数量和基本单位未领数量
/// </summary>
/// <param name="ctx"></param>
/// <param name="ppbomDatas"></param>
public void UpdateNoPickedQty(Context ctx, DynamicObject[] ppbomDatas)
{
foreach (DynamicObject ppbomData in ppbomDatas)
{
DynamicObjectCollection ppbomEntrys = ppbomData.GetDynamicValue<DynamicObjectCollection>(CONST_PRD_PPBOM.CONST_FEntity.ENTITY_ORM_PPBomEntry);
foreach (DynamicObject ppbomEntry in ppbomEntrys)
{
//应发数量
decimal mustQty = ppbomEntry.GetDynamicValue<decimal>(CONST_PRD_PPBOM.CONST_FEntity.ORM_MustQty);
//基本单位应发数量
decimal baseMustQty = ppbomEntry.GetDynamicValue<decimal>(CONST_PRD_PPBOM.CONST_FEntity.ORM_BaseMustQty);
//已领数量
decimal pickedQty = ppbomEntry.GetDynamicValue<decimal>(CONST_PRD_PPBOM.CONST_FEntity.ORM_PickedQty);
//基本单位已领数量
decimal basePickedQty = ppbomEntry.GetDynamicValue<decimal>(CONST_PRD_PPBOM.CONST_FEntity.ORM_BasePickedQty);
//良品退料数量
decimal goodReturnQty = ppbomEntry.GetDynamicValue<decimal>(CONST_PRD_PPBOM.CONST_FEntity.ORM_GoodReturnQty);
//基本单位良品退料数量
decimal baseGoodReturnQty = ppbomEntry.GetDynamicValue<decimal>(CONST_PRD_PPBOM.CONST_FEntity.ORM_BaseGoodReturnQty);
//来料不良退料数量
decimal inCDefectReturnQty = ppbomEntry.GetDynamicValue<decimal>(CONST_PRD_PPBOM.CONST_FEntity.ORM_INCDefectReturnQty);
//基本单位来料不良退料数量
decimal baseInCDefectReturnQty = ppbomEntry.GetDynamicValue<decimal>(CONST_PRD_PPBOM.CONST_FEntity.ORM_BaseIncDefectReturnQty);
//多领退回
decimal returnQty = ppbomEntry.GetDynamicValue<decimal>(CONST_PRD_PPBOM.CONST_FEntity.ORM_ReturnQty);
//基本单位多领退回
decimal baseReturnQty = ppbomEntry.GetDynamicValue<decimal>(CONST_PRD_PPBOM.CONST_FEntity.ORM_BaseReturnQty);
//未领数量
decimal noPickedQty = ppbomEntry.GetDynamicValue<decimal>(CONST_PRD_PPBOM.CONST_FEntity.ORM_NoPickedQty);
decimal updatQty = mustQty - pickedQty + goodReturnQty + inCDefectReturnQty - returnQty;
ppbomEntry.SetDynamicObjectItemValue(CONST_PRD_PPBOM.CONST_FEntity.ORM_NoPickedQty, updatQty);
ppbomEntry.SetDynamicObjectItemValue(CONST_PRD_PPBOM.CONST_FEntity.ORM_BaseNoPickedQty, baseMustQty - basePickedQty + baseGoodReturnQty + baseInCDefectReturnQty - baseReturnQty);
}
}
}
}
生产订单保存生成生产用料清单,应发数量根据子项单位的单位精度进位或舍位二开方案
1、生产用料清单保存操作上注册二开插件,如下图:![image.webp](/download/0100b2ff9cd795da471483a7fd97c0041b2b.webp)2、二开代码示例如...
点击下载文档
本文2024-09-23 03:21:25发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-158338.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章