|
|
@ -10,6 +10,7 @@ using DS.WMS.Core.Invoice.Dtos;
|
|
|
|
using DS.WMS.Core.Invoice.Interface;
|
|
|
|
using DS.WMS.Core.Invoice.Interface;
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
using DS.WMS.Core.Sys.Interface;
|
|
|
|
using DS.WMS.Core.Sys.Interface;
|
|
|
|
|
|
|
|
using Mapster;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using SqlSugar;
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
|
|
@ -157,6 +158,17 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
return DataResult<InvoiceDto>.Success(invoice);
|
|
|
|
return DataResult<InvoiceDto>.Success(invoice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 根据业务编号及类型获取费用记录
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="items">业务ID与业务类型</param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
public virtual Task<DataResult<InvoiceApplicaitonBiz>> GetFeesAsync(params FeeClient[] items)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Task.FromResult(DataResult<InvoiceApplicaitonBiz>.Success(
|
|
|
|
|
|
|
|
new InvoiceApplicaitonBiz(new List<FeeInvoiceDto>())));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma warning disable CS4014
|
|
|
|
#pragma warning disable CS4014
|
|
|
|
|
|
|
|
|
|
|
@ -191,176 +203,191 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
|
|
|
|
|
|
|
invoice.OperatorId ??= long.Parse(User.UserId);
|
|
|
|
invoice.OperatorId ??= long.Parse(User.UserId);
|
|
|
|
|
|
|
|
|
|
|
|
//按发票申请
|
|
|
|
if (request.Invoice.Mode == InvoiceMode.Applcation && request.Applications != null && request.Applications.Count > 0) //发票申请开出
|
|
|
|
if (request.Applications != null && request.Applications.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var ids = request.Applications.Select(x => x.ApplicationId);
|
|
|
|
var ids = request.Applications.Select(x => x.ApplicationId);
|
|
|
|
var details = await TenantDb.Queryable<ApplicationDetail>()
|
|
|
|
if (request.Invoice.Mode == InvoiceMode.Applcation) //按发票申请
|
|
|
|
.InnerJoin<InvoiceApplication>((x, y) => x.ApplicationId == y.Id)
|
|
|
|
|
|
|
|
.LeftJoin<InfoClientBank>((x, y, z) => y.CustomerId == z.ClientId && z.Currency == invoice.Currency && z.IsInvoiceDefault == true)
|
|
|
|
|
|
|
|
.Where((x, y, z) => ids.Contains(x.ApplicationId) && x.Category == DetailCategory.InvoiceApplication)
|
|
|
|
|
|
|
|
.Select((x, y, z) => new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
x.Id,
|
|
|
|
|
|
|
|
x.ApplicationId,
|
|
|
|
|
|
|
|
x.RecordId,
|
|
|
|
|
|
|
|
x.CustomerName,
|
|
|
|
|
|
|
|
x.FeeId,
|
|
|
|
|
|
|
|
x.FeeType,
|
|
|
|
|
|
|
|
x.FeeName,
|
|
|
|
|
|
|
|
x.ApplyAmount,
|
|
|
|
|
|
|
|
x.OriginalAmount,
|
|
|
|
|
|
|
|
x.Currency,
|
|
|
|
|
|
|
|
x.OriginalCurrency,
|
|
|
|
|
|
|
|
x.ProcessedAmount,
|
|
|
|
|
|
|
|
x.OriginalProcessedAmount,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
y.CustomerId,
|
|
|
|
|
|
|
|
y.TaxRate,
|
|
|
|
|
|
|
|
y.TaxID,
|
|
|
|
|
|
|
|
y.InvoiceHeader,
|
|
|
|
|
|
|
|
y.CustomerAddTel,
|
|
|
|
|
|
|
|
y.SaleDeptId,
|
|
|
|
|
|
|
|
y.PushMode,
|
|
|
|
|
|
|
|
y.CellPhoneNO,
|
|
|
|
|
|
|
|
y.Email,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
z.BankAccountNo,
|
|
|
|
|
|
|
|
z.BankName
|
|
|
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//税率不一致
|
|
|
|
|
|
|
|
if (details.GroupBy(x => x.TaxRate).Select(x => x.Key).Count() > 1)
|
|
|
|
|
|
|
|
return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.InvoiceCustomerOnlyOne));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
invoice.Details ??= new List<ApplicationDetail>(details.Count);
|
|
|
|
|
|
|
|
foreach (var item in details)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (invoice.CustomerId == 0)
|
|
|
|
var details = await TenantDb.Queryable<ApplicationDetail>()
|
|
|
|
{
|
|
|
|
.InnerJoin<InvoiceApplication>((x, y) => x.ApplicationId == y.Id)
|
|
|
|
invoice.CustomerId = item.CustomerId;
|
|
|
|
.LeftJoin<InfoClientBank>((x, y, z) => y.CustomerId == z.ClientId && z.Currency == invoice.Currency && z.IsInvoiceDefault == true)
|
|
|
|
invoice.CustomerName = item.CustomerName;
|
|
|
|
.Where((x, y, z) => ids.Contains(x.ApplicationId) && x.Category == DetailCategory.InvoiceApplication)
|
|
|
|
invoice.TaxRate = item.TaxRate;
|
|
|
|
.Select((x, y, z) => new
|
|
|
|
invoice.InvoiceHeader = item.InvoiceHeader;
|
|
|
|
{
|
|
|
|
invoice.CustomerTaxID = item.TaxID;
|
|
|
|
x.Id,
|
|
|
|
invoice.CustomerAddressTel = item.CustomerAddTel;
|
|
|
|
x.ApplicationId,
|
|
|
|
invoice.CustomerAccount = item.BankAccountNo;
|
|
|
|
x.RecordId,
|
|
|
|
invoice.CustomerBankName = item.BankName;
|
|
|
|
x.CustomerName,
|
|
|
|
invoice.SaleDeptId = item.SaleDeptId;
|
|
|
|
x.FeeId,
|
|
|
|
invoice.PushMode = item.PushMode;
|
|
|
|
x.FeeType,
|
|
|
|
invoice.CellPhoneNO = item.CellPhoneNO;
|
|
|
|
x.FeeName,
|
|
|
|
invoice.Email = item.Email;
|
|
|
|
x.ApplyAmount,
|
|
|
|
}
|
|
|
|
x.OriginalAmount,
|
|
|
|
else if (invoice.CustomerId != item.CustomerId) //校验开票单位是否一致
|
|
|
|
x.Currency,
|
|
|
|
{
|
|
|
|
x.OriginalCurrency,
|
|
|
|
return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.InvoiceCustomerOnlyOne));
|
|
|
|
x.ProcessedAmount,
|
|
|
|
}
|
|
|
|
x.OriginalProcessedAmount,
|
|
|
|
else if (invoice.TaxRate != item.TaxRate) //校验税率是否一致
|
|
|
|
|
|
|
|
{
|
|
|
|
y.CustomerId,
|
|
|
|
return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.InconsistentTaxRates));
|
|
|
|
y.TaxRate,
|
|
|
|
}
|
|
|
|
y.TaxID,
|
|
|
|
|
|
|
|
y.InvoiceHeader,
|
|
|
|
|
|
|
|
y.CustomerAddTel,
|
|
|
|
|
|
|
|
y.SaleDeptId,
|
|
|
|
|
|
|
|
y.PushMode,
|
|
|
|
|
|
|
|
y.CellPhoneNO,
|
|
|
|
|
|
|
|
y.Email,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
z.BankAccountNo,
|
|
|
|
|
|
|
|
z.BankName
|
|
|
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
//需转换为费用明细
|
|
|
|
//税率不一致
|
|
|
|
var detail = new ApplicationDetail
|
|
|
|
if (details.GroupBy(x => x.TaxRate).Select(x => x.Key).Count() > 1)
|
|
|
|
{
|
|
|
|
return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.InconsistentTaxRates));
|
|
|
|
ApplicationId = invoice.Id,
|
|
|
|
|
|
|
|
RefId = item.ApplicationId,
|
|
|
|
|
|
|
|
DetailId = item.Id,
|
|
|
|
|
|
|
|
RecordId = item.RecordId,
|
|
|
|
|
|
|
|
Category = DetailCategory.InvoiceIssuance,
|
|
|
|
|
|
|
|
CustomerName = item.CustomerName,
|
|
|
|
|
|
|
|
FeeId = item.FeeId,
|
|
|
|
|
|
|
|
FeeName = item.FeeName,
|
|
|
|
|
|
|
|
FeeType = item.FeeType,
|
|
|
|
|
|
|
|
Currency = invoice.Currency,
|
|
|
|
|
|
|
|
OriginalCurrency = item.Currency,
|
|
|
|
|
|
|
|
ApplyAmount = item.ApplyAmount - item.ProcessedAmount,
|
|
|
|
|
|
|
|
OriginalAmount = item.OriginalAmount - item.OriginalProcessedAmount
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var app = request.Applications.Find(x => x.ApplicationId == item.ApplicationId);
|
|
|
|
invoice.Details ??= new List<ApplicationDetail>(details.Count);
|
|
|
|
if (app != null)
|
|
|
|
foreach (var item in details)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (app.Currency == invoice.Currency)
|
|
|
|
if (invoice.CustomerId == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
detail.ExchangeRate = 1m;
|
|
|
|
invoice.CustomerId = item.CustomerId;
|
|
|
|
|
|
|
|
invoice.CustomerName = item.CustomerName;
|
|
|
|
|
|
|
|
invoice.TaxRate = item.TaxRate;
|
|
|
|
|
|
|
|
invoice.InvoiceHeader = item.InvoiceHeader;
|
|
|
|
|
|
|
|
invoice.CustomerTaxID = item.TaxID;
|
|
|
|
|
|
|
|
invoice.CustomerAddressTel = item.CustomerAddTel;
|
|
|
|
|
|
|
|
invoice.CustomerAccount = item.BankAccountNo;
|
|
|
|
|
|
|
|
invoice.CustomerBankName = item.BankName;
|
|
|
|
|
|
|
|
invoice.SaleDeptId = item.SaleDeptId;
|
|
|
|
|
|
|
|
invoice.PushMode = item.PushMode;
|
|
|
|
|
|
|
|
invoice.CellPhoneNO = item.CellPhoneNO;
|
|
|
|
|
|
|
|
invoice.Email = item.Email;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (string.IsNullOrEmpty(app.Currency)) //原币申请
|
|
|
|
else if (invoice.CustomerId != item.CustomerId) //校验开票单位是否一致
|
|
|
|
{
|
|
|
|
{
|
|
|
|
detail.ExchangeRate = app.ExchangeRates.FirstOrDefault(
|
|
|
|
return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.InvoiceCustomerOnlyOne));
|
|
|
|
x => x.Currency == invoice.Currency)?.ExchangeRate;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else if (invoice.TaxRate != item.TaxRate) //校验税率是否一致
|
|
|
|
{
|
|
|
|
{
|
|
|
|
detail.ExchangeRate = app.ExchangeRates.FirstOrDefault(
|
|
|
|
return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.InconsistentTaxRates));
|
|
|
|
x => x.Currency == invoice.Currency)?.ExchangeRate;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!detail.ExchangeRate.HasValue)
|
|
|
|
//需转换为费用明细
|
|
|
|
detail.ExchangeRate = 1m;
|
|
|
|
var detail = new ApplicationDetail
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ApplicationId = invoice.Id,
|
|
|
|
|
|
|
|
RefId = item.ApplicationId,
|
|
|
|
|
|
|
|
DetailId = item.Id,
|
|
|
|
|
|
|
|
RecordId = item.RecordId,
|
|
|
|
|
|
|
|
Category = DetailCategory.InvoiceIssuance,
|
|
|
|
|
|
|
|
CustomerName = item.CustomerName,
|
|
|
|
|
|
|
|
FeeId = item.FeeId,
|
|
|
|
|
|
|
|
FeeName = item.FeeName,
|
|
|
|
|
|
|
|
FeeType = item.FeeType,
|
|
|
|
|
|
|
|
Currency = invoice.Currency,
|
|
|
|
|
|
|
|
OriginalCurrency = item.Currency,
|
|
|
|
|
|
|
|
ApplyAmount = item.ApplyAmount - item.ProcessedAmount,
|
|
|
|
|
|
|
|
OriginalAmount = item.OriginalAmount - item.OriginalProcessedAmount
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var app = request.Applications.Find(x => x.ApplicationId == item.ApplicationId);
|
|
|
|
|
|
|
|
if (app != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (app.Currency == invoice.Currency)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
detail.ExchangeRate = 1m;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (string.IsNullOrEmpty(app.Currency)) //原币申请
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
detail.ExchangeRate = app.ExchangeRates.FirstOrDefault(
|
|
|
|
|
|
|
|
x => x.Currency == invoice.Currency)?.ExchangeRate;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
detail.ExchangeRate = app.ExchangeRates.FirstOrDefault(
|
|
|
|
|
|
|
|
x => x.Currency == invoice.Currency)?.ExchangeRate;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!detail.ExchangeRate.HasValue)
|
|
|
|
|
|
|
|
detail.ExchangeRate = 1m;
|
|
|
|
|
|
|
|
|
|
|
|
if (detail.ExchangeRate.HasValue)
|
|
|
|
if (detail.ExchangeRate.HasValue)
|
|
|
|
detail.ApplyAmount = detail.ApplyAmount * detail.ExchangeRate.Value;
|
|
|
|
detail.ApplyAmount = detail.ApplyAmount * detail.ExchangeRate.Value;
|
|
|
|
|
|
|
|
|
|
|
|
invoice.Details.Add(detail);
|
|
|
|
invoice.Details.Add(detail);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//自由申请
|
|
|
|
else if (request.Invoice.Mode == InvoiceMode.Free) //自由开票
|
|
|
|
if (request.Details?.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (invoice.Id == 0 && invoice.CustomerId == 0)
|
|
|
|
if (request.BizList?.Count > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var first = request.Details[0];
|
|
|
|
var result2 = await GetFeesAsync([.. request.BizList]);
|
|
|
|
invoice.CustomerId = first.CustomerId;
|
|
|
|
if (result2.Data != null)
|
|
|
|
invoice.CustomerName = first.CustomerName;
|
|
|
|
{
|
|
|
|
|
|
|
|
request.Details ??= [];
|
|
|
|
|
|
|
|
foreach (var item in result2.Data.Items)
|
|
|
|
|
|
|
|
request.Details.Add(item.Adapt<PaymentApplicationDetailDto>());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var ids = request.Details.Select(x => x.RecordId).Distinct();
|
|
|
|
if (request.Details?.Count > 0)
|
|
|
|
var fees = await TenantDb.Queryable<FeeRecord>().Where(x => ids.Contains(x.Id)).Select(x => new { x.Id, x.TaxRate }).ToListAsync();
|
|
|
|
|
|
|
|
//税率不一致
|
|
|
|
|
|
|
|
if (fees.GroupBy(x => x.TaxRate).Select(x => x.Key).Count() > 1 || (invoice.Id > 0 && invoice.TaxRate != fees[0].TaxRate))
|
|
|
|
|
|
|
|
return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.InvoiceCustomerOnlyOne));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//将请求明细转换为数据库的费用明细
|
|
|
|
|
|
|
|
invoice.Details = request.Details.Select(x => new ApplicationDetail
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Id = x.Id,
|
|
|
|
if (invoice.Id == 0 && invoice.CustomerId == 0)
|
|
|
|
ApplicationId = x.ApplicationId == 0 ? x.ApplicationId : invoice.Id,
|
|
|
|
{
|
|
|
|
RefId = x.RefId,
|
|
|
|
var first = request.Details[0];
|
|
|
|
DetailId = x.Id == 0 ? null : x.Id,
|
|
|
|
invoice.CustomerId = first.CustomerId;
|
|
|
|
RecordId = x.RecordId,
|
|
|
|
invoice.CustomerName = first.CustomerName;
|
|
|
|
Category = DetailCategory.InvoiceIssuance,
|
|
|
|
}
|
|
|
|
CustomerName = x.CustomerName ?? invoice.CustomerName,
|
|
|
|
|
|
|
|
FeeId = x.FeeId,
|
|
|
|
|
|
|
|
FeeName = x.FeeName,
|
|
|
|
|
|
|
|
FeeType = x.FeeType,
|
|
|
|
|
|
|
|
Currency = x.Currency,
|
|
|
|
|
|
|
|
ApplyAmount = x.ApplyAmount,
|
|
|
|
|
|
|
|
ExchangeRate = x.ExchangeRate,
|
|
|
|
|
|
|
|
OriginalAmount = x.OriginalAmount,
|
|
|
|
|
|
|
|
OriginalCurrency = x.OriginalCurrency ?? (invoice.Currency.IsNullOrEmpty() ? x.Currency : invoice.Currency),
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//补充购方信息
|
|
|
|
var ids = request.Details.Select(x => x.RecordId).Distinct();
|
|
|
|
invoice.CustomerTaxID = await TenantDb.Queryable<InfoClient>().Where(x => x.Id == invoice.CustomerId).Select(x => x.TaxNo).FirstAsync();
|
|
|
|
var fees = await TenantDb.Queryable<FeeRecord>().Where(x => ids.Contains(x.Id)).Select(x => new { x.Id, x.TaxRate }).ToListAsync();
|
|
|
|
var header = await TenantDb.Queryable<InvoiceHeader>().Where(x => x.RelativeId == invoice.CustomerId)
|
|
|
|
//税率不一致
|
|
|
|
.OrderByDescending(x => x.Id).FirstAsync();
|
|
|
|
if (fees.GroupBy(x => x.TaxRate).Select(x => x.Key).Count() > 1 || (invoice.Id > 0 && invoice.TaxRate != fees[0].TaxRate))
|
|
|
|
if (header != null)
|
|
|
|
return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.InconsistentTaxRates));
|
|
|
|
{
|
|
|
|
|
|
|
|
invoice.InvoiceHeader = header.Header;
|
|
|
|
//将请求明细转换为数据库的费用明细
|
|
|
|
invoice.CustomerAddressTel = header.AddressTel;
|
|
|
|
invoice.Details = request.Details.Select(x => new ApplicationDetail
|
|
|
|
}
|
|
|
|
|
|
|
|
var clientBank = await TenantDb.Queryable<InfoClientBank>().Where(x => x.ClientId == invoice.CustomerId && x.Currency == invoice.Currency)
|
|
|
|
|
|
|
|
.OrderByDescending(x => x.IsInvoiceDefault).Select(x => new
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
x.Account,
|
|
|
|
Id = x.Id,
|
|
|
|
x.BankName
|
|
|
|
ApplicationId = x.ApplicationId == 0 ? x.ApplicationId : invoice.Id,
|
|
|
|
}).FirstAsync();
|
|
|
|
RefId = x.RefId,
|
|
|
|
if (clientBank != null)
|
|
|
|
DetailId = x.Id == 0 ? null : x.Id,
|
|
|
|
{
|
|
|
|
RecordId = x.RecordId,
|
|
|
|
invoice.CustomerAccount = clientBank.Account;
|
|
|
|
Category = DetailCategory.InvoiceIssuance,
|
|
|
|
invoice.CustomerBankName = clientBank.BankName;
|
|
|
|
CustomerName = x.CustomerName ?? invoice.CustomerName,
|
|
|
|
|
|
|
|
FeeId = x.FeeId,
|
|
|
|
|
|
|
|
FeeName = x.FeeName,
|
|
|
|
|
|
|
|
FeeType = x.FeeType,
|
|
|
|
|
|
|
|
Currency = x.Currency,
|
|
|
|
|
|
|
|
ApplyAmount = x.ApplyAmount,
|
|
|
|
|
|
|
|
ExchangeRate = x.ExchangeRate,
|
|
|
|
|
|
|
|
OriginalAmount = x.OriginalAmount,
|
|
|
|
|
|
|
|
OriginalCurrency = x.OriginalCurrency ?? (invoice.Currency.IsNullOrEmpty() ? x.Currency : invoice.Currency),
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//补充购方信息
|
|
|
|
|
|
|
|
invoice.CustomerTaxID = await TenantDb.Queryable<InfoClient>().Where(x => x.Id == invoice.CustomerId).Select(x => x.TaxNo).FirstAsync();
|
|
|
|
|
|
|
|
var header = await TenantDb.Queryable<InvoiceHeader>().Where(x => x.RelativeId == invoice.CustomerId)
|
|
|
|
|
|
|
|
.OrderByDescending(x => x.Id).FirstAsync();
|
|
|
|
|
|
|
|
if (header != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
invoice.InvoiceHeader = header.Header;
|
|
|
|
|
|
|
|
invoice.CustomerAddressTel = header.AddressTel;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var clientBank = await TenantDb.Queryable<InfoClientBank>().Where(x => x.ClientId == invoice.CustomerId && x.Currency == invoice.Currency)
|
|
|
|
|
|
|
|
.OrderByDescending(x => x.IsInvoiceDefault).Select(x => new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
x.Account,
|
|
|
|
|
|
|
|
x.BankName
|
|
|
|
|
|
|
|
}).FirstAsync();
|
|
|
|
|
|
|
|
if (clientBank != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
invoice.CustomerAccount = clientBank.Account;
|
|
|
|
|
|
|
|
invoice.CustomerBankName = clientBank.BankName;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|