@ -1566,6 +1566,8 @@ namespace Khd.Core.Wpf.Form
// wmsRawOutstock.executeStatus = "2";
// wmsRawOutstock.endTime = DateTime.Now;
// }
// // 保存备注信息
// wmsRawOutstock.Tips = remarks.Text;
// dbContext.Update(wmsRawOutstock);
// dbContext.SaveChanges();
// }
@ -2260,6 +2262,12 @@ namespace Khd.Core.Wpf.Form
HandyControl . Controls . MessageBox . Error ( "请先输入数量" ) ; return ;
}
decimal amount = decimal . Parse ( txtInScan . Text ) ;
decimal orderAmount = decimal . Parse ( orderNumText . Text ) ;
if ( amount > orderAmount )
{
HandyControl . Controls . MessageBox . Error ( "入库数量不能超过收料通知单数量" ) ;
return ;
}
// 计算入库后当前总数量,仅用来提示使用
decimal? totalMessage = 0 ;
if ( amount < = 0 )
@ -2294,6 +2302,12 @@ namespace Khd.Core.Wpf.Form
return ;
}
if ( material . batchFlag = = "0" & & amount > 1 ) //非批次标识的物料入库数量只能为1
{
HandyControl . Controls . MessageBox . Error ( "非批次物料入库数量只能为1! " ) ;
return ;
}
if ( wmsRawStocks . Count > 0 )
{
if ( material . batchFlag ! = "1" )
@ -2332,7 +2346,8 @@ namespace Khd.Core.Wpf.Form
palletInfoCode = container . containerCode ,
poNo = mesBaseBarcodeInfo . poNo ,
warehouseId = 512 ,
tips = this . txtInStoreRemark . Text
tips = this . txtInStoreRemark . Text ,
receiveBillId = material . receiveBillId
} ;
dbContext . Add ( wmsRawInstock ) ;
@ -2676,6 +2691,18 @@ namespace Khd.Core.Wpf.Form
{
try
{
// 显示采购订单数量,在获取 material 后,查询 MesPurchaseOrder 表以获取 order_amount
var purchaseReceiveBill = dbContext . MesPurchaseReceiveBill . FirstOrDefault ( x = > x . Receive_bill_id = = material . receiveBillId ) ;
if ( purchaseReceiveBill ! = null )
{
// 假设 TextBlock 的名称为 orderAmountTextBlock
orderNumText . Text = purchaseReceiveBill . Act_land_amount . ToString ( ) ;
}
else
{
orderNumText . Text = "无收料通知单" ;
}
//显示单位信息
var mesBaseUnitInfo = dbContext . MesBaseUnitInfo . FirstOrDefault ( t = > t . ErpId = = mesBaseMaterialInfo . MaterialUnitId ) ;
if ( mesBaseUnitInfo ! = null )
@ -3028,7 +3055,7 @@ namespace Khd.Core.Wpf.Form
outstockTime = DateTime . Now ,
outstockWay = "2" ,
materialProductionDate = mesBaseBarcodeInfo . productionDate ,
Tips = this . remarks . Text
Tips = this . remarks . Text
} ;
dbContext . Add ( wmsProductOutstockDetail ) ;
dbContext . Update ( item ) ;
@ -3071,6 +3098,7 @@ namespace Khd.Core.Wpf.Form
newWmsRawOutstock . taskType = "1" ;
newWmsRawOutstock . auditStatus = "1" ;
newWmsRawOutstock . applyBy = "CtuGun" ;
newWmsRawOutstock . applyReason = this . remarks . Text ;
newWmsRawOutstock . applyDate = DateTime . Now ;
newWmsRawOutstock . executeStatus = "2" ;
newWmsRawOutstock . saleOrderId = mesBaseBarcodeInfo . saleOrderId ;
@ -5970,5 +5998,126 @@ namespace Khd.Core.Wpf.Form
HoistWarnHandlerWindow window = new HoistWarnHandlerWindow ( _host ) ;
window . ShowDialog ( ) ;
}
/// <summary>
/// 直接退库,用于辅料库的没有销售订单的退库情况
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DirectReturn_Click ( object sender , RoutedEventArgs e )
{
try
{
if ( ! string . IsNullOrEmpty ( txtReturnBox . Text ) & & ! string . IsNullOrEmpty ( txtReturnBarCode . Text ) )
{
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
var container = dbContext . WmsBaseLocation . FirstOrDefault ( t = > t . containerCode = = txtReturnBox . Text & & t . warehouseId = = 512 ) ;
//List<WmsRawStock> wmsRawStocks = dbContext.WmsRawStock
// .Where(t => txtReturnBarCode.Text == t.instockBatch)
// .Where(t => t.warehouseFloor == 5 && t.warehouseId == 512).ToList();
if ( container = = null )
{
MsgText . Text = "未查询到该容器!" ;
txtReturnBox . Focus ( ) ;
txtReturnBox . Text = string . Empty ;
return ;
}
var material = dbContext . MesBaseBarcodeInfo . FirstOrDefault ( t = > t . barcodeInfo = = txtReturnBarCode . Text ) ;
if ( material = = null )
{
txtReturnMsg . Text = ( "未查询到该条码内容!" ) ;
txtReturnBarCode . Text = string . Empty ;
txtReturnBarCode . Focus ( ) ;
return ;
}
var wmsRawStock = dbContext . WmsRawStock . FirstOrDefault ( t = > t . instockBatch = = txtReturnBarCode . Text & & t . palletInfoCode = = txtReturnBox . Text ) ;
if ( wmsRawStock ! = null )
{
int returnNum = Convert . ToInt32 ( txtReturnScan . Text ) ;
wmsRawStock . totalAmount + = returnNum ; // 退库数量加回库存
dbContext . WmsRawStock . Update ( wmsRawStock ) ;
}
else
{
var newRawStock = new WmsRawStock ( )
{
materialId = material . materialId ,
supplierId = material . manufacturerId ,
instockBatch = txtReturnBarCode . Text ,
locationCode = container . locationCode ,
stockType = "1" ,
palletInfoCode = txtReturnBox . Text ,
totalAmount = Convert . ToInt32 ( txtReturnScan . Text ) ,
activeFlag = "1" ,
occupyAmount = 0 ,
completeFlag = "1" ,
frozenAmount = 0 ,
instockDate = System . DateTime . Now ,
rawStockId = Global . SnowId . NextId ( ) ,
saleOrderId = material . saleOrderId ,
safeFlag = material . safeFlag ,
warehouseFloor = 5 ,
warehouseId = 512 ,
createBy = "WPF" ,
createDate = System . DateTime . Now ,
} ;
dbContext . WmsRawStock . Add ( newRawStock ) ;
}
// 添加到退库表
var wmsRawReturn = new WmsRawReturn ( )
{
taskCode = Global . SnowId . NextId ( ) . ToString ( ) ,
taskType = "1" ,
warehouseId = 512 ,
locationCode = container . locationCode ,
materialId = material . materialId ,
materialBarcode = material . barcodeInfo ,
planAmount = ( decimal ) wmsRawStock . totalAmount ,
returnAmount = Convert . ToInt32 ( txtReturnScan . Text ) ,
executeStatus = "2" ,
operationType = "1" ,
applyBy = "WPF" ,
applyDate = System . DateTime . Now ,
applyReason = "直接退库" ,
auditStatus = "1" ,
endTime = System . DateTime . Now
} ;
dbContext . WmsRawReturn . Add ( wmsRawReturn ) ;
//// 添加到退库明细表
//var wmsRawReturnDetail = new WmsRawReturnDetail()
//{
// rawReturnId = wmsRawReturn.taskCode,
// locationCode = "default_location", // 需要根据实际情况设置
// materialBarcode = txtReturnBarCode.Text,
// materialId = material.materialId,
// returnAmount = 1,
// executeStatus = "1",
// returnPerson = "WPF",
// returnTime = System.DateTime.Now,
// createBy = "直接退库",
// createDate = System.DateTime.Now
//};
//dbContext.WmsRawReturnDetail.Add(wmsRawReturnDetail);
dbContext . SaveChanges ( ) ;
txtReturnMsg . Text = ( $"退库成功!,当前库存{wmsRawStock?.totalAmount ?? 1}" ) ;
txtReturnBarCode . Text = string . Empty ;
txtReturnBox . Text = string . Empty ;
txtReturnBox . Focus ( ) ;
}
else
{
txtReturnMsg . Text = ( "请先扫描容器号和条码!" ) ;
}
}
catch ( Exception ex )
{
LogManager . Error ( ex ) ;
txtReturnMsg . Text = ( "退库失败" ) ;
}
}
}
}