|
@@ -284,6 +284,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
.LeftJoin<Sys_Users>((gs, gi, u, u1) => gs.StorageUserId == u1.Id)
|
|
|
.Where((gs, gi, u, u1) => gs.IsDel == 0)
|
|
|
.WhereIF(dto.GoodsId > 0, (gs, gi, u, u1) => gs.GoodsId == dto.GoodsId)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.BatchNo), (gs, gi, u, u1) => gs.BatchNo.Contains(dto.BatchNo))
|
|
|
.Select((gs, gi, u, u1) => new
|
|
|
{
|
|
|
gs.Id,
|
|
@@ -291,6 +292,8 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
gs.BatchNo,
|
|
|
GoodsName = gi.Name,
|
|
|
gs.Quantity,
|
|
|
+ gs.ReceiveQuantity,
|
|
|
+ QuantityStatusText = gs.Quantity - gs.ReceiveQuantity == 0 ? "已领用完" : "-",
|
|
|
gs.UnitPrice,
|
|
|
gs.TotalPrice,
|
|
|
gs.SupplierName,
|
|
@@ -522,7 +525,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
.LeftJoin<Sys_Users>((gr, gi, u1, u2) => gr.CreateUserId == u2.Id)
|
|
|
.Where((gr, gi, u1, u2) => gr.IsDel == 0)
|
|
|
.WhereIF(dto.GoodsId > 0, (gr, gi, u1, u2) => gr.GoodsId == dto.GoodsId)
|
|
|
- .WhereIF(dto.GoodsId > 0, (gr, gi, u1, u2) => gr.CreateUserId == dto.CurrUserId)
|
|
|
+ .WhereIF(dto.CurrUserId > 0, (gr, gi, u1, u2) => gr.CreateUserId == dto.CurrUserId)
|
|
|
.Select((gr, gi, u1, u2) => new GoodsReceiveListView
|
|
|
{
|
|
|
Id = gr.Id,
|
|
@@ -606,7 +609,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
- data.QuantityInfos = data;
|
|
|
+ data.QuantityInfos = subData;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception e)
|
|
@@ -731,6 +734,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
{
|
|
|
//1.更改审核状态
|
|
|
var currInfo = receiveInfos.Find(x => x.Id == id);
|
|
|
+ if (currInfo == null) continue;
|
|
|
var edit = await _sqlSugar.Updateable<Pm_GoodsReceive>()
|
|
|
.SetColumns(x => new Pm_GoodsReceive()
|
|
|
{
|
|
@@ -742,12 +746,19 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
.ExecuteCommandAsync();
|
|
|
if (edit < 1) status = false;
|
|
|
|
|
|
- if (auditEnum != GoodsAuditEnum.Approved) continue;
|
|
|
-
|
|
|
+ //if (auditEnum != GoodsAuditEnum.Approved) continue;
|
|
|
//2.更改库存
|
|
|
var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().Where(x => x.Id == currInfo.GoodsId).FirstAsync();
|
|
|
- goodsInfo.StockQuantity = goodsInfo.StockQuantity - currInfo.Quantity;
|
|
|
- goodsInfo.OQ_Total += currInfo.Quantity;
|
|
|
+ if (auditEnum == GoodsAuditEnum.Pending)
|
|
|
+ {
|
|
|
+ goodsInfo.StockQuantity += currInfo.Quantity;
|
|
|
+ goodsInfo.OQ_Total -= currInfo.Quantity;
|
|
|
+ }
|
|
|
+ else if (auditEnum == GoodsAuditEnum.Approved)
|
|
|
+ {
|
|
|
+ goodsInfo.StockQuantity -= currInfo.Quantity;
|
|
|
+ goodsInfo.OQ_Total += currInfo.Quantity;
|
|
|
+ }else if(auditEnum == GoodsAuditEnum.UnApproved) continue;
|
|
|
goodsInfo.LastUpdateTime = DateTime.Now;
|
|
|
goodsInfo.LastUpdateUserId = userId;
|
|
|
|
|
@@ -759,7 +770,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
x.LastUpdateUserId,
|
|
|
x.LastUpdateTime,
|
|
|
})
|
|
|
- .Where(x => x.Id == id)
|
|
|
+ .Where(x => x.Id == currInfo.GoodsId)
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
|
if (editGoods < 1) status = false;
|
|
@@ -775,53 +786,80 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
var goodsReceiveInfos = new List<GoodsReceiveLinkStorageView>();
|
|
|
var batchStorageInfos = new List<Pm_GoodsStorage>();
|
|
|
var receiveQuantity = 0.00M; //领用总数量
|
|
|
- foreach (var storage in goodsStorages)
|
|
|
+ if (auditEnum == GoodsAuditEnum.Approved)
|
|
|
{
|
|
|
- if (currInfo.Quantity == receiveQuantity) break;
|
|
|
+ foreach (var storage in goodsStorages)
|
|
|
+ {
|
|
|
+ if (currInfo.Quantity == receiveQuantity) break;
|
|
|
|
|
|
- var thisBatchSurplusQuantity = storage.Quantity - storage.ReceiveQuantity;
|
|
|
- if (thisBatchSurplusQuantity <= 0.00M) continue;
|
|
|
+ var thisBatchSurplusQuantity = storage.Quantity - storage.ReceiveQuantity;
|
|
|
+ if (thisBatchSurplusQuantity <= 0.00M) continue;
|
|
|
|
|
|
- var thisBatchReceiveQuantity = 0.00M; //此批次领用数量
|
|
|
- const decimal unit = 0.50M;
|
|
|
- while (receiveQuantity < currInfo.Quantity)
|
|
|
- {
|
|
|
- if (thisBatchSurplusQuantity == thisBatchReceiveQuantity) break;
|
|
|
+ var thisBatchReceiveQuantity = 0.00M; //此批次领用数量
|
|
|
+ const decimal unit = 0.50M;
|
|
|
+ while (receiveQuantity < currInfo.Quantity)
|
|
|
+ {
|
|
|
+ if (thisBatchSurplusQuantity == thisBatchReceiveQuantity) break;
|
|
|
|
|
|
- thisBatchReceiveQuantity += unit;
|
|
|
- receiveQuantity += unit;
|
|
|
+ thisBatchReceiveQuantity += unit;
|
|
|
+ receiveQuantity += unit;
|
|
|
+ }
|
|
|
+ goodsReceiveInfos.Add(new GoodsReceiveLinkStorageView
|
|
|
+ {
|
|
|
+ StorageId = storage.Id,
|
|
|
+ Quantity = thisBatchReceiveQuantity
|
|
|
+ });
|
|
|
+ storage.ReceiveQuantity += thisBatchReceiveQuantity;
|
|
|
+ var storageUpd = storage;
|
|
|
+ //storageUpd.ReceiveQuantity += thisBatchReceiveQuantity;
|
|
|
+ batchStorageInfos.Add(storageUpd);
|
|
|
}
|
|
|
- goodsReceiveInfos.Add(new GoodsReceiveLinkStorageView
|
|
|
+ //3.1 更改批次库存
|
|
|
+ if (goodsReceiveInfos.Count > 0)
|
|
|
{
|
|
|
- StorageId = storage.Id,
|
|
|
- Quantity = thisBatchReceiveQuantity
|
|
|
- });
|
|
|
- storage.ReceiveQuantity += thisBatchReceiveQuantity;
|
|
|
- var storageUpd = storage;
|
|
|
- //storageUpd.ReceiveQuantity += thisBatchReceiveQuantity;
|
|
|
- batchStorageInfos.Add(storageUpd);
|
|
|
- }
|
|
|
- //3.1 更改批次库存
|
|
|
- if (goodsReceiveInfos.Count > 0)
|
|
|
- {
|
|
|
- var edit1 = await _sqlSugar.Updateable(batchStorageInfos)
|
|
|
- .UpdateColumns(x => x.ReceiveQuantity)
|
|
|
- .WhereColumns(x => x.Id)
|
|
|
- .ExecuteCommandAsync();
|
|
|
- if (edit1 < 1) status = false;
|
|
|
- }
|
|
|
+ var edit1 = await _sqlSugar.Updateable(batchStorageInfos)
|
|
|
+ .UpdateColumns(x => x.ReceiveQuantity)
|
|
|
+ .WhereColumns(x => x.Id)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+ if (edit1 < 1) status = false;
|
|
|
+ }
|
|
|
|
|
|
- //3.2 添加入库批次关联领用人
|
|
|
- if (goodsReceiveInfos.Count > 0)
|
|
|
+ //3.2 添加入库批次关联领用人
|
|
|
+ if (goodsReceiveInfos.Count > 0)
|
|
|
+ {
|
|
|
+ var edit1 = await _sqlSugar.Updateable<Pm_GoodsReceive>()
|
|
|
+ .SetColumns(x => new Pm_GoodsReceive()
|
|
|
+ {
|
|
|
+ GoodsStorageInfo = JsonConvert.SerializeObject(goodsReceiveInfos)
|
|
|
+ })
|
|
|
+ .Where(x => x.Id == id)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+ if (edit1 < 1) status = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (auditEnum == GoodsAuditEnum.Pending)
|
|
|
{
|
|
|
- var edit1 = await _sqlSugar.Updateable<Pm_GoodsReceive>()
|
|
|
- .SetColumns(x => new Pm_GoodsReceive()
|
|
|
- {
|
|
|
- GoodsStorageInfo = JsonConvert.SerializeObject(goodsReceiveInfos)
|
|
|
- })
|
|
|
- .Where(x => x.Id == id)
|
|
|
- .ExecuteCommandAsync();
|
|
|
- if (edit1 < 1) status = false;
|
|
|
+ var goodsStorageInfo = currInfo.GoodsStorageInfo;
|
|
|
+ if (!string.IsNullOrEmpty(goodsStorageInfo))
|
|
|
+ {
|
|
|
+ var goodsStorageInfos = JsonConvert.DeserializeObject<List<GoodsReceiveLinkStorageView>>(goodsStorageInfo);
|
|
|
+ if (goodsStorageInfos.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var item in goodsStorageInfos)
|
|
|
+ {
|
|
|
+ var newStorageInfo = await _sqlSugar.Queryable<Pm_GoodsStorage>()
|
|
|
+ .Where(x => x.IsDel == 0 && x.Id == item.StorageId)
|
|
|
+ .FirstAsync();
|
|
|
+ if (newStorageInfo != null)
|
|
|
+ {
|
|
|
+ var newEdit = await _sqlSugar.Updateable(newStorageInfo)
|
|
|
+ .ReSetValue(x => x.ReceiveQuantity = x.ReceiveQuantity - item.Quantity)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+ if (newEdit < 1) status = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|