|
|
|
@ -5,6 +5,7 @@ using DS.Module.Core.Extensions;
|
|
|
|
|
using DS.WMS.Core.Application.Dtos;
|
|
|
|
|
using DS.WMS.Core.Application.Entity;
|
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
|
using DS.WMS.Core.Invoice.Dtos;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using DS.WMS.Core.Settlement.Dtos;
|
|
|
|
|
using DS.WMS.Core.Settlement.Entity;
|
|
|
|
@ -28,24 +29,24 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取待结算的发票申请列表
|
|
|
|
|
/// 获取待结算的发票列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <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 result = await TenantDb.Queryable<InvoiceApplication>()
|
|
|
|
|
.InnerJoin<ApplicationDetail>((a, d) => d.Category == DetailCategory.InvoiceApplication && a.Id == d.ApplicationId && d.OriginalAmount - d.OriginalSettlementAmount != 0)
|
|
|
|
|
var result = await TenantDb.Queryable<Invoice.Entity.Invoice>()
|
|
|
|
|
.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 &&
|
|
|
|
|
((f.Amount > 0 && d.OriginalAmount - d.OriginalSettlementAmount <= 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) ||
|
|
|
|
|
(f.Amount < 0 && d.OriginalAmount - d.OriginalProcessedAmount >= f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount))
|
|
|
|
|
)
|
|
|
|
|
.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)
|
|
|
|
|
{
|
|
|
|
@ -57,10 +58,16 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
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 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)
|
|
|
|
|
{
|
|
|
|
|
item.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName;
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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.Amount > 0 && d.OriginalAmount - d.OriginalSettlementAmount <= 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) ||
|
|
|
|
|
(f.Amount < 0 && d.OriginalAmount - d.OriginalProcessedAmount >= f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount))
|
|
|
|
|
)
|
|
|
|
|
.LeftJoin<SeaExport>((d, f, s) => f.BusinessId == s.Id)
|
|
|
|
|
.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 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
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
OriginalRestAmount = x.OriginalAmount - x.OriginalSettlementAmount
|
|
|
|
|
OriginalRestAmount = x.OriginalAmount - x.OriginalProcessedAmount
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new();
|
|
|
|
@ -230,5 +237,22 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|