diff --git a/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 b/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2
index ab24d821..eeae4d42 100644
Binary files a/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 and b/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 differ
diff --git a/src/WMS.Web.Domain/Entitys/Box.cs b/src/WMS.Web.Domain/Entitys/Box.cs
index 542f8b47..7cf68819 100644
--- a/src/WMS.Web.Domain/Entitys/Box.cs
+++ b/src/WMS.Web.Domain/Entitys/Box.cs
@@ -110,5 +110,50 @@ namespace WMS.Web.Domain.Entitys
}
return Result.ReSuccess();
}
+ ///
+ /// 出入库回退上架
+ ///
+ ///
+ ///
+ ///
+ 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();
+ }
+ ///
+ /// 出入库回退下架
+ ///
+ ///
+ ///
+ ///
+ 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();
+ }
}
}
diff --git a/src/WMS.Web.Domain/Services/ChangeMoveBoxService.cs b/src/WMS.Web.Domain/Services/ChangeMoveBoxService.cs
index 0183fc4a..43d0f269 100644
--- a/src/WMS.Web.Domain/Services/ChangeMoveBoxService.cs
+++ b/src/WMS.Web.Domain/Services/ChangeMoveBoxService.cs
@@ -320,70 +320,38 @@ namespace WMS.Web.Domain.Services
///
public async Task ChangeBox_BackRecord(BackRecord backRecord, LoginInDto loginInfo, bool isTransaction = true)
{
+ if (backRecord.Method == InventoryInOutMethod.Box) return Result.ReSuccess();
List dtoList = new List();
- //目标箱
- 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));
- }
- else
- {
- var dtoDetail = d.Details.FirstOrDefault(f => f.MaterialId == detailClone.MaterialId);
- if (dtoDetail == null)
- d.Details.Add(new SaveChangeBoxRecordDetailsRequest(detailClone.MaterialId, 1, s.SerialNumber));
- else
- {
- dtoDetail.Qty += 1;
- dtoDetail.SerialNumbers.Add(s.SerialNumber);
- }
- }
- 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));
- }
+ 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
- {
- 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);
- }
- }
+ box.BackRecordUp(d.MaterialId, d.Qty);
}
-
- return await ChangeBoxSave(dtoList, loginInfo, isTransaction, false);
+ IDbContextTransaction _transaction = null;
+ if (isTransaction)
+ _transaction = _basbicsRepositories.GetTransaction();
+ Result res_Rollback = Result.ReSuccess();
+ bool isSuccess = true;
+ if (res_Rollback.IsSuccess)
+ {
+ isSuccess = await _boxRepositories.EditEntityList(boxs, false);
+ if (!isSuccess) res_Rollback = Result.ReFailure(ResultCodes.DateWriteError);
+ }
+ //提交事务
+ if (isTransaction)
+ {
+ isSuccess = _basbicsRepositories.CommitTransaction(res_Rollback.IsSuccess ? false : true, _transaction);
+ if (!res_Rollback.IsSuccess) return res_Rollback;
+ if (!isSuccess)
+ return Result.ReFailure(ResultCodes.DateWriteError);
+ }
+ return Result.ReSuccess();
}
///
/// 非采购入库