|
|
|
@ -9,7 +9,6 @@ using DS.WMS.Core.Code.Entity;
|
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
|
using DS.WMS.Core.Info.Entity;
|
|
|
|
|
using DS.WMS.Core.Invoice.Dtos;
|
|
|
|
|
using DS.WMS.Core.Invoice.Entity;
|
|
|
|
|
using DS.WMS.Core.Invoice.Interface;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
@ -47,56 +46,38 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
public async Task<DataResult<InvoiceList>> GetListAsync(PageRequest<NumberQuery> request)
|
|
|
|
|
{
|
|
|
|
|
var query = TenantDb.Queryable<Entity.Invoice>()
|
|
|
|
|
.WhereIF(!string.IsNullOrEmpty(request.OtherQueryCondition?.Number), x =>
|
|
|
|
|
.LeftJoin<SysOrg>((i, s) => i.SaleDeptId == s.Id, "shippingweb8_dev.sys_org")
|
|
|
|
|
.LeftJoin<SysUser>((i, s, u1) => i.LockUserId == s.Id, "shippingweb8_dev.sys_user")
|
|
|
|
|
.LeftJoin<SysUser>((i, s, u1, u2) => i.OperatorId == s.Id, "shippingweb8_dev.sys_user")
|
|
|
|
|
.WhereIF(!string.IsNullOrEmpty(request.OtherQueryCondition?.Number), i => i.BillNO.Contains(request.OtherQueryCondition.Number) || i.InvoiceNO.Contains(request.OtherQueryCondition.Number) ||
|
|
|
|
|
SqlFunc.Subqueryable<ApplicationDetail>().InnerJoin<FeeRecord>((d, f) => d.RecordId == f.Id && f.BusinessType == BusinessType.OceanShippingExport)
|
|
|
|
|
.InnerJoin<SeaExport>((d, f, s) => f.BusinessId == s.Id).Where((d, f, s) =>
|
|
|
|
|
s.CustomerNo.Contains(request.OtherQueryCondition.Number) || s.BookingNo.Contains(request.OtherQueryCondition.Number) ||
|
|
|
|
|
s.MBLNO.Contains(request.OtherQueryCondition.Number) || s.CustomerNum.Contains(request.OtherQueryCondition.Number)).Any())
|
|
|
|
|
.Select((i) => new InvoiceDto
|
|
|
|
|
.Select((i, s, u1, u2) => new InvoiceDto
|
|
|
|
|
{
|
|
|
|
|
Details = SqlFunc.Subqueryable<ApplicationDetail>().Where(d => d.ApplicationId == i.Id)
|
|
|
|
|
.ToList(d => new ApplicationDetailDto
|
|
|
|
|
{
|
|
|
|
|
Currency = d.Currency,
|
|
|
|
|
ProcessedAmount = d.ProcessedAmount,
|
|
|
|
|
ExchangeRate = d.ExchangeRate,
|
|
|
|
|
OriginalCurrency = d.OriginalCurrency,
|
|
|
|
|
OriginalAmount = d.OriginalAmount,
|
|
|
|
|
OriginalProcessedAmount = d.OriginalProcessedAmount
|
|
|
|
|
}),
|
|
|
|
|
CreateByName = i.CreateUserName,
|
|
|
|
|
SaleDeptName = s.OrgName,
|
|
|
|
|
LockUserName = u1.UserName,
|
|
|
|
|
OperatorName = u2.UserName,
|
|
|
|
|
InvoiceApplicationList = SqlFunc.Subqueryable<ApplicationDetail>().LeftJoin<InvoiceApplication>((d, a) =>
|
|
|
|
|
d.ApplicationId == i.Id && d.RefId == a.Id)
|
|
|
|
|
.WhereIF(request.OtherQueryCondition != null && !string.IsNullOrEmpty(request.OtherQueryCondition.Number),
|
|
|
|
|
(d, a) => a.ApplicationNO.Contains(request.OtherQueryCondition.Number))
|
|
|
|
|
.GroupBy((d, a) => a.ApplicationNO).ToList((d, a) => a.ApplicationNO)
|
|
|
|
|
//.WhereIF(request.OtherQueryCondition != null && !string.IsNullOrEmpty(request.OtherQueryCondition.Number),
|
|
|
|
|
// (d, a) => a.ApplicationNO.Contains(request.OtherQueryCondition.Number))
|
|
|
|
|
.GroupBy((d, a) => a.ApplicationNO).ToList((d, a) => a.ApplicationNO),
|
|
|
|
|
ApplyAmountRMB = SqlFunc.Subqueryable<ApplicationDetail>().LeftJoin<ApplicationDetail>((d1, d2) =>
|
|
|
|
|
d1.Id == d2.DetailId).Where((d1, d2) => d2.ApplicationId == i.Id && d1.Currency == FeeCurrency.RMB_CODE)
|
|
|
|
|
.Sum((d1, d2) => d1.ApplyAmount),
|
|
|
|
|
ApplyAmountUSD = SqlFunc.Subqueryable<ApplicationDetail>().LeftJoin<ApplicationDetail>((d1, d2) =>
|
|
|
|
|
d1.Id == d2.DetailId).Where((d1, d2) => d2.ApplicationId == i.Id && d1.Currency == FeeCurrency.USD_CODE)
|
|
|
|
|
.Sum((d1, d2) => d1.ApplyAmount)
|
|
|
|
|
}, true).MergeTable();
|
|
|
|
|
|
|
|
|
|
//if (!string.IsNullOrEmpty(request.OtherQueryCondition?.Number))
|
|
|
|
|
// query = query.Where(i => i.InvoiceNO.Contains(request.OtherQueryCondition.Number) || i.BillNO.Contains(request.OtherQueryCondition.Number));
|
|
|
|
|
|
|
|
|
|
var whereList = request.GetConditionalModels(Db);
|
|
|
|
|
var result = await query.Where(whereList).ToQueryPageAsync(request.PageCondition);
|
|
|
|
|
|
|
|
|
|
if (result.Data?.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var userIds = result.Data.Select(x => x.CreateBy)
|
|
|
|
|
.Union(result.Data.Where(x => x.LockUserId.HasValue).Select(x => x.LockUserId.Value))
|
|
|
|
|
.Union(result.Data.Where(x => x.OperatorId.HasValue).Select(x => x.OperatorId.Value))
|
|
|
|
|
.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.Where(x => x.SaleDeptId.HasValue).Select(x => x.SaleDeptId.Value)
|
|
|
|
|
.Distinct();
|
|
|
|
|
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.LockUserName = users.Find(x => x.Id == item.LockUserId)?.UserName;
|
|
|
|
|
item.OperatorName = users.Find(x => x.Id == item.OperatorId)?.UserName;
|
|
|
|
|
|
|
|
|
|
item.SaleDeptName = orgs.Find(x => x.Id == item.SaleDeptId)?.OrgName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InvoiceList list = new() { List = result.Data };
|
|
|
|
@ -113,11 +94,25 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
public async Task<DataResult<InvoiceDto>> GetAsync(long id)
|
|
|
|
|
{
|
|
|
|
|
var invoice = await TenantDb.Queryable<Entity.Invoice>()
|
|
|
|
|
.LeftJoin<Entity.Invoice>((x, y) => x.RedId == y.Id)
|
|
|
|
|
.Select((x, y) => new InvoiceDto
|
|
|
|
|
.LeftJoin<Entity.Invoice>((i, ri) => i.RedId == ri.Id)
|
|
|
|
|
.LeftJoin<SysOrg>((i, ri, s) => i.SaleDeptId == s.Id, "shippingweb8_dev.sys_org")
|
|
|
|
|
.LeftJoin<SysUser>((i, ri, s, u1) => i.LockUserId == s.Id, "shippingweb8_dev.sys_user")
|
|
|
|
|
.LeftJoin<SysUser>((i, ri, s, u1, u2) => i.OperatorId == s.Id, "shippingweb8_dev.sys_user")
|
|
|
|
|
.Select((i, ri, s, u1, u2) => new InvoiceDto
|
|
|
|
|
{
|
|
|
|
|
RedNO = y.InvoiceNO
|
|
|
|
|
}, true).FirstAsync(x => x.Id == id);
|
|
|
|
|
RedNO = ri.InvoiceNO,
|
|
|
|
|
CreateByName = i.CreateUserName,
|
|
|
|
|
SaleDeptName = s.OrgName,
|
|
|
|
|
LockUserName = u1.UserName,
|
|
|
|
|
OperatorName = u2.UserName,
|
|
|
|
|
ApplyAmountRMB = SqlFunc.Subqueryable<ApplicationDetail>().LeftJoin<ApplicationDetail>((d1, d2) =>
|
|
|
|
|
d1.Id == d2.DetailId).Where((d1, d2) => d2.ApplicationId == i.Id && d1.Currency == FeeCurrency.RMB_CODE)
|
|
|
|
|
.Sum((d1, d2) => d1.ApplyAmount),
|
|
|
|
|
ApplyAmountUSD = SqlFunc.Subqueryable<ApplicationDetail>().LeftJoin<ApplicationDetail>((d1, d2) =>
|
|
|
|
|
d1.Id == d2.DetailId).Where((d1, d2) => d2.ApplicationId == i.Id && d1.Currency == FeeCurrency.USD_CODE)
|
|
|
|
|
.Sum((d1, d2) => d1.ApplyAmount)
|
|
|
|
|
}, true).FirstAsync(i => i.Id == id);
|
|
|
|
|
|
|
|
|
|
if (invoice != null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(invoice.PushMode))
|
|
|
|
@ -126,12 +121,6 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
.Select(x => (PushMode)int.Parse(x)).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (invoice.OperatorId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
invoice.OperatorName = await Db.Queryable<SysUser>().Where(x => x.Id == invoice.OperatorId.Value)
|
|
|
|
|
.Select(x => x.UserName).FirstAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
invoice.Details = await CreateApplicationDetailQuery((d, f, s) => d.ApplicationId == id && d.Category == DetailCategory.InvoiceIssuance)
|
|
|
|
|
.Select(x => new ApplicationDetailDto
|
|
|
|
|
{
|
|
|
|
@ -156,8 +145,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
SourceName = x.SourceName,
|
|
|
|
|
LoadPort = x.LoadPort,
|
|
|
|
|
Vessel = x.Vessel,
|
|
|
|
|
Voyage = x.Voyage,
|
|
|
|
|
|
|
|
|
|
Voyage = x.Voyage
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
invoice.Summary = invoice.Details.GroupBy(x => new { x.FeeType, x.Currency }).Select(x => new SummaryItem
|
|
|
|
@ -171,8 +159,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
{
|
|
|
|
|
var ids = invoice.Details.Where(x => x.RefId.HasValue).Select(x => x.RefId).Distinct();
|
|
|
|
|
invoice.Applications = await TenantDb.Queryable<InvoiceApplication>().Where(x => ids.Contains(x.Id))
|
|
|
|
|
.LeftJoin<SysUser>((x, y) => x.CreateBy == y.Id, "shippingweb8_dev.sys_user")
|
|
|
|
|
.Select((x, y) => new InvoiceApplicationDto
|
|
|
|
|
.Select(x => new InvoiceApplicationDto
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
ApplicationNO = x.ApplicationNO,
|
|
|
|
@ -180,7 +167,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
Currency = x.Currency,
|
|
|
|
|
InvoiceRemark = x.InvoiceRemark,
|
|
|
|
|
CreateBy = x.CreateBy,
|
|
|
|
|
CreateByName = y.UserName,
|
|
|
|
|
CreateByName = x.CreateUserName,
|
|
|
|
|
ApplyAmountRMB = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => x.Id == y.ApplicationId && y.Currency == FeeCurrency.RMB_CODE).Sum(y => y.ApplyAmount),
|
|
|
|
|
ApplyAmountUSD = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => x.Id == y.ApplicationId && y.Currency == FeeCurrency.USD_CODE).Sum(y => y.ApplyAmount)
|
|
|
|
|
}).ToListAsync();
|
|
|
|
@ -480,11 +467,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(invRemark))
|
|
|
|
|
{
|
|
|
|
|
invoice.Note += Environment.NewLine + invRemark;
|
|
|
|
|
invoice.InvoiceRemark += Environment.NewLine + invRemark;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//筛选出新增的费用明细
|
|
|
|
@ -627,8 +610,15 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
|
|
|
|
|
if (detail.Currency == currency)
|
|
|
|
|
{
|
|
|
|
|
if (detail.Currency == detail.OriginalCurrency)
|
|
|
|
|
{
|
|
|
|
|
detail.OriginalAmount = detail.ApplyAmount;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
detail.OriginalAmount = detail.ApplyAmount / detail.ExchangeRate.Value;
|
|
|
|
|
}
|
|
|
|
|
detail.ExchangeRate = 1;
|
|
|
|
|
detail.OriginalAmount = detail.ApplyAmount;
|
|
|
|
|
}
|
|
|
|
|
else //开票币别与费用币别不一致
|
|
|
|
|
{
|
|
|
|
@ -738,19 +728,13 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
foreach (var invoice in invoices)
|
|
|
|
|
{
|
|
|
|
|
var currDetails = details.FindAll(x => x.ApplicationId == invoice.Id);
|
|
|
|
|
|
|
|
|
|
invoice.ApplyAmount = currDetails.Sum(x => x.ApplyAmount);
|
|
|
|
|
invoice.AmountUppercase = new Money(invoice.ApplyAmount).ToString();
|
|
|
|
|
invoice.OriginalAmount = currDetails.Sum(x => x.OriginalAmount);
|
|
|
|
|
invoice.OtherInvoiceAmount = currDetails.FindAll(x => x.Currency != FeeCurrency.RMB_CODE).Sum(x => x.OriginalAmount);
|
|
|
|
|
|
|
|
|
|
invoice.InvoiceAmount = invDetails.FindAll(x => x.ApplicationId == invoice.Id).Sum(x => x.Amount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await TenantDb.Updateable(invoices).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.ApplyAmount,
|
|
|
|
|
x.AmountUppercase,
|
|
|
|
|
x.OriginalAmount,
|
|
|
|
|
x.OtherInvoiceAmount,
|
|
|
|
|
x.InvoiceAmount
|
|
|
|
@ -995,15 +979,8 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
{
|
|
|
|
|
//重新设置申请明细与总金额
|
|
|
|
|
item.Details = details.FindAll(x => x.ApplicationId == item.Id);
|
|
|
|
|
item.ApplyAmount = item.Details.Sum(x => x.ApplyAmount);
|
|
|
|
|
item.AmountUppercase = new Money(item.ApplyAmount).ToString();
|
|
|
|
|
//item.InvoiceAmount = item.InvoiceDetails.Sum(x => x.Amount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await TenantDb.Updateable(invoices).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.ApplyAmount,
|
|
|
|
|
x.AmountUppercase
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else if (deleteOption == DeleteOption.Entire)
|
|
|
|
|
{
|
|
|
|
|