From fad6e81e4ad977a693de66e8d53cd52aad1247c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B5=87=E6=96=87=E9=BE=99?= Date: Fri, 27 Sep 2024 15:32:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E7=A5=A8=E7=BB=93=E7=AE=97=E8=AF=A6?= =?UTF-8?q?=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Settlement/Dtos/SettlementDetailDto.cs | 6 +- .../Method/ApplicationSettlementService.cs | 163 ++++++++++-------- .../Method/InvoiceSettlementService.cs | 8 +- 3 files changed, 101 insertions(+), 76 deletions(-) diff --git a/ds-wms-service/DS.WMS.Core/Settlement/Dtos/SettlementDetailDto.cs b/ds-wms-service/DS.WMS.Core/Settlement/Dtos/SettlementDetailDto.cs index cb40452f..4931beac 100644 --- a/ds-wms-service/DS.WMS.Core/Settlement/Dtos/SettlementDetailDto.cs +++ b/ds-wms-service/DS.WMS.Core/Settlement/Dtos/SettlementDetailDto.cs @@ -17,7 +17,9 @@ namespace DS.WMS.Core.Settlement.Dtos /// /// 申请单号 /// - public string? ApplicationNO { get; set; } + public string? ApplicationNO => ApplicationNOList == null ? string.Empty : string.Join(",", ApplicationNOList); + + public List? ApplicationNOList { get; set; } /// /// 状态 @@ -54,7 +56,7 @@ namespace DS.WMS.Core.Settlement.Dtos /// public decimal InvoiceAmount { get; set; } - + /// /// 原始金额 /// 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 6cdb1a2a..941e2966 100644 --- a/ds-wms-service/DS.WMS.Core/Settlement/Method/ApplicationSettlementService.cs +++ b/ds-wms-service/DS.WMS.Core/Settlement/Method/ApplicationSettlementService.cs @@ -12,7 +12,6 @@ using DS.WMS.Core.Settlement.Dtos; using DS.WMS.Core.Settlement.Entity; using DS.WMS.Core.Settlement.Interface; using DS.WMS.Core.Sys.Entity; -using Masuit.Tools.Systems; using SqlSugar; namespace DS.WMS.Core.Settlement.Method @@ -113,81 +112,99 @@ namespace DS.WMS.Core.Settlement.Method return DataResult.Success(model); } - //获取结算明细 + /// + /// 获取费用申请结算明细 + /// + /// + /// protected override async Task> GetSettlementDetails(long id) { - var list = await TenantDb.Queryable() - .InnerJoin((d, pd) => d.DetailId == pd.Id) - .InnerJoin((d, pd, pa) => pd.ApplicationId == pa.Id) - .Where(d => d.ApplicationId == id) - .Select((d, pd, pa) => new - { - d.Id, - d.ApplicationId, - d.ApplyAmount, - d.Currency, - d.OriginalCurrency, - d.OriginalAmount, - pa.ApplicationNO, - pa.Status, - pa.CreateTime, - pa.CreateBy, - pa.PaymentDate, - pa.Note - }).ToListAsync(); - - var details = new List(); - if (list.Count == 0) - return details; - - var gp = list.GroupBy(d => d.ApplicationId); - var uids = list.Select(x => x.CreateBy).Distinct(); - var users = await Db.Queryable().Where(x => uids.Contains(x.Id)).Select(x => new - { - x.Id, - x.UserName - }).ToListAsync(); - - foreach (var g in gp) - { - var firstItem = g.FirstOrDefault(); - - var dto = new SettlementDetailDto - { - ApplicationId = g.Key, - //Ids = g.Select(x => x.Id), - RMBApplyAmount = g.Where(x => x.OriginalCurrency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount), - USDApplyAmount = g.Where(x => x.OriginalCurrency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount), - ApplicationNO = firstItem.ApplicationNO, - Status = (int)firstItem.Status, - StatusText = firstItem.Status.GetDescription(), - CreateTime = firstItem?.CreateTime, - CreateBy = firstItem?.CreateBy, - CreateByName = users.Find(x => x.Id == firstItem?.CreateBy)?.UserName, - PaymentDate = firstItem?.PaymentDate, - Note = firstItem?.Note - }; - - //包含多个币别 - if (g.GroupBy(x => x.OriginalCurrency).Select(x => x.Key).Count() > 1) - { - //原始币别=不等于结算单币别的首个币别(参考DS7) - dto.OriginalCurrency = g.Select(x => x.OriginalCurrency).FirstOrDefault(); - //原始金额=当前结算单的币别合计 - dto.OriginalAmount = g.Sum(x => x.ApplyAmount); - } - else + var list = await TenantDb.Queryable() + .InnerJoin((i, d1) => i.Id == d1.ApplicationId) + .InnerJoin((i, d1, d2) => d1.ApplicationId == d2.RefId) + .Where((i, d1, d2) => d2.ApplicationId == id && + d2.Category == DetailCategory.PaidApplication && d1.Category == DetailCategory.ChargeApplication) + .GroupBy((i, d1, d2) => i.Id) + .Select((i, d1, d2) => new SettlementDetailDto { - dto.OriginalCurrency = firstItem?.OriginalCurrency; - dto.OriginalAmount = g.Where(x => x.OriginalCurrency == dto.OriginalCurrency).Sum(x => x.ApplyAmount); - } - - //结算金额=原申请的原始币别合计 - dto.SettlementAmount = g.Where(x => x.OriginalCurrency == dto.OriginalCurrency).Sum(x => x.ApplyAmount); - details.Add(dto); - } - - return details; + SettlementAmount = SqlFunc.Subqueryable().Where(d3 => d3.ApplicationId == i.Id).Sum(d3 => d3.ApplyAmount), + ApplicationNOList = SqlFunc.Subqueryable().Where(a => a.Id == d1.RefId).ToList(a => a.ApplicationNO) + }, true).ToListAsync(); + + return list; + + //var list = await TenantDb.Queryable() + // .InnerJoin((d, pd) => d.DetailId == pd.Id) + // .InnerJoin((d, pd, pa) => pd.ApplicationId == pa.Id) + // .Where(d => d.ApplicationId == id) + // .Select((d, pd, pa) => new + // { + // d.Id, + // d.ApplicationId, + // d.ApplyAmount, + // d.Currency, + // d.OriginalCurrency, + // d.OriginalAmount, + // pa.ApplicationNO, + // pa.Status, + // pa.CreateTime, + // pa.CreateBy, + // pa.PaymentDate, + // pa.Note + // }).ToListAsync(); + + //var details = new List(); + //if (list.Count == 0) + // return details; + + //var gp = list.GroupBy(d => d.ApplicationId); + //var uids = list.Select(x => x.CreateBy).Distinct(); + //var users = await Db.Queryable().Where(x => uids.Contains(x.Id)).Select(x => new + //{ + // x.Id, + // x.UserName + //}).ToListAsync(); + + //foreach (var g in gp) + //{ + // var firstItem = g.FirstOrDefault(); + + // var dto = new SettlementDetailDto + // { + // ApplicationId = g.Key, + // //Ids = g.Select(x => x.Id), + // RMBApplyAmount = g.Where(x => x.OriginalCurrency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount), + // USDApplyAmount = g.Where(x => x.OriginalCurrency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount), + // ApplicationNO = firstItem.ApplicationNO, + // Status = (int)firstItem.Status, + // StatusText = firstItem.Status.GetDescription(), + // CreateTime = firstItem?.CreateTime, + // CreateBy = firstItem?.CreateBy, + // CreateByName = users.Find(x => x.Id == firstItem?.CreateBy)?.UserName, + // PaymentDate = firstItem?.PaymentDate, + // Note = firstItem?.Note + // }; + + // //包含多个币别 + // if (g.GroupBy(x => x.OriginalCurrency).Select(x => x.Key).Count() > 1) + // { + // //原始币别=不等于结算单币别的首个币别(参考DS7) + // dto.OriginalCurrency = g.Select(x => x.OriginalCurrency).FirstOrDefault(); + // //原始金额=当前结算单的币别合计 + // dto.OriginalAmount = g.Sum(x => x.ApplyAmount); + // } + // else + // { + // dto.OriginalCurrency = firstItem?.OriginalCurrency; + // dto.OriginalAmount = g.Where(x => x.OriginalCurrency == dto.OriginalCurrency).Sum(x => x.ApplyAmount); + // } + + // //结算金额=原申请的原始币别合计 + // dto.SettlementAmount = g.Where(x => x.OriginalCurrency == dto.OriginalCurrency).Sum(x => x.ApplyAmount); + // details.Add(dto); + //} + + //return details; } /// diff --git a/ds-wms-service/DS.WMS.Core/Settlement/Method/InvoiceSettlementService.cs b/ds-wms-service/DS.WMS.Core/Settlement/Method/InvoiceSettlementService.cs index 1e78eee3..e9666782 100644 --- a/ds-wms-service/DS.WMS.Core/Settlement/Method/InvoiceSettlementService.cs +++ b/ds-wms-service/DS.WMS.Core/Settlement/Method/InvoiceSettlementService.cs @@ -184,6 +184,11 @@ namespace DS.WMS.Core.Settlement.Method return DataResult>.Success(documents); } + /// + /// 获取发票结算明细 + /// + /// + /// protected override async Task> GetSettlementDetails(long id) { var list = await TenantDb.Queryable() @@ -196,7 +201,8 @@ namespace DS.WMS.Core.Settlement.Method { InvoiceApplyAmount = i.ApplyAmount, InvoiceAmount = i.InvoiceAmount, - SettlementAmount = SqlFunc.Subqueryable().Where(d3 => d3.ApplicationId == i.Id).Sum(d3 => d3.ApplyAmount) + SettlementAmount = SqlFunc.Subqueryable().Where(d3 => d3.ApplicationId == i.Id).Sum(d3 => d3.ApplyAmount), + ApplicationNOList = SqlFunc.Subqueryable().Where(a => a.Id == d1.RefId).ToList(a => a.ApplicationNO) }, true).ToListAsync(); return list;