From e83c793bebdb1b9ecdcd79fab8d83fd167baa817 Mon Sep 17 00:00:00 2001
From: wankeda <Administrator@DESKTOP-HAU3ST3>
Date: 星期一, 19 一月 2026 15:51:56 +0800
Subject: [PATCH] 盘点流程
---
WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs | 129 +++++++++++++++++++++++++++++++++++++++---
1 files changed, 118 insertions(+), 11 deletions(-)
diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs b/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs
index b6b5e1d..8f4388d 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs
@@ -1,6 +1,7 @@
锘縰sing AutoMapper;
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Excel;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using SqlSugar;
using System;
@@ -192,6 +193,112 @@
return outStocks;
}
+ //浣庢俯銆佽嵂姘村垎閰嶅簱瀛�
+ public List<Dt_StockInfo> DWANDYSGetOutboundStocks(List<Dt_StockInfo> stockInfos, string materielCode,string batchNo ,decimal needQuantity, out decimal residueQuantity)
+ {
+ List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>();
+ decimal stockTotalQuantity = stockInfos.SelectMany(x => x.Details).Where(d => d.BatchNo == batchNo).Sum(v => v.StockQuantity - v.OutboundQuantity);
+ stockInfos = stockInfos.Where(x => x.Details.Any(x => x.BatchNo == batchNo)).OrderBy(x => x.Id).ToList();
+ if (stockTotalQuantity >= needQuantity)//搴撳瓨澶�
+ {
+ int index = 0;
+ while (needQuantity > 0)
+ {
+
+ Dt_StockInfo stockInfo = stockInfos[index];
+ Dt_StockInfoDetail dt_StockInfoDetail = new Dt_StockInfoDetail();
+ foreach(var detail in stockInfo.Details)
+ {
+ if(detail.BatchNo == batchNo && detail.MaterielCode == materielCode)
+ {
+ dt_StockInfoDetail = detail;
+ }
+ }
+ decimal useableStockQuantity = dt_StockInfoDetail.StockQuantity - dt_StockInfoDetail.OutboundQuantity;
+ if (useableStockQuantity < needQuantity)
+ {
+ stockInfo.Details.ForEach(x =>
+ {
+ if(x.MaterielCode == materielCode && x.BatchNo == batchNo)
+ {
+ x.OutboundQuantity = x.StockQuantity;
+ }
+ });
+ needQuantity -= useableStockQuantity;
+ }
+ else
+ {
+
+ stockInfo.Details.ForEach(x =>
+ {
+ if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == materielCode && x.BatchNo == batchNo)
+ {
+ if (x.StockQuantity - x.OutboundQuantity >= needQuantity)
+ {
+ x.OutboundQuantity += needQuantity;
+ needQuantity = 0;
+ }
+ else
+ {
+ needQuantity -= (x.StockQuantity - x.OutboundQuantity);
+ x.OutboundQuantity = x.StockQuantity;
+ }
+ }
+ });
+ }
+ outStocks.Add(stockInfo);
+ index++;
+ }
+ }
+ else
+ {
+ for (int i = 0; i < stockInfos.Count; i++)
+ {
+ Dt_StockInfo stockInfo = stockInfos[i];
+ decimal useableStockQuantity = 0;
+ foreach (var detail in stockInfo.Details)
+ {
+ if(detail.MaterielCode == materielCode && detail.BatchNo == batchNo)
+ {
+ useableStockQuantity = detail.StockQuantity - detail.OutboundQuantity;
+ }
+ }
+
+ if (useableStockQuantity < needQuantity)
+ {
+ stockInfo.Details.ForEach(x => {
+ if(x.MaterielCode == materielCode && x.BatchNo == batchNo)
+ {
+ x.OutboundQuantity = x.StockQuantity;
+ }
+ });
+ needQuantity -= useableStockQuantity;
+ }
+ else
+ {
+ stockInfo.Details.ForEach(x =>
+ {
+ if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == materielCode && x.BatchNo == batchNo)
+ {
+ if (x.StockQuantity - x.OutboundQuantity >= needQuantity)
+ {
+ x.OutboundQuantity += needQuantity;
+ needQuantity = 0;
+ }
+ else
+ {
+ needQuantity -= (x.StockQuantity - x.OutboundQuantity);
+ x.OutboundQuantity = x.StockQuantity;
+ }
+ }
+ });
+ }
+ outStocks.Add(stockInfo);
+ }
+ }
+ residueQuantity = needQuantity;
+ return outStocks;
+ }
//瀵煎嚭
public override WebResponseContent Export(PageDataOptions options)
{
@@ -211,19 +318,19 @@
List<Dt_StockInfodt> stolist= new List<Dt_StockInfodt>();
for (int i = 0; i < entities.Count; i++)
{
- Dt_StockInfoDetail dt_StockIndet = detdata.Where(x => x.StockId == entities[i].Id).FirstOrDefault();
+ List<Dt_StockInfoDetail> dt_StockIndet = detdata.Where(x => x.StockId == entities[i].Id).ToList();
string MaterialTypet = "鍘熸潗鏂�";
if (entities[i].MaterialType == (int)InventoryMaterialType.鎴愬搧)
{
MaterialTypet = "鎴愬搧";
}
- else if(entities[i].MaterialType == (int)InventoryMaterialType.绌烘墭)
+ else if (entities[i].MaterialType == (int)InventoryMaterialType.绌烘墭)
{
MaterialTypet = "绌烘墭";
}
string Wlstatust = "寰呮";
- if (entities[i].Wlstatus== (int)InventoryMaterialStatus.鍚堟牸)
+ if (entities[i].Wlstatus == (int)InventoryMaterialStatus.鍚堟牸)
{
Wlstatust = "鍚堟牸";
}
@@ -254,14 +361,14 @@
MaterialType = MaterialTypet,
LocationCode = entities[i].LocationCode,
Wlstatus = Wlstatust,
- MaterielCode = dt_StockIndet?.MaterielCode ?? "", // 濡傛灉 dt_StockIndet 涓� null锛屼娇鐢ㄧ┖瀛楃涓蹭綔涓洪粯璁ゅ��
- MaterielName = dt_StockIndet?.MaterielName ?? "",
- OrderNo = dt_StockIndet?.OrderNo ?? "",
- BatchNo = dt_StockIndet?.BatchNo ?? "",
- SerialNumber = dt_StockIndet?.SerialNumber ?? "",
- StockQuantity = dt_StockIndet?.StockQuantity ?? 0, // 鍋囪 StockQuantity 鏄暟鍊肩被鍨嬶紝浣跨敤 0 浣滀负榛樿鍊�
- BatchNoName = dt_StockIndet?.BatchNoName ?? "",
- CreateDate = dt_StockIndet?.CreateDate ?? DateTime.MinValue, // 鍋囪 CreateDate 鏄棩鏈熺被鍨嬶紝浣跨敤榛樿鏃堕棿
+ MaterielCode = dt_StockIndet?.FirstOrDefault()?.MaterielCode ?? "",
+ MaterielName = dt_StockIndet?.FirstOrDefault()?.MaterielName ?? "",
+ OrderNo = dt_StockIndet?.FirstOrDefault()?.OrderNo ?? "",
+ BatchNo = dt_StockIndet?.FirstOrDefault()?.BatchNo ?? "",
+ SerialNumber = dt_StockIndet?.FirstOrDefault()?.SerialNumber ?? "",
+ StockQuantity = dt_StockIndet?.Sum(item => item.StockQuantity) ?? 0,
+ BatchNoName = dt_StockIndet?.FirstOrDefault()?.BatchNoName ?? "",
+ CreateDate = dt_StockIndet?.FirstOrDefault()?.CreateDate ?? DateTime.MinValue,
Remark = entities[i].Remark,
};
stolist.Add(dt_);
--
Gitblit v1.9.3