public async Task <GetDepreciationOutput> GetDepreciationForEditAsync(NullableIdDto input)
        {
            Depreciation depreciation = null;

            if (input.Id.HasValue && input.Id.Value > 0)
            {
                depreciation = await _depreciationRepository.GetAsync(input.Id.Value);
            }
            GetDepreciationOutput output = new GetDepreciationOutput
            {
                Depreciation = depreciation != null
                ? ObjectMapper.Map <DepreciationDto>(depreciation)
                : new DepreciationDto()
            };

            int parentMenuId = output.Depreciation.Id;

            output.Depreciations = await _depreciationRepository.GetAll()
                                   .Select(c => new ComboboxItemDto(c.Id.ToString(), c.Name)
            {
                IsSelected = parentMenuId == c.Id
            })
                                   .ToListAsync();

            return(output);
        }
        public async Task <IActionResult> Edit(int id, [Bind("DepreciationID,DepreciationName,DepreciationDescription")] Depreciation depreciation)
        {
            if (id != depreciation.DepreciationID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(depreciation);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DepreciationExists(depreciation.DepreciationID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(depreciation));
        }
        public async Task <ActionResult <Depreciation> > PostDepreciation(Depreciation depreciation)
        {
            _context.Depreciations.Add(depreciation);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetDepreciation", new { id = depreciation.Id }, depreciation));
        }
Example #4
0
        public ActionResult ImmoGridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Depreciation item)
        {
            var model = db.Depreciations;

            item.CompanyId = (string)Session["CompanyID"];
            item.ModelId   = (int)IWSLookUp.MetaModelId.Asset;
            DateTime dateTime = IWSLookUp.GetCurrentDateTime();

            item.Posted      = dateTime;
            item.Updated     = dateTime;
            ViewData["immo"] = item;
            if (ModelState.IsValid)
            {
                try
                {
                    model.InsertOnSubmit(item);

                    db.SubmitChanges();

                    SetDepreciation(item);
                }
                catch (Exception e)
                {
                    ViewData["GenericError"] = e.Message;
                    IWSLookUp.LogException(e);
                }
            }
            else
            {
                ViewData["GenericError"] = IWSLookUp.GetModelSateErrors(ModelState);
            }
            return(PartialView("ImmoGridViewPartial", IWSLookUp.GetDepreciation()));
        }
        public async Task <IActionResult> PutDepreciation(int id, Depreciation depreciation)
        {
            if (id != depreciation.Id)
            {
                return(BadRequest());
            }

            _context.Entry(depreciation).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DepreciationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #6
0
        public ActionResult ImmoGridViewPartialUpdate([ModelBinder(typeof(DevExpressEditorsBinder))] Depreciation item)
        {
            var model = db.Depreciations;

            ViewData["immo"] = item;
            if (ModelState.IsValid)
            {
                try
                {
                    var modelItem = model.FirstOrDefault(i => i.Id == item.Id);
                    if (modelItem != null)
                    {
                        this.UpdateModel(modelItem);
                        db.SubmitChanges();
                        DeleteDepreciation(item);

                        SetDepreciation(item);
                    }
                }
                catch (Exception e)
                {
                    ViewData["GenericError"] = e.Message;
                    IWSLookUp.LogException(e);
                }
            }
            else
            {
                ViewData["GenericError"] = IWSLookUp.GetModelSateErrors(ModelState);
            }
            return(PartialView("ImmoGridViewPartial", IWSLookUp.GetDepreciation()));
        }
Example #7
0
        private void SetDepreciation(Depreciation depreciation)
        {
            List <DepreciationInfo> depreciationInfos = ComputeDepreciation((double)depreciation.CostOfAsset, (double)depreciation.ScrapValue,
                                                                            (int)depreciation.LifeSpan, 30, depreciation.Id, (DateTime)depreciation.Started, depreciation.Currency);

            var depreciationDetails = db.DepreciationDetails;

            foreach (var item in depreciationInfos)
            {
                DepreciationDetail detail = new DepreciationDetail
                {
                    TransId = item.TransId,
                    Period  = item.Period,
                    //StraightLineDepreciation = (decimal)item.StraightLineDepreciation,
                    //StraightLineBookValue = (decimal)item.StraightLineBookValue,
                    Depreciation = (decimal)item.Depreciation,
                    Accumulated  = (decimal)item.Accumulation,
                    BookValue    = (decimal)item.BookValue,
                    Percentage   = (decimal)item.Percentage,
                    Currency     = item.Currency,
                    IsValidated  = false
                };
                depreciationDetails.InsertOnSubmit(detail);
            }
            db.SubmitChanges();
        }
Example #8
0
        public async Task <GetDepreciationOutput> GetDepreciationForEditAsync(NullableIdDto input)
        {
            Depreciation Depreciation = null;

            if (input.Id.HasValue && input.Id.Value > 0)
            {
                Depreciation = await _menuRepository.GetAsync(input.Id.Value);
            }
            var output = new GetDepreciationOutput();

            output.Depreciation = Depreciation != null
                ? ObjectMapper.Map <DepreciationDto>(Depreciation)
                : new DepreciationDto();

            var parentMenuId = output.Depreciation.ParentId ?? 0;

            output.Depreciations = await _menuRepository.GetAll()
                                   .Where(m => m.Status)
                                   .Select(c => new ComboboxItemDto(c.Id.ToString(), c.Name)
            {
                IsSelected = parentMenuId == c.Id
            })
                                   .ToListAsync();

            return(output);
        }
        public async Task <DepreciationDto> CreateDepreciationAsync(CreateDepreciationInput input)
        {
            Depreciation entity = ObjectMapper.Map <Depreciation>(input);

            entity = await _depreciationRepository.InsertAsync(entity);

            return(ObjectMapper.Map <DepreciationDto>(entity));
        }
        public async Task DeleteDepreciationAsync(EntityDto <int> input)
        {
            Depreciation entity = await _depreciationRepository.GetAsync(input.Id);

            _ = await _depreciationRepository.UpdateAsync(entity);

            await CurrentUnitOfWork.SaveChangesAsync();
        }
Example #11
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));
        }
Example #12
0
        public async Task <IActionResult> Insert(Depreciation item)
        {
            if (ModelState.IsValid)
            {
                await _depreciationRepository.AddAsync(item);

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
Example #13
0
        private void DeleteDepreciation(Depreciation item)
        {
            var details = db.DepreciationDetails.Where(i => i.TransId == item.Id).Select(i => new { i.Id });

            foreach (var detail in details)
            {
                ImmoDetailDelete(detail.Id);
                db.SubmitChanges();
            }
        }
Example #14
0
        /// <inheritdoc />
        protected override void ProcessRecord()
        {
            var item = new Depreciation {
                Name   = this.Name,
                Months = this.Months
            };

            //TODO: error handling
            WriteObject(ApiHelper.Instance.Depreciations.Create(item));
        }
        public async Task <IActionResult> Create([Bind("DepreciationID,DepreciationName,DepreciationDescription")] Depreciation depreciation)
        {
            if (ModelState.IsValid)
            {
                _context.Add(depreciation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(depreciation));
        }
        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 async Task <DepreciationDto> UpdateDepreciationAsync(UpdateDepreciationInput input)
        {
            Depreciation entity = await _depreciationRepository.GetAsync(input.Id);

            ObjectMapper.Map(input, entity);
            entity = await _depreciationRepository.UpdateAsync(entity);

            await CurrentUnitOfWork.SaveChangesAsync();

            return(ObjectMapper.Map <DepreciationDto>(entity));
        }
 public async Task UpdateDepreciationAsync(DepreciationViewModel depreciationVM, string userId)
 {
     _logger.LogInformation("UpdateDepreciationAsync called.");
     var depreciation = new Depreciation()
     {
         Id        = depreciationVM.Id,
         Name      = depreciationVM.Name,
         Months    = depreciationVM.Months,
         UpdatedAt = DateTime.Now,
         UpdatedBy = userId
     };
     await _depreciationRepository.UpdateAsync(depreciation);
 }
Example #19
0
        public async Task <IActionResult> Edit(int id, Depreciation obj)
        {
            try
            {
                await _depreciationRepository.UpdateAsync(obj);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Example #20
0
        private void generate()
        {
            depreciation = new Depreciation(
                Cost,
                salvageValue,
                lifeSpan,
                DateProcured
                );

            lblTotal.Text        = Format.formatToPeso(depreciation.getTotal());
            lblDepreciation.Text = Format.formatToPeso(depreciation.getDepreciation());

            try
            {
                double percentage = depreciation.getPercentage();
                Math.Round(percentage, 0);
                Math.Round((decimal)percentage, 0);

                gPercentage.Value  = Convert.ToInt32(percentage);
                lblPercentage.Text = percentage.ToString("0.00") + "%";
                if (isLost == false)
                {
                    dgvBookValues.DataSource = depreciation.getBookValues();
                    dgvBookValues.ClearSelection();
                }
                else
                {
                    int    years = depreciation.getYearsBeetween();
                    double bookValue = 0.0, discount = 0.0;

                    if (years > lifeSpan)
                    {
                        lblYear.ForeColor = Color.Red;
                        lblYear.Text      = years + " (exceed the expected lifespan) ";
                    }
                    else
                    {
                        bookValue    = depreciation.getCurrentBookValue();
                        discount     = (bookValue * 0.1) + bookValue;
                        lblYear.Text = years.ToString();
                    }

                    lblBookValue.Text = Format.formatToPeso(bookValue);
                    lblPlusten.Text   = Format.formatToPeso(discount);
                }
            }
            catch (Exception) { }
        }
Example #21
0
 public void tsbtckkh(string a, Form1 F, DevExpress.XtraGrid.Views.Grid.GridView view, string ngay)
 {
     try
     {
         Depreciation m = new Depreciation();
         m.myac = new Depreciation.ac(F.refreshckkh);
         m.getactive(a);
         m.getngay(ngay);
         if (a == "1")
         {
             m.getrole(view.GetRowCellValue(view.FocusedRowHandle, "ID").ToString());
         }
         m.ShowDialog();
     }
     catch { MessageBox.Show("Vui lòng chọn Tài sản khấu hao trước khi sửa."); }
 }
Example #22
0
        private void initCurrentBookValue()
        {
            Database.set("SELECT tbldepreciation.depreciation_id,tblitem.date_procured,tblitem.price,tbldepreciation.depreciation FROM tblitem INNER JOIN tbldepreciation ON tblitem.depreciation_id = tbldepreciation.depreciation_id;");
            DataTable table = new DataTable();

            table = Database.executeResultSet();

            foreach (DataRow row in table.Rows)
            {
                String id           = row["depreciation_id"].ToString();
                String dateProcured = row["date_procured"].ToString();
                double cost         = double.Parse(row["price"].ToString());
                double deprec       = double.Parse(row["depreciation"].ToString());
                double percentage   = 0.0;
                double bookValue    = Depreciation.getCurrentBookValue(dateProcured, cost, deprec);

                if (bookValue <= 0)
                {
                    bookValue = 0.00;
                }

                percentage = (bookValue / cost) * 100;

                using (MySql.Data.MySqlClient.MySqlConnection con = Database.getConnection())
                {
                    try
                    {
                        con.Open();
                        String sql = "UPDATE tbldepreciation SET book_value = @bookValue,current_percent = @currentPercent WHERE depreciation_id = @id;";
                        MySql.Data.MySqlClient.MySqlCommand command = new MySql.Data.MySqlClient.MySqlCommand(sql, con);
                        command.Parameters.AddWithValue("@bookValue", bookValue);
                        command.Parameters.AddWithValue("@currentPercent", percentage.ToString("N2"));
                        command.Parameters.AddWithValue("@id", id);
                        command.ExecuteNonQuery();
                    }
                    catch (MySql.Data.MySqlClient.MySqlException exception)
                    {
                        System.Windows.Forms.MessageBox.Show(exception.Message);
                    }
                    finally
                    {
                        con.Close();
                    }
                }
            }
        }
 public Expenses()
 {
     costOfGoodsBought           = new Costofgoodsbought();
     cisPaymentsToSubcontractors = new Cispaymentstosubcontractors();
     staffCosts           = new Staffcosts();
     travelCosts          = new Travelcosts();
     premisesRunningCosts = new Premisesrunningcosts();
     maintenanceCosts     = new Maintenancecosts();
     adminCosts           = new Admincosts();
     advertisingCosts     = new Advertisingcosts();
     interest             = new Interest();
     financialCharges     = new Financialcharges();
     badDebt          = new Baddebt();
     professionalFees = new Professionalfees();
     depreciation     = new Depreciation();
     other            = new Other1();
 }
Example #24
0
        public async Task <IActionResult> Delete(int id, Depreciation item)
        {
            if (id != item.Id)
            {
                return(RedirectToAction(nameof(Index)));
            }
            try
            {
                await _depreciationRepository.DeleteAsync(item);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Example #25
0
        private static float ReducingBalance(SCMSEntities db, Asset assetEntity, ref Model.Depreciation deprEntity, float percentageDepr, ref float accAnnualDepr,
                                             ref float annualDepr, ref float netbookValue, ref float accumulatedDepr, float salvagevalue, ref int periodcount, ref int monthcount, ref int numberOfYears)
        {
            float monthlyDepr;

            while (true)
            {
                annualDepr  = ((netbookValue - salvagevalue) * (percentageDepr / 100));
                monthlyDepr = annualDepr / 12; numberOfYears++;

                if (assetEntity.UseLifeSpan)
                {
                    if (numberOfYears > assetEntity.Lifespan)
                    {
                        break;
                    }
                }
                else
                {
                    if (annualDepr <= 12)
                    {
                        break;
                    }
                }

                do
                {
                    monthcount++; periodcount++;
                    accumulatedDepr               += monthlyDepr;
                    accAnnualDepr                 += monthlyDepr;
                    netbookValue                  -= monthlyDepr;
                    deprEntity                     = new Depreciation();
                    deprEntity.Id                  = Guid.NewGuid();
                    deprEntity.AssetId             = assetEntity.Id;
                    deprEntity.Period              = periodcount;
                    deprEntity.NetbookValue        = netbookValue;
                    deprEntity.AccDepreciation     = accumulatedDepr;
                    deprEntity.MonthlyDepreciation = monthlyDepr;
                    deprEntity.AnnualDepreciation  = accAnnualDepr;
                    deprEntity.Date                = new DateTime(DateTime.Now.AddMonths(periodcount).Year, DateTime.Now.AddMonths(periodcount).Month, 1).AddDays(-1);
                    db.Depreciations.Add(deprEntity);
                } while (monthcount <= 11); monthcount = 0; accAnnualDepr = 0;
            }
            return(monthlyDepr);
        }
Example #26
0
        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));
        }
Example #27
0
        private static float StraightLine(SCMSEntities db, Asset assetEntity, ref Model.Depreciation deprEntity, float purchasePrc, float percentageDepr,
                                          ref float accAnnualDepr, ref float annualDepr, ref float netbookValue, ref float accumulatedDepr, float salvagevalue, ref int periodcount, ref int monthcount)
        {
            float monthlyDepr;

            while (true)
            {
                if (assetEntity.UseLifeSpan)
                {
                    annualDepr = (float)((float)(purchasePrc - (float)assetEntity.SalvageValue) / assetEntity.Lifespan);
                }
                else
                {
                    annualDepr = (float)((float)(purchasePrc - (float)assetEntity.SalvageValue) * (percentageDepr / 100));
                }
                periodcount++; monthcount++;
                monthlyDepr      = annualDepr / 12;
                accumulatedDepr += monthlyDepr;
                netbookValue    -= monthlyDepr;
                accAnnualDepr   += monthlyDepr;

                deprEntity                     = new Depreciation();
                deprEntity.Id                  = Guid.NewGuid();
                deprEntity.AssetId             = assetEntity.Id;
                deprEntity.Period              = periodcount;
                deprEntity.NetbookValue        = netbookValue;
                deprEntity.AccDepreciation     = accumulatedDepr;
                deprEntity.MonthlyDepreciation = monthlyDepr;
                deprEntity.AnnualDepreciation  = accAnnualDepr;
                deprEntity.Date                = new DateTime(DateTime.Now.AddMonths(periodcount).Year, DateTime.Now.AddMonths(periodcount).Month, 1).AddDays(-1);
                db.Depreciations.Add(deprEntity);
                if (monthcount == 12)
                {
                    monthcount = 0; accAnnualDepr = 0;
                }
                if (Math.Round(netbookValue) <= Math.Round(salvagevalue))
                {
                    break;
                }
            }
            return(monthlyDepr);
        }
        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 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);
        }
        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);
        }