From 46cd437578acc8db0d4a0454fb456394265bfffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E6=80=9D=E6=AD=A3?= <2823259578@qq.com> Date: Thu, 29 Aug 2024 09:48:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E5=9D=87=E5=B9=B4=E9=99=90=E6=B3=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Entitys/XDepreciationConfig.cs | 75 +++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/Entitys/XDepreciationConfig.cs b/Entitys/XDepreciationConfig.cs index 3637c15..5ef4968 100644 --- a/Entitys/XDepreciationConfig.cs +++ b/Entitys/XDepreciationConfig.cs @@ -9,6 +9,7 @@ namespace anydata.Models public List Dimensions { get; set; } public XProperty DepreciationMethod { get; set; } public string YearAverageMethod { get; set; } + public string YearAverageMethod2 { get; set; } public XProperty DepreciationStatus { get; set; } public string AccruingStatus { get; set; } public string AccruedStatus { get; set; } @@ -19,8 +20,11 @@ namespace anydata.Models public XProperty AccruedMonths { get; set; } public XProperty UsefulLife { get; set; } public XProperty StartDate { get; set; } + public XProperty ResidualRate { get; set; } + public XProperty ResidualVal { get; set; } public List Fields { get; set; } + public bool Check() { return Dimensions is null || Dimensions.Count == 0 || DepreciationMethod is null || YearAverageMethod is null || DepreciationStatus is null || AccruingStatus is null || AccruedStatus is null @@ -39,6 +43,8 @@ namespace anydata.Models AccruedMonths.Initialize(); StartDate.Initialize(); UsefulLife.Initialize(); + ResidualRate.Initialize(); + ResidualVal.Initialize(); Fields = new List { DepreciationStatus.field, OriginalValue.field, AccumulatedDepreciation.field, MonthlyDepreciationAmount.field, NetWorth.field }; Dimensions.ForEach(item => Fields.Add(item.field)); return this; @@ -56,7 +62,8 @@ namespace anydata.Models { ["_in_"] = new JArray { - YearAverageMethod + YearAverageMethod, + YearAverageMethod2 } }, [OriginalValue.field.code] = new JObject @@ -114,7 +121,7 @@ namespace anydata.Models } } else - { + { var monthlyDepreciationAmount = Math.Round(afterNetWorth / remainderMonth, 2); after[MonthlyDepreciationAmount.field.code] = Math.Round(monthlyDepreciationAmount, 2); if (monthlyDepreciationAmount > afterNetWorth) @@ -122,7 +129,7 @@ namespace anydata.Models monthlyDepreciationAmount = afterNetWorth; } afterAccumulated += monthlyDepreciationAmount; - afterNetWorth -= monthlyDepreciationAmount; + afterNetWorth -= monthlyDepreciationAmount; remainderMonth -= 1; if (Math.Round(afterAccumulated, 2) != Math.Round(accumulated, 2)) @@ -131,7 +138,65 @@ namespace anydata.Models change.SetChangeDimension(after, context.SourceFields); changes.Add(change); } - } + } + after[AccumulatedDepreciation.field.code] = Math.Round(afterAccumulated, 2); + after[NetWorth.field.code] = Math.Round(afterNetWorth, 2); + after[AccruedMonths.field.code] = usefulLife - remainderMonth; + after[DepreciationStatus.field.code] = remainderMonth == 0 ? AccruedStatus : AccruingStatus; + + return (after, changes); + } + else if (method?.ToString() == YearAverageMethod2) + { + var originalValue = before.GetDoubleValue(OriginalValue.field); + var accumulated = before.GetDoubleValue(AccumulatedDepreciation.field); + var afterAccumulated = accumulated; + var netWorth = originalValue - accumulated; + var afterNetWorth = netWorth; + var usefulLife = before.GetIntValue(UsefulLife.field); + var startDate = before.GetDateValue(StartDate.field); + var residualRate = before.GetDoubleValue(ResidualRate.field) / 100; + var residualVal = residualRate * originalValue;//净残值=净残值率 * 原值 + var diffVal = originalValue - residualVal;//diffVal为原值减去净残值 + + if (netWorth <= 0 || startDate is null) + { + return (null, changes); + } + startDate = startDate.Value.AddMonths(1); + var after = before.Clone(); + var rightAccruedMonths = MonthBetween((DateTime)startDate, current); + var remainderMonth = usefulLife - rightAccruedMonths; + if (remainderMonth <= 0) + { + afterAccumulated = originalValue; + afterNetWorth = 0; + if (Math.Round(afterAccumulated, 2) != Math.Round(accumulated, 2)) + { + var change = new XChange(context, before.id, AccumulatedDepreciation.field.code, accumulated, afterAccumulated, snapshot.id); + change.SetChangeDimension(after, context.SourceFields); + changes.Add(change); + } + } + else + { + var monthlyDepreciationAmount = Math.Round(diffVal / remainderMonth, 2);//月折旧额=(原值-净残值)/折旧年限(月) + after[MonthlyDepreciationAmount.field.code] = Math.Round(monthlyDepreciationAmount, 2); + if (monthlyDepreciationAmount > afterNetWorth) + { + monthlyDepreciationAmount = afterNetWorth; + } + afterAccumulated += monthlyDepreciationAmount; + afterNetWorth -= monthlyDepreciationAmount; + remainderMonth -= 1; + + if (Math.Round(afterAccumulated, 2) != Math.Round(accumulated, 2)) + { + var change = new XChange(context, before.id, AccumulatedDepreciation.field.code, accumulated, afterAccumulated, snapshot.id); + change.SetChangeDimension(after, context.SourceFields); + changes.Add(change); + } + } after[AccumulatedDepreciation.field.code] = Math.Round(afterAccumulated, 2); after[NetWorth.field.code] = Math.Round(afterNetWorth, 2); after[AccruedMonths.field.code] = usefulLife - remainderMonth; @@ -144,7 +209,7 @@ namespace anydata.Models public (FilterDefinition, UpdateDefinition)? BuildFilterUpdate(EntityBase after) { var method = after[DepreciationMethod.field.code]; - if (method?.ToString() == YearAverageMethod) + if (method?.ToString() == YearAverageMethod || method?.ToString() == YearAverageMethod2) { var filter = Builders.Filter.Eq(i => i.id, after.id); var update = Builders.Update.CurrentDate(i => i.updateTime) -- Gitee