|
|
|
@ -39,7 +39,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
var query = TenantDb.Queryable<ApplicationSettlement>().WhereIF(!string.IsNullOrEmpty(request.OtherQueryCondition?.Number), x =>
|
|
|
|
|
SqlFunc.Subqueryable<ApplicationDetail>().InnerJoin<FeeRecord>((d, f) => d.RecordId == f.Id && f.BusinessType == BusinessType.OceanShippingExport)
|
|
|
|
|
.InnerJoin<SeaExport>((d, f, s) => f.BusinessId == s.Id).Where((d, f, s) =>
|
|
|
|
|
s.CustomerNo.Contains(request.OtherQueryCondition.Number) || s.BookingNo.Contains(request.OtherQueryCondition.Number) ||
|
|
|
|
|
s.CustomerNo.Contains(request.OtherQueryCondition.Number) || s.BookingNo.Contains(request.OtherQueryCondition.Number) ||
|
|
|
|
|
s.MBLNO.Contains(request.OtherQueryCondition.Number) || s.CustomerNum.Contains(request.OtherQueryCondition.Number)).Any())
|
|
|
|
|
.Select(x => new ApplicationSettlementDto
|
|
|
|
|
{
|
|
|
|
@ -472,40 +472,42 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
protected override async Task<ApplicationSettlement> PostSaveAsync(ApplicationSettlement settlement)
|
|
|
|
|
{
|
|
|
|
|
//回写付费申请的状态
|
|
|
|
|
var ids = settlement.Details.Select(x => x.DetailId);
|
|
|
|
|
var appIds = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.Id) && (x.Category == DetailCategory.PaidApplication || x.Category == DetailCategory.ChargeApplication))
|
|
|
|
|
.Select(x => x.ApplicationId).ToListAsync();
|
|
|
|
|
if (settlement.BillType == SettlementBillType.Payment)
|
|
|
|
|
{
|
|
|
|
|
var ids = settlement.Details.Select(x => x.DetailId);
|
|
|
|
|
var appIds = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.Id) && x.Category == DetailCategory.PaidApplication)
|
|
|
|
|
.Select(x => x.ApplicationId).ToListAsync();
|
|
|
|
|
|
|
|
|
|
var details = await TenantDb.Queryable<ApplicationDetail>().Where(x => appIds.Contains(x.ApplicationId) && x.Category == DetailCategory.PaidApplication)
|
|
|
|
|
.GroupBy(x => x.ApplicationId).Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.ApplicationId,
|
|
|
|
|
Count = SqlFunc.AggregateCount(x.Id),
|
|
|
|
|
ProcessedCount = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => appIds.Contains(y.ApplicationId) &&
|
|
|
|
|
y.Category == DetailCategory.PaidApplication && y.OriginalAmount - y.OriginalProcessedAmount == 0).Count()
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
var details = await TenantDb.Queryable<ApplicationDetail>().Where(x => appIds.Contains(x.ApplicationId) &&
|
|
|
|
|
(x.Category == DetailCategory.PaidApplication || x.Category == DetailCategory.ChargeApplication))
|
|
|
|
|
.GroupBy(x => x.ApplicationId).Select(x => new
|
|
|
|
|
List<PaymentApplication> applications = [];
|
|
|
|
|
foreach (var item in details)
|
|
|
|
|
{
|
|
|
|
|
x.ApplicationId,
|
|
|
|
|
Count = SqlFunc.AggregateCount(x.Id),
|
|
|
|
|
ProcessedCount = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => appIds.Contains(y.ApplicationId) &&
|
|
|
|
|
(y.Category == DetailCategory.PaidApplication || y.Category == DetailCategory.ChargeApplication) &&
|
|
|
|
|
y.OriginalAmount - y.OriginalProcessedAmount == 0).Count()
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
if (item.Count == 0 || item.ProcessedCount == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
List<PaymentApplication> applications = [];
|
|
|
|
|
foreach (var item in details)
|
|
|
|
|
{
|
|
|
|
|
if (item.Count == 0 || item.ProcessedCount == 0)
|
|
|
|
|
continue;
|
|
|
|
|
var entity = new PaymentApplication { Id = item.ApplicationId };
|
|
|
|
|
if (item.Count == item.ProcessedCount)
|
|
|
|
|
{
|
|
|
|
|
entity.Status = PaymentApplicationStatus.SettlementCompleted;
|
|
|
|
|
}
|
|
|
|
|
else if (item.ProcessedCount != 0)
|
|
|
|
|
{
|
|
|
|
|
entity.Status = PaymentApplicationStatus.PartialSettlement;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var entity = new PaymentApplication { Id = item.ApplicationId };
|
|
|
|
|
if (item.Count == item.ProcessedCount)
|
|
|
|
|
{
|
|
|
|
|
entity.Status = PaymentApplicationStatus.SettlementCompleted;
|
|
|
|
|
}
|
|
|
|
|
else if (item.ProcessedCount != 0)
|
|
|
|
|
{
|
|
|
|
|
entity.Status = PaymentApplicationStatus.PartialSettlement;
|
|
|
|
|
applications.Add(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
applications.Add(entity);
|
|
|
|
|
await TenantDb.Updateable(applications).UpdateColumns(x => new { x.Status }).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
await TenantDb.Updateable(applications).UpdateColumns(x => new { x.Status }).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await base.PostSaveAsync(settlement);
|
|
|
|
|
}
|
|
|
|
|