Exemple #1
0
        private bool IsDepreciationComputed(SCMSEntities db, TransactionScope scope, Asset assetEntity)
        {
            //var firstdateinMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddMonths(-1);
            //var lastdateinMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddDays(-1);
            //float purchasePrc = (float)gitm.PurchaseOrderItem.UnitPrice
            Model.Depreciation          deprEntity = null;
            Model.GoodsReceivedNoteItem gitm = db.GoodsReceivedNoteItems.FirstOrDefault(p => p.Id == assetEntity.GoodsReceivedNoteItemId);
            float purchasePrc = (float)assetEntity.PurchaseValue, percentageDepr = (float)assetEntity.PercentageDepr, accAnnualDepr = 0;
            float annualDepr = 0, monthlyDepr, netbookValue = purchasePrc, accumulatedDepr = 0, salvagevalue = (float)assetEntity.SalvageValue;
            int   periodcount = 0, monthcount = 0, numberOfYears = 0;

            if (assetEntity.DepreciationType == "Reducing Balance")
            {
                monthlyDepr = ReducingBalance(db, assetEntity, ref deprEntity, percentageDepr, ref accAnnualDepr, ref annualDepr, ref netbookValue, ref accumulatedDepr, salvagevalue, ref periodcount, ref monthcount, ref numberOfYears);
            }
            else
            {
                monthlyDepr = StraightLine(db, assetEntity, ref deprEntity, purchasePrc, percentageDepr, ref accAnnualDepr, ref annualDepr, ref netbookValue, ref accumulatedDepr, salvagevalue, ref periodcount, ref monthcount);
            }

            if (!(db.SaveChanges() > 0))
            {
                scope.Dispose(); SessionData.CurrentSession.DepreciationList = null; return(false);
            }
            scope.Complete(); return(true);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }