发票结算数据源

dev
嵇文龙 2 months ago
parent 5d98d15a94
commit b0ffb40a04

@ -124,17 +124,5 @@ namespace DS.WMS.Core.Application.Entity
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "原始已处理金额")] [SugarColumn(ColumnDescription = "原始已处理金额")]
public decimal OriginalProcessedAmount { get; set; } public decimal OriginalProcessedAmount { get; set; }
/// <summary>
/// 已结算金额
/// </summary>
[SugarColumn(ColumnDescription = "已结算金额")]
public decimal SettlementAmount { get; set; }
/// <summary>
/// 原始已结算金额
/// </summary>
[SugarColumn(ColumnDescription = "原始已结算金额")]
public decimal OriginalSettlementAmount { get; set; }
} }
} }

@ -1,5 +1,6 @@
using DS.Module.Core; using DS.Module.Core;
using DS.WMS.Core.Application.Dtos; using DS.WMS.Core.Application.Dtos;
using DS.WMS.Core.Invoice.Dtos;
namespace DS.WMS.Core.Settlement.Interface namespace DS.WMS.Core.Settlement.Interface
{ {
@ -13,7 +14,7 @@ namespace DS.WMS.Core.Settlement.Interface
/// </summary> /// </summary>
/// <param name="request"></param> /// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
Task<DataResult<List<InvoiceApplicationDto>>> GetInvoiceListAsync(PageRequest request); Task<DataResult<List<InvoiceDto>>> GetInvoiceListAsync(PageRequest request);
/// <summary> /// <summary>
/// 获取发票申请费用明细 /// 获取发票申请费用明细

@ -5,6 +5,7 @@ using DS.Module.Core.Extensions;
using DS.WMS.Core.Application.Dtos; using DS.WMS.Core.Application.Dtos;
using DS.WMS.Core.Application.Entity; using DS.WMS.Core.Application.Entity;
using DS.WMS.Core.Fee.Entity; using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.Invoice.Dtos;
using DS.WMS.Core.Op.Entity; using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Settlement.Dtos; using DS.WMS.Core.Settlement.Dtos;
using DS.WMS.Core.Settlement.Entity; using DS.WMS.Core.Settlement.Entity;
@ -28,24 +29,24 @@ namespace DS.WMS.Core.Settlement.Method
} }
/// <summary> /// <summary>
/// 获取待结算的发票申请列表 /// 获取待结算的发票列表
/// </summary> /// </summary>
/// <param name="request"></param> /// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
public async Task<DataResult<List<InvoiceApplicationDto>>> GetInvoiceListAsync(PageRequest request) public async Task<DataResult<List<InvoiceDto>>> GetInvoiceListAsync(PageRequest request)
{ {
var whereList = request.GetConditionalModels(Db); var whereList = request.GetConditionalModels(Db);
var result = await TenantDb.Queryable<InvoiceApplication>() var result = await TenantDb.Queryable<Invoice.Entity.Invoice>()
.InnerJoin<ApplicationDetail>((a, d) => d.Category == DetailCategory.InvoiceApplication && a.Id == d.ApplicationId && d.OriginalAmount - d.OriginalSettlementAmount != 0) .InnerJoin<ApplicationDetail>((a, d) => d.Category == DetailCategory.InvoiceIssuance && a.Id == d.ApplicationId && d.OriginalAmount - d.OriginalProcessedAmount != 0)
.InnerJoin<FeeRecord>((a, d, f) => (f.FeeStatus == FeeStatus.AuditPassed || f.FeeStatus == FeeStatus.PartialSettlement) && d.RecordId == f.Id && .InnerJoin<FeeRecord>((a, d, f) => (f.FeeStatus == FeeStatus.AuditPassed || f.FeeStatus == FeeStatus.PartialSettlement) && d.RecordId == f.Id &&
((f.Amount > 0 && d.OriginalAmount - d.OriginalSettlementAmount <= f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount) || ((f.Amount > 0 && d.OriginalAmount - d.OriginalProcessedAmount <= f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount) ||
(f.Amount < 0 && d.OriginalAmount - d.OriginalSettlementAmount >= f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount)) (f.Amount < 0 && d.OriginalAmount - d.OriginalProcessedAmount >= f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount))
) )
.GroupBy((a, d, f) => a.Id) .GroupBy((a, d, f) => a.Id)
.Select((a, d, f) => new InvoiceApplicationDto .Select((a, d, f) => new InvoiceDto
{ {
}, true).MergeTable().Where(a => a.Status == InvoiceApplicationStatus.AuditPassed || a.Status == InvoiceApplicationStatus.PartialInvoiced).Where(whereList).ToQueryPageAsync(request.PageCondition); }, true).MergeTable().Where(whereList).ToQueryPageAsync(request.PageCondition);
if (result.Data?.Count > 0) if (result.Data?.Count > 0)
{ {
@ -57,10 +58,16 @@ namespace DS.WMS.Core.Settlement.Method
var orgIds = result.Data.Select(x => x.SaleDeptId).Distinct().ToList(); var orgIds = result.Data.Select(x => x.SaleDeptId).Distinct().ToList();
var orgs = await Db.Queryable<SysOrg>().Where(x => orgIds.Contains(x.Id)).Select(x => new { x.Id, x.OrgName }).ToListAsync(); var orgs = await Db.Queryable<SysOrg>().Where(x => orgIds.Contains(x.Id)).Select(x => new { x.Id, x.OrgName }).ToListAsync();
var ids = result.Data.Select(x => x.Id);
var details = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.ApplicationId) &&
x.Category == DetailCategory.InvoiceIssuance).Select<ApplicationDetailDto>().ToListAsync();
foreach (var item in result.Data) foreach (var item in result.Data)
{ {
item.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName; item.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName;
item.SaleDeptName = orgs.Find(x => x.Id == item.SaleDeptId)?.OrgName; item.SaleDeptName = orgs.Find(x => x.Id == item.SaleDeptId)?.OrgName;
item.Details = details.FindAll(x => x.ApplicationId == item.Id);
} }
} }
@ -75,10 +82,10 @@ namespace DS.WMS.Core.Settlement.Method
public async Task<DataResult<List<ApplicationDetailDto>>> GetInvoiceDetailsAsync(params long[] ids) public async Task<DataResult<List<ApplicationDetailDto>>> GetInvoiceDetailsAsync(params long[] ids)
{ {
var query1 = TenantDb.Queryable<ApplicationDetail>() var query1 = TenantDb.Queryable<ApplicationDetail>()
.InnerJoin<FeeRecord>((d, f) => d.Category == DetailCategory.InvoiceApplication && d.RecordId == f.Id && .InnerJoin<FeeRecord>((d, f) => d.Category == DetailCategory.InvoiceIssuance && d.RecordId == f.Id &&
(f.FeeStatus == FeeStatus.AuditPassed || f.FeeStatus == FeeStatus.PartialSettlement) && f.BusinessType == BusinessType.OceanShippingExport && (f.FeeStatus == FeeStatus.AuditPassed || f.FeeStatus == FeeStatus.PartialSettlement) && f.BusinessType == BusinessType.OceanShippingExport &&
((f.Amount > 0 && d.OriginalAmount - d.OriginalSettlementAmount <= f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount) || ((f.Amount > 0 && d.OriginalAmount - d.OriginalProcessedAmount <= f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount) ||
(f.Amount < 0 && d.OriginalAmount - d.OriginalSettlementAmount >= f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount)) (f.Amount < 0 && d.OriginalAmount - d.OriginalProcessedAmount >= f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount))
) )
.LeftJoin<SeaExport>((d, f, s) => f.BusinessId == s.Id) .LeftJoin<SeaExport>((d, f, s) => f.BusinessId == s.Id)
.Where((d, f, s) => ids.Contains(d.ApplicationId)) .Where((d, f, s) => ids.Contains(d.ApplicationId))
@ -195,11 +202,11 @@ namespace DS.WMS.Core.Settlement.Method
//获取剩余待结算金额 //获取剩余待结算金额
var ids2 = settlement.Details.Select(x => x.DetailId); var ids2 = settlement.Details.Select(x => x.DetailId);
var appDetails = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids2.Contains(x.Id) && x.Category == DetailCategory.InvoiceApplication) var appDetails = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids2.Contains(x.Id) && x.Category == DetailCategory.InvoiceIssuance)
.Select(x => new .Select(x => new
{ {
x.Id, x.Id,
OriginalRestAmount = x.OriginalAmount - x.OriginalSettlementAmount OriginalRestAmount = x.OriginalAmount - x.OriginalProcessedAmount
}).ToListAsync(); }).ToListAsync();
StringBuilder sb = new(); StringBuilder sb = new();
@ -230,5 +237,22 @@ namespace DS.WMS.Core.Settlement.Method
return sb.Length > 0 ? DataResult.Failed(sb.ToString()) : DataResult.Success; return sb.Length > 0 ? DataResult.Failed(sb.ToString()) : DataResult.Success;
} }
protected override async Task OnSaveAsync(PaymentSettlement settlement)
{
//更新发票费用明细的已处理金额
var list = settlement.Details.Select(x => new ApplicationDetail
{
Id = x.DetailId.Value,
Category = DetailCategory.InvoiceIssuance,
ProcessedAmount = x.ApplyAmount,
OriginalProcessedAmount = x.OriginalAmount
}).ToList();
await TenantDb.Updateable(list)
.PublicSetColumns(x => x.ProcessedAmount, "+")
.PublicSetColumns(x => x.OriginalProcessedAmount, "+")
.UpdateColumns(x => new { x.ProcessedAmount, x.OriginalProcessedAmount })
.ExecuteCommandAsync();
}
} }
} }

@ -325,6 +325,7 @@ namespace DS.WMS.Core.Settlement.Method
return DataResult<FreeSettlement>.Success(model); return DataResult<FreeSettlement>.Success(model);
} }
protected override async Task<DataResult> PreSaveAsync(PaymentSettlement settlement) protected override async Task<DataResult> PreSaveAsync(PaymentSettlement settlement)
{ {
//settlement.Mode = SettlementMode.FreeSettlement; //settlement.Mode = SettlementMode.FreeSettlement;
@ -375,5 +376,10 @@ namespace DS.WMS.Core.Settlement.Method
return DataResult.Success; return DataResult.Success;
} }
//protected override Task OnSaveAsync(PaymentSettlement settlement)
//{
// return base.OnSaveAsync(settlement);
//}
} }
} }

@ -524,10 +524,11 @@ namespace DS.WMS.Core.Settlement.Method
protected override async Task OnSaveAsync(PaymentSettlement settlement) protected override async Task OnSaveAsync(PaymentSettlement settlement)
{ {
//更新申请明细的已处理金额 //更新付费申请明细的已处理金额
var list = settlement.Details.Select(x => new ApplicationDetail var list = settlement.Details.Select(x => new ApplicationDetail
{ {
Id = x.DetailId.Value, Id = x.DetailId.Value,
Category = DetailCategory.PaidApplication,
ProcessedAmount = x.ApplyAmount, ProcessedAmount = x.ApplyAmount,
OriginalProcessedAmount = x.OriginalAmount OriginalProcessedAmount = x.OriginalAmount
}).ToList(); }).ToList();

@ -68,9 +68,9 @@ namespace DS.WMS.Core.Settlement.Method
List<ApplicationDetail>? details1 = null; List<ApplicationDetail>? details1 = null;
//自由结算 //自由结算
if (request.Details?.Count > 0) if (settlement.Mode == SettlementMode.FreeSettlement && request.Details?.Count > 0)
{ {
if (settlement.Id == 0 && settlement.CustomerId == 0) if (settlement.Id == 0)
{ {
var first = request.Details[0]; var first = request.Details[0];
settlement.CustomerId = first.CustomerId; settlement.CustomerId = first.CustomerId;
@ -97,7 +97,7 @@ namespace DS.WMS.Core.Settlement.Method
//按付费/发票申请结算 //按付费/发票申请结算
if (request.Documents?.Count > 0) if (request.Documents?.Count > 0)
{ {
if (settlement.Id == 0 && settlement.CustomerId == 0) if (settlement.Id == 0)
{ {
var first = request.Documents[0]; var first = request.Documents[0];
settlement.CustomerId = first.CustomerId; settlement.CustomerId = first.CustomerId;
@ -105,7 +105,6 @@ namespace DS.WMS.Core.Settlement.Method
} }
var ids = request.Documents.Select(x => x.Id); var ids = request.Documents.Select(x => x.Id);
//收/付费申请结算 //收/付费申请结算
if (settlement.Mode == SettlementMode.Payment || settlement.Mode == SettlementMode.Charge) if (settlement.Mode == SettlementMode.Payment || settlement.Mode == SettlementMode.Charge)
{ {
@ -115,33 +114,35 @@ namespace DS.WMS.Core.Settlement.Method
RefId = x.ApplicationId, RefId = x.ApplicationId,
DetailId = x.Id, DetailId = x.Id,
RecordId = x.RecordId, RecordId = x.RecordId,
Category = settlement.Mode == SettlementMode.Payment ? DetailCategory.PaidApplicationSettlement : DetailCategory.ChargeApplicationSettlement,
CustomerName = x.CustomerName ?? settlement.CustomerName, CustomerName = x.CustomerName ?? settlement.CustomerName,
FeeId = x.FeeId, FeeId = x.FeeId,
FeeName = x.FeeName, FeeName = x.FeeName,
FeeType = x.FeeType, FeeType = x.FeeType,
ApplyAmount = x.ApplyAmount - x.SettlementAmount, ApplyAmount = x.ApplyAmount - x.ProcessedAmount,
Currency = x.Currency, Currency = x.Currency,
ExchangeRate = x.ExchangeRate, ExchangeRate = x.ExchangeRate,
OriginalAmount = x.OriginalAmount, OriginalAmount = x.OriginalAmount - x.OriginalProcessedAmount,
}).ToListAsync(); }).ToListAsync();
} }
//发票申请结算 //发票结算
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.InvoiceApplication) details1 = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.ApplicationId) && x.Category == DetailCategory.InvoiceIssuance)
.Select(x => new ApplicationDetail .Select(x => new ApplicationDetail
{ {
RefId = x.ApplicationId, RefId = x.ApplicationId,
DetailId = x.Id, DetailId = x.Id,
RecordId = x.RecordId, RecordId = x.RecordId,
Category = DetailCategory.InvoiceSettlement,
CustomerName = x.CustomerName ?? settlement.CustomerName, CustomerName = x.CustomerName ?? settlement.CustomerName,
FeeId = x.FeeId, FeeId = x.FeeId,
FeeName = x.FeeName, FeeName = x.FeeName,
FeeType = x.FeeType, FeeType = x.FeeType,
ApplyAmount = x.ApplyAmount - x.SettlementAmount, ApplyAmount = x.ApplyAmount - x.ProcessedAmount,
Currency = x.Currency, Currency = x.Currency,
ExchangeRate = x.ExchangeRate, ExchangeRate = x.ExchangeRate,
OriginalAmount = x.OriginalAmount, OriginalAmount = x.OriginalAmount - x.OriginalProcessedAmount,
}).ToListAsync(); }).ToListAsync();
} }
@ -175,7 +176,7 @@ namespace DS.WMS.Core.Settlement.Method
{ {
return DataResult<TEntity>.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist); return DataResult<TEntity>.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist);
} }
settlement.ApplicationNO = "CP" + SnowFlakeSingle.Instance.NextId(); //申请编号 settlement.ApplicationNO = "ST" + SnowFlakeSingle.Instance.NextId(); //申请编号
settlement.SettlementNO = sequence.Data; //结算单号 settlement.SettlementNO = sequence.Data; //结算单号
await TenantDb.InsertNav(settlement).Include(x => x.Details.FindAll(x => x.Id == 0)).ExecuteCommandAsync(); await TenantDb.InsertNav(settlement).Include(x => x.Details.FindAll(x => x.Id == 0)).ExecuteCommandAsync();
@ -215,7 +216,8 @@ namespace DS.WMS.Core.Settlement.Method
} }
await TenantDb.Ado.CommitTranAsync(); await TenantDb.Ado.CommitTranAsync();
return DataResult<TEntity>.Success(await PostSaveAsync(settlement)); PostSaveAsync(settlement);
return DataResult<TEntity>.Success(settlement);
} }
catch (Exception ex) catch (Exception ex)
{ {

@ -1,6 +1,7 @@
using DS.Module.Core; using DS.Module.Core;
using DS.Module.Core.Data; using DS.Module.Core.Data;
using DS.WMS.Core.Application.Dtos; using DS.WMS.Core.Application.Dtos;
using DS.WMS.Core.Invoice.Dtos;
using DS.WMS.Core.Settlement.Interface; using DS.WMS.Core.Settlement.Interface;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -23,12 +24,12 @@ namespace DS.WMS.FeeApi.Controllers
} }
/// <summary> /// <summary>
/// 获取待结算的发票申请列表 /// 获取待结算的发票列表
/// </summary> /// </summary>
/// <param name="request"></param> /// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost, Route("GetInvoiceList")] [HttpPost, Route("GetInvoiceList")]
public async Task<DataResult<List<InvoiceApplicationDto>>> GetInvoiceListAsync(PageRequest request) public async Task<DataResult<List<InvoiceDto>>> GetInvoiceListAsync(PageRequest request)
{ {
return await _service.GetInvoiceListAsync(request); return await _service.GetInvoiceListAsync(request);
} }

Loading…
Cancel
Save