|
|
|
@ -10,7 +10,6 @@ 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;
|
|
|
|
@ -575,19 +574,18 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
|
await base.OnSaveAsync(application, fees);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//刷新发票明细
|
|
|
|
|
async Task RefreshInvoiceDetailsAsync(InvoiceApplication application)
|
|
|
|
|
{
|
|
|
|
|
if (application.Details.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var recordIds = application.Details.Select(x => x.RecordId).ToList();
|
|
|
|
|
var codeList = await TenantDb.Queryable<FeeRecord>()
|
|
|
|
|
.InnerJoin<FeeCode>((f, c) => f.FeeId == c.Id && recordIds.Contains(f.Id))
|
|
|
|
|
.LeftJoin<CodeInvoice>((f, c, ci) => c.GoodName == ci.Name)
|
|
|
|
|
.Select((f, c, ci) => new
|
|
|
|
|
application.InvoiceDetails ??= [];
|
|
|
|
|
var currencies = application.Details.Select(x => x.Currency).Distinct();
|
|
|
|
|
var codeList = await TenantDb.Queryable<CodeInvoice>()
|
|
|
|
|
.Where(ci => currencies.Contains(ci.DefaultCurrency))
|
|
|
|
|
.OrderBy(ci => ci.IsDefault)
|
|
|
|
|
.Select(ci => new
|
|
|
|
|
{
|
|
|
|
|
RecordId = f.Id,
|
|
|
|
|
ci.Id,
|
|
|
|
|
ci.Name,
|
|
|
|
|
ci.DefaultCurrency,
|
|
|
|
@ -596,13 +594,15 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
|
ci.Unit
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
application.InvoiceDetails ??= [];
|
|
|
|
|
foreach (var detail in application.Details)
|
|
|
|
|
{
|
|
|
|
|
var code = codeList.Find(x => x.RecordId == detail.RecordId);
|
|
|
|
|
if (code == null || string.IsNullOrEmpty(code.Name))
|
|
|
|
|
var code = codeList.Find(x => x.DefaultCurrency == detail.Currency);
|
|
|
|
|
if (code == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (application.BuildOption == BuildOption.Update && codeList.IndexOf(code) == 0)//取第一条发票代码税率
|
|
|
|
|
application.TaxRate = code.TaxRate;
|
|
|
|
|
|
|
|
|
|
var invDetail = application.InvoiceDetails.Find(x => x.CodeId == code.Id);
|
|
|
|
|
if (invDetail == null)
|
|
|
|
|
{
|
|
|
|
@ -612,9 +612,8 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
|
CodeId = code.Id,
|
|
|
|
|
Name = code.Name,
|
|
|
|
|
Quantity = 1,
|
|
|
|
|
TaxUnitPrice = application.Details.FindAll(x => x.RecordId == code.RecordId).Sum(x => x.ApplyAmount),
|
|
|
|
|
TaxRate = application.TaxRate,
|
|
|
|
|
//TaxRate = code.TaxRate,
|
|
|
|
|
TaxUnitPrice = application.Details.FindAll(x => x.Currency == code.DefaultCurrency).Sum(x => x.ApplyAmount),
|
|
|
|
|
TaxRate = code.TaxRate,
|
|
|
|
|
Specification = code.Specification,
|
|
|
|
|
Unit = code.Unit,
|
|
|
|
|
Category = DetailCategory.InvoiceApplication
|
|
|
|
@ -633,6 +632,7 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override DataResult PreDelete(List<InvoiceApplication> applications)
|
|
|
|
|
{
|
|
|
|
|
if (applications.Any(x => x.Status != InvoiceApplicationStatus.Pending && x.Status != InvoiceApplicationStatus.AuditRejected))
|
|
|
|
@ -653,40 +653,6 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
|
.PublicSetColumns(it => it.OrderInvoiceAmount, "-")
|
|
|
|
|
.UpdateColumns(x => new { x.OrderInvoiceAmount })
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
//if (deleteOption == DeleteOption.DetailOnly)
|
|
|
|
|
//{
|
|
|
|
|
// //删除明细需要同时变更发票明细
|
|
|
|
|
// var appIds = applications.Select(x => x.Id).ToList();
|
|
|
|
|
// var excludeIds = applications.SelectMany(x => x.Details).Select(x => x.Id).ToList();
|
|
|
|
|
// var details = await TenantDb.Queryable<ApplicationDetail>().Where(x => appIds.Contains(x.ApplicationId) && !excludeIds.Contains(x.Id))
|
|
|
|
|
// .Select(x => new ApplicationDetail
|
|
|
|
|
// {
|
|
|
|
|
// Id = x.Id,
|
|
|
|
|
// ApplicationId = x.ApplicationId,
|
|
|
|
|
// RecordId = x.RecordId,
|
|
|
|
|
// FeeId = x.FeeId,
|
|
|
|
|
// ApplyAmount = x.ApplyAmount
|
|
|
|
|
// }).ToListAsync();
|
|
|
|
|
// foreach (var item in applications)
|
|
|
|
|
// {
|
|
|
|
|
// //重新设置申请明细
|
|
|
|
|
// item.Details = details.FindAll(x => x.ApplicationId == item.Id);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// await TenantDb.Deleteable<InvoiceDetail>().Where(x => appIds.Contains(x.ApplicationId)).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
// await FillInvoiceDetailsAsync(applications);
|
|
|
|
|
// var invDetails = applications.SelectMany(x => x.InvoiceDetails).ToList();
|
|
|
|
|
// if (invDetails.Count > 0)
|
|
|
|
|
// await TenantDb.Insertable(invDetails).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
// await TenantDb.Updateable(applications).UpdateColumns(x => new
|
|
|
|
|
// {
|
|
|
|
|
// x.ApplyAmount,
|
|
|
|
|
// x.AmountUppercase
|
|
|
|
|
// }).ExecuteCommandAsync();
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override DataResult PreSubmitApproval(List<InvoiceApplication> applications)
|
|
|
|
|