修复bug
This commit is contained in:
Binary file not shown.
@@ -110,5 +110,50 @@ namespace WMS.Web.Domain.Entitys
|
||||
}
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
/// <summary>
|
||||
/// 出入库回退上架
|
||||
/// </summary>
|
||||
/// <param name="materialId"></param>
|
||||
/// <param name="qty"></param>
|
||||
/// <returns></returns>
|
||||
public Result BackRecordUp(int materialId, decimal qty)
|
||||
{
|
||||
var d = this.Details.FirstOrDefault(f => f.MaterialId == materialId);
|
||||
if(d==null)
|
||||
{
|
||||
this.Details.Add(new BoxDetails()
|
||||
{
|
||||
MaterialId = materialId,
|
||||
Qty = qty
|
||||
});
|
||||
}else
|
||||
{
|
||||
d.Qty = d.Qty + qty;
|
||||
}
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
/// <summary>
|
||||
/// 出入库回退下架
|
||||
/// </summary>
|
||||
/// <param name="materialId"></param>
|
||||
/// <param name="qty"></param>
|
||||
/// <returns></returns>
|
||||
public Result BackRecordDown(int materialId, decimal qty)
|
||||
{
|
||||
var d = this.Details.FirstOrDefault(f => f.MaterialId == materialId);
|
||||
if (d == null)
|
||||
{
|
||||
this.Details.Add(new BoxDetails()
|
||||
{
|
||||
MaterialId = materialId,
|
||||
Qty = qty
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
d.Qty = d.Qty + qty;
|
||||
}
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,70 +320,38 @@ namespace WMS.Web.Domain.Services
|
||||
/// <returns></returns>
|
||||
public async Task<Result> ChangeBox_BackRecord(BackRecord backRecord, LoginInDto loginInfo, bool isTransaction = true)
|
||||
{
|
||||
if (backRecord.Method == InventoryInOutMethod.Box) return Result.ReSuccess();
|
||||
List<SaveChangeBoxRecordRequest> dtoList = new List<SaveChangeBoxRecordRequest>();
|
||||
//目标箱
|
||||
var destIds = backRecord.Details.GroupBy(g => g.BoxId);
|
||||
var serialNumbers = backRecord.Details.SelectMany(s => s.SerialNumbers).ToList();
|
||||
var serialNumberList = await _serialNumbersRepositories.GetEntityList(serialNumbers);
|
||||
foreach (var detail in backRecord.Details)
|
||||
var boxIds = backRecord.Details.Select(s => s.BoxId).Distinct().ToList();
|
||||
var boxs = await _boxRepositories.GetEntityList(boxIds);
|
||||
foreach (var d in backRecord.Details)
|
||||
{
|
||||
if (detail.Qty == 0) continue;
|
||||
var detailClone = detail.Clone();
|
||||
//处理序列号
|
||||
var sList = serialNumberList.Where(w => detailClone.SerialNumbers.Contains(w.SerialNumber)).ToList();
|
||||
foreach (var s in sList)
|
||||
{
|
||||
//原箱和目标箱一样不处理
|
||||
if (s.BoxId == detailClone.BoxId)
|
||||
{
|
||||
detailClone.Qty = detailClone.Qty - 1;
|
||||
detailClone.SerialNumbers.Remove(s.SerialNumber);
|
||||
continue;
|
||||
}
|
||||
|
||||
var d = dtoList.FirstOrDefault(f => f.DestBoxId == detailClone.BoxId && f.SrcBoxId == s.BoxId);
|
||||
if (d == null)
|
||||
{
|
||||
d = new SaveChangeBoxRecordRequest(s.BoxId, detailClone.BoxId);
|
||||
d.Details.Add(new SaveChangeBoxRecordDetailsRequest(detailClone.MaterialId, 1, s.SerialNumber));
|
||||
}
|
||||
var box = boxs.FirstOrDefault(f => f.Id == d.BoxId);
|
||||
if (box == null) continue;
|
||||
if (backRecord.Type == BackRecordType.InstockOff)
|
||||
box.BackRecordDown(d.MaterialId, d.Qty);
|
||||
else
|
||||
box.BackRecordUp(d.MaterialId, d.Qty);
|
||||
}
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _basbicsRepositories.GetTransaction();
|
||||
Result res_Rollback = Result.ReSuccess();
|
||||
bool isSuccess = true;
|
||||
if (res_Rollback.IsSuccess)
|
||||
{
|
||||
var dtoDetail = d.Details.FirstOrDefault(f => f.MaterialId == detailClone.MaterialId);
|
||||
if (dtoDetail == null)
|
||||
d.Details.Add(new SaveChangeBoxRecordDetailsRequest(detailClone.MaterialId, 1, s.SerialNumber));
|
||||
else
|
||||
isSuccess = await _boxRepositories.EditEntityList(boxs, false);
|
||||
if (!isSuccess) res_Rollback = Result.ReFailure(ResultCodes.DateWriteError);
|
||||
}
|
||||
//提交事务
|
||||
if (isTransaction)
|
||||
{
|
||||
dtoDetail.Qty += 1;
|
||||
dtoDetail.SerialNumbers.Add(s.SerialNumber);
|
||||
isSuccess = _basbicsRepositories.CommitTransaction(res_Rollback.IsSuccess ? false : true, _transaction);
|
||||
if (!res_Rollback.IsSuccess) return res_Rollback;
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
}
|
||||
}
|
||||
detailClone.Qty = detailClone.Qty - 1;
|
||||
detailClone.SerialNumbers.Remove(s.SerialNumber);
|
||||
}
|
||||
|
||||
//处理非序列号的数据
|
||||
if (detailClone.Qty <= 0) continue;
|
||||
var dto = dtoList.FirstOrDefault(f => f.DestBoxId == detailClone.BoxId && f.SrcBoxId == 0);
|
||||
if (dto == null)
|
||||
{
|
||||
dto = new SaveChangeBoxRecordRequest(0, detailClone.BoxId);
|
||||
dto.Details.Add(new SaveChangeBoxRecordDetailsRequest(detailClone.MaterialId, detailClone.Qty, detailClone.SerialNumbers));
|
||||
}
|
||||
else
|
||||
{
|
||||
var dtoDetail = dto.Details.FirstOrDefault(f => f.MaterialId == detailClone.MaterialId);
|
||||
if (dtoDetail == null)
|
||||
dto.Details.Add(new SaveChangeBoxRecordDetailsRequest(detailClone.MaterialId, detailClone.Qty, detailClone.SerialNumbers));
|
||||
else
|
||||
{
|
||||
dtoDetail.Qty += detailClone.Qty;
|
||||
dtoDetail.SerialNumbers.AddRange(detailClone.SerialNumbers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return await ChangeBoxSave(dtoList, loginInfo, isTransaction, false);
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
/// <summary>
|
||||
/// 非采购入库
|
||||
|
||||
Reference in New Issue
Block a user