Commit 44603696 by 陶然

升级发票更新接口 支持更新税率

parent 4f50c4a3
......@@ -152,7 +152,7 @@ namespace Kivii.Finances.Entities
#region 金额和税
[ApiMember(Description = "发票税率")]
[IgnoreUpdate]
[InternalSetter]
[DecimalLength(5, 4), Default(0)]
public decimal TaxRate { get; set; }
......
......@@ -67,7 +67,7 @@ namespace Kivii.Finances.Entities
public decimal QuantityUnitPriceUntaxed { get; set; }
[ApiMember(Description = "税率")]
[IgnoreUpdate,InternalSetter]
[InternalSetter]
[DecimalLength(5, 2), Required]
public decimal TaxRate { get; set; }
......
......@@ -121,7 +121,7 @@ namespace Kivii.Finances.Transforms
if (Item.Amount <= 0) throw new Exception("发票金额不能小于等于0!");
var details = conn.Select<InvoiceDetail>(o => o.InvoiceKvid == Item.Kvid);
if (exist.AmountPayment > 0) throw new Exception("无法更新发票金额!");
Item.AmountUntaxed = Math.Round(Item.Amount / (1 + exist.TaxRate), 2);
Item.AmountUntaxed = Math.Round(Item.Amount / (1 + Item.TaxRate), 2);
Item.AddOnlyProperties(o => o.AmountUntaxed);
Item.AmountTax = Item.Amount - Item.AmountUntaxed;
Item.AddOnlyProperties(o => o.AmountTax);
......@@ -131,7 +131,7 @@ namespace Kivii.Finances.Transforms
else detail.GoodsFullName = "检测费";
detail.Kvid = Guid.NewGuid();
detail.InvoiceKvid = exist.Kvid;
detail.TaxRate = exist.TaxRate;
detail.TaxRate = Item.TaxRate;
detail.Amount = Item.Amount;
detail.AmountUntaxed = Item.AmountUntaxed;
detail.AmountTax = Item.AmountTax;
......@@ -156,6 +156,43 @@ namespace Kivii.Finances.Transforms
throw ex;
}
}
else if (Item.OnlyPropertiesIsExist(o => o.TaxRate))
{
(Item.TaxRate < 0 || Item.TaxRate > 1).ThrowIfTrue("发票税率取值不合法!");
var details = conn.Select<InvoiceDetail>(o => o.InvoiceKvid == Item.Kvid);
Item.AmountUntaxed = Math.Round(exist.Amount / (1 + Item.TaxRate), 2);
Item.AddOnlyProperties(o => o.AmountUntaxed);
Item.AmountTax = exist.Amount - Item.AmountUntaxed;
Item.AddOnlyProperties(o => o.AmountTax);
foreach (var detail in details)
{
detail.TaxRate = Item.TaxRate;
detail.AddOnlyProperties(o => o.TaxRate);
detail.AmountUntaxed = Math.Round(detail.Amount / (1 + detail.TaxRate), 2);
detail.AddOnlyProperties(o => o.AmountUntaxed);
detail.AmountTax = detail.Amount - detail.AmountUntaxed;
detail.AddOnlyProperties(o => o.AmountTax);
detail.QuantityUnitPriceUntaxed = Math.Round(detail.AmountUntaxed / detail.Quantity, 2);
detail.AddOnlyProperties(o => o.QuantityUnitPriceUntaxed);
}
var trans = conn.OpenTransaction();
try
{
conn.UpdateOnly(Item);
foreach (var item in details)
{
conn.UpdateOnly(item);
}
trans.Commit();
}
catch (Exception ex)
{
trans.Rollback();
throw ex;
}
}
else conn.UpdateOnly(Item);
rtns.Results.Add(Item);
return rtns;
......
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