单据转换插件案例原创
3人赞赏了该文章
466次浏览
编辑于2024年03月28日 17:03:40
[Description("采购订单判断最小包装量、最大最小订货量")] public class CheckQty : AbstractConvertPlugIn { private string message = string.Empty; public override void OnAfterCreateLink(CreateLinkEventArgs e) { ExtendedDataEntity[] array = e.TargetExtendedDataEntities.FindByEntityKey("FBillHead"); ExtendedDataEntity[] array2 = e.TargetExtendedDataEntities.FindByEntityKey("FPOOrderEntry"); ExtendedDataEntity[] array3 = e.TargetExtendedDataEntities.FindByEntityKey("FEntryDeliveryPlan"); if (array[0]["PurchaseOrgId_Id"] == null) { return; } long purchaseOrgId = Convert.ToInt64(array[0]["PurchaseOrgId_Id"]); string billTypeId = Convert.ToString(array[0]["BillTypeId_Id"]); if (!IsCheckQty(purchaseOrgId, billTypeId) || array2 == null || array2.Length <= 0) { return; } ExtendedDataEntity[] array4 = array2; for (int i = 0; i < array4.Length; i++) { ExtendedDataEntity extendedDataEntity = array4[i]; if (Convert.ToBoolean(extendedDataEntity.DataEntity["GiveAway"])) { continue; } IUnitConvertService service = ServiceHelper.GetService<IUnitConvertService>(); DynamicObject dynamicObject = extendedDataEntity.DataEntity["MaterialId"] as DynamicObject; if (dynamicObject == null) { return; } DynamicObjectCollection dynamicObjectCollection = dynamicObject["MaterialBase"] as DynamicObjectCollection; long num = 0L; if (dynamicObjectCollection != null && dynamicObjectCollection.Count > 0) { DynamicObject dynamicObject2 = dynamicObjectCollection[0]; num = Convert.ToInt64(dynamicObject2["BaseUnitId_Id"]); } long num2 = 0L; DynamicObject dynamicObject3 = extendedDataEntity.DataEntity["UnitId"] as DynamicObject; if (dynamicObject3 != null) { num2 = Convert.ToInt64(dynamicObject3["Id"]); } DynamicObjectCollection dynamicObjectCollection2 = dynamicObject["MaterialPlan"] as DynamicObjectCollection; if (dynamicObjectCollection2 == null || dynamicObjectCollection2.Count <= 0) { continue; } DynamicObject dynamicObject4 = dynamicObjectCollection2[0]; if (dynamicObject4 == null) { continue; } decimal num3 = Convert.ToDecimal(extendedDataEntity.DataEntity["Qty"]); decimal num4 = 0m; bool flag = false; if (dynamicObject4.DynamicObjectType.Properties.ContainsKey("MaxPOQty") && dynamicObject4.DynamicObjectType.Properties.ContainsKey("MinPOQty")) { decimal num5 = Convert.ToDecimal(dynamicObject4["MaxPOQty"]); decimal num6 = Convert.ToDecimal(dynamicObject4["MinPOQty"]); if (num6 > num5) { throw new Exception(string.Format(ResManager.LoadKDString("物料【{0}】【{1}】最小订货量({2})不能大于最大订货量({3})!", "00444584000020442", SubSystemType.SCM), Convert.ToString(dynamicObject["number"]), Convert.ToString(dynamicObject["name"]), num6, num5)); } } if (!(num3 > 0m)) { continue; } UnitConvert unitConvertRate = service.GetUnitConvertRate(base.Context, new GetUnitConvertRateArgs { DestUnitId = num2, MasterId = Convert.ToInt64(dynamicObject["msterID"]), SourceUnitId = num }); if (dynamicObject4.DynamicObjectType.Properties.ContainsKey("MaxPOQty")) { decimal num7 = Convert.ToDecimal(dynamicObject4["MaxPOQty"]); if (num != num2) { num7 = unitConvertRate.ConvertQty(num7); } if (num7 != 0m) { if (num3 > num7) { flag = true; num4 = num7; } else { num4 = num3; } } } if (dynamicObject4.DynamicObjectType.Properties.ContainsKey("MinPOQty")) { decimal num8 = Convert.ToDecimal(dynamicObject4["MinPOQty"]); if (num != num2) { num8 = unitConvertRate.ConvertQty(num8); } if (num8 != 0m) { if (num3 < num8) { num4 = num8; } else if (!flag) { num4 = num3; } } } if (dynamicObject4.DynamicObjectType.Properties.ContainsKey("IncreaseQty")) { decimal num9 = Convert.ToDecimal(dynamicObject4["IncreaseQty"]); if (num != num2) { num9 = unitConvertRate.ConvertQty(num9); } if (num9 != 0m && num4 % num9 != 0m) { num4 = ((!flag) ? (Math.Ceiling(num4 / num9) * num9) : (Math.Floor(num4 / num9) * num9)); } }
赞 3
3人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读