|
|
|
@ -10,10 +10,13 @@ using DS.WMS.Core.Flow.Dtos;
|
|
|
|
|
using DS.WMS.Core.Flow.Interface;
|
|
|
|
|
using DS.WMS.Core.TaskInteraction.Dtos;
|
|
|
|
|
using DS.WMS.Core.TaskInteraction.Interface;
|
|
|
|
|
using LanguageExt.Common;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Masuit.Tools.Database;
|
|
|
|
|
using Masuit.Tools.Systems;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using static AnyDiff.DifferenceLines;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
{
|
|
|
|
@ -72,8 +75,148 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
//修改
|
|
|
|
|
if (req.Id>0)
|
|
|
|
|
{
|
|
|
|
|
var FeeR = tenantDb.Queryable<FeeReimbursement>().Where(t => t.Id == req.Id).First();
|
|
|
|
|
if (FeeR == null)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed($"数据不存在,请检查");
|
|
|
|
|
}
|
|
|
|
|
if (FeeR.ReimbursementType!= ReimbursementTypeEnums.NotSubmitted)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed($"报销单状态不为未提交,不可修改");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var data = req.Adapt<FeeReimbursement>();
|
|
|
|
|
data.UserId = user.UserId;
|
|
|
|
|
data.ReimbursementType = ReimbursementTypeEnums.NotSubmitted;
|
|
|
|
|
data.Reimburser = user.UserName;
|
|
|
|
|
data.OrgId = user.OrgId;
|
|
|
|
|
var info = tenantDb.Updateable(data).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
//将子表数据删除,重新添加
|
|
|
|
|
|
|
|
|
|
var datadtl = tenantDb.Queryable<FeeReimbursementDetail>().Where(t => t.PId == req.Id).ToList();
|
|
|
|
|
foreach (var item in datadtl)
|
|
|
|
|
{
|
|
|
|
|
var ininfo = tenantDb.Queryable<InInvoice>().Where(t => t.InvoiceNumber == item.InvoiceNumber).First();
|
|
|
|
|
if (ininfo.ReimbursementType != ReimbursementTypeEnums.NotSubmitted)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed($"发票状态异常,不可修改");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tenantDb.Deleteable(datadtl).ExecuteCommand();
|
|
|
|
|
foreach (var item in req.Data)
|
|
|
|
|
{
|
|
|
|
|
//查询发票信息是否存在
|
|
|
|
|
var inviceinfo = tenantDb.Queryable<InInvoice>().Where(t => t.InvoiceNumber == item.InvoiceNumber).First();
|
|
|
|
|
if (inviceinfo == null)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed($"发票号{item.InvoiceNumber}不存在,请检查");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//发票报销状态 校验 待完善
|
|
|
|
|
if (inviceinfo.ReimbursementType == ReimbursementTypeEnums.UnderReview) //报销中
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed($"提交失败,发票号{item.InvoiceNumber}正在报销,请检查");
|
|
|
|
|
}
|
|
|
|
|
if (inviceinfo.ReimbursementType == ReimbursementTypeEnums.Approved) //已报销
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed($"提交失败,发票号{item.InvoiceNumber}已报销,请检查");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inviceinfo.ReimbursementType = ReimbursementTypeEnums.NotSubmitted;
|
|
|
|
|
tenantDb.Updateable(inviceinfo).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
var dataDetail = item.Adapt<FeeReimbursementDetail>();
|
|
|
|
|
dataDetail.Status = ReimbursementTypeEnums.NotSubmitted;
|
|
|
|
|
dataDetail.PId = req.Id;
|
|
|
|
|
tenantDb.Insertable(dataDetail).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//新增
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
#region 提交报销数据校验
|
|
|
|
|
foreach (var item in req.Data)
|
|
|
|
|
{
|
|
|
|
|
//查询发票信息是否存在
|
|
|
|
|
var inviceinfo = tenantDb.Queryable<InInvoice>().Where(t => t.InvoiceNumber == item.InvoiceNumber).First();
|
|
|
|
|
if (inviceinfo == null)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed($"发票号{item.InvoiceNumber}不存在,请检查");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//发票报销状态 校验 待完善
|
|
|
|
|
if (inviceinfo.ReimbursementType == ReimbursementTypeEnums.UnderReview) //报销中
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed($"提交失败,发票号{item.InvoiceNumber}正在报销,请检查");
|
|
|
|
|
}
|
|
|
|
|
if (inviceinfo.ReimbursementType == ReimbursementTypeEnums.Approved) //已报销
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed($"提交失败,发票号{item.InvoiceNumber}已报销,请检查");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
//添加主表信息
|
|
|
|
|
|
|
|
|
|
var data = req.Adapt<FeeReimbursement>();
|
|
|
|
|
data.UserId = user.UserId;
|
|
|
|
|
//data.ReimbursementId = "23"; //报销单编号.
|
|
|
|
|
//data.CreationTime = DateTime.Now;//制单时间
|
|
|
|
|
data.ReimbursementType = ReimbursementTypeEnums.NotSubmitted;
|
|
|
|
|
data.Reimburser = user.UserName;
|
|
|
|
|
data.OrgId = user.OrgId;
|
|
|
|
|
var info = tenantDb.Insertable(data).ExecuteReturnEntity();
|
|
|
|
|
//添加子表信息
|
|
|
|
|
|
|
|
|
|
foreach (var item in req.Data)
|
|
|
|
|
{
|
|
|
|
|
var inviceinfo = tenantDb.Queryable<InInvoice>().Where(t => t.InvoiceNumber == item.InvoiceNumber).First();
|
|
|
|
|
var dataDetail = item.Adapt<FeeReimbursementDetail>();
|
|
|
|
|
dataDetail.Status = ReimbursementTypeEnums.NotSubmitted;
|
|
|
|
|
dataDetail.PId = info.Id;
|
|
|
|
|
dataDetail.Amount = (decimal)inviceinfo.Amount;
|
|
|
|
|
tenantDb.Insertable(dataDetail).ExecuteReturnEntity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return await Task.FromResult(DataResult.Successed("操作成功"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 提交报销单审核
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> SubmitReimbursement(SubmitReimbursementReq req)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
var info= tenantDb.Queryable<FeeReimbursement>().Where(t => t.Id == req.Id).First();
|
|
|
|
|
if (info==null)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed($"报销单不存在,请检查");
|
|
|
|
|
}
|
|
|
|
|
if (info.ReimbursementType!=ReimbursementTypeEnums.NotSubmitted)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed($"报销单状态异常,请检查");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var Pinfo = tenantDb.Queryable<FeeReimbursementDetail>().Where(t => t.PId == req.Id).ToList();
|
|
|
|
|
#region 提交报销数据校验
|
|
|
|
|
foreach (var item in req.Data)
|
|
|
|
|
foreach (var item in Pinfo)
|
|
|
|
|
{
|
|
|
|
|
//查询发票信息是否存在
|
|
|
|
|
var inviceinfo = tenantDb.Queryable<InInvoice>().Where(t => t.InvoiceNumber == item.InvoiceNumber).First();
|
|
|
|
@ -95,22 +238,23 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
//添加主表信息
|
|
|
|
|
|
|
|
|
|
var data = req.Adapt<FeeReimbursement>();
|
|
|
|
|
data.UserId = user.UserId;
|
|
|
|
|
data.ReimbursementId = "23"; //报销单编号.
|
|
|
|
|
var info = tenantDb.Insertable(data).ExecuteReturnEntity();
|
|
|
|
|
//添加子表信息
|
|
|
|
|
//修改主表信息
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in req.Data)
|
|
|
|
|
{
|
|
|
|
|
var dataDetail = item.Adapt<FeeReimbursementDetail>();
|
|
|
|
|
dataDetail.Status = ReimbursementTypeEnums.NotSubmitted;
|
|
|
|
|
dataDetail.PId = info.Id;
|
|
|
|
|
|
|
|
|
|
tenantDb.Insertable(dataDetail).ExecuteReturnEntity();
|
|
|
|
|
info.ReimbursementId = "23"; //报销单编号.
|
|
|
|
|
info.CreationTime = DateTime.Now;//制单时间
|
|
|
|
|
info.ReimbursementType = ReimbursementTypeEnums.UnderReview;
|
|
|
|
|
info.Reimburser = user.UserName;
|
|
|
|
|
info.OrgId = user.OrgId;
|
|
|
|
|
var data = tenantDb.Updateable(info).ExecuteCommand();
|
|
|
|
|
//修改子表信息
|
|
|
|
|
foreach (var item in Pinfo)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
item.Status = ReimbursementTypeEnums.UnderReview;
|
|
|
|
|
|
|
|
|
|
tenantDb.Updateable(item).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -118,10 +262,10 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
var taskReq = new TaskCreationRequest()
|
|
|
|
|
{
|
|
|
|
|
BusinessId = info.Id,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TaskTypeName = TaskBaseTypeEnum.ReimbursementApproval.ToString(),
|
|
|
|
|
TaskTitle = $"【{TaskBaseTypeEnum.ReimbursementApproval.GetDescription()}】{user.UserName}提交的报销单审核",
|
|
|
|
|
TaskDescription = $"【{TaskBaseTypeEnum.ReimbursementApproval.GetDescription()}】共包含发票{req.Data.Count()}张,报销金额{req.Data.Sum(t=>t.Amount)}元",
|
|
|
|
|
TaskDescription = $"【{TaskBaseTypeEnum.ReimbursementApproval.GetDescription()}】共包含发票{Pinfo.Count}张,报销金额{Pinfo.Sum(t => t.Amount)}元",
|
|
|
|
|
};
|
|
|
|
|
var result = await taskService.CreateTaskAsync(taskReq, false);
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
@ -130,29 +274,45 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(DataResult.Successed(result.Message));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 详情
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult<ReimbursementRes> GetReimbursementInfo(string id)
|
|
|
|
|
public DataResult<GetReimbursementRes> GetReimbursementInfo(string id)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var data = tenantDb.Queryable<FeeReimbursement>()
|
|
|
|
|
.Where(a => a.Id == long.Parse(id))
|
|
|
|
|
.Select<ReimbursementRes>()
|
|
|
|
|
.Select<GetReimbursementRes>()
|
|
|
|
|
.First();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult<ReimbursementRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
|
|
|
|
|
var dtlist= tenantDb.Queryable<FeeReimbursementDetail>().Where(t => t.PId == data.Id).ToList();
|
|
|
|
|
foreach (var item in dtlist)
|
|
|
|
|
{
|
|
|
|
|
var dt= tenantDb.Queryable<InInvoice>().Where(t => t.InvoiceNumber == item.InvoiceNumber).Select<GetReimbursementResData>().First();
|
|
|
|
|
if (dt != null)
|
|
|
|
|
{
|
|
|
|
|
data.Data = new List<GetReimbursementResData>();
|
|
|
|
|
data.Data.Add(dt);
|
|
|
|
|
|
|
|
|
|
foreach (var itemdata in data.Data)
|
|
|
|
|
{
|
|
|
|
|
itemdata.Data = new List<InInvoiceDetail>();
|
|
|
|
|
itemdata.Data = tenantDb.Queryable<InInvoiceDetail>().Where(t => t.InvoiceNumber == item.InvoiceNumber).ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return DataResult<GetReimbursementRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -170,12 +330,12 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
.Select<FeeReimbursement>()
|
|
|
|
|
.First();
|
|
|
|
|
|
|
|
|
|
if (data.Status != ReimbursementTypeEnums.NotSubmitted)
|
|
|
|
|
if (data.ReimbursementType != ReimbursementTypeEnums.NotSubmitted)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("报销单只有未审批可撤回!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.Status = ReimbursementTypeEnums.Revoked;
|
|
|
|
|
data.ReimbursementType = ReimbursementTypeEnums.Revoked;
|
|
|
|
|
db.Updateable(data).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
var dataDetail = tenantDb.Queryable<FeeReimbursementDetail>()
|
|
|
|
@ -184,7 +344,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
.ToList();
|
|
|
|
|
foreach (var item in dataDetail)
|
|
|
|
|
{
|
|
|
|
|
item.Status = ReimbursementTypeEnums.Revoked;
|
|
|
|
|
item.ReimbursementType = ReimbursementTypeEnums.Revoked;
|
|
|
|
|
db.Updateable(item).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -230,7 +390,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
if (callback.FlowStatus == FlowStatusEnum.Approve)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
info.Status = ReimbursementTypeEnums.Approved;
|
|
|
|
|
info.ReimbursementType = ReimbursementTypeEnums.Approved;
|
|
|
|
|
tenantDb.Updateable(info).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
var dtllist = tenantDb.Queryable<FeeReimbursementDetail>().Where(t => t.PId == info.Id).ToList();
|
|
|
|
@ -244,7 +404,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
}
|
|
|
|
|
if (callback.FlowStatus == FlowStatusEnum.Reject)
|
|
|
|
|
{
|
|
|
|
|
info.Status = ReimbursementTypeEnums.Rejected;
|
|
|
|
|
info.ReimbursementType = ReimbursementTypeEnums.Rejected;
|
|
|
|
|
info.RejectReason = callback.RejectReason;
|
|
|
|
|
|
|
|
|
|
tenantDb.Updateable(info).ExecuteCommand();
|
|
|
|
|