|
|
|
@ -186,9 +186,6 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
IsLocked = x.IsLocked,
|
|
|
|
|
Type = x.Type,
|
|
|
|
|
}).FirstAsync(x => x.Id == request.Invoice.Id);
|
|
|
|
|
|
|
|
|
|
if (dbValue != null && dbValue.IsLocked)
|
|
|
|
|
return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.InvoiceIsLocked));
|
|
|
|
|
}
|
|
|
|
|
var result = EnsureSettlement(request.Invoice, dbValue);
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
@ -261,7 +258,6 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
invoice.Details.Add(detail);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//自由申请
|
|
|
|
|
if (request.Details?.Count > 0)
|
|
|
|
|
{
|
|
|
|
@ -292,6 +288,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (invoice.Details?.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
//金额禁止为0
|
|
|
|
@ -334,22 +331,14 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
if (invoice.Details?.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
await TenantDb.Insertable(invoice.Details).ExecuteCommandAsync();
|
|
|
|
|
//因需要重新生成明细,所以要先清空现有发票明细
|
|
|
|
|
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.InvoiceDetails).IgnoreColumns(x => new { x.Category }).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await TenantDb.Updateable(invoice).IgnoreColumns(x => new
|
|
|
|
@ -378,7 +367,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
.UpdateColumns(x => new { x.InvoiceAmount })
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
await CreateInvoiceDetailsAsync([invoice]);
|
|
|
|
|
await BuildInvoiceDetailAsync([invoice]);
|
|
|
|
|
if (invoice.InvoiceDetails?.Count > 0)
|
|
|
|
|
await TenantDb.Insertable(invoice.InvoiceDetails).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
@ -404,7 +393,13 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
/// <param name="invoice">提交的发票</param>
|
|
|
|
|
/// <param name="dbValue">数据库值,新增时为null</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected virtual DataResult EnsureSettlement(TEntity invoice, TEntity? dbValue) => DataResult.Success;
|
|
|
|
|
protected virtual DataResult EnsureSettlement(TEntity invoice, TEntity? dbValue)
|
|
|
|
|
{
|
|
|
|
|
if (dbValue != null && dbValue.IsLocked)
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.InvoiceIsLocked));
|
|
|
|
|
|
|
|
|
|
return DataResult.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 在保存前调用
|
|
|
|
@ -527,6 +522,17 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除发票明细
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids">发票明细ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> DeleteInvoiceDetailAsync(params long[] ids)
|
|
|
|
|
{
|
|
|
|
|
int rows = await TenantDb.Deleteable<InvoiceDetail>().Where(x => ids.Contains(x.Id)).ExecuteCommandAsync();
|
|
|
|
|
return rows > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 在删除发票或其明细之前调用,用于检查状态
|
|
|
|
|
/// </summary>
|
|
|
|
@ -549,12 +555,11 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
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();
|
|
|
|
|
//await TenantDb.Deleteable<InvoiceDetail>().Where(x => excludeIds.Contains(x.Id)).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
if (deleteOption == DeleteOption.DetailOnly)
|
|
|
|
|
{
|
|
|
|
|
var appIds = invoices.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
|
|
|
|
|
{
|
|
|
|
@ -572,10 +577,11 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
item.AmountUppercase = new Money(item.ApplyAmount).ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await CreateInvoiceDetailsAsync(invoices);
|
|
|
|
|
var invDetails = invoices.SelectMany(x => x.InvoiceDetails).ToList();
|
|
|
|
|
if (invDetails.Count > 0)
|
|
|
|
|
await TenantDb.Insertable(invDetails).ExecuteCommandAsync();
|
|
|
|
|
////删除明细需要同时变更发票明细
|
|
|
|
|
//await CreateInvoiceDetailsAsync(invoices);
|
|
|
|
|
//var invDetails = invoices.SelectMany(x => x.InvoiceDetails).ToList();
|
|
|
|
|
//if (invDetails.Count > 0)
|
|
|
|
|
// await TenantDb.Insertable(invDetails).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
await TenantDb.Updateable(invoices).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
@ -603,7 +609,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="invoices"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected async Task CreateInvoiceDetailsAsync(IEnumerable<TEntity> invoices)
|
|
|
|
|
protected async Task BuildInvoiceDetailAsync(IEnumerable<TEntity> invoices)
|
|
|
|
|
{
|
|
|
|
|
foreach (var invoice in invoices)
|
|
|
|
|
{
|
|
|
|
|