桌面端原材料入场记录完善
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Globalization;
|
||||
using YY.Admin.Core;
|
||||
using YY.Admin.Core.Entity;
|
||||
using YY.Admin.Core.Services;
|
||||
using YY.Admin.Core.Util;
|
||||
using YY.Admin.Services.Service;
|
||||
using YY.Admin.Services.Service.MixerMaterialTareStrategy;
|
||||
using YY.Admin.Views.RawMaterialEntry;
|
||||
@@ -25,6 +26,7 @@ public class RawMaterialEntryEditDialogViewModel : BaseViewModel, IDialogResulta
|
||||
private readonly IMixerMaterialService _mixerMaterialService;
|
||||
private readonly IMixerMaterialTareStrategyService _tareStrategyService;
|
||||
private readonly ISupplierService _supplierService;
|
||||
private readonly IWeightRecordService _weightRecordService;
|
||||
private bool _suppressTareStrategyRefresh;
|
||||
protected string? _pendingMaterialId;
|
||||
|
||||
@@ -212,6 +214,7 @@ public class RawMaterialEntryEditDialogViewModel : BaseViewModel, IDialogResulta
|
||||
IMixerMaterialService mixerMaterialService,
|
||||
IMixerMaterialTareStrategyService tareStrategyService,
|
||||
ISupplierService supplierService,
|
||||
IWeightRecordService weightRecordService,
|
||||
IContainerExtension container,
|
||||
IRegionManager regionManager) : base(container, regionManager)
|
||||
{
|
||||
@@ -220,6 +223,7 @@ public class RawMaterialEntryEditDialogViewModel : BaseViewModel, IDialogResulta
|
||||
_mixerMaterialService = mixerMaterialService;
|
||||
_tareStrategyService = tareStrategyService;
|
||||
_supplierService = supplierService;
|
||||
_weightRecordService = weightRecordService;
|
||||
SaveCommand = new DelegateCommand(async () => await SaveAsync());
|
||||
CancelCommand = new DelegateCommand(() => CloseAction?.Invoke());
|
||||
ResetCommand = new DelegateCommand(InitializeForAdd);
|
||||
@@ -468,6 +472,10 @@ public class RawMaterialEntryEditDialogViewModel : BaseViewModel, IDialogResulta
|
||||
return false;
|
||||
}
|
||||
|
||||
//update-begin---author:jiangxh ---date:20260731 for:【原料入场】新增/加量前校验磅单剩余净重-----------
|
||||
if (!await ValidateBillRemainingWeightAsync()) return false;
|
||||
//update-end---author:jiangxh ---date:20260731 for:【原料入场】新增/加量前校验磅单剩余净重-----------
|
||||
|
||||
bool ok;
|
||||
if (IsAddMode)
|
||||
{
|
||||
@@ -483,6 +491,69 @@ public class RawMaterialEntryEditDialogViewModel : BaseViewModel, IDialogResulta
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 校验关联磅单剩余可入场量:剩余 = 净重 - 其他已存在入场记录累计(份数×每份重量)。
|
||||
/// 剩余 ≤ 0 或本次申请量超过剩余时禁止保存。编辑时排除当前记录自身。
|
||||
/// </summary>
|
||||
protected async Task<bool> ValidateBillRemainingWeightAsync()
|
||||
{
|
||||
if (Entry == null || string.IsNullOrWhiteSpace(Entry.BillNo)) return true;
|
||||
|
||||
// 先刷新入场缓存,保证已入场累计与远端一致
|
||||
await _entryService.PageAsync(1, 1, billNo: Entry.BillNo);
|
||||
|
||||
MesXslWeightRecord? weightRecord = null;
|
||||
if (!string.IsNullOrWhiteSpace(Entry.WeightRecordId))
|
||||
{
|
||||
weightRecord = await _weightRecordService.GetByIdAsync(Entry.WeightRecordId);
|
||||
}
|
||||
if (weightRecord == null)
|
||||
{
|
||||
var page = await _weightRecordService.PageAsync(1, 5, filterBillNo: Entry.BillNo);
|
||||
weightRecord = page.Records.FirstOrDefault(r =>
|
||||
string.Equals(r.BillNo, Entry.BillNo, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
if (weightRecord?.NetWeight is not { } netWeight)
|
||||
{
|
||||
HandyControl.Controls.MessageBox.Warning("关联磅单缺少净重,无法校验剩余可入场量,禁止保存。");
|
||||
return false;
|
||||
}
|
||||
|
||||
var others = _entryService.GetCachedSnapshot()
|
||||
.Where(e => !string.IsNullOrWhiteSpace(e.BillNo)
|
||||
&& string.Equals(e.BillNo, Entry.BillNo, StringComparison.OrdinalIgnoreCase)
|
||||
&& (string.IsNullOrWhiteSpace(Entry.Id)
|
||||
|| !string.Equals(e.Id, Entry.Id, StringComparison.OrdinalIgnoreCase)))
|
||||
.ToList();
|
||||
var enteredMap = EnteredWeightCalculator.SumByBillNos(others, new[] { Entry.BillNo });
|
||||
var entered = enteredMap.TryGetValue(Entry.BillNo, out var acc) ? acc : 0d;
|
||||
var remaining = Math.Round(netWeight - entered, 2);
|
||||
|
||||
var requested = EnteredWeightCalculator.SumOneEntry(Entry.TotalPortions, Entry.PortionWeight);
|
||||
if (requested <= 0d && Entry.TotalWeight is { } tw && tw > 0d)
|
||||
{
|
||||
requested = tw;
|
||||
}
|
||||
requested = Math.Round(requested, 2);
|
||||
|
||||
if (remaining <= 0d)
|
||||
{
|
||||
HandyControl.Controls.MessageBox.Warning(
|
||||
$"关联磅单「{Entry.BillNo}」净重已被已有入场记录扣完(净重 {netWeight:0.##},已入场 {entered:0.##}),不能再生成入场记录。");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (requested > remaining + 0.009d)
|
||||
{
|
||||
HandyControl.Controls.MessageBox.Warning(
|
||||
$"本次入场重量 {requested:0.##} 超过磅单剩余可入场量 {remaining:0.##}(净重 {netWeight:0.##},已入场 {entered:0.##}),请调整后再保存。");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual async Task SaveAsync()
|
||||
{
|
||||
if (Entry == null) return;
|
||||
|
||||
Reference in New Issue
Block a user