发票相关优化

dev
嵇文龙 2 months ago
parent 90d74a61d3
commit 6202782a5a

@ -62,8 +62,8 @@ namespace DS.WMS.Core.Application.Entity
/// <summary>
/// 纳税人识别号
/// </summary>
[SugarColumn(ColumnDescription = "纳税人识别号", Length = 60, IsNullable = false)]
public string TaxID { get; set; } = string.Empty;
[SugarColumn(ColumnDescription = "纳税人识别号", Length = 60, IsNullable = true)]
public string? TaxID { get; set; }
/// <summary>
/// 申请金额

@ -109,19 +109,6 @@ namespace DS.WMS.Core.Application.Method
var fee = fees[0];
application.CustomerId = fee.CustomerId;
application.CustomerName = fee.CustomerName;
var bankCurrency = application.Currency ?? fee.Currency;
var bank = await TenantDb.Queryable<InfoClientBank>().Where(x => x.ClientId == application.CustomerId &&
x.Currency == bankCurrency).OrderByDescending(x => x.IsInvoiceDefault)
.Select(x => new
{
x.Id,
x.BankName,
x.Account
}).FirstAsync();
if (bank != null)
application.CustomerBankId = bank.Id;
}
foreach (var detail in application.Details)

@ -10,6 +10,7 @@ using DS.WMS.Core.Code.Entity;
using DS.WMS.Core.Fee.Dtos;
using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.Info.Entity;
using DS.WMS.Core.Invoice.Entity;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Sys.Entity;
using SqlSugar;
@ -452,7 +453,6 @@ namespace DS.WMS.Core.Application.Method
return DataResult.Success;
}
protected override DataResult CalculateAmount(InvoiceApplication application, List<FeeRecord> fees)
{
if (fees == null)
@ -517,6 +517,42 @@ namespace DS.WMS.Core.Application.Method
return DataResult.Success;
}
protected override async Task PreSaveAsync(InvoiceApplication application)
{
if (application.Id > 0)
return;
if (application.CustomerBankId == null)
{
var bankId = await TenantDb.Queryable<InfoClientBank>().Where(x => x.ClientId == application.CustomerId &&
x.Currency == FeeCurrency.RMB_CODE).OrderByDescending(x => x.IsInvoiceDefault).Select(x => x.Id).FirstAsync();
if (bankId > 0)
application.CustomerBankId = bankId;
}
if (application.USDCustomerBankId == null)
{
var bankId = await TenantDb.Queryable<InfoClientBank>().Where(x => x.ClientId == application.CustomerId &&
x.Currency == FeeCurrency.USD_CODE).OrderByDescending(x => x.IsInvoiceDefault).Select(x => x.Id).FirstAsync();
if (bankId > 0)
application.CustomerBankId = bankId;
}
if (string.IsNullOrEmpty(application.InvoiceHeader))
{
application.TaxID = await TenantDb.Queryable<InfoClient>().Where(x => x.Id == application.CustomerId).Select(x => x.TaxNo).FirstAsync();
var header = await TenantDb.Queryable<InvoiceHeader>().Where(
x => x.RelativeId == application.CustomerId).OrderByDescending(x => x.Id).FirstAsync();
if (header != null)
{
application.InvoiceHeader = header.Header;
application.CustomerAddTel = header.AddressTel;
}
}
}
//提交事务前
protected override async Task OnSaveAsync(InvoiceApplication application, List<FeeRecord>? fees)
{
@ -583,16 +619,16 @@ namespace DS.WMS.Core.Application.Method
Unit = code.Unit,
Category = DetailCategory.InvoiceApplication
};
invDetail.TaxAmount = invDetail.TaxUnitPrice * application.TaxRate;
invDetail.UnitPrice = invDetail.TaxUnitPrice - invDetail.TaxAmount;
invDetail.Amount = invDetail.TaxUnitPrice * invDetail.Quantity;
application.InvoiceDetails.Add(invDetail);
}
else
{
invDetail.Amount += detail.ApplyAmount;
}
invDetail.TaxAmount = invDetail.TaxUnitPrice * application.TaxRate;
invDetail.UnitPrice = invDetail.TaxUnitPrice - invDetail.TaxAmount;
invDetail.Amount = invDetail.TaxUnitPrice * invDetail.Quantity;
}
}
}

@ -497,6 +497,23 @@ namespace DS.WMS.Core.Application.Method
return sb.Length > 0 ? DataResult.Failed(sb.ToString()) : DataResult.Success;
}
protected override async Task PreSaveAsync(PaymentApplication application)
{
if (application.CustomerBankId == null)
{
var bankCurrency = application.Currency;
if (string.IsNullOrEmpty(bankCurrency) && application.Details.Count > 0)
bankCurrency = application.Details[0].Currency;
var bankId = await TenantDb.Queryable<InfoClientBank>().Where(x => x.ClientId == application.CustomerId &&
x.Currency == bankCurrency).OrderByDescending(x => x.IsInvoiceDefault)
.Select(x => x.Id).FirstAsync();
if (bankId > 0)
application.CustomerBankId = bankId;
}
}
protected override async Task OnSaveAsync(PaymentApplication application, List<FeeRecord>? fees)
{
var details = application.Details;

@ -591,16 +591,16 @@ namespace DS.WMS.Core.Invoice.Method
Unit = code.Unit,
Category = DetailCategory.InvoiceApplication
};
invDetail.TaxAmount = invDetail.TaxUnitPrice * invoice.TaxRate;
invDetail.UnitPrice = invDetail.TaxUnitPrice - invDetail.TaxAmount;
invDetail.Amount = invDetail.TaxUnitPrice * invDetail.Quantity;
invoice.InvoiceDetails.Add(invDetail);
}
else
{
invDetail.Amount += detail.ApplyAmount;
}
invDetail.TaxAmount = invDetail.TaxUnitPrice * invoice.TaxRate;
invDetail.UnitPrice = invDetail.TaxUnitPrice - invDetail.TaxAmount;
invDetail.Amount = invDetail.TaxUnitPrice * invDetail.Quantity;
}
}

Loading…
Cancel
Save