|
|
@ -5,6 +5,7 @@ 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.Interface;
|
|
|
|
using DS.WMS.Core.Application.Interface;
|
|
|
|
|
|
|
|
using DS.WMS.Core.Code.Entity;
|
|
|
|
using DS.WMS.Core.Fee.Dtos;
|
|
|
|
using DS.WMS.Core.Fee.Dtos;
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
using DS.WMS.Core.Info.Entity;
|
|
|
|
using DS.WMS.Core.Info.Entity;
|
|
|
@ -511,7 +512,7 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
await TenantDb.Deleteable<InvoiceDetail>().Where(x => x.ApplicationId == application.Id).ExecuteCommandAsync();
|
|
|
|
await TenantDb.Deleteable<InvoiceDetail>().Where(x => x.ApplicationId == application.Id).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
|
|
//然后根据申请单明细重新生成
|
|
|
|
//然后根据申请单明细重新生成
|
|
|
|
await CreateInvoiceDetailsAsync([application]);
|
|
|
|
await FillInvoiceDetailsAsync([application]);
|
|
|
|
|
|
|
|
|
|
|
|
if (application.InvoiceDetails?.Count > 0)
|
|
|
|
if (application.InvoiceDetails?.Count > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -528,8 +529,8 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
await base.OnSaveAsync(application, fees);
|
|
|
|
await base.OnSaveAsync(application, fees);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//生成发票明细
|
|
|
|
//根据费用明细填充发票明细
|
|
|
|
async Task CreateInvoiceDetailsAsync(IEnumerable<InvoiceApplication> applications)
|
|
|
|
async Task FillInvoiceDetailsAsync(IEnumerable<InvoiceApplication> applications)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreach (var application in applications)
|
|
|
|
foreach (var application in applications)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -539,7 +540,8 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
if (application.Details.Count > 0 && (application.InvoiceDetails == null || application.InvoiceDetails.Count == 0))
|
|
|
|
if (application.Details.Count > 0 && (application.InvoiceDetails == null || application.InvoiceDetails.Count == 0))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var ids = application.Details.Select(x => x.RecordId).ToList();
|
|
|
|
var ids = application.Details.Select(x => x.RecordId).ToList();
|
|
|
|
var feesCodes = await TenantDb.Queryable<FeeRecord>().InnerJoin<FeeCode>((f, c) => f.FeeId == c.Id && ids.Contains(f.Id))
|
|
|
|
var feesCodes = await TenantDb.Queryable<FeeRecord>()
|
|
|
|
|
|
|
|
.InnerJoin<FeeCode>((f, c) => f.FeeId == c.Id && ids.Contains(f.Id))
|
|
|
|
.Select((f, c) => new
|
|
|
|
.Select((f, c) => new
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FeeId = c.Id,
|
|
|
|
FeeId = c.Id,
|
|
|
@ -551,10 +553,24 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
Name = x.Key,
|
|
|
|
Name = x.Key,
|
|
|
|
FeeIds = x.Select(y => y.FeeId)
|
|
|
|
FeeIds = x.Select(y => y.FeeId)
|
|
|
|
}).ToList();
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var goodsNames = list.Select(x => x.Name);
|
|
|
|
|
|
|
|
var invCodes = await TenantDb.Queryable<CodeInvoice>().Where(x => goodsNames.Contains(x.Name))
|
|
|
|
|
|
|
|
.Select(x => new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
x.Id,
|
|
|
|
|
|
|
|
x.Name,
|
|
|
|
|
|
|
|
x.DefaultCurrency,
|
|
|
|
|
|
|
|
x.TaxRate,
|
|
|
|
|
|
|
|
x.Specification,
|
|
|
|
|
|
|
|
x.Unit
|
|
|
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
application.InvoiceDetails = new List<InvoiceDetail>(list.Count);
|
|
|
|
application.InvoiceDetails = new List<InvoiceDetail>(list.Count);
|
|
|
|
foreach (var item in list)
|
|
|
|
foreach (var item in list)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var invDetail = new InvoiceDetail
|
|
|
|
var invCode = invCodes.Find(x => x.Name == item.Name);
|
|
|
|
|
|
|
|
var detail = new InvoiceDetail
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ApplicationId = application.Id,
|
|
|
|
ApplicationId = application.Id,
|
|
|
|
Name = item.Name,
|
|
|
|
Name = item.Name,
|
|
|
@ -563,10 +579,18 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
TaxUnitPrice = application.Details.FindAll(x => item.FeeIds.Contains(x.FeeId)).Sum(x => x.ApplyAmount),
|
|
|
|
TaxUnitPrice = application.Details.FindAll(x => item.FeeIds.Contains(x.FeeId)).Sum(x => x.ApplyAmount),
|
|
|
|
Category = DetailCategory.InvoiceApplication
|
|
|
|
Category = DetailCategory.InvoiceApplication
|
|
|
|
};
|
|
|
|
};
|
|
|
|
invDetail.TaxAmount = invDetail.TaxUnitPrice * application.TaxRate;
|
|
|
|
|
|
|
|
invDetail.UnitPrice = invDetail.TaxUnitPrice - invDetail.TaxAmount;
|
|
|
|
if (invCode != null)
|
|
|
|
invDetail.Amount = invDetail.TaxUnitPrice * invDetail.Quantity;
|
|
|
|
{
|
|
|
|
application.InvoiceDetails.Add(invDetail);
|
|
|
|
detail.TaxRate = invCode.TaxRate;
|
|
|
|
|
|
|
|
detail.Specification = invCode.Specification;
|
|
|
|
|
|
|
|
detail.Unit = invCode.Unit;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
detail.TaxAmount = detail.TaxUnitPrice * application.TaxRate;
|
|
|
|
|
|
|
|
detail.UnitPrice = detail.TaxUnitPrice - detail.TaxAmount;
|
|
|
|
|
|
|
|
detail.Amount = detail.TaxUnitPrice * detail.Quantity;
|
|
|
|
|
|
|
|
application.InvoiceDetails.Add(detail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -615,7 +639,7 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
|
|
|
|
|
|
|
|
await TenantDb.Deleteable<InvoiceDetail>().Where(x => appIds.Contains(x.ApplicationId)).ExecuteCommandAsync();
|
|
|
|
await TenantDb.Deleteable<InvoiceDetail>().Where(x => appIds.Contains(x.ApplicationId)).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
|
|
await CreateInvoiceDetailsAsync(applications);
|
|
|
|
await FillInvoiceDetailsAsync(applications);
|
|
|
|
var invDetails = applications.SelectMany(x => x.InvoiceDetails).ToList();
|
|
|
|
var invDetails = applications.SelectMany(x => x.InvoiceDetails).ToList();
|
|
|
|
if (invDetails.Count > 0)
|
|
|
|
if (invDetails.Count > 0)
|
|
|
|
await TenantDb.Insertable(invDetails).ExecuteCommandAsync();
|
|
|
|
await TenantDb.Insertable(invDetails).ExecuteCommandAsync();
|
|
|
|