示例#1
0
        public ActionResult Depreciation(int startMonth, int startYear, int endMonth, int endYear)
        {
            Depreciation         depreciation         = new Depreciation();
            MyDataSet            myDataSet            = new MyDataSet(db);
            DepreciationPlanList depreciationPlanList = depreciation.CalculatePlan(startMonth, startYear, endMonth, endYear, myDataSet.MonthNames);

            depreciation.CalculatePlanForAssets(depreciationPlanList, myDataSet, true);

            return(View(depreciationPlanList));
        }
        public void TestMethodDepretiatinPlan()
        {
            Depreciation             depreciation = new Depreciation();
            Dictionary <int, string> monthNames   = MocForMonths();

            int startMonth = 2, startYear = 2017, endMonth = 5, endYear = 2018;

            DepreciationPlanList depreciationPlanList = depreciation.CalculatePlan(startMonth, startYear, endMonth, endYear, monthNames);

            Assert.IsTrue(depreciationPlanList.DepreciationPlans.Count == 16);
        }
        public void TestMethodDepretiatinPlanCalculation()
        {
            Depreciation             depreciation = new Depreciation();
            Dictionary <int, string> monthNames   = MocForMonths();

            int startMonth = 2, startYear = 2017, endMonth = 5, endYear = 2030;

            DepreciationPlanList depreciationPlanList = depreciation.CalculatePlan(startMonth, startYear, endMonth, endYear, monthNames);

            List <AssetType> assetTypes = new List <AssetType>();

            assetTypes.Add(new AssetType()
            {
                Id = 3, LowValueAsset = false, Name = "Zestaw komputerowy"
            });
            assetTypes.Add(new AssetType()
            {
                Id = 4, LowValueAsset = false, Name = "Drukarka"
            });
            assetTypes.Add(new AssetType()
            {
                Id = 5, LowValueAsset = false, Name = "Serwer"
            });
            assetTypes.Add(new AssetType()
            {
                Id = 6, LowValueAsset = true, Name = "Biurko"
            });
            assetTypes.Add(new AssetType()
            {
                Id = 7, LowValueAsset = true, Name = "Krzeslo"
            });
            assetTypes.Add(new AssetType()
            {
                Id = 8, LowValueAsset = false, Name = "Projektor"
            });
            assetTypes.Add(new AssetType()
            {
                Id = 9, LowValueAsset = false, Name = "UPS"
            });
            assetTypes.Add(new AssetType()
            {
                Id = 10, LowValueAsset = false, Name = "Macierz dyskowa"
            });
            assetTypes.Add(new AssetType()
            {
                Id = 11, LowValueAsset = false, Name = "Super biurko prezesowej"
            });
            List <Asset> assetList      = new List <Asset>();

            assetList.Add(new Asset()
            {
                Id = 2, AssetName = "Serwer HP", StartUsingDate = new DateTime(2017, 12, 8), InitialValue = (decimal)1000.21, AmortisedValue = 0, DepreciationTypeId = 1, AssetTypeId = 5, IsUsed = true, Depreciated = false
            });
            assetList.Add(new Asset()
            {
                Id = 3, AssetName = "Macierz dyskowa 50TB", StartUsingDate = new DateTime(2017, 12, 21), InitialValue = (decimal)25000, AmortisedValue = 0, DepreciationTypeId = 1, AssetTypeId = 10, IsUsed = true, Depreciated = false
            });
            assetList.Add(new Asset()
            {
                Id = 6, AssetName = "Biurko prezesowej", StartUsingDate = new DateTime(2017, 12, 8), InitialValue = (decimal)10000.00, AmortisedValue = 0, DepreciationTypeId = 1, AssetTypeId = 11, IsUsed = true, Depreciated = false
            });
            assetList.Add(new Asset()
            {
                Id = 9, AssetName = "Biurko pracownika", StartUsingDate = new DateTime(2017, 10, 15), InitialValue = (decimal)500.00, AmortisedValue = 0, DepreciationTypeId = 2, AssetTypeId = 6, IsUsed = true, Depreciated = false
            });

            Dictionary <int, DepreciationType> depreciationTypes = new Dictionary <int, DepreciationType>();

            depreciationTypes.Add(1, new DepreciationType()
            {
                Id = 1, Name = "Liniowa 30%", DepreciationRate = (decimal)30
            });
            depreciationTypes.Add(2, new DepreciationType()
            {
                Id = 2, Name = "Jednorazowa", DepreciationRate = (decimal)100
            });

            Dictionary <string, DepreciationCharge> depreciationCharges = new Dictionary <string, DepreciationCharge>();
            MyDataSet myDataSet = new MyDataSet();

            myDataSet.AssetList           = assetList;
            myDataSet.DepreciationTypes   = depreciationTypes;
            myDataSet.DepreciationCharges = depreciationCharges;
            myDataSet.AssetTypes          = assetTypes;

            depreciation.CalculatePlanForAssets(depreciationPlanList, myDataSet, false);

            decimal total = 0;

            foreach (DepreciationPlan dep in depreciationPlanList.DepreciationPlans)
            {
                total += dep.CurrentCharge;
            }

            Assert.AreEqual(total, (decimal)(10000.00 + 25000.00 + 1000.21 + 500));
        }
        public void TestMethodDepretiatinProccessedView()
        {
            Depreciation             depreciation = new Depreciation();
            Dictionary <int, string> monthNames   = MocForMonths();

            int startMonth = 1, startYear = 2018, endMonth = 2, endYear = 2018;

            DepreciationPlanList depreciationPlanList = depreciation.CalculatePlan(startMonth, startYear, endMonth, endYear, monthNames);

            List <Asset> assetList = new List <Asset>();

            assetList.Add(new Asset()
            {
                Id = 2, AssetName = "Serwer HP", StartUsingDate = new DateTime(2017, 12, 8), InitialValue = (decimal)1000.21, AmortisedValue = 0, DepreciationTypeId = 1
            });
            assetList.Add(new Asset()
            {
                Id = 3, AssetName = "Macierz dyskowa 50TB", StartUsingDate = new DateTime(2017, 12, 21), InitialValue = (decimal)25000, AmortisedValue = 0, DepreciationTypeId = 1
            });
            assetList.Add(new Asset()
            {
                Id = 6, AssetName = "Biurko prezesowej", StartUsingDate = new DateTime(2017, 12, 8), InitialValue = (decimal)10000.00, AmortisedValue = 0, DepreciationTypeId = 1
            });

            Dictionary <int, DepreciationType> depreciationTypes = new Dictionary <int, DepreciationType>();

            depreciationTypes.Add(1, new DepreciationType()
            {
                Id = 1, Name = "Liniowa 30%", DepreciationRate = (decimal)30
            });

            Dictionary <string, DepreciationCharge> depreciationCharges = new Dictionary <string, DepreciationCharge>();

            depreciationCharges.Add("2018012", 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("2018013", new DepreciationCharge()
            {
                Id = 11, No = 1, Month = 1, Year = 2018, CurrentCharge = (decimal)625.00, CumulativelyCharge = (decimal)25.01, RemainingAmount = (decimal)24375.00, AssetId = 3
            });
            depreciationCharges.Add("2018016", new DepreciationCharge()
            {
                Id = 12, No = 1, Month = 1, Year = 2018, CurrentCharge = (decimal)250.00, CumulativelyCharge = (decimal)25.01, RemainingAmount = (decimal)9750.00, AssetId = 6
            });
            depreciationCharges.Add("2018022", new DepreciationCharge()
            {
                Id = 13, No = 2, Month = 2, Year = 2018, CurrentCharge = (decimal)25.01, CumulativelyCharge = (decimal)50.02, RemainingAmount = (decimal)950.19, AssetId = 2
            });
            depreciationCharges.Add("2018023", new DepreciationCharge()
            {
                Id = 14, No = 2, Month = 2, Year = 2018, CurrentCharge = (decimal)625.00, CumulativelyCharge = (decimal)1250.00, RemainingAmount = (decimal)23750.00, AssetId = 3
            });
            depreciationCharges.Add("2018026", new DepreciationCharge()
            {
                Id = 15, No = 2, Month = 2, Year = 2018, CurrentCharge = (decimal)250.00, CumulativelyCharge = (decimal)500.00, RemainingAmount = (decimal)9500.00, AssetId = 6
            });

            MyDataSet myDataSet = new MyDataSet();

            myDataSet.AssetList           = assetList;
            myDataSet.DepreciationTypes   = depreciationTypes;
            myDataSet.DepreciationCharges = depreciationCharges;

            depreciation.CalculateProcessedDepreciation(depreciationPlanList, myDataSet);

            decimal total11 = 0;
            decimal total12 = 0;
            decimal total13 = 0;

            decimal total21 = 0;
            decimal total22 = 0;
            decimal total23 = 0;

            decimal total31 = 0;
            decimal total32 = 0;
            decimal total33 = 0;

            foreach (DepreciationPlan dep in depreciationPlanList.DepreciationPlans)
            {
                foreach (DepreciationItem d in dep.Depreciacions)
                {
                    total11 += d.CurrentCharge;
                    total12 += d.CumulativelyCharge;
                    total13 += d.RemainingAmount;
                }

                total21 += dep.CurrentCharge;
                total22  = dep.CumulativelyCharge;
                total23  = dep.RemainingAmount;
            }

            total31 = depreciationPlanList.TotalCurrentCharge;
            total32 = depreciationPlanList.TotalCumulativelyCharge;
            total33 = depreciationPlanList.TotalRemainingAmount;


            Assert.AreEqual(total11, total21);
            Assert.AreEqual(total31, total21);
            Assert.AreEqual(total22, total32);
            Assert.AreEqual(total23, total33);
        }