예제 #1
0
        public async Task ItCanDepreciateAnAsset()
        {
            var currentDate = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1);
            var rand        = new Random();
            var asset       = new Asset()
            {
                Number                    = "TestProd" + rand.Next(9999999),
                Description               = "TEST PRODUCT",
                TypeId                    = "8",
                DepreciationMethod        = "0",
                AcquisitionValue          = 13000,
                DepreciateToResidualValue = 1300,
                AcquisitionDate           = currentDate,
                AcquisitionStart          = currentDate.AddMonths(1),
                DepreciationFinal         = currentDate.AddYears(1),
            };

            var request = new FortnoxApiRequest(this.connectionSettings.AccessToken, this.connectionSettings.ClientSecret);
            var result  = await AssetsService.CreateAssetAsync(request, asset);

            Assert.AreEqual(asset.Number, result.Number);

            var depreciationDate = currentDate.AddMonths(2);

            depreciationDate = new DateTime(depreciationDate.Year, depreciationDate.Month, DateTime.DaysInMonth(depreciationDate.Year, depreciationDate.Month));
            var assetDepreciation = new DepreciateAssets {
                DepreciateUntil = depreciationDate, AssetIds = new List <int> {
                    result.Id
                }
            };
            var depreciatedAssetResponse = await AssetsService.DepreciateAssetAsync(request, assetDepreciation);

            var depreciationResult = depreciatedAssetResponse.Data.First();

            Assert.IsTrue(depreciationResult.FinancialYear == 3);
            Assert.IsTrue(depreciationResult.VoucherSeries.Equals("G"));
        }