|
|
|
@ -49,23 +49,23 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult<List<FeeRecordRes>> GetListByPage(PageRequest request)
|
|
|
|
|
public async Task<DataResult<List<FeeRecordRes>>> GetListByPageAsync(PageRequest request)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
long userId = long.Parse(user.UserId);
|
|
|
|
|
//序列化查询条件
|
|
|
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
|
|
|
var data = tenantDb.Queryable<FeeRecord>()
|
|
|
|
|
var data = await tenantDb.Queryable<FeeRecord>()
|
|
|
|
|
.Where(x => x.IsOpen || (!x.IsOpen && x.CreateBy == userId))
|
|
|
|
|
.Where(whereList)
|
|
|
|
|
.Select<FeeRecordRes>()
|
|
|
|
|
.ToQueryPage(request.PageCondition);
|
|
|
|
|
.ToQueryPageAsync(request.PageCondition);
|
|
|
|
|
|
|
|
|
|
//关联用户名称
|
|
|
|
|
var userIds = data.Data.Where(x => x.UpdateBy.HasValue).Select(x => x.UpdateBy.Value)
|
|
|
|
|
//.Union(data.Data.Where(x => x.SubmitBy.HasValue).Select(x => x.SubmitBy.Value))
|
|
|
|
|
.Union(data.Data.Select(x => x.CreateBy)).Distinct();
|
|
|
|
|
var users = db.Queryable<SysUser>().Where(x => userIds.Contains(x.Id)).Select(x => new { x.Id, x.UserName }).ToList();
|
|
|
|
|
var users = await db.Queryable<SysUser>().Where(x => userIds.Contains(x.Id)).Select(x => new { x.Id, x.UserName }).ToListAsync();
|
|
|
|
|
foreach (var item in data.Data)
|
|
|
|
|
{
|
|
|
|
|
item.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName;
|
|
|
|
@ -89,7 +89,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="query"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult<List<FeeRecord>> GetList(string query)
|
|
|
|
|
public async Task<DataResult<List<FeeRecord>>> GetListAsync(string query)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
long userId = long.Parse(user.UserId);
|
|
|
|
@ -101,7 +101,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
src = src.Where(whereList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var data = src.ToList();
|
|
|
|
|
var data = await src.ToListAsync();
|
|
|
|
|
return new DataResult<List<FeeRecord>>(ResultCode.Success) { Data = data };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -112,7 +112,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// <param name="businessType">业务类型</param>
|
|
|
|
|
/// <param name="type">锁定范围</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
bool IsFeeLocked(long bid, BusinessType businessType, FeeType type = FeeType.All)
|
|
|
|
|
internal async Task<bool> IsFeeLockedAsync(long bid, BusinessType businessType, FeeType type = FeeType.All)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
bool? isFeeLocking = null;
|
|
|
|
@ -123,8 +123,8 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
case FeeType.Payable:
|
|
|
|
|
break;
|
|
|
|
|
case FeeType.All:
|
|
|
|
|
isFeeLocking = tenantDb.Queryable<BusinessFeeStatus>().Where(
|
|
|
|
|
x => x.BusinessId == bid && x.BusinessType == businessType).Select(x => x.IsFeeLocking).First();
|
|
|
|
|
isFeeLocking = await tenantDb.Queryable<BusinessFeeStatus>().Where(
|
|
|
|
|
x => x.BusinessId == bid && x.BusinessType == businessType).Select(x => x.IsFeeLocking).FirstAsync();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return isFeeLocking.GetValueOrDefault();
|
|
|
|
@ -135,29 +135,29 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="items">要提交的费用记录</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult InsertOrUpdate(IEnumerable<FeeRecord> items)
|
|
|
|
|
public async Task<DataResult> SaveAsync(IEnumerable<FeeRecord> items)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
var first = items.Select(x => new { x.BusinessType, x.BusinessId }).FirstOrDefault();
|
|
|
|
|
if (IsFeeLocked(first.BusinessId, first.BusinessType))
|
|
|
|
|
if (await IsFeeLockedAsync(first.BusinessId, first.BusinessType))
|
|
|
|
|
return DataResult.Failed("当前业务已费用锁定,禁止提交", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
tenantDb.Ado.BeginTran();
|
|
|
|
|
await tenantDb.Ado.BeginTranAsync();
|
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
var feeIds = items.Where(x => x.Id > 0).Select(x => x.Id).ToArray();
|
|
|
|
|
//包含修改的项,需要检测费用状态再修改
|
|
|
|
|
if (feeIds.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
var fees = tenantDb.Queryable<FeeRecord>().Where(x => feeIds.Contains(x.Id)).Select(x => new FeeRecord
|
|
|
|
|
var fees = await tenantDb.Queryable<FeeRecord>().Where(x => feeIds.Contains(x.Id)).Select(x => new FeeRecord
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
FeeName = x.FeeName,
|
|
|
|
|
FeeStatus = x.FeeStatus
|
|
|
|
|
}).ToList();
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
foreach (var fe in fees)
|
|
|
|
@ -173,7 +173,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//若计价货币单位不等于默认货币则尝试获取最新汇率
|
|
|
|
|
FetchExchangeRate(tenantDb, items);
|
|
|
|
|
await FetchExchangeRateAsync(tenantDb, items);
|
|
|
|
|
|
|
|
|
|
List<FeeRecord> list = new List<FeeRecord>(items.Count());
|
|
|
|
|
foreach (var item in items)
|
|
|
|
@ -184,41 +184,42 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
{
|
|
|
|
|
item.BusinessId = first.BusinessId;
|
|
|
|
|
item.BusinessType = first.BusinessType;
|
|
|
|
|
tenantDb.Insertable(item).ExecuteCommand();
|
|
|
|
|
await tenantDb.Insertable(item).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tenantDb.Updateable(item).IgnoreColumns(x => new
|
|
|
|
|
await tenantDb.Updateable(item).IgnoreColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.FeeStatus,
|
|
|
|
|
x.CreateBy,
|
|
|
|
|
x.CreateTime,
|
|
|
|
|
x.BusinessId,
|
|
|
|
|
x.BusinessType,
|
|
|
|
|
x.DeleteBy,
|
|
|
|
|
x.Deleted,
|
|
|
|
|
x.DeleteTime,
|
|
|
|
|
x.SubmitDate,
|
|
|
|
|
x.SubmitBy
|
|
|
|
|
}).ExecuteCommand();
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list.Add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tenantDb.Ado.CommitTran();
|
|
|
|
|
await tenantDb.Ado.CommitTranAsync();
|
|
|
|
|
|
|
|
|
|
var list2 = list.Select(x => x.Adapt<FeeRecordRes>()).ToList();
|
|
|
|
|
return DataResult.Successed("保存成功", list2, MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
tenantDb.Ado.RollbackTran();
|
|
|
|
|
ex.Log(db);
|
|
|
|
|
await tenantDb.Ado.RollbackTranAsync();
|
|
|
|
|
await ex.LogAsync(db);
|
|
|
|
|
return DataResult.Failed("保存失败", MultiLanguageConst.DataUpdateFailed);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
WriteBackStatus(tenantDb, first.BusinessId, first.BusinessType);
|
|
|
|
|
await WriteBackStatusAsync(tenantDb, first.BusinessId, first.BusinessType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -229,17 +230,17 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// <param name="businessType">业务类型</param>
|
|
|
|
|
/// <param name="tidArray">模板ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult CreateByTemplate(long bid, BusinessType businessType, params long[] tidArray)
|
|
|
|
|
public async Task<DataResult> CreateByTemplateAsync(long bid, BusinessType businessType, params long[] tidArray)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
bool hasExists = tenantDb.Queryable<FeeRecord>().LeftJoin<FeeTemplateDetail>((x, y) =>
|
|
|
|
|
x.FeeId == y.FeeId && x.FeeType == y.FeeType).Any((x, y) =>
|
|
|
|
|
x.BusinessId == bid && x.BusinessType == businessType && tidArray.Contains(y.TemplateId) && !y.Deleted);
|
|
|
|
|
x.FeeId == y.FeeId && x.FeeType == y.FeeType).Any(
|
|
|
|
|
(x, y) => x.BusinessId == bid && x.BusinessType == businessType && tidArray.Contains(y.TemplateId));
|
|
|
|
|
if (hasExists)
|
|
|
|
|
return DataResult.Failed("费用记录已存在", MultiLanguageConst.FeeRecordExist);
|
|
|
|
|
|
|
|
|
|
var details = tenantDb.Queryable<FeeTemplateDetail>().Where(x => tidArray.Contains(x.TemplateId) && !x.Deleted).Select(x => new
|
|
|
|
|
var details = await tenantDb.Queryable<FeeTemplateDetail>().Where(x => tidArray.Contains(x.TemplateId) && !x.Deleted).Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.FeeType,
|
|
|
|
|
x.FeeId,
|
|
|
|
@ -261,7 +262,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
x.IsInvoice,
|
|
|
|
|
x.SaleOrgId,
|
|
|
|
|
x.Note
|
|
|
|
|
}).ToList();
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
List<FeeRecord> records = new List<FeeRecord>(details.Count);
|
|
|
|
|
foreach (var item in details)
|
|
|
|
@ -274,11 +275,10 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//若计价货币单位不等于默认货币则尝试获取最新汇率
|
|
|
|
|
FetchExchangeRate(tenantDb, records);
|
|
|
|
|
|
|
|
|
|
int result = tenantDb.Insertable(records).ExecuteCommand();
|
|
|
|
|
await FetchExchangeRateAsync(tenantDb, records);
|
|
|
|
|
int result = await tenantDb.Insertable(records).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
WriteBackStatus(tenantDb, bid, businessType);
|
|
|
|
|
await WriteBackStatusAsync(tenantDb, bid, businessType);
|
|
|
|
|
|
|
|
|
|
return result > 0 ? DataResult.Successed("保存成功", records, MultiLanguageConst.DataCreateSuccess) : DataResult.Successed("操作失败!", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
@ -288,20 +288,20 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids">费用记录ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult Delete(params long[] ids)
|
|
|
|
|
public async Task<DataResult> DeleteAsync(params long[] ids)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
var model = tenantDb.Queryable<FeeRecord>().Where(x => ids.Contains(x.Id)).Select(x => new { x.BusinessId, x.BusinessType }).First();
|
|
|
|
|
if (IsFeeLocked(model.BusinessId, model.BusinessType))
|
|
|
|
|
var model = await tenantDb.Queryable<FeeRecord>().Where(x => ids.Contains(x.Id)).Select(x => new { x.BusinessId, x.BusinessType }).FirstAsync();
|
|
|
|
|
if (await IsFeeLockedAsync(model.BusinessId, model.BusinessType))
|
|
|
|
|
return DataResult.Failed("当前业务已费用锁定,禁止修改", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
|
if (tenantDb.Queryable<FeeRecord>().Any(x => ids.Contains(x.Id) && (x.FeeStatus != FeeStatus.Entering && x.FeeStatus != FeeStatus.RejectSubmission)))
|
|
|
|
|
if (await tenantDb.Queryable<FeeRecord>().AnyAsync(x => ids.Contains(x.Id) && (x.FeeStatus != FeeStatus.Entering && x.FeeStatus != FeeStatus.RejectSubmission)))
|
|
|
|
|
return DataResult.Failed("只能删除状态为‘录入’或‘驳回提交’的费用", MultiLanguageConst.FeeRecordDelete);
|
|
|
|
|
|
|
|
|
|
int result = tenantDb.Deleteable<FeeRecord>(x => ids.Contains(x.Id)).ExecuteCommand();
|
|
|
|
|
int result = await tenantDb.Deleteable<FeeRecord>(x => ids.Contains(x.Id)).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
WriteBackStatus(tenantDb, model.BusinessId, model.BusinessType);
|
|
|
|
|
await WriteBackStatusAsync(tenantDb, model.BusinessId, model.BusinessType);
|
|
|
|
|
|
|
|
|
|
return result > 0 ? DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess) : DataResult.Failed("删除失败!", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
@ -313,10 +313,10 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// <param name="remark">备注</param>
|
|
|
|
|
/// <param name="idArray">费用记录ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult SubmitForApproval(FeeAuditType auditType, string remark, params long[] idArray)
|
|
|
|
|
public async Task<DataResult> SubmitForApprovalAsync(FeeAuditType auditType, string remark, params long[] idArray)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var fees = tenantDb.Queryable<FeeRecord>().Where(x => idArray.Contains(x.Id)).Select(
|
|
|
|
|
var fees = await tenantDb.Queryable<FeeRecord>().Where(x => idArray.Contains(x.Id)).Select(
|
|
|
|
|
x => new FeeRecord
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
@ -324,14 +324,14 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
FeeStatus = x.FeeStatus,
|
|
|
|
|
FlowId = x.FlowId,
|
|
|
|
|
BusinessId = x.BusinessId
|
|
|
|
|
}).ToList();
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
if (fees.IsNullOrEmpty())
|
|
|
|
|
return DataResult.Failed($"未能获取费用信息,提交失败", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
|
var bid = fees[0].BusinessId;
|
|
|
|
|
var bType = fees[0].BusinessType;
|
|
|
|
|
//业务状态检测
|
|
|
|
|
if (IsFeeLocked(bid, bType))
|
|
|
|
|
if (await IsFeeLockedAsync(bid, bType))
|
|
|
|
|
return DataResult.Failed("当前业务已费用锁定,禁止提交", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
|
if (fees.Any(x => x.FlowId.HasValue))
|
|
|
|
@ -341,7 +341,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
return DataResult.Failed($"当前审批费用包含已结算/部分结算的费用,无法提交", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
|
DataResult result = DataResult.Failed(string.Empty, MultiLanguageConst.Operation_Failed);
|
|
|
|
|
tenantDb.Ado.BeginTran();
|
|
|
|
|
await tenantDb.Ado.BeginTranAsync();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (auditType == FeeAuditType.ApplyAudit)
|
|
|
|
@ -355,25 +355,25 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
tenantDb.Ado.RollbackTran();
|
|
|
|
|
await tenantDb.Ado.RollbackTranAsync();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tenantDb.Updateable(fees).UpdateColumns(x => new
|
|
|
|
|
await tenantDb.Updateable(fees).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
x.FeeStatus,
|
|
|
|
|
x.SubmitBy,
|
|
|
|
|
x.SubmitDate,
|
|
|
|
|
x.FlowId
|
|
|
|
|
}).ExecuteCommand();
|
|
|
|
|
tenantDb.Ado.CommitTran();
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
await tenantDb.Ado.CommitTranAsync();
|
|
|
|
|
return DataResult.Successed("提交成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
tenantDb.Ado.RollbackTran();
|
|
|
|
|
ex.Log(db);
|
|
|
|
|
await tenantDb.Ado.RollbackTranAsync();
|
|
|
|
|
await ex.LogAsync(db);
|
|
|
|
|
return DataResult.Failed("提交失败!", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -472,16 +472,16 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="items">费用修改信息</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult SubmitForModification(IEnumerable<FeeModification> items)
|
|
|
|
|
public async Task<DataResult> SubmitForModificationAsync(IEnumerable<FeeModification> items)
|
|
|
|
|
{
|
|
|
|
|
var idList = items.Select(x => x.FeeRecordId).Distinct().ToList();
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var fees = tenantDb.Queryable<FeeRecord>().Where(x => idList.Contains(x.Id)).Select(x => new FeeRecord
|
|
|
|
|
var fees = await tenantDb.Queryable<FeeRecord>().Where(x => idList.Contains(x.Id)).Select(x => new FeeRecord
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
FeeName = x.FeeName,
|
|
|
|
|
FeeStatus = x.FeeStatus
|
|
|
|
|
}).ToList();
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
if (fees.Count == 0)
|
|
|
|
|
return DataResult.Failed("未能获取费用信息", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
@ -502,7 +502,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
return DataResult.Failed("未能找到审批模板", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
|
|
tenantDb.Ado.BeginTran();
|
|
|
|
|
await tenantDb.Ado.BeginTranAsync();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (var fee in fees)
|
|
|
|
@ -528,16 +528,16 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = items.ToList();
|
|
|
|
|
tenantDb.Insertable(list).ExecuteCommand();
|
|
|
|
|
tenantDb.Updateable(fees).UpdateColumns(x => new { x.FeeStatus, x.FlowId }).ExecuteCommand();
|
|
|
|
|
await tenantDb.Insertable(list).ExecuteCommandAsync();
|
|
|
|
|
await tenantDb.Updateable(fees).UpdateColumns(x => new { x.FeeStatus, x.FlowId }).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
tenantDb.Ado.CommitTran();
|
|
|
|
|
await tenantDb.Ado.CommitTranAsync();
|
|
|
|
|
return DataResult.Successed("提交成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
tenantDb.Ado.RollbackTran();
|
|
|
|
|
ex.Log(db);
|
|
|
|
|
await tenantDb.Ado.RollbackTranAsync();
|
|
|
|
|
await ex.LogAsync(db);
|
|
|
|
|
return DataResult.Failed("提交失败!", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -547,17 +547,17 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idArray">费用记录ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult Withdraw(params long[] idArray)
|
|
|
|
|
public async Task<DataResult> WithdrawAsync(params long[] idArray)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var fees = tenantDb.Queryable<FeeRecord>().Where(x => idArray.Contains(x.Id)).Select(
|
|
|
|
|
var fees = await tenantDb.Queryable<FeeRecord>().Where(x => idArray.Contains(x.Id)).Select(
|
|
|
|
|
x => new FeeRecord
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
FeeName = x.FeeName,
|
|
|
|
|
FeeStatus = x.FeeStatus,
|
|
|
|
|
FlowId = x.FlowId
|
|
|
|
|
}).ToList();
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (fees.IsNullOrEmpty())
|
|
|
|
|
return DataResult.Failed("未能找到费用记录", MultiLanguageConst.Operation_Failed);
|
|
|
|
@ -574,8 +574,8 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
tenantDb.Ado.BeginTran();
|
|
|
|
|
db.Updateable(flows).UpdateColumns(x => new { x.FlowStatus, x.MakerList }).ExecuteCommand();
|
|
|
|
|
await tenantDb.Ado.BeginTranAsync();
|
|
|
|
|
await db.Updateable(flows).UpdateColumns(x => new { x.FlowStatus, x.MakerList }).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
foreach (var item in fees)
|
|
|
|
|
{
|
|
|
|
@ -588,11 +588,11 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
item.FeeStatus = FeeStatus.AuditPassed;
|
|
|
|
|
|
|
|
|
|
//删除暂存数据
|
|
|
|
|
var entity = tenantDb.Queryable<FeeModification>().OrderByDescending(
|
|
|
|
|
x => x.CreateTime).Select(x => new { x.Id, x.FeeRecordId }).First(x => x.FeeRecordId == item.Id);
|
|
|
|
|
var entity = await tenantDb.Queryable<FeeModification>().OrderByDescending(
|
|
|
|
|
x => x.CreateTime).Select(x => new { x.Id, x.FeeRecordId }).FirstAsync(x => x.FeeRecordId == item.Id);
|
|
|
|
|
if (entity != null)
|
|
|
|
|
{
|
|
|
|
|
tenantDb.Deleteable<FeeModification>().Where(x => x.Id == entity.Id).ExecuteCommand();
|
|
|
|
|
await tenantDb.Deleteable<FeeModification>().Where(x => x.Id == entity.Id).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case FeeStatus.ApplyDeletion:
|
|
|
|
@ -605,15 +605,15 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
item.FlowId = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tenantDb.Updateable(fees).UpdateColumns(x => new { x.Id, x.FeeStatus, x.SubmitBy, x.SubmitDate, x.FlowId }).ExecuteCommand();
|
|
|
|
|
await tenantDb.Updateable(fees).UpdateColumns(x => new { x.Id, x.FeeStatus, x.SubmitBy, x.SubmitDate, x.FlowId }).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
tenantDb.Ado.CommitTran();
|
|
|
|
|
await tenantDb.Ado.CommitTranAsync();
|
|
|
|
|
return DataResult.Successed("提交成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
tenantDb.Ado.RollbackTran();
|
|
|
|
|
ex.Log(db);
|
|
|
|
|
await tenantDb.Ado.RollbackTranAsync();
|
|
|
|
|
await ex.LogAsync(db);
|
|
|
|
|
return DataResult.Failed("提交失败!", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -625,17 +625,17 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// <param name="bid">业务ID</param>
|
|
|
|
|
/// <param name="type">业务类型</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult SubmitBusinessAudit(long bid, BusinessType type)
|
|
|
|
|
public async Task<DataResult> SubmitBusinessAuditAsync(long bid, BusinessType type)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var entity = tenantDb.Queryable<BusinessFeeStatus>().Where(x => x.BusinessId == bid &&
|
|
|
|
|
var entity = await tenantDb.Queryable<BusinessFeeStatus>().Where(x => x.BusinessId == bid &&
|
|
|
|
|
x.BusinessType == BusinessType.OceanShippingExport).Select(x => new BusinessFeeStatus
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
IsFeeLocking = x.IsFeeLocking,
|
|
|
|
|
BillAuditStatus = x.BillAuditStatus,
|
|
|
|
|
FlowId = x.FlowId
|
|
|
|
|
}).First();
|
|
|
|
|
}).FirstAsync();
|
|
|
|
|
|
|
|
|
|
if (entity == null)
|
|
|
|
|
return DataResult.Failed("未能找到业务信息", MultiLanguageConst.Operation_Failed);
|
|
|
|
@ -666,14 +666,16 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
entity.BillFeeStatusTime = DateTime.Now;
|
|
|
|
|
entity.FlowId = instance.Id;
|
|
|
|
|
|
|
|
|
|
tenantDb.Updateable(entity).UpdateColumns(x => new
|
|
|
|
|
await tenantDb.Updateable(entity).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.BillAuditStatus,
|
|
|
|
|
x.BillFeeStatusTime,
|
|
|
|
|
x.FlowId
|
|
|
|
|
}).ExecuteCommand();
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
//修改关联费用状态为提交审核
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tenantDb.Ado.CommitTran();
|
|
|
|
|
return DataResult.Successed("提交成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -686,11 +688,11 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// <param name="enabled">是否启用</param>
|
|
|
|
|
/// <param name="idArray">费用记录ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult SetInvoiceEnabled(bool enabled, params long[] idArray)
|
|
|
|
|
public async Task<DataResult> SetInvoiceEnabledAsync(bool enabled, params long[] idArray)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var list = idArray.Select(x => new FeeRecord { Id = x, IsInvoice = enabled }).ToList();
|
|
|
|
|
int rows = tenantDb.Updateable(list).UpdateColumns(x => new { x.IsInvoice }).ExecuteCommand();
|
|
|
|
|
int rows = await tenantDb.Updateable(list).UpdateColumns(x => new { x.IsInvoice }).ExecuteCommandAsync();
|
|
|
|
|
return rows > 0 ? DataResult.Successed("设置成功!", MultiLanguageConst.DataUpdateSuccess) : DataResult.Failed("设置失败!", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -701,15 +703,15 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// <param name="customerType">客户类别</param>
|
|
|
|
|
/// <param name="idArray">费用记录ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult SetCustomer(long customerId, string customerType, params long[] idArray)
|
|
|
|
|
public async Task<DataResult> SetCustomerAsync(long customerId, string customerType, params long[] idArray)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var model = tenantDb.Queryable<InfoClient>().Where(x => x.Id == customerId).Select(x => new
|
|
|
|
|
var model = await tenantDb.Queryable<InfoClient>().Where(x => x.Id == customerId).Select(x => new
|
|
|
|
|
{
|
|
|
|
|
Id = customerId,
|
|
|
|
|
x.CodeName,
|
|
|
|
|
x.Name
|
|
|
|
|
}).First();
|
|
|
|
|
}).FirstAsync();
|
|
|
|
|
if (model == null)
|
|
|
|
|
return DataResult.Failed("未能找到费用对象信息,设置失败!", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
@ -721,7 +723,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
CustomerName = model.Name,
|
|
|
|
|
CustomerType = customerType
|
|
|
|
|
}).ToList();
|
|
|
|
|
int rows = tenantDb.Updateable(list).UpdateColumns(x => new { x.CustomerId, x.CustomerCode, x.CustomerName, x.CustomerType }).ExecuteCommand();
|
|
|
|
|
int rows = await tenantDb.Updateable(list).UpdateColumns(x => new { x.CustomerId, x.CustomerCode, x.CustomerName, x.CustomerType }).ExecuteCommandAsync();
|
|
|
|
|
return rows > 0 ? DataResult.Successed("设置成功!", MultiLanguageConst.DataUpdateSuccess) : DataResult.Failed("设置失败!", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -731,16 +733,14 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// <param name="businessType">业务类型</param>
|
|
|
|
|
/// <param name="idArray">费用记录ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult<CostAccountingForm> GetPrintInfo(BusinessType businessType, params long[] idArray)
|
|
|
|
|
public async Task<DataResult<CostAccountingForm>> GetPrintInfoAsync(BusinessType businessType, params long[] idArray)
|
|
|
|
|
{
|
|
|
|
|
CostAccountingForm form = null;
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
switch (businessType)
|
|
|
|
|
{
|
|
|
|
|
//case BusinessType.ChangeOrder:
|
|
|
|
|
// break;
|
|
|
|
|
case BusinessType.OceanShippingExport:
|
|
|
|
|
form = GetOceanShippingExportForm(tenantDb, idArray);
|
|
|
|
|
form = await GetOceanShippingExportAsync(tenantDb, idArray);
|
|
|
|
|
break;
|
|
|
|
|
case BusinessType.OceanShippingImport:
|
|
|
|
|
|
|
|
|
@ -767,7 +767,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
new FeeRecord { Currency = "USD", FeeType = FeeType.Receivable },
|
|
|
|
|
new FeeRecord { Currency = "USD", FeeType = FeeType.Payable }
|
|
|
|
|
};
|
|
|
|
|
FetchExchangeRate(tenantDb, fees);
|
|
|
|
|
await FetchExchangeRateAsync(tenantDb, fees);
|
|
|
|
|
form.ExchangeRate = fees[0].ExchangeRate.HasValue ? fees[0].ExchangeRate.Value : 1;
|
|
|
|
|
form.TotalReceivable = Math.Round(form.ReceivableUSD * form.ExchangeRate, 4, MidpointRounding.ToEven) + form.ReceivableRMB + form.ReceivableOther;
|
|
|
|
|
form.TotalPayable = Math.Round(form.PayableUSD * form.ExchangeRate, 4, MidpointRounding.ToEven) + form.PayableRMB + form.PayableOther;
|
|
|
|
@ -776,11 +776,11 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
return DataResult<CostAccountingForm>.Success(form);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CostAccountingForm GetOceanShippingExportForm(SqlSugarScopeProvider tenantDb, params long[] idArray)
|
|
|
|
|
//获取海运出口打印数据
|
|
|
|
|
async Task<CostAccountingForm> GetOceanShippingExportAsync(SqlSugarScopeProvider tenantDb, params long[] idArray)
|
|
|
|
|
{
|
|
|
|
|
CostAccountingForm form = null;
|
|
|
|
|
var list = tenantDb.Queryable<FeeRecord>().InnerJoin<SeaExport>((x, y) => x.BusinessId == y.Id)
|
|
|
|
|
var list = await tenantDb.Queryable<FeeRecord>().InnerJoin<SeaExport>((x, y) => x.BusinessId == y.Id)
|
|
|
|
|
.Where((x, y) => idArray.Contains(x.Id)
|
|
|
|
|
//&& x.FeeStatus == FeeStatus.SettlementCompleted
|
|
|
|
|
).Select((x, y) => new
|
|
|
|
@ -802,7 +802,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
y.DischargePort,
|
|
|
|
|
y.CntrTotal, //Volume
|
|
|
|
|
y.IssueType //放单方式
|
|
|
|
|
}).ToList();
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (list.Count == 0)
|
|
|
|
|
return form;
|
|
|
|
@ -835,21 +835,23 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
return form;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//回写业务主表的费用状态
|
|
|
|
|
internal static void WriteBackStatus(SqlSugarScopeProvider tenantDb, long businessId, BusinessType businessType)
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 回写业务表费用状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="tenantDb"></param>
|
|
|
|
|
/// <param name="businessId">业务ID</param>
|
|
|
|
|
/// <param name="businessType">业务类型</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task WriteBackStatusAsync(SqlSugarScopeProvider tenantDb, long businessId, BusinessType businessType)
|
|
|
|
|
{
|
|
|
|
|
var fees = tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == businessId && x.BusinessType == businessType)
|
|
|
|
|
var fees = await tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == businessId && x.BusinessType == businessType)
|
|
|
|
|
.Select(x => new FeeRecord
|
|
|
|
|
{
|
|
|
|
|
//BusinessId = businessId,
|
|
|
|
|
//BusinessType = businessType,
|
|
|
|
|
FeeType = x.FeeType,
|
|
|
|
|
FeeStatus = x.FeeStatus
|
|
|
|
|
}).ToList();
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
if (fees.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var arFeeStatus = DetermineStatus(fees.FindAll(x => x.FeeType == FeeType.Receivable));
|
|
|
|
|
var apFeeStatus = DetermineStatus(fees.FindAll(x => x.FeeType == FeeType.Payable));
|
|
|
|
@ -866,8 +868,14 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
upt = upt.SetColumns(x => x.APFeeStatus == apFeeStatus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
upt.Where(x => x.BusinessType == businessType && x.BusinessId == businessId)
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await upt.Where(x => x.BusinessType == businessType && x.BusinessId == businessId).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
await ex.LogAsync(db);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -879,6 +887,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
{
|
|
|
|
|
billFeeStatus = BillFeeStatus.NotEntered;
|
|
|
|
|
}
|
|
|
|
|
//全状态
|
|
|
|
|
else if (fees.All(x => x.FeeStatus == FeeStatus.Entering))
|
|
|
|
|
{
|
|
|
|
|
billFeeStatus = BillFeeStatus.Entering;
|
|
|
|
@ -903,6 +912,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
{
|
|
|
|
|
billFeeStatus = BillFeeStatus.SettlementCompleted;
|
|
|
|
|
}
|
|
|
|
|
//部分状态
|
|
|
|
|
else if (fees.Any(x => x.FeeStatus == FeeStatus.Entering))
|
|
|
|
|
{
|
|
|
|
|
billFeeStatus = BillFeeStatus.PartialEntering;
|
|
|
|
@ -933,13 +943,13 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取汇率
|
|
|
|
|
void FetchExchangeRate(SqlSugarScopeProvider tenantDb, IEnumerable<FeeRecord> items)
|
|
|
|
|
async Task FetchExchangeRateAsync(SqlSugarScopeProvider tenantDb, IEnumerable<FeeRecord> items)
|
|
|
|
|
{
|
|
|
|
|
var exRecords = items.Where(x => !x.ExchangeRate.HasValue && x.Currency != DefaultCurrency).ToList();
|
|
|
|
|
if (exRecords.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var codes = exRecords.Select(x => x.Currency).Distinct().ToList();
|
|
|
|
|
var currencies = tenantDb.Queryable<FeeCurrency>().Where(x => codes.Contains(x.CodeName)).Includes(x => x.Exchanges).ToList();
|
|
|
|
|
var currencies = await tenantDb.Queryable<FeeCurrency>().Where(x => codes.Contains(x.CodeName)).Includes(x => x.Exchanges).ToListAsync();
|
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
|
|
foreach (var item in exRecords)
|
|
|
|
|
{
|
|
|
|
|