Commit c008a2fd by 陶然

新增发票修改接口

parent 2330aac9
......@@ -61,17 +61,18 @@ namespace Kivii.Finances.Entities
#endregion
#region 收付双方 Payer付款单位,贷方 Payee收款单位,借方 全禁止更新
[IgnoreUpdate]
[InternalSetter]
[DefaultEmptyGuid]
public Guid PayerKvid { get; set; }
[ApiMember(Description = "付款单位,贷方")]
[IgnoreUpdate]
[InternalSetter]
[StringLength(100), Required]
public string PayerName { get; set; }
[ApiMember(Description ="付方税号,收票方税号")]
[IgnoreUpdate]
[InternalSetter]
[StringLength(100)]
public string PayerTaxNumber { get; set; }
......@@ -84,46 +85,46 @@ namespace Kivii.Finances.Entities
public string PayerPhone { get; set; }
[ApiMember(Description = "付款账户名称,指开户银行")]
[IgnoreUpdate]
[InternalSetter]
[StringLength(200), Default("")]
public string PayerRegisteredBank { get; set; }
[ApiMember(Description = "付款账户卡号")]
[IgnoreUpdate]
[InternalSetter]
[StringLength(100), Default("")]
public string PayerBankAccount { get; set; }
[IgnoreUpdate]
[InternalSetter]
[DefaultEmptyGuid]
public Guid PayeeKvid { get; set; }
[ApiMember(Description = "收款单位,借方")]
[IgnoreUpdate]
[InternalSetter]
[StringLength(100), Required]
public string PayeeName { get; set; }
[ApiMember(Description = "收方税号,开票方税号")]
[IgnoreUpdate]
[InternalSetter]
[StringLength(100), Required]
public string PayeeTaxNumber { get; set; }
[ApiMember(Description = "公司地址")]
[IgnoreUpdate]
[InternalSetter]
[StringLength(200), Default("")]
public string PayeeCompanyAddress { get; set; }
[ApiMember(Description = "电话号码")]
[IgnoreUpdate]
[InternalSetter]
[StringLength(50), Default("")]
public string PayeePhone { get; set; }
[ApiMember(Description = "收款账户名称,指开户银行")]
[IgnoreUpdate]
[InternalSetter]
[StringLength(200), Default("")]
public string PayeeRegisteredBank { get; set; }
[ApiMember(Description = "收款账户卡号")]
[IgnoreUpdate]
[InternalSetter]
[StringLength(100), Default("")]
public string PayeeBankAccount { get; set; }
#endregion
......@@ -161,7 +162,7 @@ namespace Kivii.Finances.Entities
public decimal AmountPayment { get; set; }
[ApiMember(Description = "含税金额,合同或订单中使用的金额")]
[IgnoreUpdate]
[InternalSetter]
[DecimalLength(15, 2), Default(0)]
public decimal Amount { get; set; }
......@@ -198,7 +199,7 @@ namespace Kivii.Finances.Entities
#region 文本 摘要 备注
[ApiMember(Description = "摘要,最大500字")]
[IgnoreUpdate]
[InternalSetter]
[StringLength(500), Default("")]
public string Summary { get; set; }
......@@ -210,7 +211,7 @@ namespace Kivii.Finances.Entities
#region 操作相关 Organization Creator Updater Operator OperateTime 全禁止更新
[ApiMember(Description = "操作日期")]
[IgnoreUpdate]
[InternalSetter]
[Required]
public DateTime OperateTime { get; set; }
......
......@@ -94,6 +94,74 @@ namespace Kivii.Finances.Transforms
}
[Api(Description = "发票更新")]
[RequiresAnyRole(SystemRoles.Everyone)]
public class InvoiceUpdateEx : RestfulExecution<Invoice>
{
public Invoice Item { get; set; }
public override object OnExecution(IRequest req, IResponse res)
{
Item.ThrowIfNull("请传入要更新的信息!");
Item.Kvid.ThrowIfEmpty("缺少更新Kvid!");
Item.RemoveOnlyProperties(o => o.AmountPayment);
Item.RemoveOnlyProperties(o => o.RootKvid);
Item.RemoveOnlyProperties(o => o.AmountUntaxed);
Item.RemoveOnlyProperties(o => o.AmountTax);
var rtns = new RestfulUpdateResponse<Invoice>();
rtns.Results = new List<Invoice>();
if (Item.GetOnlyProperties().IsNullOrEmpty()) return rtns;
var conn = KiviiContext.GetOpenedDbConnection<Invoice>();
var exist = conn.SingleById<Invoice>(Item.Kvid);
exist.ThrowIfNull("未找到要更新的发票信息!");
if (exist.Type.ToLower() == "relation") throw new Exception("不支持的数据类型,无法更新!");
if (Item.OffsetKvid != Guid.Empty) throw new Exception("无法更新已作废发票!");
if (Item.Amount == exist.Amount) Item.RemoveOnlyProperties(o => o.Amount);
if (Item.OnlyPropertiesIsExist(o => o.Amount))
{
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.AddOnlyProperties(o => o.AmountUntaxed);
Item.AmountTax = Item.Amount - Item.AmountUntaxed;
Item.AddOnlyProperties(o => o.AmountTax);
var detail = new InvoiceDetail();
if (!details.IsNullOrEmpty()) detail.PopulateInstance(details[0]);
else detail.GoodsFullName = "检测费";
detail.Kvid = Guid.NewGuid();
detail.InvoiceKvid = exist.Kvid;
detail.TaxRate = exist.TaxRate;
detail.Amount = Item.Amount;
detail.AmountUntaxed = Item.AmountUntaxed;
detail.AmountTax = Item.AmountTax;
detail.QuantityUnitPrice = Math.Round(detail.Amount / detail.Quantity, 2);
detail.QuantityUnitPriceUntaxed = Math.Round(detail.AmountUntaxed / detail.Quantity, 2);
detail.Remark = "手改修改发票金额,生成记录";
var trans = conn.OpenTransaction();
try
{
conn.UpdateOnly(Item);
conn.Insert(detail);
var updateDetails = conn.From<InvoiceDetail>();
updateDetails = updateDetails.Update(o => o.Status);
updateDetails = updateDetails.Where(o => Sql.In(o.Kvid, details.ConvertAll(p => p.Kvid)));
conn.UpdateOnly<InvoiceDetail>(new InvoiceDetail { Status = -1 }, updateDetails);
trans.Commit();
}
catch (Exception ex)
{
trans.Rollback();
throw ex;
}
}
else conn.UpdateOnly(Item);
rtns.Results.Add(Item);
return rtns;
}
}
[RequiresAnyRole(SystemRoles.Everyone)]
public class InvoiceRead : RestfulRead<Invoice>
{
......@@ -239,6 +307,7 @@ namespace Kivii.Finances.Transforms
detail.AmountUntaxed = invoice.AmountUntaxed;
detail.Amount = invoice.Amount;
detail.AmountTax = invoice.AmountTax;
detail.QuantityUnitPrice = Math.Round(detail.Amount / detail.Quantity, 2);
detail.QuantityUnitPriceUntaxed = Math.Round(detail.AmountUntaxed / detail.Quantity, 2);
insertInvoiceDetails.Add(detail);
}
......
......@@ -652,6 +652,7 @@ namespace Kivii.Finances.Transforms
detail.AmountUntaxed = invoice.AmountUntaxed;
detail.Amount = invoice.Amount;
detail.AmountTax = invoice.AmountTax;
detail.QuantityUnitPrice = Math.Round(detail.Amount / detail.Quantity, 2);
detail.QuantityUnitPriceUntaxed = Math.Round(detail.AmountUntaxed / detail.Quantity, 2);
insertInvoiceDetails.Add(detail);
}
......
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