From aa99ad4bb98a9935507fb5ba24f7303e535b246d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B5=87=E6=96=87=E9=BE=99?= Date: Thu, 7 Nov 2024 17:54:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=93=E7=AE=97=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Method/ApplicationSettlementService.cs | 55 ++++++++++++++----- .../Settlement/Method/SettlementService`1.cs | 19 +++++-- 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/ds-wms-service/DS.WMS.Core/Settlement/Method/ApplicationSettlementService.cs b/ds-wms-service/DS.WMS.Core/Settlement/Method/ApplicationSettlementService.cs index 0db7489a..24b57fe7 100644 --- a/ds-wms-service/DS.WMS.Core/Settlement/Method/ApplicationSettlementService.cs +++ b/ds-wms-service/DS.WMS.Core/Settlement/Method/ApplicationSettlementService.cs @@ -141,29 +141,54 @@ namespace DS.WMS.Core.Settlement.Method /// protected override async Task> GetSettlementDetails(long id) { + var appIds = await TenantDb.Queryable().Where(x => x.ApplicationId == id) + .Select(x => x.DetailId).ToListAsync(); + var list = await TenantDb.Queryable() - .InnerJoin((i, d1) => i.Id == d1.ApplicationId) //d1=申请明细 - .InnerJoin((i, d1, d2) => d2.DetailId == d1.Id) //d2=结算明细 - .Where((i, d1, d2) => d2.ApplicationId == id) - .GroupBy((i, d1, d2) => i.Id) - .Select((i, d1, d2) => new SettlementDetailGroup + .InnerJoin((pa, d1) => pa.Id == d1.ApplicationId) //d1=申请明细 + .Where((pa, d1) => SqlFunc.Subqueryable().Where(d2 => d2.DetailId == d1.Id && d2.ApplicationId == id).Any()) + .GroupBy((pa, d1) => pa.Id) + .Select((pa, d1) => new SettlementDetailGroup { - Status = (int)i.Status, - BillNO = i.ApplicationNO, - PaymentDate = i.PaymentDate, - RMBApplyAmount = SqlFunc.Subqueryable().Where(x => x.ApplicationId == d2.RefId && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount), - USDApplyAmount = SqlFunc.Subqueryable().Where(x => x.ApplicationId == d2.RefId && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount), - RMBStlAmount = SqlFunc.Subqueryable().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount), - USDStlAmount = SqlFunc.Subqueryable().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount), - RMBStlRestAmount = SqlFunc.Subqueryable().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount - x.ProcessedAmount), - USDStlRestAmount = SqlFunc.Subqueryable().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount - x.ProcessedAmount), - //ApplicationNOList = SqlFunc.Subqueryable().Where(a => a.Id == d1.RefId.Value).ToList(a => a.ApplicationNO) + Id = pa.Id, + Status = (int)pa.Status, + BillNO = pa.ApplicationNO, + PaymentDate = pa.PaymentDate, + //RMBApplyAmount = SqlFunc.Subqueryable().Where(x => x.ApplicationId == d2.RefId && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount), + //USDApplyAmount = SqlFunc.Subqueryable().Where(x => x.ApplicationId == d2.RefId && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount), + //RMBStlAmount = SqlFunc.Subqueryable().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount), + //USDStlAmount = SqlFunc.Subqueryable().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount), + //RMBStlRestAmount = SqlFunc.Subqueryable().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount - x.ProcessedAmount), + //USDStlRestAmount = SqlFunc.Subqueryable().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount - x.ProcessedAmount), }, true).ToListAsync(); + var ids = list.Select(x => x.Id); + var appDetails = await TenantDb.Queryable().Where(x => ids.Contains(x.ApplicationId)) + .Select(x => new + { + x.Id, + x.ApplicationId, + x.Currency, + x.ApplyAmount, + }).ToListAsync(); + foreach (var item in list) { PaymentApplicationStatus status = (PaymentApplicationStatus)item.Status; item.StatusText = status.GetDescription(); + + //申请金额 + var details = appDetails.Where(x => x.ApplicationId == item.Id); + item.RMBApplyAmount = details.Where(x => x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount); + item.USDApplyAmount = details.Where(x => x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount); + + //本次结算金额 + item.RMBStlAmount = details.Where(x => appIds.Contains(x.Id) && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount); + item.USDStlAmount = details.Where(x => appIds.Contains(x.Id) && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount); + + //剩余结算金额 + item.RMBStlRestAmount = (item.RMBApplyAmount - item.RMBStlAmount).GetValueOrDefault(); + item.RMBStlRestAmount = (item.USDApplyAmount - item.USDStlAmount).GetValueOrDefault(); } return list; diff --git a/ds-wms-service/DS.WMS.Core/Settlement/Method/SettlementService`1.cs b/ds-wms-service/DS.WMS.Core/Settlement/Method/SettlementService`1.cs index 480c77cc..71de85c8 100644 --- a/ds-wms-service/DS.WMS.Core/Settlement/Method/SettlementService`1.cs +++ b/ds-wms-service/DS.WMS.Core/Settlement/Method/SettlementService`1.cs @@ -113,10 +113,19 @@ namespace DS.WMS.Core.Settlement.Method if (settlement.Mode == SettlementMode.Payment || settlement.Mode == SettlementMode.Charge) { var detailCategory = settlement.Mode == SettlementMode.Payment ? DetailCategory.PaidApplication : DetailCategory.ChargeApplication; - details1 = await TenantDb.Queryable().Where(x => ids.Contains(x.ApplicationId) && x.Category == detailCategory) - .WhereIF(request.Documents.Any(x => x.SettlementRMB.HasValue), x => x.Currency == FeeCurrency.RMB_CODE) - .WhereIF(request.Documents.Any(x => x.SettlementUSD.HasValue), x => x.Currency == FeeCurrency.USD_CODE) - .WhereIF(request.Documents.Any(x => x.SettlementOther.HasValue), x => x.Currency != FeeCurrency.RMB_CODE && x.Currency != FeeCurrency.USD_CODE) + var expr = Expressionable.Create().And(x => ids.Contains(x.ApplicationId) && x.Category == detailCategory); + + if (request.Documents.Any(x => x.SettlementRMB.GetValueOrDefault() == 0) || request.Documents.Any(x => x.SettlementUSD.GetValueOrDefault() == 0) || + request.Documents.Any(x => x.SettlementOther.GetValueOrDefault() == 0)) //按币别结算 + { + if (request.Documents.Any(x => x.SettlementRMB.GetValueOrDefault() != 0)) + expr = expr.And(x => x.Currency == FeeCurrency.RMB_CODE); + + if (request.Documents.Any(x => x.SettlementUSD.GetValueOrDefault() != 0)) + expr = expr.And(x => x.Currency == FeeCurrency.USD_CODE); + } + + details1 = await TenantDb.Queryable().Where(expr.ToExpression()) .Select(x => new ApplicationDetail { ApplicationId = settlement.Id, @@ -152,7 +161,7 @@ namespace DS.WMS.Core.Settlement.Method return DataResult.Failed($"未传入结算币别 {settlement.Currency} 与费用原币别 {detail.OriginalCurrency} 之间的汇率信息"); detail.ExchangeRate = exchange.ExchangeRate; - detail.ApplyAmount = Math.Round(exchange.ExchangeRate.GetValueOrDefault() * detail.OriginalAmount, 2, MidpointRounding.AwayFromZero); + //detail.ApplyAmount = Math.Round(exchange.ExchangeRate.GetValueOrDefault() * detail.OriginalAmount, 2, MidpointRounding.AwayFromZero); } } }