|
|
|
@ -1,16 +1,20 @@
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.WMS.Core.Application.Dtos;
|
|
|
|
|
using DS.WMS.Core.Settlement.Entity;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
using DS.WMS.Core.Application.Dtos;
|
|
|
|
|
using DS.WMS.Core.Application.Entity;
|
|
|
|
|
using DS.WMS.Core.Code.Entity;
|
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using DS.WMS.Core.Settlement.Entity;
|
|
|
|
|
using DS.WMS.Core.Settlement.Interface;
|
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 发票结算
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class InvoiceSettlementService : SettlementService<PaymentSettlement>
|
|
|
|
|
public class InvoiceSettlementService : SettlementService<PaymentSettlement>, IInvoiceSettlementService
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化
|
|
|
|
@ -25,7 +29,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<List<InvoiceApplicationDto>>> GetApplicationListAsync(PageRequest request)
|
|
|
|
|
public async Task<DataResult<List<InvoiceApplicationDto>>> GetInvoiceListAsync(PageRequest request)
|
|
|
|
|
{
|
|
|
|
|
var whereList = request.GetConditionalModels(Db);
|
|
|
|
|
var result = await TenantDb.Queryable<InvoiceApplication>()
|
|
|
|
@ -33,19 +37,57 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
.InnerJoin<FeeRecord>((a, d, f) => 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))
|
|
|
|
|
.Select(x => new InvoiceApplicationDto
|
|
|
|
|
.Select((a, d, f) => new InvoiceApplicationDto
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}, true).MergeTable().Where(whereList).ToQueryPageAsync(request.PageCondition);
|
|
|
|
|
|
|
|
|
|
if (result.Data?.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
//关联用户名称
|
|
|
|
|
var userIds = result.Data.Select(x => x.CreateBy)
|
|
|
|
|
.Distinct();
|
|
|
|
|
var users = await Db.Queryable<SysUser>().Where(x => userIds.Contains(x.Id)).Select(x => new { x.Id, x.UserName }).ToListAsync();
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取发票申请费用明细
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<List<ApplicationDetailDto>>> GetInvoiceDetailsAsync(params long[] ids)
|
|
|
|
|
{
|
|
|
|
|
var query1 = TenantDb.Queryable<ApplicationDetail>()
|
|
|
|
|
.InnerJoin<FeeRecord>((d, f) => d.RecordId == f.Id && 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))
|
|
|
|
|
.LeftJoin<SeaExport>((d, f, s) => f.BusinessId == s.Id)
|
|
|
|
|
.Where((d, f, s) => ids.Contains(d.ApplicationId))
|
|
|
|
|
.Select((d, f, s) => new ApplicationDetailDto
|
|
|
|
|
{
|
|
|
|
|
ClientName = s.CustomerName,
|
|
|
|
|
Voyage = s.Voyno,
|
|
|
|
|
SourceName = s.SourceName,
|
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var list = await TenantDb.UnionAll(query1).ToListAsync();
|
|
|
|
|
var result = DataResult<List<ApplicationDetailDto>>.Success(list);
|
|
|
|
|
result.Count = list.Count;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|