仅保留新增费用明细

dev
嵇文龙 2 months ago
parent cd02b873e1
commit 0f5ff79719

@ -48,7 +48,7 @@ namespace DS.WMS.Core.Settlement.Method
CustomerAccount = x.CustomerBank.AccountName + "/" + x.CustomerBank.Currency, CustomerAccount = x.CustomerBank.AccountName + "/" + x.CustomerBank.Currency,
CustomerBankName = x.CustomerBank.BankName, CustomerBankName = x.CustomerBank.BankName,
//未开票 //未开票
UnInvoiceList = SqlFunc.Subqueryable<ApplicationDetail>().InnerJoin<FeeRecord>((d, f) => d.RecordId == f.Id && (f.Amount - f.InvoiceAmount - f.OrderInvoiceAmount) != 0) UnInvoiceList = SqlFunc.Subqueryable<ApplicationDetail>().InnerJoin<FeeRecord>((d, f) => d.ApplicationId == x.Id && d.RecordId == f.Id && (f.Amount - f.InvoiceAmount - f.OrderInvoiceAmount) != 0)
.GroupBy((d, f) => f.Currency).ToList((d, f) => new CurrencyAmount { Currency = f.Currency, Amount = f.Amount - f.InvoiceAmount - f.OrderInvoiceAmount }), .GroupBy((d, f) => f.Currency).ToList((d, f) => new CurrencyAmount { Currency = f.Currency, Amount = f.Amount - f.InvoiceAmount - f.OrderInvoiceAmount }),
}, true); }, true);

@ -11,6 +11,7 @@ using DS.WMS.Core.Settlement.Dtos;
using DS.WMS.Core.Settlement.Entity; using DS.WMS.Core.Settlement.Entity;
using DS.WMS.Core.Settlement.Interface; using DS.WMS.Core.Settlement.Interface;
using DS.WMS.Core.Sys.Entity; using DS.WMS.Core.Sys.Entity;
using Fasterflect;
using SqlSugar; using SqlSugar;
namespace DS.WMS.Core.Settlement.Method namespace DS.WMS.Core.Settlement.Method
@ -41,6 +42,10 @@ namespace DS.WMS.Core.Settlement.Method
if (model != null) if (model != null)
{ {
if (model.SaleDeptId.HasValue)
model.SaleDeptName = await Db.Queryable<SysOrg>().Where(x => x.Id == model.SaleDeptId.Value)
.Select(x => x.OrgName).FirstAsync();
model.Details = await GetSettlementDetails(id); model.Details = await GetSettlementDetails(id);
if (model.Details.Count > 0) if (model.Details.Count > 0)
{ {

@ -125,7 +125,7 @@ namespace DS.WMS.Core.Settlement.Method
if (!result.Succeeded) if (!result.Succeeded)
return DataResult<TEntity>.Failed(result.Message, result.MultiCode); return DataResult<TEntity>.Failed(result.Message, result.MultiCode);
List<ApplicationDetail>? details1 = null; List<ApplicationDetail>? details = null;
//自由结算 //自由结算
if (settlement.Mode == SettlementMode.FreeSettlement && request.Details?.Count > 0) if (settlement.Mode == SettlementMode.FreeSettlement && request.Details?.Count > 0)
{ {
@ -220,7 +220,7 @@ namespace DS.WMS.Core.Settlement.Method
if (settlement.Mode == SettlementMode.Payment || settlement.Mode == SettlementMode.Charge) if (settlement.Mode == SettlementMode.Payment || settlement.Mode == SettlementMode.Charge)
{ {
var detailCategory = settlement.Mode == SettlementMode.Payment ? DetailCategory.PaidApplication : DetailCategory.ChargeApplication; var detailCategory = settlement.Mode == SettlementMode.Payment ? DetailCategory.PaidApplication : DetailCategory.ChargeApplication;
details1 = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.ApplicationId) && x.Category == detailCategory) details = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.ApplicationId) && x.Category == detailCategory)
.Select(x => new ApplicationDetail .Select(x => new ApplicationDetail
{ {
ApplicationId = settlement.Id, ApplicationId = settlement.Id,
@ -242,7 +242,7 @@ namespace DS.WMS.Core.Settlement.Method
if (!string.IsNullOrEmpty(settlement.Currency)) //指定结算币别 if (!string.IsNullOrEmpty(settlement.Currency)) //指定结算币别
{ {
var details2 = details1.FindAll(x => x.OriginalCurrency != settlement.Currency); var details2 = details.FindAll(x => x.OriginalCurrency != settlement.Currency);
foreach (var detail in details2) foreach (var detail in details2)
{ {
detail.Currency = settlement.Currency; detail.Currency = settlement.Currency;
@ -263,7 +263,7 @@ namespace DS.WMS.Core.Settlement.Method
//发票结算 //发票结算
else if (settlement.Mode == SettlementMode.InvoiceSettlement || settlement.Mode == SettlementMode.PaymentInvoiceSettlement) else if (settlement.Mode == SettlementMode.InvoiceSettlement || settlement.Mode == SettlementMode.PaymentInvoiceSettlement)
{ {
details1 = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.ApplicationId) && x.Category == DetailCategory.InvoiceIssuance) details = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.ApplicationId) && x.Category == DetailCategory.InvoiceIssuance)
.Select(x => new ApplicationDetail .Select(x => new ApplicationDetail
{ {
ApplicationId = settlement.Id, ApplicationId = settlement.Id,
@ -285,7 +285,7 @@ namespace DS.WMS.Core.Settlement.Method
if (settlement.Currency != FeeCurrency.RMB_CODE) //发票结算非人民币需做转换 if (settlement.Currency != FeeCurrency.RMB_CODE) //发票结算非人民币需做转换
{ {
var details2 = details1.FindAll(x => x.OriginalCurrency != settlement.Currency); var details2 = details.FindAll(x => x.OriginalCurrency != settlement.Currency);
foreach (var detail in details2) foreach (var detail in details2)
{ {
detail.Currency = settlement.Currency; detail.Currency = settlement.Currency;
@ -307,7 +307,7 @@ namespace DS.WMS.Core.Settlement.Method
//执行结算费用分配 //执行结算费用分配
foreach (var doc in request.Documents) foreach (var doc in request.Documents)
{ {
var details2 = details1.Where(x => x.RefId == doc.Id).OrderBy(x => x.ApplyAmount).ToList(); var details2 = details.Where(x => x.RefId == doc.Id).OrderBy(x => x.ApplyAmount).ToList();
var rmbDetails = details2.FindAll(x => x.Currency == FeeCurrency.RMB_CODE); var rmbDetails = details2.FindAll(x => x.Currency == FeeCurrency.RMB_CODE);
var totalRMB = rmbDetails.Sum(x => x.ApplyAmount); var totalRMB = rmbDetails.Sum(x => x.ApplyAmount);
@ -370,11 +370,11 @@ namespace DS.WMS.Core.Settlement.Method
} }
} }
} }
if (details?.Count > 0)
settlement.Details.AddRange(details);
//仅保留新增费用明细
if (details1?.Count > 0) settlement.Details = settlement.Details.FindAll(x => x.Id == 0);
settlement.Details.AddRange(details1);
//金额禁止为0 //金额禁止为0
if (settlement.Details.Exists(x => x.ApplyAmount == 0 || x.OriginalAmount == 0)) if (settlement.Details.Exists(x => x.ApplyAmount == 0 || x.OriginalAmount == 0))
return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.AmountCannotBeZero)); return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.AmountCannotBeZero));
@ -388,15 +388,15 @@ namespace DS.WMS.Core.Settlement.Method
if (!result.Succeeded) if (!result.Succeeded)
return DataResult<TEntity>.Failed(result.Message, result.MultiCode); return DataResult<TEntity>.Failed(result.Message, result.MultiCode);
} }
var details = settlement.Details.FindAll(x => x.Id == 0);
await TenantDb.Ado.BeginTranAsync(); await TenantDb.Ado.BeginTranAsync();
try try
{ {
//关联导航属性插入 //关联导航属性插入
if (settlement.Id == 0) if (settlement.Id == 0)
{ {
settlement.Amount = settlement.Details.Sum(x => x.ApplyAmount); if (!string.IsNullOrEmpty(settlement.Currency))
settlement.Amount = settlement.Details.Sum(x => x.ApplyAmount);
//创建时需要生成申请单编号 //创建时需要生成申请单编号
var sequence = CommonService.Value. GetSequenceNext<TEntity>(); var sequence = CommonService.Value. GetSequenceNext<TEntity>();
@ -411,12 +411,12 @@ namespace DS.WMS.Core.Settlement.Method
} }
else else
{ {
if (details.Count > 0) if (settlement.Details.Count > 0)
await TenantDb.Insertable(details).ExecuteCommandAsync(); await TenantDb.Insertable(settlement.Details).ExecuteCommandAsync();
////更新结算金额 if (!string.IsNullOrEmpty(settlement.Currency))
//var dbDetails = await TenantDb.Queryable<ApplicationDetail>().Where(x => x.ApplicationId == settlement.Id) settlement.Amount = await TenantDb.Queryable<ApplicationDetail>()
// .Select(x => new { x.ApplyAmount, x.Currency }).ToListAsync(); .Where(x => x.ApplicationId == settlement.Id).SumAsync(x => x.ApplyAmount);
await TenantDb.Updateable(settlement).IgnoreColumns(x => new await TenantDb.Updateable(settlement).IgnoreColumns(x => new
{ {
@ -433,10 +433,10 @@ namespace DS.WMS.Core.Settlement.Method
await OnSaveAsync(settlement); await OnSaveAsync(settlement);
if (details.Count > 0) if (settlement.Details.Count > 0)
{ {
//更新费用记录的已结算金额 //更新费用记录的已结算金额
var fees = details.Select(x => new FeeRecord var fees = settlement.Details.Select(x => new FeeRecord
{ {
Id = x.RecordId, Id = x.RecordId,
SettlementAmount = x.OriginalAmount SettlementAmount = x.OriginalAmount

@ -5,7 +5,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<_PublishTargetUrl>D:\Publish\DS8\FeeApi</_PublishTargetUrl> <_PublishTargetUrl>D:\Publish\DS8\FeeApi</_PublishTargetUrl>
<History>True|2024-09-27T02:37:35.0336563Z||;False|2024-09-27T10:31:52.6302264+08:00||;True|2024-09-26T19:50:15.5513195+08:00||;True|2024-09-26T19:47:14.0781788+08:00||;True|2024-09-26T19:01:26.5428388+08:00||;True|2024-09-26T18:35:28.7455319+08:00||;True|2024-09-26T18:24:30.8084807+08:00||;True|2024-09-26T18:20:47.3005460+08:00||;True|2024-09-26T18:04:39.8012913+08:00||;True|2024-09-26T17:48:13.8526872+08:00||;True|2024-09-26T16:08:20.1746970+08:00||;True|2024-09-26T16:01:01.1501975+08:00||;False|2024-09-26T16:00:34.1516745+08:00||;True|2024-09-26T14:33:03.4007570+08:00||;True|2024-09-25T19:14:27.8906774+08:00||;True|2024-09-25T18:57:40.1435131+08:00||;True|2024-09-25T17:38:44.0915841+08:00||;True|2024-09-25T15:33:58.4630618+08:00||;True|2024-09-25T15:10:31.3022063+08:00||;False|2024-09-25T14:14:40.9640545+08:00||;True|2024-09-25T10:09:32.2558600+08:00||;True|2024-09-25T09:59:17.1525160+08:00||;False|2024-09-25T09:57:58.7265103+08:00||;False|2024-09-25T09:53:36.7732713+08:00||;False|2024-09-24T18:40:10.0166224+08:00||;True|2024-09-24T08:59:56.1995425+08:00||;True|2024-09-23T18:07:54.7222163+08:00||;True|2024-09-23T17:23:57.7568406+08:00||;True|2024-09-23T16:28:49.3169826+08:00||;True|2024-09-23T15:57:31.8052490+08:00||;True|2024-09-23T11:47:21.1445419+08:00||;True|2024-09-23T09:24:36.0732229+08:00||;True|2024-09-21T11:59:19.0549926+08:00||;True|2024-09-21T11:24:32.4451752+08:00||;True|2024-09-21T10:39:11.5297411+08:00||;True|2024-09-20T18:24:31.7827684+08:00||;True|2024-09-19T17:55:53.1666689+08:00||;True|2024-09-19T17:42:47.9061485+08:00||;True|2024-09-19T16:08:21.7225571+08:00||;False|2024-09-19T14:15:42.9318446+08:00||;True|2024-09-19T11:20:03.5567568+08:00||;True|2024-09-18T11:35:18.1509724+08:00||;True|2024-09-18T09:08:59.1152574+08:00||;True|2024-09-14T15:48:22.9374486+08:00||;True|2024-09-14T15:42:19.0503983+08:00||;True|2024-09-14T11:51:53.3339222+08:00||;True|2024-09-14T11:41:38.3542237+08:00||;True|2024-09-14T11:19:13.1037012+08:00||;True|2024-09-13T14:31:12.4598160+08:00||;True|2024-09-13T10:44:56.1241214+08:00||;False|2024-09-13T10:44:26.6088271+08:00||;False|2024-09-13T10:44:06.1615137+08:00||;False|2024-09-13T10:43:19.2432517+08:00||;False|2024-09-13T10:38:18.1663387+08:00||;True|2024-09-06T18:49:17.9435308+08:00||;True|2024-09-06T17:01:39.6646353+08:00||;True|2024-09-06T10:27:36.9990456+08:00||;True|2024-09-06T09:48:23.4236094+08:00||;True|2024-09-05T13:57:23.8452431+08:00||;True|2024-09-05T10:21:34.6675149+08:00||;True|2024-09-05T09:12:44.5610882+08:00||;True|2024-09-04T10:07:38.3707398+08:00||;True|2024-09-04T09:52:47.0574599+08:00||;True|2024-09-03T16:41:23.7516960+08:00||;True|2024-09-03T15:22:31.8718097+08:00||;True|2024-09-03T10:01:09.7656702+08:00||;False|2024-09-03T09:46:46.8956531+08:00||;True|2024-09-02T17:07:41.0268500+08:00||;True|2024-09-02T13:50:22.0203254+08:00||;True|2024-09-02T13:34:23.3441546+08:00||;True|2024-08-30T11:25:14.7431645+08:00||;True|2024-08-29T16:38:26.3491372+08:00||;True|2024-08-29T16:32:31.8580864+08:00||;False|2024-08-29T16:30:41.4763198+08:00||;True|2024-08-09T09:18:05.8484398+08:00||;True|2024-08-09T08:45:38.7858906+08:00||;True|2024-08-05T11:37:07.3133020+08:00||;True|2024-07-24T16:45:58.2272340+08:00||;True|2024-07-24T15:48:52.0128987+08:00||;True|2024-07-23T17:41:01.7494842+08:00||;True|2024-07-23T17:25:11.8773492+08:00||;True|2024-07-23T17:07:16.5460273+08:00||;True|2024-07-22T08:59:23.3235603+08:00||;True|2024-07-12T17:35:11.1225017+08:00||;True|2024-07-11T11:40:17.3581147+08:00||;True|2024-07-04T17:20:50.0175739+08:00||;True|2024-07-02T11:26:14.2092751+08:00||;True|2024-07-02T09:21:51.3513605+08:00||;True|2024-07-01T17:47:56.0407256+08:00||;True|2024-07-01T16:42:55.7374984+08:00||;True|2024-07-01T15:49:58.9266967+08:00||;True|2024-07-01T14:35:48.1117178+08:00||;True|2024-07-01T11:41:52.2969338+08:00||;True|2024-07-01T11:13:02.6561160+08:00||;True|2024-06-28T15:28:43.1470725+08:00||;True|2024-06-28T15:16:20.1999596+08:00||;True|2024-06-28T15:14:56.2534743+08:00||;True|2024-06-28T15:02:41.3033806+08:00||;True|2024-06-28T13:37:28.2462742+08:00||;True|2024-06-28T11:06:30.7400535+08:00||;</History> <History>True|2024-09-27T02:58:33.1059648Z||;True|2024-09-27T10:37:35.0336563+08:00||;False|2024-09-27T10:31:52.6302264+08:00||;True|2024-09-26T19:50:15.5513195+08:00||;True|2024-09-26T19:47:14.0781788+08:00||;True|2024-09-26T19:01:26.5428388+08:00||;True|2024-09-26T18:35:28.7455319+08:00||;True|2024-09-26T18:24:30.8084807+08:00||;True|2024-09-26T18:20:47.3005460+08:00||;True|2024-09-26T18:04:39.8012913+08:00||;True|2024-09-26T17:48:13.8526872+08:00||;True|2024-09-26T16:08:20.1746970+08:00||;True|2024-09-26T16:01:01.1501975+08:00||;False|2024-09-26T16:00:34.1516745+08:00||;True|2024-09-26T14:33:03.4007570+08:00||;True|2024-09-25T19:14:27.8906774+08:00||;True|2024-09-25T18:57:40.1435131+08:00||;True|2024-09-25T17:38:44.0915841+08:00||;True|2024-09-25T15:33:58.4630618+08:00||;True|2024-09-25T15:10:31.3022063+08:00||;False|2024-09-25T14:14:40.9640545+08:00||;True|2024-09-25T10:09:32.2558600+08:00||;True|2024-09-25T09:59:17.1525160+08:00||;False|2024-09-25T09:57:58.7265103+08:00||;False|2024-09-25T09:53:36.7732713+08:00||;False|2024-09-24T18:40:10.0166224+08:00||;True|2024-09-24T08:59:56.1995425+08:00||;True|2024-09-23T18:07:54.7222163+08:00||;True|2024-09-23T17:23:57.7568406+08:00||;True|2024-09-23T16:28:49.3169826+08:00||;True|2024-09-23T15:57:31.8052490+08:00||;True|2024-09-23T11:47:21.1445419+08:00||;True|2024-09-23T09:24:36.0732229+08:00||;True|2024-09-21T11:59:19.0549926+08:00||;True|2024-09-21T11:24:32.4451752+08:00||;True|2024-09-21T10:39:11.5297411+08:00||;True|2024-09-20T18:24:31.7827684+08:00||;True|2024-09-19T17:55:53.1666689+08:00||;True|2024-09-19T17:42:47.9061485+08:00||;True|2024-09-19T16:08:21.7225571+08:00||;False|2024-09-19T14:15:42.9318446+08:00||;True|2024-09-19T11:20:03.5567568+08:00||;True|2024-09-18T11:35:18.1509724+08:00||;True|2024-09-18T09:08:59.1152574+08:00||;True|2024-09-14T15:48:22.9374486+08:00||;True|2024-09-14T15:42:19.0503983+08:00||;True|2024-09-14T11:51:53.3339222+08:00||;True|2024-09-14T11:41:38.3542237+08:00||;True|2024-09-14T11:19:13.1037012+08:00||;True|2024-09-13T14:31:12.4598160+08:00||;True|2024-09-13T10:44:56.1241214+08:00||;False|2024-09-13T10:44:26.6088271+08:00||;False|2024-09-13T10:44:06.1615137+08:00||;False|2024-09-13T10:43:19.2432517+08:00||;False|2024-09-13T10:38:18.1663387+08:00||;True|2024-09-06T18:49:17.9435308+08:00||;True|2024-09-06T17:01:39.6646353+08:00||;True|2024-09-06T10:27:36.9990456+08:00||;True|2024-09-06T09:48:23.4236094+08:00||;True|2024-09-05T13:57:23.8452431+08:00||;True|2024-09-05T10:21:34.6675149+08:00||;True|2024-09-05T09:12:44.5610882+08:00||;True|2024-09-04T10:07:38.3707398+08:00||;True|2024-09-04T09:52:47.0574599+08:00||;True|2024-09-03T16:41:23.7516960+08:00||;True|2024-09-03T15:22:31.8718097+08:00||;True|2024-09-03T10:01:09.7656702+08:00||;False|2024-09-03T09:46:46.8956531+08:00||;True|2024-09-02T17:07:41.0268500+08:00||;True|2024-09-02T13:50:22.0203254+08:00||;True|2024-09-02T13:34:23.3441546+08:00||;True|2024-08-30T11:25:14.7431645+08:00||;True|2024-08-29T16:38:26.3491372+08:00||;True|2024-08-29T16:32:31.8580864+08:00||;False|2024-08-29T16:30:41.4763198+08:00||;True|2024-08-09T09:18:05.8484398+08:00||;True|2024-08-09T08:45:38.7858906+08:00||;True|2024-08-05T11:37:07.3133020+08:00||;True|2024-07-24T16:45:58.2272340+08:00||;True|2024-07-24T15:48:52.0128987+08:00||;True|2024-07-23T17:41:01.7494842+08:00||;True|2024-07-23T17:25:11.8773492+08:00||;True|2024-07-23T17:07:16.5460273+08:00||;True|2024-07-22T08:59:23.3235603+08:00||;True|2024-07-12T17:35:11.1225017+08:00||;True|2024-07-11T11:40:17.3581147+08:00||;True|2024-07-04T17:20:50.0175739+08:00||;True|2024-07-02T11:26:14.2092751+08:00||;True|2024-07-02T09:21:51.3513605+08:00||;True|2024-07-01T17:47:56.0407256+08:00||;True|2024-07-01T16:42:55.7374984+08:00||;True|2024-07-01T15:49:58.9266967+08:00||;True|2024-07-01T14:35:48.1117178+08:00||;True|2024-07-01T11:41:52.2969338+08:00||;True|2024-07-01T11:13:02.6561160+08:00||;True|2024-06-28T15:28:43.1470725+08:00||;True|2024-06-28T15:16:20.1999596+08:00||;True|2024-06-28T15:14:56.2534743+08:00||;True|2024-06-28T15:02:41.3033806+08:00||;True|2024-06-28T13:37:28.2462742+08:00||;</History>
<LastFailureDetails /> <LastFailureDetails />
</PropertyGroup> </PropertyGroup>
</Project> </Project>
Loading…
Cancel
Save