Commit 6cfc2f2c by 陶然

修复发票删除bug

parent aa31e884
......@@ -30,8 +30,8 @@ namespace Kivii.Finances
offsetInvoice.BizKvid = Guid.Empty;
offsetInvoice.BizType = string.Empty;
offsetInvoice.Kvid = newInvoiceKvid;
offsetInvoice.RootKvid = newInvoiceKvid;
offsetInvoice.ParentKvid = Guid.Empty;
//offsetInvoice.RootKvid = newInvoiceKvid;
//offsetInvoice.ParentKvid = Guid.Empty;
offsetInvoice.SerialNumber = invoice.SerialNumber.IsNullOrEmpty() ? "" : ("-" + invoice.SerialNumber);
offsetInvoice.Remark = $"{remark}";
offsetInvoice.Amount = 0 - offsetInvoice.Amount;//反向值
......
......@@ -208,10 +208,12 @@ namespace Kivii.Finances.Transforms
var invoices = conn.SelectByIds<Invoice>(Kvids);
if (invoices.IsNullOrEmpty()) throw new Exception("未找到所选发票信息!");
if (invoices.Exists(o => o.OffsetKvid == Guid.Empty)) throw new Exception("存在未作废的发票,请先作废后再删除!");
var relationInvoices = conn.Select<Invoice>(o => Sql.In(o.ParentKvid, invoices.ConvertAll(p => p.Kvid)) && o.Type == "Relation");
var offsets = conn.SelectByIds<Invoice>(invoices.ConvertAll(p => p.OffsetKvid));
var deletes = new List<Guid>();
if (!offsets.IsNullOrEmpty())
if (!invoices.IsNullOrEmpty())
{
foreach (var item in invoices)
{
......@@ -225,6 +227,13 @@ namespace Kivii.Finances.Transforms
deletes.AddIfNotExists(item.Kvid);
}
}
if (!relationInvoices.IsNullOrEmpty())
{
foreach (var item in relationInvoices)
{
deletes.AddIfNotExists(item.Kvid);
}
}
var rtns = new RestfulDeleteResponse<Guid>();
rtns.Results = new List<Guid>();
......@@ -233,7 +242,7 @@ namespace Kivii.Finances.Transforms
{
foreach (var kvid in deletes)
{
conn.DeleteById<Invoice>(kvid);
conn.Delete<Invoice>(o => o.Kvid == kvid);
rtns.Results.Add(kvid);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment