|
|
@ -3,8 +3,8 @@ using DS.Module.Core.Enums;
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
using DS.WMS.Core.Application.Dtos;
|
|
|
|
using DS.WMS.Core.Application.Dtos;
|
|
|
|
using DS.WMS.Core.Application.Entity;
|
|
|
|
using DS.WMS.Core.Application.Entity;
|
|
|
|
|
|
|
|
using DS.WMS.Core.Application.Method;
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
using DS.WMS.Core.Fee.Method;
|
|
|
|
|
|
|
|
using DS.WMS.Core.Invoice.Dto;
|
|
|
|
using DS.WMS.Core.Invoice.Dto;
|
|
|
|
using DS.WMS.Core.Invoice.Dtos;
|
|
|
|
using DS.WMS.Core.Invoice.Dtos;
|
|
|
|
using DS.WMS.Core.Invoice.Interface;
|
|
|
|
using DS.WMS.Core.Invoice.Interface;
|
|
|
@ -19,10 +19,9 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
/// 发票服务基类
|
|
|
|
/// 发票服务基类
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="TEntity"></typeparam>
|
|
|
|
/// <typeparam name="TEntity"></typeparam>
|
|
|
|
public class InvoiceService<TEntity> : FeeServiceBase, IInvoiceService<TEntity>
|
|
|
|
public class InvoiceService<TEntity> : ApplicationServiceBase, IInvoiceService<TEntity>
|
|
|
|
where TEntity : Entity.Invoice, new()
|
|
|
|
where TEntity : Entity.Invoice, new()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
readonly Lazy<ICommonService> CommonService;
|
|
|
|
readonly Lazy<ICommonService> CommonService;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -162,6 +161,8 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
return DataResult<InvoiceDto>.Success(invoice);
|
|
|
|
return DataResult<InvoiceDto>.Success(invoice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma warning disable CS4014
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 提交发票开票
|
|
|
|
/// 提交发票开票
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -193,6 +194,75 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
if (!result.Succeeded)
|
|
|
|
if (!result.Succeeded)
|
|
|
|
return DataResult<TEntity>.Failed(result.Message, result.MultiCode);
|
|
|
|
return DataResult<TEntity>.Failed(result.Message, result.MultiCode);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//按发票申请
|
|
|
|
|
|
|
|
if (request.Applications != null && request.Applications.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var ids = request.Applications.Select(x => x.ApplicationId);
|
|
|
|
|
|
|
|
var details = await TenantDb.Queryable<ApplicationDetail>()
|
|
|
|
|
|
|
|
.InnerJoin<InvoiceApplication>((x, y) => x.ApplicationId == y.Id)
|
|
|
|
|
|
|
|
.Where((x, y) => ids.Contains(x.ApplicationId) && x.Category == DetailCategory.InvoiceApplication)
|
|
|
|
|
|
|
|
.Select((x, y) => 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
|
|
|
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
invoice.Details = new List<ApplicationDetail>(details.Count);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in details)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (request.Invoice.CustomerId == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
request.Invoice.CustomerId = item.CustomerId;
|
|
|
|
|
|
|
|
request.Invoice.CustomerName = item.CustomerName;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (request.Invoice.CustomerId != item.CustomerId) //校验开票单位是否一致
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.InvoiceCustomerOnlyOne));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//需转换为费用明细
|
|
|
|
|
|
|
|
var detail = new ApplicationDetail
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ApplicationId = request.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 = RMB_CODE,
|
|
|
|
|
|
|
|
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 && app.Currency != invoice.Currency)
|
|
|
|
|
|
|
|
detail.ExchangeRate = app.ExchangeRate;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
detail.ExchangeRate = 1m;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (detail.ExchangeRate.HasValue)
|
|
|
|
|
|
|
|
detail.ApplyAmount = detail.ApplyAmount * detail.ExchangeRate.Value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
invoice.Details.Add(detail);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//自由申请
|
|
|
|
if (request.Details?.Count > 0)
|
|
|
|
if (request.Details?.Count > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (invoice.Id == 0 && invoice.CustomerId == 0)
|
|
|
|
if (invoice.Id == 0 && invoice.CustomerId == 0)
|
|
|
@ -202,11 +272,14 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
invoice.CustomerName = first.CustomerName;
|
|
|
|
invoice.CustomerName = first.CustomerName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//将请求明细转换为数据库的费用明细
|
|
|
|
invoice.Details = request.Details.Select(x => new ApplicationDetail
|
|
|
|
invoice.Details = request.Details.Select(x => new ApplicationDetail
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ApplicationId = x.ApplicationId,
|
|
|
|
ApplicationId = x.ApplicationId,
|
|
|
|
|
|
|
|
RefId = x.RefId,
|
|
|
|
DetailId = x.Id == 0 ? null : x.Id,
|
|
|
|
DetailId = x.Id == 0 ? null : x.Id,
|
|
|
|
RecordId = x.RecordId,
|
|
|
|
RecordId = x.RecordId,
|
|
|
|
|
|
|
|
Category = DetailCategory.InvoiceIssuance,
|
|
|
|
CustomerName = x.CustomerName ?? invoice.CustomerName,
|
|
|
|
CustomerName = x.CustomerName ?? invoice.CustomerName,
|
|
|
|
FeeId = x.FeeId,
|
|
|
|
FeeId = x.FeeId,
|
|
|
|
FeeName = x.FeeName,
|
|
|
|
FeeName = x.FeeName,
|
|
|
@ -217,7 +290,10 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
OriginalAmount = x.OriginalAmount,
|
|
|
|
OriginalAmount = x.OriginalAmount,
|
|
|
|
OriginalCurrency = x.OriginalCurrency ?? (invoice.Currency.IsNullOrEmpty() ? x.Currency : invoice.Currency),
|
|
|
|
OriginalCurrency = x.OriginalCurrency ?? (invoice.Currency.IsNullOrEmpty() ? x.Currency : invoice.Currency),
|
|
|
|
}).ToList();
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (invoice.Details?.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
//金额禁止为0
|
|
|
|
//金额禁止为0
|
|
|
|
if (invoice.Details.Any(x => x.ApplyAmount == 0 || x.OriginalAmount == 0))
|
|
|
|
if (invoice.Details.Any(x => x.ApplyAmount == 0 || x.OriginalAmount == 0))
|
|
|
|
return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.AmountCannotBeZero));
|
|
|
|
return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.AmountCannotBeZero));
|
|
|
@ -233,7 +309,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
return DataResult<TEntity>.Failed(result.Message, result.MultiCode);
|
|
|
|
return DataResult<TEntity>.Failed(result.Message, result.MultiCode);
|
|
|
|
|
|
|
|
|
|
|
|
invoice.ApplyAmount = invoice.Details.Sum(x => x.ApplyAmount);
|
|
|
|
invoice.ApplyAmount = invoice.Details.Sum(x => x.ApplyAmount);
|
|
|
|
invoice.AmountUppercase = new Money(invoice.InvoiceAmount).ToString();
|
|
|
|
invoice.AmountUppercase = new Money(invoice.ApplyAmount).ToString();
|
|
|
|
invoice.OriginalAmount = invoice.Details.Sum(x => x.OriginalAmount);
|
|
|
|
invoice.OriginalAmount = invoice.Details.Sum(x => x.OriginalAmount);
|
|
|
|
invoice.OtherInvoiceAmount = invoice.Details.Where(x => x.Currency != RMB_CODE).Sum(x => x.OriginalAmount);
|
|
|
|
invoice.OtherInvoiceAmount = invoice.Details.Where(x => x.Currency != RMB_CODE).Sum(x => x.OriginalAmount);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -241,8 +317,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
await TenantDb.Ado.BeginTranAsync();
|
|
|
|
await TenantDb.Ado.BeginTranAsync();
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//关联导航属性插入
|
|
|
|
if (invoice.Id == 0)//新增
|
|
|
|
if (invoice.Id == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//创建时需要生成申请单编号
|
|
|
|
//创建时需要生成申请单编号
|
|
|
|
var sequence = CommonService.Value.GetSequenceNext<TEntity>();
|
|
|
|
var sequence = CommonService.Value.GetSequenceNext<TEntity>();
|
|
|
@ -251,10 +326,10 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
return DataResult<TEntity>.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist);
|
|
|
|
return DataResult<TEntity>.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
invoice.BillNO = sequence.Data;
|
|
|
|
invoice.BillNO = sequence.Data;
|
|
|
|
|
|
|
|
//关联导航属性插入
|
|
|
|
await TenantDb.InsertNav(invoice).Include(x => x.Details).ExecuteCommandAsync();
|
|
|
|
await TenantDb.InsertNav(invoice).Include(x => x.Details).ExecuteCommandAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else//编辑
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (invoice.Details?.Count > 0)
|
|
|
|
if (invoice.Details?.Count > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -262,11 +337,26 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
//因需要重新生成明细,所以要先清空现有发票明细
|
|
|
|
//因需要重新生成明细,所以要先清空现有发票明细
|
|
|
|
await TenantDb.Deleteable<InvoiceDetail>().Where(x => x.ApplicationId == invoice.Id).ExecuteCommandAsync();
|
|
|
|
await TenantDb.Deleteable<InvoiceDetail>().Where(x => x.ApplicationId == invoice.Id).ExecuteCommandAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (invoice.InvoiceDetails?.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await TenantDb.Updateable(invoice.InvoiceDetails).UpdateColumns(x => new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
x.Name,
|
|
|
|
|
|
|
|
x.Specification,
|
|
|
|
|
|
|
|
x.Unit,
|
|
|
|
|
|
|
|
x.UnitPrice,
|
|
|
|
|
|
|
|
x.TaxRate,
|
|
|
|
|
|
|
|
x.TaxAmount,
|
|
|
|
|
|
|
|
x.UpdateTime,
|
|
|
|
|
|
|
|
x.UpdateBy
|
|
|
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await TenantDb.Updateable(invoice).IgnoreColumns(x => new
|
|
|
|
await TenantDb.Updateable(invoice).IgnoreColumns(x => new
|
|
|
|
{
|
|
|
|
{
|
|
|
|
x.BillNO,
|
|
|
|
x.BillNO,
|
|
|
|
x.IsLocked,
|
|
|
|
x.IsLocked,
|
|
|
|
|
|
|
|
|
|
|
|
x.CreateBy,
|
|
|
|
x.CreateBy,
|
|
|
|
x.CreateTime,
|
|
|
|
x.CreateTime,
|
|
|
|
x.Deleted,
|
|
|
|
x.Deleted,
|
|
|
@ -295,7 +385,10 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
|
|
|
|
|
|
|
await OnSaveAsync(invoice);
|
|
|
|
await OnSaveAsync(invoice);
|
|
|
|
await TenantDb.Ado.CommitTranAsync();
|
|
|
|
await TenantDb.Ado.CommitTranAsync();
|
|
|
|
return DataResult<TEntity>.Success(await PostSaveAsync(invoice));
|
|
|
|
|
|
|
|
|
|
|
|
PostSaveAsync(invoice);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult<TEntity>.Success(invoice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -311,40 +404,27 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
/// <param name="invoice">提交的发票</param>
|
|
|
|
/// <param name="invoice">提交的发票</param>
|
|
|
|
/// <param name="dbValue">数据库值,新增时为null</param>
|
|
|
|
/// <param name="dbValue">数据库值,新增时为null</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
protected virtual DataResult EnsureSettlement(TEntity invoice, TEntity? dbValue)
|
|
|
|
protected virtual DataResult EnsureSettlement(TEntity invoice, TEntity? dbValue) => DataResult.Success;
|
|
|
|
{
|
|
|
|
|
|
|
|
return DataResult.Success;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 在保存前调用
|
|
|
|
/// 在保存前调用
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="invoice">发票</param>
|
|
|
|
/// <param name="invoice">发票</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
protected virtual Task<DataResult> PreSaveAsync(TEntity invoice)
|
|
|
|
protected virtual Task<DataResult> PreSaveAsync(TEntity invoice) => Task.FromResult(DataResult.Success);
|
|
|
|
{
|
|
|
|
|
|
|
|
return Task.FromResult(DataResult.Success);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 在保存时调用
|
|
|
|
/// 在保存时调用
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="invoice">要保存的发票</param>
|
|
|
|
/// <param name="invoice">要保存的发票</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
protected virtual Task OnSaveAsync(TEntity invoice)
|
|
|
|
protected virtual Task OnSaveAsync(TEntity invoice) => Task.CompletedTask;
|
|
|
|
{
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 在保存完成后调用
|
|
|
|
/// 在保存完成后调用
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="invoice">发票</param>
|
|
|
|
/// <param name="invoice">发票</param>
|
|
|
|
protected virtual Task<TEntity> PostSaveAsync(TEntity invoice)
|
|
|
|
protected virtual Task PostSaveAsync(TEntity invoice) => Task.CompletedTask;
|
|
|
|
{
|
|
|
|
|
|
|
|
return Task.FromResult(invoice);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -364,7 +444,10 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Id = x.Id,
|
|
|
|
Id = x.Id,
|
|
|
|
ApplicationId = x.ApplicationId,
|
|
|
|
ApplicationId = x.ApplicationId,
|
|
|
|
|
|
|
|
DetailId = x.DetailId,
|
|
|
|
|
|
|
|
RefId = x.RefId,
|
|
|
|
RecordId = x.RecordId,
|
|
|
|
RecordId = x.RecordId,
|
|
|
|
|
|
|
|
ApplyAmount = x.ApplyAmount,
|
|
|
|
OriginalAmount = x.OriginalAmount
|
|
|
|
OriginalAmount = x.OriginalAmount
|
|
|
|
}).ToListAsync();
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
@ -379,8 +462,10 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await OnDeleteDetailAsync(apps, DeleteOption.Entire);
|
|
|
|
await OnDeleteDetailAsync(apps, DeleteOption.Entire);
|
|
|
|
await TenantDb.DeleteNav<TEntity>(x => ids.Contains(x.Id)).Include(x => x.Details).ExecuteCommandAsync();
|
|
|
|
await TenantDb.DeleteNav<TEntity>(x => ids.Contains(x.Id)).Include(x => x.Details).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
|
|
await TenantDb.Ado.CommitTranAsync();
|
|
|
|
await TenantDb.Ado.CommitTranAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PostDeleteAsync(apps, DeleteOption.Entire);
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult.Success;
|
|
|
|
return DataResult.Success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
@ -403,7 +488,10 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Id = x.Id,
|
|
|
|
Id = x.Id,
|
|
|
|
ApplicationId = x.ApplicationId,
|
|
|
|
ApplicationId = x.ApplicationId,
|
|
|
|
|
|
|
|
DetailId = x.DetailId,
|
|
|
|
|
|
|
|
RefId = x.RefId,
|
|
|
|
RecordId = x.RecordId,
|
|
|
|
RecordId = x.RecordId,
|
|
|
|
|
|
|
|
ApplyAmount = x.ApplyAmount,
|
|
|
|
OriginalAmount = x.OriginalAmount
|
|
|
|
OriginalAmount = x.OriginalAmount
|
|
|
|
}).ToListAsync();
|
|
|
|
}).ToListAsync();
|
|
|
|
var appIds = details.Select(x => x.ApplicationId).Distinct().ToList();
|
|
|
|
var appIds = details.Select(x => x.ApplicationId).Distinct().ToList();
|
|
|
@ -425,8 +513,10 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await OnDeleteDetailAsync(apps, DeleteOption.DetailOnly);
|
|
|
|
await OnDeleteDetailAsync(apps, DeleteOption.DetailOnly);
|
|
|
|
await TenantDb.Deleteable(details).ExecuteCommandAsync();
|
|
|
|
await TenantDb.Deleteable(details).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
|
|
await TenantDb.Ado.CommitTranAsync();
|
|
|
|
await TenantDb.Ado.CommitTranAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PostDeleteAsync(apps, DeleteOption.Entire);
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult.Success;
|
|
|
|
return DataResult.Success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
@ -458,11 +548,13 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
protected virtual async Task OnDeleteDetailAsync(List<TEntity> invoices, DeleteOption deleteOption)
|
|
|
|
protected virtual async Task OnDeleteDetailAsync(List<TEntity> invoices, DeleteOption deleteOption)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
var excludeIds = invoices.SelectMany(x => x.Details).Select(x => x.Id).ToList();
|
|
|
|
|
|
|
|
await TenantDb.Deleteable<InvoiceDetail>().Where(x => excludeIds.Contains(x.Id)).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
|
|
if (deleteOption == DeleteOption.DetailOnly)
|
|
|
|
if (deleteOption == DeleteOption.DetailOnly)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//删除明细需要同时变更发票明细
|
|
|
|
|
|
|
|
var appIds = invoices.Select(x => x.Id).ToList();
|
|
|
|
var appIds = invoices.Select(x => x.Id).ToList();
|
|
|
|
var excludeIds = invoices.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))
|
|
|
|
var details = await TenantDb.Queryable<ApplicationDetail>().Where(x => appIds.Contains(x.ApplicationId) && !excludeIds.Contains(x.Id))
|
|
|
|
.Select(x => new ApplicationDetail
|
|
|
|
.Select(x => new ApplicationDetail
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -474,12 +566,12 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
}).ToListAsync();
|
|
|
|
}).ToListAsync();
|
|
|
|
foreach (var item in invoices)
|
|
|
|
foreach (var item in invoices)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//重新设置申请明细
|
|
|
|
//重新设置申请明细与总金额
|
|
|
|
item.Details = details.FindAll(x => x.ApplicationId == item.Id);
|
|
|
|
item.Details = details.FindAll(x => x.ApplicationId == item.Id);
|
|
|
|
|
|
|
|
item.ApplyAmount = item.Details.Sum(x => x.ApplyAmount);
|
|
|
|
|
|
|
|
item.AmountUppercase = new Money(item.ApplyAmount).ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await TenantDb.Deleteable<InvoiceDetail>().Where(x => appIds.Contains(x.ApplicationId)).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await CreateInvoiceDetailsAsync(invoices);
|
|
|
|
await CreateInvoiceDetailsAsync(invoices);
|
|
|
|
var invDetails = invoices.SelectMany(x => x.InvoiceDetails).ToList();
|
|
|
|
var invDetails = invoices.SelectMany(x => x.InvoiceDetails).ToList();
|
|
|
|
if (invDetails.Count > 0)
|
|
|
|
if (invDetails.Count > 0)
|
|
|
@ -499,6 +591,13 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 在删除完成后调用
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="invoices">发票及其明细</param>
|
|
|
|
|
|
|
|
/// <param name="deleteOption">发票删除选项</param>
|
|
|
|
|
|
|
|
protected virtual Task PostDeleteAsync(List<TEntity> invoices, DeleteOption deleteOption) => Task.CompletedTask;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 生成发票明细
|
|
|
|
/// 生成发票明细
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -591,4 +690,5 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
return rows > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
|
|
|
|
return rows > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|