コード例 #1
0
        private List <DepreciationInfo> ComputeDepreciation(double bookValue, double scrapValue, int lifeSpan, int frequency,
                                                            int DepreciationType, double rate, string assetId, DateTime period, string currency)
        {
            var depreciatedPeriod = IWSLookUp.GetLastDepreciatedPeriod(assetId);

            List <DepreciationInfo> depreciation = new List <DepreciationInfo>();

            if (bookValue <= 0 || scrapValue < 0 || lifeSpan <= 0 || bookValue <= scrapValue)
            {
                return(depreciation);
            }

            double newBookValue = Math.Round(bookValue, 2);

            newBookValue -= scrapValue;
            //double depreciationValue = 0;
            double           depreciationValue = Math.Round((newBookValue * frequency) / lifeSpan, 2);
            DepreciationInfo dpInfo            = new DepreciationInfo();

            for (DateTime p = depreciatedPeriod; p <= period; p = p.AddMonths(1))
            {
                //depreciationValue = Math.Round((newBookValue * frequency) / lifeSpan, 2);

                if (DepreciationType.Equals((int)IWSLookUp.DepreciationType.Degressive))
                {
                    if (lifeSpan > 1)
                    {
                        //depreciationValue = Math.Round(rate * newBookValue,2);
                        depreciationValue = Math.Round(rate * bookValue, 2);
                    }
                }
                if (depreciationValue >= newBookValue)
                {
                    newBookValue = Math.Round(scrapValue, 2);
                }
                else
                {
                    //if (DepreciationType.Equals((int)IWSLookUp.DepreciationType.StraightLine))
                    //{
                    //    newBookValue -= Math.Round(depreciationValue / frequency,2);
                    //}
                    //if (DepreciationType.Equals((int)IWSLookUp.DepreciationType.Degressive))
                    //{
                    //    newBookValue -= Math.Round(depreciationValue/frequency,2);
                    //}
                    newBookValue -= Math.Round(depreciationValue / frequency, 2);
                }
                DateTime dateTimePeriod = p;
                string   stringMonth    = dateTimePeriod.Month < 10 ?
                                          "0" + dateTimePeriod.Month.ToString() :
                                          dateTimePeriod.Month.ToString();
                string stringPeriod = dateTimePeriod.Year.ToString() + stringMonth;

                dpInfo = new DepreciationInfo
                {
                    TransId = assetId,
                    Period  = stringPeriod,
                    StraightLineDepreciation = 0,
                    StraightLineBookValue    = 0,
                    Depreciation             = Math.Round(depreciationValue / frequency, 2),
                    Accumulation             = 0,
                    BookValue  = newBookValue,
                    Percentage = 0,
                    Currency   = currency
                };
                if (!IsPreviousDepreciated(dpInfo.TransId, dpInfo.Period))
                {
                    depreciation.Add(dpInfo);
                }

                if (newBookValue <= 0 || newBookValue <= scrapValue)
                {
                    return(depreciation);
                }
            }
            return(depreciation);
        }
コード例 #2
0
        private List <DepreciationInfo> ComputeDepreciation(double costValue, double scrapValue, int lifeSpan, int frequency,
                                                            string transId, DateTime startDate, string currency)
        {
            List <DepreciationInfo> depreciation = new List <DepreciationInfo>();

            if (costValue <= 0 || scrapValue < 0 || lifeSpan <= 0 || costValue <= scrapValue)
            {
                return(depreciation);
            }

            double accumulation = 0;

            double bookValue = costValue - scrapValue;

            double yearlyDepreciation = bookValue / lifeSpan;

            double straightLineBookValue = costValue;

            double expense = 0;

            int sum = lifeSpan * (lifeSpan + 1) / 2;

            int totalPeriod = lifeSpan;

            DateTime dateTimePeriod = startDate;

            string stringPeriod;

            string stringMonth;

            for (int i = 0; i < lifeSpan; i++)
            {
                double percentage = totalPeriod / (double)sum;

                straightLineBookValue -= yearlyDepreciation;

                expense = bookValue * percentage;

                costValue -= expense;

                accumulation += expense;

                dateTimePeriod = dateTimePeriod.AddMonths(1);

                stringMonth = dateTimePeriod.Month < 10 ?
                              "0" + dateTimePeriod.Month.ToString() :
                              dateTimePeriod.Month.ToString();

                stringPeriod = dateTimePeriod.Year + "-" + stringMonth;

                DepreciationInfo dpInfo = new DepreciationInfo
                {
                    TransId = transId,

                    Period = stringPeriod,

                    StraightLineDepreciation = yearlyDepreciation,

                    StraightLineBookValue = straightLineBookValue,

                    Depreciation = expense,

                    Accumulation = accumulation,

                    BookValue = costValue,

                    Percentage = percentage * 100,
                    Currency   = currency
                };

                depreciation.Add(dpInfo);

                totalPeriod--;
            }
            return(depreciation);
        }