|
@@ -1,5 +1,6 @@
|
|
|
using Aspose.Cells;
|
|
|
using AutoMapper;
|
|
|
+using EyeSoft.Runtime.InteropServices;
|
|
|
using Newtonsoft.Json;
|
|
|
using OASystem.Domain;
|
|
|
using OASystem.Domain.Dtos.PersonnelModule;
|
|
@@ -872,7 +873,6 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
|
|
|
if (auditType == 1)//入库
|
|
|
{
|
|
|
-
|
|
|
hrAuditorIds.AuditorIds = new int[] {
|
|
|
//343, // 陈湘
|
|
|
374, // 罗颖
|
|
@@ -1400,6 +1400,27 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
!auditEnums.Contains(x.AuditStatus)
|
|
|
).SumAsync(x => x.Quantity);
|
|
|
|
|
|
+ //验证默认审核 多条 or 单条
|
|
|
+ //出库确认默认审核状态
|
|
|
+ var isAuditPer = GoodsAuditType(goodsInfo?.Type ?? 0);
|
|
|
+
|
|
|
+ //验证默认审核 多条审核时添加
|
|
|
+ var goodsAuditInfo1 = new Pm_GoodsAudit(2, GoodsAuditDepEnum.Hr_Reception, info.Id, GoodsConfirmEnum.WaitConfirm, currUserId);
|
|
|
+ var goodsAuditInfo2 = new Pm_GoodsAudit(2, GoodsAuditDepEnum.Hr, info.Id, GoodsConfirmEnum.WaitConfirm, currUserId);
|
|
|
+ var goodsAuditInfos = new List<Pm_GoodsAudit>() { goodsAuditInfo1 };
|
|
|
+
|
|
|
+ //状态描述
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ stringBuilder.Append($"领用确认:状态:待确认 审核人:- 审核时间:-;<br/>");
|
|
|
+
|
|
|
+ if (isAuditPer)
|
|
|
+ {
|
|
|
+ goodsAuditInfos.Add(goodsAuditInfo2);
|
|
|
+ stringBuilder.Append($"人事部:状态:待确认 审核人:- 审核时间:-;<br/>");
|
|
|
+ }
|
|
|
+
|
|
|
+ info.StatusDesc = stringBuilder.ToString();
|
|
|
+
|
|
|
if (info.Id > 0) //修改
|
|
|
{
|
|
|
//审核验证
|
|
@@ -1427,29 +1448,20 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
x.Quantity,
|
|
|
x.Reason,
|
|
|
x.Remark,
|
|
|
+ x.StatusDesc,
|
|
|
})
|
|
|
.Where(x => x.Id == info.Id)
|
|
|
.ExecuteCommandAsync();
|
|
|
if (edit > 0)
|
|
|
{
|
|
|
+ var auditInfos = await _sqlSugar.Queryable<Pm_GoodsAudit>().Where(x => x.DataId == info.Id).ToListAsync();
|
|
|
+ if (!auditInfos.Any()) await _sqlSugar.Insertable(goodsAuditInfos).ExecuteCommandAsync();
|
|
|
+
|
|
|
_sqlSugar.CommitTran();
|
|
|
_jv.Msg = $"操作成功!";
|
|
|
_jv.Code = StatusCodes.Status200OK;
|
|
|
return _jv;
|
|
|
}
|
|
|
-
|
|
|
- //验证默认审核 多条 or 单挑
|
|
|
- var isAuditPer = GoodsAuditType(goodsInfo?.Type ?? 0);
|
|
|
- if (!isAuditPer)
|
|
|
- {
|
|
|
- //出库确认默认审核状态
|
|
|
- var goodsAuditList = new List<Pm_GoodsAudit>() {
|
|
|
- new (2, GoodsAuditDepEnum.Hr, info.Id, GoodsConfirmEnum.WaitConfirm, currUserId),
|
|
|
- //new (2, GoodsAuditDepEnum.Financial, add, GoodsConfirmEnum.WaitConfirm, currUserId)
|
|
|
- };
|
|
|
- await _sqlSugar.Insertable(goodsAuditList).ExecuteCommandAsync();
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
else if (info.Id < 1) //添加
|
|
|
{
|
|
@@ -1463,30 +1475,16 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
}
|
|
|
|
|
|
var add = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
|
|
|
- if (add < 1)
|
|
|
+ if (add > 0)
|
|
|
{
|
|
|
- _sqlSugar.RollbackTran();
|
|
|
- _jv.Msg = $"添加失败!";
|
|
|
- _jv.Code = StatusCodes.Status400BadRequest;
|
|
|
- return _jv;
|
|
|
- }
|
|
|
+ goodsAuditInfos.ForEach(x => x.DataId = add);
|
|
|
+ await _sqlSugar.Insertable(goodsAuditInfos).ExecuteCommandAsync();
|
|
|
|
|
|
- //验证默认审核 多条 or 单挑
|
|
|
- var isAuditPer = GoodsAuditType(goodsInfo?.Type ?? 0);
|
|
|
- if (isAuditPer)
|
|
|
- {
|
|
|
- //出库确认默认审核状态
|
|
|
- var goodsAuditList = new List<Pm_GoodsAudit>() {
|
|
|
- new (2, GoodsAuditDepEnum.Hr, add, GoodsConfirmEnum.WaitConfirm, currUserId),
|
|
|
- //new (2, GoodsAuditDepEnum.Financial, add, GoodsConfirmEnum.WaitConfirm, currUserId)
|
|
|
- };
|
|
|
- await _sqlSugar.Insertable(goodsAuditList).ExecuteCommandAsync();
|
|
|
+ _sqlSugar.CommitTran();
|
|
|
+ _jv.Msg = $"操作成功!";
|
|
|
+ _jv.Code = StatusCodes.Status200OK;
|
|
|
+ return _jv;
|
|
|
}
|
|
|
-
|
|
|
- _sqlSugar.CommitTran();
|
|
|
- _jv.Msg = $"操作成功!";
|
|
|
- _jv.Code = StatusCodes.Status200OK;
|
|
|
- return _jv;
|
|
|
}
|
|
|
_sqlSugar.RollbackTran();
|
|
|
return _jv;
|
|
@@ -1503,47 +1501,18 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
{
|
|
|
if (idArray.Length < 1) return _jv;
|
|
|
|
|
|
- var auditEnums = new List<GoodsAuditEnum>() {
|
|
|
- GoodsAuditEnum.Pending,
|
|
|
- GoodsAuditEnum.Approved,
|
|
|
- GoodsAuditEnum.UnApproved,
|
|
|
- GoodsAuditEnum.OutPending,
|
|
|
- GoodsAuditEnum.OutConfirmed,
|
|
|
- GoodsAuditEnum.OutRejected,
|
|
|
- };
|
|
|
-
|
|
|
- if (!auditEnums.Contains(auditEnum))
|
|
|
+ if (!Enum.IsDefined(typeof(GoodsAuditEnum),(int)auditEnum))
|
|
|
{
|
|
|
_jv.Msg = $"出库确认状态超出可用范围!";
|
|
|
return _jv;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
int receiveId = idArray[0];
|
|
|
|
|
|
- //验证审核部门 审核状态 大于等于 OutPending 时 验证
|
|
|
- var auditDep = GoodsAuditDepEnum.Hr;
|
|
|
- if (auditEnum >= GoodsAuditEnum.OutPending)
|
|
|
- {
|
|
|
- var auditList = GoodsStorageConfirmAuditDep(2);
|
|
|
- var auditDepInfo = auditList.Find(x => x.AuditorIds.Contains(userId));
|
|
|
- if (auditDepInfo == null)
|
|
|
- {
|
|
|
- _jv.Msg = string.Format("未分配出库确认权限!");
|
|
|
- return _jv;
|
|
|
- }
|
|
|
-
|
|
|
- auditDep = auditDepInfo.AuditDep;
|
|
|
- }
|
|
|
-
|
|
|
var currUserName = _sqlSugar.Queryable<Sys_Users>().First(x => x.Id == userId)?.CnName ?? "-";
|
|
|
|
|
|
_sqlSugar.BeginTran();
|
|
|
- var receiveInfo = await _sqlSugar
|
|
|
- .Queryable<Pm_GoodsReceive>()
|
|
|
- //.Where(x => x.IsDel == 0 && idArray.Contains(x.Id))
|
|
|
- .Where(x => x.IsDel == 0 && receiveId == x.Id)
|
|
|
- .FirstAsync();
|
|
|
+ var receiveInfo = await _sqlSugar.Queryable<Pm_GoodsReceive>().FirstAsync(x => x.IsDel == 0 && receiveId == x.Id);
|
|
|
|
|
|
if (receiveInfo == null)
|
|
|
{
|
|
@@ -1552,6 +1521,10 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
return _jv;
|
|
|
}
|
|
|
|
|
|
+ var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().FirstAsync(x => x.Id == receiveInfo.GoodsId);
|
|
|
+
|
|
|
+ int goodTypeId = goodsInfo?.Type ?? 0;
|
|
|
+
|
|
|
//审核前状态
|
|
|
var preChangeStatus = receiveInfo.AuditStatus;
|
|
|
|
|
@@ -1563,27 +1536,60 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
// return _jv;
|
|
|
//}
|
|
|
|
|
|
- switch (auditEnum)
|
|
|
- {
|
|
|
- case GoodsAuditEnum.Pending: //领用待确认(取消确认、取消拒绝)
|
|
|
- _jv = await GoodsReceivePending(preChangeStatus, receiveId, userId, currUserName, auditEnum);
|
|
|
- break;
|
|
|
- case GoodsAuditEnum.Approved: //领用确认
|
|
|
- _jv = await GoodsReceiveApproved(preChangeStatus, receiveId, userId, currUserName, auditEnum);
|
|
|
- break;
|
|
|
- case GoodsAuditEnum.UnApproved: //领用拒绝
|
|
|
- _jv = await GoodsReceiveUnApproved(preChangeStatus, receiveId, userId, currUserName, auditEnum);
|
|
|
- break;
|
|
|
- case GoodsAuditEnum.OutPending: //出库待确认(取消出库确认、取消出库拒绝)
|
|
|
- _jv = await GoodsReceiveOutPending(preChangeStatus, receiveInfo, userId, auditDep, auditEnum);
|
|
|
- break;
|
|
|
- case GoodsAuditEnum.OutConfirmed: //出库确认
|
|
|
- _jv = await GoodsReceiveOutConfirming(receiveInfo, userId, auditDep, auditEnum);
|
|
|
-
|
|
|
- break;
|
|
|
- case GoodsAuditEnum.OutRejected: //出库拒绝
|
|
|
- _jv = await GoodsReceiveOutConfirming(receiveInfo, userId, auditDep, auditEnum);
|
|
|
- break;
|
|
|
+ var isAuditPer = GoodsAuditType(goodTypeId);
|
|
|
+
|
|
|
+ if (isAuditPer) //多人审核
|
|
|
+ {
|
|
|
+ var auditDep = GoodsAuditDepEnum.Hr_Reception;
|
|
|
+
|
|
|
+ var auditInfo = await _sqlSugar.Queryable<Pm_GoodsAudit>()
|
|
|
+ .FirstAsync(x => x.Type == 2 && x.DataId == receiveInfo.Id && x.Dep == GoodsAuditDepEnum.Hr_Reception);
|
|
|
+ if (auditInfo != null && auditInfo.AuditStatus == GoodsConfirmEnum.Confirmed)
|
|
|
+ {
|
|
|
+ auditDep = GoodsAuditDepEnum.Hr;
|
|
|
+
|
|
|
+ //多人审核的时候验证审核权限
|
|
|
+ var auditList = GoodsStorageConfirmAuditDep(2);
|
|
|
+ var auditDepInfo = auditList.Find(x => x.AuditorIds.Contains(userId));
|
|
|
+ if (auditDepInfo == null)
|
|
|
+ {
|
|
|
+ _jv.Msg = string.Format("未分配出库确认权限!");
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确认中 确认 拒绝
|
|
|
+ _jv = await GoodsReceiveOutConfirmingMultiple(receiveInfo, userId, auditDep, auditEnum);
|
|
|
+
|
|
|
+ //switch (auditEnum)
|
|
|
+ //{
|
|
|
+ // case GoodsAuditEnum.Pending: //领用待确认(取消确认、取消拒绝)
|
|
|
+ // _jv = await GoodsReceivePending(preChangeStatus, receiveId, userId, currUserName, auditEnum);
|
|
|
+ // break;
|
|
|
+ // case GoodsAuditEnum.Approved: //领用确认
|
|
|
+ // _jv = await GoodsReceiveApproved(preChangeStatus, receiveId, userId, currUserName, auditEnum);
|
|
|
+ // break;
|
|
|
+ // case GoodsAuditEnum.UnApproved: //领用拒绝
|
|
|
+ // _jv = await GoodsReceiveUnApproved(preChangeStatus, receiveId, userId, currUserName, auditEnum);
|
|
|
+ // break;
|
|
|
+ // case GoodsAuditEnum.OutPending: //出库待确认(取消出库确认、取消出库拒绝)
|
|
|
+ // _jv = await GoodsReceiveOutPending(preChangeStatus, receiveInfo, userId, auditDep, auditEnum);
|
|
|
+ // break;
|
|
|
+ // case GoodsAuditEnum.OutConfirmed: //出库确认
|
|
|
+ // _jv = await GoodsReceiveOutConfirming(receiveInfo, userId, auditDep, auditEnum);
|
|
|
+ // break;
|
|
|
+ // case GoodsAuditEnum.OutRejected: //出库拒绝
|
|
|
+ // _jv = await GoodsReceiveOutConfirming(receiveInfo, userId, auditDep, auditEnum);
|
|
|
+ // break;
|
|
|
+ //}
|
|
|
+
|
|
|
+ }
|
|
|
+ else //单人审核
|
|
|
+ {
|
|
|
+ //领用确认 --> 已确认 / 领用拒绝 --> 已拒绝
|
|
|
+ _jv = await GoodsReceiveOutConfirmingSingle(receiveInfo,userId, currUserName,auditEnum);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
if (_jv.Code == StatusCodes.Status200OK)
|
|
@@ -1598,6 +1604,8 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
return _jv;
|
|
|
}
|
|
|
|
|
|
+ #region 多人审核状态变更
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 物品领用状态 - 领用待确认(取消确认、取消拒绝)
|
|
|
/// </summary>
|
|
@@ -2024,8 +2032,6 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
statusDesc.Append(auditInfStatusDesc);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
if (preChangeStatus == auditEnum)
|
|
|
{
|
|
|
_jv.Msg = $"此操作已执行,不可重复操作!";
|
|
@@ -2196,6 +2202,547 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
return _jv;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="receiveInfo"></param>
|
|
|
+ /// <param name="userId"></param>
|
|
|
+ /// <param name="depEnum"></param>
|
|
|
+ /// <param name="auditEnum"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<JsonView> GoodsReceiveOutConfirmingMultiple(Pm_GoodsReceive receiveInfo, int userId, GoodsAuditDepEnum depEnum, GoodsAuditEnum auditEnum)
|
|
|
+ {
|
|
|
+ _jv.Code = StatusCodes.Status400BadRequest;
|
|
|
+
|
|
|
+ //更改前状态
|
|
|
+ receiveInfo.CreateUserId = userId;
|
|
|
+ var preChangeStatus = receiveInfo.AuditStatus;
|
|
|
+ var currUserOpDt = DateTime.Now;
|
|
|
+ var currUserOpTime = currUserOpDt.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
+ var receiveUserName = _sqlSugar.Queryable<Sys_Users>().First(x => x.Id == receiveInfo.AuditUserId)?.CnName ?? "-";
|
|
|
+
|
|
|
+ var auditInfos = await _sqlSugar.Queryable<Pm_GoodsAudit>()
|
|
|
+ .Where(x => x.IsDel == 0 && x.DataId == receiveInfo.Id && x.Type == 2)
|
|
|
+ .ToListAsync();
|
|
|
+
|
|
|
+ var auditStatus = GoodsConfirmEnum.WaitConfirm;
|
|
|
+ if (auditEnum == GoodsAuditEnum.UnApproved) auditStatus = GoodsConfirmEnum.UnApproved;
|
|
|
+ else if (auditEnum == GoodsAuditEnum.Approved) auditStatus = GoodsConfirmEnum.Confirmed;
|
|
|
+
|
|
|
+ var auditInfo = auditInfos.Find(x => x.Dep == depEnum);
|
|
|
+
|
|
|
+ if (auditInfo == null)
|
|
|
+ {
|
|
|
+ auditInfo = new Pm_GoodsAudit(2, depEnum, receiveInfo.Id, auditStatus, userId);
|
|
|
+ auditInfo.AuditUserId = userId;
|
|
|
+ var addStatus = await _sqlSugar.Insertable(auditInfo).ExecuteCommandAsync();
|
|
|
+ if (addStatus < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"出库确认操作失败!";
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+ auditInfos.Add(auditInfo);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //移除旧数据
|
|
|
+ auditInfos.Remove(auditInfo);
|
|
|
+ auditInfo.AuditStatus = auditStatus;
|
|
|
+ auditInfo.AuditUserId = userId;
|
|
|
+ auditInfo.AuditTime = currUserOpDt;
|
|
|
+ var updStatus = await _sqlSugar.Updateable<Pm_GoodsAudit>()
|
|
|
+ .SetColumns(x => new Pm_GoodsAudit()
|
|
|
+ {
|
|
|
+ AuditStatus = auditStatus,
|
|
|
+ AuditUserId = userId,
|
|
|
+ AuditTime = currUserOpDt
|
|
|
+ })
|
|
|
+ .Where(x => x.Id == auditInfo.Id)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+
|
|
|
+ if (updStatus < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"出库确认操作失败!";
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加更新后的数据
|
|
|
+ auditInfos.Add(auditInfo);
|
|
|
+ }
|
|
|
+ auditInfos = auditInfos.OrderBy(x => x.Dep).ToList();
|
|
|
+ //处理状态描述
|
|
|
+ StringBuilder statusDesc = new StringBuilder();
|
|
|
+ foreach (var auditInf in auditInfos)
|
|
|
+ {
|
|
|
+ string auditType = auditInf.Dep == GoodsAuditDepEnum.Hr ? "人事部" : "领用确认";
|
|
|
+ string userName = _sqlSugar.Queryable<Sys_Users>().First(x => x.Id == auditInf.AuditUserId)?.CnName ?? "-";
|
|
|
+ string userOpTime = !userName.Equals("-") ? auditInf.AuditTime.ToString("yyyy-MM-dd HH:mm:ss") : "-";
|
|
|
+ string auditInfStatusDesc = string.Format("{0}:状态:{1} 审核人:{2} 审核时间:{3};<br/>",
|
|
|
+ auditType, auditInf.AuditStatus.GetEnumDescription(), userName, currUserOpTime);
|
|
|
+ statusDesc.Append(auditInfStatusDesc);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (preChangeStatus == auditEnum)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"此操作已执行,不可重复操作!";
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ //批次库存信息
|
|
|
+ string goodsStorageInfo = receiveInfo.GoodsStorageInfo;
|
|
|
+
|
|
|
+ //更改领用状态及库存
|
|
|
+ if (auditInfos.Any(x => x.AuditStatus == GoodsConfirmEnum.UnApproved))
|
|
|
+ {
|
|
|
+ //出库确认拒绝
|
|
|
+ auditEnum = GoodsAuditEnum.OutRejected;
|
|
|
+
|
|
|
+ if (preChangeStatus == GoodsAuditEnum.OutConfirmed)
|
|
|
+ {
|
|
|
+ //回滚库存
|
|
|
+ _jv = await GoodsInventoryRollback(receiveInfo);
|
|
|
+ if (_jv.Code != StatusCodes.Status200OK) return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (auditInfos.Where(x => x.AuditStatus == GoodsConfirmEnum.Confirmed).Count() == 2)
|
|
|
+ {
|
|
|
+ //1.出库确认完成
|
|
|
+ auditEnum = GoodsAuditEnum.OutConfirmed;
|
|
|
+
|
|
|
+ //2.更改前的状态为出库确认中 且 更改后的状态为出库确认完成 执行库存减操作
|
|
|
+ if (preChangeStatus == GoodsAuditEnum.OutConfirming || preChangeStatus == GoodsAuditEnum.OutRejected)
|
|
|
+ {
|
|
|
+ //2.1 更改库存
|
|
|
+ var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().Where(x => x.Id == receiveInfo.GoodsId).FirstAsync();
|
|
|
+ goodsInfo.StockQuantity -= receiveInfo.Quantity;
|
|
|
+ goodsInfo.OQ_Total += receiveInfo.Quantity;
|
|
|
+ goodsInfo.LastUpdateTime = DateTime.Now;
|
|
|
+ goodsInfo.LastUpdateUserId = userId;
|
|
|
+
|
|
|
+ var editGoods = await _sqlSugar
|
|
|
+ .Updateable(goodsInfo)
|
|
|
+ .UpdateColumns(x => new
|
|
|
+ {
|
|
|
+ x.StockQuantity,
|
|
|
+ x.OQ_Total,
|
|
|
+ x.LastUpdateUserId,
|
|
|
+ x.LastUpdateTime,
|
|
|
+ })
|
|
|
+ .Where(x => x.Id == receiveInfo.GoodsId)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+
|
|
|
+ if (editGoods < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"库存更新失败!";
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ //2.2 入库批次关联领用人 更改批次库存
|
|
|
+ var goodsStorages = await _sqlSugar
|
|
|
+ .Queryable<Pm_GoodsStorage>()
|
|
|
+ .Where(x => x.IsDel == 0 &&
|
|
|
+ x.GoodsId == receiveInfo.GoodsId &&
|
|
|
+ (x.Quantity - x.ReceiveQuantity) > 0
|
|
|
+ )
|
|
|
+ .OrderBy(x => x.CreateTime)
|
|
|
+ .ToListAsync();
|
|
|
+
|
|
|
+ var goodsReceiveInfos = new List<GoodsReceiveLinkStorageView>();
|
|
|
+ var batchStorageInfos = new List<Pm_GoodsStorage>();
|
|
|
+ var receiveQuantity = 0.00M; //领用总数量
|
|
|
+ foreach (var storage in goodsStorages)
|
|
|
+ {
|
|
|
+ if (receiveInfo.Quantity == receiveQuantity) break;
|
|
|
+
|
|
|
+ var thisBatchSurplusQuantity = storage.Quantity - storage.ReceiveQuantity;
|
|
|
+ if (thisBatchSurplusQuantity <= 0.00M) continue;
|
|
|
+
|
|
|
+ var thisBatchReceiveQuantity = 0.00M; //此批次领用数量
|
|
|
+ const decimal unit = 0.50M;
|
|
|
+ while (receiveQuantity < receiveInfo.Quantity)
|
|
|
+ {
|
|
|
+ if (thisBatchSurplusQuantity == thisBatchReceiveQuantity) break;
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ //2.2.1 更改批次库存
|
|
|
+ if (goodsReceiveInfos.Count > 0)
|
|
|
+ {
|
|
|
+ var edit1 = await _sqlSugar.Updateable(batchStorageInfos)
|
|
|
+ .UpdateColumns(x => x.ReceiveQuantity)
|
|
|
+ .WhereColumns(x => x.Id)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+ if (edit1 < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"批次库存更新失败!";
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //2.2.2 添加入库批次关联领用人
|
|
|
+ if (goodsReceiveInfos.Count > 0)
|
|
|
+ {
|
|
|
+ goodsStorageInfo = JsonConvert.SerializeObject(goodsReceiveInfos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (auditInfos.Where(x => x.AuditStatus == GoodsConfirmEnum.Confirmed).Count() == 1)
|
|
|
+ {
|
|
|
+ //出库确认中
|
|
|
+ auditEnum = GoodsAuditEnum.OutConfirming;
|
|
|
+
|
|
|
+ if (preChangeStatus == GoodsAuditEnum.OutConfirmed)
|
|
|
+ {
|
|
|
+ //回滚库存
|
|
|
+ _jv = await GoodsInventoryRollback(receiveInfo);
|
|
|
+ if (_jv.Code != StatusCodes.Status200OK) return _jv;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else auditEnum = GoodsAuditEnum.OutPending;
|
|
|
+
|
|
|
+ var statusDesc1 = statusDesc.ToString();
|
|
|
+
|
|
|
+ var changeStatus = await _sqlSugar
|
|
|
+ .Updateable<Pm_GoodsReceive>()
|
|
|
+ .SetColumns(x => new Pm_GoodsReceive()
|
|
|
+ {
|
|
|
+ AuditStatus = auditEnum,
|
|
|
+ StatusDesc = statusDesc1,
|
|
|
+ GoodsStorageInfo = goodsStorageInfo,
|
|
|
+ })
|
|
|
+ .Where(x => x.Id == receiveInfo.Id)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+
|
|
|
+ if (changeStatus > 0)
|
|
|
+ {
|
|
|
+ _jv.Code = StatusCodes.Status200OK;
|
|
|
+ }
|
|
|
+
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 物品库存回滚
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="receiveInfo"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<JsonView> GoodsInventoryRollback(Pm_GoodsReceive receiveInfo)
|
|
|
+ {
|
|
|
+ var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().FirstAsync(x => x.Id == receiveInfo.GoodsId);
|
|
|
+
|
|
|
+ //回滚库存
|
|
|
+ var changeGoods = await _sqlSugar
|
|
|
+ .Updateable(goodsInfo)
|
|
|
+ .ReSetValue(it => {
|
|
|
+ it.StockQuantity += receiveInfo.Quantity;
|
|
|
+ it.OQ_Total -= receiveInfo.Quantity;
|
|
|
+ it.LastUpdateTime = DateTime.Now;
|
|
|
+ it.LastUpdateUserId = receiveInfo.CreateUserId;
|
|
|
+ })
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+
|
|
|
+ if (changeGoods < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"库存回滚失败!";
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+ //批次领用记录
|
|
|
+ _jv.Code = StatusCodes.Status200OK;
|
|
|
+ var goodsStorageInfo = receiveInfo.GoodsStorageInfo;
|
|
|
+
|
|
|
+ if (string.IsNullOrEmpty(goodsStorageInfo)) return _jv;
|
|
|
+
|
|
|
+ var goodsStorageInfos = JsonConvert.DeserializeObject<List<GoodsReceiveLinkStorageView>>(goodsStorageInfo);
|
|
|
+
|
|
|
+ if (!goodsStorageInfos.Any()) return _jv;
|
|
|
+
|
|
|
+ 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) continue;
|
|
|
+
|
|
|
+ var newEdit = await _sqlSugar.Updateable(newStorageInfo)
|
|
|
+ .ReSetValue(x => x.ReceiveQuantity = x.ReceiveQuantity - item.Quantity)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+
|
|
|
+ if (newEdit < 1)
|
|
|
+ {
|
|
|
+ _jv.Code = StatusCodes.Status400BadRequest;
|
|
|
+ _jv.Msg = $"批次领用库存更新失败!";
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ _jv.Code = StatusCodes.Status200OK;
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 单人审核状态变更
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 物品领用状态 - 出库确认完成、出库确认拒绝
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="receiveInfo"></param>
|
|
|
+ /// <param name="userId"></param>
|
|
|
+ /// <param name="currUserName"></param>
|
|
|
+ /// <param name="auditEnum"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<JsonView> GoodsReceiveOutConfirmingSingle(Pm_GoodsReceive receiveInfo, int userId,string currUserName,GoodsAuditEnum auditEnum)
|
|
|
+ {
|
|
|
+ _jv.Code = StatusCodes.Status400BadRequest;
|
|
|
+
|
|
|
+ //状态操作范围验证
|
|
|
+ var auditEnums = new List<GoodsAuditEnum>() {
|
|
|
+ GoodsAuditEnum.Pending,
|
|
|
+ GoodsAuditEnum.Approved,
|
|
|
+ GoodsAuditEnum.UnApproved,
|
|
|
+ };
|
|
|
+
|
|
|
+ if (!auditEnums.Contains(auditEnum))
|
|
|
+ {
|
|
|
+ _jv.Msg = $"{GoodsAuditEnum.Pending.GetEnumDescription()}、{GoodsAuditEnum.OutConfirmed.GetEnumDescription()}、{GoodsAuditEnum.OutRejected.GetEnumDescription()},状态下可操作!";
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ var currUserOpDt = DateTime.Now;
|
|
|
+ var currUserOpTime = currUserOpDt.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ //更改前状态
|
|
|
+ var preChangeStatus = receiveInfo.AuditStatus;
|
|
|
+
|
|
|
+ //前台状态验证
|
|
|
+ var auditInfo = await _sqlSugar.Queryable<Pm_GoodsAudit>().FirstAsync(x => x.IsDel == 0 && x.Type == 2 && x.DataId == receiveInfo.Id);
|
|
|
+ if (auditInfo == null)
|
|
|
+ {
|
|
|
+ var addInfo = new Pm_GoodsAudit(2, GoodsAuditDepEnum.Hr_Reception, receiveInfo.Id, GoodsConfirmEnum.WaitConfirm, userId);
|
|
|
+ auditInfo = await _sqlSugar.Insertable(addInfo).ExecuteReturnEntityAsync();
|
|
|
+ if (auditInfo == null)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"确认操作失败!";
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (auditEnum == GoodsAuditEnum.Approved)
|
|
|
+ {
|
|
|
+ auditInfo.AuditStatus = GoodsConfirmEnum.Confirmed;
|
|
|
+ auditEnum = GoodsAuditEnum.OutConfirmed;
|
|
|
+ }
|
|
|
+ else if (auditEnum == GoodsAuditEnum.UnApproved)
|
|
|
+ {
|
|
|
+ auditInfo.AuditStatus = GoodsConfirmEnum.UnApproved;
|
|
|
+ auditEnum = GoodsAuditEnum.OutRejected;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (preChangeStatus == auditEnum)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"此操作已执行,不可重复操作!";
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新子表审核状态
|
|
|
+ var updStatus = await _sqlSugar.Updateable<Pm_GoodsAudit>()
|
|
|
+ .SetColumns(x => new Pm_GoodsAudit()
|
|
|
+ {
|
|
|
+ AuditStatus = auditInfo.AuditStatus,
|
|
|
+ AuditUserId = userId,
|
|
|
+ AuditTime = currUserOpDt
|
|
|
+ })
|
|
|
+ .Where(x => x.Id == auditInfo.Id)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+
|
|
|
+ if (updStatus < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"确认操作失败!";
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理状态描述
|
|
|
+ StringBuilder statusDesc = new StringBuilder();
|
|
|
+ statusDesc.Append(string.Format("领用确认:状态:{0} 审核人:{1} 审核时间:{2};", auditInfo.AuditStatus.GetEnumDescription(), currUserName, currUserOpTime));
|
|
|
+
|
|
|
+ //批次库存信息
|
|
|
+ string goodsStorageInfo = receiveInfo.GoodsStorageInfo;
|
|
|
+
|
|
|
+ if (auditEnum == GoodsAuditEnum.OutConfirmed) //出库确认
|
|
|
+ {
|
|
|
+ //1 更改库存
|
|
|
+ var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().Where(x => x.Id == receiveInfo.GoodsId).FirstAsync();
|
|
|
+ goodsInfo.StockQuantity -= receiveInfo.Quantity;
|
|
|
+ goodsInfo.OQ_Total += receiveInfo.Quantity;
|
|
|
+ goodsInfo.LastUpdateTime = DateTime.Now;
|
|
|
+ goodsInfo.LastUpdateUserId = userId;
|
|
|
+
|
|
|
+ var editGoods = await _sqlSugar.Updateable(goodsInfo)
|
|
|
+ .UpdateColumns(x => new
|
|
|
+ {
|
|
|
+ x.StockQuantity,
|
|
|
+ x.OQ_Total,
|
|
|
+ x.LastUpdateUserId,
|
|
|
+ x.LastUpdateTime,
|
|
|
+ })
|
|
|
+ .Where(x => x.Id == receiveInfo.GoodsId)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+
|
|
|
+ if (editGoods < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"库存更新失败!";
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ //2 入库批次关联领用人 更改批次库存
|
|
|
+ var goodsStorages = await _sqlSugar
|
|
|
+ .Queryable<Pm_GoodsStorage>()
|
|
|
+ .Where(x => x.IsDel == 0 &&
|
|
|
+ x.GoodsId == receiveInfo.GoodsId &&
|
|
|
+ (x.Quantity - x.ReceiveQuantity) > 0
|
|
|
+ )
|
|
|
+ .OrderBy(x => x.CreateTime)
|
|
|
+ .ToListAsync();
|
|
|
+
|
|
|
+ var goodsReceiveInfos = new List<GoodsReceiveLinkStorageView>();
|
|
|
+ var batchStorageInfos = new List<Pm_GoodsStorage>();
|
|
|
+ var receiveQuantity = 0.00M; //领用总数量
|
|
|
+ foreach (var storage in goodsStorages)
|
|
|
+ {
|
|
|
+ if (receiveInfo.Quantity == receiveQuantity) break;
|
|
|
+
|
|
|
+ var thisBatchSurplusQuantity = storage.Quantity - storage.ReceiveQuantity;
|
|
|
+ if (thisBatchSurplusQuantity <= 0.00M) continue;
|
|
|
+
|
|
|
+ var thisBatchReceiveQuantity = 0.00M; //此批次领用数量
|
|
|
+ const decimal unit = 0.50M;
|
|
|
+ while (receiveQuantity < receiveInfo.Quantity)
|
|
|
+ {
|
|
|
+ if (thisBatchSurplusQuantity == thisBatchReceiveQuantity) break;
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ //3 更改批次库存
|
|
|
+ if (goodsReceiveInfos.Count > 0)
|
|
|
+ {
|
|
|
+ var edit1 = await _sqlSugar.Updateable(batchStorageInfos)
|
|
|
+ .UpdateColumns(x => x.ReceiveQuantity)
|
|
|
+ .WhereColumns(x => x.Id)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+ if (edit1 < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"批次库存更新失败!";
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //4 添加入库批次关联领用人
|
|
|
+ if (goodsReceiveInfos.Count > 0)
|
|
|
+ {
|
|
|
+ goodsStorageInfo = JsonConvert.SerializeObject(goodsReceiveInfos);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (auditEnum == GoodsAuditEnum.OutRejected) //出库拒绝
|
|
|
+ {
|
|
|
+ //拒绝之前的状态为已完成 回滚库存
|
|
|
+ if (preChangeStatus == GoodsAuditEnum.OutConfirmed)
|
|
|
+ {
|
|
|
+ //回滚库存
|
|
|
+ var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().FirstAsync(x => x.Id == receiveInfo.GoodsId);
|
|
|
+
|
|
|
+ var changeGoods = await _sqlSugar
|
|
|
+ .Updateable(goodsInfo)
|
|
|
+ .ReSetValue(it => {
|
|
|
+ it.StockQuantity += receiveInfo.Quantity;
|
|
|
+ it.OQ_Total -= receiveInfo.Quantity;
|
|
|
+ it.LastUpdateTime = DateTime.Now;
|
|
|
+ it.LastUpdateUserId = userId;
|
|
|
+ })
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+
|
|
|
+ if (changeGoods < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"库存回滚失败!";
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ //批次号库存 信息更新
|
|
|
+ var goodsStorageInfo1 = receiveInfo.GoodsStorageInfo;
|
|
|
+ if (!string.IsNullOrEmpty(goodsStorageInfo))
|
|
|
+ {
|
|
|
+ var goodsStorageInfos = JsonConvert.DeserializeObject<List<GoodsReceiveLinkStorageView>>(goodsStorageInfo);
|
|
|
+ if (goodsStorageInfos.Any())
|
|
|
+ {
|
|
|
+ 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) continue;
|
|
|
+
|
|
|
+ var newEdit = await _sqlSugar.Updateable(newStorageInfo)
|
|
|
+ .ReSetValue(x => x.ReceiveQuantity = x.ReceiveQuantity - item.Quantity)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+
|
|
|
+ if (newEdit < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"批次领用库存更新失败!";
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var statusDesc1 = statusDesc.ToString();
|
|
|
+
|
|
|
+ var changeStatus = await _sqlSugar
|
|
|
+ .Updateable<Pm_GoodsReceive>()
|
|
|
+ .SetColumns(x => new Pm_GoodsReceive()
|
|
|
+ {
|
|
|
+ AuditStatus = auditEnum,
|
|
|
+ StatusDesc = statusDesc1,
|
|
|
+ GoodsStorageInfo = goodsStorageInfo,
|
|
|
+ })
|
|
|
+ .Where(x => x.Id == receiveInfo.Id)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+
|
|
|
+ if (changeStatus > 0) _jv.Code = StatusCodes.Status200OK;
|
|
|
+
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 物品领用 Del
|
|
|
/// </summary>
|