|
|
|
@ -49,12 +49,14 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
InvoiceDate = i.InvoiceDate,
|
|
|
|
|
CustomerId = i.CustomerId,
|
|
|
|
|
CustomerName = i.CustomerName,
|
|
|
|
|
Type = i.Type,
|
|
|
|
|
Type = i.Mode,
|
|
|
|
|
Category = i.Category,
|
|
|
|
|
InvoiceHeader = i.InvoiceHeader,
|
|
|
|
|
TaxID = i.TaxID,
|
|
|
|
|
CustomerAddTel = i.CustomerAddTel,
|
|
|
|
|
CustomerBank = i.CustomerBank,
|
|
|
|
|
CustomerAddress = i.CustomerAddress,
|
|
|
|
|
CustomerBankName = i.CustomerBankName,
|
|
|
|
|
CustomerPhone = i.CustomerPhone,
|
|
|
|
|
CustomerAccount = i.CustomerAccount,
|
|
|
|
|
AutualCustomerName = i.AutualCustomerName,
|
|
|
|
|
Currency = i.Currency,
|
|
|
|
|
ReceiptCurrency = i.ReceiptCurrency,
|
|
|
|
@ -185,7 +187,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
IsLocked = x.IsLocked,
|
|
|
|
|
Type = x.Type,
|
|
|
|
|
Mode = x.Mode,
|
|
|
|
|
}).FirstAsync(x => x.Id == request.Invoice.Id);
|
|
|
|
|
}
|
|
|
|
|
var result = EnsureSettlement(request.Invoice, dbValue);
|
|
|
|
@ -335,15 +337,18 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
{
|
|
|
|
|
x.InvoiceNO,
|
|
|
|
|
x.InvoiceDate,
|
|
|
|
|
x.Account,
|
|
|
|
|
x.BankName,
|
|
|
|
|
//x.Currency,
|
|
|
|
|
x.ReceiptCurrency,
|
|
|
|
|
x.CustomerId,
|
|
|
|
|
x.CustomerName,
|
|
|
|
|
x.AutualCustomerName,
|
|
|
|
|
x.InvoiceHeader,
|
|
|
|
|
x.Account,
|
|
|
|
|
x.CustomerAddTel,
|
|
|
|
|
x.CustomerBank,
|
|
|
|
|
x.CustomerAddress,
|
|
|
|
|
x.CustomerPhone,
|
|
|
|
|
x.CustomerBankName,
|
|
|
|
|
x.CustomerAccount,
|
|
|
|
|
x.OperatorId,
|
|
|
|
|
x.TaxID,
|
|
|
|
|
x.TaxRate,
|
|
|
|
@ -370,7 +375,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
var updateable = TenantDb.Updateable(fees).PublicSetColumns(x => x.InvoiceAmount, "+");
|
|
|
|
|
if (invoice.Type == InvoiceType.Applcation)
|
|
|
|
|
if (invoice.Mode == InvoiceMode.Applcation)
|
|
|
|
|
updateable = updateable.PublicSetColumns(x => x.OrderInvSettlementAmount, "+")
|
|
|
|
|
.UpdateColumns(x => new { x.OrderInvSettlementAmount });
|
|
|
|
|
|
|
|
|
@ -430,12 +435,13 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
ApplicationId = invoice.Id,
|
|
|
|
|
Name = g.Key,
|
|
|
|
|
TaxRate = invoice.TaxRate,
|
|
|
|
|
Quantity = 1,
|
|
|
|
|
TaxUnitPrice = invoice.Details.FindAll(x => g.Select(x => x.DetailId).Contains(x.Id)).Sum(x => x.ApplyAmount),
|
|
|
|
|
Category = DetailCategory.InvoiceIssuance
|
|
|
|
|
};
|
|
|
|
|
invDetail.TaxAmount = invDetail.TaxUnitPrice * invoice.TaxRate;
|
|
|
|
|
invDetail.UnitPrice = invDetail.TaxUnitPrice - invDetail.TaxAmount;
|
|
|
|
|
|
|
|
|
|
invDetail.Amount = invDetail.TaxUnitPrice * invDetail.Quantity;
|
|
|
|
|
invoice.InvoiceDetails.Add(invDetail);
|
|
|
|
|
|
|
|
|
|
foreach (var item in g)
|
|
|
|
@ -487,13 +493,14 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
Id = SnowFlakeSingle.Instance.NextId(),
|
|
|
|
|
ApplicationId = invoice.Id,
|
|
|
|
|
Name = goodsName,
|
|
|
|
|
Quantity = 1,
|
|
|
|
|
TaxRate = invoice.TaxRate,
|
|
|
|
|
TaxUnitPrice = detail.ApplyAmount,
|
|
|
|
|
Category = DetailCategory.InvoiceIssuance
|
|
|
|
|
};
|
|
|
|
|
invDetail.TaxAmount = invDetail.TaxUnitPrice * invoice.TaxRate;
|
|
|
|
|
invDetail.UnitPrice = invDetail.TaxUnitPrice - invDetail.TaxAmount;
|
|
|
|
|
|
|
|
|
|
invDetail.Amount = invDetail.TaxUnitPrice * invDetail.Quantity;
|
|
|
|
|
invoice.InvoiceDetails.Add(invDetail);
|
|
|
|
|
|
|
|
|
|
relationList.Add(new ApplicationDetailRelation
|
|
|
|
@ -566,7 +573,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
var details = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.ApplicationId))
|
|
|
|
|
.Select(x => new { x.ApplicationId, x.Currency, x.ApplyAmount, x.OriginalAmount }).ToListAsync();
|
|
|
|
|
var invDetails = await TenantDb.Queryable<InvoiceDetail>().Where(x => ids.Contains(x.ApplicationId))
|
|
|
|
|
.Select(x => new { x.ApplicationId, x.TaxUnitPrice }).ToListAsync();
|
|
|
|
|
.Select(x => new { x.ApplicationId, x.Amount }).ToListAsync();
|
|
|
|
|
|
|
|
|
|
foreach (var invoice in invoices)
|
|
|
|
|
{
|
|
|
|
@ -577,7 +584,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
invoice.OriginalAmount = currDetails.Sum(x => x.OriginalAmount);
|
|
|
|
|
invoice.OtherInvoiceAmount = currDetails.FindAll(x => x.Currency != RMB_CODE).Sum(x => x.OriginalAmount);
|
|
|
|
|
|
|
|
|
|
invoice.InvoiceAmount = invDetails.FindAll(x => x.ApplicationId == invoice.Id).Sum(x => x.TaxUnitPrice);
|
|
|
|
|
invoice.InvoiceAmount = invDetails.FindAll(x => x.ApplicationId == invoice.Id).Sum(x => x.Amount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await TenantDb.Updateable(invoices).UpdateColumns(x => new
|
|
|
|
@ -638,7 +645,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
var apps = await TenantDb.Queryable<TEntity>().Where(x => ids.Contains(x.Id)).Select(x => new TEntity
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
Type = x.Type,
|
|
|
|
|
Mode = x.Mode,
|
|
|
|
|
IsLocked = x.IsLocked
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
@ -709,7 +716,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
var invoices = await TenantDb.Queryable<TEntity>().Where(x => invIds.Contains(x.Id)).Select(x => new TEntity
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
Type = x.Type,
|
|
|
|
|
Mode = x.Mode,
|
|
|
|
|
IsLocked = x.IsLocked
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
@ -749,11 +756,11 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var invDetails = await TenantDb.Queryable<InvoiceDetail>().Where(x => ids.Contains(x.Id))
|
|
|
|
|
.Select(x => new { x.ApplicationId, x.TaxUnitPrice }).ToListAsync();
|
|
|
|
|
.Select(x => new { x.ApplicationId, x.Amount }).ToListAsync();
|
|
|
|
|
var groups = invDetails.GroupBy(x => x.ApplicationId);
|
|
|
|
|
foreach (var g in groups)
|
|
|
|
|
{
|
|
|
|
|
var list = g.Select(x => new TEntity { Id = g.Key, InvoiceAmount = g.Sum(x => x.TaxUnitPrice) }).ToList();
|
|
|
|
|
var list = g.Select(x => new TEntity { Id = g.Key, InvoiceAmount = g.Sum(x => x.Amount) }).ToList();
|
|
|
|
|
//更新发票主表的开票金额
|
|
|
|
|
await TenantDb.Updateable(list).PublicSetColumns(x => x.InvoiceAmount, "-")
|
|
|
|
|
.UpdateColumns(x => new { x.InvoiceAmount }).ExecuteCommandAsync();
|
|
|
|
@ -828,7 +835,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
//删除明细之间的关系
|
|
|
|
|
|
|
|
|
|
await TenantDb.Deleteable<ApplicationDetailRelation>().Where(x => excludeIds.Contains(x.DetailId)).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else if (deleteOption == DeleteOption.Entire)
|
|
|
|
|
{
|
|
|
|
@ -846,7 +853,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
|
|
|
|
|
var updateable = TenantDb.Updateable(fees).PublicSetColumns(x => x.InvoiceAmount, "-");
|
|
|
|
|
|
|
|
|
|
if (item.Type == InvoiceType.Applcation)
|
|
|
|
|
if (item.Mode == InvoiceMode.Applcation)
|
|
|
|
|
updateable = updateable.PublicSetColumns(x => x.OrderInvSettlementAmount, "-")
|
|
|
|
|
.UpdateColumns(x => new { x.OrderInvSettlementAmount });
|
|
|
|
|
|
|
|
|
|