Commit c571c933 by 陶然

优化Payment数据结构,增加开票日期和核算日期

parent 2653c880
......@@ -181,6 +181,12 @@ namespace Kivii.Finances.Entities
[Required]
public DateTime OperateTime { get; set; }
[ApiMember(Description = "开票日期,多张发票时取最大日期")]
public DateTime? InvoiceTime { get; set; }
[ApiMember(Description = "审核日期,从到账日期和开票日期中取最大值")]
public DateTime? AuditTime { get; set; }
[IgnoreUpdate]
[DefaultEmptyGuid]
public Guid OperatorKvid { get; set; }
......
......@@ -85,6 +85,35 @@ namespace Kivii.Finances
#endregion
payment.AmountInvoice += amount;
if (payment.InvoiceTime == null)
{
payment.InvoiceTime = invoice.OperateTime;
payment.AddOnlyProperties(o => o.InvoiceTime);
}
else
{
if (payment.InvoiceTime.Value < invoice.OperateTime)
{
payment.InvoiceTime = invoice.OperateTime;
payment.AddOnlyProperties(o => o.InvoiceTime);
}
}
}
if (payment.InvoiceTime != null)
{
if (payment.AuditTime == null)
{
payment.AuditTime = payment.InvoiceTime;
payment.AddOnlyProperties(o => o.AuditTime);
}
else
{
if (payment.AuditTime.Value < payment.InvoiceTime.Value)
{
payment.AuditTime = payment.InvoiceTime;
payment.AddOnlyProperties(o => o.AuditTime);
}
}
}
payment.AddOnlyProperties(o => o.AmountInvoice);
}
......
......@@ -325,6 +325,7 @@ namespace Kivii.Finances
if (conn == null) conn = KiviiContext.GetOpenedDbConnection<Payment>();
var amountInvoiced = conn.Scalar<Payment, decimal>(o => Sql.Sum(o.AmountInvoice), p => Sql.In(p.Type, PaymentType.Assign, PaymentType.Split) && p.ParentKvid == payment.Kvid && p.OffsetKvid == Guid.Empty);
var invoiceTime = conn.Scalar<Payment, DateTime?>(o => Sql.Max(o.InvoiceTime), p => Sql.In(p.Type, PaymentType.Assign, PaymentType.Split) && p.ParentKvid == payment.Kvid && p.OffsetKvid == Guid.Empty);
Payment parentPayment = null;
if (payment.ParentKvid != Guid.Empty) parentPayment = conn.SingleById<Payment>(payment.ParentKvid);
......@@ -334,6 +335,24 @@ namespace Kivii.Finances
{
payment.AmountInvoice = amountInvoiced;
payment.AddOnlyProperties(o => o.AmountInvoice);
if (invoiceTime != null)
{
payment.InvoiceTime = invoiceTime;
payment.AddOnlyProperties(o => o.InvoiceTime);
if (payment.AuditTime == null)
{
payment.AuditTime = invoiceTime;
payment.AddOnlyProperties(o => o.AuditTime);
}
else
{
if (payment.AuditTime.Value < invoiceTime.Value)
{
payment.AuditTime = invoiceTime;
payment.AddOnlyProperties(o => o.AuditTime);
}
}
}
conn.UpdateOnly(payment);
if (parentPayment != null) parentPayment.RecalculateAmountInvoice(conn);
trans?.Commit();
......@@ -697,10 +716,15 @@ namespace Kivii.Finances
splitPayment.Category = category;
//金额设置
splitPayment.AuditorName = splitPayment.OperateTime.Year.ToString();
splitPayment.AuditTime = payment.OperateTime;
splitPayment.Amount = amountSplit;
splitPayment.AmountSplited = 0;
splitPayment.AmountUsed = 0;
splitPayment.AmountInvoice = amountInvoice;// payment.AmountInvoice > amountSplit ? amountSplit : payment.AmountInvoice;
if (amountInvoice <= 0)
{
splitPayment.InvoiceTime = null;
}
//splitPayment.Summary = string.Empty;
if (!remark.IsNullOrEmpty()) splitPayment.Remark += $"[认领备注: {remark}]";
splitPayment.OperateTime = payment.OperateTime;
......@@ -777,10 +801,15 @@ namespace Kivii.Finances
splitPayment.Type = paymentType;
//金额设置
splitPayment.AuditorName = splitPayment.OperateTime.Year.ToString();
splitPayment.AuditTime = payment.OperateTime;
splitPayment.Amount = amountSplit;
splitPayment.AmountSplited = 0;
splitPayment.AmountUsed = 0;
splitPayment.AmountInvoice = amountInvoice;
if (amountInvoice <= 0)
{
splitPayment.InvoiceTime = null;
}
splitPayment.Summary = string.Empty;
splitPayment.Remark = remark;
splitPayment.OperateTime = payment.OperateTime;
......
......@@ -33,5 +33,5 @@ using System.Runtime.InteropServices;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.4.2023.12290")]
[assembly: AssemblyFileVersion("5.4.2023.12290")]
[assembly: AssemblyVersion("5.4.2024.1060")]
[assembly: AssemblyFileVersion("5.4.2024.1060")]
......@@ -167,6 +167,11 @@ namespace Kivii.Finances.Transforms
item.AmountInvoice -= relations.Sum(o => o.Amount);
if (item.AmountInvoice < 0) item.AmountInvoice = 0;
item.AddOnlyProperties(o => o.AmountInvoice);
if (item.AmountInvoice <= 0)
{
item.InvoiceTime = null;
item.AddOnlyProperties(o => o.InvoiceTime);
}
}
if (!splitPayments.IsNullOrEmpty())//要是所选Payment存在拆分项,满足条件就要更新AmountInvoice
{
......@@ -177,6 +182,11 @@ namespace Kivii.Finances.Transforms
if (amountInvoice <= 0) split.AmountInvoice = 0;
else split.AmountInvoice = split.Amount >= amountInvoice ? amountInvoice : split.Amount;
split.AddOnlyProperties(o => o.AmountInvoice);
if (split.AmountInvoice <= 0)
{
split.InvoiceTime = null;
split.AddOnlyProperties(o => o.InvoiceTime);
}
amountInvoice -= split.AmountInvoice;
}
}
......
......@@ -48,6 +48,11 @@ namespace Kivii.Finances.Transforms
item.AmountInvoice -= relations.Sum(o => o.Amount);
if (item.AmountInvoice < 0) item.AmountInvoice = 0;
item.AddOnlyProperties(o => o.AmountInvoice);
if (item.AmountInvoice <= 0)
{
item.InvoiceTime = null;
item.AddOnlyProperties(o => o.InvoiceTime);
}
}
if (!splitPayments.IsNullOrEmpty())//要是所选Payment存在拆分项,满足条件就要更新AmountInvoice
{
......@@ -58,6 +63,11 @@ namespace Kivii.Finances.Transforms
if (amountInvoice <= 0) split.AmountInvoice = 0;
else split.AmountInvoice = split.Amount >= amountInvoice ? amountInvoice : split.Amount;
split.AddOnlyProperties(o => o.AmountInvoice);
if (split.AmountInvoice <= 0)
{
split.InvoiceTime = null;
split.AddOnlyProperties(o => o.InvoiceTime);
}
amountInvoice -= split.AmountInvoice;
}
}
......
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