public ActionResult AssetDepreciationView(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Asset asset = db.T_Assets.Find(id); if (asset == null) { return(HttpNotFound()); } Depreciation depreciation = new Depreciation(); AssetDataSet assetDataSet = new AssetDataSet(db, asset.Id); AssetDepreciationPlan assetDepreciationPlan = depreciation.CalculateAssetDepreciationPlan(assetDataSet, asset, false); return(View(assetDepreciationPlan)); }
public void TestCalculateAssetDepreciationPlan() { Asset asset = new Asset() { Id = 2, AssetName = "Serwer HP", StartUsingDate = new DateTime(2017, 12, 8), InitialValue = (decimal)1000.21, AmortisedValue = 0, DepreciationTypeId = 1 }; Dictionary <int, string> monthNames = MocForMonths(); Dictionary <int, DepreciationType> depreciationTypes = new Dictionary <int, DepreciationType>(); depreciationTypes.Add(1, new DepreciationType() { Id = 1, Name = "Liniowa 30%", DepreciationRate = (decimal)30 }); List <DepreciationCharge> depreciationCharges = new List <DepreciationCharge>(); depreciationCharges.Add(new DepreciationCharge() { Id = 10, No = 1, Month = 1, Year = 2018, CurrentCharge = (decimal)25.01, CumulativelyCharge = (decimal)25.01, RemainingAmount = (decimal)975.20, AssetId = 2 }); depreciationCharges.Add(new DepreciationCharge() { Id = 11, No = 2, Month = 2, Year = 2018, CurrentCharge = (decimal)25.01, CumulativelyCharge = (decimal)50.02, RemainingAmount = (decimal)950.19, AssetId = 2 }); depreciationCharges.Add(new DepreciationCharge() { Id = 12, No = 3, Month = 3, Year = 2018, CurrentCharge = (decimal)25.01, CumulativelyCharge = (decimal)75.03, RemainingAmount = (decimal)925.18, AssetId = 2 }); depreciationCharges.Add(new DepreciationCharge() { Id = 13, No = 4, Month = 4, Year = 2018, CurrentCharge = (decimal)25.01, CumulativelyCharge = (decimal)100.04, RemainingAmount = (decimal)900.17, AssetId = 2 }); depreciationCharges.Add(new DepreciationCharge() { Id = 14, No = 5, Month = 5, Year = 2018, CurrentCharge = (decimal)25.01, CumulativelyCharge = (decimal)125.05, RemainingAmount = (decimal)875.16, AssetId = 2 }); depreciationCharges.Add(new DepreciationCharge() { Id = 15, No = 6, Month = 6, Year = 2018, CurrentCharge = (decimal)25.01, CumulativelyCharge = (decimal)150.06, RemainingAmount = (decimal)850.15, AssetId = 2 }); depreciationCharges.Add(new DepreciationCharge() { Id = 16, No = 7, Month = 7, Year = 2018, CurrentCharge = (decimal)25.01, CumulativelyCharge = (decimal)175.07, RemainingAmount = (decimal)825.14, AssetId = 2 }); depreciationCharges.Add(new DepreciationCharge() { Id = 17, No = 8, Month = 8, Year = 2018, CurrentCharge = (decimal)25.01, CumulativelyCharge = (decimal)200.08, RemainingAmount = (decimal)800.13, AssetId = 2 }); depreciationCharges.Add(new DepreciationCharge() { Id = 18, No = 9, Month = 9, Year = 2018, CurrentCharge = (decimal)25.01, CumulativelyCharge = (decimal)225.09, RemainingAmount = (decimal)775.12, AssetId = 2 }); depreciationCharges.Add(new DepreciationCharge() { Id = 19, No = 10, Month = 10, Year = 2018, CurrentCharge = (decimal)25.01, CumulativelyCharge = (decimal)250.10, RemainingAmount = (decimal)750.11, AssetId = 2 }); depreciationCharges.Add(new DepreciationCharge() { Id = 20, No = 11, Month = 11, Year = 2018, CurrentCharge = (decimal)25.01, CumulativelyCharge = (decimal)275.11, RemainingAmount = (decimal)725.10, AssetId = 2 }); depreciationCharges.Add(new DepreciationCharge() { Id = 21, No = 12, Month = 12, Year = 2018, CurrentCharge = (decimal)25.01, CumulativelyCharge = (decimal)300.12, RemainingAmount = (decimal)700.09, AssetId = 2 }); depreciationCharges.Add(new DepreciationCharge() { Id = 22, No = 13, Month = 1, Year = 2019, CurrentCharge = (decimal)25.01, CumulativelyCharge = (decimal)325.13, RemainingAmount = (decimal)675.08, AssetId = 2 }); depreciationCharges.Add(new DepreciationCharge() { Id = 23, No = 14, Month = 2, Year = 2019, CurrentCharge = (decimal)25.01, CumulativelyCharge = (decimal)350.14, RemainingAmount = (decimal)650.07, AssetId = 2 }); depreciationCharges.Add(new DepreciationCharge() { Id = 24, No = 15, Month = 3, Year = 2019, CurrentCharge = (decimal)25.01, CumulativelyCharge = (decimal)375.15, RemainingAmount = (decimal)625.06, AssetId = 2 }); AssetDataSet assetDataSet = new AssetDataSet() { MonthNames = monthNames, DepreciationTypes = depreciationTypes, DepreciationCharges = depreciationCharges }; Depreciation depreciation = new Depreciation(); AssetDepreciationPlan assetDepreciationPlan = depreciation.CalculateAssetDepreciationPlan(assetDataSet, asset, true); decimal total11 = 0; decimal total12 = 0; decimal total13 = 0; decimal total21 = 0; decimal total31 = assetDepreciationPlan.TotalCurrentCharge; decimal total32 = assetDepreciationPlan.TotalCumulativelyCharge; decimal total33 = assetDepreciationPlan.TotalRemainingAmount; foreach (AssetDepreciationYearPlan assetDepreciationYearPlan in assetDepreciationPlan.AssetDepreciationYearPlans) { foreach (AssetDepreciationMonthPlan assetDepreciationMonthPlan in assetDepreciationYearPlan.AssetDepreciationMonthPlans) { total11 += assetDepreciationMonthPlan.CurrentCharge; total12 = assetDepreciationMonthPlan.CumulativelyCharge; total13 = assetDepreciationMonthPlan.RemainingAmount; } total21 += assetDepreciationYearPlan.TotalYearCharge; } Assert.AreEqual(total11, total21); Assert.AreEqual(total31, total21); Assert.AreEqual(total12, total32); Assert.AreEqual(total13, total33); }