|
@@ -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,
|
|
@@ -515,20 +516,80 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
/// <returns></returns>
|
|
|
public async Task<JsonView> GoodsReceiveList(GoodsReceiveListDTO dto)
|
|
|
{
|
|
|
+ //参数处理
|
|
|
+ int[] typeLabel = new int[] { },
|
|
|
+ userLabel = new int[] { },
|
|
|
+ auditLabel = new int[] { };
|
|
|
+ if (!string.IsNullOrEmpty(dto.TypeLabel))
|
|
|
+ {
|
|
|
+ typeLabel = dto.TypeLabel
|
|
|
+ .Split(',')
|
|
|
+ .Select(x =>
|
|
|
+ {
|
|
|
+ if (int.TryParse(x, out var id)) return id;
|
|
|
+ return id;
|
|
|
+ })
|
|
|
+ .ToArray();
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty(dto.UserLabel))
|
|
|
+ {
|
|
|
+ userLabel = dto.UserLabel
|
|
|
+ .Split(',')
|
|
|
+ .Select(x =>
|
|
|
+ {
|
|
|
+ if (int.TryParse(x, out var id)) return id;
|
|
|
+ return id;
|
|
|
+ })
|
|
|
+ .ToArray();
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty(dto.AuditLabel))
|
|
|
+ {
|
|
|
+ auditLabel = dto.AuditLabel
|
|
|
+ .Split(',')
|
|
|
+ .Select(x =>
|
|
|
+ {
|
|
|
+ if (int.TryParse(x, out var id)) return id;
|
|
|
+ return id;
|
|
|
+ })
|
|
|
+ .ToArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ //物品ID和物品名称只能传一个
|
|
|
+ if (dto.GoodsId > 0) dto.GoodsName = string.Empty;
|
|
|
+ if (!string.IsNullOrEmpty(dto.GoodsName)) dto.GoodsId = 0;
|
|
|
+
|
|
|
+ bool beginBool = false,
|
|
|
+ endBool = false;
|
|
|
+ DateTime begin = DateTime.Now,
|
|
|
+ end = DateTime.Now;
|
|
|
+ if (!string.IsNullOrEmpty(dto.BeginDt) && !string.IsNullOrEmpty(dto.EndDt))
|
|
|
+ {
|
|
|
+ beginBool = DateTime.TryParse($"{dto.BeginDt} 00:00:00", out begin);
|
|
|
+ endBool = DateTime.TryParse($"{dto.EndDt} 23:59:59", out end);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
RefAsync<int> total = 0;
|
|
|
var data = await _sqlSugar.Queryable<Pm_GoodsReceive>()
|
|
|
.LeftJoin<Pm_GoodsInfo>((gr, gi) => gr.GoodsId == gi.Id)
|
|
|
- .LeftJoin<Sys_Users>((gr, gi, u1) => gr.AuditUserId == u1.Id)
|
|
|
- .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)
|
|
|
- .Select((gr, gi, u1, u2) => new GoodsReceiveListView
|
|
|
+ .LeftJoin<Sys_SetData>((gr, gi,sd) => gi.Type == sd.Id)
|
|
|
+ .LeftJoin<Sys_Users>((gr, gi,sd,u1) => gr.AuditUserId == u1.Id)
|
|
|
+ .LeftJoin<Sys_Users>((gr, gi,sd, u1, u2) => gr.CreateUserId == u2.Id)
|
|
|
+ .Where((gr, gi, sd, u1, u2) => gr.IsDel == 0)
|
|
|
+ .WhereIF(dto.GoodsId > 0, (gr, gi, sd, u1, u2) => gr.GoodsId == dto.GoodsId)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.GoodsName), (gr, gi, sd, u1, u2) => gi.Name.Contains(dto.GoodsName))
|
|
|
+ .WhereIF(auditLabel.Length > 0, (gr, gi, sd, u1, u2) => auditLabel.Contains((int)gr.AuditStatus))
|
|
|
+ .WhereIF(typeLabel.Length > 0, (gr, gi, sd, u1, u2) => typeLabel.Contains(gi.Type))
|
|
|
+ .WhereIF(userLabel.Length > 0, (gr, gi, sd, u1, u2) => userLabel.Contains(gr.CreateUserId))
|
|
|
+ .WhereIF(beginBool && endBool, (gr, gi, sd, u1, u2) => gr.CreateTime >= begin && gr.CreateTime <= end)
|
|
|
+ .Select((gr, gi, sd, u1, u2) => new GoodsReceiveListView
|
|
|
{
|
|
|
Id = gr.Id,
|
|
|
GroupId = gr.GroupId,
|
|
|
GoodsId = gr.GoodsId,
|
|
|
GoodsName = gi.Name,
|
|
|
+ GoodsType = sd.Name,
|
|
|
Quantity = gr.Quantity,
|
|
|
Reason = gr.Reason,
|
|
|
Remark = gr.Remark,
|
|
@@ -591,6 +652,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
var subData1 = JsonConvert.DeserializeObject<List<GoodsReceiveLinkStorageView>>(data.GoodsStorageInfo);
|
|
|
if (subData1.Count > 0)
|
|
|
{
|
|
|
+ string goodsStorageInfoStr = string.Empty;
|
|
|
var storageIds = subData1.Select(x => x.StorageId).ToList();
|
|
|
var storages = await _sqlSugar.Queryable<Pm_GoodsStorage>().Where(x => x.IsDel == 0 && storageIds.Contains(x.Id)).ToListAsync();
|
|
|
foreach (var item in subData1)
|
|
@@ -604,9 +666,11 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
BatchNo = storageInfo.BatchNo,
|
|
|
RecsiveQuantity = item.Quantity
|
|
|
});
|
|
|
+ goodsStorageInfoStr += $"物品名称:{data.GoodsName} 批次号:{storageInfo.BatchNo} 领用数量:{item.Quantity} \r\n";
|
|
|
}
|
|
|
}
|
|
|
- data.QuantityInfos = data;
|
|
|
+ data.QuantityInfos = subData;
|
|
|
+ data.GoodsStorageInfoStr = goodsStorageInfoStr;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception e)
|
|
@@ -731,6 +795,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 +807,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 +831,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 +847,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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|