|
|
|
@ -6,7 +6,6 @@ using DS.Module.UserModule;
|
|
|
|
|
using DS.WMS.Core.Fee.Dtos;
|
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
|
using DS.WMS.Core.Fee.Interface;
|
|
|
|
|
using DS.WMS.Core.Flow.Entity;
|
|
|
|
|
using DS.WMS.Core.Flow.Interface;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
@ -48,7 +47,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
public async Task<DataResult<List<FeeApplicationBiz>>> GetBizListAsync(PageRequest request)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var queryList = CreateBizQuery(tenantDb, null);
|
|
|
|
|
var queryList = CreateBizQuery(tenantDb);
|
|
|
|
|
|
|
|
|
|
if (!request.QueryCondition.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
@ -77,15 +76,12 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//创建各项业务数据的查询并集
|
|
|
|
|
internal static ISugarQueryable<FeeApplicationBiz> CreateBizQuery(SqlSugarScopeProvider tenantDb, IEnumerable<FlowInstance>? additions)
|
|
|
|
|
internal static ISugarQueryable<FeeApplicationBiz> CreateBizQuery(SqlSugarScopeProvider tenantDb)
|
|
|
|
|
{
|
|
|
|
|
//海运出口
|
|
|
|
|
var ids1 = additions?.Where(x => x.BusinessType == BusinessType.OceanShippingExport).Select(x => x.BusinessId).ToList();
|
|
|
|
|
if (ids1?.Count == 0)
|
|
|
|
|
ids1.Add(0);
|
|
|
|
|
|
|
|
|
|
var query1 = tenantDb.Queryable<SeaExport>()
|
|
|
|
|
.Where(s => ids1.Contains(s.Id))
|
|
|
|
|
var query1 = tenantDb.Queryable<SeaExport>().InnerJoin<FeeRecord>((s, f) => s.Id == f.BusinessId && f.BusinessType == BusinessType.OceanShippingExport)
|
|
|
|
|
.Where((s, f) => f.FeeStatus == FeeStatus.AuditPassed)
|
|
|
|
|
.GroupBy((s, f) => s.Id)
|
|
|
|
|
.Select(s => new FeeApplicationBiz
|
|
|
|
|
{
|
|
|
|
|
Id = s.Id,
|
|
|
|
@ -110,21 +106,21 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
BookingNO = s.BookingNo,
|
|
|
|
|
StlName = s.StlName,
|
|
|
|
|
UnpaidRMB = SqlFunc.Subqueryable<FeeRecord>().Where(f => f.BusinessId == s.Id && f.FeeStatus == FeeStatus.AuditPassed &&
|
|
|
|
|
f.FeeType == FeeType.Payable && f.Currency == "CNY").Select(x => SqlFunc.AggregateSumNoNull(x.Amount.Value)),
|
|
|
|
|
f.FeeType == FeeType.Payable && f.Currency == "CNY").Select(f => SqlFunc.AggregateSumNoNull(f.Amount.Value)),
|
|
|
|
|
UnpaidUSD = SqlFunc.Subqueryable<FeeRecord>().Where(f => f.BusinessId == s.Id && f.FeeStatus == FeeStatus.AuditPassed &&
|
|
|
|
|
f.FeeType == FeeType.Payable && f.Currency == "USD").Select(x => SqlFunc.AggregateSumNoNull(x.Amount.Value)),
|
|
|
|
|
f.FeeType == FeeType.Payable && f.Currency == "USD").Select(f => SqlFunc.AggregateSumNoNull(f.Amount.Value)),
|
|
|
|
|
UnpaidOther = SqlFunc.Subqueryable<FeeRecord>().Where(f => f.BusinessId == s.Id && f.FeeStatus == FeeStatus.AuditPassed &&
|
|
|
|
|
f.FeeType == FeeType.Payable && (f.Currency != "USD" && f.Currency != "CNY")).Select(x => SqlFunc.AggregateSumNoNull(x.Amount.Value)),
|
|
|
|
|
f.FeeType == FeeType.Payable && (f.Currency != "USD" && f.Currency != "CNY")).Select(f => SqlFunc.AggregateSumNoNull(f.Amount.Value)),
|
|
|
|
|
UnreceivedRMB = SqlFunc.Subqueryable<FeeRecord>().Where(f => f.BusinessId == s.Id && f.FeeStatus == FeeStatus.AuditPassed &&
|
|
|
|
|
f.FeeType == FeeType.Receivable && f.Currency == "CNY").Select(x => SqlFunc.AggregateSumNoNull(x.Amount.Value)),
|
|
|
|
|
f.FeeType == FeeType.Receivable && f.Currency == "CNY").Select(f => SqlFunc.AggregateSumNoNull(f.Amount.Value)),
|
|
|
|
|
UnreceivedUSD = SqlFunc.Subqueryable<FeeRecord>().Where(f => f.BusinessId == s.Id && f.FeeStatus == FeeStatus.AuditPassed &&
|
|
|
|
|
f.FeeType == FeeType.Receivable && f.Currency == "USD").Select(x => SqlFunc.AggregateSumNoNull(x.Amount.Value)),
|
|
|
|
|
f.FeeType == FeeType.Receivable && f.Currency == "USD").Select(f => SqlFunc.AggregateSumNoNull(f.Amount.Value)),
|
|
|
|
|
UnreceivedOther = SqlFunc.Subqueryable<FeeRecord>().Where(f => f.BusinessId == s.Id && f.FeeStatus == FeeStatus.AuditPassed &&
|
|
|
|
|
f.FeeType == FeeType.Receivable && (f.Currency != "USD" && f.Currency != "CNY")).Select(x => SqlFunc.AggregateSumNoNull(x.Amount.Value)),
|
|
|
|
|
f.FeeType == FeeType.Receivable && (f.Currency != "USD" && f.Currency != "CNY")).Select(f => SqlFunc.AggregateSumNoNull(f.Amount.Value)),
|
|
|
|
|
UnpaidRMBInv = SqlFunc.Subqueryable<FeeRecord>().Where(f => f.BusinessId == s.Id && f.FeeStatus == FeeStatus.AuditPassed &&
|
|
|
|
|
f.FeeType == FeeType.Payable && f.Currency == "CNY").Select(x => SqlFunc.AggregateSumNoNull(x.InvoiceAmount.Value)),
|
|
|
|
|
f.FeeType == FeeType.Payable && f.Currency == "CNY").Select(f => SqlFunc.AggregateSumNoNull(f.InvoiceAmount.Value)),
|
|
|
|
|
UnpaidUSDInv = SqlFunc.Subqueryable<FeeRecord>().Where(f => f.BusinessId == s.Id && f.FeeStatus == FeeStatus.AuditPassed &&
|
|
|
|
|
f.FeeType == FeeType.Payable && f.Currency == "USD").Select(x => SqlFunc.AggregateSumNoNull(x.InvoiceAmount.Value))
|
|
|
|
|
f.FeeType == FeeType.Payable && f.Currency == "USD").Select(f => SqlFunc.AggregateSumNoNull(f.InvoiceAmount.Value))
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//海运进口
|
|
|
|
@ -173,18 +169,35 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
return DataResult.Failed("只能修改状态为:未提交/审核驳回的申请单");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//关联用户名称
|
|
|
|
|
var userIds = new long?[] { application.SettlerId, application.PaymentApplicantId };
|
|
|
|
|
var users = await db.Queryable<SysUser>().Where(x => userIds.Contains(x.Id)).Select(x => new { x.Id, x.UserName }).ToListAsync();
|
|
|
|
|
application.SettlerName = application.SettlerId.HasValue ? users.Find(x => x.Id == application.SettlerId.Value)?.UserName : string.Empty;
|
|
|
|
|
application.PaymentApplicantName = application.PaymentApplicantId.HasValue ? users.Find(x => x.Id == application.PaymentApplicantId.Value)?.UserName : string.Empty;
|
|
|
|
|
|
|
|
|
|
await tenantDb.Ado.BeginTranAsync();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await tenantDb.Ado.BeginTranAsync();
|
|
|
|
|
|
|
|
|
|
//关联导航属性插入
|
|
|
|
|
if (application.Id == 0)
|
|
|
|
|
{
|
|
|
|
|
await tenantDb.InsertNav(application).Include(x => x.Details).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
//关联导航属性更新
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await tenantDb.UpdateNav(application).Include(x => x.Details).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await tenantDb.Ado.CommitTranAsync();
|
|
|
|
|
return DataResult.Success;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
await tenantDb.Ado.RollbackTranAsync();
|
|
|
|
|
await ex.LogAsync(db);
|
|
|
|
|
return DataResult.Failed("发生错误,提交失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -199,14 +212,48 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
if (await tenantDb.Queryable<FeeApplication>().AnyAsync(x => ids.Contains(x.Id) && (x.Status != ApplicationStatus.Pending && x.Status != ApplicationStatus.AuditRejected)))
|
|
|
|
|
return DataResult.Failed("只能删除状态为‘待审核’或‘驳回’的申请单", MultiLanguageConst.FeeRecordDelete);
|
|
|
|
|
|
|
|
|
|
int result = await tenantDb.Deleteable<FeeApplication>(x => ids.Contains(x.Id)).ExecuteCommandAsync();
|
|
|
|
|
return result > 0 ? DataResult.Successed("删除成功!") : DataResult.Failed("删除失败!");
|
|
|
|
|
bool result = await tenantDb.DeleteNav<FeeApplication>(x => ids.Contains(x.Id)).Include(x => x.Details).ExecuteCommandAsync();
|
|
|
|
|
return result ? DataResult.Successed("删除成功!") : DataResult.Failed("删除失败!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 提交审批
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="remark">审批备注</param>
|
|
|
|
|
/// <param name="idArray">申请单ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> SubmitForApprovalAsync(string remark, params long[] idArray)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var list = await tenantDb.Queryable<FeeApplication>().Where(x => idArray.Contains(x.Id))
|
|
|
|
|
.Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
x.Status,
|
|
|
|
|
ItemCount = x.Details.Count()
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (list.Exists(x => x.Status == ApplicationStatus.AuditSubmittd || x.Status == ApplicationStatus.AuditPassed))
|
|
|
|
|
return DataResult.Failed("提交内容包含正在审批中/已审批的申请单", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
|
if (list.Exists(x => x.ItemCount == 0))
|
|
|
|
|
return DataResult.Failed("提交审批时必须包含费用明细,请检查", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
|
await tenantDb.Ado.BeginTranAsync();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list2 = list.Select(x => new FeeApplication { Id = x.Id, Status = ApplicationStatus.AuditSubmittd }).ToList();
|
|
|
|
|
await tenantDb.Updateable(list2).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
await tenantDb.Ado.CommitTranAsync();
|
|
|
|
|
return DataResult.Success;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
await tenantDb.Ado.RollbackTranAsync();
|
|
|
|
|
await ex.LogAsync(db);
|
|
|
|
|
return DataResult.Failed("发生错误,提交失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<DataResult> WithdrawAsync(params long[] ids)
|
|
|
|
|